@canonical/react-ds-global-form 0.47.0 → 0.48.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/README.md +5 -6
- package/dist/esm/density.css +23 -28
- package/dist/esm/index.css +28 -13
- package/dist/esm/lib/{component → _work_in_progress/component}/ColorField/ColorField.js +2 -2
- package/dist/esm/lib/_work_in_progress/component/ColorField/ColorField.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/component/ColorField/index.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/component/ColorField/types.js.map +1 -0
- package/dist/esm/lib/{component → _work_in_progress/component}/ComboboxField/ComboboxField.js +2 -2
- package/dist/esm/lib/_work_in_progress/component/ComboboxField/ComboboxField.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/component/ComboboxField/index.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/component/ComboboxField/types.js.map +1 -0
- package/dist/esm/lib/{component → _work_in_progress/component}/RatingField/RatingField.js +2 -2
- package/dist/esm/lib/_work_in_progress/component/RatingField/RatingField.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/component/RatingField/index.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/component/RatingField/types.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ColorInput/ColorInput.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ColorInput/index.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ColorInput/types.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/ComboboxInput.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.js +198 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.js +120 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -0
- package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/List.js +16 -4
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/List.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/index.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/types.js.map +1 -0
- package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/ResetButton.js +2 -2
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/ResetButton.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/index.js.map +1 -0
- package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/styles.css +3 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/types.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/common/index.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/constants.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/index.js.map +1 -0
- package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/messages.js +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/messages.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/types.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertValueToItem.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.js +7 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.js +6 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.js +10 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.js +25 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/RatingInput/RatingInput.js.map +1 -0
- package/dist/esm/lib/_work_in_progress/subcomponent/RatingInput/index.js.map +1 -0
- package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/styles.css +7 -7
- package/dist/esm/lib/_work_in_progress/subcomponent/RatingInput/types.js.map +1 -0
- package/dist/esm/lib/common/Wrapper/InvisibleWrapper.js +3 -1
- package/dist/esm/lib/common/Wrapper/InvisibleWrapper.js.map +1 -1
- package/dist/esm/lib/common/Wrapper/ToggleWrapper.css +0 -6
- package/dist/esm/lib/common/Wrapper/ToggleWrapper.js +2 -1
- package/dist/esm/lib/common/Wrapper/ToggleWrapper.js.map +1 -1
- package/dist/esm/lib/common/Wrapper/Wrapper.js +10 -6
- package/dist/esm/lib/common/Wrapper/Wrapper.js.map +1 -1
- package/dist/esm/lib/common/Wrapper/createMiddleware.js +70 -0
- package/dist/esm/lib/common/Wrapper/createMiddleware.js.map +1 -0
- package/dist/esm/lib/common/Wrapper/hooks/useFieldWrapper.js +2 -2
- package/dist/esm/lib/common/Wrapper/hooks/useFieldWrapper.js.map +1 -1
- package/dist/esm/lib/common/Wrapper/withConditionalDisplay.js +17 -12
- package/dist/esm/lib/common/Wrapper/withConditionalDisplay.js.map +1 -1
- package/dist/esm/lib/common/Wrapper/withWrapper.js +16 -10
- package/dist/esm/lib/common/Wrapper/withWrapper.js.map +1 -1
- package/dist/esm/lib/component/ChoicesField/Choices.js +2 -2
- package/dist/esm/lib/component/ChoicesField/Choices.js.map +1 -1
- package/dist/esm/lib/component/ChoicesField/ChoicesField.js +3 -2
- package/dist/esm/lib/component/ChoicesField/ChoicesField.js.map +1 -1
- package/dist/esm/lib/component/ChoicesField/styles.css +3 -65
- package/dist/esm/lib/component/DateTimeField/DateTimeField.js +2 -1
- package/dist/esm/lib/component/DateTimeField/DateTimeField.js.map +1 -1
- package/dist/esm/lib/component/FileUploadField/FileUploadField.js +45 -41
- package/dist/esm/lib/component/FileUploadField/FileUploadField.js.map +1 -1
- package/dist/esm/lib/component/FileUploadField/fileUploadRules.js +39 -0
- package/dist/esm/lib/component/FileUploadField/fileUploadRules.js.map +1 -0
- package/dist/esm/lib/component/FileUploadField/styles.css +30 -0
- package/dist/esm/lib/component/RichChoicesField/RichChoices.js +2 -2
- package/dist/esm/lib/component/RichChoicesField/RichChoices.js.map +1 -1
- package/dist/esm/lib/component/RichChoicesField/RichChoicesField.js +2 -2
- package/dist/esm/lib/component/index.js +5 -4
- package/dist/esm/lib/component/index.js.map +1 -1
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/esm/lib/pattern/Field/Field.js +3 -3
- package/dist/esm/lib/pattern/Field/Field.js.map +1 -1
- package/dist/esm/lib/subcomponent/DateInput/styles.css +16 -0
- package/dist/esm/lib/subcomponent/DateTimeInput/styles.css +24 -7
- package/dist/esm/lib/subcomponent/Field/Description/Description.js +1 -3
- package/dist/esm/lib/subcomponent/Field/Description/Description.js.map +1 -1
- package/dist/esm/lib/subcomponent/Field/Description/styles.css +4 -0
- package/dist/esm/lib/subcomponent/Field/Error/Error.js +4 -4
- package/dist/esm/lib/subcomponent/Field/Error/Error.js.map +1 -1
- package/dist/esm/lib/subcomponent/Field/Error/styles.css +8 -0
- package/dist/esm/lib/subcomponent/Field/Label/styles.css +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/FileUploadInput.js +119 -64
- package/dist/esm/lib/subcomponent/FileUploadInput/FileUploadInput.js.map +1 -1
- package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.js +52 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/index.js +2 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/index.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/types.js +2 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/FileItem/types.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.js +40 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/index.js +2 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/index.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/types.js +2 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/common/Thumbnail/types.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/constants.js +3 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/constants.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/hooks/index.js +3 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/hooks/index.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useFileUploads.js +148 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useFileUploads.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.js +22 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/messages.js +25 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/messages.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/styles.css +255 -94
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/formatFileSize.js +21 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/formatFileSize.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/getFileMessage.js +20 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/getFileMessage.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/index.js +4 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/index.js.map +1 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/matchesAccept.js +26 -0
- package/dist/esm/lib/subcomponent/FileUploadInput/utils/matchesAccept.js.map +1 -0
- package/dist/esm/lib/subcomponent/NumberInput/NumberInput.js +1 -1
- package/dist/esm/lib/subcomponent/NumberInput/NumberInput.js.map +1 -1
- package/dist/esm/lib/subcomponent/NumberInput/styles.css +17 -0
- package/dist/esm/lib/subcomponent/PasswordInput/styles.css +7 -1
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +8 -2
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
- package/dist/esm/lib/subcomponent/RadioInput/styles.css +15 -13
- package/dist/esm/lib/subcomponent/TextInput/TextInput.js +3 -1
- package/dist/esm/lib/subcomponent/TextInput/TextInput.js.map +1 -1
- package/dist/esm/lib/subcomponent/index.js +5 -5
- package/dist/esm/lib/subcomponent/index.js.map +1 -1
- package/dist/esm/lib/utils/hooks/useFieldAriaProperties.js +6 -4
- package/dist/esm/lib/utils/hooks/useFieldAriaProperties.js.map +1 -1
- package/dist/esm/lib/utils/hooks/useOptionAriaProperties.js +3 -3
- package/dist/esm/lib/utils/hooks/useOptionAriaProperties.js.map +1 -1
- package/dist/esm/lib/utils/middleware/addRESTOptions.js +99 -39
- package/dist/esm/lib/utils/middleware/addRESTOptions.js.map +1 -1
- package/dist/esm/lib/utils/middleware/addRESTValidation.js +246 -32
- package/dist/esm/lib/utils/middleware/addRESTValidation.js.map +1 -1
- package/dist/esm/lib/utils/middleware/index.js +1 -0
- package/dist/esm/lib/utils/middleware/index.js.map +1 -1
- package/dist/esm/testing/expectNoAxeViolations.js +30 -0
- package/dist/esm/testing/expectNoAxeViolations.js.map +1 -0
- package/dist/types/lib/{component → _work_in_progress/component}/ColorField/ColorField.d.ts +7 -12
- package/dist/types/lib/_work_in_progress/component/ColorField/ColorField.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/component/ColorField/index.d.ts.map +1 -0
- package/dist/types/lib/{component → _work_in_progress/component}/ColorField/types.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/component/ColorField/types.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/component/ComboboxField/ComboboxField.d.ts +53 -0
- package/dist/types/lib/_work_in_progress/component/ComboboxField/ComboboxField.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/component/ComboboxField/index.d.ts.map +1 -0
- package/dist/types/lib/{component → _work_in_progress/component}/ComboboxField/types.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/component/ComboboxField/types.d.ts.map +1 -0
- package/dist/types/lib/{component → _work_in_progress/component}/RatingField/RatingField.d.ts +7 -12
- package/dist/types/lib/_work_in_progress/component/RatingField/RatingField.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/component/RatingField/index.d.ts.map +1 -0
- package/dist/types/lib/{component → _work_in_progress/component}/RatingField/types.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/component/RatingField/types.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ColorInput/ColorInput.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ColorInput/index.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/types.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/subcomponent/ColorInput/types.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/ComboboxInput.d.ts +13 -5
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/ComboboxInput.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.d.ts +24 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/MultipleCombobox.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/SingleCombobox.d.ts +19 -4
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/List.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/List.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/index.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/types.d.ts +2 -1
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/List/types.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/ResetButton.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/ResetButton.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/index.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/types.d.ts +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/ResetButton/types.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/common/index.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/constants.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/index.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/messages.d.ts +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/messages.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/types.d.ts +52 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/types.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.d.ts +4 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertItemToString.d.ts.map +1 -0
- package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/convertValueToItem.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/convertValueToItem.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.d.ts +4 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/filterItems.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.d.ts +7 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.d.ts +4 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/isPromise.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.d.ts +8 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/settleLookup.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.d.ts +13 -0
- package/dist/types/lib/_work_in_progress/subcomponent/ComboboxInput/utils/stopPageMovesAtEnds.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/RatingInput/RatingInput.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/RatingInput/index.d.ts.map +1 -0
- package/dist/types/lib/_work_in_progress/subcomponent/RatingInput/types.d.ts.map +1 -0
- package/dist/types/lib/common/Wrapper/InvisibleWrapper.d.ts.map +1 -1
- package/dist/types/lib/common/Wrapper/ToggleWrapper.d.ts.map +1 -1
- package/dist/types/lib/common/Wrapper/Wrapper.d.ts +1 -1
- package/dist/types/lib/common/Wrapper/Wrapper.d.ts.map +1 -1
- package/dist/types/lib/common/Wrapper/createMiddleware.d.ts +43 -0
- package/dist/types/lib/common/Wrapper/createMiddleware.d.ts.map +1 -0
- package/dist/types/lib/common/Wrapper/hooks/useFieldWrapper.d.ts +2 -0
- package/dist/types/lib/common/Wrapper/hooks/useFieldWrapper.d.ts.map +1 -1
- package/dist/types/lib/common/Wrapper/withConditionalDisplay.d.ts +9 -3
- package/dist/types/lib/common/Wrapper/withConditionalDisplay.d.ts.map +1 -1
- package/dist/types/lib/common/Wrapper/withWrapper.d.ts +3 -5
- package/dist/types/lib/common/Wrapper/withWrapper.d.ts.map +1 -1
- package/dist/types/lib/common/types.d.ts +19 -7
- package/dist/types/lib/common/types.d.ts.map +1 -1
- package/dist/types/lib/component/ChoicesField/Choices.d.ts +1 -1
- package/dist/types/lib/component/ChoicesField/Choices.d.ts.map +1 -1
- package/dist/types/lib/component/ChoicesField/ChoicesField.d.ts +9 -13
- package/dist/types/lib/component/ChoicesField/ChoicesField.d.ts.map +1 -1
- package/dist/types/lib/component/ChoicesField/types.d.ts +2 -2
- package/dist/types/lib/component/ChoicesField/types.d.ts.map +1 -1
- package/dist/types/lib/component/DateField/DateField.d.ts +6 -11
- package/dist/types/lib/component/DateTimeField/DateTimeField.d.ts +7 -11
- package/dist/types/lib/component/DateTimeField/DateTimeField.d.ts.map +1 -1
- package/dist/types/lib/component/FileUploadField/FileUploadField.d.ts +299 -19
- package/dist/types/lib/component/FileUploadField/FileUploadField.d.ts.map +1 -1
- package/dist/types/lib/component/FileUploadField/fileUploadRules.d.ts +24 -0
- package/dist/types/lib/component/FileUploadField/fileUploadRules.d.ts.map +1 -0
- package/dist/types/lib/component/HiddenField/HiddenField.d.ts +6 -11
- package/dist/types/lib/component/NumberField/NumberField.d.ts +6 -11
- package/dist/types/lib/component/PasswordField/PasswordField.d.ts +6 -11
- package/dist/types/lib/component/PhoneField/PhoneField.d.ts +7 -11
- package/dist/types/lib/component/RangeField/RangeField.d.ts +6 -11
- package/dist/types/lib/component/RichChoicesField/RichChoices.d.ts +1 -1
- package/dist/types/lib/component/RichChoicesField/RichChoices.d.ts.map +1 -1
- package/dist/types/lib/component/RichChoicesField/RichChoicesField.d.ts +8 -13
- package/dist/types/lib/component/RichChoicesField/types.d.ts +2 -2
- package/dist/types/lib/component/RichChoicesField/types.d.ts.map +1 -1
- package/dist/types/lib/component/SelectField/SelectField.d.ts +6 -11
- package/dist/types/lib/component/TextField/TextField.d.ts +6 -11
- package/dist/types/lib/component/TextareaField/TextareaField.d.ts +6 -11
- package/dist/types/lib/component/TimeField/TimeField.d.ts +6 -11
- package/dist/types/lib/component/index.d.ts +3 -3
- package/dist/types/lib/component/index.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +1 -1
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/pattern/Field/types.d.ts +4 -4
- package/dist/types/lib/pattern/Field/types.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/Field/Description/Description.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/Field/Error/Error.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/FileUploadInput/FileUploadInput.d.ts +25 -4
- package/dist/types/lib/subcomponent/FileUploadInput/FileUploadInput.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.d.ts +15 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/FileItem.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/index.d.ts +3 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/index.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/types.d.ts +28 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/FileItem/types.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.d.ts +14 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/Thumbnail.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/index.d.ts +3 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/index.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/types.d.ts +9 -0
- package/dist/types/lib/subcomponent/FileUploadInput/common/Thumbnail/types.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/constants.d.ts +3 -0
- package/dist/types/lib/subcomponent/FileUploadInput/constants.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/hooks/index.d.ts +3 -0
- package/dist/types/lib/subcomponent/FileUploadInput/hooks/index.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/hooks/useFileUploads.d.ts +33 -0
- package/dist/types/lib/subcomponent/FileUploadInput/hooks/useFileUploads.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.d.ts +8 -0
- package/dist/types/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/index.d.ts +1 -1
- package/dist/types/lib/subcomponent/FileUploadInput/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/FileUploadInput/messages.d.ts +4 -0
- package/dist/types/lib/subcomponent/FileUploadInput/messages.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/types.d.ts +165 -8
- package/dist/types/lib/subcomponent/FileUploadInput/types.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/FileUploadInput/utils/formatFileSize.d.ts +7 -0
- package/dist/types/lib/subcomponent/FileUploadInput/utils/formatFileSize.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/utils/getFileMessage.d.ts +14 -0
- package/dist/types/lib/subcomponent/FileUploadInput/utils/getFileMessage.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/utils/index.d.ts +5 -0
- package/dist/types/lib/subcomponent/FileUploadInput/utils/index.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/FileUploadInput/utils/matchesAccept.d.ts +10 -0
- package/dist/types/lib/subcomponent/FileUploadInput/utils/matchesAccept.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +12 -0
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +11 -2
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/TextInput/TextInput.d.ts +2 -0
- package/dist/types/lib/subcomponent/TextInput/TextInput.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/index.d.ts +7 -7
- package/dist/types/lib/subcomponent/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/types.d.ts +6 -0
- package/dist/types/lib/subcomponent/types.d.ts.map +1 -1
- package/dist/types/lib/utils/hooks/useFieldAriaProperties.d.ts +2 -1
- package/dist/types/lib/utils/hooks/useFieldAriaProperties.d.ts.map +1 -1
- package/dist/types/lib/utils/hooks/useOptionAriaProperties.d.ts +3 -2
- package/dist/types/lib/utils/hooks/useOptionAriaProperties.d.ts.map +1 -1
- package/dist/types/lib/utils/middleware/addRESTOptions.d.ts +37 -4
- package/dist/types/lib/utils/middleware/addRESTOptions.d.ts.map +1 -1
- package/dist/types/lib/utils/middleware/addRESTValidation.d.ts +38 -3
- package/dist/types/lib/utils/middleware/addRESTValidation.d.ts.map +1 -1
- package/dist/types/lib/utils/middleware/index.d.ts +2 -0
- package/dist/types/lib/utils/middleware/index.d.ts.map +1 -1
- package/dist/types/testing/expectNoAxeViolations.d.ts +10 -0
- package/dist/types/testing/expectNoAxeViolations.d.ts.map +1 -0
- package/package.json +18 -17
- package/dist/esm/lib/component/ColorField/ColorField.js.map +0 -1
- package/dist/esm/lib/component/ColorField/index.js.map +0 -1
- package/dist/esm/lib/component/ColorField/types.js.map +0 -1
- package/dist/esm/lib/component/ComboboxField/ComboboxField.js.map +0 -1
- package/dist/esm/lib/component/ComboboxField/index.js.map +0 -1
- package/dist/esm/lib/component/ComboboxField/types.js.map +0 -1
- package/dist/esm/lib/component/RatingField/RatingField.js.map +0 -1
- package/dist/esm/lib/component/RatingField/index.js.map +0 -1
- package/dist/esm/lib/component/RatingField/types.js.map +0 -1
- package/dist/esm/lib/subcomponent/ColorInput/ColorInput.js.map +0 -1
- package/dist/esm/lib/subcomponent/ColorInput/index.js.map +0 -1
- package/dist/esm/lib/subcomponent/ColorInput/types.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/ComboboxInput.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/MultipleCombobox.js +0 -84
- package/dist/esm/lib/subcomponent/ComboboxInput/MultipleCombobox.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +0 -67
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/index.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/types.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/ResetButton.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/index.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/ResetButton/types.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/index.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/constants.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/index.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/messages.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/types.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/convertItemToString.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/convertValueToItem.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/filterItems.js.map +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -4
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +0 -1
- package/dist/esm/lib/subcomponent/RatingInput/RatingInput.js.map +0 -1
- package/dist/esm/lib/subcomponent/RatingInput/index.js.map +0 -1
- package/dist/esm/lib/subcomponent/RatingInput/types.js.map +0 -1
- package/dist/types/lib/component/ColorField/ColorField.d.ts.map +0 -1
- package/dist/types/lib/component/ColorField/index.d.ts.map +0 -1
- package/dist/types/lib/component/ColorField/types.d.ts.map +0 -1
- package/dist/types/lib/component/ComboboxField/ComboboxField.d.ts +0 -56
- package/dist/types/lib/component/ComboboxField/ComboboxField.d.ts.map +0 -1
- package/dist/types/lib/component/ComboboxField/index.d.ts.map +0 -1
- package/dist/types/lib/component/ComboboxField/types.d.ts.map +0 -1
- package/dist/types/lib/component/RatingField/RatingField.d.ts.map +0 -1
- package/dist/types/lib/component/RatingField/index.d.ts.map +0 -1
- package/dist/types/lib/component/RatingField/types.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ColorInput/ColorInput.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ColorInput/index.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ColorInput/types.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/ComboboxInput.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/MultipleCombobox.d.ts +0 -16
- package/dist/types/lib/subcomponent/ComboboxInput/MultipleCombobox.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/common/List/List.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/common/List/index.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/common/List/types.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/common/ResetButton/ResetButton.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/common/ResetButton/index.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/common/ResetButton/types.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/common/index.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/constants.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/index.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/messages.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/types.d.ts +0 -27
- package/dist/types/lib/subcomponent/ComboboxInput/types.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/convertItemToString.d.ts +0 -4
- package/dist/types/lib/subcomponent/ComboboxInput/utils/convertItemToString.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/convertValueToItem.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/filterItems.d.ts +0 -4
- package/dist/types/lib/subcomponent/ComboboxInput/utils/filterItems.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -4
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/RatingInput/RatingInput.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/RatingInput/index.d.ts.map +0 -1
- package/dist/types/lib/subcomponent/RatingInput/types.d.ts.map +0 -1
- /package/dist/esm/lib/{component → _work_in_progress/component}/ColorField/index.js +0 -0
- /package/dist/esm/lib/{component → _work_in_progress/component}/ColorField/types.js +0 -0
- /package/dist/esm/lib/{component → _work_in_progress/component}/ComboboxField/index.js +0 -0
- /package/dist/esm/lib/{component → _work_in_progress/component}/ComboboxField/types.js +0 -0
- /package/dist/esm/lib/{component → _work_in_progress/component}/RatingField/index.js +0 -0
- /package/dist/esm/lib/{component → _work_in_progress/component}/RatingField/types.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/ColorInput.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/index.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/styles.css +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/types.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/ComboboxInput.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/index.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/styles.css +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/types.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/index.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/types.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/index.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/constants.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/index.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/styles.css +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/types.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/convertItemToString.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/convertValueToItem.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/utils/filterItems.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/RatingInput.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/index.js +0 -0
- /package/dist/esm/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/types.js +0 -0
- /package/dist/types/lib/{component → _work_in_progress/component}/ColorField/index.d.ts +0 -0
- /package/dist/types/lib/{component → _work_in_progress/component}/ComboboxField/index.d.ts +0 -0
- /package/dist/types/lib/{component → _work_in_progress/component}/RatingField/index.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/ColorInput.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ColorInput/index.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/List/index.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/ResetButton/index.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/common/index.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/constants.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/ComboboxInput/index.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/RatingInput.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/index.d.ts +0 -0
- /package/dist/types/lib/{subcomponent → _work_in_progress/subcomponent}/RatingInput/types.d.ts +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { RESULT_DISPLAY_DURATION } from "../constants.js";
|
|
3
|
+
const clamp = (fraction) => Math.min(1, Math.max(0, Number.isFinite(fraction) ? fraction : 0));
|
|
4
|
+
const summarise = (states) => {
|
|
5
|
+
let uploading = 0;
|
|
6
|
+
let failed = 0;
|
|
7
|
+
for (const state of states.values()) {
|
|
8
|
+
if (state.status === "uploading")
|
|
9
|
+
uploading += 1;
|
|
10
|
+
if (state.status === "failed")
|
|
11
|
+
failed += 1;
|
|
12
|
+
}
|
|
13
|
+
return { uploading, failed };
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Runs the live uploads of the chosen files. Each new file that may be
|
|
17
|
+
* uploaded is sent once with its own abort signal; a file that leaves the
|
|
18
|
+
* selection has its upload aborted and its state dropped. Upload state lives
|
|
19
|
+
* here, keyed by the `File` object, and never in the form value.
|
|
20
|
+
*
|
|
21
|
+
* Cancelling an upload is removing its file: the consumer drops it from the
|
|
22
|
+
* value, and the upload is aborted with it. Once an upload ends, success or
|
|
23
|
+
* failure, its result shows for `RESULT_DISPLAY_DURATION`; a failed upload
|
|
24
|
+
* then stays failed until it is retried or removed.
|
|
25
|
+
*
|
|
26
|
+
* Every upload promise is settled here, so neither a rejection nor an abort
|
|
27
|
+
* escapes as an unhandled rejection. A result from an upload that has since
|
|
28
|
+
* been retried or removed is ignored.
|
|
29
|
+
*/
|
|
30
|
+
export default function useFileUploads(files, { upload, canUpload, onSummaryChange }) {
|
|
31
|
+
const [states, setStates] = useState(() => new Map());
|
|
32
|
+
const controllers = useRef(new Map());
|
|
33
|
+
const timers = useRef(new Map());
|
|
34
|
+
const tracked = useRef(new Set());
|
|
35
|
+
const latest = useRef({ upload, canUpload, onSummaryChange });
|
|
36
|
+
latest.current = { upload, canUpload, onSummaryChange };
|
|
37
|
+
const reported = useRef({ uploading: 0, failed: 0 });
|
|
38
|
+
const update = useCallback((file, next) => {
|
|
39
|
+
setStates((previous) => {
|
|
40
|
+
const current = previous.get(file);
|
|
41
|
+
const state = next(current);
|
|
42
|
+
if (state === current)
|
|
43
|
+
return previous;
|
|
44
|
+
const map = new Map(previous);
|
|
45
|
+
if (state)
|
|
46
|
+
map.set(file, state);
|
|
47
|
+
else
|
|
48
|
+
map.delete(file);
|
|
49
|
+
return map;
|
|
50
|
+
});
|
|
51
|
+
}, []);
|
|
52
|
+
const stop = useCallback((file) => {
|
|
53
|
+
controllers.current.get(file)?.abort();
|
|
54
|
+
controllers.current.delete(file);
|
|
55
|
+
clearTimeout(timers.current.get(file));
|
|
56
|
+
timers.current.delete(file);
|
|
57
|
+
}, []);
|
|
58
|
+
/**
|
|
59
|
+
* Records how an upload ended and shows its result, then hides the result
|
|
60
|
+
* after `RESULT_DISPLAY_DURATION`, keeping the outcome.
|
|
61
|
+
*/
|
|
62
|
+
const end = useCallback((file, outcome) => {
|
|
63
|
+
controllers.current.delete(file);
|
|
64
|
+
update(file, outcome);
|
|
65
|
+
timers.current.set(file, setTimeout(() => {
|
|
66
|
+
timers.current.delete(file);
|
|
67
|
+
update(file, (current) => current && current.status !== "uploading"
|
|
68
|
+
? { ...current, showResult: false }
|
|
69
|
+
: current);
|
|
70
|
+
}, RESULT_DISPLAY_DURATION));
|
|
71
|
+
}, [update]);
|
|
72
|
+
const start = useCallback((file, send) => {
|
|
73
|
+
stop(file);
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
controllers.current.set(file, controller);
|
|
76
|
+
const isCurrent = () => controllers.current.get(file) === controller;
|
|
77
|
+
update(file, () => ({ status: "uploading", progress: 0 }));
|
|
78
|
+
const onProgress = (fraction) => {
|
|
79
|
+
if (!isCurrent())
|
|
80
|
+
return;
|
|
81
|
+
const progress = clamp(fraction);
|
|
82
|
+
update(file, (current) => current?.status === "uploading" &&
|
|
83
|
+
Math.round(current.progress * 100) === Math.round(progress * 100)
|
|
84
|
+
? current
|
|
85
|
+
: { status: "uploading", progress });
|
|
86
|
+
};
|
|
87
|
+
new Promise((resolve) => {
|
|
88
|
+
resolve(send(file, { signal: controller.signal, onProgress }));
|
|
89
|
+
}).then(() => {
|
|
90
|
+
if (!isCurrent())
|
|
91
|
+
return;
|
|
92
|
+
end(file, () => ({ status: "uploaded", showResult: true }));
|
|
93
|
+
}, (reason) => {
|
|
94
|
+
if (!isCurrent())
|
|
95
|
+
return;
|
|
96
|
+
end(file, (current) => ({
|
|
97
|
+
status: "failed",
|
|
98
|
+
reason,
|
|
99
|
+
progress: current?.status === "uploading" ? current.progress : 0,
|
|
100
|
+
showResult: true,
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
}, [end, stop, update]);
|
|
104
|
+
const live = Boolean(upload);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const present = new Set(files);
|
|
107
|
+
for (const file of tracked.current) {
|
|
108
|
+
if (present.has(file) && live)
|
|
109
|
+
continue;
|
|
110
|
+
stop(file);
|
|
111
|
+
tracked.current.delete(file);
|
|
112
|
+
update(file, () => undefined);
|
|
113
|
+
}
|
|
114
|
+
const send = latest.current.upload;
|
|
115
|
+
if (!send)
|
|
116
|
+
return;
|
|
117
|
+
for (const file of files) {
|
|
118
|
+
if (tracked.current.has(file) || !latest.current.canUpload(file)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
tracked.current.add(file);
|
|
122
|
+
start(file, send);
|
|
123
|
+
}
|
|
124
|
+
}, [files, live, start, stop, update]);
|
|
125
|
+
useEffect(() => () => {
|
|
126
|
+
for (const file of tracked.current)
|
|
127
|
+
stop(file);
|
|
128
|
+
tracked.current.clear();
|
|
129
|
+
}, [stop]);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const summary = summarise(states);
|
|
132
|
+
const previous = reported.current;
|
|
133
|
+
if (summary.uploading === previous.uploading &&
|
|
134
|
+
summary.failed === previous.failed) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
reported.current = summary;
|
|
138
|
+
latest.current.onSummaryChange?.(summary);
|
|
139
|
+
}, [states]);
|
|
140
|
+
const retry = useCallback((file) => {
|
|
141
|
+
const send = latest.current.upload;
|
|
142
|
+
if (!send || !tracked.current.has(file))
|
|
143
|
+
return;
|
|
144
|
+
start(file, send);
|
|
145
|
+
}, [start]);
|
|
146
|
+
return { states, retry };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=useFileUploads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFileUploads.js","sourceRoot":"","sources":["../../../../../../src/lib/subcomponent/FileUploadInput/hooks/useFileUploads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAmB1D,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAU,EAAE,CACzC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAErE,MAAM,SAAS,GAAG,CAAC,MAAsC,EAAiB,EAAE;IAC1E,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACpC,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW;YAAE,SAAS,IAAI,CAAC,CAAC;QACjD,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ;YAAE,MAAM,IAAI,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,KAAsB,EACtB,EAAE,MAAM,E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,CAAC;IAEvC,SAAS,CACP,GAAG,EAAE,CAAC,GAAG,EAAE;QACT,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,OAAO;YAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC;QAClC,IACE,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,SAAS;YACxC,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAClC,CAAC;YACD,OAAO;QACT,CAAC;QACD,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,MAAM,KAAK,GAAG,WAAW,CACvB,CAAC,IAAU,EAAE,EAAE;QACb,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACnC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO;QAChD,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpB,CAAC,EACD,CAAC,KAAK,CAAC,CACR,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* An object URL for a file, created after mount and revoked when the file
|
|
4
|
+
* changes or the component unmounts. `undefined` without a file, during server
|
|
5
|
+
* rendering, on the first client render, and where object URLs are not
|
|
6
|
+
* supported.
|
|
7
|
+
*/
|
|
8
|
+
export default function useObjectUrl(file) {
|
|
9
|
+
const [url, setUrl] = useState();
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!file || typeof URL.createObjectURL !== "function")
|
|
12
|
+
return;
|
|
13
|
+
const objectUrl = URL.createObjectURL(file);
|
|
14
|
+
setUrl(objectUrl);
|
|
15
|
+
return () => {
|
|
16
|
+
URL.revokeObjectURL(objectUrl);
|
|
17
|
+
setUrl(undefined);
|
|
18
|
+
};
|
|
19
|
+
}, [file]);
|
|
20
|
+
return url;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=useObjectUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObjectUrl.js","sourceRoot":"","sources":["../../../../../../src/lib/subcomponent/FileUploadInput/hooks/useObjectUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,IAAsB;IAEtB,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,EAAU,CAAC;IAEzC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,eAAe,KAAK,UAAU;YAAE,OAAO;QAC/D,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,SAAS,CAAC,CAAC;QAClB,OAAO,GAAG,EAAE;YACV,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;YAC/B,MAAM,CAAC,SAAS,CAAC,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { formatFileSize } from "./utils/index.js";
|
|
2
|
+
const percent = new Intl.NumberFormat("en", { style: "percent" });
|
|
3
|
+
const messages = {
|
|
4
|
+
dropAreaText: () => "Drag and drop or",
|
|
5
|
+
chooseFile: (multiple) => (multiple ? "Choose files" : "Choose file"),
|
|
6
|
+
fileSize: (bytes) => formatFileSize(bytes),
|
|
7
|
+
progress: (fraction) => percent.format(fraction),
|
|
8
|
+
statusUploading: (fileName) => `Uploading ${fileName}`,
|
|
9
|
+
statusUploaded: (fileName) => `${fileName} uploaded`,
|
|
10
|
+
statusUploadedWithWarning: (fileName) => `${fileName} uploaded with a warning`,
|
|
11
|
+
statusFailed: (fileName) => `${fileName} failed to upload`,
|
|
12
|
+
remove: (fileName) => `Remove ${fileName}`,
|
|
13
|
+
cancelUpload: (fileName) => `Cancel upload of ${fileName}`,
|
|
14
|
+
retryUpload: (fileName) => `Retry upload of ${fileName}`,
|
|
15
|
+
messageLevel: (level) => (level === "error" ? "Error:" : "Warning:"),
|
|
16
|
+
uploadFailed: () => "File failed to upload.",
|
|
17
|
+
fileTooLarge: (maxSize) => `File size exceeds ${maxSize}.`,
|
|
18
|
+
fileTypeNotAccepted: () => "File type is not accepted.",
|
|
19
|
+
tooManyFiles: (maxFiles) => `You can upload at most ${maxFiles} file${maxFiles === 1 ? "" : "s"}.`,
|
|
20
|
+
filesHaveErrors: () => "Remove the files that have errors.",
|
|
21
|
+
uploadsPending: () => "Wait for the uploads to finish.",
|
|
22
|
+
uploadsFailed: () => "Retry or remove the files that failed to upload.",
|
|
23
|
+
};
|
|
24
|
+
export default messages;
|
|
25
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/FileUploadInput/messages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,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AQ,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;IACxE,eAAe,EAAE,GAAG,EAAE,CAAC,oCAAoC;IAC3D,cAAc,EAAE,GAAG,EAAE,CAAC,iCAAiC;IACvD,aAAa,EAAE,GAAG,EAAE,CAAC,kDAAkD;CACxE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,144 +1,305 @@
|
|
|
1
1
|
/* Layer: ds.components.global (@canonical/styles README, "Cascade layers"). */
|
|
2
2
|
|
|
3
3
|
@layer ds.components.global {
|
|
4
|
+
/* The whole image in the thumbnail's tooltip, uncropped. It fills the
|
|
5
|
+
tooltip's own maximum width, since the tooltip sizes to its content and an
|
|
6
|
+
image without an intrinsic size (an SVG with only a viewBox) would
|
|
7
|
+
otherwise collapse. A tall image is held to half the viewport and
|
|
8
|
+
letterboxed. */
|
|
9
|
+
.ds.tooltip.file-upload-preview img {
|
|
10
|
+
--file-upload-preview-inset: calc(2 * var(--tooltip-padding-horizontal));
|
|
11
|
+
|
|
12
|
+
display: block;
|
|
13
|
+
inline-size: calc(
|
|
14
|
+
var(--tooltip-max-width) -
|
|
15
|
+
var(--file-upload-preview-inset)
|
|
16
|
+
);
|
|
17
|
+
block-size: auto;
|
|
18
|
+
max-block-size: 50vh;
|
|
19
|
+
object-fit: contain;
|
|
20
|
+
}
|
|
21
|
+
|
|
4
22
|
.ds.input.file-upload {
|
|
23
|
+
position: relative;
|
|
5
24
|
display: flex;
|
|
6
25
|
flex-direction: column;
|
|
7
|
-
|
|
26
|
+
/* 16px between the drop area and message group and the file list. */
|
|
27
|
+
gap: var(--dimension-200);
|
|
28
|
+
|
|
29
|
+
/* ── Drop area and its field-level message ─────────────────────── */
|
|
30
|
+
& > .drop-area-group {
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
gap: var(--dimension-100);
|
|
34
|
+
}
|
|
8
35
|
|
|
9
|
-
|
|
36
|
+
/* The border and fill read the Criticality channels; the drop area takes
|
|
37
|
+
the `error` class while the field is invalid. Their hover, active and
|
|
38
|
+
disabled values have no channel, so those states name the neutral
|
|
39
|
+
tokens. */
|
|
40
|
+
& > .drop-area-group > .drop-area {
|
|
10
41
|
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
11
43
|
align-items: center;
|
|
12
44
|
justify-content: center;
|
|
13
45
|
box-sizing: border-box;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
padding:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var(--
|
|
23
|
-
|
|
24
|
-
background-color
|
|
25
|
-
color: var(--color-text-muted);
|
|
26
|
-
cursor: pointer;
|
|
27
|
-
transition:
|
|
28
|
-
border-color var(--motion-duration-fast) ease,
|
|
29
|
-
background-color var(--motion-duration-fast) ease;
|
|
30
|
-
|
|
31
|
-
& > input[type="file"] {
|
|
32
|
-
position: absolute;
|
|
33
|
-
width: 1px;
|
|
34
|
-
height: 1px;
|
|
35
|
-
overflow: hidden;
|
|
36
|
-
clip: rect(0, 0, 0, 0);
|
|
37
|
-
white-space: nowrap;
|
|
38
|
-
border: 0;
|
|
39
|
-
}
|
|
46
|
+
/* 112px; no dimension token declares it. */
|
|
47
|
+
min-block-size: calc(var(--dimension-200) * 7);
|
|
48
|
+
padding: var(--dimension-200);
|
|
49
|
+
gap: var(--dimension-100);
|
|
50
|
+
border: var(--dimension-stroke-thickness-medium) dashed
|
|
51
|
+
var(--modifier-color-border, var(--color-border));
|
|
52
|
+
background-color: var(
|
|
53
|
+
--modifier-color-foreground-input,
|
|
54
|
+
var(--color-foreground-input)
|
|
55
|
+
);
|
|
56
|
+
transition: background-color var(--motion-duration-fast) ease;
|
|
40
57
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
);
|
|
58
|
+
/* A file dragged over the area takes the hover fill. */
|
|
59
|
+
&:hover:not(:has(> .ds.button:disabled)),
|
|
60
|
+
&.drag-over {
|
|
61
|
+
background-color: var(--color-foreground-input-hover);
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
box-shadow: 0 0 0 1px var(--form-focus-ring-color);
|
|
64
|
+
/* Pressing the Choose file button makes the whole area active. */
|
|
65
|
+
&:has(> .ds.button:active:not(:disabled)) {
|
|
66
|
+
background-color: var(--color-foreground-input-active);
|
|
52
67
|
}
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
border-color: var(--
|
|
56
|
-
background-color: var(
|
|
57
|
-
--hover--color-foreground-input,
|
|
58
|
-
var(--color-foreground-input-hover)
|
|
59
|
-
);
|
|
69
|
+
&:has(> .ds.button:disabled) {
|
|
70
|
+
border-color: var(--color-border-disabled);
|
|
71
|
+
background-color: var(--color-foreground-input-disabled);
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
/* The Choose file button stays neutral in the error state. The
|
|
75
|
+
Criticality class on the drop area sets these channels for the area's
|
|
76
|
+
own border and fill, but they inherit, and the button would read them
|
|
77
|
+
for its border, icon and focus ring. `initial` unsets each one, so the
|
|
78
|
+
button falls back to its own colours. */
|
|
79
|
+
& > .ds.button {
|
|
80
|
+
--modifier-color-border: initial;
|
|
81
|
+
--modifier-color-icon: initial;
|
|
82
|
+
--modifier-color-focus-ring: initial;
|
|
66
83
|
}
|
|
67
84
|
}
|
|
68
85
|
|
|
86
|
+
& > .drop-area-group > .drop-area > .drop-area-text {
|
|
87
|
+
font-family: var(--typography-text-primary-font-family);
|
|
88
|
+
font-size: var(--typography-text-primary-font-size);
|
|
89
|
+
font-weight: var(--typography-text-primary-font-weight);
|
|
90
|
+
color: var(--color-text);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&.disabled > .drop-area-group > .drop-area > .drop-area-text {
|
|
94
|
+
color: var(--color-text-disabled);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* The native file input stays in the document (it carries the name and
|
|
98
|
+
`required`, and the button opens it) but is visually hidden. */
|
|
99
|
+
& > input[type="file"] {
|
|
100
|
+
position: absolute;
|
|
101
|
+
inline-size: 1px;
|
|
102
|
+
block-size: 1px;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
clip-path: inset(50%);
|
|
105
|
+
white-space: nowrap;
|
|
106
|
+
border: 0;
|
|
107
|
+
padding: 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* ── File list ─────────────────────────────────────────────────── */
|
|
69
111
|
& > .file-list {
|
|
70
112
|
list-style: none;
|
|
71
113
|
margin: 0;
|
|
72
114
|
padding: 0;
|
|
73
115
|
display: flex;
|
|
74
116
|
flex-direction: column;
|
|
75
|
-
gap: var(--
|
|
117
|
+
gap: var(--dimension-200);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.ds.input.file-upload > .file-list > .file-item {
|
|
122
|
+
/* Hover and active fills of the tile's actions. The Criticality family has
|
|
123
|
+
no hover or active channel yet, so each criticality is named here. */
|
|
124
|
+
--file-upload-tile-hover: var(--color-foreground-input-hover);
|
|
125
|
+
--file-upload-tile-active: var(--color-foreground-input-active);
|
|
126
|
+
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-direction: column;
|
|
129
|
+
gap: var(--dimension-100);
|
|
130
|
+
margin: 0;
|
|
131
|
+
|
|
132
|
+
&.warning {
|
|
133
|
+
--file-upload-tile-hover: var(--color-foreground-input-warning-hover);
|
|
134
|
+
--file-upload-tile-active: var(--color-foreground-input-warning-active);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&.error {
|
|
138
|
+
--file-upload-tile-hover: var(--color-foreground-input-error-hover);
|
|
139
|
+
--file-upload-tile-active: var(--color-foreground-input-error-active);
|
|
76
140
|
}
|
|
77
141
|
|
|
78
|
-
|
|
142
|
+
/* The warning or error message under the tile. */
|
|
143
|
+
& > .file-message {
|
|
79
144
|
display: flex;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var(--
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
145
|
+
flex-direction: row;
|
|
146
|
+
align-items: flex-start;
|
|
147
|
+
gap: var(--dimension-050);
|
|
148
|
+
margin: 0;
|
|
149
|
+
|
|
150
|
+
& > .ds.icon {
|
|
151
|
+
flex-shrink: 0;
|
|
152
|
+
margin-block: var(--dimension-025);
|
|
153
|
+
color: var(--modifier-color-icon, var(--color-icon));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
& > .message-text {
|
|
157
|
+
flex-grow: 1;
|
|
158
|
+
font-family: var(--typography-text-secondary-font-family);
|
|
159
|
+
font-size: var(--typography-text-secondary-font-size);
|
|
160
|
+
font-weight: var(--typography-text-secondary-font-weight);
|
|
161
|
+
line-height: var(--typography-text-secondary-line-height);
|
|
162
|
+
color: var(--modifier-color-text, var(--color-text-destructive));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
& > .tile {
|
|
167
|
+
display: flex;
|
|
168
|
+
flex-direction: row;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* With a preview, the tooltip's wrapper is the tile's flex item and the
|
|
172
|
+
thumbnail sits inside it. */
|
|
173
|
+
& > .tile > .thumbnail-preview {
|
|
174
|
+
display: flex;
|
|
175
|
+
flex-shrink: 0;
|
|
176
|
+
|
|
177
|
+
& > .target {
|
|
178
|
+
display: block;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* 60×36 (5:3). The image fills the box edge to edge; the height matches
|
|
183
|
+
the tile's. */
|
|
184
|
+
& > .tile > .thumbnail,
|
|
185
|
+
& > .tile > .thumbnail-preview > .target > .thumbnail {
|
|
186
|
+
display: block;
|
|
97
187
|
flex-shrink: 0;
|
|
188
|
+
inline-size: 60px;
|
|
189
|
+
block-size: 36px;
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
|
|
192
|
+
& > img {
|
|
193
|
+
display: block;
|
|
194
|
+
inline-size: 100%;
|
|
195
|
+
block-size: 100%;
|
|
196
|
+
object-fit: cover;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* No border: the fill alone draws the tile. */
|
|
201
|
+
& > .tile > .tile-details {
|
|
202
|
+
display: flex;
|
|
203
|
+
flex-direction: row;
|
|
204
|
+
align-items: center;
|
|
205
|
+
flex-grow: 1;
|
|
206
|
+
min-inline-size: 0;
|
|
207
|
+
gap: var(--dimension-100);
|
|
208
|
+
padding-block: var(--dimension-050);
|
|
209
|
+
padding-inline: var(--dimension-150) var(--dimension-050);
|
|
210
|
+
background-color: var(
|
|
211
|
+
--modifier-color-foreground-input,
|
|
212
|
+
var(--color-foreground-input)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
& > .tile > .tile-details > .file-info {
|
|
217
|
+
display: flex;
|
|
218
|
+
flex-direction: row;
|
|
219
|
+
align-items: center;
|
|
220
|
+
flex-grow: 1;
|
|
221
|
+
min-inline-size: 0;
|
|
222
|
+
gap: var(--dimension-100);
|
|
98
223
|
}
|
|
99
224
|
|
|
100
|
-
& > .
|
|
101
|
-
flex: 1;
|
|
102
|
-
min-
|
|
225
|
+
& > .tile > .tile-details > .file-info > .file-name {
|
|
226
|
+
flex-shrink: 1;
|
|
227
|
+
min-inline-size: 0;
|
|
103
228
|
overflow: hidden;
|
|
104
229
|
text-overflow: ellipsis;
|
|
105
230
|
white-space: nowrap;
|
|
231
|
+
font-family: var(--typography-text-primary-font-family);
|
|
232
|
+
font-size: var(--typography-text-primary-font-size);
|
|
233
|
+
font-weight: var(--typography-text-primary-font-weight);
|
|
234
|
+
color: var(
|
|
235
|
+
--modifier-color-text-onForegroundSecondary,
|
|
236
|
+
var(--color-text-onForegroundSecondary)
|
|
237
|
+
);
|
|
106
238
|
}
|
|
107
239
|
|
|
108
|
-
& > .
|
|
109
|
-
|
|
240
|
+
& > .tile > .tile-details > .file-info > .file-size,
|
|
241
|
+
& > .tile > .tile-details > .status-and-actions .upload-progress {
|
|
110
242
|
white-space: nowrap;
|
|
243
|
+
font-family: var(--typography-text-secondary-font-family);
|
|
244
|
+
font-size: var(--typography-text-secondary-font-size);
|
|
245
|
+
font-weight: var(--typography-text-secondary-font-weight);
|
|
111
246
|
}
|
|
112
247
|
|
|
113
|
-
& > .
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
248
|
+
& > .tile > .tile-details > .file-info > .file-size {
|
|
249
|
+
color: var(--modifier-color-text, var(--color-text-muted));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
& > .tile > .tile-details > .status-and-actions {
|
|
253
|
+
display: flex;
|
|
254
|
+
flex-direction: row;
|
|
255
|
+
align-items: center;
|
|
256
|
+
/* 6px; no dimension token declares this step. */
|
|
257
|
+
gap: 6px;
|
|
258
|
+
}
|
|
120
259
|
|
|
121
|
-
|
|
122
|
-
|
|
260
|
+
& > .tile > .tile-details > .status-and-actions > .file-status {
|
|
261
|
+
display: flex;
|
|
262
|
+
flex-direction: row;
|
|
263
|
+
align-items: center;
|
|
264
|
+
gap: var(--dimension-100);
|
|
265
|
+
|
|
266
|
+
&:empty {
|
|
267
|
+
display: none;
|
|
123
268
|
}
|
|
124
269
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
change the cascade for no visual gain. */
|
|
128
|
-
&:disabled {
|
|
129
|
-
cursor: not-allowed;
|
|
130
|
-
opacity: 0.5;
|
|
270
|
+
& > .upload-progress {
|
|
271
|
+
color: var(--color-text-muted);
|
|
131
272
|
}
|
|
132
273
|
}
|
|
133
|
-
}
|
|
134
274
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
275
|
+
& > .tile > .tile-details > .status-and-actions > .file-actions {
|
|
276
|
+
display: flex;
|
|
277
|
+
flex-direction: row;
|
|
278
|
+
align-items: center;
|
|
279
|
+
}
|
|
139
280
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
281
|
+
/* Icon buttons, 28×28. Their colours come from the tile: the icon reads
|
|
282
|
+
the tile's Criticality icon channel, and the hover and active fills are
|
|
283
|
+
the tile's own. */
|
|
284
|
+
&
|
|
285
|
+
> .tile
|
|
286
|
+
> .tile-details
|
|
287
|
+
> .status-and-actions
|
|
288
|
+
> .file-actions
|
|
289
|
+
> .ds.button.file-action {
|
|
290
|
+
--modifier-surface: transparent;
|
|
291
|
+
--modifier-surface-hover: var(--file-upload-tile-hover);
|
|
292
|
+
--modifier-surface-active: var(--file-upload-tile-active);
|
|
293
|
+
--modifier-outline: 0;
|
|
294
|
+
--modifier-color-text: var(--modifier-color-icon, var(--color-icon));
|
|
295
|
+
|
|
296
|
+
box-sizing: border-box;
|
|
297
|
+
inline-size: calc(var(--dimension-050) * 7);
|
|
298
|
+
block-size: calc(var(--dimension-050) * 7);
|
|
299
|
+
padding: 0;
|
|
300
|
+
align-items: center;
|
|
301
|
+
justify-content: center;
|
|
302
|
+
line-height: 1;
|
|
303
|
+
}
|
|
143
304
|
}
|
|
144
305
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const UNITS = ["byte", "kilobyte", "megabyte", "gigabyte", "terabyte"];
|
|
2
|
+
/**
|
|
3
|
+
* Formats a byte count as a short, human-readable size in the given locale,
|
|
4
|
+
* for example `1.5 MB` in English or `1,5 MB` in German. Sizes step by 1024.
|
|
5
|
+
* @note Pure.
|
|
6
|
+
*/
|
|
7
|
+
export default function formatFileSize(bytes, locale = "en") {
|
|
8
|
+
let value = bytes;
|
|
9
|
+
let unit = 0;
|
|
10
|
+
while (value >= 1024 && unit < UNITS.length - 1) {
|
|
11
|
+
value /= 1024;
|
|
12
|
+
unit += 1;
|
|
13
|
+
}
|
|
14
|
+
return new Intl.NumberFormat(locale, {
|
|
15
|
+
style: "unit",
|
|
16
|
+
unit: UNITS[unit],
|
|
17
|
+
unitDisplay: "short",
|
|
18
|
+
maximumFractionDigits: 1,
|
|
19
|
+
}).format(value);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=formatFileSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatFileSize.js","sourceRoot":"","sources":["../../../../../../src/lib/subcomponent/FileUploadInput/utils/formatFileSize.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAU,CAAC;AAEhF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAa,EAAE,MAAM,GAAG,IAAI;IACjE,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,KAAK,IAAI,IAAI,CAAC;QACd,IAAI,IAAI,CAAC,CAAC;IACZ,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QACnC,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;QACjB,WAAW,EAAE,OAAO;QACpB,qBAAqB,EAAE,CAAC;KACzB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import matchesAccept from "./matchesAccept.js";
|
|
2
|
+
/**
|
|
3
|
+
* The message for one chosen file: an error when `accept` or `maxSize` rejects
|
|
4
|
+
* it, otherwise whatever `validateFile` returns. The input shows it under the
|
|
5
|
+
* file's tile, and the field turns an error into an invalid field.
|
|
6
|
+
* @note Pure when `validateFile` is.
|
|
7
|
+
*/
|
|
8
|
+
export default function getFileMessage(file, { accept, maxSize, validateFile }, messages) {
|
|
9
|
+
if (accept && !matchesAccept(file, accept)) {
|
|
10
|
+
return { level: "error", message: messages.fileTypeNotAccepted(accept) };
|
|
11
|
+
}
|
|
12
|
+
if (typeof maxSize === "number" && file.size > maxSize) {
|
|
13
|
+
return {
|
|
14
|
+
level: "error",
|
|
15
|
+
message: messages.fileTooLarge(messages.fileSize(maxSize)),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return validateFile?.(file);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=getFileMessage.js.map
|