@pega/cosmos-react-core 7.0.0-build.1.0 → 7.0.0-build.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppShell/AppHeader.styles.js +2 -2
- package/lib/components/AppShell/AppHeader.styles.js.map +1 -1
- package/lib/components/AppShell/AppShell.styles.js +2 -2
- package/lib/components/AppShell/AppShell.styles.js.map +1 -1
- package/lib/components/AppShell/style-utils.js +2 -2
- package/lib/components/AppShell/style-utils.js.map +1 -1
- package/lib/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/components/Avatar/Avatar.js +2 -1
- package/lib/components/Avatar/Avatar.js.map +1 -1
- package/lib/components/Badges/Keyboard.d.ts.map +1 -1
- package/lib/components/Badges/Keyboard.js +9 -8
- package/lib/components/Badges/Keyboard.js.map +1 -1
- package/lib/components/Banner/Banner.d.ts.map +1 -1
- package/lib/components/Banner/Banner.js +2 -1
- package/lib/components/Banner/Banner.js.map +1 -1
- package/lib/components/Button/Button.d.ts.map +1 -1
- package/lib/components/Button/Button.js +70 -10
- package/lib/components/Button/Button.js.map +1 -1
- package/lib/components/DateTime/Input/DateInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateInput.js +3 -6
- package/lib/components/DateTime/Input/DateInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.js +3 -5
- package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
- package/lib/components/DateTime/Input/MonthInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/MonthInput.js +2 -2
- package/lib/components/DateTime/Input/MonthInput.js.map +1 -1
- package/lib/components/DateTime/Input/utils.d.ts +1 -0
- package/lib/components/DateTime/Input/utils.d.ts.map +1 -1
- package/lib/components/DateTime/Input/utils.js +4 -0
- package/lib/components/DateTime/Input/utils.js.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.js +5 -4
- package/lib/components/DateTime/Picker/Calendar.js.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.styles.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.styles.js +2 -1
- package/lib/components/DateTime/Picker/Calendar.styles.js.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.js +31 -6
- package/lib/components/DateTime/Picker/DatePicker.js.map +1 -1
- package/lib/components/DateTime/utils.d.ts +4 -0
- package/lib/components/DateTime/utils.d.ts.map +1 -1
- package/lib/components/DateTime/utils.js +8 -0
- package/lib/components/DateTime/utils.js.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.d.ts +1 -0
- package/lib/components/FieldGroup/FieldGroupList.d.ts.map +1 -1
- package/lib/components/FieldGroup/FieldGroupList.js +2 -2
- package/lib/components/FieldGroup/FieldGroupList.js.map +1 -1
- package/lib/components/File/FileDisplay.d.ts +1 -1
- package/lib/components/File/FileDisplay.d.ts.map +1 -1
- package/lib/components/File/FileDisplay.js +2 -2
- package/lib/components/File/FileDisplay.js.map +1 -1
- package/lib/components/File/FileDisplayList.d.ts +8 -0
- package/lib/components/File/FileDisplayList.d.ts.map +1 -0
- package/lib/components/File/FileDisplayList.js +8 -0
- package/lib/components/File/FileDisplayList.js.map +1 -0
- package/lib/components/File/FileInput.d.ts +7 -2
- package/lib/components/File/FileInput.d.ts.map +1 -1
- package/lib/components/File/FileInput.js +44 -28
- package/lib/components/File/FileInput.js.map +1 -1
- package/lib/components/File/FileItem.d.ts +19 -7
- package/lib/components/File/FileItem.d.ts.map +1 -1
- package/lib/components/File/FileItem.js +107 -32
- package/lib/components/File/FileItem.js.map +1 -1
- package/lib/components/File/FileList.d.ts +14 -0
- package/lib/components/File/FileList.d.ts.map +1 -0
- package/lib/components/File/FileList.js +22 -0
- package/lib/components/File/FileList.js.map +1 -0
- package/lib/components/File/index.d.ts +4 -0
- package/lib/components/File/index.d.ts.map +1 -1
- package/lib/components/File/index.js +2 -0
- package/lib/components/File/index.js.map +1 -1
- package/lib/components/FormField/FormField.js +2 -2
- package/lib/components/FormField/FormField.js.map +1 -1
- package/lib/components/HTML/HTML.js +2 -2
- package/lib/components/HTML/HTML.js.map +1 -1
- package/lib/components/Icon/Icon.d.ts.map +1 -1
- package/lib/components/Icon/Icon.js +1 -1
- package/lib/components/Icon/Icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-down.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-down.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-down.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-left.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-left.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-left.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-down.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-down.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-left.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-left.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-right.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-right.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-up.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-micro-up.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-right.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-right.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-right.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-up.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/arrow-up.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/arrow-up.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-down.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-down.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/caret-down.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-left.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-left.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/caret-left.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-right.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-right.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/caret-right.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-up.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/caret-up.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/caret-up.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/case-solid.icon.d.ts +1 -1
- package/lib/components/Icon/streamline-icons/case-solid.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/case-solid.icon.js +2 -2
- package/lib/components/Icon/streamline-icons/case-solid.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/clipboard-pencil-solid.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/clipboard-pencil-solid.icon.js +2 -2
- package/lib/components/Icon/streamline-icons/clipboard-pencil-solid.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/clock-solid.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/clock-solid.icon.js +2 -2
- package/lib/components/Icon/streamline-icons/clock-solid.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/disc-stack-solid.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/disc-stack-solid.icon.js +2 -2
- package/lib/components/Icon/streamline-icons/disc-stack-solid.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/drag.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/drag.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/information-solid.icon.d.ts +5 -0
- package/lib/components/Icon/streamline-icons/information-solid.icon.d.ts.map +1 -0
- package/lib/components/Icon/streamline-icons/information-solid.icon.js +7 -0
- package/lib/components/Icon/streamline-icons/information-solid.icon.js.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-down.icon.d.ts +5 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-down.icon.d.ts.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-down.icon.js +7 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-down.icon.js.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-left.icon.d.ts +5 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-left.icon.d.ts.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-left.icon.js +7 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-left.icon.js.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-right.icon.d.ts +5 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-right.icon.d.ts.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-right.icon.js +7 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-right.icon.js.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-up.icon.d.ts +5 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-up.icon.d.ts.map +1 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-up.icon.js +7 -0
- package/lib/components/Icon/streamline-icons/micro-arrow-up.icon.js.map +1 -0
- package/lib/components/Icon/streamline-icons/minus.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/minus.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/minus.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/open.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/open.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/open.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/plus.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/plus.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/plus.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/rule-library-solid.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/rule-library-solid.icon.js +2 -2
- package/lib/components/Icon/streamline-icons/rule-library-solid.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/search-analytics-solid.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/search-analytics-solid.icon.js +2 -2
- package/lib/components/Icon/streamline-icons/search-analytics-solid.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/times.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/times.icon.js +1 -1
- package/lib/components/Icon/streamline-icons/times.icon.js.map +1 -1
- package/lib/components/Icon/streamline-icons/warn-solid.icon.d.ts.map +1 -1
- package/lib/components/Icon/streamline-icons/warn-solid.icon.js +2 -2
- package/lib/components/Icon/streamline-icons/warn-solid.icon.js.map +1 -1
- package/lib/components/Icon/streamlineIconNames.d.ts +1 -1
- package/lib/components/Icon/streamlineIconNames.d.ts.map +1 -1
- package/lib/components/Icon/streamlineIconNames.js +5 -0
- package/lib/components/Icon/streamlineIconNames.js.map +1 -1
- package/lib/components/Label/Label.js +2 -2
- package/lib/components/Label/Label.js.map +1 -1
- package/lib/components/Lightbox/Lightbox.d.ts.map +1 -1
- package/lib/components/Lightbox/Lightbox.js +8 -6
- package/lib/components/Lightbox/Lightbox.js.map +1 -1
- package/lib/components/Link/Link.d.ts.map +1 -1
- package/lib/components/Link/Link.js +13 -6
- package/lib/components/Link/Link.js.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.js +1 -1
- package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.styles.d.ts.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.styles.js +1 -4
- package/lib/components/ListToolbar/ListToolbar.styles.js.map +1 -1
- package/lib/components/Location/CurrentLocationButton.d.ts +12 -6
- package/lib/components/Location/CurrentLocationButton.d.ts.map +1 -1
- package/lib/components/Location/CurrentLocationButton.js +3 -1
- package/lib/components/Location/CurrentLocationButton.js.map +1 -1
- package/lib/components/Location/LocationInput.d.ts +5 -0
- package/lib/components/Location/LocationInput.d.ts.map +1 -1
- package/lib/components/Location/LocationInput.js +138 -39
- package/lib/components/Location/LocationInput.js.map +1 -1
- package/lib/components/Location/LocationView.d.ts +1 -3
- package/lib/components/Location/LocationView.d.ts.map +1 -1
- package/lib/components/Location/LocationView.js +38 -21
- package/lib/components/Location/LocationView.js.map +1 -1
- package/lib/components/Location/index.d.ts +1 -0
- package/lib/components/Location/index.d.ts.map +1 -1
- package/lib/components/Location/index.js +1 -0
- package/lib/components/Location/index.js.map +1 -1
- package/lib/components/Location/types.d.ts +7 -0
- package/lib/components/Location/types.d.ts.map +1 -1
- package/lib/components/Location/types.js.map +1 -1
- package/lib/components/Location/utils.d.ts +28 -9
- package/lib/components/Location/utils.d.ts.map +1 -1
- package/lib/components/Location/utils.js +157 -1
- package/lib/components/Location/utils.js.map +1 -1
- package/lib/components/Menu/FlyoutMenuList.d.ts.map +1 -1
- package/lib/components/Menu/FlyoutMenuList.js +1 -1
- package/lib/components/Menu/FlyoutMenuList.js.map +1 -1
- package/lib/components/Menu/Menu.styles.d.ts.map +1 -1
- package/lib/components/Menu/Menu.styles.js +3 -3
- package/lib/components/Menu/Menu.styles.js.map +1 -1
- package/lib/components/Modal/Modal.styles.d.ts.map +1 -1
- package/lib/components/Modal/Modal.styles.js +24 -3
- package/lib/components/Modal/Modal.styles.js.map +1 -1
- package/lib/components/MultiStepForm/HorizontalFormProgress.d.ts.map +1 -1
- package/lib/components/MultiStepForm/HorizontalFormProgress.js +1 -1
- package/lib/components/MultiStepForm/HorizontalFormProgress.js.map +1 -1
- package/lib/components/PageTemplates/CategorySubPage.styles.d.ts.map +1 -1
- package/lib/components/PageTemplates/CategorySubPage.styles.js +1 -2
- package/lib/components/PageTemplates/CategorySubPage.styles.js.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.d.ts.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.js +1 -1
- package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
- package/lib/components/Phone/PhoneInput.d.ts.map +1 -1
- package/lib/components/Phone/PhoneInput.js +8 -3
- package/lib/components/Phone/PhoneInput.js.map +1 -1
- package/lib/components/Progress/Progress.styles.js +2 -2
- package/lib/components/Progress/Progress.styles.js.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.js +2 -2
- package/lib/components/RadioCheck/RadioCheck.js.map +1 -1
- package/lib/components/Switch/Switch.js +2 -2
- package/lib/components/Switch/Switch.js.map +1 -1
- package/lib/hooks/useActiveDescendant.d.ts.map +1 -1
- package/lib/hooks/useActiveDescendant.js +2 -2
- package/lib/hooks/useActiveDescendant.js.map +1 -1
- package/lib/hooks/useArrows.d.ts.map +1 -1
- package/lib/hooks/useArrows.js +3 -11
- package/lib/hooks/useArrows.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +8 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/hooks/useScrollStick.d.ts +3 -3
- package/lib/hooks/useScrollStick.d.ts.map +1 -1
- package/lib/hooks/useScrollStick.js +6 -5
- package/lib/hooks/useScrollStick.js.map +1 -1
- package/lib/i18n/default.d.ts +8 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +10 -2
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +8 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/styles/mixins.d.ts +2 -0
- package/lib/styles/mixins.d.ts.map +1 -0
- package/lib/styles/mixins.js +8 -0
- package/lib/styles/mixins.js.map +1 -0
- package/lib/styles/utils.d.ts +11 -5
- package/lib/styles/utils.d.ts.map +1 -1
- package/lib/styles/utils.js +28 -12
- package/lib/styles/utils.js.map +1 -1
- package/lib/utils/getFocusables.d.ts +1 -0
- package/lib/utils/getFocusables.d.ts.map +1 -1
- package/lib/utils/getFocusables.js +2 -1
- package/lib/utils/getFocusables.js.map +1 -1
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -2
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/utils/sameOrigin.d.ts +0 -7
- package/lib/utils/sameOrigin.d.ts.map +0 -1
- package/lib/utils/sameOrigin.js +0 -25
- package/lib/utils/sameOrigin.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDisplay.js","sourceRoot":"","sources":["../../../src/components/File/FileDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAsBlC,MAAM,WAAW,GAAuD,UAAU,CAChF,SAAS,WAAW,CAClB,EACE,WAAW,EACX,KAAK,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,UAAU,EACV,GAAG,SAAS,EACsB,EACpC,GAA4B;IAE5B,IAAI,OAAO,KAAK,MAAM,IAAI,CAAC,KAAK,EAAE;QAChC,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,CAAC,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC,CAAC,KAAC,OAAO,KAAG,GACtC,CACR,CAAC;KACH;IAED,IAAI,OAAO,KAAK,MAAM;QACpB,OAAO,CACL,KAAC,IAAI,IAAC,GAAG,EAAE,GAA6B,KAAM,SAAS,EAAE,IAAI,EAAE,KAAK,YACjE,WAAW,IAAI,KAAK,GAChB,CACR,CAAC;IAEJ,OAAO,CACL,KAAC,QAAQ,OACH,SAAS,EACb,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"FileDisplay.js","sourceRoot":"","sources":["../../../src/components/File/FileDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAsBlC,MAAM,WAAW,GAAuD,UAAU,CAChF,SAAS,WAAW,CAClB,EACE,EAAE,EACF,WAAW,EACX,KAAK,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,UAAU,EACV,GAAG,SAAS,EACsB,EACpC,GAA4B;IAE5B,IAAI,OAAO,KAAK,MAAM,IAAI,CAAC,KAAK,EAAE;QAChC,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,CAAC,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC,CAAC,KAAC,OAAO,KAAG,GACtC,CACR,CAAC;KACH;IAED,IAAI,OAAO,KAAK,MAAM;QACpB,OAAO,CACL,KAAC,IAAI,IAAC,GAAG,EAAE,GAA6B,KAAM,SAAS,EAAE,IAAI,EAAE,KAAK,YACjE,WAAW,IAAI,KAAK,GAChB,CACR,CAAC;IAEJ,OAAO,CACL,KAAC,QAAQ,OACH,SAAS,EACb,EAAE,EAAE,EAAE,EACN,GAAG,EAAE,GAA0B,EAC/B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,EACvC,IAAI,EAAE,WAAW,IAAI,KAAK,EAC1B,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,GACpB,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { FunctionComponent, PropsWithoutRef, Ref } from 'react';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport Link from '../Link';\nimport NoValue from '../NoValue/NoValue';\n\nimport FileItem from './FileItem';\nimport type { FileItemProps } from './FileItem';\n\nexport interface FileDisplayProps\n extends Pick<FileItemProps, 'id' | 'onPreview' | 'onDownload'>,\n BaseProps,\n NoChildrenProp {\n /** URL address */\n value?: string;\n /** The text to be displayed. */\n displayText?: string;\n /**\n * Display value either as file, link only or textual representation.\n * @default 'file'\n */\n variant?: 'file' | 'link' | 'text';\n /** Thumbnail image. */\n thumbnail?: string;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement | HTMLAnchorElement | HTMLSpanElement>;\n}\n\nconst FileDisplay: FunctionComponent<FileDisplayProps & ForwardProps> = forwardRef(\n function FileDisplay(\n {\n id,\n displayText,\n value,\n variant,\n thumbnail,\n onPreview,\n onDownload,\n ...restProps\n }: PropsWithoutRef<FileDisplayProps>,\n ref: FileDisplayProps['ref']\n ) {\n if (variant === 'text' || !value) {\n return (\n <span ref={ref} {...restProps}>\n {value ? displayText || value : <NoValue />}\n </span>\n );\n }\n\n if (variant === 'link')\n return (\n <Link ref={ref as Ref<HTMLAnchorElement>} {...restProps} href={value}>\n {displayText || value}\n </Link>\n );\n\n return (\n <FileItem\n {...restProps}\n id={id}\n ref={ref as Ref<HTMLDivElement>}\n format={value.split('.').pop() ?? value}\n name={displayText || value}\n thumbnail={thumbnail}\n onDownload={onDownload}\n onPreview={onPreview}\n />\n );\n }\n);\n\nexport default FileDisplay;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NoChildrenProp, OmitStrict, WithAttributes } from '../../types';
|
|
2
|
+
import type { FileDisplayProps } from './FileDisplay';
|
|
3
|
+
export type FileDisplayListProps = WithAttributes<'div', Pick<FileDisplayProps, 'variant'> & NoChildrenProp & {
|
|
4
|
+
items: OmitStrict<FileDisplayProps, 'variant'>[];
|
|
5
|
+
}>;
|
|
6
|
+
declare const FileDisplayList: import("react").ForwardRefExoticComponent<Omit<FileDisplayListProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export default FileDisplayList;
|
|
8
|
+
//# sourceMappingURL=FileDisplayList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileDisplayList.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileDisplayList.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAc,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAC/C,KAAK,EACL,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,GAC/B,cAAc,GAAG;IACf,KAAK,EAAE,UAAU,CAAC,gBAAgB,EAAE,SAAS,CAAC,EAAE,CAAC;CAClD,CACJ,CAAC;AAEF,QAAA,MAAM,eAAe,8HAYnB,CAAC;AAEH,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import FileList from './FileList';
|
|
4
|
+
const FileDisplayList = forwardRef(function FileDisplayList({ variant, items, ...restProps }, ref) {
|
|
5
|
+
return (_jsx(FileList, { ...restProps, type: 'display', items: items.map(item => ({ ...item, variant })), ref: ref }));
|
|
6
|
+
});
|
|
7
|
+
export default FileDisplayList;
|
|
8
|
+
//# sourceMappingURL=FileDisplayList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileDisplayList.js","sourceRoot":"","sources":["../../../src/components/File/FileDisplayList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAMnC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAUlC,MAAM,eAAe,GAAG,UAAU,CAGhC,SAAS,eAAe,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,GAAG;IAC9D,OAAO,CACL,KAAC,QAAQ,OACH,SAAS,EACb,IAAI,EAAC,SAAS,EACd,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,EAChD,GAAG,EAAE,GAAG,GACR,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport type { NoChildrenProp, OmitStrict, RefElement, WithAttributes } from '../../types';\n\nimport type { FileDisplayProps } from './FileDisplay';\nimport FileList from './FileList';\n\nexport type FileDisplayListProps = WithAttributes<\n 'div',\n Pick<FileDisplayProps, 'variant'> &\n NoChildrenProp & {\n items: OmitStrict<FileDisplayProps, 'variant'>[];\n }\n>;\n\nconst FileDisplayList = forwardRef<\n RefElement<FileDisplayListProps>,\n PropsWithoutRef<FileDisplayListProps>\n>(function FileDisplayList({ variant, items, ...restProps }, ref) {\n return (\n <FileList\n {...restProps}\n type='display'\n items={items.map(item => ({ ...item, variant }))}\n ref={ref}\n />\n );\n});\n\nexport default FileDisplayList;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FunctionComponent, Ref } from 'react';
|
|
2
2
|
import type { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';
|
|
3
3
|
import type { FormControlProps } from '../FormControl';
|
|
4
|
-
import type {
|
|
4
|
+
import type { FileItemProps } from './FileItem';
|
|
5
5
|
export interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {
|
|
6
6
|
/** Called when files are added either via the input or drop zone. */
|
|
7
7
|
onFilesAdded?: (files: File[]) => void;
|
|
@@ -13,7 +13,12 @@ export interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {
|
|
|
13
13
|
*/
|
|
14
14
|
multiple?: boolean;
|
|
15
15
|
/** An array of files that have been uploaded. */
|
|
16
|
-
files?:
|
|
16
|
+
files?: FileItemProps[];
|
|
17
|
+
/**
|
|
18
|
+
* Specify allowed file types.
|
|
19
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept}
|
|
20
|
+
*/
|
|
21
|
+
accept?: string | string[];
|
|
17
22
|
/**
|
|
18
23
|
* Sets DOM id for the control and associates label element via 'for' attribute.
|
|
19
24
|
* If an id is not pass, a random id will be generated for any render.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileInput.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAA2C,MAAM,OAAO,CAAC;AAI7F,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,cAAc,EAEd,UAAU,EACX,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"FileInput.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAA2C,MAAM,OAAO,CAAC;AAI7F,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,cAAc,EAEd,UAAU,EACX,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAShD,MAAM,WAAW,cAAe,SAAQ,SAAS,EAAE,cAAc,EAAE,UAAU;IAC3E,qEAAqE;IACrE,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iDAAiD;IACjD,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,EAAE,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC5B,oDAAoD;IACpD,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,2DAA2D;IAC3D,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClC,uCAAuC;IACvC,WAAW,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC9C,6GAA6G;IAC7G,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,+FAA+F;IAC/F,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAChC,8EAA8E;IAC9E,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACpD,sEAAsE;IACtE,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B;AAED,eAAO,MAAM,cAAc;cAAmC,OAAO;SAoBpE,CAAC;AAIF,eAAO,MAAM,eAAe,wMAc3B,CAAC;;;;AAgLF,wBAA2D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useCallback, useState } from 'react';
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
4
|
import { hideVisually } from 'polished';
|
|
5
|
-
import { useConsolidatedRef, useI18n, useUID, useDirection, useTestIds
|
|
5
|
+
import { useConsolidatedRef, useI18n, useUID, useDirection, useTestIds } from '../../hooks';
|
|
6
6
|
import FormControl from '../FormControl';
|
|
7
7
|
import { defaultThemeProp } from '../../theme';
|
|
8
8
|
import Flex from '../Flex';
|
|
@@ -11,23 +11,25 @@ import Icon, { registerIcon } from '../Icon';
|
|
|
11
11
|
import * as paperClipIcon from '../Icon/icons/paper-clip.icon';
|
|
12
12
|
import FormField from '../FormField';
|
|
13
13
|
import Grid from '../Grid';
|
|
14
|
-
import { withTestIds } from '../../utils';
|
|
15
|
-
import FileUploadItem from './FileUploadItem';
|
|
14
|
+
import { getFocusables, withTestIds } from '../../utils';
|
|
16
15
|
import { getFileInputTestIds } from './File.test-ids';
|
|
16
|
+
import FileList from './FileList';
|
|
17
|
+
import FileItem from './FileItem';
|
|
17
18
|
registerIcon(paperClipIcon);
|
|
18
|
-
export const StyledDropZone = styled(FormControl)(({ dragOver, theme }) => {
|
|
19
|
+
export const StyledDropZone = styled(FormControl)(({ dragOver, theme: { base: { spacing }, components } }) => {
|
|
19
20
|
return css `
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
padding: calc(2 * ${spacing});
|
|
22
|
+
height: ${components.input.height};
|
|
23
|
+
border-style: dashed;
|
|
24
|
+
cursor: pointer;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
${dragOver &&
|
|
26
27
|
css `
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
border-style: solid;
|
|
29
|
+
`}
|
|
30
|
+
`;
|
|
30
31
|
});
|
|
32
|
+
StyledDropZone.defaultProps = defaultThemeProp;
|
|
31
33
|
export const StyledFileInput = styled.div(({ theme }) => {
|
|
32
34
|
return css `
|
|
33
35
|
position: relative;
|
|
@@ -39,10 +41,6 @@ export const StyledFileInput = styled.div(({ theme }) => {
|
|
|
39
41
|
input:enabled:focus + ${StyledDropZone} {
|
|
40
42
|
box-shadow: ${theme.components['form-control'][':focus']['box-shadow']};
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
input[hidden] + ${StyledDropZone} {
|
|
44
|
-
display: none;
|
|
45
|
-
}
|
|
46
44
|
`;
|
|
47
45
|
});
|
|
48
46
|
StyledFileInput.defaultProps = defaultThemeProp;
|
|
@@ -52,13 +50,18 @@ const StyledInteractiveText = styled.span(({ theme }) => {
|
|
|
52
50
|
`;
|
|
53
51
|
});
|
|
54
52
|
StyledInteractiveText.defaultProps = defaultThemeProp;
|
|
53
|
+
const StyledSingleFileWrapper = styled.div `
|
|
54
|
+
display: contents;
|
|
55
|
+
`;
|
|
55
56
|
const FileInput = forwardRef(function FileInput(props, ref) {
|
|
56
57
|
const uid = useUID();
|
|
57
|
-
const { testId, id = uid, label, labelHidden, info, required = false, disabled = false, files, onFilesAdded, multiple = false, status, additionalInfo, ...restProps } = props;
|
|
58
|
-
const { base: { 'content-width': { md } } } = useTheme();
|
|
58
|
+
const { testId, id = uid, label, labelHidden, info, required = false, disabled = false, files, onFilesAdded, multiple = false, status, additionalInfo, accept, ...restProps } = props;
|
|
59
59
|
const testIds = useTestIds(testId, getFileInputTestIds);
|
|
60
60
|
const icon = _jsx(Icon, { name: 'paper-clip' });
|
|
61
61
|
const inputRef = useConsolidatedRef(ref);
|
|
62
|
+
const fileItemListRef = useRef();
|
|
63
|
+
// Tracks whether at least one file is uploaded -- used for updating the focus to DropZone when the files are deleted
|
|
64
|
+
const isFilesAdded = useRef(false);
|
|
62
65
|
const onChange = useCallback((e) => {
|
|
63
66
|
if (e.target.files) {
|
|
64
67
|
onFilesAdded?.(Array.from(e.target.files));
|
|
@@ -77,7 +80,8 @@ const FileInput = forwardRef(function FileInput(props, ref) {
|
|
|
77
80
|
const t = useI18n();
|
|
78
81
|
const [dragOver, setDragOver] = useState(false);
|
|
79
82
|
const { ltr, rtl } = useDirection();
|
|
80
|
-
const
|
|
83
|
+
const hideFileInput = !multiple && files && files.length > 0;
|
|
84
|
+
const fileInput = (_jsxs(StyledFileInput, { children: [_jsx("input", { "data-testid": testIds.control, ...restProps, ref: inputRef, type: 'file', id: id, disabled: disabled, onChange: onChange, multiple: multiple, accept: Array.isArray(accept) ? accept.join(',') : accept }), _jsxs(Flex, { container: { alignItems: 'center', justify: 'center' }, item: { grow: 1 }, as: StyledDropZone, dragOver: dragOver, onClick: () => {
|
|
81
85
|
inputRef.current?.focus();
|
|
82
86
|
inputRef.current?.click();
|
|
83
87
|
}, onDragOver: (e) => {
|
|
@@ -89,14 +93,26 @@ const FileInput = forwardRef(function FileInput(props, ref) {
|
|
|
89
93
|
}, children: [ltr && icon, _jsxs(Text, { variant: 'primary', children: ["\u00A0", t('file_upload_text_main', [
|
|
90
94
|
_jsx(StyledInteractiveText, { children: t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one') })
|
|
91
95
|
]), "\u00A0"] }), rtl && icon] })] }));
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
const fileItemList = hideFileInput ? (_jsx(StyledSingleFileWrapper, { "data-testid": testIds.files, ref: element => {
|
|
97
|
+
if (element)
|
|
98
|
+
fileItemListRef.current = element;
|
|
99
|
+
}, children: _jsx(FileItem, { ...files[0] }) })) : (_jsx(FileList, { type: 'item', items: files ?? [], "data-testid": testIds.files, ref: element => {
|
|
100
|
+
if (element)
|
|
101
|
+
fileItemListRef.current = element;
|
|
102
|
+
} }));
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (files && files.length > 0 && !isFilesAdded.current)
|
|
105
|
+
isFilesAdded.current = true;
|
|
106
|
+
else if (files?.length === 0 && isFilesAdded.current) {
|
|
107
|
+
isFilesAdded.current = false;
|
|
108
|
+
inputRef.current?.focus();
|
|
109
|
+
}
|
|
110
|
+
if (hideFileInput && fileItemListRef.current) {
|
|
111
|
+
getFocusables(fileItemListRef.current)[0]?.focus();
|
|
112
|
+
}
|
|
113
|
+
}, [files]);
|
|
114
|
+
const renderElement = hideFileInput ? fileItemList : fileInput;
|
|
115
|
+
return (_jsxs(Grid, { container: { rowGap: hideFileInput ? undefined : 1 }, children: [label ? (_jsx(FormField, { testId: testIds, label: label, labelHidden: labelHidden, id: id, info: info, required: required, disabled: !hideFileInput && disabled, status: status, additionalInfo: additionalInfo, children: renderElement })) : (renderElement), !hideFileInput && fileItemList] }));
|
|
100
116
|
});
|
|
101
117
|
export default withTestIds(FileInput, getFileInputTestIds);
|
|
102
118
|
//# sourceMappingURL=FileInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileInput.js","sourceRoot":"","sources":["../../../src/components/File/FileInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AASxC,OAAO,EACL,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,QAAQ,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAC/D,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,YAAY,CAAC,aAAa,CAAC,CAAC;AAyC5B,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,CAAwB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;IAC/F,OAAO,GAAG,C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AAS,EAAE;oBACT,GAAG,EAAE,CAAC;oBACN,IAAI,EAAE,gCAAgC,EAAE,iBAAiB;iBAC1D,EACD,EAAE,EAAC,IAAI,YAEN,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;oBACzB,MAAM,GAAG,GACP,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;oBAEjF,4IAA4I;oBAC5I,OAAO,KAAC,cAAc,OAAe,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,IAAlD,GAAG,CAAmD,CAAC;gBACrF,CAAC,CAAC,GACG,CACR,IACI,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useState } from 'react';\nimport type { FunctionComponent, Ref, ChangeEvent, PropsWithoutRef, DragEvent } from 'react';\nimport styled, { css } from 'styled-components';\nimport { hideVisually } from 'polished';\n\nimport type {\n BaseProps,\n ForwardProps,\n NoChildrenProp,\n PropsWithDefaults,\n TestIdProp\n} from '../../types';\nimport {\n useConsolidatedRef,\n useI18n,\n useUID,\n useDirection,\n useTestIds,\n useTheme\n} from '../../hooks';\nimport FormControl from '../FormControl';\nimport type { FormControlProps } from '../FormControl';\nimport { defaultThemeProp } from '../../theme';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport Icon, { registerIcon } from '../Icon';\nimport * as paperClipIcon from '../Icon/icons/paper-clip.icon';\nimport FormField from '../FormField';\nimport Grid from '../Grid';\nimport { withTestIds } from '../../utils';\n\nimport FileUploadItem from './FileUploadItem';\nimport type { FileUploadItemProps } from './FileUploadItem';\nimport { getFileInputTestIds } from './File.test-ids';\n\nregisterIcon(paperClipIcon);\n\ntype FileInputPropsWithDefaults = PropsWithDefaults<FileInputProps>;\n\nexport interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** Called when files are added either via the input or drop zone. */\n onFilesAdded?: (files: File[]) => void;\n /**\n * Allow multiple files to be selected from the OS specific file browser.\n * NOTE: This does not restrict multiple files from being added via drag and drop.\n * Restrict multi file drag and drop via onFilesAdded and custom info message.\n * @default false\n */\n multiple?: boolean;\n /** An array of files that have been uploaded. */\n files?: FileUploadItemProps[];\n /**\n * Sets DOM id for the control and associates label element via 'for' attribute.\n * If an id is not pass, a random id will be generated for any render.\n */\n id?: FormControlProps['id'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref for the input element within the component's dom structure. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport const StyledDropZone = styled(FormControl)<{ dragOver: boolean }>(({ dragOver, theme }) => {\n return css`\n padding: calc(2 * ${theme.base.spacing});\n min-height: 4rem;\n border-style: dashed;\n cursor: pointer;\n\n ${dragOver &&\n css`\n border-style: solid;\n `}\n `;\n});\n\nexport const StyledFileInput = styled.div<FileInputPropsWithDefaults & ForwardProps>(\n ({ theme }) => {\n return css`\n position: relative;\n\n input {\n ${hideVisually}\n }\n\n input:enabled:focus + ${StyledDropZone} {\n box-shadow: ${theme.components['form-control'][':focus']['box-shadow']};\n }\n\n input[hidden] + ${StyledDropZone} {\n display: none;\n }\n `;\n }\n);\n\nStyledFileInput.defaultProps = defaultThemeProp;\n\nconst StyledInteractiveText = styled.span(({ theme }) => {\n return css`\n color: ${theme.base.palette.interactive};\n `;\n});\n\nStyledInteractiveText.defaultProps = defaultThemeProp;\n\nconst FileInput: FunctionComponent<FileInputProps & ForwardProps> = forwardRef(function FileInput(\n props: PropsWithoutRef<FileInputProps>,\n ref: FileInputProps['ref']\n) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n label,\n labelHidden,\n info,\n required = false,\n disabled = false,\n files,\n onFilesAdded,\n multiple = false,\n status,\n additionalInfo,\n ...restProps\n } = props;\n\n const {\n base: {\n 'content-width': { md }\n }\n } = useTheme();\n\n const testIds = useTestIds(testId, getFileInputTestIds);\n\n const icon = <Icon name='paper-clip' />;\n const inputRef = useConsolidatedRef(ref);\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) {\n onFilesAdded?.(Array.from(e.target.files));\n }\n /**\n * WHY are we doing this?\n * We are not working with the \"value\" prop of the input but rather the File instances that are created.\n * The consumer of this component should manage an array or File(s) and allow for a user to remove a selected file.\n * Since we can not modify the input value of files for browser security reasons,\n * and since setting the files property is less than ideal, we reset/toggle the input to a fresh state after a render.\n * This enables onChange to fire even if the user had just previously selected a file, removed it, and selected it again.\n */\n if (inputRef.current) inputRef.current.value = '';\n },\n [onFilesAdded]\n );\n\n const t = useI18n();\n const [dragOver, setDragOver] = useState(false);\n const { ltr, rtl } = useDirection();\n\n const fileInput = (\n <StyledFileInput>\n <input\n data-testid={testIds.control}\n {...restProps}\n ref={inputRef}\n type='file'\n id={id}\n disabled={disabled}\n onChange={onChange}\n multiple={multiple}\n />\n <Flex\n container={{ alignItems: 'center', justify: 'center' }}\n item={{ grow: 1 }}\n as={StyledDropZone}\n dragOver={dragOver}\n onClick={() => {\n inputRef.current?.focus();\n inputRef.current?.click();\n }}\n onDragOver={(e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n }}\n onDragEnter={() => setDragOver(true)}\n onDragLeave={() => setDragOver(false)}\n onDrop={(e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n setDragOver(false);\n onFilesAdded?.(Array.from(e.dataTransfer.files));\n }}\n >\n {ltr && icon}\n <Text variant='primary'>\n \n {t('file_upload_text_main', [\n <StyledInteractiveText>\n {t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')}\n </StyledInteractiveText>\n ])}\n \n </Text>\n {rtl && icon}\n </Flex>\n </StyledFileInput>\n );\n\n return (\n <Grid container={{ rowGap: 1 }}>\n {label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n required={required}\n disabled={disabled}\n status={status}\n additionalInfo={additionalInfo}\n >\n {fileInput}\n </FormField>\n ) : (\n fileInput\n )}\n {!!files?.length && (\n <Grid\n data-testid={testIds.files}\n container={{\n gap: 1,\n cols: `repeat(auto-fill, minmax(min(${md}, 100%), 1fr));`\n }}\n as='ul'\n >\n {files.map((file, index) => {\n const key =\n file.id ?? (file.File ? `${file.File.name}_${file.File.lastModified}` : index);\n\n // When files is an array of native File objects, all properties (including name) are on the prototype, so spreading will not set any props.\n return <FileUploadItem key={key} {...file} name={file.name} disabled={disabled} />;\n })}\n </Grid>\n )}\n </Grid>\n );\n});\n\nexport default withTestIds(FileInput, getFileInputTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"FileInput.js","sourceRoot":"","sources":["../../../src/components/File/FileInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AASxC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAA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,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO;YAAE,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;aAC/E,IAAI,KAAK,EAAE,MAAM,KAAK,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE;YACpD,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;YAC7B,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;SAC3B;QAED,IAAI,aAAa,IAAI,eAAe,CAAC,OAAO,EAAE;YAC5C,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SACpD;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,MAAM,aAAa,GAAG,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IAE/D,OAAO,CACL,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,aACvD,KAAK,CAAC,CAAC,CAAC,CACP,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,CAAC,aAAa,IAAI,QAAQ,EACpC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,YAE7B,aAAa,GACJ,CACb,CAAC,CAAC,CAAC,CACF,aAAa,CACd,EACA,CAAC,aAAa,IAAI,YAAY,IAC1B,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';\nimport type { FunctionComponent, Ref, ChangeEvent, PropsWithoutRef, DragEvent } from 'react';\nimport styled, { css } from 'styled-components';\nimport { hideVisually } from 'polished';\n\nimport type {\n BaseProps,\n ForwardProps,\n NoChildrenProp,\n PropsWithDefaults,\n TestIdProp\n} from '../../types';\nimport { useConsolidatedRef, useI18n, useUID, useDirection, useTestIds } from '../../hooks';\nimport FormControl from '../FormControl';\nimport type { FormControlProps } from '../FormControl';\nimport { defaultThemeProp } from '../../theme';\nimport Flex from '../Flex';\nimport Text from '../Text';\nimport Icon, { registerIcon } from '../Icon';\nimport * as paperClipIcon from '../Icon/icons/paper-clip.icon';\nimport FormField from '../FormField';\nimport Grid from '../Grid';\nimport { getFocusables, withTestIds } from '../../utils';\n\nimport type { FileItemProps } from './FileItem';\nimport { getFileInputTestIds } from './File.test-ids';\nimport FileList from './FileList';\nimport FileItem from './FileItem';\n\nregisterIcon(paperClipIcon);\n\ntype FileInputPropsWithDefaults = PropsWithDefaults<FileInputProps>;\n\nexport interface FileInputProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** Called when files are added either via the input or drop zone. */\n onFilesAdded?: (files: File[]) => void;\n /**\n * Allow multiple files to be selected from the OS specific file browser.\n * NOTE: This does not restrict multiple files from being added via drag and drop.\n * Restrict multi file drag and drop via onFilesAdded and custom info message.\n * @default false\n */\n multiple?: boolean;\n /** An array of files that have been uploaded. */\n files?: FileItemProps[];\n /**\n * Specify allowed file types.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept}\n */\n accept?: string | string[];\n /**\n * Sets DOM id for the control and associates label element via 'for' attribute.\n * If an id is not pass, a random id will be generated for any render.\n */\n id?: FormControlProps['id'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Sets html name attribute for the underlying control. Useful for mapping to a data field. */\n name?: FormControlProps['name'];\n /** Pass a heading and content to show additional information on the field. */\n additionalInfo?: FormControlProps['additionalInfo'];\n /** Ref for the input element within the component's dom structure. */\n ref?: Ref<HTMLInputElement>;\n}\n\nexport const StyledDropZone = styled(FormControl)<{ dragOver: boolean }>(\n ({\n dragOver,\n theme: {\n base: { spacing },\n components\n }\n }) => {\n return css`\n padding: calc(2 * ${spacing});\n height: ${components.input.height};\n border-style: dashed;\n cursor: pointer;\n\n ${dragOver &&\n css`\n border-style: solid;\n `}\n `;\n }\n);\n\nStyledDropZone.defaultProps = defaultThemeProp;\n\nexport const StyledFileInput = styled.div<FileInputPropsWithDefaults & ForwardProps>(\n ({ theme }) => {\n return css`\n position: relative;\n\n input {\n ${hideVisually}\n }\n\n input:enabled:focus + ${StyledDropZone} {\n box-shadow: ${theme.components['form-control'][':focus']['box-shadow']};\n }\n `;\n }\n);\n\nStyledFileInput.defaultProps = defaultThemeProp;\n\nconst StyledInteractiveText = styled.span(({ theme }) => {\n return css`\n color: ${theme.base.palette.interactive};\n `;\n});\n\nStyledInteractiveText.defaultProps = defaultThemeProp;\n\nconst StyledSingleFileWrapper = styled.div`\n display: contents;\n`;\n\nconst FileInput: FunctionComponent<FileInputProps & ForwardProps> = forwardRef(function FileInput(\n props: PropsWithoutRef<FileInputProps>,\n ref: FileInputProps['ref']\n) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n label,\n labelHidden,\n info,\n required = false,\n disabled = false,\n files,\n onFilesAdded,\n multiple = false,\n status,\n additionalInfo,\n accept,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getFileInputTestIds);\n\n const icon = <Icon name='paper-clip' />;\n const inputRef = useConsolidatedRef(ref);\n const fileItemListRef = useRef<HTMLDivElement>();\n\n // Tracks whether at least one file is uploaded -- used for updating the focus to DropZone when the files are deleted\n const isFilesAdded = useRef(false);\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) {\n onFilesAdded?.(Array.from(e.target.files));\n }\n /**\n * WHY are we doing this?\n * We are not working with the \"value\" prop of the input but rather the File instances that are created.\n * The consumer of this component should manage an array or File(s) and allow for a user to remove a selected file.\n * Since we can not modify the input value of files for browser security reasons,\n * and since setting the files property is less than ideal, we reset/toggle the input to a fresh state after a render.\n * This enables onChange to fire even if the user had just previously selected a file, removed it, and selected it again.\n */\n if (inputRef.current) inputRef.current.value = '';\n },\n [onFilesAdded]\n );\n\n const t = useI18n();\n const [dragOver, setDragOver] = useState(false);\n const { ltr, rtl } = useDirection();\n const hideFileInput = !multiple && files && files.length > 0;\n\n const fileInput = (\n <StyledFileInput>\n <input\n data-testid={testIds.control}\n {...restProps}\n ref={inputRef}\n type='file'\n id={id}\n disabled={disabled}\n onChange={onChange}\n multiple={multiple}\n accept={Array.isArray(accept) ? accept.join(',') : accept}\n />\n <Flex\n container={{ alignItems: 'center', justify: 'center' }}\n item={{ grow: 1 }}\n as={StyledDropZone}\n dragOver={dragOver}\n onClick={() => {\n inputRef.current?.focus();\n inputRef.current?.click();\n }}\n onDragOver={(e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n }}\n onDragEnter={() => setDragOver(true)}\n onDragLeave={() => setDragOver(false)}\n onDrop={(e: DragEvent<HTMLDivElement>) => {\n e.preventDefault();\n setDragOver(false);\n onFilesAdded?.(Array.from(e.dataTransfer.files));\n }}\n >\n {ltr && icon}\n <Text variant='primary'>\n \n {t('file_upload_text_main', [\n <StyledInteractiveText>\n {t(multiple ? 'file_upload_text_multiple' : 'file_upload_text_one')}\n </StyledInteractiveText>\n ])}\n \n </Text>\n {rtl && icon}\n </Flex>\n </StyledFileInput>\n );\n\n const fileItemList = hideFileInput ? (\n <StyledSingleFileWrapper\n data-testid={testIds.files}\n ref={element => {\n if (element) fileItemListRef.current = element;\n }}\n >\n <FileItem {...files[0]} />\n </StyledSingleFileWrapper>\n ) : (\n <FileList\n type='item'\n items={files ?? []}\n data-testid={testIds.files}\n ref={element => {\n if (element) fileItemListRef.current = element;\n }}\n />\n );\n\n useEffect(() => {\n if (files && files.length > 0 && !isFilesAdded.current) isFilesAdded.current = true;\n else if (files?.length === 0 && isFilesAdded.current) {\n isFilesAdded.current = false;\n inputRef.current?.focus();\n }\n\n if (hideFileInput && fileItemListRef.current) {\n getFocusables(fileItemListRef.current)[0]?.focus();\n }\n }, [files]);\n\n const renderElement = hideFileInput ? fileItemList : fileInput;\n\n return (\n <Grid container={{ rowGap: hideFileInput ? undefined : 1 }}>\n {label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n required={required}\n disabled={!hideFileInput && disabled}\n status={status}\n additionalInfo={additionalInfo}\n >\n {renderElement}\n </FormField>\n ) : (\n renderElement\n )}\n {!hideFileInput && fileItemList}\n </Grid>\n );\n});\n\nexport default withTestIds(FileInput, getFileInputTestIds);\n"]}
|
|
@@ -2,18 +2,30 @@ import type { FC, Ref } from 'react';
|
|
|
2
2
|
import type { ForwardProps, BaseProps } from '../../types';
|
|
3
3
|
import type { FileVisualProps } from './FileVisual';
|
|
4
4
|
export interface FileItemProps extends BaseProps {
|
|
5
|
+
/** Unique id for item. */
|
|
6
|
+
id: string;
|
|
5
7
|
/** Name of the file. */
|
|
6
8
|
name: string;
|
|
7
|
-
/** Url of the file. */
|
|
8
|
-
url: string;
|
|
9
9
|
/** A string to be used as an image src for a attachment thumbnail. Falls back to a provided icon or the default attachment icon. */
|
|
10
10
|
thumbnail?: FileVisualProps['thumbnail'];
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/** When passed,
|
|
14
|
-
|
|
11
|
+
/** File extension. Use 'url' for link */
|
|
12
|
+
format?: string;
|
|
13
|
+
/** When passed, will render a single icon button for yet to be or in progress uploads. Use this action to trigger xhr request termination. */
|
|
14
|
+
onCancel?: (id: FileItemProps['id']) => void;
|
|
15
|
+
/** When passed, will render a single icon button or within a MenuButton if other actions are defined. */
|
|
16
|
+
onEdit?: (id: FileItemProps['id']) => void;
|
|
17
|
+
/** When passed, will be called on click of the name. Passes file id as the parameter. */
|
|
18
|
+
onPreview?: (id: FileItemProps['id']) => void;
|
|
19
|
+
/** When passed, will render a single icon button or within a MenuButton if other actions are defined. Passes file id as the parameter. */
|
|
20
|
+
onDownload?: (id: FileItemProps['id']) => void;
|
|
21
|
+
/** When passed, will render a single icon button or within a MenuButton if other actions are defined. */
|
|
22
|
+
onDelete?: (id: FileItemProps['id']) => void;
|
|
23
|
+
/** If the attachment is in an upload state, pass progress as a number between 0-100 representing the percentage of progress. */
|
|
24
|
+
progress?: number;
|
|
25
|
+
/** Set if there is an error uploading the file. Applies error styling to the meta string passed. */
|
|
26
|
+
error?: string;
|
|
15
27
|
/** Ref for the wrapping element. */
|
|
16
|
-
ref?: Ref<
|
|
28
|
+
ref?: Ref<HTMLDivElement>;
|
|
17
29
|
}
|
|
18
30
|
declare const FileItem: FC<FileItemProps & ForwardProps>;
|
|
19
31
|
export default FileItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileItem.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,EAAE,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAMtD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"FileItem.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,EAAE,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAMtD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAU,MAAM,aAAa,CAAC;AAanE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,0BAA0B;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,oIAAoI;IACpI,SAAS,CAAC,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC;IACzC,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8IAA8I;IAC9I,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC7C,yGAAyG;IACzG,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC3C,yFAAyF;IACzF,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC9C,0IAA0I;IAC1I,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC/C,yGAAyG;IACzG,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC7C,gIAAgI;IAChI,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oGAAoG;IACpG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAqFD,QAAA,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,GAAG,YAAY,CAwJ7C,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -1,64 +1,139 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useState } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
4
|
import Text, { StyledText } from '../Text';
|
|
5
5
|
import Icon from '../Icon';
|
|
6
6
|
import Tooltip from '../Tooltip';
|
|
7
7
|
import { defaultThemeProp } from '../../theme';
|
|
8
|
-
import Button
|
|
9
|
-
import
|
|
10
|
-
import
|
|
8
|
+
import Button from '../Button';
|
|
9
|
+
import { useI18n, useElement, useConfiguration } from '../../hooks';
|
|
10
|
+
import Actions from '../Actions';
|
|
11
|
+
import Progress from '../Progress';
|
|
12
|
+
import { StyledProgressRing } from '../Progress/Progress.styles';
|
|
13
|
+
import { formatNumber } from '../Number';
|
|
14
|
+
import Flex from '../Flex';
|
|
11
15
|
import { StyledIconShape } from '../Icon/Icon';
|
|
12
16
|
import { getKindFromMimeType, getMimeTypeFromFile } from './utils';
|
|
13
17
|
import FileVisual, { StyledFileVisual } from './FileVisual';
|
|
14
|
-
const
|
|
18
|
+
const StyledErrorIcon = styled(Icon)(({ theme }) => {
|
|
19
|
+
return css `
|
|
20
|
+
color: ${theme.base.palette.urgent};
|
|
21
|
+
margin-inline-start: calc(0.5 * ${theme.base.spacing});
|
|
22
|
+
`;
|
|
23
|
+
});
|
|
24
|
+
StyledErrorIcon.defaultProps = defaultThemeProp;
|
|
25
|
+
const titleEllipsisStyle = css `
|
|
26
|
+
flex-shrink: 1;
|
|
27
|
+
white-space: nowrap;
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
text-overflow: ellipsis;
|
|
30
|
+
`;
|
|
31
|
+
const StyledPreviewTitle = styled(Button) `
|
|
32
|
+
${titleEllipsisStyle}
|
|
33
|
+
`;
|
|
34
|
+
const StyledTextTitle = styled(Text) `
|
|
35
|
+
${titleEllipsisStyle}
|
|
36
|
+
`;
|
|
37
|
+
const StyledMeta = styled(StyledText)(({ theme, error }) => {
|
|
38
|
+
return css `
|
|
39
|
+
/* min width to show percentage in full */
|
|
40
|
+
min-width: 4ch;
|
|
41
|
+
margin-inline-start: auto;
|
|
42
|
+
${titleEllipsisStyle}
|
|
43
|
+
${error &&
|
|
44
|
+
css `
|
|
45
|
+
color: ${theme.base.palette.urgent};
|
|
46
|
+
`}
|
|
47
|
+
`;
|
|
48
|
+
});
|
|
49
|
+
StyledMeta.defaultProps = defaultThemeProp;
|
|
50
|
+
const StyledActionsWrapper = styled.div(({ meta }) => {
|
|
51
|
+
return css `
|
|
52
|
+
margin-inline-start: ${meta ? 'unset' : 'auto'};
|
|
53
|
+
`;
|
|
54
|
+
});
|
|
55
|
+
StyledActionsWrapper.defaultProps = defaultThemeProp;
|
|
56
|
+
const StyledFileItem = styled.div(({ theme: { base: { palette, 'border-radius': borderRadius, spacing, 'hit-area': { compact } }, components } }) => {
|
|
15
57
|
return css `
|
|
16
58
|
border-radius: calc(0.5 * ${borderRadius});
|
|
17
59
|
border: 0.0625rem solid ${palette['border-line']};
|
|
18
60
|
background-color: ${palette['primary-background']};
|
|
61
|
+
height: ${components.input.height};
|
|
62
|
+
min-width: calc(${components.input.height} + 12ch + 1.5 * ${spacing} + ${compact});
|
|
63
|
+
> ${StyledProgressRing} {
|
|
64
|
+
margin-inline-start: calc(0.5 * ${spacing});
|
|
65
|
+
}
|
|
19
66
|
|
|
20
67
|
> ${StyledFileVisual}, > ${StyledIconShape} {
|
|
21
68
|
border-start-start-radius: inherit;
|
|
22
69
|
border-end-start-radius: inherit;
|
|
23
70
|
border-start-end-radius: 0;
|
|
24
71
|
border-end-end-radius: 0;
|
|
25
|
-
height: ${components.input.height};
|
|
26
72
|
width: ${components.input.height};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
> :is(${StyledFileVisual}, ${StyledIconShape}) + :is(${StyledButtonLink}, ${StyledText}) {
|
|
30
|
-
margin-inline-start: ${spacing};
|
|
31
|
-
width: auto;
|
|
32
|
-
max-width: calc(100% - calc(2 * ${spacing}));
|
|
33
|
-
white-space: nowrap;
|
|
34
|
-
overflow: hidden;
|
|
35
|
-
text-overflow: ellipsis;
|
|
73
|
+
flex-shrink: 0;
|
|
36
74
|
}
|
|
37
75
|
`;
|
|
38
76
|
});
|
|
39
77
|
StyledFileItem.defaultProps = defaultThemeProp;
|
|
40
78
|
const FileItem = forwardRef(function FileItem(props, ref) {
|
|
41
|
-
const {
|
|
79
|
+
const { id, name, thumbnail, format, error, onCancel, onEdit, onPreview, onDownload, onDelete, progress, ...restProps } = props;
|
|
42
80
|
const [thumbnailError, setThumbnailError] = useState(false);
|
|
43
|
-
const [
|
|
81
|
+
const [textTarget, setTextTarget] = useElement();
|
|
82
|
+
const [metaTarget, setMetaTarget] = useElement();
|
|
83
|
+
const { locale } = useConfiguration();
|
|
44
84
|
const t = useI18n();
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
85
|
+
const uploading = typeof progress === 'number' && progress < 100;
|
|
86
|
+
let metaMessage;
|
|
87
|
+
if (uploading) {
|
|
88
|
+
metaMessage = formatNumber(progress, {
|
|
89
|
+
locale,
|
|
90
|
+
options: {
|
|
91
|
+
style: 'unit',
|
|
92
|
+
unit: 'percent',
|
|
93
|
+
maximumFractionDigits: 0
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (error) {
|
|
98
|
+
metaMessage = error;
|
|
99
|
+
}
|
|
100
|
+
const definedActions = [
|
|
101
|
+
{ onClick: onEdit, text: t('edit'), icon: 'pencil' },
|
|
102
|
+
{ onClick: onDownload, text: t('download'), icon: 'download' },
|
|
103
|
+
{ onClick: onDelete, text: t('delete'), icon: 'trash' }
|
|
104
|
+
]
|
|
105
|
+
.filter(action => {
|
|
106
|
+
return !!action.onClick;
|
|
107
|
+
})
|
|
108
|
+
.map(({ text: actiontext, icon, onClick }) => ({
|
|
109
|
+
id: actiontext,
|
|
110
|
+
text: actiontext,
|
|
111
|
+
icon,
|
|
112
|
+
onClick: () => {
|
|
113
|
+
if (onClick)
|
|
114
|
+
onClick(id);
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
let visual;
|
|
118
|
+
if (uploading) {
|
|
119
|
+
visual = _jsx(Progress, { variant: 'ring', placement: 'inline', value: progress });
|
|
120
|
+
}
|
|
121
|
+
else if (error) {
|
|
122
|
+
visual = _jsx(StyledErrorIcon, { name: 'warn-solid' });
|
|
50
123
|
}
|
|
51
|
-
else
|
|
52
|
-
|
|
124
|
+
else {
|
|
125
|
+
visual = (_jsx(FileVisual, { type: format === 'url' ? 'link' : getKindFromMimeType(getMimeTypeFromFile(format ?? '') ?? ''), thumbnail: thumbnailError ? undefined : thumbnail, onThumbnailError: () => {
|
|
126
|
+
setThumbnailError(true);
|
|
127
|
+
} }));
|
|
53
128
|
}
|
|
54
|
-
return (_jsxs(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, "aria-label":
|
|
129
|
+
return (_jsxs(Flex, { as: StyledFileItem, container: {
|
|
130
|
+
pad: [undefined, 0.5, undefined, undefined],
|
|
131
|
+
alignItems: 'center',
|
|
132
|
+
justify: 'start',
|
|
133
|
+
gap: 1
|
|
134
|
+
}, ref: ref, children: [visual, onPreview && !(error || uploading) ? (_jsxs(Button, { ...restProps, as: StyledPreviewTitle, variant: 'link', ref: setTextTarget, onClick: () => {
|
|
135
|
+
onPreview(id);
|
|
136
|
+
}, "aria-label": t('preview_file', [name]), children: [name, format === 'url' && _jsx(Icon, { name: 'open' })] })) : (_jsx(Text, { ...restProps, as: StyledTextTitle, ref: setTextTarget, children: name })), metaMessage && (_jsxs(_Fragment, { children: [_jsx(Text, { as: StyledMeta, variant: 'secondary', error: error && !uploading, ref: setMetaTarget, children: metaMessage }), metaTarget && (_jsx(Tooltip, { target: metaTarget, describeTarget: false, smart: true, children: metaMessage }))] })), (error || uploading) && onCancel && (_jsx(StyledActionsWrapper, { meta: !!metaMessage, children: _jsx(Button, { label: t('cancel'), "aria-label": `${t('cancel')} - ${name}`, variant: 'simple', compact: true, icon: true, onClick: () => onCancel(id), children: _jsx(Icon, { name: 'times' }) }) })), !(error || uploading) && !!definedActions.length && (_jsx(StyledActionsWrapper, { meta: !!metaMessage, children: _jsx(Actions, { items: definedActions, compact: true, iconOnly: true, contextualLabel: name }) })), textTarget && (_jsx(Tooltip, { target: textTarget, smart: true, describeTarget: false, children: name }))] }));
|
|
62
137
|
});
|
|
63
138
|
export default FileItem;
|
|
64
139
|
//# sourceMappingURL=FileItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileItem.js","sourceRoot":"","sources":["../../../src/components/File/FileItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,MAAM,EAAE,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAkB5D,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAC/B,CAAC,EACC,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,EACzD,UAAU,EACX,EACF,EAAE,EAAE;IACH,OAAO,GAAG,CAAA;kCACoB,YAAY;gCACd,OAAO,CAAC,aAAa,CAAC;0BAC5B,OAAO,CAAC,oBAAoB,CAAC;;UAE7C,gBAAgB,OAAO,eA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ACrC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EACjD,gBAAgB,EAAE,GAAG,EAAE;oBACrB,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBAC1B,CAAC,GACD,EACD,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC,CACzB,MAAC,MAAM,OACD,SAAS,EACb,OAAO,EAAC,MAAM,EACd,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,GAAG,EAAE;oBACZ,IAAI,SAAS;wBAAE,SAAS,CAAC,GAAG,CAAC,CAAC;yBACzB,IAAI,UAAU;wBAAE,UAAU,CAAC,GAAG,CAAC,CAAC;gBACvC,CAAC,gBACW,SAAS,aAEpB,IAAI,EACJ,SAAS,IAAI,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,IAC3B,CACV,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,OAAK,SAAS,EAAE,GAAG,EAAE,SAAS,YAChC,IAAI,GACA,CACR,EACD,KAAC,OAAO,IAAC,MAAM,EAAE,MAAM,EAAE,KAAK,kBAC3B,IAAI,GACG,IACL,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useState } from 'react';\nimport type { PropsWithoutRef, FC, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Text, { StyledText } from '../Text';\nimport Icon from '../Icon';\nimport Tooltip from '../Tooltip';\nimport type { ForwardProps, BaseProps } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Button, { StyledButtonLink } from '../Button';\nimport Grid from '../Grid';\nimport { useI18n, useElement } from '../../hooks';\nimport { StyledIconShape } from '../Icon/Icon';\n\nimport { getKindFromMimeType, getMimeTypeFromFile } from './utils';\nimport FileVisual, { StyledFileVisual } from './FileVisual';\nimport type { FileVisualProps } from './FileVisual';\n\nexport interface FileItemProps extends BaseProps {\n /** Name of the file. */\n name: string;\n /** Url of the file. */\n url: string;\n /** A string to be used as an image src for a attachment thumbnail. Falls back to a provided icon or the default attachment icon. */\n thumbnail?: FileVisualProps['thumbnail'];\n /** When passed, it will make the name region to perform open in new tab action. Passes file url as the parameter. */\n onPreview?: (url: FileItemProps['url']) => void;\n /** When passed, it will make the name region to perform download action. Passes file url as the parameter. */\n onDownload?: (url: FileItemProps['url']) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLButtonElement>;\n}\n\nconst StyledFileItem = styled.div(\n ({\n theme: {\n base: { palette, spacing, 'border-radius': borderRadius },\n components\n }\n }) => {\n return css`\n border-radius: calc(0.5 * ${borderRadius});\n border: 0.0625rem solid ${palette['border-line']};\n background-color: ${palette['primary-background']};\n\n > ${StyledFileVisual}, > ${StyledIconShape} {\n border-start-start-radius: inherit;\n border-end-start-radius: inherit;\n border-start-end-radius: 0;\n border-end-end-radius: 0;\n height: ${components.input.height};\n width: ${components.input.height};\n }\n\n > :is(${StyledFileVisual}, ${StyledIconShape}) + :is(${StyledButtonLink}, ${StyledText}) {\n margin-inline-start: ${spacing};\n width: auto;\n max-width: calc(100% - calc(2 * ${spacing}));\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n `;\n }\n);\n\nStyledFileItem.defaultProps = defaultThemeProp;\n\nconst FileItem: FC<FileItemProps & ForwardProps> = forwardRef(function FileItem(\n props: PropsWithoutRef<FileItemProps>,\n ref: FileItemProps['ref']\n) {\n const { name, url, thumbnail, onPreview, onDownload, ...restProps } = props;\n\n const [thumbnailError, setThumbnailError] = useState(false);\n const [target, setTarget] = useElement<HTMLButtonElement | HTMLSpanElement>();\n const t = useI18n();\n\n const type = getMimeTypeFromFile(url);\n const text = name || url;\n\n let ariaLabel: undefined | string;\n\n if (onPreview) {\n ariaLabel = t('open_file_in_new_tab', [text]);\n } else if (onDownload) {\n ariaLabel = t('download_file', [text]);\n }\n\n return (\n <Grid\n as={StyledFileItem}\n container={{ cols: 'auto 1fr', alignItems: 'center', justifyItems: 'start' }}\n ref={ref}\n >\n <FileVisual\n type={getKindFromMimeType(type ?? '')}\n thumbnail={thumbnailError ? undefined : thumbnail}\n onThumbnailError={() => {\n setThumbnailError(true);\n }}\n />\n {onPreview || onDownload ? (\n <Button\n {...restProps}\n variant='link'\n ref={setTarget}\n onClick={() => {\n if (onPreview) onPreview(url);\n else if (onDownload) onDownload(url);\n }}\n aria-label={ariaLabel}\n >\n {text}\n {onPreview && <Icon name='open' />}\n </Button>\n ) : (\n <Text {...restProps} ref={setTarget}>\n {text}\n </Text>\n )}\n <Tooltip target={target} smart>\n {text}\n </Tooltip>\n </Grid>\n );\n});\n\nexport default FileItem;\n"]}
|
|
1
|
+
{"version":3,"file":"FileItem.js","sourceRoot":"","sources":["../../../src/components/File/FileItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,SAAS,C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,SAAS,EAAE,GAAG,EAAE,aAAa,YACrF,WAAW,GACP,EAEN,UAAU,IAAI,CACb,KAAC,OAAO,IAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,kBACtD,WAAW,GACJ,CACX,IACA,CACJ,EAEA,CAAC,KAAK,IAAI,SAAS,CAAC,IAAI,QAAQ,IAAI,CACnC,KAAC,oBAAoB,IAAC,IAAI,EAAE,CAAC,CAAC,WAAW,YACvC,KAAC,MAAM,IACL,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,gBACN,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,EACtC,OAAO,EAAC,QAAQ,EAChB,OAAO,QACP,IAAI,QACJ,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,YAE3B,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACd,GACY,CACxB,EAEA,CAAC,CAAC,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,MAAM,IAAI,CACnD,KAAC,oBAAoB,IAAC,IAAI,EAAE,CAAC,CAAC,WAAW,YACvC,KAAC,OAAO,IAAC,KAAK,EAAE,cAAc,EAAE,OAAO,QAAC,QAAQ,QAAC,eAAe,EAAE,IAAI,GAAI,GACrD,CACxB,EAEA,UAAU,IAAI,CACb,KAAC,OAAO,IAAC,MAAM,EAAE,UAAU,EAAE,KAAK,QAAC,cAAc,EAAE,KAAK,YACrD,IAAI,GACG,CACX,IACI,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef, useState } from 'react';\nimport type { PropsWithoutRef, FC, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Text, { StyledText } from '../Text';\nimport Icon from '../Icon';\nimport Tooltip from '../Tooltip';\nimport type { ForwardProps, BaseProps, Action } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Button from '../Button';\nimport { useI18n, useElement, useConfiguration } from '../../hooks';\nimport Actions from '../Actions';\nimport Progress from '../Progress';\nimport { StyledProgressRing } from '../Progress/Progress.styles';\nimport { formatNumber } from '../Number';\nimport Flex from '../Flex';\nimport { StyledIconShape } from '../Icon/Icon';\n\nimport { getKindFromMimeType, getMimeTypeFromFile } from './utils';\nimport FileVisual, { StyledFileVisual } from './FileVisual';\nimport type { FileVisualProps } from './FileVisual';\n\nexport interface FileItemProps extends BaseProps {\n /** Unique id for item. */\n id: string;\n /** Name of the file. */\n name: string;\n /** A string to be used as an image src for a attachment thumbnail. Falls back to a provided icon or the default attachment icon. */\n thumbnail?: FileVisualProps['thumbnail'];\n /** File extension. Use 'url' for link */\n format?: string;\n /** When passed, will render a single icon button for yet to be or in progress uploads. Use this action to trigger xhr request termination. */\n onCancel?: (id: FileItemProps['id']) => void;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. */\n onEdit?: (id: FileItemProps['id']) => void;\n /** When passed, will be called on click of the name. Passes file id as the parameter. */\n onPreview?: (id: FileItemProps['id']) => void;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. Passes file id as the parameter. */\n onDownload?: (id: FileItemProps['id']) => void;\n /** When passed, will render a single icon button or within a MenuButton if other actions are defined. */\n onDelete?: (id: FileItemProps['id']) => void;\n /** If the attachment is in an upload state, pass progress as a number between 0-100 representing the percentage of progress. */\n progress?: number;\n /** Set if there is an error uploading the file. Applies error styling to the meta string passed. */\n error?: string;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n\nconst StyledErrorIcon = styled(Icon)(({ theme }) => {\n return css`\n color: ${theme.base.palette.urgent};\n margin-inline-start: calc(0.5 * ${theme.base.spacing});\n `;\n});\n\nStyledErrorIcon.defaultProps = defaultThemeProp;\n\nconst titleEllipsisStyle = css`\n flex-shrink: 1;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n`;\n\nconst StyledPreviewTitle = styled(Button)`\n ${titleEllipsisStyle}\n`;\n\nconst StyledTextTitle = styled(Text)`\n ${titleEllipsisStyle}\n`;\n\nconst StyledMeta = styled(StyledText)<{ error: boolean }>(({ theme, error }) => {\n return css`\n /* min width to show percentage in full */\n min-width: 4ch;\n margin-inline-start: auto;\n ${titleEllipsisStyle}\n ${error &&\n css`\n color: ${theme.base.palette.urgent};\n `}\n `;\n});\n\nStyledMeta.defaultProps = defaultThemeProp;\n\nconst StyledActionsWrapper = styled.div<{ meta: boolean }>(({ meta }) => {\n return css`\n margin-inline-start: ${meta ? 'unset' : 'auto'};\n `;\n});\n\nStyledActionsWrapper.defaultProps = defaultThemeProp;\n\nconst StyledFileItem = styled.div(\n ({\n theme: {\n base: {\n palette,\n 'border-radius': borderRadius,\n spacing,\n 'hit-area': { compact }\n },\n components\n }\n }) => {\n return css`\n border-radius: calc(0.5 * ${borderRadius});\n border: 0.0625rem solid ${palette['border-line']};\n background-color: ${palette['primary-background']};\n height: ${components.input.height};\n min-width: calc(${components.input.height} + 12ch + 1.5 * ${spacing} + ${compact});\n > ${StyledProgressRing} {\n margin-inline-start: calc(0.5 * ${spacing});\n }\n\n > ${StyledFileVisual}, > ${StyledIconShape} {\n border-start-start-radius: inherit;\n border-end-start-radius: inherit;\n border-start-end-radius: 0;\n border-end-end-radius: 0;\n width: ${components.input.height};\n flex-shrink: 0;\n }\n `;\n }\n);\n\nStyledFileItem.defaultProps = defaultThemeProp;\n\nconst FileItem: FC<FileItemProps & ForwardProps> = forwardRef(function FileItem(\n props: PropsWithoutRef<FileItemProps>,\n ref: FileItemProps['ref']\n) {\n const {\n id,\n name,\n thumbnail,\n format,\n error,\n onCancel,\n onEdit,\n onPreview,\n onDownload,\n onDelete,\n progress,\n ...restProps\n } = props;\n\n const [thumbnailError, setThumbnailError] = useState(false);\n const [textTarget, setTextTarget] = useElement();\n const [metaTarget, setMetaTarget] = useElement();\n const { locale } = useConfiguration();\n const t = useI18n();\n const uploading = typeof progress === 'number' && progress < 100;\n\n let metaMessage;\n\n if (uploading) {\n metaMessage = formatNumber(progress, {\n locale,\n options: {\n style: 'unit',\n unit: 'percent',\n maximumFractionDigits: 0\n }\n });\n } else if (error) {\n metaMessage = error;\n }\n\n const definedActions: Action[] = [\n { onClick: onEdit, text: t('edit'), icon: 'pencil' },\n { onClick: onDownload, text: t('download'), icon: 'download' },\n { onClick: onDelete, text: t('delete'), icon: 'trash' }\n ]\n .filter(action => {\n return !!action.onClick;\n })\n .map(({ text: actiontext, icon, onClick }) => ({\n id: actiontext,\n text: actiontext,\n icon,\n onClick: () => {\n if (onClick) onClick(id);\n }\n }));\n\n let visual;\n\n if (uploading) {\n visual = <Progress variant='ring' placement='inline' value={progress} />;\n } else if (error) {\n visual = <StyledErrorIcon name='warn-solid' />;\n } else {\n visual = (\n <FileVisual\n type={\n format === 'url' ? 'link' : getKindFromMimeType(getMimeTypeFromFile(format ?? '') ?? '')\n }\n thumbnail={thumbnailError ? undefined : thumbnail}\n onThumbnailError={() => {\n setThumbnailError(true);\n }}\n />\n );\n }\n\n return (\n <Flex\n as={StyledFileItem}\n container={{\n pad: [undefined, 0.5, undefined, undefined],\n alignItems: 'center',\n justify: 'start',\n gap: 1\n }}\n ref={ref}\n >\n {visual}\n\n {onPreview && !(error || uploading) ? (\n <Button\n {...restProps}\n as={StyledPreviewTitle}\n variant='link'\n ref={setTextTarget}\n onClick={() => {\n onPreview(id);\n }}\n aria-label={t('preview_file', [name])}\n >\n {name}\n {format === 'url' && <Icon name='open' />}\n </Button>\n ) : (\n <Text {...restProps} as={StyledTextTitle} ref={setTextTarget}>\n {name}\n </Text>\n )}\n {metaMessage && (\n <>\n <Text as={StyledMeta} variant='secondary' error={error && !uploading} ref={setMetaTarget}>\n {metaMessage}\n </Text>\n\n {metaTarget && (\n <Tooltip target={metaTarget} describeTarget={false} smart>\n {metaMessage}\n </Tooltip>\n )}\n </>\n )}\n\n {(error || uploading) && onCancel && (\n <StyledActionsWrapper meta={!!metaMessage}>\n <Button\n label={t('cancel')}\n aria-label={`${t('cancel')} - ${name}`}\n variant='simple'\n compact\n icon\n onClick={() => onCancel(id)}\n >\n <Icon name='times' />\n </Button>\n </StyledActionsWrapper>\n )}\n\n {!(error || uploading) && !!definedActions.length && (\n <StyledActionsWrapper meta={!!metaMessage}>\n <Actions items={definedActions} compact iconOnly contextualLabel={name} />\n </StyledActionsWrapper>\n )}\n\n {textTarget && (\n <Tooltip target={textTarget} smart describeTarget={false}>\n {name}\n </Tooltip>\n )}\n </Flex>\n );\n});\n\nexport default FileItem;\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PropsWithoutRef } from 'react';
|
|
2
|
+
import type { WithAttributes } from '../../types';
|
|
3
|
+
import type { FileDisplayProps } from './FileDisplay';
|
|
4
|
+
import type { FileItemProps } from './FileItem';
|
|
5
|
+
export type FileListProps = WithAttributes<'div', {
|
|
6
|
+
type: 'display';
|
|
7
|
+
items: FileDisplayProps[];
|
|
8
|
+
} | {
|
|
9
|
+
type: 'item';
|
|
10
|
+
items: FileItemProps[];
|
|
11
|
+
}>;
|
|
12
|
+
declare const FileList: import("react").ForwardRefExoticComponent<PropsWithoutRef<FileListProps> & import("react").RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export default FileList;
|
|
14
|
+
//# sourceMappingURL=FileList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileList.d.ts","sourceRoot":"","sources":["../../../src/components/File/FileList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAG7C,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,aAAa,CAAC;AAK9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD,MAAM,MAAM,aAAa,GAAG,cAAc,CACxC,KAAK,EACH;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB,CACJ,CAAC;AAQF,QAAA,MAAM,QAAQ,2HAkBb,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { useBreakpoint, useConsolidatedRef } from '../../hooks';
|
|
5
|
+
import Grid from '../Grid';
|
|
6
|
+
import { StyledLink } from '../Link';
|
|
7
|
+
import FileDisplay from './FileDisplay';
|
|
8
|
+
import FileItem from './FileItem';
|
|
9
|
+
const StyledFileList = styled(Grid) `
|
|
10
|
+
${StyledLink} + ${StyledLink} {
|
|
11
|
+
margin-inline-start: unset;
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
const FileList = forwardRef(function FileList({ type, items, ...restProps }, ref) {
|
|
15
|
+
const listRef = useConsolidatedRef(ref);
|
|
16
|
+
const isSmallOrAbove = useBreakpoint('sm', { breakpointRef: listRef });
|
|
17
|
+
return (_jsx(Grid, { ...restProps, ref: listRef, container: { gap: 0.5, cols: isSmallOrAbove ? 'repeat(2, 1fr)' : '1fr' }, as: StyledFileList, children: type === 'display'
|
|
18
|
+
? items.map(item => _jsx(FileDisplay, { ...item }, item.id))
|
|
19
|
+
: items.map(item => _jsx(FileItem, { ...item }, item.id)) }));
|
|
20
|
+
});
|
|
21
|
+
export default FileList;
|
|
22
|
+
//# sourceMappingURL=FileList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileList.js","sourceRoot":"","sources":["../../../src/components/File/FileList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIrC,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAclC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAC/B,UAAU,MAAM,UAAU;;;CAG7B,CAAC;AAEF,MAAM,QAAQ,GAAG,UAAU,CACzB,SAAS,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,GAAG;IAClD,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IAEvE,OAAO,CACL,KAAC,IAAI,OACC,SAAS,EACb,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,KAAK,EAAE,EACxE,EAAE,EAAE,cAAc,YAEjB,IAAI,KAAK,SAAS;YACjB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAC,WAAW,OAAmB,IAAI,IAAjB,IAAI,CAAC,EAAE,CAAc,CAAC;YAC5D,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAC,QAAQ,OAAmB,IAAI,IAAjB,IAAI,CAAC,EAAE,CAAc,CAAC,GACtD,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport styled from 'styled-components';\n\nimport type { RefElement, WithAttributes } from '../../types';\nimport { useBreakpoint, useConsolidatedRef } from '../../hooks';\nimport Grid from '../Grid';\nimport { StyledLink } from '../Link';\n\nimport type { FileDisplayProps } from './FileDisplay';\nimport type { FileItemProps } from './FileItem';\nimport FileDisplay from './FileDisplay';\nimport FileItem from './FileItem';\n\nexport type FileListProps = WithAttributes<\n 'div',\n | {\n type: 'display';\n items: FileDisplayProps[];\n }\n | {\n type: 'item';\n items: FileItemProps[];\n }\n>;\n\nconst StyledFileList = styled(Grid)`\n ${StyledLink} + ${StyledLink} {\n margin-inline-start: unset;\n }\n`;\n\nconst FileList = forwardRef<RefElement<FileListProps>, PropsWithoutRef<FileListProps>>(\n function FileList({ type, items, ...restProps }, ref) {\n const listRef = useConsolidatedRef(ref);\n const isSmallOrAbove = useBreakpoint('sm', { breakpointRef: listRef });\n\n return (\n <Grid\n {...restProps}\n ref={listRef}\n container={{ gap: 0.5, cols: isSmallOrAbove ? 'repeat(2, 1fr)' : '1fr' }}\n as={StyledFileList}\n >\n {type === 'display'\n ? items.map(item => <FileDisplay key={item.id} {...item} />)\n : items.map(item => <FileItem key={item.id} {...item} />)}\n </Grid>\n );\n }\n);\n\nexport default FileList;\n"]}
|