@wordpress/components 29.12.0 → 30.0.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/CHANGELOG.md +23 -0
- package/build/autocomplete/index.js +4 -0
- package/build/autocomplete/index.js.map +1 -1
- package/build/box-control/input-control.js +2 -2
- package/build/box-control/input-control.js.map +1 -1
- package/build/calendar/date-calendar/index.js +69 -0
- package/build/calendar/date-calendar/index.js.map +1 -0
- package/build/calendar/date-range-calendar/index.js +172 -0
- package/build/calendar/date-range-calendar/index.js.map +1 -0
- package/build/calendar/index.js +27 -0
- package/build/calendar/index.js.map +1 -0
- package/build/calendar/types.js +6 -0
- package/build/calendar/types.js.map +1 -0
- package/build/calendar/utils/constants.js +68 -0
- package/build/calendar/utils/constants.js.map +1 -0
- package/build/calendar/utils/day-cell.js +137 -0
- package/build/calendar/utils/day-cell.js.map +1 -0
- package/build/calendar/utils/misc.js +10 -0
- package/build/calendar/utils/misc.js.map +1 -0
- package/build/calendar/utils/use-localization-props.js +162 -0
- package/build/calendar/utils/use-localization-props.js.map +1 -0
- package/build/custom-gradient-picker/gradient-bar/control-points.js +1 -1
- package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build/custom-select-control-v2/custom-select.js +3 -3
- package/build/custom-select-control-v2/custom-select.js.map +1 -1
- package/build/date-time/date/index.js +1 -1
- package/build/date-time/date/index.js.map +1 -1
- package/build/form-token-field/index.js +11 -1
- package/build/form-token-field/index.js.map +1 -1
- package/build/form-token-field/token.js +1 -1
- package/build/form-token-field/token.js.map +1 -1
- package/build/icon/index.js +2 -0
- package/build/icon/index.js.map +1 -1
- package/build/mobile/bottom-sheet/cell.native.js +2 -2
- package/build/mobile/bottom-sheet/cell.native.js.map +1 -1
- package/build/mobile/link-picker/index.native.js +1 -1
- package/build/mobile/link-picker/index.native.js.map +1 -1
- package/build/navigation/menu/menu-title-search.js +1 -1
- package/build/navigation/menu/menu-title-search.js.map +1 -1
- package/build/palette-edit/index.js +4 -4
- package/build/palette-edit/index.js.map +1 -1
- package/build/private-apis.js +5 -1
- package/build/private-apis.js.map +1 -1
- package/build/select-control/index.js +1 -1
- package/build/select-control/index.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
- package/build/utils/hooks/use-controlled-value.js +8 -4
- package/build/utils/hooks/use-controlled-value.js.map +1 -1
- package/build/validated-form-controls/components/checkbox-control.js +52 -0
- package/build/validated-form-controls/components/checkbox-control.js.map +1 -0
- package/build/validated-form-controls/components/combobox-control.js +64 -0
- package/build/validated-form-controls/components/combobox-control.js.map +1 -0
- package/build/validated-form-controls/components/custom-select-control.js +71 -0
- package/build/validated-form-controls/components/custom-select-control.js.map +1 -0
- package/build/validated-form-controls/components/index.js +138 -0
- package/build/validated-form-controls/components/index.js.map +1 -0
- package/build/validated-form-controls/components/input-control.js +50 -0
- package/build/validated-form-controls/components/input-control.js.map +1 -0
- package/build/validated-form-controls/components/number-control.js +53 -0
- package/build/validated-form-controls/components/number-control.js.map +1 -0
- package/build/validated-form-controls/components/radio-control.js +51 -0
- package/build/validated-form-controls/components/radio-control.js.map +1 -0
- package/build/validated-form-controls/components/range-control.js +51 -0
- package/build/validated-form-controls/components/range-control.js.map +1 -0
- package/build/validated-form-controls/components/select-control.js +53 -0
- package/build/validated-form-controls/components/select-control.js.map +1 -0
- package/build/validated-form-controls/components/text-control.js +51 -0
- package/build/validated-form-controls/components/text-control.js.map +1 -0
- package/build/validated-form-controls/components/textarea-control.js +50 -0
- package/build/validated-form-controls/components/textarea-control.js.map +1 -0
- package/build/validated-form-controls/components/toggle-control.js +60 -0
- package/build/validated-form-controls/components/toggle-control.js.map +1 -0
- package/build/validated-form-controls/components/toggle-group-control.js +69 -0
- package/build/validated-form-controls/components/toggle-group-control.js.map +1 -0
- package/build/validated-form-controls/components/types.js +6 -0
- package/build/validated-form-controls/components/types.js.map +1 -0
- package/build/validated-form-controls/control-with-error.js +137 -0
- package/build/validated-form-controls/control-with-error.js.map +1 -0
- package/build/validated-form-controls/index.js +28 -0
- package/build/validated-form-controls/index.js.map +1 -0
- package/build-module/autocomplete/index.js +4 -0
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/box-control/input-control.js +2 -2
- package/build-module/box-control/input-control.js.map +1 -1
- package/build-module/calendar/date-calendar/index.js +59 -0
- package/build-module/calendar/date-calendar/index.js.map +1 -0
- package/build-module/calendar/date-range-calendar/index.js +161 -0
- package/build-module/calendar/date-range-calendar/index.js.map +1 -0
- package/build-module/calendar/index.js +4 -0
- package/build-module/calendar/index.js.map +1 -0
- package/build-module/calendar/types.js +2 -0
- package/build-module/calendar/types.js.map +1 -0
- package/build-module/calendar/utils/constants.js +61 -0
- package/build-module/calendar/utils/constants.js.map +1 -0
- package/build-module/calendar/utils/day-cell.js +131 -0
- package/build-module/calendar/utils/day-cell.js.map +1 -0
- package/build-module/calendar/utils/misc.js +4 -0
- package/build-module/calendar/utils/misc.js.map +1 -0
- package/build-module/calendar/utils/use-localization-props.js +154 -0
- package/build-module/calendar/utils/use-localization-props.js.map +1 -0
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build-module/custom-select-control-v2/custom-select.js +4 -4
- package/build-module/custom-select-control-v2/custom-select.js.map +1 -1
- package/build-module/date-time/date/index.js +1 -1
- package/build-module/date-time/date/index.js.map +1 -1
- package/build-module/form-token-field/index.js +11 -1
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/form-token-field/token.js +1 -1
- package/build-module/form-token-field/token.js.map +1 -1
- package/build-module/icon/index.js +2 -0
- package/build-module/icon/index.js.map +1 -1
- package/build-module/mobile/bottom-sheet/cell.native.js +2 -2
- package/build-module/mobile/bottom-sheet/cell.native.js.map +1 -1
- package/build-module/mobile/link-picker/index.native.js +1 -1
- package/build-module/mobile/link-picker/index.native.js.map +1 -1
- package/build-module/navigation/menu/menu-title-search.js +1 -1
- package/build-module/navigation/menu/menu-title-search.js.map +1 -1
- package/build-module/palette-edit/index.js +4 -4
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/private-apis.js +5 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/select-control/index.js +1 -1
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
- package/build-module/utils/hooks/use-controlled-value.js +9 -5
- package/build-module/utils/hooks/use-controlled-value.js.map +1 -1
- package/build-module/validated-form-controls/components/checkbox-control.js +44 -0
- package/build-module/validated-form-controls/components/checkbox-control.js.map +1 -0
- package/build-module/validated-form-controls/components/combobox-control.js +56 -0
- package/build-module/validated-form-controls/components/combobox-control.js.map +1 -0
- package/build-module/validated-form-controls/components/custom-select-control.js +63 -0
- package/build-module/validated-form-controls/components/custom-select-control.js.map +1 -0
- package/build-module/validated-form-controls/components/index.js +13 -0
- package/build-module/validated-form-controls/components/index.js.map +1 -0
- package/build-module/validated-form-controls/components/input-control.js +42 -0
- package/build-module/validated-form-controls/components/input-control.js.map +1 -0
- package/build-module/validated-form-controls/components/number-control.js +45 -0
- package/build-module/validated-form-controls/components/number-control.js.map +1 -0
- package/build-module/validated-form-controls/components/radio-control.js +43 -0
- package/build-module/validated-form-controls/components/radio-control.js.map +1 -0
- package/build-module/validated-form-controls/components/range-control.js +43 -0
- package/build-module/validated-form-controls/components/range-control.js.map +1 -0
- package/build-module/validated-form-controls/components/select-control.js +45 -0
- package/build-module/validated-form-controls/components/select-control.js.map +1 -0
- package/build-module/validated-form-controls/components/text-control.js +43 -0
- package/build-module/validated-form-controls/components/text-control.js.map +1 -0
- package/build-module/validated-form-controls/components/textarea-control.js +42 -0
- package/build-module/validated-form-controls/components/textarea-control.js.map +1 -0
- package/build-module/validated-form-controls/components/toggle-control.js +52 -0
- package/build-module/validated-form-controls/components/toggle-control.js.map +1 -0
- package/build-module/validated-form-controls/components/toggle-group-control.js +62 -0
- package/build-module/validated-form-controls/components/toggle-group-control.js.map +1 -0
- package/build-module/validated-form-controls/components/types.js +2 -0
- package/build-module/validated-form-controls/components/types.js.map +1 -0
- package/build-module/validated-form-controls/control-with-error.js +129 -0
- package/build-module/validated-form-controls/control-with-error.js.map +1 -0
- package/build-module/validated-form-controls/index.js +3 -0
- package/build-module/validated-form-controls/index.js.map +1 -0
- package/build-style/style-rtl.css +418 -22
- package/build-style/style.css +418 -22
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/box-control/input-control.d.ts.map +1 -1
- package/build-types/box-control/utils.d.ts +7 -7
- package/build-types/calendar/date-calendar/index.d.ts +11 -0
- package/build-types/calendar/date-calendar/index.d.ts.map +1 -0
- package/build-types/calendar/date-range-calendar/index.d.ts +14 -0
- package/build-types/calendar/date-range-calendar/index.d.ts.map +1 -0
- package/build-types/calendar/index.d.ts +4 -0
- package/build-types/calendar/index.d.ts.map +1 -0
- package/build-types/calendar/stories/date-calendar.story.d.ts +16 -0
- package/build-types/calendar/stories/date-calendar.story.d.ts.map +1 -0
- package/build-types/calendar/stories/date-range-calendar.story.d.ts +16 -0
- package/build-types/calendar/stories/date-range-calendar.story.d.ts.map +1 -0
- package/build-types/calendar/test/__utils__/index.d.ts +10 -0
- package/build-types/calendar/test/__utils__/index.d.ts.map +1 -0
- package/build-types/calendar/test/date-calendar.d.ts +2 -0
- package/build-types/calendar/test/date-calendar.d.ts.map +1 -0
- package/build-types/calendar/test/date-range-calendar.d.ts +2 -0
- package/build-types/calendar/test/date-range-calendar.d.ts.map +1 -0
- package/build-types/calendar/types.d.ts +317 -0
- package/build-types/calendar/types.d.ts.map +1 -0
- package/build-types/calendar/utils/constants.d.ts +52 -0
- package/build-types/calendar/utils/constants.d.ts.map +1 -0
- package/build-types/calendar/utils/day-cell.d.ts +21 -0
- package/build-types/calendar/utils/day-cell.d.ts.map +1 -0
- package/build-types/calendar/utils/misc.d.ts +2 -0
- package/build-types/calendar/utils/misc.d.ts.map +1 -0
- package/build-types/calendar/utils/use-localization-props.d.ts +64 -0
- package/build-types/calendar/utils/use-localization-props.d.ts.map +1 -0
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/constants.d.ts +6 -3
- package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/custom-select.d.ts.map +1 -1
- package/build-types/dimension-control/sizes.d.ts +15 -3
- package/build-types/dimension-control/sizes.d.ts.map +1 -1
- package/build-types/font-size-picker/constants.d.ts +2 -2
- package/build-types/font-size-picker/constants.d.ts.map +1 -1
- package/build-types/form-token-field/index.d.ts.map +1 -1
- package/build-types/icon/index.d.ts.map +1 -1
- package/build-types/popover/overlay-middlewares.d.ts +6 -1
- package/build-types/popover/overlay-middlewares.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/select-control/stories/index.story.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts.map +1 -1
- package/build-types/utils/hooks/use-controlled-value.d.ts +2 -2
- package/build-types/utils/hooks/use-controlled-value.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/checkbox-control.d.ts +9 -0
- package/build-types/validated-form-controls/components/checkbox-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/combobox-control.d.ts +21 -0
- package/build-types/validated-form-controls/components/combobox-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/custom-select-control.d.ts +4 -0
- package/build-types/validated-form-controls/components/custom-select-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/index.d.ts +13 -0
- package/build-types/validated-form-controls/components/index.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/input-control.d.ts +4 -0
- package/build-types/validated-form-controls/components/input-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/number-control.d.ts +17 -0
- package/build-types/validated-form-controls/components/number-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/radio-control.d.ts +11 -0
- package/build-types/validated-form-controls/components/radio-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/range-control.d.ts +36 -0
- package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/select-control.d.ts +9 -0
- package/build-types/validated-form-controls/components/select-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/input-control.story.d.ts +18 -0
- package/build-types/validated-form-controls/components/stories/input-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/number-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/number-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts +19 -0
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/range-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/range-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/select-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/select-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/story-utils.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/story-utils.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/text-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/text-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/text-control.d.ts +8 -0
- package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/textarea-control.d.ts +7 -0
- package/build-types/validated-form-controls/components/textarea-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/toggle-control.d.ts +7 -0
- package/build-types/validated-form-controls/components/toggle-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/toggle-group-control.d.ts +15 -0
- package/build-types/validated-form-controls/components/toggle-group-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/types.d.ts +27 -0
- package/build-types/validated-form-controls/components/types.d.ts.map +1 -0
- package/build-types/validated-form-controls/control-with-error.d.ts +36 -0
- package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -0
- package/build-types/validated-form-controls/index.d.ts +3 -0
- package/build-types/validated-form-controls/index.d.ts.map +1 -0
- package/package.json +21 -20
- package/src/autocomplete/index.tsx +4 -0
- package/src/box-control/input-control.tsx +14 -5
- package/src/calendar/date-calendar/README.md +261 -0
- package/src/calendar/date-calendar/index.tsx +69 -0
- package/src/calendar/date-range-calendar/README.md +298 -0
- package/src/calendar/date-range-calendar/index.tsx +215 -0
- package/src/calendar/index.tsx +3 -0
- package/src/calendar/stories/date-calendar.story.tsx +221 -0
- package/src/calendar/stories/date-range-calendar.story.tsx +230 -0
- package/src/calendar/style.scss +431 -0
- package/src/calendar/test/__utils__/index.ts +56 -0
- package/src/calendar/test/date-calendar.tsx +975 -0
- package/src/calendar/test/date-range-calendar.tsx +1701 -0
- package/src/calendar/types.ts +342 -0
- package/src/calendar/utils/constants.ts +62 -0
- package/src/calendar/utils/day-cell.tsx +133 -0
- package/src/calendar/utils/misc.ts +3 -0
- package/src/calendar/utils/use-localization-props.ts +169 -0
- package/src/custom-gradient-picker/gradient-bar/control-points.tsx +1 -1
- package/src/custom-select-control-v2/custom-select.tsx +6 -3
- package/src/date-time/date/index.tsx +1 -1
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +8 -8
- package/src/form-token-field/index.tsx +12 -1
- package/src/form-token-field/token.tsx +1 -1
- package/src/icon/index.tsx +2 -0
- package/src/mobile/bottom-sheet/cell.native.js +2 -2
- package/src/mobile/link-picker/index.native.js +1 -1
- package/src/navigation/menu/menu-title-search.tsx +1 -1
- package/src/palette-edit/index.tsx +4 -4
- package/src/private-apis.ts +5 -0
- package/src/select-control/index.tsx +1 -1
- package/src/select-control/style.scss +0 -6
- package/src/style.scss +3 -2
- package/src/toggle-group-control/toggle-group-control/as-button-group.tsx +3 -1
- package/src/utils/hooks/use-controlled-value.ts +16 -8
- package/src/validated-form-controls/components/checkbox-control.tsx +64 -0
- package/src/validated-form-controls/components/combobox-control.tsx +77 -0
- package/src/validated-form-controls/components/custom-select-control.tsx +86 -0
- package/src/validated-form-controls/components/index.ts +12 -0
- package/src/validated-form-controls/components/input-control.tsx +59 -0
- package/src/validated-form-controls/components/number-control.tsx +61 -0
- package/src/validated-form-controls/components/radio-control.tsx +60 -0
- package/src/validated-form-controls/components/range-control.tsx +60 -0
- package/src/validated-form-controls/components/select-control.tsx +75 -0
- package/src/validated-form-controls/components/stories/checkbox-control.story.tsx +57 -0
- package/src/validated-form-controls/components/stories/combobox-control.story.tsx +64 -0
- package/src/validated-form-controls/components/stories/custom-select-control.story.tsx +64 -0
- package/src/validated-form-controls/components/stories/input-control.story.tsx +132 -0
- package/src/validated-form-controls/components/stories/number-control.story.tsx +62 -0
- package/src/validated-form-controls/components/stories/overview.mdx +52 -0
- package/src/validated-form-controls/components/stories/overview.story.tsx +100 -0
- package/src/validated-form-controls/components/stories/radio-control.story.tsx +64 -0
- package/src/validated-form-controls/components/stories/range-control.story.tsx +60 -0
- package/src/validated-form-controls/components/stories/select-control.story.tsx +60 -0
- package/src/validated-form-controls/components/stories/story-utils.tsx +46 -0
- package/src/validated-form-controls/components/stories/text-control.story.tsx +55 -0
- package/src/validated-form-controls/components/stories/textarea-control.story.tsx +52 -0
- package/src/validated-form-controls/components/stories/toggle-control.story.tsx +55 -0
- package/src/validated-form-controls/components/stories/toggle-group-control.story.tsx +66 -0
- package/src/validated-form-controls/components/text-control.tsx +60 -0
- package/src/validated-form-controls/components/textarea-control.tsx +59 -0
- package/src/validated-form-controls/components/toggle-control.tsx +69 -0
- package/src/validated-form-controls/components/toggle-group-control.tsx +82 -0
- package/src/validated-form-controls/components/types.ts +28 -0
- package/src/validated-form-controls/control-with-error.tsx +198 -0
- package/src/validated-form-controls/index.ts +2 -0
- package/src/validated-form-controls/style.scss +75 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/dimension-control/style.scss +0 -22
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { ValidatedInputControl } from '..';
|
|
15
|
+
import { formDecorator } from './story-utils';
|
|
16
|
+
import type { ControlWithError } from '../../control-with-error';
|
|
17
|
+
|
|
18
|
+
const meta: Meta< typeof ControlWithError > = {
|
|
19
|
+
title: 'Components (Experimental)/Validated Form Controls/Overview',
|
|
20
|
+
tags: [ 'status-private' ],
|
|
21
|
+
decorators: formDecorator,
|
|
22
|
+
};
|
|
23
|
+
export default meta;
|
|
24
|
+
|
|
25
|
+
type Story = StoryObj< typeof ControlWithError >;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* When there are multiple controls with errors, attempting to submit will
|
|
29
|
+
* move focus to the first control with an error.
|
|
30
|
+
*/
|
|
31
|
+
export const WithMultipleControls: Story = {
|
|
32
|
+
render: function Template() {
|
|
33
|
+
const [ text, setText ] = useState( '' );
|
|
34
|
+
const [ text2, setText2 ] = useState( '' );
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
<ValidatedInputControl
|
|
39
|
+
label="Text"
|
|
40
|
+
required
|
|
41
|
+
value={ text }
|
|
42
|
+
help="The word 'error' will trigger an error."
|
|
43
|
+
customValidator={ ( value ) => {
|
|
44
|
+
if ( value?.toLowerCase() === 'error' ) {
|
|
45
|
+
return 'The word "error" is not allowed.';
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
} }
|
|
49
|
+
onChange={ ( value ) => setText( value ?? '' ) }
|
|
50
|
+
/>
|
|
51
|
+
<ValidatedInputControl
|
|
52
|
+
label="Text"
|
|
53
|
+
required
|
|
54
|
+
value={ text2 }
|
|
55
|
+
help="The word 'error' will trigger an error."
|
|
56
|
+
customValidator={ ( value ) => {
|
|
57
|
+
if ( value?.toLowerCase() === 'error' ) {
|
|
58
|
+
return 'The word "error" is not allowed.';
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
} }
|
|
62
|
+
onChange={ ( value ) => setText2( value ?? '' ) }
|
|
63
|
+
/>
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Help text can be configured to be hidden when a custom error is reported. Whether to opt for this approach
|
|
71
|
+
* will depend on context.
|
|
72
|
+
*/
|
|
73
|
+
export const WithHelpTextReplacement: Story = {
|
|
74
|
+
render: function Template() {
|
|
75
|
+
const [ text, setText ] = useState( '' );
|
|
76
|
+
const [ hasCustomError, setHasCustomError ] = useState( false );
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<ValidatedInputControl
|
|
80
|
+
label="Text"
|
|
81
|
+
required
|
|
82
|
+
value={ text }
|
|
83
|
+
help={
|
|
84
|
+
hasCustomError
|
|
85
|
+
? undefined
|
|
86
|
+
: 'The word "error" is not allowed.'
|
|
87
|
+
}
|
|
88
|
+
customValidator={ ( value ) => {
|
|
89
|
+
if ( value?.toLowerCase() === 'error' ) {
|
|
90
|
+
setHasCustomError( true );
|
|
91
|
+
return 'The word "error" is not allowed.';
|
|
92
|
+
}
|
|
93
|
+
setHasCustomError( false );
|
|
94
|
+
return undefined;
|
|
95
|
+
} }
|
|
96
|
+
onChange={ ( value ) => setText( value ?? '' ) }
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { ValidatedRadioControl } from '../radio-control';
|
|
15
|
+
import { formDecorator } from './story-utils';
|
|
16
|
+
|
|
17
|
+
const meta: Meta< typeof ValidatedRadioControl > = {
|
|
18
|
+
title: 'Components (Experimental)/Validated Form Controls/ValidatedRadioControl',
|
|
19
|
+
component: ValidatedRadioControl,
|
|
20
|
+
tags: [ 'status-private' ],
|
|
21
|
+
decorators: formDecorator,
|
|
22
|
+
args: { onChange: () => {} },
|
|
23
|
+
argTypes: {
|
|
24
|
+
selected: { control: false },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
export const Default: StoryObj< typeof ValidatedRadioControl > = {
|
|
30
|
+
render: function Template( { onChange, ...args } ) {
|
|
31
|
+
const [ selected, setSelected ] =
|
|
32
|
+
useState<
|
|
33
|
+
React.ComponentProps<
|
|
34
|
+
typeof ValidatedRadioControl
|
|
35
|
+
>[ 'selected' ]
|
|
36
|
+
>();
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ValidatedRadioControl
|
|
40
|
+
{ ...args }
|
|
41
|
+
selected={ selected }
|
|
42
|
+
onChange={ ( value ) => {
|
|
43
|
+
setSelected( value );
|
|
44
|
+
onChange?.( value );
|
|
45
|
+
} }
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
Default.args = {
|
|
51
|
+
required: true,
|
|
52
|
+
label: 'Radio',
|
|
53
|
+
help: 'Option B is not allowed.',
|
|
54
|
+
options: [
|
|
55
|
+
{ label: 'Option A', value: 'a' },
|
|
56
|
+
{ label: 'Option B (not allowed)', value: 'b' },
|
|
57
|
+
],
|
|
58
|
+
customValidator: ( value ) => {
|
|
59
|
+
if ( value === 'b' ) {
|
|
60
|
+
return 'Option B is not allowed.';
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { formDecorator } from './story-utils';
|
|
15
|
+
import { ValidatedRangeControl } from '../range-control';
|
|
16
|
+
|
|
17
|
+
const meta: Meta< typeof ValidatedRangeControl > = {
|
|
18
|
+
title: 'Components (Experimental)/Validated Form Controls/ValidatedRangeControl',
|
|
19
|
+
component: ValidatedRangeControl,
|
|
20
|
+
tags: [ 'status-private' ],
|
|
21
|
+
decorators: formDecorator,
|
|
22
|
+
args: { onChange: () => {} },
|
|
23
|
+
argTypes: {
|
|
24
|
+
value: { control: false },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
export const Default: StoryObj< typeof ValidatedRangeControl > = {
|
|
30
|
+
render: function Template( { onChange, ...args } ) {
|
|
31
|
+
const [ value, setValue ] =
|
|
32
|
+
useState<
|
|
33
|
+
React.ComponentProps< typeof ValidatedRangeControl >[ 'value' ]
|
|
34
|
+
>();
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<ValidatedRangeControl
|
|
38
|
+
{ ...args }
|
|
39
|
+
value={ value }
|
|
40
|
+
onChange={ ( newValue ) => {
|
|
41
|
+
setValue( newValue );
|
|
42
|
+
onChange?.( newValue );
|
|
43
|
+
} }
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
Default.args = {
|
|
49
|
+
required: true,
|
|
50
|
+
label: 'Range',
|
|
51
|
+
help: 'Odd numbers are not allowed.',
|
|
52
|
+
min: 0,
|
|
53
|
+
max: 20,
|
|
54
|
+
customValidator: ( value ) => {
|
|
55
|
+
if ( value && value % 2 !== 0 ) {
|
|
56
|
+
return 'Choose an even number.';
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { ValidatedSelectControl } from '../select-control';
|
|
15
|
+
import { formDecorator } from './story-utils';
|
|
16
|
+
|
|
17
|
+
const meta: Meta< typeof ValidatedSelectControl > = {
|
|
18
|
+
title: 'Components (Experimental)/Validated Form Controls/ValidatedSelectControl',
|
|
19
|
+
component: ValidatedSelectControl,
|
|
20
|
+
tags: [ 'status-private' ],
|
|
21
|
+
decorators: formDecorator,
|
|
22
|
+
args: { onChange: () => {} },
|
|
23
|
+
argTypes: {
|
|
24
|
+
value: { control: false },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
export const Default: StoryObj< typeof ValidatedSelectControl > = {
|
|
30
|
+
render: function Template( { onChange, ...args } ) {
|
|
31
|
+
const [ value, setValue ] = useState( '' );
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<ValidatedSelectControl
|
|
35
|
+
{ ...args }
|
|
36
|
+
value={ value }
|
|
37
|
+
onChange={ ( newValue ) => {
|
|
38
|
+
setValue( newValue );
|
|
39
|
+
onChange?.( newValue );
|
|
40
|
+
} }
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
Default.args = {
|
|
46
|
+
required: true,
|
|
47
|
+
label: 'Select',
|
|
48
|
+
help: 'Selecting option 1 will trigger an error.',
|
|
49
|
+
options: [
|
|
50
|
+
{ value: '', label: 'Select an option' },
|
|
51
|
+
{ value: '1', label: 'Option 1 (not allowed)' },
|
|
52
|
+
{ value: '2', label: 'Option 2' },
|
|
53
|
+
],
|
|
54
|
+
customValidator: ( value ) => {
|
|
55
|
+
if ( value === '1' ) {
|
|
56
|
+
return 'Option 1 is not allowed.';
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* External dependencies
|
|
7
|
+
*/
|
|
8
|
+
import type { Meta } from '@storybook/react';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import Button from '../../../button';
|
|
14
|
+
|
|
15
|
+
export const formDecorator: Meta[ 'decorators' ] = ( Story ) => (
|
|
16
|
+
<form
|
|
17
|
+
style={ {
|
|
18
|
+
fontFamily: 'sans-serif',
|
|
19
|
+
display: 'flex',
|
|
20
|
+
flexDirection: 'column',
|
|
21
|
+
alignItems: 'flex-start',
|
|
22
|
+
gap: 16,
|
|
23
|
+
} }
|
|
24
|
+
onSubmit={ ( e ) => {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
// eslint-disable-next-line no-alert
|
|
27
|
+
alert( 'Form submitted!' );
|
|
28
|
+
} }
|
|
29
|
+
>
|
|
30
|
+
<div
|
|
31
|
+
style={ {
|
|
32
|
+
display: 'flex',
|
|
33
|
+
flexDirection: 'column',
|
|
34
|
+
gap: 16,
|
|
35
|
+
alignItems: 'stretch',
|
|
36
|
+
width: 300,
|
|
37
|
+
} }
|
|
38
|
+
>
|
|
39
|
+
<Story />
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<Button variant="primary" type="submit" __next40pxDefaultSize>
|
|
43
|
+
Submit
|
|
44
|
+
</Button>
|
|
45
|
+
</form>
|
|
46
|
+
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { formDecorator } from './story-utils';
|
|
15
|
+
import { ValidatedTextControl } from '../text-control';
|
|
16
|
+
|
|
17
|
+
const meta: Meta< typeof ValidatedTextControl > = {
|
|
18
|
+
title: 'Components (Experimental)/Validated Form Controls/ValidatedTextControl',
|
|
19
|
+
component: ValidatedTextControl,
|
|
20
|
+
tags: [ 'status-private' ],
|
|
21
|
+
decorators: formDecorator,
|
|
22
|
+
args: { onChange: () => {} },
|
|
23
|
+
argTypes: {
|
|
24
|
+
value: { control: false },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
export const Default: StoryObj< typeof ValidatedTextControl > = {
|
|
30
|
+
render: function Template( { onChange, ...args } ) {
|
|
31
|
+
const [ value, setValue ] = useState( '' );
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<ValidatedTextControl
|
|
35
|
+
{ ...args }
|
|
36
|
+
value={ value }
|
|
37
|
+
onChange={ ( newValue ) => {
|
|
38
|
+
setValue( newValue );
|
|
39
|
+
onChange?.( newValue );
|
|
40
|
+
} }
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
Default.args = {
|
|
46
|
+
required: true,
|
|
47
|
+
label: 'Text',
|
|
48
|
+
help: "The word 'error' will trigger an error.",
|
|
49
|
+
customValidator: ( value ) => {
|
|
50
|
+
if ( value?.toString().toLowerCase() === 'error' ) {
|
|
51
|
+
return 'The word "error" is not allowed.';
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { formDecorator } from './story-utils';
|
|
14
|
+
import { ValidatedTextareaControl } from '../textarea-control';
|
|
15
|
+
|
|
16
|
+
const meta: Meta< typeof ValidatedTextareaControl > = {
|
|
17
|
+
title: 'Components (Experimental)/Validated Form Controls/ValidatedTextareaControl',
|
|
18
|
+
component: ValidatedTextareaControl,
|
|
19
|
+
tags: [ 'status-private' ],
|
|
20
|
+
decorators: formDecorator,
|
|
21
|
+
args: { onChange: () => {} },
|
|
22
|
+
argTypes: { value: { control: false } },
|
|
23
|
+
};
|
|
24
|
+
export default meta;
|
|
25
|
+
|
|
26
|
+
export const Default: StoryObj< typeof ValidatedTextareaControl > = {
|
|
27
|
+
render: function Template( { onChange, ...args } ) {
|
|
28
|
+
const [ value, setValue ] = useState( '' );
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ValidatedTextareaControl
|
|
32
|
+
{ ...args }
|
|
33
|
+
onChange={ ( newValue ) => {
|
|
34
|
+
setValue( newValue );
|
|
35
|
+
onChange?.( newValue );
|
|
36
|
+
} }
|
|
37
|
+
value={ value }
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
Default.args = {
|
|
43
|
+
required: true,
|
|
44
|
+
label: 'Textarea',
|
|
45
|
+
help: 'The word "error" will trigger an error.',
|
|
46
|
+
customValidator: ( value ) => {
|
|
47
|
+
if ( value?.toLowerCase() === 'error' ) {
|
|
48
|
+
return 'The word "error" is not allowed.';
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { formDecorator } from './story-utils';
|
|
15
|
+
import { ValidatedToggleControl } from '../toggle-control';
|
|
16
|
+
|
|
17
|
+
const meta: Meta< typeof ValidatedToggleControl > = {
|
|
18
|
+
title: 'Components (Experimental)/Validated Form Controls/ValidatedToggleControl',
|
|
19
|
+
component: ValidatedToggleControl,
|
|
20
|
+
tags: [ 'status-private' ],
|
|
21
|
+
decorators: formDecorator,
|
|
22
|
+
args: { onChange: () => {} },
|
|
23
|
+
argTypes: {
|
|
24
|
+
checked: { control: false },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
export const Default: StoryObj< typeof ValidatedToggleControl > = {
|
|
30
|
+
render: function Template( { onChange, ...args } ) {
|
|
31
|
+
const [ checked, setChecked ] = useState( false );
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<ValidatedToggleControl
|
|
35
|
+
{ ...args }
|
|
36
|
+
checked={ checked }
|
|
37
|
+
onChange={ ( value ) => {
|
|
38
|
+
setChecked( value );
|
|
39
|
+
onChange?.( value );
|
|
40
|
+
} }
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
Default.args = {
|
|
46
|
+
required: true,
|
|
47
|
+
label: 'Toggle',
|
|
48
|
+
help: 'This toggle may neither be enabled nor disabled.',
|
|
49
|
+
customValidator: ( value ) => {
|
|
50
|
+
if ( value ) {
|
|
51
|
+
return 'This toggle may not be enabled.';
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { formDecorator } from './story-utils';
|
|
15
|
+
import { ValidatedToggleGroupControl } from '../toggle-group-control';
|
|
16
|
+
import { ToggleGroupControlOption } from '../../../toggle-group-control';
|
|
17
|
+
|
|
18
|
+
const meta: Meta< typeof ValidatedToggleGroupControl > = {
|
|
19
|
+
title: 'Components (Experimental)/Validated Form Controls/ValidatedToggleGroupControl',
|
|
20
|
+
component: ValidatedToggleGroupControl,
|
|
21
|
+
tags: [ 'status-private' ],
|
|
22
|
+
decorators: formDecorator,
|
|
23
|
+
args: { onChange: () => {} },
|
|
24
|
+
argTypes: {
|
|
25
|
+
value: { control: false },
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export default meta;
|
|
29
|
+
|
|
30
|
+
export const Default: StoryObj< typeof ValidatedToggleGroupControl > = {
|
|
31
|
+
render: function Template( { onChange, ...args } ) {
|
|
32
|
+
const [ value, setValue ] =
|
|
33
|
+
useState<
|
|
34
|
+
React.ComponentProps<
|
|
35
|
+
typeof ValidatedToggleGroupControl
|
|
36
|
+
>[ 'value' ]
|
|
37
|
+
>( '1' );
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<ValidatedToggleGroupControl
|
|
41
|
+
{ ...args }
|
|
42
|
+
value={ value }
|
|
43
|
+
onChange={ ( newValue ) => {
|
|
44
|
+
setValue( newValue );
|
|
45
|
+
onChange?.( newValue );
|
|
46
|
+
} }
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
Default.args = {
|
|
52
|
+
required: true,
|
|
53
|
+
label: 'Toggle Group',
|
|
54
|
+
isBlock: true,
|
|
55
|
+
children: [
|
|
56
|
+
<ToggleGroupControlOption value="1" key="1" label="Option 1" />,
|
|
57
|
+
<ToggleGroupControlOption value="2" key="2" label="Option 2" />,
|
|
58
|
+
],
|
|
59
|
+
help: 'Selecting option 2 will trigger an error.',
|
|
60
|
+
customValidator: ( value ) => {
|
|
61
|
+
if ( value === '2' ) {
|
|
62
|
+
return 'Option 2 is not allowed.';
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMergeRefs } from '@wordpress/compose';
|
|
5
|
+
import { forwardRef, useRef } from '@wordpress/element';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { ControlWithError } from '../control-with-error';
|
|
11
|
+
import type { ValidatedControlProps } from './types';
|
|
12
|
+
import TextControl from '../../text-control';
|
|
13
|
+
import type { TextControlProps } from '../../text-control/types';
|
|
14
|
+
|
|
15
|
+
type Value = TextControlProps[ 'value' ];
|
|
16
|
+
|
|
17
|
+
const UnforwardedValidatedTextControl = (
|
|
18
|
+
{
|
|
19
|
+
required,
|
|
20
|
+
customValidator,
|
|
21
|
+
onChange,
|
|
22
|
+
markWhenOptional,
|
|
23
|
+
...restProps
|
|
24
|
+
}: Omit<
|
|
25
|
+
React.ComponentProps< typeof TextControl >,
|
|
26
|
+
'__next40pxDefaultSize' | '__nextHasNoMarginBottom'
|
|
27
|
+
> &
|
|
28
|
+
ValidatedControlProps< Value >,
|
|
29
|
+
forwardedRef: React.ForwardedRef< HTMLInputElement >
|
|
30
|
+
) => {
|
|
31
|
+
const validityTargetRef = useRef< HTMLInputElement >( null );
|
|
32
|
+
const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
|
|
33
|
+
const valueRef = useRef< Value >( restProps.value );
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<ControlWithError
|
|
37
|
+
required={ required }
|
|
38
|
+
markWhenOptional={ markWhenOptional }
|
|
39
|
+
customValidator={ () => {
|
|
40
|
+
return customValidator?.( valueRef.current );
|
|
41
|
+
} }
|
|
42
|
+
getValidityTarget={ () => validityTargetRef.current }
|
|
43
|
+
>
|
|
44
|
+
<TextControl
|
|
45
|
+
__next40pxDefaultSize
|
|
46
|
+
__nextHasNoMarginBottom
|
|
47
|
+
ref={ mergedRefs }
|
|
48
|
+
onChange={ ( value ) => {
|
|
49
|
+
valueRef.current = value;
|
|
50
|
+
onChange?.( value );
|
|
51
|
+
} }
|
|
52
|
+
{ ...restProps }
|
|
53
|
+
/>
|
|
54
|
+
</ControlWithError>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const ValidatedTextControl = forwardRef(
|
|
59
|
+
UnforwardedValidatedTextControl
|
|
60
|
+
);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { forwardRef, useRef } from '@wordpress/element';
|
|
5
|
+
import { useMergeRefs } from '@wordpress/compose';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { ControlWithError } from '../control-with-error';
|
|
11
|
+
import type { ValidatedControlProps } from './types';
|
|
12
|
+
import TextareaControl from '../../textarea-control';
|
|
13
|
+
import type { TextareaControlProps } from '../../textarea-control/types';
|
|
14
|
+
|
|
15
|
+
type Value = TextareaControlProps[ 'value' ];
|
|
16
|
+
|
|
17
|
+
const UnforwardedValidatedTextareaControl = (
|
|
18
|
+
{
|
|
19
|
+
required,
|
|
20
|
+
customValidator,
|
|
21
|
+
onChange,
|
|
22
|
+
markWhenOptional,
|
|
23
|
+
...restProps
|
|
24
|
+
}: Omit<
|
|
25
|
+
React.ComponentProps< typeof TextareaControl >,
|
|
26
|
+
'__nextHasNoMarginBottom'
|
|
27
|
+
> &
|
|
28
|
+
ValidatedControlProps< Value >,
|
|
29
|
+
forwardedRef: React.ForwardedRef< HTMLTextAreaElement >
|
|
30
|
+
) => {
|
|
31
|
+
const validityTargetRef = useRef< HTMLTextAreaElement >( null );
|
|
32
|
+
const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
|
|
33
|
+
const valueRef = useRef< Value >( restProps.value );
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<ControlWithError
|
|
37
|
+
required={ required }
|
|
38
|
+
markWhenOptional={ markWhenOptional }
|
|
39
|
+
customValidator={ () => {
|
|
40
|
+
return customValidator?.( valueRef.current );
|
|
41
|
+
} }
|
|
42
|
+
getValidityTarget={ () => validityTargetRef.current }
|
|
43
|
+
>
|
|
44
|
+
<TextareaControl
|
|
45
|
+
__nextHasNoMarginBottom
|
|
46
|
+
ref={ mergedRefs }
|
|
47
|
+
onChange={ ( value ) => {
|
|
48
|
+
valueRef.current = value;
|
|
49
|
+
onChange?.( value );
|
|
50
|
+
} }
|
|
51
|
+
{ ...restProps }
|
|
52
|
+
/>
|
|
53
|
+
</ControlWithError>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const ValidatedTextareaControl = forwardRef(
|
|
58
|
+
UnforwardedValidatedTextareaControl
|
|
59
|
+
);
|