@wordpress/dataviews 10.0.1-next.ff1cebbba.0 → 10.1.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 +10 -1
- package/README.md +97 -8
- package/build/components/dataform/index.js +11 -2
- package/build/components/dataform/index.js.map +2 -2
- package/build/components/dataform-context/index.js.map +2 -2
- package/build/components/dataviews-bulk-actions/index.js +2 -4
- package/build/components/dataviews-bulk-actions/index.js.map +2 -2
- package/build/components/dataviews-filters/filter.js +9 -4
- package/build/components/dataviews-filters/filter.js.map +3 -3
- package/build/components/dataviews-filters/search-widget.js +13 -2
- package/build/components/dataviews-filters/search-widget.js.map +3 -3
- package/build/components/dataviews-filters/use-filters.js +4 -2
- package/build/components/dataviews-filters/use-filters.js.map +2 -2
- package/build/components/dataviews-item-actions/index.js +6 -6
- package/build/components/dataviews-item-actions/index.js.map +2 -2
- package/build/dataform-controls/array.js +14 -61
- package/build/dataform-controls/array.js.map +3 -3
- package/build/dataform-controls/checkbox.js +5 -29
- package/build/dataform-controls/checkbox.js.map +3 -3
- package/build/dataform-controls/color.js +5 -29
- package/build/dataform-controls/color.js.map +3 -3
- package/build/dataform-controls/date.js +40 -57
- package/build/dataform-controls/date.js.map +3 -3
- package/build/dataform-controls/datetime.js +12 -37
- package/build/dataform-controls/datetime.js.map +3 -3
- package/build/dataform-controls/email.js +3 -1
- package/build/dataform-controls/email.js.map +2 -2
- package/build/dataform-controls/index.js +2 -1
- package/build/dataform-controls/index.js.map +3 -3
- package/build/dataform-controls/password.js +3 -1
- package/build/dataform-controls/password.js.map +2 -2
- package/build/dataform-controls/radio.js +24 -43
- package/build/dataform-controls/radio.js.map +3 -3
- package/build/dataform-controls/select.js +13 -30
- package/build/dataform-controls/select.js.map +3 -3
- package/build/dataform-controls/telephone.js +3 -1
- package/build/dataform-controls/telephone.js.map +2 -2
- package/build/dataform-controls/text.js +3 -1
- package/build/dataform-controls/text.js.map +2 -2
- package/build/dataform-controls/textarea.js +6 -30
- package/build/dataform-controls/textarea.js.map +3 -3
- package/build/dataform-controls/toggle-group.js +38 -56
- package/build/dataform-controls/toggle-group.js.map +3 -3
- package/build/dataform-controls/toggle.js +6 -30
- package/build/dataform-controls/toggle.js.map +3 -3
- package/build/dataform-controls/url.js +3 -1
- package/build/dataform-controls/url.js.map +2 -2
- package/build/dataform-controls/utils/get-custom-validity.js +35 -0
- package/build/dataform-controls/utils/get-custom-validity.js.map +7 -0
- package/build/dataform-controls/utils/validated-input.js +4 -28
- package/build/dataform-controls/utils/validated-input.js.map +3 -3
- package/build/dataform-controls/utils/validated-number.js +6 -30
- package/build/dataform-controls/utils/validated-number.js.map +3 -3
- package/build/dataform-layouts/card/index.js +6 -3
- package/build/dataform-layouts/card/index.js.map +2 -2
- package/build/dataform-layouts/data-form-layout.js +8 -2
- package/build/dataform-layouts/data-form-layout.js.map +2 -2
- package/build/dataform-layouts/panel/dropdown.js +21 -9
- package/build/dataform-layouts/panel/dropdown.js.map +2 -2
- package/build/dataform-layouts/panel/index.js +12 -10
- package/build/dataform-layouts/panel/index.js.map +2 -2
- package/build/dataform-layouts/panel/modal.js +32 -22
- package/build/dataform-layouts/panel/modal.js.map +3 -3
- package/build/dataform-layouts/regular/index.js +8 -4
- package/build/dataform-layouts/regular/index.js.map +2 -2
- package/build/dataform-layouts/row/index.js +11 -7
- package/build/dataform-layouts/row/index.js.map +2 -2
- package/build/dataviews-layouts/list/index.js +7 -7
- package/build/dataviews-layouts/list/index.js.map +2 -2
- package/build/dataviews-layouts/table/column-header-menu.js +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js.map +2 -2
- package/build/field-types/boolean.js +3 -2
- package/build/field-types/boolean.js.map +3 -3
- package/build/field-types/color.js +2 -2
- package/build/field-types/color.js.map +3 -3
- package/build/field-types/date.js +3 -2
- package/build/field-types/date.js.map +3 -3
- package/build/field-types/datetime.js +2 -1
- package/build/field-types/datetime.js.map +3 -3
- package/build/field-types/email.js +2 -1
- package/build/field-types/email.js.map +3 -3
- package/build/field-types/index.js +2 -1
- package/build/field-types/index.js.map +3 -3
- package/build/field-types/integer.js +2 -1
- package/build/field-types/integer.js.map +3 -3
- package/build/field-types/number.js +18 -9
- package/build/field-types/number.js.map +3 -3
- package/build/field-types/password.js +2 -1
- package/build/field-types/password.js.map +3 -3
- package/build/field-types/telephone.js +2 -1
- package/build/field-types/telephone.js.map +3 -3
- package/build/field-types/text.js +2 -1
- package/build/field-types/text.js.map +3 -3
- package/build/field-types/url.js +2 -1
- package/build/field-types/url.js.map +3 -3
- package/build/field-types/utils/render-from-elements.js +24 -3
- package/build/field-types/utils/render-from-elements.js.map +4 -4
- package/build/hooks/index.js +39 -0
- package/build/hooks/index.js.map +7 -0
- package/build/hooks/use-elements.js +63 -0
- package/build/hooks/use-elements.js.map +7 -0
- package/build/hooks/use-form-validity.js +426 -0
- package/build/hooks/use-form-validity.js.map +7 -0
- package/build/index.js +3 -3
- package/build/index.js.map +2 -2
- package/build/types/dataform.js.map +1 -1
- package/build/types/dataviews.js.map +1 -1
- package/build/types/field-api.js.map +1 -1
- package/build/utils/has-elements.js +27 -0
- package/build/utils/has-elements.js.map +7 -0
- package/build/utils/normalize-fields.js +4 -2
- package/build/utils/normalize-fields.js.map +3 -3
- package/build-module/components/dataform/index.js +11 -2
- package/build-module/components/dataform/index.js.map +2 -2
- package/build-module/components/dataform-context/index.js.map +2 -2
- package/build-module/components/dataviews-bulk-actions/index.js +2 -4
- package/build-module/components/dataviews-bulk-actions/index.js.map +2 -2
- package/build-module/components/dataviews-filters/filter.js +9 -4
- package/build-module/components/dataviews-filters/filter.js.map +2 -2
- package/build-module/components/dataviews-filters/search-widget.js +19 -3
- package/build-module/components/dataviews-filters/search-widget.js.map +2 -2
- package/build-module/components/dataviews-filters/use-filters.js +4 -2
- package/build-module/components/dataviews-filters/use-filters.js.map +2 -2
- package/build-module/components/dataviews-item-actions/index.js +6 -6
- package/build-module/components/dataviews-item-actions/index.js.map +2 -2
- package/build-module/dataform-controls/array.js +16 -63
- package/build-module/dataform-controls/array.js.map +2 -2
- package/build-module/dataform-controls/checkbox.js +6 -30
- package/build-module/dataform-controls/checkbox.js.map +2 -2
- package/build-module/dataform-controls/color.js +6 -30
- package/build-module/dataform-controls/color.js.map +2 -2
- package/build-module/dataform-controls/date.js +49 -66
- package/build-module/dataform-controls/date.js.map +2 -2
- package/build-module/dataform-controls/datetime.js +14 -39
- package/build-module/dataform-controls/datetime.js.map +2 -2
- package/build-module/dataform-controls/email.js +3 -1
- package/build-module/dataform-controls/email.js.map +2 -2
- package/build-module/dataform-controls/index.js +2 -1
- package/build-module/dataform-controls/index.js.map +2 -2
- package/build-module/dataform-controls/password.js +3 -1
- package/build-module/dataform-controls/password.js.map +2 -2
- package/build-module/dataform-controls/radio.js +26 -45
- package/build-module/dataform-controls/radio.js.map +2 -2
- package/build-module/dataform-controls/select.js +15 -32
- package/build-module/dataform-controls/select.js.map +2 -2
- package/build-module/dataform-controls/telephone.js +3 -1
- package/build-module/dataform-controls/telephone.js.map +2 -2
- package/build-module/dataform-controls/text.js +3 -1
- package/build-module/dataform-controls/text.js.map +2 -2
- package/build-module/dataform-controls/textarea.js +7 -31
- package/build-module/dataform-controls/textarea.js.map +2 -2
- package/build-module/dataform-controls/toggle-group.js +41 -58
- package/build-module/dataform-controls/toggle-group.js.map +2 -2
- package/build-module/dataform-controls/toggle.js +7 -31
- package/build-module/dataform-controls/toggle.js.map +2 -2
- package/build-module/dataform-controls/url.js +3 -1
- package/build-module/dataform-controls/url.js.map +2 -2
- package/build-module/dataform-controls/utils/get-custom-validity.js +15 -0
- package/build-module/dataform-controls/utils/get-custom-validity.js.map +7 -0
- package/build-module/dataform-controls/utils/validated-input.js +5 -29
- package/build-module/dataform-controls/utils/validated-input.js.map +2 -2
- package/build-module/dataform-controls/utils/validated-number.js +7 -31
- package/build-module/dataform-controls/utils/validated-number.js.map +2 -2
- package/build-module/dataform-layouts/card/index.js +6 -3
- package/build-module/dataform-layouts/card/index.js.map +2 -2
- package/build-module/dataform-layouts/data-form-layout.js +8 -2
- package/build-module/dataform-layouts/data-form-layout.js.map +2 -2
- package/build-module/dataform-layouts/panel/dropdown.js +21 -9
- package/build-module/dataform-layouts/panel/dropdown.js.map +2 -2
- package/build-module/dataform-layouts/panel/index.js +12 -10
- package/build-module/dataform-layouts/panel/index.js.map +2 -2
- package/build-module/dataform-layouts/panel/modal.js +33 -23
- package/build-module/dataform-layouts/panel/modal.js.map +2 -2
- package/build-module/dataform-layouts/regular/index.js +8 -4
- package/build-module/dataform-layouts/regular/index.js.map +2 -2
- package/build-module/dataform-layouts/row/index.js +11 -7
- package/build-module/dataform-layouts/row/index.js.map +2 -2
- package/build-module/dataviews-layouts/list/index.js +7 -7
- package/build-module/dataviews-layouts/list/index.js.map +2 -2
- package/build-module/dataviews-layouts/table/column-header-menu.js +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +2 -2
- package/build-module/field-types/boolean.js +4 -3
- package/build-module/field-types/boolean.js.map +2 -2
- package/build-module/field-types/color.js +3 -3
- package/build-module/field-types/color.js.map +2 -2
- package/build-module/field-types/date.js +4 -3
- package/build-module/field-types/date.js.map +2 -2
- package/build-module/field-types/datetime.js +3 -2
- package/build-module/field-types/datetime.js.map +2 -2
- package/build-module/field-types/email.js +3 -2
- package/build-module/field-types/email.js.map +2 -2
- package/build-module/field-types/index.js +3 -2
- package/build-module/field-types/index.js.map +2 -2
- package/build-module/field-types/integer.js +3 -2
- package/build-module/field-types/integer.js.map +2 -2
- package/build-module/field-types/number.js +8 -9
- package/build-module/field-types/number.js.map +2 -2
- package/build-module/field-types/password.js +3 -2
- package/build-module/field-types/password.js.map +2 -2
- package/build-module/field-types/telephone.js +3 -2
- package/build-module/field-types/telephone.js.map +2 -2
- package/build-module/field-types/text.js +3 -2
- package/build-module/field-types/text.js.map +2 -2
- package/build-module/field-types/url.js +3 -2
- package/build-module/field-types/url.js.map +2 -2
- package/build-module/field-types/utils/render-from-elements.js +14 -3
- package/build-module/field-types/utils/render-from-elements.js.map +3 -3
- package/build-module/hooks/index.js +5 -0
- package/build-module/hooks/index.js.map +7 -0
- package/build-module/hooks/use-elements.js +43 -0
- package/build-module/hooks/use-elements.js.map +7 -0
- package/build-module/hooks/use-form-validity.js +392 -0
- package/build-module/hooks/use-form-validity.js.map +7 -0
- package/build-module/index.js +2 -2
- package/build-module/index.js.map +2 -2
- package/build-module/utils/has-elements.js +7 -0
- package/build-module/utils/has-elements.js.map +7 -0
- package/build-module/utils/normalize-fields.js +4 -2
- package/build-module/utils/normalize-fields.js.map +2 -2
- package/build-style/style-rtl.css +10 -4
- package/build-style/style.css +10 -4
- package/build-types/components/dataform/index.d.ts +1 -1
- package/build-types/components/dataform/index.d.ts.map +1 -1
- package/build-types/components/dataform-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/filter.d.ts +1 -1
- package/build-types/components/dataviews-filters/filter.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/use-filters.d.ts.map +1 -1
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/dataform-controls/array.d.ts +1 -1
- package/build-types/dataform-controls/array.d.ts.map +1 -1
- package/build-types/dataform-controls/checkbox.d.ts +1 -1
- package/build-types/dataform-controls/checkbox.d.ts.map +1 -1
- package/build-types/dataform-controls/color.d.ts +1 -1
- package/build-types/dataform-controls/color.d.ts.map +1 -1
- package/build-types/dataform-controls/date.d.ts +1 -1
- package/build-types/dataform-controls/date.d.ts.map +1 -1
- package/build-types/dataform-controls/datetime.d.ts +1 -1
- package/build-types/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/dataform-controls/email.d.ts +1 -1
- package/build-types/dataform-controls/email.d.ts.map +1 -1
- package/build-types/dataform-controls/index.d.ts.map +1 -1
- package/build-types/dataform-controls/password.d.ts +1 -1
- package/build-types/dataform-controls/password.d.ts.map +1 -1
- package/build-types/dataform-controls/radio.d.ts +1 -1
- package/build-types/dataform-controls/radio.d.ts.map +1 -1
- package/build-types/dataform-controls/select.d.ts +1 -1
- package/build-types/dataform-controls/select.d.ts.map +1 -1
- package/build-types/dataform-controls/telephone.d.ts +1 -1
- package/build-types/dataform-controls/telephone.d.ts.map +1 -1
- package/build-types/dataform-controls/text.d.ts +1 -1
- package/build-types/dataform-controls/text.d.ts.map +1 -1
- package/build-types/dataform-controls/textarea.d.ts +1 -1
- package/build-types/dataform-controls/textarea.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle-group.d.ts +1 -1
- package/build-types/dataform-controls/toggle-group.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle.d.ts +1 -1
- package/build-types/dataform-controls/toggle.d.ts.map +1 -1
- package/build-types/dataform-controls/url.d.ts +1 -1
- package/build-types/dataform-controls/url.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/get-custom-validity.d.ts +9 -0
- package/build-types/dataform-controls/utils/get-custom-validity.d.ts.map +1 -0
- package/build-types/dataform-controls/utils/validated-input.d.ts +1 -1
- package/build-types/dataform-controls/utils/validated-input.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/validated-number.d.ts +1 -1
- package/build-types/dataform-controls/utils/validated-number.d.ts.map +1 -1
- package/build-types/dataform-layouts/card/index.d.ts +1 -1
- package/build-types/dataform-layouts/card/index.d.ts.map +1 -1
- package/build-types/dataform-layouts/data-form-layout.d.ts +5 -3
- package/build-types/dataform-layouts/data-form-layout.d.ts.map +1 -1
- package/build-types/dataform-layouts/panel/dropdown.d.ts +8 -7
- package/build-types/dataform-layouts/panel/dropdown.d.ts.map +1 -1
- package/build-types/dataform-layouts/panel/index.d.ts +1 -1
- package/build-types/dataform-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataform-layouts/panel/modal.d.ts +5 -5
- package/build-types/dataform-layouts/panel/modal.d.ts.map +1 -1
- package/build-types/dataform-layouts/regular/index.d.ts +1 -1
- package/build-types/dataform-layouts/regular/index.d.ts.map +1 -1
- package/build-types/dataform-layouts/row/index.d.ts +1 -1
- package/build-types/dataform-layouts/row/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/field-types/boolean.d.ts +1 -1
- package/build-types/field-types/date.d.ts +1 -1
- package/build-types/field-types/datetime.d.ts.map +1 -1
- package/build-types/field-types/email.d.ts.map +1 -1
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/integer.d.ts.map +1 -1
- package/build-types/field-types/number.d.ts +1 -1
- package/build-types/field-types/number.d.ts.map +1 -1
- package/build-types/field-types/password.d.ts +1 -1
- package/build-types/field-types/password.d.ts.map +1 -1
- package/build-types/field-types/telephone.d.ts.map +1 -1
- package/build-types/field-types/text.d.ts.map +1 -1
- package/build-types/field-types/url.d.ts.map +1 -1
- package/build-types/field-types/utils/render-from-elements.d.ts +1 -1
- package/build-types/field-types/utils/render-from-elements.d.ts.map +1 -1
- package/build-types/hooks/index.d.ts +5 -0
- package/build-types/hooks/index.d.ts.map +1 -0
- package/build-types/hooks/use-elements.d.ts +12 -0
- package/build-types/hooks/use-elements.d.ts.map +1 -0
- package/build-types/hooks/use-form-validity.d.ts +16 -0
- package/build-types/hooks/use-form-validity.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/stories/dataform.story.d.ts +14 -4
- package/build-types/stories/dataform.story.d.ts.map +1 -1
- package/build-types/stories/dataviews.fixtures.d.ts.map +1 -1
- package/build-types/stories/field-types.story.d.ts +38 -15
- package/build-types/stories/field-types.story.d.ts.map +1 -1
- package/build-types/test/use-form-validity.d.ts +2 -0
- package/build-types/test/use-form-validity.d.ts.map +1 -0
- package/build-types/types/dataform.d.ts +4 -1
- package/build-types/types/dataform.d.ts.map +1 -1
- package/build-types/types/dataviews.d.ts +10 -2
- package/build-types/types/dataviews.d.ts.map +1 -1
- package/build-types/types/field-api.d.ts +25 -1
- package/build-types/types/field-api.d.ts.map +1 -1
- package/build-types/utils/has-elements.d.ts +6 -0
- package/build-types/utils/has-elements.d.ts.map +1 -0
- package/build-types/utils/normalize-fields.d.ts.map +1 -1
- package/build-wp/index.js +1011 -819
- package/package.json +15 -15
- package/src/components/dataform/index.tsx +7 -1
- package/src/components/dataform-context/index.tsx +3 -1
- package/src/components/dataviews-bulk-actions/index.tsx +3 -5
- package/src/components/dataviews-filters/filter.tsx +11 -5
- package/src/components/dataviews-filters/search-widget.tsx +30 -3
- package/src/components/dataviews-filters/style.scss +8 -0
- package/src/components/dataviews-filters/use-filters.ts +4 -2
- package/src/components/dataviews-item-actions/index.tsx +11 -6
- package/src/components/dataviews-item-actions/style.scss +1 -0
- package/src/dataform-controls/array.tsx +16 -82
- package/src/dataform-controls/checkbox.tsx +5 -41
- package/src/dataform-controls/color.tsx +5 -37
- package/src/dataform-controls/date.tsx +63 -76
- package/src/dataform-controls/datetime.tsx +11 -45
- package/src/dataform-controls/email.tsx +2 -0
- package/src/dataform-controls/index.tsx +2 -1
- package/src/dataform-controls/password.tsx +2 -0
- package/src/dataform-controls/radio.tsx +24 -55
- package/src/dataform-controls/select.tsx +14 -42
- package/src/dataform-controls/telephone.tsx +2 -0
- package/src/dataform-controls/text.tsx +2 -0
- package/src/dataform-controls/textarea.tsx +6 -42
- package/src/dataform-controls/toggle-group.tsx +38 -64
- package/src/dataform-controls/toggle.tsx +6 -42
- package/src/dataform-controls/url.tsx +2 -0
- package/src/dataform-controls/utils/get-custom-validity.ts +24 -0
- package/src/dataform-controls/utils/validated-input.tsx +4 -40
- package/src/dataform-controls/utils/validated-number.tsx +6 -44
- package/src/dataform-layouts/card/index.tsx +3 -0
- package/src/dataform-layouts/data-form-layout.tsx +18 -3
- package/src/dataform-layouts/panel/dropdown.tsx +35 -14
- package/src/dataform-layouts/panel/index.tsx +9 -7
- package/src/dataform-layouts/panel/modal.tsx +41 -30
- package/src/dataform-layouts/regular/index.tsx +4 -0
- package/src/dataform-layouts/row/index.tsx +8 -4
- package/src/dataviews-layouts/list/index.tsx +9 -7
- package/src/dataviews-layouts/table/column-header-menu.tsx +1 -1
- package/src/dataviews-layouts/table/style.scss +2 -3
- package/src/field-types/boolean.tsx +3 -3
- package/src/field-types/color.tsx +3 -3
- package/src/field-types/date.tsx +3 -3
- package/src/field-types/datetime.tsx +6 -4
- package/src/field-types/email.tsx +6 -4
- package/src/field-types/index.tsx +6 -4
- package/src/field-types/integer.tsx +6 -4
- package/src/field-types/number.tsx +8 -12
- package/src/field-types/password.tsx +6 -4
- package/src/field-types/telephone.tsx +6 -4
- package/src/field-types/text.tsx +6 -4
- package/src/field-types/url.tsx +6 -4
- package/src/field-types/utils/render-from-elements.tsx +29 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/use-elements.ts +66 -0
- package/src/hooks/use-form-validity.ts +571 -0
- package/src/index.ts +1 -1
- package/src/stories/dataform.story.tsx +243 -59
- package/src/stories/dataviews.fixtures.tsx +9 -4
- package/src/stories/field-types.story.tsx +159 -29
- package/src/test/use-form-validity.ts +546 -0
- package/src/types/dataform.ts +5 -1
- package/src/types/dataviews.ts +12 -2
- package/src/types/field-api.ts +32 -1
- package/src/utils/has-elements.ts +11 -0
- package/src/utils/normalize-fields.ts +7 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/utils/is-item-valid.js +0 -75
- package/build/utils/is-item-valid.js.map +0 -7
- package/build-module/utils/is-item-valid.js +0 -45
- package/build-module/utils/is-item-valid.js.map +0 -7
- package/build-types/test/validation.d.ts +0 -2
- package/build-types/test/validation.d.ts.map +0 -1
- package/build-types/utils/is-item-valid.d.ts +0 -12
- package/build-types/utils/is-item-valid.d.ts.map +0 -1
- package/src/field-types/utils/render-from-elements.ts +0 -15
- package/src/test/validation.ts +0 -322
- package/src/utils/is-item-valid.ts +0 -93
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import {
|
|
6
|
+
format,
|
|
7
|
+
isValid as isValidDate,
|
|
8
|
+
subMonths,
|
|
9
|
+
subDays,
|
|
10
|
+
subYears,
|
|
11
|
+
startOfMonth,
|
|
12
|
+
startOfYear,
|
|
13
|
+
} from 'date-fns';
|
|
14
|
+
|
|
1
15
|
/**
|
|
2
16
|
* WordPress dependencies
|
|
3
17
|
*/
|
|
@@ -21,21 +35,6 @@ import { __ } from '@wordpress/i18n';
|
|
|
21
35
|
import { getDate, getSettings } from '@wordpress/date';
|
|
22
36
|
import { error as errorIcon } from '@wordpress/icons';
|
|
23
37
|
|
|
24
|
-
/**
|
|
25
|
-
* External dependencies
|
|
26
|
-
*/
|
|
27
|
-
import clsx from 'clsx';
|
|
28
|
-
import {
|
|
29
|
-
format,
|
|
30
|
-
isValid,
|
|
31
|
-
subMonths,
|
|
32
|
-
subDays,
|
|
33
|
-
subYears,
|
|
34
|
-
startOfMonth,
|
|
35
|
-
startOfYear,
|
|
36
|
-
} from 'date-fns';
|
|
37
|
-
import deepMerge from 'deepmerge';
|
|
38
|
-
|
|
39
38
|
/**
|
|
40
39
|
* Internal dependencies
|
|
41
40
|
*/
|
|
@@ -46,7 +45,12 @@ import {
|
|
|
46
45
|
OPERATOR_BETWEEN,
|
|
47
46
|
} from '../constants';
|
|
48
47
|
import { unlock } from '../lock-unlock';
|
|
49
|
-
import type {
|
|
48
|
+
import type {
|
|
49
|
+
DataFormControlProps,
|
|
50
|
+
FieldValidity,
|
|
51
|
+
NormalizedField,
|
|
52
|
+
} from '../types';
|
|
53
|
+
import getCustomValidity from './utils/get-custom-validity';
|
|
50
54
|
|
|
51
55
|
const { DateCalendar, DateRangeCalendar } = unlock( componentsPrivateApis );
|
|
52
56
|
|
|
@@ -136,7 +140,7 @@ const parseDate = ( dateString?: string ): Date | null => {
|
|
|
136
140
|
return null;
|
|
137
141
|
}
|
|
138
142
|
const parsed = getDate( dateString );
|
|
139
|
-
return parsed &&
|
|
143
|
+
return parsed && isValidDate( parsed ) ? parsed : null;
|
|
140
144
|
};
|
|
141
145
|
|
|
142
146
|
const formatDate = ( date?: Date | string ): string => {
|
|
@@ -147,19 +151,15 @@ const formatDate = ( date?: Date | string ): string => {
|
|
|
147
151
|
};
|
|
148
152
|
|
|
149
153
|
function ValidatedDateControl< Item >( {
|
|
150
|
-
value,
|
|
151
154
|
field,
|
|
152
|
-
|
|
153
|
-
setValue,
|
|
155
|
+
validity,
|
|
154
156
|
inputRefs,
|
|
155
157
|
isTouched,
|
|
156
158
|
setIsTouched,
|
|
157
159
|
children,
|
|
158
160
|
}: {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
data: Item;
|
|
162
|
-
setValue: any;
|
|
161
|
+
field: NormalizedField< Item >;
|
|
162
|
+
validity?: FieldValidity;
|
|
163
163
|
inputRefs:
|
|
164
164
|
| React.RefObject< HTMLInputElement >
|
|
165
165
|
| React.RefObject< HTMLInputElement >[];
|
|
@@ -167,62 +167,43 @@ function ValidatedDateControl< Item >( {
|
|
|
167
167
|
setIsTouched: ( touched: boolean ) => void;
|
|
168
168
|
children: React.ReactNode;
|
|
169
169
|
} ) {
|
|
170
|
+
const { isValid } = field;
|
|
170
171
|
const [ customValidity, setCustomValidity ] = useState<
|
|
171
|
-
{ type: 'invalid'; message
|
|
172
|
+
| { type: 'valid' | 'validating' | 'invalid'; message?: string }
|
|
173
|
+
| undefined
|
|
172
174
|
>( undefined );
|
|
173
175
|
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
),
|
|
186
|
-
field
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
if ( customMessage ) {
|
|
190
|
-
setCustomValidity( {
|
|
191
|
-
type: 'invalid',
|
|
192
|
-
message: customMessage,
|
|
193
|
-
} );
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Check HTML5 validity on all refs
|
|
199
|
-
const refs = Array.isArray( inputRefs ) ? inputRefs : [ inputRefs ];
|
|
200
|
-
for ( const ref of refs ) {
|
|
201
|
-
const input = ref.current;
|
|
202
|
-
if ( input && ! input.validity.valid ) {
|
|
203
|
-
setCustomValidity( {
|
|
204
|
-
type: 'invalid',
|
|
205
|
-
message: input.validationMessage,
|
|
206
|
-
} );
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
176
|
+
const validateRefs = useCallback( () => {
|
|
177
|
+
// Check HTML5 validity on all refs
|
|
178
|
+
const refs = Array.isArray( inputRefs ) ? inputRefs : [ inputRefs ];
|
|
179
|
+
for ( const ref of refs ) {
|
|
180
|
+
const input = ref.current;
|
|
181
|
+
if ( input && ! input.validity.valid ) {
|
|
182
|
+
setCustomValidity( {
|
|
183
|
+
type: 'invalid',
|
|
184
|
+
message: input.validationMessage,
|
|
185
|
+
} );
|
|
186
|
+
return;
|
|
209
187
|
}
|
|
188
|
+
}
|
|
210
189
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
[ data, field, setValue, inputRefs ]
|
|
215
|
-
);
|
|
190
|
+
// No errors
|
|
191
|
+
setCustomValidity( undefined );
|
|
192
|
+
}, [ inputRefs ] );
|
|
216
193
|
|
|
217
194
|
useEffect( () => {
|
|
218
195
|
if ( isTouched ) {
|
|
219
196
|
const timeoutId = setTimeout( () => {
|
|
220
|
-
|
|
197
|
+
if ( validity ) {
|
|
198
|
+
setCustomValidity( getCustomValidity( isValid, validity ) );
|
|
199
|
+
} else {
|
|
200
|
+
validateRefs();
|
|
201
|
+
}
|
|
221
202
|
}, 0 );
|
|
222
203
|
return () => clearTimeout( timeoutId );
|
|
223
204
|
}
|
|
224
205
|
return undefined;
|
|
225
|
-
}, [ isTouched,
|
|
206
|
+
}, [ isTouched, isValid, validity, validateRefs ] );
|
|
226
207
|
|
|
227
208
|
const onBlur = ( event: React.FocusEvent< HTMLDivElement > ) => {
|
|
228
209
|
if ( isTouched ) {
|
|
@@ -247,7 +228,12 @@ function ValidatedDateControl< Item >( {
|
|
|
247
228
|
<p
|
|
248
229
|
className={ clsx(
|
|
249
230
|
'components-validated-control__indicator',
|
|
250
|
-
'
|
|
231
|
+
customValidity.type === 'invalid'
|
|
232
|
+
? 'is-invalid'
|
|
233
|
+
: undefined,
|
|
234
|
+
customValidity.type === 'valid'
|
|
235
|
+
? 'is-valid'
|
|
236
|
+
: undefined
|
|
251
237
|
) }
|
|
252
238
|
>
|
|
253
239
|
<Icon
|
|
@@ -269,8 +255,9 @@ function CalendarDateControl< Item >( {
|
|
|
269
255
|
field,
|
|
270
256
|
onChange,
|
|
271
257
|
hideLabelFromVision,
|
|
258
|
+
validity,
|
|
272
259
|
}: DataFormControlProps< Item > ) {
|
|
273
|
-
const { id, label, setValue, getValue } = field;
|
|
260
|
+
const { id, label, setValue, getValue, isValid } = field;
|
|
274
261
|
const [ selectedPresetId, setSelectedPresetId ] = useState< string | null >(
|
|
275
262
|
null
|
|
276
263
|
);
|
|
@@ -336,16 +323,14 @@ function CalendarDateControl< Item >( {
|
|
|
336
323
|
l10n: { startOfWeek },
|
|
337
324
|
} = getSettings();
|
|
338
325
|
|
|
339
|
-
const displayLabel =
|
|
326
|
+
const displayLabel = isValid?.required
|
|
340
327
|
? `${ label } (${ __( 'Required' ) })`
|
|
341
328
|
: label;
|
|
342
329
|
|
|
343
330
|
return (
|
|
344
331
|
<ValidatedDateControl
|
|
345
|
-
value={ value }
|
|
346
332
|
field={ field }
|
|
347
|
-
|
|
348
|
-
setValue={ setValue }
|
|
333
|
+
validity={ validity }
|
|
349
334
|
inputRefs={ validityTargetRef }
|
|
350
335
|
isTouched={ isTouched }
|
|
351
336
|
setIsTouched={ setIsTouched }
|
|
@@ -424,6 +409,7 @@ function CalendarDateRangeControl< Item >( {
|
|
|
424
409
|
field,
|
|
425
410
|
onChange,
|
|
426
411
|
hideLabelFromVision,
|
|
412
|
+
validity,
|
|
427
413
|
}: DataFormControlProps< Item > ) {
|
|
428
414
|
const { id, label, getValue, setValue } = field;
|
|
429
415
|
let value: DateRange;
|
|
@@ -543,10 +529,8 @@ function CalendarDateRangeControl< Item >( {
|
|
|
543
529
|
|
|
544
530
|
return (
|
|
545
531
|
<ValidatedDateControl
|
|
546
|
-
value={ value }
|
|
547
532
|
field={ field }
|
|
548
|
-
|
|
549
|
-
setValue={ setValue }
|
|
533
|
+
validity={ validity }
|
|
550
534
|
inputRefs={ [ fromInputRef, toInputRef ] }
|
|
551
535
|
isTouched={ isTouched }
|
|
552
536
|
setIsTouched={ setIsTouched }
|
|
@@ -639,6 +623,7 @@ export default function DateControl< Item >( {
|
|
|
639
623
|
onChange,
|
|
640
624
|
hideLabelFromVision,
|
|
641
625
|
operator,
|
|
626
|
+
validity,
|
|
642
627
|
}: DataFormControlProps< Item > ) {
|
|
643
628
|
if ( operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER ) {
|
|
644
629
|
return (
|
|
@@ -660,6 +645,7 @@ export default function DateControl< Item >( {
|
|
|
660
645
|
field={ field }
|
|
661
646
|
onChange={ onChange }
|
|
662
647
|
hideLabelFromVision={ hideLabelFromVision }
|
|
648
|
+
validity={ validity }
|
|
663
649
|
/>
|
|
664
650
|
);
|
|
665
651
|
}
|
|
@@ -670,6 +656,7 @@ export default function DateControl< Item >( {
|
|
|
670
656
|
field={ field }
|
|
671
657
|
onChange={ onChange }
|
|
672
658
|
hideLabelFromVision={ hideLabelFromVision }
|
|
659
|
+
validity={ validity }
|
|
673
660
|
/>
|
|
674
661
|
);
|
|
675
662
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
5
|
-
import { format, isValid } from 'date-fns';
|
|
4
|
+
import { format, isValid as isValidDate } from 'date-fns';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* WordPress dependencies
|
|
@@ -22,6 +21,7 @@ import { getDate, getSettings } from '@wordpress/date';
|
|
|
22
21
|
import type { DataFormControlProps } from '../types';
|
|
23
22
|
import { OPERATOR_IN_THE_PAST, OPERATOR_OVER } from '../constants';
|
|
24
23
|
import RelativeDateControl from './utils/relative-date-control';
|
|
24
|
+
import getCustomValidity from './utils/get-custom-validity';
|
|
25
25
|
import { unlock } from '../lock-unlock';
|
|
26
26
|
|
|
27
27
|
const { DateCalendar, ValidatedInputControl } = unlock( componentsPrivateApis );
|
|
@@ -31,7 +31,7 @@ const parseDateTime = ( dateTimeString?: string ): Date | null => {
|
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
33
|
const parsed = getDate( dateTimeString );
|
|
34
|
-
return parsed &&
|
|
34
|
+
return parsed && isValidDate( parsed ) ? parsed : null;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const formatDateTime = ( date?: Date | string ): string => {
|
|
@@ -50,8 +50,9 @@ function CalendarDateTimeControl< Item >( {
|
|
|
50
50
|
field,
|
|
51
51
|
onChange,
|
|
52
52
|
hideLabelFromVision,
|
|
53
|
+
validity,
|
|
53
54
|
}: DataFormControlProps< Item > ) {
|
|
54
|
-
const { id, label, description, setValue, getValue } = field;
|
|
55
|
+
const { id, label, description, setValue, getValue, isValid } = field;
|
|
55
56
|
const fieldValue = getValue( { item: data } );
|
|
56
57
|
const value = typeof fieldValue === 'string' ? fieldValue : undefined;
|
|
57
58
|
|
|
@@ -60,13 +61,6 @@ function CalendarDateTimeControl< Item >( {
|
|
|
60
61
|
return parsedDate || new Date(); // Default to current month
|
|
61
62
|
} );
|
|
62
63
|
|
|
63
|
-
const [ customValidity, setCustomValidity ] =
|
|
64
|
-
useState<
|
|
65
|
-
React.ComponentProps<
|
|
66
|
-
typeof ValidatedInputControl
|
|
67
|
-
>[ 'customValidity' ]
|
|
68
|
-
>( undefined );
|
|
69
|
-
|
|
70
64
|
const inputControlRef = useRef< HTMLInputElement >( null );
|
|
71
65
|
const validationTimeoutRef = useRef< ReturnType< typeof setTimeout > >();
|
|
72
66
|
const previousFocusRef = useRef< Element | null >( null );
|
|
@@ -86,32 +80,6 @@ function CalendarDateTimeControl< Item >( {
|
|
|
86
80
|
};
|
|
87
81
|
}, [] );
|
|
88
82
|
|
|
89
|
-
const onValidateControl = useCallback(
|
|
90
|
-
( newValue: any ) => {
|
|
91
|
-
const message = field.isValid?.custom?.(
|
|
92
|
-
deepMerge(
|
|
93
|
-
data,
|
|
94
|
-
setValue( {
|
|
95
|
-
item: data,
|
|
96
|
-
value: newValue,
|
|
97
|
-
} ) as Partial< Item >
|
|
98
|
-
),
|
|
99
|
-
field
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
if ( message ) {
|
|
103
|
-
setCustomValidity( {
|
|
104
|
-
type: 'invalid',
|
|
105
|
-
message,
|
|
106
|
-
} );
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setCustomValidity( undefined );
|
|
111
|
-
},
|
|
112
|
-
[ data, field, setValue ]
|
|
113
|
-
);
|
|
114
|
-
|
|
115
83
|
const onSelectDate = useCallback(
|
|
116
84
|
( newDate: Date | undefined | null ) => {
|
|
117
85
|
let dateTimeValue: string | undefined;
|
|
@@ -133,7 +101,6 @@ function CalendarDateTimeControl< Item >( {
|
|
|
133
101
|
|
|
134
102
|
dateTimeValue = finalDateTime.toISOString();
|
|
135
103
|
onChangeCallback( dateTimeValue );
|
|
136
|
-
onValidateControl( dateTimeValue );
|
|
137
104
|
|
|
138
105
|
// Clear any existing timeout
|
|
139
106
|
if ( validationTimeoutRef.current ) {
|
|
@@ -141,7 +108,6 @@ function CalendarDateTimeControl< Item >( {
|
|
|
141
108
|
}
|
|
142
109
|
} else {
|
|
143
110
|
onChangeCallback( undefined );
|
|
144
|
-
onValidateControl( undefined );
|
|
145
111
|
}
|
|
146
112
|
// Save the currently focused element
|
|
147
113
|
previousFocusRef.current =
|
|
@@ -155,7 +121,6 @@ function CalendarDateTimeControl< Item >( {
|
|
|
155
121
|
inputControlRef.current.focus();
|
|
156
122
|
inputControlRef.current.blur();
|
|
157
123
|
onChangeCallback( dateTimeValue );
|
|
158
|
-
onValidateControl( dateTimeValue );
|
|
159
124
|
|
|
160
125
|
// Restore focus to the previously focused element
|
|
161
126
|
if (
|
|
@@ -167,7 +132,7 @@ function CalendarDateTimeControl< Item >( {
|
|
|
167
132
|
}
|
|
168
133
|
}, 0 );
|
|
169
134
|
},
|
|
170
|
-
[ onChangeCallback, value
|
|
135
|
+
[ onChangeCallback, value ]
|
|
171
136
|
);
|
|
172
137
|
|
|
173
138
|
const handleManualDateTimeChange = useCallback(
|
|
@@ -195,7 +160,7 @@ function CalendarDateTimeControl< Item >( {
|
|
|
195
160
|
} = getSettings();
|
|
196
161
|
|
|
197
162
|
const displayLabel =
|
|
198
|
-
|
|
163
|
+
isValid?.required && ! hideLabelFromVision
|
|
199
164
|
? `${ label } (${ __( 'Required' ) })`
|
|
200
165
|
: label;
|
|
201
166
|
|
|
@@ -224,9 +189,8 @@ function CalendarDateTimeControl< Item >( {
|
|
|
224
189
|
<ValidatedInputControl
|
|
225
190
|
ref={ inputControlRef }
|
|
226
191
|
__next40pxDefaultSize
|
|
227
|
-
required={ !!
|
|
228
|
-
|
|
229
|
-
customValidity={ customValidity }
|
|
192
|
+
required={ !! isValid?.required }
|
|
193
|
+
customValidity={ getCustomValidity( isValid, validity ) }
|
|
230
194
|
type="datetime-local"
|
|
231
195
|
label={ __( 'Date time' ) }
|
|
232
196
|
hideLabelFromVision
|
|
@@ -250,6 +214,7 @@ export default function DateTime< Item >( {
|
|
|
250
214
|
onChange,
|
|
251
215
|
hideLabelFromVision,
|
|
252
216
|
operator,
|
|
217
|
+
validity,
|
|
253
218
|
}: DataFormControlProps< Item > ) {
|
|
254
219
|
if ( operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER ) {
|
|
255
220
|
return (
|
|
@@ -270,6 +235,7 @@ export default function DateTime< Item >( {
|
|
|
270
235
|
field={ field }
|
|
271
236
|
onChange={ onChange }
|
|
272
237
|
hideLabelFromVision={ hideLabelFromVision }
|
|
238
|
+
validity={ validity }
|
|
273
239
|
/>
|
|
274
240
|
);
|
|
275
241
|
}
|
|
@@ -18,6 +18,7 @@ export default function Email< Item >( {
|
|
|
18
18
|
field,
|
|
19
19
|
onChange,
|
|
20
20
|
hideLabelFromVision,
|
|
21
|
+
validity,
|
|
21
22
|
}: DataFormControlProps< Item > ) {
|
|
22
23
|
return (
|
|
23
24
|
<ValidatedText
|
|
@@ -26,6 +27,7 @@ export default function Email< Item >( {
|
|
|
26
27
|
field,
|
|
27
28
|
onChange,
|
|
28
29
|
hideLabelFromVision,
|
|
30
|
+
validity,
|
|
29
31
|
type: 'email',
|
|
30
32
|
prefix: (
|
|
31
33
|
<InputControlPrefixWrapper variant="icon">
|
|
@@ -29,6 +29,7 @@ import toggleGroup from './toggle-group';
|
|
|
29
29
|
import array from './array';
|
|
30
30
|
import color from './color';
|
|
31
31
|
import password from './password';
|
|
32
|
+
import hasElements from '../utils/has-elements';
|
|
32
33
|
|
|
33
34
|
interface FormControls {
|
|
34
35
|
[ key: string ]: ComponentType< DataFormControlProps< any > >;
|
|
@@ -87,7 +88,7 @@ export function getControl< Item >(
|
|
|
87
88
|
return createConfiguredControl( field.Edit );
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
if ( field
|
|
91
|
+
if ( hasElements( field ) && field.type !== 'array' ) {
|
|
91
92
|
return getControlByType( 'select' );
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -16,6 +16,7 @@ export default function Password< Item >( {
|
|
|
16
16
|
field,
|
|
17
17
|
onChange,
|
|
18
18
|
hideLabelFromVision,
|
|
19
|
+
validity,
|
|
19
20
|
}: DataFormControlProps< Item > ) {
|
|
20
21
|
const [ isVisible, setIsVisible ] = useState( false );
|
|
21
22
|
|
|
@@ -30,6 +31,7 @@ export default function Password< Item >( {
|
|
|
30
31
|
field,
|
|
31
32
|
onChange,
|
|
32
33
|
hideLabelFromVision,
|
|
34
|
+
validity,
|
|
33
35
|
type: isVisible ? 'text' : 'password',
|
|
34
36
|
suffix: (
|
|
35
37
|
<Button
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import deepMerge from 'deepmerge';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
9
|
-
import { privateApis } from '@wordpress/components';
|
|
10
|
-
import { useCallback
|
|
4
|
+
import { privateApis, Spinner } from '@wordpress/components';
|
|
5
|
+
import { useCallback } from '@wordpress/element';
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* Internal dependencies
|
|
14
9
|
*/
|
|
15
10
|
import type { DataFormControlProps } from '../types';
|
|
16
11
|
import { unlock } from '../lock-unlock';
|
|
12
|
+
import getCustomValidity from './utils/get-custom-validity';
|
|
13
|
+
import useElements from '../hooks/use-elements';
|
|
17
14
|
|
|
18
15
|
const { ValidatedRadioControl } = unlock( privateApis );
|
|
19
16
|
|
|
@@ -22,15 +19,14 @@ export default function Radio< Item >( {
|
|
|
22
19
|
field,
|
|
23
20
|
onChange,
|
|
24
21
|
hideLabelFromVision,
|
|
22
|
+
validity,
|
|
25
23
|
}: DataFormControlProps< Item > ) {
|
|
26
|
-
const { label, description,
|
|
24
|
+
const { label, description, getValue, setValue, isValid } = field;
|
|
25
|
+
const { elements, isLoading } = useElements( {
|
|
26
|
+
elements: field.elements,
|
|
27
|
+
getElements: field.getElements,
|
|
28
|
+
} );
|
|
27
29
|
const value = getValue( { item: data } );
|
|
28
|
-
const [ customValidity, setCustomValidity ] =
|
|
29
|
-
useState<
|
|
30
|
-
React.ComponentProps<
|
|
31
|
-
typeof ValidatedRadioControl
|
|
32
|
-
>[ 'customValidity' ]
|
|
33
|
-
>( undefined );
|
|
34
30
|
|
|
35
31
|
const onChangeControl = useCallback(
|
|
36
32
|
( newValue: string ) =>
|
|
@@ -38,47 +34,20 @@ export default function Radio< Item >( {
|
|
|
38
34
|
[ data, onChange, setValue ]
|
|
39
35
|
);
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const message = field.isValid?.custom?.(
|
|
44
|
-
deepMerge(
|
|
45
|
-
data,
|
|
46
|
-
setValue( {
|
|
47
|
-
item: data,
|
|
48
|
-
value: newValue,
|
|
49
|
-
} ) as Partial< Item >
|
|
50
|
-
),
|
|
51
|
-
field
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
if ( message ) {
|
|
55
|
-
setCustomValidity( {
|
|
56
|
-
type: 'invalid',
|
|
57
|
-
message,
|
|
58
|
-
} );
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
setCustomValidity( undefined );
|
|
63
|
-
},
|
|
64
|
-
[ data, field, setValue ]
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
if ( elements ) {
|
|
68
|
-
return (
|
|
69
|
-
<ValidatedRadioControl
|
|
70
|
-
required={ !! field.isValid?.required }
|
|
71
|
-
onValidate={ onValidateControl }
|
|
72
|
-
customValidity={ customValidity }
|
|
73
|
-
label={ label }
|
|
74
|
-
help={ description }
|
|
75
|
-
onChange={ onChangeControl }
|
|
76
|
-
options={ elements }
|
|
77
|
-
selected={ value }
|
|
78
|
-
hideLabelFromVision={ hideLabelFromVision }
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
37
|
+
if ( isLoading ) {
|
|
38
|
+
return <Spinner />;
|
|
81
39
|
}
|
|
82
40
|
|
|
83
|
-
return
|
|
41
|
+
return (
|
|
42
|
+
<ValidatedRadioControl
|
|
43
|
+
required={ !! field.isValid?.required }
|
|
44
|
+
customValidity={ getCustomValidity( isValid, validity ) }
|
|
45
|
+
label={ label }
|
|
46
|
+
help={ description }
|
|
47
|
+
onChange={ onChangeControl }
|
|
48
|
+
options={ elements }
|
|
49
|
+
selected={ value }
|
|
50
|
+
hideLabelFromVision={ hideLabelFromVision }
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
84
53
|
}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import deepMerge from 'deepmerge';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
9
|
-
import { privateApis } from '@wordpress/components';
|
|
10
|
-
import { useCallback
|
|
4
|
+
import { privateApis, Spinner } from '@wordpress/components';
|
|
5
|
+
import { useCallback } from '@wordpress/element';
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* Internal dependencies
|
|
14
9
|
*/
|
|
15
10
|
import type { DataFormControlProps } from '../types';
|
|
11
|
+
import useElements from '../hooks/use-elements';
|
|
16
12
|
import { unlock } from '../lock-unlock';
|
|
13
|
+
import getCustomValidity from './utils/get-custom-validity';
|
|
17
14
|
|
|
18
15
|
const { ValidatedSelectControl } = unlock( privateApis );
|
|
19
16
|
|
|
@@ -22,14 +19,9 @@ export default function Select< Item >( {
|
|
|
22
19
|
field,
|
|
23
20
|
onChange,
|
|
24
21
|
hideLabelFromVision,
|
|
22
|
+
validity,
|
|
25
23
|
}: DataFormControlProps< Item > ) {
|
|
26
|
-
const { type, label, description, getValue, setValue } = field;
|
|
27
|
-
const [ customValidity, setCustomValidity ] =
|
|
28
|
-
useState<
|
|
29
|
-
React.ComponentProps<
|
|
30
|
-
typeof ValidatedSelectControl
|
|
31
|
-
>[ 'customValidity' ]
|
|
32
|
-
>( undefined );
|
|
24
|
+
const { type, label, description, getValue, setValue, isValid } = field;
|
|
33
25
|
|
|
34
26
|
const isMultiple = type === 'array';
|
|
35
27
|
const value = getValue( { item: data } ) ?? ( isMultiple ? [] : '' );
|
|
@@ -40,39 +32,19 @@ export default function Select< Item >( {
|
|
|
40
32
|
[ data, onChange, setValue ]
|
|
41
33
|
);
|
|
42
34
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
data,
|
|
48
|
-
setValue( {
|
|
49
|
-
item: data,
|
|
50
|
-
value: newValue,
|
|
51
|
-
} ) as Partial< Item >
|
|
52
|
-
),
|
|
53
|
-
field
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if ( message ) {
|
|
57
|
-
setCustomValidity( {
|
|
58
|
-
type: 'invalid',
|
|
59
|
-
message,
|
|
60
|
-
} );
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setCustomValidity( undefined );
|
|
65
|
-
},
|
|
66
|
-
[ data, field, setValue ]
|
|
67
|
-
);
|
|
35
|
+
const { elements, isLoading } = useElements( {
|
|
36
|
+
elements: field.elements,
|
|
37
|
+
getElements: field.getElements,
|
|
38
|
+
} );
|
|
68
39
|
|
|
69
|
-
|
|
40
|
+
if ( isLoading ) {
|
|
41
|
+
return <Spinner />;
|
|
42
|
+
}
|
|
70
43
|
|
|
71
44
|
return (
|
|
72
45
|
<ValidatedSelectControl
|
|
73
46
|
required={ !! field.isValid?.required }
|
|
74
|
-
|
|
75
|
-
customValidity={ customValidity }
|
|
47
|
+
customValidity={ getCustomValidity( isValid, validity ) }
|
|
76
48
|
label={ label }
|
|
77
49
|
value={ value }
|
|
78
50
|
help={ description }
|
|
@@ -18,6 +18,7 @@ export default function Telephone< Item >( {
|
|
|
18
18
|
field,
|
|
19
19
|
onChange,
|
|
20
20
|
hideLabelFromVision,
|
|
21
|
+
validity,
|
|
21
22
|
}: DataFormControlProps< Item > ) {
|
|
22
23
|
return (
|
|
23
24
|
<ValidatedText
|
|
@@ -26,6 +27,7 @@ export default function Telephone< Item >( {
|
|
|
26
27
|
field,
|
|
27
28
|
onChange,
|
|
28
29
|
hideLabelFromVision,
|
|
30
|
+
validity,
|
|
29
31
|
type: 'tel',
|
|
30
32
|
prefix: (
|
|
31
33
|
<InputControlPrefixWrapper variant="icon">
|
|
@@ -15,6 +15,7 @@ export default function Text< Item >( {
|
|
|
15
15
|
onChange,
|
|
16
16
|
hideLabelFromVision,
|
|
17
17
|
config,
|
|
18
|
+
validity,
|
|
18
19
|
}: DataFormControlProps< Item > ) {
|
|
19
20
|
const { prefix, suffix } = config || {};
|
|
20
21
|
|
|
@@ -25,6 +26,7 @@ export default function Text< Item >( {
|
|
|
25
26
|
field,
|
|
26
27
|
onChange,
|
|
27
28
|
hideLabelFromVision,
|
|
29
|
+
validity,
|
|
28
30
|
prefix: prefix ? createElement( prefix ) : undefined,
|
|
29
31
|
suffix: suffix ? createElement( suffix ) : undefined,
|
|
30
32
|
} }
|