Skip to content

Commit

Permalink
feat: Added description-prop for fileupload item (#2975)
Browse files Browse the repository at this point in the history
* feat: Added description-prop for fileupload item

* Update @navikt/core/react/src/form/file-upload/parts/item/Item.tsx

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>

---------

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
  • Loading branch information
KenAJoh and HalvorHaugan authored Jun 5, 2024
1 parent 5b01119 commit d0debc1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-walls-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": minor
---

FileUpload: Added description-prop for Item.
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,15 @@ export const Download: StoryObj = {
</VStack>
),
};

export const Description: StoryObj = {
render: () => (
<VStack gap="5">
<FileUpload.Item file={fileTxt} description="Mottat 11.11.11" />
<FileUpload.Item
file={fileTxt}
description="Lorem ipsum dolor, sit amet consectetur adipisicing elit. Enim officiis nisi beatae quia non iste nihil accusantium nobis amet, officia eius, repellendus a cupiditate, commodi eos! Quis illum repudiandae exercitationem."
/>
</VStack>
),
};
8 changes: 7 additions & 1 deletion @navikt/core/react/src/form/file-upload/parts/item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export interface FileUploadItemProps
* @default "idle"
*/
status?: "downloading" | "uploading" | "idle";
/**
* File description. Replaces file size when status is "idle".
* This is useful for displaying upload date. Should not act as a replacement for error messages.
*/
description?: string;
/**
* Props for the action button.
*/
Expand Down Expand Up @@ -71,6 +76,7 @@ export const Item: OverridableComponent<FileUploadItemProps, HTMLDivElement> =
onFileClick,
button,
translations,
description,
...rest
}: FileUploadItemProps,
ref,
Expand All @@ -91,7 +97,7 @@ export const Item: OverridableComponent<FileUploadItemProps, HTMLDivElement> =
if (status === "downloading") {
return translate("item.downloading");
}
return formatFileSize(file);
return description ?? formatFileSize(file);
}

return (
Expand Down

0 comments on commit d0debc1

Please sign in to comment.