@wordpress/components 30.1.1-next.46f643fa0.0 → 30.2.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 +20 -4
- package/build/custom-gradient-picker/serializer.js +14 -0
- package/build/custom-gradient-picker/serializer.js.map +1 -1
- package/build/custom-gradient-picker/utils.js +12 -0
- package/build/custom-gradient-picker/utils.js.map +1 -1
- package/build/date-time/date/index.js +2 -4
- package/build/date-time/date/index.js.map +1 -1
- package/build/date-time/date/styles.js +41 -20
- package/build/date-time/date/styles.js.map +1 -1
- package/build/menu-item/index.js +1 -0
- package/build/menu-item/index.js.map +1 -1
- package/build/validated-form-controls/components/checkbox-control.js +5 -3
- package/build/validated-form-controls/components/checkbox-control.js.map +1 -1
- package/build/validated-form-controls/components/combobox-control.js +5 -3
- package/build/validated-form-controls/components/combobox-control.js.map +1 -1
- package/build/validated-form-controls/components/custom-select-control.js +5 -3
- package/build/validated-form-controls/components/custom-select-control.js.map +1 -1
- package/build/validated-form-controls/components/input-control.js +5 -3
- package/build/validated-form-controls/components/input-control.js.map +1 -1
- package/build/validated-form-controls/components/number-control.js +5 -3
- package/build/validated-form-controls/components/number-control.js.map +1 -1
- package/build/validated-form-controls/components/radio-control.js +5 -3
- package/build/validated-form-controls/components/radio-control.js.map +1 -1
- package/build/validated-form-controls/components/range-control.js +5 -3
- package/build/validated-form-controls/components/range-control.js.map +1 -1
- package/build/validated-form-controls/components/select-control.js +5 -3
- package/build/validated-form-controls/components/select-control.js.map +1 -1
- package/build/validated-form-controls/components/text-control.js +5 -3
- package/build/validated-form-controls/components/text-control.js.map +1 -1
- package/build/validated-form-controls/components/textarea-control.js +5 -3
- package/build/validated-form-controls/components/textarea-control.js.map +1 -1
- package/build/validated-form-controls/components/toggle-control.js +5 -3
- package/build/validated-form-controls/components/toggle-control.js.map +1 -1
- package/build/validated-form-controls/components/toggle-group-control.js +5 -3
- package/build/validated-form-controls/components/toggle-group-control.js.map +1 -1
- package/build/validated-form-controls/components/types.js.map +1 -1
- package/build/validated-form-controls/control-with-error.js +57 -22
- package/build/validated-form-controls/control-with-error.js.map +1 -1
- package/build/validated-form-controls/validity-indicator.js +45 -0
- package/build/validated-form-controls/validity-indicator.js.map +1 -0
- package/build-module/custom-gradient-picker/serializer.js +14 -0
- package/build-module/custom-gradient-picker/serializer.js.map +1 -1
- package/build-module/custom-gradient-picker/utils.js +12 -0
- package/build-module/custom-gradient-picker/utils.js.map +1 -1
- package/build-module/date-time/date/index.js +3 -4
- package/build-module/date-time/date/index.js.map +1 -1
- package/build-module/date-time/date/styles.js +39 -14
- package/build-module/date-time/date/styles.js.map +1 -1
- package/build-module/menu-item/index.js +1 -0
- package/build-module/menu-item/index.js.map +1 -1
- package/build-module/validated-form-controls/components/checkbox-control.js +5 -3
- package/build-module/validated-form-controls/components/checkbox-control.js.map +1 -1
- package/build-module/validated-form-controls/components/combobox-control.js +5 -3
- package/build-module/validated-form-controls/components/combobox-control.js.map +1 -1
- package/build-module/validated-form-controls/components/custom-select-control.js +5 -3
- package/build-module/validated-form-controls/components/custom-select-control.js.map +1 -1
- package/build-module/validated-form-controls/components/input-control.js +5 -3
- package/build-module/validated-form-controls/components/input-control.js.map +1 -1
- package/build-module/validated-form-controls/components/number-control.js +5 -3
- package/build-module/validated-form-controls/components/number-control.js.map +1 -1
- package/build-module/validated-form-controls/components/radio-control.js +5 -3
- package/build-module/validated-form-controls/components/radio-control.js.map +1 -1
- package/build-module/validated-form-controls/components/range-control.js +5 -3
- package/build-module/validated-form-controls/components/range-control.js.map +1 -1
- package/build-module/validated-form-controls/components/select-control.js +5 -3
- package/build-module/validated-form-controls/components/select-control.js.map +1 -1
- package/build-module/validated-form-controls/components/text-control.js +5 -3
- package/build-module/validated-form-controls/components/text-control.js.map +1 -1
- package/build-module/validated-form-controls/components/textarea-control.js +5 -3
- package/build-module/validated-form-controls/components/textarea-control.js.map +1 -1
- package/build-module/validated-form-controls/components/toggle-control.js +5 -3
- package/build-module/validated-form-controls/components/toggle-control.js.map +1 -1
- package/build-module/validated-form-controls/components/toggle-group-control.js +5 -3
- package/build-module/validated-form-controls/components/toggle-group-control.js.map +1 -1
- package/build-module/validated-form-controls/components/types.js.map +1 -1
- package/build-module/validated-form-controls/control-with-error.js +57 -21
- package/build-module/validated-form-controls/control-with-error.js.map +1 -1
- package/build-module/validated-form-controls/validity-indicator.js +37 -0
- package/build-module/validated-form-controls/validity-indicator.js.map +1 -0
- package/build-style/style-rtl.css +39 -29
- package/build-style/style.css +39 -29
- package/build-types/confirm-dialog/stories/index.story.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/utils.d.ts.map +1 -1
- package/build-types/date-time/date/index.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +6 -0
- package/build-types/date-time/date/styles.d.ts.map +1 -1
- package/build-types/divider/stories/index.story.d.ts.map +1 -1
- package/build-types/elevation/stories/index.story.d.ts.map +1 -1
- package/build-types/form-token-field/stories/index.story.d.ts +10 -5
- package/build-types/form-token-field/stories/index.story.d.ts.map +1 -1
- package/build-types/gradient-picker/stories/index.story.d.ts +2 -1
- package/build-types/gradient-picker/stories/index.story.d.ts.map +1 -1
- package/build-types/grid/stories/index.story.d.ts.map +1 -1
- package/build-types/h-stack/stories/index.story.d.ts.map +1 -1
- package/build-types/heading/stories/index.story.d.ts.map +1 -1
- package/build-types/input-control/stories/index.story.d.ts.map +1 -1
- package/build-types/item-group/stories/index.story.d.ts.map +1 -1
- package/build-types/menu-item/index.d.ts.map +1 -1
- package/build-types/number-control/stories/index.story.d.ts.map +1 -1
- package/build-types/scrollable/stories/index.story.d.ts.map +1 -1
- package/build-types/spacer/stories/index.story.d.ts.map +1 -1
- package/build-types/surface/stories/index.story.d.ts.map +1 -1
- package/build-types/text/stories/index.story.d.ts.map +1 -1
- package/build-types/toggle-group-control/stories/index.story.d.ts.map +1 -1
- package/build-types/tools-panel/stories/index.story.d.ts.map +1 -1
- package/build-types/tree-grid/stories/index.story.d.ts.map +1 -1
- package/build-types/truncate/stories/index.story.d.ts.map +1 -1
- package/build-types/unit-control/stories/index.story.d.ts.map +1 -1
- package/build-types/v-stack/stories/index.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/checkbox-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/combobox-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/custom-select-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/input-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/number-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/radio-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/select-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/input-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/number-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts +13 -0
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/range-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/select-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/text-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/textarea-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/toggle-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/toggle-group-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/types.d.ts +21 -10
- package/build-types/validated-form-controls/components/types.d.ts.map +1 -1
- package/build-types/validated-form-controls/control-with-error.d.ts +4 -5
- package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
- package/build-types/validated-form-controls/validity-indicator.d.ts +5 -0
- package/build-types/validated-form-controls/validity-indicator.d.ts.map +1 -0
- package/build-types/view/stories/index.story.d.ts.map +1 -1
- package/build-types/z-stack/stories/index.story.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/button/style.scss +3 -3
- package/src/calendar/style.scss +22 -22
- package/src/confirm-dialog/stories/index.story.tsx +3 -2
- package/src/custom-gradient-picker/serializer.ts +14 -0
- package/src/custom-gradient-picker/test/serializer.ts +25 -0
- package/src/custom-gradient-picker/utils.ts +10 -0
- package/src/date-time/date/index.tsx +4 -3
- package/src/date-time/date/styles.ts +13 -20
- package/src/divider/stories/index.story.tsx +2 -1
- package/src/elevation/stories/index.story.tsx +2 -1
- package/src/form-token-field/stories/index.story.tsx +15 -7
- package/src/gradient-picker/stories/index.story.tsx +48 -0
- package/src/grid/stories/index.story.tsx +2 -1
- package/src/h-stack/stories/e2e/index.story.tsx +1 -1
- package/src/h-stack/stories/index.story.tsx +3 -2
- package/src/heading/stories/index.story.tsx +3 -2
- package/src/input-control/stories/index.story.tsx +3 -2
- package/src/item-group/stories/index.story.tsx +2 -1
- package/src/menu/stories/index.story.tsx +1 -1
- package/src/menu-item/index.tsx +1 -0
- package/src/number-control/stories/index.story.tsx +3 -2
- package/src/scrollable/stories/index.story.tsx +2 -1
- package/src/spacer/stories/index.story.tsx +2 -1
- package/src/surface/stories/index.story.tsx +2 -1
- package/src/text/stories/index.story.tsx +3 -2
- package/src/toggle-group-control/stories/index.story.tsx +3 -2
- package/src/tools-panel/stories/index.story.tsx +2 -1
- package/src/tree-grid/stories/index.story.tsx +3 -2
- package/src/truncate/stories/index.story.tsx +3 -2
- package/src/unit-control/stories/index.story.tsx +3 -2
- package/src/utils/theme-variables.scss +1 -0
- package/src/v-stack/stories/e2e/index.story.tsx +1 -1
- package/src/v-stack/stories/index.story.tsx +3 -2
- package/src/validated-form-controls/components/checkbox-control.tsx +5 -3
- package/src/validated-form-controls/components/combobox-control.tsx +5 -3
- package/src/validated-form-controls/components/custom-select-control.tsx +5 -3
- package/src/validated-form-controls/components/input-control.tsx +5 -3
- package/src/validated-form-controls/components/number-control.tsx +5 -3
- package/src/validated-form-controls/components/radio-control.tsx +5 -3
- package/src/validated-form-controls/components/range-control.tsx +5 -3
- package/src/validated-form-controls/components/select-control.tsx +5 -3
- package/src/validated-form-controls/components/stories/checkbox-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/combobox-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/custom-select-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/input-control.story.tsx +53 -19
- package/src/validated-form-controls/components/stories/number-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/overview.mdx +2 -2
- package/src/validated-form-controls/components/stories/overview.story.tsx +124 -16
- package/src/validated-form-controls/components/stories/radio-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/range-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/select-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/text-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/textarea-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/toggle-control.story.tsx +19 -7
- package/src/validated-form-controls/components/stories/toggle-group-control.story.tsx +19 -7
- package/src/validated-form-controls/components/text-control.tsx +5 -3
- package/src/validated-form-controls/components/textarea-control.tsx +5 -3
- package/src/validated-form-controls/components/toggle-control.tsx +5 -3
- package/src/validated-form-controls/components/toggle-group-control.tsx +5 -3
- package/src/validated-form-controls/components/types.ts +21 -12
- package/src/validated-form-controls/control-with-error.tsx +77 -26
- package/src/validated-form-controls/style.scss +19 -5
- package/src/validated-form-controls/validity-indicator.tsx +48 -0
- package/src/view/stories/index.story.tsx +2 -1
- package/src/z-stack/stories/index.story.tsx +2 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMergeRefs","forwardRef","useRef","ControlWithError","RadioControl","jsx","_jsx","UnforwardedValidatedRadioControl","required","
|
|
1
|
+
{"version":3,"names":["useMergeRefs","forwardRef","useRef","ControlWithError","RadioControl","jsx","_jsx","UnforwardedValidatedRadioControl","required","onValidate","customValidity","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","mergedRefs","valueRef","selected","ref","current","getValidityTarget","querySelector","children","value","ValidatedRadioControl"],"sources":["@wordpress/components/src/validated-form-controls/components/radio-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { forwardRef, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport RadioControl from '../../radio-control';\nimport type { RadioControlProps } from '../../radio-control/types';\n\ntype Value = RadioControlProps[ 'selected' ];\n\nconst UnforwardedValidatedRadioControl = (\n\t{\n\t\trequired,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: React.ComponentProps< typeof RadioControl > &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLDivElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLDivElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.selected );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\t// TODO: Upstream limitation - RadioControl does not accept a ref.\n\t\t\tref={ mergedRefs }\n\t\t\tonValidate={ () => {\n\t\t\t\treturn onValidate?.( valueRef.current );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tgetValidityTarget={ () =>\n\t\t\t\tvalidityTargetRef.current?.querySelector< HTMLInputElement >(\n\t\t\t\t\t'input[type=\"radio\"]'\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<RadioControl\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>\n\t);\n};\n\nexport const ValidatedRadioControl = forwardRef(\n\tUnforwardedValidatedRadioControl\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,oBAAoB;AACjD,SAASC,UAAU,EAAEC,MAAM,QAAQ,oBAAoB;;AAEvD;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,OAAOC,YAAY,MAAM,qBAAqB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAK/C,MAAMC,gCAAgC,GAAGA,CACxC;EACCC,QAAQ;EACRC,UAAU;EACVC,cAAc;EACdC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;AAE0B,CAAC,EAC/BC,YAAkD,KAC9C;EACJ,MAAMC,iBAAiB,GAAGb,MAAM,CAAoB,IAAK,CAAC;EAC1D,MAAMc,UAAU,GAAGhB,YAAY,CAAE,CAAEc,YAAY,EAAEC,iBAAiB,CAAG,CAAC;EACtE,MAAME,QAAQ,GAAGf,MAAM,CAAWW,SAAS,CAACK,QAAS,CAAC;EAEtD,oBACCZ,IAAA,CAACH,gBAAgB;IAChBK,QAAQ,EAAGA,QAAU;IACrBI,gBAAgB,EAAGA;IACnB;IAAA;IACAO,GAAG,EAAGH,UAAY;IAClBP,UAAU,EAAGA,CAAA,KAAM;MAClB,OAAOA,UAAU,GAAIQ,QAAQ,CAACG,OAAQ,CAAC;IACxC,CAAG;IACHV,cAAc,EAAGA,cAAgB;IACjCW,iBAAiB,EAAGA,CAAA,KACnBN,iBAAiB,CAACK,OAAO,EAAEE,aAAa,CACvC,qBACD,CACA;IAAAC,QAAA,eAEDjB,IAAA,CAACF,YAAY;MACZO,QAAQ,EAAKa,KAAK,IAAM;QACvBP,QAAQ,CAACG,OAAO,GAAGI,KAAK;QACxBb,QAAQ,GAAIa,KAAM,CAAC;MACpB,CAAG;MAAA,GACEX;IAAS,CACd;EAAC,CACe,CAAC;AAErB,CAAC;AAED,OAAO,MAAMY,qBAAqB,GAAGxB,UAAU,CAC9CM,gCACD,CAAC","ignoreList":[]}
|
|
@@ -12,7 +12,8 @@ import RangeControl from '../../range-control';
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
const UnforwardedValidatedRangeControl = ({
|
|
14
14
|
required,
|
|
15
|
-
|
|
15
|
+
onValidate,
|
|
16
|
+
customValidity,
|
|
16
17
|
onChange,
|
|
17
18
|
markWhenOptional,
|
|
18
19
|
...restProps
|
|
@@ -23,9 +24,10 @@ const UnforwardedValidatedRangeControl = ({
|
|
|
23
24
|
return /*#__PURE__*/_jsx(ControlWithError, {
|
|
24
25
|
required: required,
|
|
25
26
|
markWhenOptional: markWhenOptional,
|
|
26
|
-
|
|
27
|
-
return
|
|
27
|
+
onValidate: () => {
|
|
28
|
+
return onValidate?.(valueRef.current);
|
|
28
29
|
},
|
|
30
|
+
customValidity: customValidity,
|
|
29
31
|
getValidityTarget: () => validityTargetRef.current,
|
|
30
32
|
children: /*#__PURE__*/_jsx(RangeControl, {
|
|
31
33
|
__next40pxDefaultSize: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMergeRefs","forwardRef","useRef","ControlWithError","RangeControl","jsx","_jsx","UnforwardedValidatedRangeControl","required","
|
|
1
|
+
{"version":3,"names":["useMergeRefs","forwardRef","useRef","ControlWithError","RangeControl","jsx","_jsx","UnforwardedValidatedRangeControl","required","onValidate","customValidity","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","mergedRefs","valueRef","value","current","getValidityTarget","children","__next40pxDefaultSize","__nextHasNoMarginBottom","ref","ValidatedRangeControl"],"sources":["@wordpress/components/src/validated-form-controls/components/range-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { forwardRef, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport RangeControl from '../../range-control';\nimport type { RangeControlProps } from '../../range-control/types';\n\ntype Value = RangeControlProps[ 'value' ];\n\nconst UnforwardedValidatedRangeControl = (\n\t{\n\t\trequired,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof RangeControl >,\n\t\t'__next40pxDefaultSize' | '__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLInputElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLInputElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.value );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tonValidate={ () => {\n\t\t\t\treturn onValidate?.( valueRef.current );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t>\n\t\t\t<RangeControl\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tref={ mergedRefs }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>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gCACD,CAAC","ignoreList":[]}
|
|
@@ -14,7 +14,8 @@ import SelectControl from '../../select-control';
|
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
const UnforwardedValidatedSelectControl = ({
|
|
16
16
|
required,
|
|
17
|
-
|
|
17
|
+
onValidate,
|
|
18
|
+
customValidity,
|
|
18
19
|
onChange,
|
|
19
20
|
markWhenOptional,
|
|
20
21
|
...restProps
|
|
@@ -25,9 +26,10 @@ const UnforwardedValidatedSelectControl = ({
|
|
|
25
26
|
return /*#__PURE__*/_jsx(ControlWithError, {
|
|
26
27
|
required: required,
|
|
27
28
|
markWhenOptional: markWhenOptional,
|
|
28
|
-
|
|
29
|
-
return
|
|
29
|
+
onValidate: () => {
|
|
30
|
+
return onValidate?.(valueRef.current);
|
|
30
31
|
},
|
|
32
|
+
customValidity: customValidity,
|
|
31
33
|
getValidityTarget: () => validityTargetRef.current,
|
|
32
34
|
children: /*#__PURE__*/_jsx(SelectControl, {
|
|
33
35
|
__nextHasNoMarginBottom: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useRef","useMergeRefs","ControlWithError","SelectControl","jsx","_jsx","UnforwardedValidatedSelectControl","required","
|
|
1
|
+
{"version":3,"names":["forwardRef","useRef","useMergeRefs","ControlWithError","SelectControl","jsx","_jsx","UnforwardedValidatedSelectControl","required","onValidate","customValidity","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","mergedRefs","valueRef","value","current","getValidityTarget","children","__nextHasNoMarginBottom","__next40pxDefaultSize","ref","ValidatedSelectControl"],"sources":["@wordpress/components/src/validated-form-controls/components/select-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport SelectControl from '../../select-control';\nimport type { ValidatedControlProps } from './types';\nimport type { SelectControlProps as _SelectControlProps } from '../../select-control/types';\n\n// Only support single value selection\ntype SelectControlProps = Omit<\n\t_SelectControlProps,\n\t'multiple' | 'onChange' | 'value'\n> & {\n\tonChange?: ( value: string ) => void;\n\tvalue?: string;\n};\n\ntype Value = SelectControlProps[ 'value' ];\n\nconst UnforwardedValidatedSelectControl = (\n\t{\n\t\trequired,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof SelectControl >,\n\t\t| '__next40pxDefaultSize'\n\t\t| '__nextHasNoMarginBottom'\n\t\t| 'multiple'\n\t\t| 'onChange'\n\t\t| 'value'\n\t> & {\n\t\tvalue?: string;\n\t\tonChange: ( value: string ) => void;\n\t} & ValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLSelectElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLSelectElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.value );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tonValidate={ () => {\n\t\t\t\treturn onValidate?.( valueRef.current );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t>\n\t\t\t<SelectControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tref={ mergedRefs }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>\n\t);\n};\n\nexport const ValidatedSelectControl = forwardRef(\n\tUnforwardedValidatedSelectControl\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,MAAM,QAAQ,oBAAoB;AACvD,SAASC,YAAY,QAAQ,oBAAoB;;AAEjD;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,uBAAuB;AACxD,OAAOC,aAAa,MAAM,sBAAsB;;AAIhD;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAWA,MAAMC,iCAAiC,GAAGA,CACzC;EACCC,QAAQ;EACRC,UAAU;EACVC,cAAc;EACdC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;AAW6B,CAAC,EAClCC,YAAqD,KACjD;EACJ,MAAMC,iBAAiB,GAAGd,MAAM,CAAuB,IAAK,CAAC;EAC7D,MAAMe,UAAU,GAAGd,YAAY,CAAE,CAAEY,YAAY,EAAEC,iBAAiB,CAAG,CAAC;EACtE,MAAME,QAAQ,GAAGhB,MAAM,CAAWY,SAAS,CAACK,KAAM,CAAC;EAEnD,oBACCZ,IAAA,CAACH,gBAAgB;IAChBK,QAAQ,EAAGA,QAAU;IACrBI,gBAAgB,EAAGA,gBAAkB;IACrCH,UAAU,EAAGA,CAAA,KAAM;MAClB,OAAOA,UAAU,GAAIQ,QAAQ,CAACE,OAAQ,CAAC;IACxC,CAAG;IACHT,cAAc,EAAGA,cAAgB;IACjCU,iBAAiB,EAAGA,CAAA,KAAML,iBAAiB,CAACI,OAAS;IAAAE,QAAA,eAErDf,IAAA,CAACF,aAAa;MACbkB,uBAAuB;MACvBC,qBAAqB;MACrBC,GAAG,EAAGR,UAAY;MAClBL,QAAQ,EAAKO,KAAK,IAAM;QACvBD,QAAQ,CAACE,OAAO,GAAGD,KAAK;QACxBP,QAAQ,GAAIO,KAAM,CAAC;MACpB,CAAG;MAAA,GACEL;IAAS,CACd;EAAC,CACe,CAAC;AAErB,CAAC;AAED,OAAO,MAAMY,sBAAsB,GAAGzB,UAAU,CAC/CO,iCACD,CAAC","ignoreList":[]}
|
|
@@ -12,7 +12,8 @@ import TextControl from '../../text-control';
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
const UnforwardedValidatedTextControl = ({
|
|
14
14
|
required,
|
|
15
|
-
|
|
15
|
+
onValidate,
|
|
16
|
+
customValidity,
|
|
16
17
|
onChange,
|
|
17
18
|
markWhenOptional,
|
|
18
19
|
...restProps
|
|
@@ -23,9 +24,10 @@ const UnforwardedValidatedTextControl = ({
|
|
|
23
24
|
return /*#__PURE__*/_jsx(ControlWithError, {
|
|
24
25
|
required: required,
|
|
25
26
|
markWhenOptional: markWhenOptional,
|
|
26
|
-
|
|
27
|
-
return
|
|
27
|
+
onValidate: () => {
|
|
28
|
+
return onValidate?.(valueRef.current);
|
|
28
29
|
},
|
|
30
|
+
customValidity: customValidity,
|
|
29
31
|
getValidityTarget: () => validityTargetRef.current,
|
|
30
32
|
children: /*#__PURE__*/_jsx(TextControl, {
|
|
31
33
|
__next40pxDefaultSize: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMergeRefs","forwardRef","useRef","ControlWithError","TextControl","jsx","_jsx","UnforwardedValidatedTextControl","required","
|
|
1
|
+
{"version":3,"names":["useMergeRefs","forwardRef","useRef","ControlWithError","TextControl","jsx","_jsx","UnforwardedValidatedTextControl","required","onValidate","customValidity","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","mergedRefs","valueRef","value","current","getValidityTarget","children","__next40pxDefaultSize","__nextHasNoMarginBottom","ref","ValidatedTextControl"],"sources":["@wordpress/components/src/validated-form-controls/components/text-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { forwardRef, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport TextControl from '../../text-control';\nimport type { TextControlProps } from '../../text-control/types';\n\ntype Value = TextControlProps[ 'value' ];\n\nconst UnforwardedValidatedTextControl = (\n\t{\n\t\trequired,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof TextControl >,\n\t\t'__next40pxDefaultSize' | '__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLInputElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLInputElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.value );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tonValidate={ () => {\n\t\t\t\treturn onValidate?.( valueRef.current );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t>\n\t\t\t<TextControl\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tref={ mergedRefs }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>\n\t);\n};\n\nexport const ValidatedTextControl = forwardRef(\n\tUnforwardedValidatedTextControl\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,oBAAoB;AACjD,SAASC,UAAU,EAAEC,MAAM,QAAQ,oBAAoB;;AAEvD;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,OAAOC,WAAW,MAAM,oBAAoB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAK7C,MAAMC,+BAA+B,GAAGA,CACvC;EACCC,QAAQ;EACRC,UAAU;EACVC,cAAc;EACdC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;AAK0B,CAAC,EAC/BC,YAAoD,KAChD;EACJ,MAAMC,iBAAiB,GAAGb,MAAM,CAAsB,IAAK,CAAC;EAC5D,MAAMc,UAAU,GAAGhB,YAAY,CAAE,CAAEc,YAAY,EAAEC,iBAAiB,CAAG,CAAC;EACtE,MAAME,QAAQ,GAAGf,MAAM,CAAWW,SAAS,CAACK,KAAM,CAAC;EAEnD,oBACCZ,IAAA,CAACH,gBAAgB;IAChBK,QAAQ,EAAGA,QAAU;IACrBI,gBAAgB,EAAGA,gBAAkB;IACrCH,UAAU,EAAGA,CAAA,KAAM;MAClB,OAAOA,UAAU,GAAIQ,QAAQ,CAACE,OAAQ,CAAC;IACxC,CAAG;IACHT,cAAc,EAAGA,cAAgB;IACjCU,iBAAiB,EAAGA,CAAA,KAAML,iBAAiB,CAACI,OAAS;IAAAE,QAAA,eAErDf,IAAA,CAACF,WAAW;MACXkB,qBAAqB;MACrBC,uBAAuB;MACvBC,GAAG,EAAGR,UAAY;MAClBL,QAAQ,EAAKO,KAAK,IAAM;QACvBD,QAAQ,CAACE,OAAO,GAAGD,KAAK;QACxBP,QAAQ,GAAIO,KAAM,CAAC;MACpB,CAAG;MAAA,GACEL;IAAS,CACd;EAAC,CACe,CAAC;AAErB,CAAC;AAED,OAAO,MAAMY,oBAAoB,GAAGxB,UAAU,CAC7CM,+BACD,CAAC","ignoreList":[]}
|
|
@@ -12,7 +12,8 @@ import TextareaControl from '../../textarea-control';
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
const UnforwardedValidatedTextareaControl = ({
|
|
14
14
|
required,
|
|
15
|
-
|
|
15
|
+
onValidate,
|
|
16
|
+
customValidity,
|
|
16
17
|
onChange,
|
|
17
18
|
markWhenOptional,
|
|
18
19
|
...restProps
|
|
@@ -23,9 +24,10 @@ const UnforwardedValidatedTextareaControl = ({
|
|
|
23
24
|
return /*#__PURE__*/_jsx(ControlWithError, {
|
|
24
25
|
required: required,
|
|
25
26
|
markWhenOptional: markWhenOptional,
|
|
26
|
-
|
|
27
|
-
return
|
|
27
|
+
onValidate: () => {
|
|
28
|
+
return onValidate?.(valueRef.current);
|
|
28
29
|
},
|
|
30
|
+
customValidity: customValidity,
|
|
29
31
|
getValidityTarget: () => validityTargetRef.current,
|
|
30
32
|
children: /*#__PURE__*/_jsx(TextareaControl, {
|
|
31
33
|
__nextHasNoMarginBottom: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useRef","useMergeRefs","ControlWithError","TextareaControl","jsx","_jsx","UnforwardedValidatedTextareaControl","required","
|
|
1
|
+
{"version":3,"names":["forwardRef","useRef","useMergeRefs","ControlWithError","TextareaControl","jsx","_jsx","UnforwardedValidatedTextareaControl","required","onValidate","customValidity","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","mergedRefs","valueRef","value","current","getValidityTarget","children","__nextHasNoMarginBottom","ref","ValidatedTextareaControl"],"sources":["@wordpress/components/src/validated-form-controls/components/textarea-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport TextareaControl from '../../textarea-control';\nimport type { TextareaControlProps } from '../../textarea-control/types';\n\ntype Value = TextareaControlProps[ 'value' ];\n\nconst UnforwardedValidatedTextareaControl = (\n\t{\n\t\trequired,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof TextareaControl >,\n\t\t'__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLTextAreaElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLTextAreaElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.value );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tonValidate={ () => {\n\t\t\t\treturn onValidate?.( valueRef.current );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t>\n\t\t\t<TextareaControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tref={ mergedRefs }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>\n\t);\n};\n\nexport const ValidatedTextareaControl = forwardRef(\n\tUnforwardedValidatedTextareaControl\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,MAAM,QAAQ,oBAAoB;AACvD,SAASC,YAAY,QAAQ,oBAAoB;;AAEjD;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,OAAOC,eAAe,MAAM,wBAAwB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAKrD,MAAMC,mCAAmC,GAAGA,CAC3C;EACCC,QAAQ;EACRC,UAAU;EACVC,cAAc;EACdC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;AAK0B,CAAC,EAC/BC,YAAuD,KACnD;EACJ,MAAMC,iBAAiB,GAAGd,MAAM,CAAyB,IAAK,CAAC;EAC/D,MAAMe,UAAU,GAAGd,YAAY,CAAE,CAAEY,YAAY,EAAEC,iBAAiB,CAAG,CAAC;EACtE,MAAME,QAAQ,GAAGhB,MAAM,CAAWY,SAAS,CAACK,KAAM,CAAC;EAEnD,oBACCZ,IAAA,CAACH,gBAAgB;IAChBK,QAAQ,EAAGA,QAAU;IACrBI,gBAAgB,EAAGA,gBAAkB;IACrCH,UAAU,EAAGA,CAAA,KAAM;MAClB,OAAOA,UAAU,GAAIQ,QAAQ,CAACE,OAAQ,CAAC;IACxC,CAAG;IACHT,cAAc,EAAGA,cAAgB;IACjCU,iBAAiB,EAAGA,CAAA,KAAML,iBAAiB,CAACI,OAAS;IAAAE,QAAA,eAErDf,IAAA,CAACF,eAAe;MACfkB,uBAAuB;MACvBC,GAAG,EAAGP,UAAY;MAClBL,QAAQ,EAAKO,KAAK,IAAM;QACvBD,QAAQ,CAACE,OAAO,GAAGD,KAAK;QACxBP,QAAQ,GAAIO,KAAM,CAAC;MACpB,CAAG;MAAA,GACEL;IAAS,CACd;EAAC,CACe,CAAC;AAErB,CAAC;AAED,OAAO,MAAMW,wBAAwB,GAAGxB,UAAU,CACjDO,mCACD,CAAC","ignoreList":[]}
|
|
@@ -14,7 +14,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
14
14
|
|
|
15
15
|
const UnforwardedValidatedToggleControl = ({
|
|
16
16
|
required,
|
|
17
|
-
|
|
17
|
+
onValidate,
|
|
18
|
+
customValidity,
|
|
18
19
|
onChange,
|
|
19
20
|
markWhenOptional,
|
|
20
21
|
...restProps
|
|
@@ -33,9 +34,10 @@ const UnforwardedValidatedToggleControl = ({
|
|
|
33
34
|
return /*#__PURE__*/_jsx(ControlWithError, {
|
|
34
35
|
required: required,
|
|
35
36
|
markWhenOptional: markWhenOptional,
|
|
36
|
-
|
|
37
|
-
return
|
|
37
|
+
onValidate: () => {
|
|
38
|
+
return onValidate?.(valueRef.current);
|
|
38
39
|
},
|
|
40
|
+
customValidity: customValidity,
|
|
39
41
|
getValidityTarget: () => validityTargetRef.current,
|
|
40
42
|
children: /*#__PURE__*/_jsx(ToggleControl, {
|
|
41
43
|
__nextHasNoMarginBottom: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useRef","useEffect","useMergeRefs","ControlWithError","ToggleControl","jsx","_jsx","UnforwardedValidatedToggleControl","required","
|
|
1
|
+
{"version":3,"names":["forwardRef","useRef","useEffect","useMergeRefs","ControlWithError","ToggleControl","jsx","_jsx","UnforwardedValidatedToggleControl","required","onValidate","customValidity","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","mergedRefs","valueRef","checked","current","getValidityTarget","children","__nextHasNoMarginBottom","ref","value","ValidatedToggleControl"],"sources":["@wordpress/components/src/validated-form-controls/components/toggle-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useRef, useEffect } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport ToggleControl from '../../toggle-control';\nimport type { ToggleControlProps } from '../../toggle-control/types';\n\ntype Value = ToggleControlProps[ 'checked' ];\n\n// TODO: Should we customize the default `missingValue` message? It says to \"check this box\".\n\nconst UnforwardedValidatedToggleControl = (\n\t{\n\t\trequired,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof ToggleControl >,\n\t\t'__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLInputElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLInputElement >( null );\n\tconst mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );\n\tconst valueRef = useRef< Value >( restProps.checked );\n\n\t// TODO: Upstream limitation - The `required` attribute is not passed down to the input,\n\t// so we need to set it manually.\n\tuseEffect( () => {\n\t\tif ( validityTargetRef.current ) {\n\t\t\tvalidityTargetRef.current.required = required ?? false;\n\t\t}\n\t}, [ required ] );\n\n\treturn (\n\t\t<ControlWithError\n\t\t\trequired={ required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tonValidate={ () => {\n\t\t\t\treturn onValidate?.( valueRef.current );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t>\n\t\t\t<ToggleControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tref={ mergedRefs }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\tonChange?.( value );\n\t\t\t\t} }\n\t\t\t\t{ ...restProps }\n\t\t\t/>\n\t\t</ControlWithError>\n\t);\n};\n\nexport const ValidatedToggleControl = forwardRef(\n\tUnforwardedValidatedToggleControl\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,MAAM,EAAEC,SAAS,QAAQ,oBAAoB;AAClE,SAASC,YAAY,QAAQ,oBAAoB;;AAEjD;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,OAAOC,aAAa,MAAM,sBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAKjD;;AAEA,MAAMC,iCAAiC,GAAGA,CACzC;EACCC,QAAQ;EACRC,UAAU;EACVC,cAAc;EACdC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;AAK0B,CAAC,EAC/BC,YAAoD,KAChD;EACJ,MAAMC,iBAAiB,GAAGf,MAAM,CAAsB,IAAK,CAAC;EAC5D,MAAMgB,UAAU,GAAGd,YAAY,CAAE,CAAEY,YAAY,EAAEC,iBAAiB,CAAG,CAAC;EACtE,MAAME,QAAQ,GAAGjB,MAAM,CAAWa,SAAS,CAACK,OAAQ,CAAC;;EAErD;EACA;EACAjB,SAAS,CAAE,MAAM;IAChB,IAAKc,iBAAiB,CAACI,OAAO,EAAG;MAChCJ,iBAAiB,CAACI,OAAO,CAACX,QAAQ,GAAGA,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAI,KAAK;IACvD;EACD,CAAC,EAAE,CAAEA,QAAQ,CAAG,CAAC;EAEjB,oBACCF,IAAA,CAACH,gBAAgB;IAChBK,QAAQ,EAAGA,QAAU;IACrBI,gBAAgB,EAAGA,gBAAkB;IACrCH,UAAU,EAAGA,CAAA,KAAM;MAClB,OAAOA,UAAU,GAAIQ,QAAQ,CAACE,OAAQ,CAAC;IACxC,CAAG;IACHT,cAAc,EAAGA,cAAgB;IACjCU,iBAAiB,EAAGA,CAAA,KAAML,iBAAiB,CAACI,OAAS;IAAAE,QAAA,eAErDf,IAAA,CAACF,aAAa;MACbkB,uBAAuB;MACvBC,GAAG,EAAGP,UAAY;MAClBL,QAAQ,EAAKa,KAAK,IAAM;QACvBP,QAAQ,CAACE,OAAO,GAAGK,KAAK;QACxBb,QAAQ,GAAIa,KAAM,CAAC;MACpB,CAAG;MAAA,GACEX;IAAS,CACd;EAAC,CACe,CAAC;AAErB,CAAC;AAED,OAAO,MAAMY,sBAAsB,GAAG1B,UAAU,CAC/CQ,iCACD,CAAC","ignoreList":[]}
|
|
@@ -11,7 +11,8 @@ import { ToggleGroupControl } from '../../toggle-group-control';
|
|
|
11
11
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
12
|
const UnforwardedValidatedToggleGroupControl = ({
|
|
13
13
|
required,
|
|
14
|
-
|
|
14
|
+
onValidate,
|
|
15
|
+
customValidity,
|
|
15
16
|
onChange,
|
|
16
17
|
markWhenOptional,
|
|
17
18
|
...restProps
|
|
@@ -24,9 +25,10 @@ const UnforwardedValidatedToggleGroupControl = ({
|
|
|
24
25
|
children: [/*#__PURE__*/_jsx(ControlWithError, {
|
|
25
26
|
required: required,
|
|
26
27
|
markWhenOptional: markWhenOptional,
|
|
27
|
-
|
|
28
|
-
return
|
|
28
|
+
onValidate: () => {
|
|
29
|
+
return onValidate?.(valueRef.current);
|
|
29
30
|
},
|
|
31
|
+
customValidity: customValidity,
|
|
30
32
|
getValidityTarget: () => validityTargetRef.current,
|
|
31
33
|
children: /*#__PURE__*/_jsx(ToggleGroupControl, {
|
|
32
34
|
__nextHasNoMarginBottom: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useId","useRef","ControlWithError","ToggleGroupControl","jsx","_jsx","jsxs","_jsxs","UnforwardedValidatedToggleGroupControl","required","
|
|
1
|
+
{"version":3,"names":["forwardRef","useId","useRef","ControlWithError","ToggleGroupControl","jsx","_jsx","jsxs","_jsxs","UnforwardedValidatedToggleGroupControl","required","onValidate","customValidity","onChange","markWhenOptional","restProps","forwardedRef","validityTargetRef","valueRef","value","nameAttr","className","children","current","getValidityTarget","__nextHasNoMarginBottom","__next40pxDefaultSize","ref","type","checked","tabIndex","name","onFocus","e","target","previousElementSibling","querySelector","focus","ValidatedToggleGroupControl"],"sources":["@wordpress/components/src/validated-form-controls/components/toggle-group-control.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useId, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport type { ValidatedControlProps } from './types';\nimport { ToggleGroupControl } from '../../toggle-group-control';\nimport type { ToggleGroupControlProps } from '../../toggle-group-control/types';\n\ntype Value = ToggleGroupControlProps[ 'value' ];\n\nconst UnforwardedValidatedToggleGroupControl = (\n\t{\n\t\trequired,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tonChange,\n\t\tmarkWhenOptional,\n\t\t...restProps\n\t}: Omit<\n\t\tReact.ComponentProps< typeof ToggleGroupControl >,\n\t\t'__next40pxDefaultSize' | '__nextHasNoMarginBottom'\n\t> &\n\t\tValidatedControlProps< Value >,\n\tforwardedRef: React.ForwardedRef< HTMLInputElement >\n) => {\n\tconst validityTargetRef = useRef< HTMLInputElement >( null );\n\tconst valueRef = useRef< Value >( restProps.value );\n\n\tconst nameAttr = useId();\n\n\treturn (\n\t\t<div className=\"components-validated-control__wrapper-with-error-delegate\">\n\t\t\t<ControlWithError\n\t\t\t\trequired={ required }\n\t\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\t\tonValidate={ () => {\n\t\t\t\t\treturn onValidate?.( valueRef.current );\n\t\t\t\t} }\n\t\t\t\tcustomValidity={ customValidity }\n\t\t\t\tgetValidityTarget={ () => validityTargetRef.current }\n\t\t\t>\n\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ forwardedRef }\n\t\t\t\t\t// TODO: Upstream limitation - In uncontrolled mode, starting from an undefined value then\n\t\t\t\t\t// setting a value has a visual bug.\n\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\tvalueRef.current = value;\n\t\t\t\t\t\tonChange?.( value );\n\t\t\t\t\t} }\n\t\t\t\t\t{ ...restProps }\n\t\t\t\t/>\n\t\t\t</ControlWithError>\n\t\t\t<input\n\t\t\t\tclassName=\"components-validated-control__error-delegate\"\n\t\t\t\ttype=\"radio\"\n\t\t\t\tref={ validityTargetRef }\n\t\t\t\trequired={ required }\n\t\t\t\tchecked={ restProps.value !== null }\n\t\t\t\ttabIndex={ -1 }\n\t\t\t\t// A name attribute is needed for the `required` behavior to work.\n\t\t\t\tname={ nameAttr }\n\t\t\t\tonChange={ () => {} }\n\t\t\t\tonFocus={ ( e ) => {\n\t\t\t\t\te.target.previousElementSibling\n\t\t\t\t\t\t?.querySelector< HTMLButtonElement | HTMLInputElement >(\n\t\t\t\t\t\t\t'[data-active-item=\"true\"]'\n\t\t\t\t\t\t)\n\t\t\t\t\t\t?.focus();\n\t\t\t\t} }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport const ValidatedToggleGroupControl = forwardRef(\n\tUnforwardedValidatedToggleGroupControl\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,KAAK,EAAEC,MAAM,QAAQ,oBAAoB;;AAE9D;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,SAASC,kBAAkB,QAAQ,4BAA4B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAKhE,MAAMC,sCAAsC,GAAGA,CAC9C;EACCC,QAAQ;EACRC,UAAU;EACVC,cAAc;EACdC,QAAQ;EACRC,gBAAgB;EAChB,GAAGC;AAK0B,CAAC,EAC/BC,YAAoD,KAChD;EACJ,MAAMC,iBAAiB,GAAGf,MAAM,C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AU,CACpDS,sCACD,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/components/src/validated-form-controls/components/types.ts"],"sourcesContent":["export type ValidatedControlProps< V > = {\n\t/**\n\t * Whether the control is required.\n\t * @default false\n\t */\n\trequired?: boolean;\n\t/**\n\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t * @default false\n\t */\n\tmarkWhenOptional?: boolean;\n\t/**\n\t *
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/components/src/validated-form-controls/components/types.ts"],"sourcesContent":["export type ValidatedControlProps< V > = {\n\t/**\n\t * Whether the control is required.\n\t * @default false\n\t */\n\trequired?: boolean;\n\t/**\n\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t * @default false\n\t */\n\tmarkWhenOptional?: boolean;\n\t/**\n\t * Optional callback to run when the input should be validated. Use this to set\n\t * a `customValidity` as necessary.\n\t *\n\t * Always prefer using standard HTML attributes like `required` and `min`/`max` over\n\t * custom validators when possible, as they are simpler and have localized error messages built in.\n\t */\n\tonValidate?: ( currentValue: V ) => void;\n\t/**\n\t * Show a custom message based on the validation status.\n\t *\n\t * - When `type` is `invalid`, the message will be applied to the underlying element using the\n\t * native [`setCustomValidity()` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity).\n\t * This means the custom message will be prioritized over any existing validity messages\n\t * triggered by HTML attribute-based validation.\n\t * - When `type` is `validating` or `valid`, the custom validity message of the underlying element\n\t * will be cleared. If there are no remaining validity messages triggered by HTML attribute-based validation,\n\t * the message will be presented as a status indicator rather than an error. These indicators are intended\n\t * for asynchronous validation calls that may take more than 1 second to complete.\n\t * Otherwise, custom errors can simply be cleared by setting the `customValidity` prop to `undefined`.\n\t */\n\tcustomValidity?: {\n\t\ttype: 'validating' | 'valid' | 'invalid';\n\t\tmessage: string;\n\t};\n};\n"],"mappings":"","ignoreList":[]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import { error } from '@wordpress/icons';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* External dependencies
|
|
@@ -13,7 +12,7 @@ import { cloneElement, forwardRef, useEffect, useState } from '@wordpress/elemen
|
|
|
13
12
|
* Internal dependencies
|
|
14
13
|
*/
|
|
15
14
|
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';
|
|
16
|
-
import
|
|
15
|
+
import { ValidityIndicator } from './validity-indicator';
|
|
17
16
|
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
18
17
|
function appendRequiredIndicator(label, required, markWhenOptional) {
|
|
19
18
|
if (required && !markWhenOptional) {
|
|
@@ -41,11 +40,13 @@ function appendRequiredIndicator(label, required, markWhenOptional) {
|
|
|
41
40
|
function UnforwardedControlWithError({
|
|
42
41
|
required,
|
|
43
42
|
markWhenOptional,
|
|
44
|
-
|
|
43
|
+
onValidate,
|
|
44
|
+
customValidity,
|
|
45
45
|
getValidityTarget,
|
|
46
46
|
children
|
|
47
47
|
}, forwardedRef) {
|
|
48
48
|
const [errorMessage, setErrorMessage] = useState();
|
|
49
|
+
const [statusMessage, setStatusMessage] = useState();
|
|
49
50
|
const [isTouched, setIsTouched] = useState(false);
|
|
50
51
|
|
|
51
52
|
// Ensure that error messages are visible after user attemps to submit a form
|
|
@@ -58,12 +59,49 @@ function UnforwardedControlWithError({
|
|
|
58
59
|
validityTarget?.removeEventListener('invalid', showValidationMessage);
|
|
59
60
|
};
|
|
60
61
|
});
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!isTouched) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
63
66
|
const validityTarget = getValidityTarget();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
if (!customValidity?.type) {
|
|
68
|
+
validityTarget?.setCustomValidity('');
|
|
69
|
+
setErrorMessage(validityTarget?.validationMessage);
|
|
70
|
+
setStatusMessage(undefined);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
switch (customValidity.type) {
|
|
74
|
+
case 'validating':
|
|
75
|
+
{
|
|
76
|
+
// Wait before showing a validating state.
|
|
77
|
+
const timer = setTimeout(() => {
|
|
78
|
+
setStatusMessage({
|
|
79
|
+
type: 'validating',
|
|
80
|
+
message: customValidity.message
|
|
81
|
+
});
|
|
82
|
+
}, 1000);
|
|
83
|
+
return () => clearTimeout(timer);
|
|
84
|
+
}
|
|
85
|
+
case 'valid':
|
|
86
|
+
{
|
|
87
|
+
validityTarget?.setCustomValidity('');
|
|
88
|
+
setErrorMessage(validityTarget?.validationMessage);
|
|
89
|
+
setStatusMessage({
|
|
90
|
+
type: 'valid',
|
|
91
|
+
message: customValidity.message
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
case 'invalid':
|
|
96
|
+
{
|
|
97
|
+
var _customValidity$messa;
|
|
98
|
+
validityTarget?.setCustomValidity((_customValidity$messa = customValidity.message) !== null && _customValidity$messa !== void 0 ? _customValidity$messa : '');
|
|
99
|
+
setErrorMessage(validityTarget?.validationMessage);
|
|
100
|
+
setStatusMessage(undefined);
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}, [isTouched, customValidity?.type, customValidity?.message, getValidityTarget]);
|
|
67
105
|
const onBlur = event => {
|
|
68
106
|
// Only consider "blurred from the component" if focus has fully left the wrapping div.
|
|
69
107
|
// This prevents unnecessary blurs from components with multiple focusable elements.
|
|
@@ -78,7 +116,7 @@ function UnforwardedControlWithError({
|
|
|
78
116
|
}
|
|
79
117
|
return;
|
|
80
118
|
}
|
|
81
|
-
|
|
119
|
+
onValidate?.();
|
|
82
120
|
}
|
|
83
121
|
};
|
|
84
122
|
const onChange = (...args) => {
|
|
@@ -87,14 +125,14 @@ function UnforwardedControlWithError({
|
|
|
87
125
|
// Only validate incrementally if the field has blurred at least once,
|
|
88
126
|
// or currently has an error message.
|
|
89
127
|
if (isTouched || errorMessage) {
|
|
90
|
-
|
|
128
|
+
onValidate?.();
|
|
91
129
|
}
|
|
92
130
|
};
|
|
93
131
|
const onKeyDown = event => {
|
|
94
132
|
// Ensures that custom validators are triggered when the user submits by pressing Enter,
|
|
95
133
|
// without ever blurring the control.
|
|
96
134
|
if (event.key === 'Enter') {
|
|
97
|
-
|
|
135
|
+
onValidate?.();
|
|
98
136
|
}
|
|
99
137
|
};
|
|
100
138
|
return (
|
|
@@ -110,17 +148,15 @@ function UnforwardedControlWithError({
|
|
|
110
148
|
label: appendRequiredIndicator(children.props.label, required, markWhenOptional),
|
|
111
149
|
onChange,
|
|
112
150
|
required
|
|
113
|
-
}), /*#__PURE__*/
|
|
151
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
114
152
|
"aria-live": "polite",
|
|
115
|
-
children: errorMessage && /*#__PURE__*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}), errorMessage]
|
|
123
|
-
})
|
|
153
|
+
children: [errorMessage && /*#__PURE__*/_jsx(ValidityIndicator, {
|
|
154
|
+
type: "invalid",
|
|
155
|
+
message: errorMessage
|
|
156
|
+
}), !errorMessage && statusMessage && /*#__PURE__*/_jsx(ValidityIndicator, {
|
|
157
|
+
type: statusMessage.type,
|
|
158
|
+
message: statusMessage.message
|
|
159
|
+
})]
|
|
124
160
|
})]
|
|
125
161
|
})
|
|
126
162
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","error","cloneElement","forwardRef","useEffect","useState","withIgnoreIMEEvents","Icon","Fragment","_Fragment","jsxs","_jsxs","jsx","_jsx","appendRequiredIndicator","label","required","markWhenOptional","children","UnforwardedControlWithError","customValidator","getValidityTarget","forwardedRef","errorMessage","setErrorMessage","isTouched","setIsTouched","validityTarget","showValidationMessage","validationMessage","addEventListener","removeEventListener","validate","message","setCustomValidity","onBlur","event","relatedTarget","currentTarget","contains","validity","valid","onChange","args","props","onKeyDown","key","className","ref","icon","size","fill","ControlWithError"],"sources":["@wordpress/components/src/validated-form-controls/control-with-error.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { error } from '@wordpress/icons';\n\n/**\n * External dependencies\n */\nimport {\n\tcloneElement,\n\tforwardRef,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\n\nimport Icon from '../icon';\n\nfunction appendRequiredIndicator(\n\tlabel: React.ReactNode,\n\trequired: boolean | undefined,\n\tmarkWhenOptional: boolean | undefined\n) {\n\tif ( required && ! markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Required' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\tif ( ! required && markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Optional' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\treturn label;\n}\n\n/**\n * HTML elements that support the Constraint Validation API.\n *\n * Here, we exclude HTMLButtonElement because although it does technically support the API,\n * normal buttons are actually exempted from any validation.\n * @see https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/willValidate\n */\ntype ValidityTarget =\n\t| HTMLFieldSetElement\n\t| HTMLInputElement\n\t| HTMLSelectElement\n\t| HTMLTextAreaElement;\n\nfunction UnforwardedControlWithError< C extends React.ReactElement >(\n\t{\n\t\trequired,\n\t\tmarkWhenOptional,\n\t\tcustomValidator,\n\t\tgetValidityTarget,\n\t\tchildren,\n\t}: {\n\t\t/**\n\t\t * Whether the control is required.\n\t\t */\n\t\trequired?: boolean;\n\t\t/**\n\t\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t\t */\n\t\tmarkWhenOptional?: boolean;\n\t\t/**\n\t\t * A function that returns a custom validity message when applicable.\n\t\t *\n\t\t * This message will be applied to the element returned by `getValidityTarget`.\n\t\t * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity\n\t\t */\n\t\tcustomValidator?: () => string | void;\n\t\t/**\n\t\t * A function that returns the actual element on which the validity data should be applied.\n\t\t */\n\t\tgetValidityTarget: () => ValidityTarget | null | undefined;\n\t\t/**\n\t\t * The control component to apply validation to.\n\t\t */\n\t\tchildren: C;\n\t},\n\tforwardedRef: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst [ errorMessage, setErrorMessage ] = useState< string | undefined >();\n\tconst [ isTouched, setIsTouched ] = useState( false );\n\n\t// Ensure that error messages are visible after user attemps to submit a form\n\t// with multiple invalid fields.\n\tuseEffect( () => {\n\t\tconst validityTarget = getValidityTarget();\n\t\tconst showValidationMessage = () =>\n\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\tvalidityTarget?.addEventListener( 'invalid', showValidationMessage );\n\n\t\treturn () => {\n\t\t\tvalidityTarget?.removeEventListener(\n\t\t\t\t'invalid',\n\t\t\t\tshowValidationMessage\n\t\t\t);\n\t\t};\n\t} );\n\n\tconst validate = () => {\n\t\tconst message = customValidator?.();\n\t\tconst validityTarget = getValidityTarget();\n\n\t\tvalidityTarget?.setCustomValidity( message ?? '' );\n\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t};\n\n\tconst onBlur = ( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t// Only consider \"blurred from the component\" if focus has fully left the wrapping div.\n\t\t// This prevents unnecessary blurs from components with multiple focusable elements.\n\t\tif (\n\t\t\t! event.relatedTarget ||\n\t\t\t! event.currentTarget.contains( event.relatedTarget )\n\t\t) {\n\t\t\tsetIsTouched( true );\n\n\t\t\tconst validityTarget = getValidityTarget();\n\n\t\t\t// Prevents a double flash of the native error tooltip when the control is already showing one.\n\t\t\tif ( ! validityTarget?.validity.valid ) {\n\t\t\t\tif ( ! errorMessage ) {\n\t\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\tconst onChange = ( ...args: unknown[] ) => {\n\t\tchildren.props.onChange?.( ...args );\n\n\t\t// Only validate incrementally if the field has blurred at least once,\n\t\t// or currently has an error message.\n\t\tif ( isTouched || errorMessage ) {\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\tconst onKeyDown = ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t// Ensures that custom validators are triggered when the user submits by pressing Enter,\n\t\t// without ever blurring the control.\n\t\tif ( event.key === 'Enter' ) {\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\treturn (\n\t\t// Disable reason: Just listening to a bubbled event, not for interaction.\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName=\"components-validated-control\"\n\t\t\tref={ forwardedRef }\n\t\t\tonBlur={ onBlur }\n\t\t\tonKeyDown={ withIgnoreIMEEvents( onKeyDown ) }\n\t\t>\n\t\t\t{ cloneElement( children, {\n\t\t\t\tlabel: appendRequiredIndicator(\n\t\t\t\t\tchildren.props.label,\n\t\t\t\t\trequired,\n\t\t\t\t\tmarkWhenOptional\n\t\t\t\t),\n\t\t\t\tonChange,\n\t\t\t\trequired,\n\t\t\t} ) }\n\t\t\t<div aria-live=\"polite\">\n\t\t\t\t{ errorMessage && (\n\t\t\t\t\t<p className=\"components-validated-control__error\">\n\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\tclassName=\"components-validated-control__error-icon\"\n\t\t\t\t\t\t\ticon={ error }\n\t\t\t\t\t\t\tsize={ 16 }\n\t\t\t\t\t\t\tfill=\"currentColor\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport const ControlWithError = forwardRef( UnforwardedControlWithError );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,KAAK,QAAQ,kBAAkB;;AAExC;AACA;AACA;AACA,SACCC,YAAY,EACZC,UAAU,EACVC,SAAS,EACTC,QAAQ,QACF,oBAAoB;;AAE3B;AACA;AACA;AACA,SAASC,mBAAmB,QAAQ,iCAAiC;AAErE,OAAOC,IAAI,MAAM,SAAS;AAAC,SAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA,EAAAC,GAAA,IAAAC,IAAA;AAE3B,SAASC,uBAAuBA,CAC/BC,KAAsB,EACtBC,QAA6B,EAC7BC,gBAAqC,EACpC;EACD,IAAKD,QAAQ,IAAI,CAAEC,gBAAgB,EAAG;IACrC,oBACCN,KAAA,CAAAF,SAAA;MAAAS,QAAA,GACGH,KAAK,EAAE,GAAC,EAAE,IAAKf,EAAE,CAAE,UAAW,CAAC,GAAI;IAAA,CACpC,CAAC;EAEL;EACA,IAAK,CAAEgB,QAAQ,IAAIC,gBAAgB,EAAG;IACrC,oBACCN,KAAA,CAAAF,SAAA;MAAAS,QAAA,GACGH,KAAK,EAAE,GAAC,EAAE,IAAKf,EAAE,CAAE,UAAW,CAAC,GAAI;IAAA,CACpC,CAAC;EAEL;EACA,OAAOe,KAAK;AACb;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASI,2BAA2BA,CACnC;EACCH,QAAQ;EACRC,gBAAgB;EAChBG,eAAe;EACfC,iBAAiB;EACjBH;AAyBD,CAAC,EACDI,YAAkD,EACjD;EACD,MAAM,CAAEC,YAAY,EAAEC,eAAe,CAAE,GAAGnB,QAAQ,CAAuB,CAAC;EAC1E,MAAM,CAAEoB,SAAS,EAAEC,YAAY,CAAE,GAAGrB,QAAQ,CAAE,KAAM,CAAC;;E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;MAChCS,QAAQ,CAAC,CAAC;IACX;EACD,CAAC;EAED,MAAMa,SAAS,GAAKT,KAA4C,IAAM;IACrE;IACA;IACA,IAAKA,KAAK,CAACU,GAAG,KAAK,OAAO,EAAG;MAC5Bd,QAAQ,CAAC,CAAC;IACX;EACD,CAAC;EAED;IAAA;IACC;IACA;IACArB,KAAA;MACCoC,SAAS,EAAC,8BAA8B;MACxCC,GAAG,EAAG1B,YAAc;MACpBa,MAAM,EAAGA,MAAQ;MACjBU,SAAS,EAAGvC,mBAAmB,CAAEuC,SAAU,CAAG;MAAA3B,QAAA,GAE5ChB,YAAY,CAAEgB,QAAQ,EAAE;QACzBH,KAAK,EAAED,uBAAuB,CAC7BI,QAAQ,CAAC0B,KAAK,CAAC7B,KAAK,EACpBC,QAAQ,EACRC,gBACD,CAAC;QACDyB,QAAQ;QACR1B;MACD,CAAE,CAAC,eACHH,IAAA;QAAK,aAAU,QAAQ;QAAAK,QAAA,EACpBK,YAAY,iBACbZ,KAAA;UAAGoC,SAAS,EAAC,qCAAqC;UAAA7B,QAAA,gBACjDL,IAAA,CAACN,IAAI;YACJwC,SAAS,EAAC,0CAA0C;YACpDE,IAAI,EAAGhD,KAAO;YACdiD,IAAI,EAAG,EAAI;YACXC,IAAI,EAAC;UAAc,CACnB,CAAC,EACA5B,YAAY;QAAA,CACZ;MACH,CACG,CAAC;IAAA,CACF;EAAC;AAER;AAEA,OAAO,MAAM6B,gBAAgB,GAAGjD,UAAU,CAAEgB,2BAA4B,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["__","cloneElement","forwardRef","useEffect","useState","withIgnoreIMEEvents","ValidityIndicator","Fragment","_Fragment","jsxs","_jsxs","jsx","_jsx","appendRequiredIndicator","label","required","markWhenOptional","children","UnforwardedControlWithError","onValidate","customValidity","getValidityTarget","forwardedRef","errorMessage","setErrorMessage","statusMessage","setStatusMessage","isTouched","setIsTouched","validityTarget","showValidationMessage","validationMessage","addEventListener","removeEventListener","type","setCustomValidity","undefined","timer","setTimeout","message","clearTimeout","_customValidity$messa","onBlur","event","relatedTarget","currentTarget","contains","validity","valid","onChange","args","props","onKeyDown","key","className","ref","ControlWithError"],"sources":["@wordpress/components/src/validated-form-controls/control-with-error.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * External dependencies\n */\nimport {\n\tcloneElement,\n\tforwardRef,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport type { ValidatedControlProps } from './components/types';\nimport { ValidityIndicator } from './validity-indicator';\n\nfunction appendRequiredIndicator(\n\tlabel: React.ReactNode,\n\trequired: boolean | undefined,\n\tmarkWhenOptional: boolean | undefined\n) {\n\tif ( required && ! markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Required' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\tif ( ! required && markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Optional' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\treturn label;\n}\n\n/**\n * HTML elements that support the Constraint Validation API.\n *\n * Here, we exclude HTMLButtonElement because although it does technically support the API,\n * normal buttons are actually exempted from any validation.\n * @see https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/willValidate\n */\ntype ValidityTarget =\n\t| HTMLFieldSetElement\n\t| HTMLInputElement\n\t| HTMLSelectElement\n\t| HTMLTextAreaElement;\n\nfunction UnforwardedControlWithError< C extends React.ReactElement >(\n\t{\n\t\trequired,\n\t\tmarkWhenOptional,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tgetValidityTarget,\n\t\tchildren,\n\t}: {\n\t\t/**\n\t\t * Whether the control is required.\n\t\t */\n\t\trequired?: boolean;\n\t\t/**\n\t\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t\t */\n\t\tmarkWhenOptional?: boolean;\n\t\t/**\n\t\t * The callback to run when the input should be validated.\n\t\t */\n\t\tonValidate?: () => void;\n\t\tcustomValidity?: ValidatedControlProps< unknown >[ 'customValidity' ];\n\t\t/**\n\t\t * A function that returns the actual element on which the validity data should be applied.\n\t\t */\n\t\tgetValidityTarget: () => ValidityTarget | null | undefined;\n\t\t/**\n\t\t * The control component to apply validation to.\n\t\t */\n\t\tchildren: C;\n\t},\n\tforwardedRef: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst [ errorMessage, setErrorMessage ] = useState< string | undefined >();\n\tconst [ statusMessage, setStatusMessage ] = useState<\n\t\t| {\n\t\t\t\ttype: 'validating' | 'valid';\n\t\t\t\tmessage?: string;\n\t\t }\n\t\t| undefined\n\t>();\n\tconst [ isTouched, setIsTouched ] = useState( false );\n\n\t// Ensure that error messages are visible after user attemps to submit a form\n\t// with multiple invalid fields.\n\tuseEffect( () => {\n\t\tconst validityTarget = getValidityTarget();\n\t\tconst showValidationMessage = () =>\n\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\tvalidityTarget?.addEventListener( 'invalid', showValidationMessage );\n\n\t\treturn () => {\n\t\t\tvalidityTarget?.removeEventListener(\n\t\t\t\t'invalid',\n\t\t\t\tshowValidationMessage\n\t\t\t);\n\t\t};\n\t} );\n\n\tuseEffect( () => {\n\t\tif ( ! isTouched ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst validityTarget = getValidityTarget();\n\n\t\tif ( ! customValidity?.type ) {\n\t\t\tvalidityTarget?.setCustomValidity( '' );\n\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t\t\tsetStatusMessage( undefined );\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( customValidity.type ) {\n\t\t\tcase 'validating': {\n\t\t\t\t// Wait before showing a validating state.\n\t\t\t\tconst timer = setTimeout( () => {\n\t\t\t\t\tsetStatusMessage( {\n\t\t\t\t\t\ttype: 'validating',\n\t\t\t\t\t\tmessage: customValidity.message,\n\t\t\t\t\t} );\n\t\t\t\t}, 1000 );\n\n\t\t\t\treturn () => clearTimeout( timer );\n\t\t\t}\n\t\t\tcase 'valid': {\n\t\t\t\tvalidityTarget?.setCustomValidity( '' );\n\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\t\t\tsetStatusMessage( {\n\t\t\t\t\ttype: 'valid',\n\t\t\t\t\tmessage: customValidity.message,\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'invalid': {\n\t\t\t\tvalidityTarget?.setCustomValidity(\n\t\t\t\t\tcustomValidity.message ?? ''\n\t\t\t\t);\n\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\t\t\tsetStatusMessage( undefined );\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t}, [\n\t\tisTouched,\n\t\tcustomValidity?.type,\n\t\tcustomValidity?.message,\n\t\tgetValidityTarget,\n\t] );\n\n\tconst onBlur = ( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t// Only consider \"blurred from the component\" if focus has fully left the wrapping div.\n\t\t// This prevents unnecessary blurs from components with multiple focusable elements.\n\t\tif (\n\t\t\t! event.relatedTarget ||\n\t\t\t! event.currentTarget.contains( event.relatedTarget )\n\t\t) {\n\t\t\tsetIsTouched( true );\n\n\t\t\tconst validityTarget = getValidityTarget();\n\n\t\t\t// Prevents a double flash of the native error tooltip when the control is already showing one.\n\t\t\tif ( ! validityTarget?.validity.valid ) {\n\t\t\t\tif ( ! errorMessage ) {\n\t\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tonValidate?.();\n\t\t}\n\t};\n\n\tconst onChange = ( ...args: unknown[] ) => {\n\t\tchildren.props.onChange?.( ...args );\n\n\t\t// Only validate incrementally if the field has blurred at least once,\n\t\t// or currently has an error message.\n\t\tif ( isTouched || errorMessage ) {\n\t\t\tonValidate?.();\n\t\t}\n\t};\n\n\tconst onKeyDown = ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t// Ensures that custom validators are triggered when the user submits by pressing Enter,\n\t\t// without ever blurring the control.\n\t\tif ( event.key === 'Enter' ) {\n\t\t\tonValidate?.();\n\t\t}\n\t};\n\n\treturn (\n\t\t// Disable reason: Just listening to a bubbled event, not for interaction.\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName=\"components-validated-control\"\n\t\t\tref={ forwardedRef }\n\t\t\tonBlur={ onBlur }\n\t\t\tonKeyDown={ withIgnoreIMEEvents( onKeyDown ) }\n\t\t>\n\t\t\t{ cloneElement( children, {\n\t\t\t\tlabel: appendRequiredIndicator(\n\t\t\t\t\tchildren.props.label,\n\t\t\t\t\trequired,\n\t\t\t\t\tmarkWhenOptional\n\t\t\t\t),\n\t\t\t\tonChange,\n\t\t\t\trequired,\n\t\t\t} ) }\n\t\t\t<div aria-live=\"polite\">\n\t\t\t\t{ errorMessage && (\n\t\t\t\t\t<ValidityIndicator\n\t\t\t\t\t\ttype=\"invalid\"\n\t\t\t\t\t\tmessage={ errorMessage }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ ! errorMessage && statusMessage && (\n\t\t\t\t\t<ValidityIndicator\n\t\t\t\t\t\ttype={ statusMessage.type }\n\t\t\t\t\t\tmessage={ statusMessage.message }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport const ControlWithError = forwardRef( UnforwardedControlWithError );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SACCC,YAAY,EACZC,UAAU,EACVC,SAAS,EACTC,QAAQ,QACF,oBAAoB;;AAE3B;AACA;AACA;AACA,SAASC,mBAAmB,QAAQ,iCAAiC;AAErE,SAASC,iBA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eACHL,KAAA;QAAK,aAAU,QAAQ;QAAAO,QAAA,GACpBM,YAAY,iBACbX,IAAA,CAACN,iBAAiB;UACjB4B,IAAI,EAAC,SAAS;UACdK,OAAO,EAAGhB;QAAc,CACxB,CACD,EACC,CAAEA,YAAY,IAAIE,aAAa,iBAChCb,IAAA,CAACN,iBAAiB;UACjB4B,IAAI,EAAGT,aAAa,CAACS,IAAM;UAC3BK,OAAO,EAAGd,aAAa,CAACc;QAAS,CACjC,CACD;MAAA,CACG,CAAC;IAAA,CACF;EAAC;AAER;AAEA,OAAO,MAAMiB,gBAAgB,GAAGtD,UAAU,CAAEgB,2BAA4B,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { error, published } from '@wordpress/icons';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import Icon from '../icon';
|
|
15
|
+
import Spinner from '../spinner';
|
|
16
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export function ValidityIndicator({
|
|
18
|
+
type,
|
|
19
|
+
message
|
|
20
|
+
}) {
|
|
21
|
+
const ICON = {
|
|
22
|
+
valid: published,
|
|
23
|
+
invalid: error
|
|
24
|
+
};
|
|
25
|
+
return /*#__PURE__*/_jsxs("p", {
|
|
26
|
+
className: clsx('components-validated-control__indicator', `is-${type}`),
|
|
27
|
+
children: [type === 'validating' ? /*#__PURE__*/_jsx(Spinner, {
|
|
28
|
+
className: "components-validated-control__indicator-spinner"
|
|
29
|
+
}) : /*#__PURE__*/_jsx(Icon, {
|
|
30
|
+
className: "components-validated-control__indicator-icon",
|
|
31
|
+
icon: ICON[type],
|
|
32
|
+
size: 16,
|
|
33
|
+
fill: "currentColor"
|
|
34
|
+
}), message]
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=validity-indicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["clsx","error","published","Icon","Spinner","jsx","_jsx","jsxs","_jsxs","ValidityIndicator","type","message","ICON","valid","invalid","className","children","icon","size","fill"],"sources":["@wordpress/components/src/validated-form-controls/validity-indicator.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { error, published } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport Icon from '../icon';\nimport Spinner from '../spinner';\n\nexport function ValidityIndicator( {\n\ttype,\n\tmessage,\n}: {\n\ttype: 'validating' | 'valid' | 'invalid';\n\tmessage?: string;\n} ) {\n\tconst ICON = {\n\t\tvalid: published,\n\t\tinvalid: error,\n\t};\n\treturn (\n\t\t<p\n\t\t\tclassName={ clsx(\n\t\t\t\t'components-validated-control__indicator',\n\t\t\t\t`is-${ type }`\n\t\t\t) }\n\t\t>\n\t\t\t{ type === 'validating' ? (\n\t\t\t\t<Spinner className=\"components-validated-control__indicator-spinner\" />\n\t\t\t) : (\n\t\t\t\t<Icon\n\t\t\t\t\tclassName=\"components-validated-control__indicator-icon\"\n\t\t\t\t\ticon={ ICON[ type ] }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t\tfill=\"currentColor\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ message }\n\t\t</p>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SAASC,KAAK,EAAEC,SAAS,QAAQ,kBAAkB;;AAEnD;AACA;AACA;AACA,OAAOC,IAAI,MAAM,SAAS;AAC1B,OAAOC,OAAO,MAAM,YAAY;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAEjC,OAAO,SAASC,iBAAiBA,CAAE;EAClCC,IAAI;EACJC;AAID,CAAC,EAAG;EACH,MAAMC,IAAI,GAAG;IACZC,KAAK,EAAEX,SAAS;IAChBY,OAAO,EAAEb;EACV,CAAC;EACD,oBACCO,KAAA;IACCO,SAAS,EAAGf,IAAI,CACf,yCAAyC,EACzC,MAAOU,IAAI,EACZ,CAAG;IAAAM,QAAA,GAEDN,IAAI,KAAK,YAAY,gBACtBJ,IAAA,CAACF,OAAO;MAACW,SAAS,EAAC;IAAiD,CAAE,CAAC,gBAEvET,IAAA,CAACH,IAAI;MACJY,SAAS,EAAC,8CAA8C;MACxDE,IAAI,EAAGL,IAAI,CAAEF,IAAI,CAAI;MACrBQ,IAAI,EAAG,EAAI;MACXC,IAAI,EAAC;IAAc,CACnB,CACD,EACCR,OAAO;EAAA,CACP,CAAC;AAEN","ignoreList":[]}
|