@canonical/react-ds-global-form 0.45.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 +14 -9
- 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 +38 -31
- 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/withToggleWrapper.d.ts +2 -2
- package/dist/types/lib/common/Wrapper/withToggleWrapper.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/CheckboxField/CheckboxField.d.ts +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/SwitchField/SwitchField.d.ts +1 -1
- 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/Field.d.ts +9 -5
- package/dist/types/lib/pattern/Field/Field.d.ts.map +1 -1
- package/dist/types/lib/pattern/Field/types.d.ts +69 -45
- 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 +23 -18
- 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
|
@@ -24,24 +24,25 @@
|
|
|
24
24
|
background-color var(--motion-duration-fast) ease,
|
|
25
25
|
border-color var(--motion-duration-fast) ease;
|
|
26
26
|
|
|
27
|
+
/* Ring fill = selected token, centre dot = unselected token; both
|
|
28
|
+
* surface-provided (flat fallback) so the control adapts to OnSurface
|
|
29
|
+
* stepping. */
|
|
27
30
|
&:checked {
|
|
28
|
-
/* Dot = selected token, ring fill = unselected token; both surface-provided
|
|
29
|
-
* (flat fallback) so the control adapts to OnSurface stepping. */
|
|
30
31
|
border-color: var(
|
|
31
32
|
--surface-color-foreground-radio-selected,
|
|
32
33
|
var(--color-foreground-radio-selected)
|
|
33
34
|
);
|
|
34
35
|
background: radial-gradient(
|
|
35
|
-
var(
|
|
36
|
-
--surface-color-foreground-radio-selected,
|
|
37
|
-
var(--color-foreground-radio-selected)
|
|
38
|
-
)
|
|
39
|
-
40%,
|
|
40
36
|
var(
|
|
41
37
|
--surface-color-foreground-radio-unselected,
|
|
42
38
|
var(--color-foreground-radio-unselected)
|
|
43
39
|
)
|
|
44
|
-
|
|
40
|
+
30%,
|
|
41
|
+
var(
|
|
42
|
+
--surface-color-foreground-radio-selected,
|
|
43
|
+
var(--color-foreground-radio-selected)
|
|
44
|
+
)
|
|
45
|
+
31%
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -49,18 +50,19 @@
|
|
|
49
50
|
background-color: var(--color-foreground-radio-unselected-hover);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
/* Hover on a selected radio shifts only the
|
|
53
|
-
* brightness filter (which would also dim the
|
|
54
|
-
* the hovered selected shade from the
|
|
53
|
+
/* Hover on a selected radio shifts only the ring's fill, not via a
|
|
54
|
+
* whole-element brightness filter (which would also dim the dot).
|
|
55
|
+
* Re-paint the gradient with the hovered selected shade from the
|
|
56
|
+
* `--hover--…-selected` channel. */
|
|
55
57
|
&:checked:hover:not(:disabled) {
|
|
56
58
|
border-color: var(--hover--color-foreground-radio-selected);
|
|
57
59
|
background: radial-gradient(
|
|
58
|
-
var(--hover--color-foreground-radio-selected) 40%,
|
|
59
60
|
var(
|
|
60
61
|
--surface-color-foreground-radio-unselected,
|
|
61
62
|
var(--color-foreground-radio-unselected)
|
|
62
63
|
)
|
|
63
|
-
|
|
64
|
+
30%,
|
|
65
|
+
var(--hover--color-foreground-radio-selected) 31%
|
|
64
66
|
);
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -7,6 +7,8 @@ const componentCssClassName = "ds input text chrome";
|
|
|
7
7
|
*
|
|
8
8
|
* Usable standalone (controlled via `value`/`onChange`, or uncontrolled) or via
|
|
9
9
|
* the field tier, which spreads react-hook-form's `register()` result onto it.
|
|
10
|
+
* The `id` goes on the native `<input>`, not the chrome wrapper, so a
|
|
11
|
+
* `<label for>` names and focuses the real control.
|
|
10
12
|
* @returns {ReactElement} - Rendered Text
|
|
11
13
|
*
|
|
12
14
|
* `import { TextInput } from "@canonical/react-ds-global-form";`
|
|
@@ -14,7 +16,7 @@ const componentCssClassName = "ds input text chrome";
|
|
|
14
16
|
* @implements ds:global.subcomponent.text_input
|
|
15
17
|
*/
|
|
16
18
|
export const TextInput = forwardRef(function TextInput({ id, className, style, inputType = "text", prefix, suffix, ...nativeProps }, ref) {
|
|
17
|
-
return (_jsxs("div", {
|
|
19
|
+
return (_jsxs("div", { style: style, className: [componentCssClassName, className].filter(Boolean).join(" "), children: [prefix && _jsx("span", { className: "prefix", children: prefix }), _jsx("input", { id: id, type: inputType, ref: ref, ...nativeProps }), suffix && _jsx("span", { className: "suffix", children: suffix })] }));
|
|
18
20
|
});
|
|
19
21
|
export default TextInput;
|
|
20
22
|
//# sourceMappingURL=TextInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/TextInput/TextInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,OAAO,CAAC;AAEtD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,sBAAsB,CAAC;AAErD
|
|
1
|
+
{"version":3,"file":"TextInput.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/TextInput/TextInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,OAAO,CAAC;AAEtD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,sBAAsB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CACjC,SAAS,SAAS,CAChB,EACE,EAAE,EACF,SAAS,EACT,KAAK,EACL,SAAS,GAAG,MAAM,EAClB,MAAM,EACN,MAAM,EACN,GAAG,WAAW,EACf,EACD,GAAG;IAEH,OAAO,CACL,eACE,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aAEtE,MAAM,IAAI,eAAM,SAAS,EAAC,QAAQ,YAAE,MAAM,GAAQ,EACnD,gBAAO,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,KAAM,WAAW,GAAI,EAC5D,MAAM,IAAI,eAAM,SAAS,EAAC,QAAQ,YAAE,MAAM,GAAQ,IAC/C,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// ds:Subcomponent tier barrel. Presentational input parts (no react-hook-form
|
|
2
2
|
// context) + the Field chrome subcomponents (Field.Label/Description/Error).
|
|
3
|
-
// The field/RHF-bound versions live under `component/` (via `fields/`).
|
|
4
|
-
//
|
|
3
|
+
// The field/RHF-bound versions live under `component/` (via `fields/`). The
|
|
4
|
+
// work-in-progress inputs live under `_work_in_progress/` until they are ready.
|
|
5
|
+
export { ColorInput } from "../_work_in_progress/subcomponent/ColorInput/index.js";
|
|
6
|
+
export { ComboboxInput } from "../_work_in_progress/subcomponent/ComboboxInput/index.js";
|
|
7
|
+
export { RatingInput } from "../_work_in_progress/subcomponent/RatingInput/index.js";
|
|
5
8
|
export { CheckboxInput } from "./CheckboxInput/index.js";
|
|
6
|
-
export { ColorInput } from "./ColorInput/index.js";
|
|
7
|
-
export { ComboboxInput } from "./ComboboxInput/index.js";
|
|
8
9
|
export { DateInput } from "./DateInput/index.js";
|
|
9
10
|
export { DateTimeInput } from "./DateTimeInput/index.js";
|
|
10
11
|
// Field chrome subcomponents (Field.Label / Field.Description / Field.Error)
|
|
@@ -16,7 +17,6 @@ export { PasswordInput } from "./PasswordInput/index.js";
|
|
|
16
17
|
export { PhoneInput } from "./PhoneInput/index.js";
|
|
17
18
|
export { RadioInput } from "./RadioInput/index.js";
|
|
18
19
|
export { RangeInput } from "./RangeInput/index.js";
|
|
19
|
-
export { RatingInput } from "./RatingInput/index.js";
|
|
20
20
|
export { SelectInput } from "./SelectInput/index.js";
|
|
21
21
|
export { SwitchInput } from "./SwitchInput/index.js";
|
|
22
22
|
export { TextareaInput } from "./TextareaInput/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/subcomponent/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/subcomponent/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,gFAAgF;AAMhF,OAAO,EAAE,UAAU,EAAE,MAAM,uDAAuD,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,MAAM,0DAA0D,CAAC;AAKzF,OAAO,EAAE,WAAW,EAAE,MAAM,wDAAwD,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AAUjC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,gFAAgF;AAChF,cAAc,YAAY,CAAC"}
|
|
@@ -4,9 +4,10 @@ import { useId, useMemo } from "react";
|
|
|
4
4
|
* @param {string} name - The name of the field.
|
|
5
5
|
* @param {boolean} isError - Indicates if the field is in an error state.
|
|
6
6
|
* @param {boolean} [isRequired] - Whether the field is required (drives `aria-required`, independent of error state).
|
|
7
|
+
* @param {boolean} [hasDescription] - Whether a description is rendered. `aria-describedby` only references ids that are in the document.
|
|
7
8
|
* @returns An object containing ARIA attributes for input, label, description, and error state.
|
|
8
9
|
*/
|
|
9
|
-
const useFieldAriaProps = (name, isError, isRequired = false) => {
|
|
10
|
+
const useFieldAriaProps = (name, isError, isRequired = false, hasDescription = false) => {
|
|
10
11
|
const uniqueId = useId();
|
|
11
12
|
const props = useMemo(() => {
|
|
12
13
|
const baseId = `${uniqueId}-${name}`;
|
|
@@ -17,8 +18,9 @@ const useFieldAriaProps = (name, isError, isRequired = false) => {
|
|
|
17
18
|
input: {
|
|
18
19
|
id: baseId,
|
|
19
20
|
"aria-labelledby": labelId,
|
|
20
|
-
"aria-describedby": [descriptionId, isError ? errorId : ""]
|
|
21
|
-
|
|
21
|
+
"aria-describedby": [hasDescription ? descriptionId : "", isError ? errorId : ""]
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
.join(" ") || undefined,
|
|
22
24
|
"aria-errormessage": isError ? errorId : undefined,
|
|
23
25
|
"aria-invalid": isError,
|
|
24
26
|
// Required state is a property of the field's optionality, NOT its
|
|
@@ -36,7 +38,7 @@ const useFieldAriaProps = (name, isError, isRequired = false) => {
|
|
|
36
38
|
// role: "alert",
|
|
37
39
|
},
|
|
38
40
|
};
|
|
39
|
-
}, [name, isError, isRequired, uniqueId]);
|
|
41
|
+
}, [name, isError, isRequired, hasDescription, uniqueId]);
|
|
40
42
|
return props;
|
|
41
43
|
};
|
|
42
44
|
export default useFieldAriaProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useFieldAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"useFieldAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useFieldAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,CACxB,IAAY,EACZ,OAAgB,EAChB,UAAU,GAAG,KAAK,EAClB,cAAc,GAAG,KAAK,EACtB,EAAE;IACF,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,GAAG,MAAM,QAAQ,CAAC;QAClC,MAAM,aAAa,GAAG,GAAG,MAAM,cAAc,CAAC;QAC9C,MAAM,OAAO,GAAG,GAAG,MAAM,QAAQ,CAAC;QAElC,OAAO;YACL,KAAK,EAAE;gBACL,EAAE,EAAE,MAAM;gBACV,iBAAiB,EAAE,OAAO;gBAC1B,kBAAkB,EAChB,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC1D,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS;gBAC3B,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBAClD,cAAc,EAAE,OAAO;gBACvB,mEAAmE;gBACnE,wEAAwE;gBACxE,4DAA4D;gBAC5D,eAAe,EAAE,UAAU,IAAI,SAAS;aACzC;YACD,KAAK,EAAE;gBACL,EAAE,EAAE,OAAO;gBACX,OAAO,EAAE,MAAM;aAChB;YACD,WAAW,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE;YAClC,KAAK,EAAE;gBACL,EAAE,EAAE,OAAO;gBACX,iBAAiB;aAClB;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -2,7 +2,9 @@ import { useId, useMemo } from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* Generates ARIA properties for a specific option in a choice-style field.
|
|
4
4
|
* Pure (no react-hook-form) — lives in the presentational tier so option-group
|
|
5
|
-
* inputs (Choices, RichChoices) can use it standalone.
|
|
5
|
+
* inputs (Choices, RichChoices) can use it standalone. Options carry no
|
|
6
|
+
* `aria-describedby`: the field description describes the whole group, so it is
|
|
7
|
+
* referenced from the group's fieldset instead.
|
|
6
8
|
* @param {string} name - The base name of the input field.
|
|
7
9
|
* @param {string} optionValue - The value of the specific option.
|
|
8
10
|
* @returns An object containing ARIA attributes for the option.
|
|
@@ -11,14 +13,12 @@ const useOptionAriaProps = (name, optionValue) => {
|
|
|
11
13
|
const uniqueId = useId();
|
|
12
14
|
const props = useMemo(() => {
|
|
13
15
|
const baseId = `${uniqueId}-${name}`;
|
|
14
|
-
const descriptionId = `${baseId}-description`;
|
|
15
16
|
const optionBaseId = `${baseId}-${optionValue}`;
|
|
16
17
|
const optionLabelId = `${optionBaseId}-label`;
|
|
17
18
|
return {
|
|
18
19
|
input: {
|
|
19
20
|
id: optionBaseId,
|
|
20
21
|
"aria-labelledby": optionLabelId,
|
|
21
|
-
"aria-describedby": descriptionId,
|
|
22
22
|
},
|
|
23
23
|
label: {
|
|
24
24
|
id: optionLabelId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOptionAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useOptionAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"useOptionAriaProperties.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useOptionAriaProperties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAE,EAAE;IAC/D,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrC,MAAM,YAAY,GAAG,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;QAChD,MAAM,aAAa,GAAG,GAAG,YAAY,QAAQ,CAAC;QAE9C,OAAO;YACL,KAAK,EAAE;gBACL,EAAE,EAAE,YAAY;gBAChB,iBAAiB,EAAE,aAAa;aACjC;YACD,KAAK,EAAE;gBACL,EAAE,EAAE,aAAa;gBACjB,OAAO,EAAE,YAAY;aACtB;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,44 +1,104 @@
|
|
|
1
|
-
import { createElement, useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { createElement, useEffect, useEffectEvent, useState, } from "react";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
3
|
+
import createMiddleware, {} from "../../common/Wrapper/createMiddleware.js";
|
|
4
|
+
/** The error type the middleware sets, so it only ever clears its own error. */
|
|
5
|
+
const REST_OPTIONS_ERROR_TYPE = "restOptions";
|
|
6
|
+
/** The options of a field before, or without, a successful request. */
|
|
7
|
+
const NO_OPTIONS = [];
|
|
8
|
+
/** Reads a displayable message from whatever a failed request rejected with. */
|
|
9
|
+
const readErrorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
10
|
+
/**
|
|
11
|
+
* Requests the options and transforms the body.
|
|
12
|
+
* @note Impure: performs a network request.
|
|
13
|
+
*/
|
|
14
|
+
const requestOptions = async (url, { method, headers, transform }, signal) => {
|
|
15
|
+
const response = await fetch(url, { method, headers, signal });
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error("Failed to fetch options");
|
|
18
|
+
}
|
|
19
|
+
return transform(await response.json());
|
|
20
|
+
};
|
|
21
|
+
/** Builds the component that fetches the options and passes them on. */
|
|
22
|
+
const buildRESTOptions = (WrappedComponent, useSettings) => {
|
|
23
|
+
function WithRESTOptions(props) {
|
|
24
|
+
const { name } = props;
|
|
25
|
+
const settings = useSettings();
|
|
26
|
+
const { url } = settings;
|
|
27
|
+
const { setError, clearErrors, getFieldState } = useFormContext();
|
|
28
|
+
const [status, setStatus] = useState("loading");
|
|
29
|
+
const [fetchedOptions, setFetchedOptions] = useState(NO_OPTIONS);
|
|
30
|
+
// The request reads the newest method, headers and transform, but only a
|
|
31
|
+
// new URL starts one.
|
|
32
|
+
const fetchOptions = useEffectEvent((requestUrl, signal) => requestOptions(requestUrl, settings, signal));
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
/** Clears the field's error when this middleware set it. */
|
|
36
|
+
const clearOwnError = () => {
|
|
37
|
+
if (getFieldState(name).error?.type === REST_OPTIONS_ERROR_TYPE) {
|
|
38
|
+
clearErrors(name);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
// The failure of the previous URL is part of its answer: drop it too.
|
|
42
|
+
clearOwnError();
|
|
43
|
+
setStatus("loading");
|
|
44
|
+
setFetchedOptions(NO_OPTIONS);
|
|
45
|
+
fetchOptions(url, controller.signal)
|
|
46
|
+
.then((result) => {
|
|
47
|
+
if (controller.signal.aborted)
|
|
48
|
+
return;
|
|
49
|
+
setFetchedOptions(result);
|
|
50
|
+
setStatus("ready");
|
|
51
|
+
clearOwnError();
|
|
52
|
+
})
|
|
53
|
+
.catch((error) => {
|
|
54
|
+
if (controller.signal.aborted)
|
|
55
|
+
return;
|
|
56
|
+
setStatus("failed");
|
|
57
|
+
setError(name, {
|
|
58
|
+
type: REST_OPTIONS_ERROR_TYPE,
|
|
59
|
+
message: readErrorMessage(error),
|
|
28
60
|
});
|
|
29
|
-
}, []);
|
|
30
|
-
if (loading) {
|
|
31
|
-
return createElement("div", null, "Loading options...");
|
|
32
|
-
}
|
|
33
|
-
if (error) {
|
|
34
|
-
return createElement("div", null, `Error: ${error}`);
|
|
35
|
-
}
|
|
36
|
-
return createElement(WrappedComponent, {
|
|
37
|
-
...props,
|
|
38
|
-
options: optionsData,
|
|
39
61
|
});
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
return () => controller.abort();
|
|
63
|
+
}, [url, name, setError, clearErrors, getFieldState]);
|
|
64
|
+
const isLoading = status === "loading";
|
|
65
|
+
return createElement(WrappedComponent, {
|
|
66
|
+
...props,
|
|
67
|
+
options: fetchedOptions,
|
|
68
|
+
disabled: props.disabled || isLoading,
|
|
69
|
+
"aria-busy": isLoading || undefined,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return WithRESTOptions;
|
|
73
|
+
};
|
|
74
|
+
const configureRESTOptions = createMiddleware(buildRESTOptions);
|
|
75
|
+
/**
|
|
76
|
+
* Fetches a field's options from a REST endpoint and passes them as the
|
|
77
|
+
* `options` prop.
|
|
78
|
+
*
|
|
79
|
+
* The field keeps its normal markup in every state. While loading it is
|
|
80
|
+
* disabled, marked `aria-busy`, and has no options. A failed request is set as
|
|
81
|
+
* the field's error, so it shows where the field shows any other error, and
|
|
82
|
+
* leaves the field enabled. The middleware can be created inline: the field
|
|
83
|
+
* keeps one instance, which fetches again only when the URL changes, and
|
|
84
|
+
* drops the answer for the previous URL, its error included. The request is
|
|
85
|
+
* aborted when the field unmounts. Use one per field: an inner instance's
|
|
86
|
+
* options replace the outer one's.
|
|
87
|
+
*
|
|
88
|
+
* @param url - The endpoint returning the options.
|
|
89
|
+
* @param options - Request and transform options.
|
|
90
|
+
* @returns A middleware for any field that takes `options`.
|
|
91
|
+
*
|
|
92
|
+
* `import { addRESTOptions } from "@canonical/react-ds-global-form";`
|
|
93
|
+
*/
|
|
94
|
+
function addRESTFieldOptions(url, options = {}) {
|
|
95
|
+
const { method = "GET", headers = {}, transformData } = options;
|
|
96
|
+
return configureRESTOptions({
|
|
97
|
+
url,
|
|
98
|
+
method,
|
|
99
|
+
headers,
|
|
100
|
+
transform: (data) => transformData ? transformData(data) : data,
|
|
101
|
+
});
|
|
42
102
|
}
|
|
43
103
|
export default addRESTFieldOptions;
|
|
44
104
|
//# sourceMappingURL=addRESTOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addRESTOptions.js","sourceRoot":"","sources":["../../../../../src/lib/utils/middleware/addRESTOptions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"addRESTOptions.js","sourceRoot":"","sources":["../../../../../src/lib/utils/middleware/addRESTOptions.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,38 +1,252 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { createElement, useEffect, useEffectEvent, useRef, } from "react";
|
|
2
|
+
import { useFormContext, useWatch, } from "react-hook-form";
|
|
3
|
+
import createMiddleware, {} from "../../common/Wrapper/createMiddleware.js";
|
|
4
|
+
/**
|
|
5
|
+
* The error type the middleware sets, and the name of the `validate` rule it
|
|
6
|
+
* registers, so it only ever clears its own error.
|
|
7
|
+
*/
|
|
8
|
+
const REST_VALIDATION_ERROR_TYPE = "restValidation";
|
|
9
|
+
/** The message shown when the endpoint rejects a value without a readable one. */
|
|
10
|
+
const DEFAULT_ERROR_MESSAGE = "Validation failed";
|
|
11
|
+
const VALID = { kind: "valid" };
|
|
12
|
+
const NO_ANSWER = { kind: "none" };
|
|
13
|
+
/** Reads the message of an error set by a REST check, if it is one. */
|
|
14
|
+
const readRESTMessage = (error) => error?.type === REST_VALIDATION_ERROR_TYPE ? error.message : undefined;
|
|
15
|
+
/** Whether a value is long enough, and a string, to be sent. */
|
|
16
|
+
const isCheckable = (value, minLength) => typeof value === "string" && value.length >= minLength;
|
|
17
|
+
/**
|
|
18
|
+
* Reads the message of a rejected value, falling back to the default when
|
|
19
|
+
* `errorExtractor` cannot read the response, so the value still shows as
|
|
20
|
+
* rejected.
|
|
21
|
+
*/
|
|
22
|
+
const readErrorMessage = async (response, errorExtractor) => {
|
|
23
|
+
try {
|
|
24
|
+
return await errorExtractor(response);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return DEFAULT_ERROR_MESSAGE;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Sends the value and reads the endpoint's answer. A request that fails to
|
|
32
|
+
* complete says nothing about the value. An aborted request's answer is never
|
|
33
|
+
* read: `startCheck` settles the check before it aborts the request.
|
|
34
|
+
* @note Impure: performs a network request.
|
|
35
|
+
*/
|
|
36
|
+
const requestAnswer = async (url, value, { method, headers, bodyFormatter, errorExtractor }, signal) => {
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(url, {
|
|
39
|
+
method,
|
|
40
|
+
headers,
|
|
41
|
+
body: JSON.stringify(bodyFormatter(value)),
|
|
42
|
+
signal,
|
|
43
|
+
});
|
|
44
|
+
if (response.ok)
|
|
45
|
+
return VALID;
|
|
46
|
+
const message = await readErrorMessage(response, errorExtractor);
|
|
47
|
+
return { kind: "invalid", message };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return NO_ANSWER;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Starts a check that sends the value once `debounceWait` has passed, and
|
|
55
|
+
* gives up on the request after `timeout`.
|
|
56
|
+
* @note Impure: schedules timers and a network request.
|
|
57
|
+
*/
|
|
58
|
+
const startCheck = (url, value, settings) => {
|
|
59
|
+
const controller = new AbortController();
|
|
60
|
+
let settle;
|
|
61
|
+
const answer = new Promise((resolve) => {
|
|
62
|
+
settle = resolve;
|
|
63
|
+
});
|
|
64
|
+
let requestTimer;
|
|
65
|
+
const cancel = () => {
|
|
66
|
+
clearTimeout(debounceTimer);
|
|
67
|
+
clearTimeout(requestTimer);
|
|
68
|
+
settle(NO_ANSWER);
|
|
69
|
+
controller.abort();
|
|
70
|
+
};
|
|
71
|
+
const debounceTimer = setTimeout(() => {
|
|
72
|
+
requestTimer = setTimeout(cancel, settings.timeout);
|
|
73
|
+
requestAnswer(url, value, settings, controller.signal).then((result) => {
|
|
74
|
+
clearTimeout(requestTimer);
|
|
75
|
+
settle(result);
|
|
76
|
+
});
|
|
77
|
+
}, settings.debounceWait);
|
|
78
|
+
return { url, value, answer, cancel };
|
|
79
|
+
};
|
|
80
|
+
/** Whether a `validate` rule's result lets the value through. */
|
|
81
|
+
const isPassing = (result) => result === true || result === undefined || result === null;
|
|
82
|
+
/**
|
|
83
|
+
* Runs two `validate` rules together and returns the first failure, so a
|
|
84
|
+
* second REST check on the field keeps the first one under the same name.
|
|
85
|
+
*/
|
|
86
|
+
const combineRules = (first, second) => async (value, formValues) => {
|
|
87
|
+
const [firstResult, secondResult] = await Promise.all([
|
|
88
|
+
first(value, formValues),
|
|
89
|
+
second(value, formValues),
|
|
90
|
+
]);
|
|
91
|
+
return isPassing(firstResult) ? secondResult : firstResult;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Adds a rule to the field's `validate` rules, keeping the rules it has. A
|
|
95
|
+
* single `validate` function stays under the `validate` name, the error type
|
|
96
|
+
* react-hook-form gives it. A `restValidation` rule already there, from
|
|
97
|
+
* another REST check on the field, runs together with the new one.
|
|
98
|
+
*/
|
|
99
|
+
const addValidateRule = (registerProps, rule) => {
|
|
100
|
+
const validate = registerProps?.validate;
|
|
101
|
+
const rules = typeof validate === "function" ? { validate } : validate;
|
|
102
|
+
const previous = rules?.[REST_VALIDATION_ERROR_TYPE];
|
|
103
|
+
return {
|
|
104
|
+
...registerProps,
|
|
105
|
+
validate: {
|
|
106
|
+
...rules,
|
|
107
|
+
[REST_VALIDATION_ERROR_TYPE]: previous
|
|
108
|
+
? combineRules(previous, rule)
|
|
109
|
+
: rule,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
/** Builds the component that checks the value and owns the REST error. */
|
|
114
|
+
const buildRESTValidation = (WrappedComponent, useSettings) => {
|
|
115
|
+
function WithRESTValidation(props) {
|
|
116
|
+
const { name } = props;
|
|
117
|
+
const settings = useSettings();
|
|
118
|
+
const { url } = settings;
|
|
119
|
+
const { setError, clearErrors, getFieldState } = useFormContext();
|
|
120
|
+
const value = useWatch({ name });
|
|
121
|
+
const pending = useRef(null);
|
|
122
|
+
// The message this instance last gave, so a second REST check on the
|
|
123
|
+
// field cannot clear or keep the other one's message. A REST message left
|
|
124
|
+
// from before the field mounted is adopted, so it can still be cleared.
|
|
125
|
+
const ownMessage = useRef(readRESTMessage(getFieldState(name).error));
|
|
126
|
+
/** Reads the field's error message when this instance set it. */
|
|
127
|
+
const readOwnMessage = () => {
|
|
128
|
+
const message = readRESTMessage(getFieldState(name).error);
|
|
129
|
+
return message === ownMessage.current ? message : undefined;
|
|
130
|
+
};
|
|
131
|
+
/** Clears the field's error when this instance set it. */
|
|
132
|
+
const clearOwnError = () => {
|
|
133
|
+
if (readOwnMessage() !== undefined)
|
|
134
|
+
clearErrors(name);
|
|
135
|
+
ownMessage.current = undefined;
|
|
136
|
+
};
|
|
137
|
+
/** Sets the endpoint's rejection as the field's error. */
|
|
138
|
+
const setOwnError = (message) => {
|
|
139
|
+
ownMessage.current = message;
|
|
140
|
+
setError(name, { type: REST_VALIDATION_ERROR_TYPE, message });
|
|
141
|
+
};
|
|
142
|
+
/** Stops the pending check, if any. */
|
|
143
|
+
const cancelPending = () => {
|
|
144
|
+
pending.current?.cancel();
|
|
145
|
+
pending.current = null;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Resolves to the answer for a value, sharing the pending check when it is
|
|
149
|
+
* for the same value and URL, so typing and submitting send one request.
|
|
150
|
+
* A newer value cancels the previous check, so only the answer for the
|
|
151
|
+
* latest value is ever used. A check that got no answer is dropped, so the
|
|
152
|
+
* next one asks again.
|
|
153
|
+
*/
|
|
154
|
+
const check = (checkUrl, checkValue) => {
|
|
155
|
+
const current = pending.current;
|
|
156
|
+
if (current?.url === checkUrl && current.value === checkValue) {
|
|
157
|
+
return current.answer;
|
|
158
|
+
}
|
|
159
|
+
cancelPending();
|
|
160
|
+
const next = startCheck(checkUrl, checkValue, settings);
|
|
161
|
+
pending.current = next;
|
|
162
|
+
next.answer.then((answer) => {
|
|
163
|
+
if (answer.kind === "none" && pending.current === next) {
|
|
164
|
+
pending.current = null;
|
|
23
165
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
166
|
+
});
|
|
167
|
+
return next.answer;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* The `validate` rule react-hook-form runs, on submit among others, so a
|
|
171
|
+
* value the endpoint rejected cannot be submitted. Without an answer it
|
|
172
|
+
* keeps the message this middleware last set.
|
|
173
|
+
*/
|
|
174
|
+
const validateRemotely = async (fieldValue) => {
|
|
175
|
+
if (!isCheckable(fieldValue, settings.minLength))
|
|
176
|
+
return true;
|
|
177
|
+
const answer = await check(url, fieldValue);
|
|
178
|
+
if (answer.kind === "valid") {
|
|
179
|
+
ownMessage.current = undefined;
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
if (answer.kind === "invalid") {
|
|
183
|
+
ownMessage.current = answer.message;
|
|
184
|
+
return answer.message;
|
|
185
|
+
}
|
|
186
|
+
return readOwnMessage() || true;
|
|
187
|
+
};
|
|
188
|
+
const followValue = useEffectEvent((nextValue, nextUrl) => {
|
|
189
|
+
if (!isCheckable(nextValue, settings.minLength)) {
|
|
190
|
+
cancelPending();
|
|
191
|
+
clearOwnError();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
check(nextUrl, nextValue).then((answer) => {
|
|
195
|
+
if (answer.kind === "valid") {
|
|
196
|
+
clearOwnError();
|
|
28
197
|
}
|
|
29
|
-
else {
|
|
30
|
-
|
|
198
|
+
else if (answer.kind === "invalid") {
|
|
199
|
+
setOwnError(answer.message);
|
|
31
200
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
|
|
201
|
+
// A check without an answer leaves the field's error as it is.
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
useEffect(() => followValue(value, url), [value, url]);
|
|
205
|
+
useEffect(() => () => {
|
|
206
|
+
pending.current?.cancel();
|
|
207
|
+
pending.current = null;
|
|
208
|
+
}, []);
|
|
209
|
+
return createElement(WrappedComponent, {
|
|
210
|
+
...props,
|
|
211
|
+
registerProps: addValidateRule(props.registerProps, validateRemotely),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return WithRESTValidation;
|
|
215
|
+
};
|
|
216
|
+
const configureRESTValidation = createMiddleware(buildRESTValidation);
|
|
217
|
+
/**
|
|
218
|
+
* Validates a field's value against a REST endpoint once the user stops
|
|
219
|
+
* typing, and sets the field's error when the endpoint rejects it.
|
|
220
|
+
*
|
|
221
|
+
* The check is also registered as the field's `restValidation` rule, so
|
|
222
|
+
* submitting re-checks the value and a rejected value blocks the submit. Each
|
|
223
|
+
* change cancels the pending timer and aborts the request in flight, so only
|
|
224
|
+
* the answer for the latest value can set or clear the error; unmounting the
|
|
225
|
+
* field does the same. A request that fails to complete keeps the previous
|
|
226
|
+
* message, and a request still unanswered after `timeout` is given up. It
|
|
227
|
+
* only clears the error it set, so an error from the field's own rules or
|
|
228
|
+
* another middleware stays in place. Two instances on one field each keep
|
|
229
|
+
* their own message, and submit runs both checks. The middleware can be
|
|
230
|
+
* created inline: the field keeps one instance.
|
|
231
|
+
*
|
|
232
|
+
* @param url - The endpoint validating the value.
|
|
233
|
+
* @param options - Request, debounce and error options.
|
|
234
|
+
* @returns A middleware for any field.
|
|
235
|
+
*
|
|
236
|
+
* `import { addRESTValidation } from "@canonical/react-ds-global-form";`
|
|
237
|
+
*/
|
|
238
|
+
function addRESTFieldValidation(url, options = {}) {
|
|
239
|
+
const { method = "POST", headers = { "Content-Type": "application/json" }, bodyFormatter = (value) => ({ value }), errorExtractor = () => DEFAULT_ERROR_MESSAGE, minLength = 3, debounceWait = 300, timeout = 10000, } = options;
|
|
240
|
+
return configureRESTValidation({
|
|
241
|
+
url,
|
|
242
|
+
method,
|
|
243
|
+
headers,
|
|
244
|
+
bodyFormatter,
|
|
245
|
+
errorExtractor,
|
|
246
|
+
minLength,
|
|
247
|
+
debounceWait,
|
|
248
|
+
timeout,
|
|
249
|
+
});
|
|
36
250
|
}
|
|
37
251
|
export default addRESTFieldValidation;
|
|
38
252
|
//# sourceMappingURL=addRESTValidation.js.map
|