@wordpress/components 30.9.1-next.8b30e05b0.0 → 31.0.1-next.6deb34194.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 +25 -4
- package/build/alignment-matrix-control/cell.js +131 -3
- package/build/alignment-matrix-control/cell.js.map +4 -4
- package/build/alignment-matrix-control/index.js +134 -6
- package/build/alignment-matrix-control/index.js.map +3 -3
- package/build/angle-picker-control/angle-circle.js +119 -15
- package/build/angle-picker-control/angle-circle.js.map +4 -4
- package/build/angle-picker-control/index.js +12 -7
- package/build/angle-picker-control/index.js.map +3 -3
- package/build/dropdown-menu/index.js +1 -1
- package/build/dropdown-menu/index.js.map +2 -2
- package/build/menu/styles.js +17 -17
- package/build/menu/styles.js.map +2 -2
- package/build/menu-item/index.js +1 -1
- package/build/menu-item/index.js.map +2 -2
- package/build/notice/index.js +1 -1
- package/build/notice/index.js.map +2 -2
- package/build/snackbar/index.js +1 -1
- package/build/snackbar/index.js.map +1 -1
- package/build/validated-form-controls/components/checkbox-control.js +0 -10
- package/build/validated-form-controls/components/checkbox-control.js.map +2 -2
- package/build/validated-form-controls/components/combobox-control.js +1 -11
- package/build/validated-form-controls/components/combobox-control.js.map +2 -2
- package/build/validated-form-controls/components/custom-select-control.js +0 -10
- package/build/validated-form-controls/components/custom-select-control.js.map +2 -2
- package/build/validated-form-controls/components/form-token-field.js +2 -12
- package/build/validated-form-controls/components/form-token-field.js.map +2 -2
- package/build/validated-form-controls/components/input-control.js +0 -10
- package/build/validated-form-controls/components/input-control.js.map +2 -2
- package/build/validated-form-controls/components/number-control.js +0 -10
- package/build/validated-form-controls/components/number-control.js.map +2 -2
- package/build/validated-form-controls/components/radio-control.js +0 -10
- package/build/validated-form-controls/components/radio-control.js.map +2 -2
- package/build/validated-form-controls/components/range-control.js +0 -10
- package/build/validated-form-controls/components/range-control.js.map +2 -2
- package/build/validated-form-controls/components/select-control.js +0 -10
- package/build/validated-form-controls/components/select-control.js.map +2 -2
- package/build/validated-form-controls/components/text-control.js +0 -10
- package/build/validated-form-controls/components/text-control.js.map +2 -2
- package/build/validated-form-controls/components/textarea-control.js +0 -10
- package/build/validated-form-controls/components/textarea-control.js.map +2 -2
- package/build/validated-form-controls/components/toggle-control.js +0 -10
- package/build/validated-form-controls/components/toggle-control.js.map +2 -2
- package/build/validated-form-controls/components/toggle-group-control.js +0 -10
- package/build/validated-form-controls/components/toggle-group-control.js.map +2 -2
- package/build/validated-form-controls/control-with-error.js +53 -58
- package/build/validated-form-controls/control-with-error.js.map +2 -2
- package/build-module/alignment-matrix-control/cell.js +131 -3
- package/build-module/alignment-matrix-control/cell.js.map +3 -3
- package/build-module/alignment-matrix-control/index.js +134 -6
- package/build-module/alignment-matrix-control/index.js.map +3 -3
- package/build-module/angle-picker-control/angle-circle.js +109 -15
- package/build-module/angle-picker-control/angle-circle.js.map +3 -3
- package/build-module/angle-picker-control/index.js +12 -7
- package/build-module/angle-picker-control/index.js.map +2 -2
- package/build-module/dropdown-menu/index.js +1 -1
- package/build-module/dropdown-menu/index.js.map +2 -2
- package/build-module/menu/styles.js +17 -17
- package/build-module/menu/styles.js.map +2 -2
- package/build-module/menu-item/index.js +1 -1
- package/build-module/menu-item/index.js.map +2 -2
- package/build-module/notice/index.js +1 -1
- package/build-module/notice/index.js.map +2 -2
- package/build-module/snackbar/index.js +1 -1
- package/build-module/snackbar/index.js.map +1 -1
- package/build-module/validated-form-controls/components/checkbox-control.js +0 -10
- package/build-module/validated-form-controls/components/checkbox-control.js.map +2 -2
- package/build-module/validated-form-controls/components/combobox-control.js +1 -11
- package/build-module/validated-form-controls/components/combobox-control.js.map +2 -2
- package/build-module/validated-form-controls/components/custom-select-control.js +0 -10
- package/build-module/validated-form-controls/components/custom-select-control.js.map +2 -2
- package/build-module/validated-form-controls/components/form-token-field.js +2 -12
- package/build-module/validated-form-controls/components/form-token-field.js.map +2 -2
- package/build-module/validated-form-controls/components/input-control.js +0 -10
- package/build-module/validated-form-controls/components/input-control.js.map +2 -2
- package/build-module/validated-form-controls/components/number-control.js +0 -10
- package/build-module/validated-form-controls/components/number-control.js.map +2 -2
- package/build-module/validated-form-controls/components/radio-control.js +0 -10
- package/build-module/validated-form-controls/components/radio-control.js.map +2 -2
- package/build-module/validated-form-controls/components/range-control.js +0 -10
- package/build-module/validated-form-controls/components/range-control.js.map +2 -2
- package/build-module/validated-form-controls/components/select-control.js +0 -10
- package/build-module/validated-form-controls/components/select-control.js.map +2 -2
- package/build-module/validated-form-controls/components/text-control.js +0 -10
- package/build-module/validated-form-controls/components/text-control.js.map +2 -2
- package/build-module/validated-form-controls/components/textarea-control.js +0 -10
- package/build-module/validated-form-controls/components/textarea-control.js.map +2 -2
- package/build-module/validated-form-controls/components/toggle-control.js +0 -10
- package/build-module/validated-form-controls/components/toggle-control.js.map +2 -2
- package/build-module/validated-form-controls/components/toggle-group-control.js +0 -10
- package/build-module/validated-form-controls/components/toggle-group-control.js.map +2 -2
- package/build-module/validated-form-controls/control-with-error.js +53 -58
- package/build-module/validated-form-controls/control-with-error.js.map +2 -2
- package/build-style/style-rtl.css +21 -33
- package/build-style/style.css +21 -33
- package/build-types/alignment-matrix-control/cell.d.ts.map +1 -1
- package/build-types/alignment-matrix-control/index.d.ts.map +1 -1
- package/build-types/angle-picker-control/angle-circle.d.ts +1 -1
- package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
- package/build-types/angle-picker-control/index.d.ts.map +1 -1
- package/build-types/notice/index.d.ts.map +1 -1
- package/build-types/notice/stories/index.story.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/checkbox-control.d.ts +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 +2 -3
- 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 +1 -2
- package/build-types/validated-form-controls/components/custom-select-control.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/form-token-field.d.ts +1 -2
- package/build-types/validated-form-controls/components/form-token-field.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/input-control.d.ts +1 -2
- 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 +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 +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 +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 +2 -3
- 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/form-token-field.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 +7 -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 +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 +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 +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 +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 +1 -9
- 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/package.json +20 -20
- package/src/alignment-matrix-control/cell.tsx +14 -3
- package/src/alignment-matrix-control/index.tsx +15 -6
- package/src/alignment-matrix-control/style.module.scss +84 -0
- package/src/angle-picker-control/angle-circle.tsx +27 -12
- package/src/angle-picker-control/index.tsx +8 -7
- package/src/angle-picker-control/style.module.scss +40 -0
- package/src/button/style.scss +1 -1
- package/src/dropdown-menu/index.tsx +1 -1
- package/src/dropdown-menu/style.scss +1 -1
- package/src/guide/style.scss +3 -3
- package/src/menu/styles.ts +2 -2
- package/src/menu-item/index.tsx +1 -1
- package/src/menu-item/test/__snapshots__/index.js.snap +4 -4
- package/src/modal/style.scss +5 -5
- package/src/notice/index.tsx +53 -46
- package/src/notice/stories/index.story.tsx +17 -1
- package/src/notice/style.scss +3 -20
- package/src/snackbar/index.tsx +1 -1
- package/src/validated-form-controls/components/checkbox-control.tsx +1 -14
- package/src/validated-form-controls/components/combobox-control.tsx +1 -14
- package/src/validated-form-controls/components/custom-select-control.tsx +1 -19
- package/src/validated-form-controls/components/form-token-field.tsx +2 -15
- package/src/validated-form-controls/components/input-control.tsx +1 -14
- package/src/validated-form-controls/components/number-control.tsx +1 -16
- package/src/validated-form-controls/components/radio-control.tsx +2 -18
- package/src/validated-form-controls/components/range-control.tsx +1 -14
- package/src/validated-form-controls/components/select-control.tsx +1 -23
- package/src/validated-form-controls/components/stories/checkbox-control.story.tsx +11 -20
- package/src/validated-form-controls/components/stories/combobox-control.story.tsx +8 -17
- package/src/validated-form-controls/components/stories/custom-select-control.story.tsx +8 -17
- package/src/validated-form-controls/components/stories/form-token-field.story.tsx +14 -26
- package/src/validated-form-controls/components/stories/input-control.story.tsx +25 -50
- package/src/validated-form-controls/components/stories/number-control.story.tsx +10 -19
- package/src/validated-form-controls/components/stories/overview.mdx +3 -3
- package/src/validated-form-controls/components/stories/overview.story.tsx +94 -79
- package/src/validated-form-controls/components/stories/radio-control.story.tsx +11 -20
- package/src/validated-form-controls/components/stories/range-control.story.tsx +8 -17
- package/src/validated-form-controls/components/stories/select-control.story.tsx +9 -18
- package/src/validated-form-controls/components/stories/text-control.story.tsx +11 -17
- package/src/validated-form-controls/components/stories/textarea-control.story.tsx +12 -16
- package/src/validated-form-controls/components/stories/toggle-control.story.tsx +11 -20
- package/src/validated-form-controls/components/stories/toggle-group-control.story.tsx +8 -17
- package/src/validated-form-controls/components/text-control.tsx +1 -14
- package/src/validated-form-controls/components/textarea-control.tsx +1 -14
- package/src/validated-form-controls/components/toggle-control.tsx +1 -14
- package/src/validated-form-controls/components/toggle-group-control.tsx +1 -14
- package/src/validated-form-controls/components/types.ts +1 -9
- package/src/validated-form-controls/control-with-error.tsx +57 -84
- package/src/validated-form-controls/style.scss +7 -7
- package/src/validated-form-controls/test/control-with-error.tsx +66 -5
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/alignment-matrix-control/styles.js +0 -105
- package/build/alignment-matrix-control/styles.js.map +0 -7
- package/build/angle-picker-control/styles/angle-picker-control-styles.js +0 -88
- package/build/angle-picker-control/styles/angle-picker-control-styles.js.map +0 -7
- package/build-module/alignment-matrix-control/styles.js +0 -67
- package/build-module/alignment-matrix-control/styles.js.map +0 -7
- package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +0 -50
- package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +0 -7
- package/build-types/alignment-matrix-control/styles.d.ts +0 -21
- package/build-types/alignment-matrix-control/styles.d.ts.map +0 -1
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +0 -18
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +0 -1
- package/src/alignment-matrix-control/styles.ts +0 -113
- package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +0 -58
|
@@ -33,12 +33,6 @@ export const Default: StoryObj< typeof ValidatedRangeControl > = {
|
|
|
33
33
|
useState<
|
|
34
34
|
React.ComponentProps< typeof ValidatedRangeControl >[ 'value' ]
|
|
35
35
|
>();
|
|
36
|
-
const [ customValidity, setCustomValidity ] =
|
|
37
|
-
useState<
|
|
38
|
-
React.ComponentProps<
|
|
39
|
-
typeof ValidatedRangeControl
|
|
40
|
-
>[ 'customValidity' ]
|
|
41
|
-
>( undefined );
|
|
42
36
|
|
|
43
37
|
return (
|
|
44
38
|
<ValidatedRangeControl
|
|
@@ -48,17 +42,14 @@ export const Default: StoryObj< typeof ValidatedRangeControl > = {
|
|
|
48
42
|
setValue( newValue );
|
|
49
43
|
onChange?.( newValue );
|
|
50
44
|
} }
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
} }
|
|
61
|
-
customValidity={ customValidity }
|
|
45
|
+
customValidity={
|
|
46
|
+
value && value % 2 !== 0
|
|
47
|
+
? {
|
|
48
|
+
type: 'invalid',
|
|
49
|
+
message: 'Choose an even number.',
|
|
50
|
+
}
|
|
51
|
+
: undefined
|
|
52
|
+
}
|
|
62
53
|
/>
|
|
63
54
|
);
|
|
64
55
|
},
|
|
@@ -29,13 +29,7 @@ export default meta;
|
|
|
29
29
|
|
|
30
30
|
export const Default: StoryObj< typeof ValidatedSelectControl > = {
|
|
31
31
|
render: function Template( { onChange, ...args } ) {
|
|
32
|
-
const [ value, setValue ] = useState( '' );
|
|
33
|
-
const [ customValidity, setCustomValidity ] =
|
|
34
|
-
useState<
|
|
35
|
-
React.ComponentProps<
|
|
36
|
-
typeof ValidatedSelectControl
|
|
37
|
-
>[ 'customValidity' ]
|
|
38
|
-
>( undefined );
|
|
32
|
+
const [ value, setValue ] = useState< string | undefined >( '' );
|
|
39
33
|
|
|
40
34
|
return (
|
|
41
35
|
<ValidatedSelectControl
|
|
@@ -45,17 +39,14 @@ export const Default: StoryObj< typeof ValidatedSelectControl > = {
|
|
|
45
39
|
setValue( newValue );
|
|
46
40
|
onChange?.( newValue );
|
|
47
41
|
} }
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
} }
|
|
58
|
-
customValidity={ customValidity }
|
|
42
|
+
customValidity={
|
|
43
|
+
value === '1'
|
|
44
|
+
? {
|
|
45
|
+
type: 'invalid',
|
|
46
|
+
message: 'Option 1 is not allowed.',
|
|
47
|
+
}
|
|
48
|
+
: undefined
|
|
49
|
+
}
|
|
59
50
|
/>
|
|
60
51
|
);
|
|
61
52
|
},
|
|
@@ -29,13 +29,10 @@ export default meta;
|
|
|
29
29
|
|
|
30
30
|
export const Default: StoryObj< typeof ValidatedTextControl > = {
|
|
31
31
|
render: function Template( { onChange, ...args } ) {
|
|
32
|
-
const [ value, setValue ] =
|
|
33
|
-
const [ customValidity, setCustomValidity ] =
|
|
32
|
+
const [ value, setValue ] =
|
|
34
33
|
useState<
|
|
35
|
-
React.ComponentProps<
|
|
36
|
-
|
|
37
|
-
>[ 'customValidity' ]
|
|
38
|
-
>( undefined );
|
|
34
|
+
React.ComponentProps< typeof ValidatedTextControl >[ 'value' ]
|
|
35
|
+
>( '' );
|
|
39
36
|
|
|
40
37
|
return (
|
|
41
38
|
<ValidatedTextControl
|
|
@@ -45,17 +42,14 @@ export const Default: StoryObj< typeof ValidatedTextControl > = {
|
|
|
45
42
|
setValue( newValue );
|
|
46
43
|
onChange?.( newValue );
|
|
47
44
|
} }
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
} }
|
|
58
|
-
customValidity={ customValidity }
|
|
45
|
+
customValidity={
|
|
46
|
+
value === 'error'
|
|
47
|
+
? {
|
|
48
|
+
type: 'invalid',
|
|
49
|
+
message: 'The word "error" is not allowed.',
|
|
50
|
+
}
|
|
51
|
+
: undefined
|
|
52
|
+
}
|
|
59
53
|
/>
|
|
60
54
|
);
|
|
61
55
|
},
|
|
@@ -26,33 +26,29 @@ export default meta;
|
|
|
26
26
|
|
|
27
27
|
export const Default: StoryObj< typeof ValidatedTextareaControl > = {
|
|
28
28
|
render: function Template( { onChange, ...args } ) {
|
|
29
|
-
const [ value, setValue ] =
|
|
30
|
-
const [ customValidity, setCustomValidity ] =
|
|
29
|
+
const [ value, setValue ] =
|
|
31
30
|
useState<
|
|
32
31
|
React.ComponentProps<
|
|
33
32
|
typeof ValidatedTextareaControl
|
|
34
|
-
>[ '
|
|
35
|
-
>(
|
|
33
|
+
>[ 'value' ]
|
|
34
|
+
>( '' );
|
|
36
35
|
|
|
37
36
|
return (
|
|
38
37
|
<ValidatedTextareaControl
|
|
39
38
|
{ ...args }
|
|
39
|
+
value={ value }
|
|
40
40
|
onChange={ ( newValue ) => {
|
|
41
41
|
setValue( newValue );
|
|
42
42
|
onChange?.( newValue );
|
|
43
43
|
} }
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
setCustomValidity( undefined );
|
|
53
|
-
}
|
|
54
|
-
} }
|
|
55
|
-
customValidity={ customValidity }
|
|
44
|
+
customValidity={
|
|
45
|
+
value?.toLowerCase() === 'error'
|
|
46
|
+
? {
|
|
47
|
+
type: 'invalid',
|
|
48
|
+
message: 'The word "error" is not allowed.',
|
|
49
|
+
}
|
|
50
|
+
: undefined
|
|
51
|
+
}
|
|
56
52
|
/>
|
|
57
53
|
);
|
|
58
54
|
},
|
|
@@ -30,32 +30,23 @@ export default meta;
|
|
|
30
30
|
export const Default: StoryObj< typeof ValidatedToggleControl > = {
|
|
31
31
|
render: function Template( { onChange, ...args } ) {
|
|
32
32
|
const [ checked, setChecked ] = useState( false );
|
|
33
|
-
const [ customValidity, setCustomValidity ] =
|
|
34
|
-
useState<
|
|
35
|
-
React.ComponentProps<
|
|
36
|
-
typeof ValidatedToggleControl
|
|
37
|
-
>[ 'customValidity' ]
|
|
38
|
-
>( undefined );
|
|
39
33
|
|
|
40
34
|
return (
|
|
41
35
|
<ValidatedToggleControl
|
|
42
36
|
{ ...args }
|
|
43
37
|
checked={ checked }
|
|
44
|
-
onChange={ (
|
|
45
|
-
setChecked(
|
|
46
|
-
onChange?.(
|
|
38
|
+
onChange={ ( newValue ) => {
|
|
39
|
+
setChecked( newValue );
|
|
40
|
+
onChange?.( newValue );
|
|
47
41
|
} }
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
} }
|
|
58
|
-
customValidity={ customValidity }
|
|
42
|
+
customValidity={
|
|
43
|
+
checked
|
|
44
|
+
? {
|
|
45
|
+
type: 'invalid',
|
|
46
|
+
message: 'This toggle may not be enabled.',
|
|
47
|
+
}
|
|
48
|
+
: undefined
|
|
49
|
+
}
|
|
59
50
|
/>
|
|
60
51
|
);
|
|
61
52
|
},
|
|
@@ -36,12 +36,6 @@ export const Default: StoryObj< typeof ValidatedToggleGroupControl > = {
|
|
|
36
36
|
typeof ValidatedToggleGroupControl
|
|
37
37
|
>[ 'value' ]
|
|
38
38
|
>( '1' );
|
|
39
|
-
const [ customValidity, setCustomValidity ] =
|
|
40
|
-
useState<
|
|
41
|
-
React.ComponentProps<
|
|
42
|
-
typeof ValidatedToggleGroupControl
|
|
43
|
-
>[ 'customValidity' ]
|
|
44
|
-
>( undefined );
|
|
45
39
|
|
|
46
40
|
return (
|
|
47
41
|
<ValidatedToggleGroupControl
|
|
@@ -51,17 +45,14 @@ export const Default: StoryObj< typeof ValidatedToggleGroupControl > = {
|
|
|
51
45
|
setValue( newValue );
|
|
52
46
|
onChange?.( newValue );
|
|
53
47
|
} }
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
} }
|
|
64
|
-
customValidity={ customValidity }
|
|
48
|
+
customValidity={
|
|
49
|
+
value === '2'
|
|
50
|
+
? {
|
|
51
|
+
type: 'invalid',
|
|
52
|
+
message: 'Option 2 is not allowed.',
|
|
53
|
+
}
|
|
54
|
+
: undefined
|
|
55
|
+
}
|
|
65
56
|
/>
|
|
66
57
|
);
|
|
67
58
|
},
|
|
@@ -10,36 +10,27 @@ import { forwardRef, useRef } from '@wordpress/element';
|
|
|
10
10
|
import { ControlWithError } from '../control-with-error';
|
|
11
11
|
import type { ValidatedControlProps } from './types';
|
|
12
12
|
import TextControl from '../../text-control';
|
|
13
|
-
import type { TextControlProps } from '../../text-control/types';
|
|
14
|
-
|
|
15
|
-
type Value = TextControlProps[ 'value' ];
|
|
16
13
|
|
|
17
14
|
const UnforwardedValidatedTextControl = (
|
|
18
15
|
{
|
|
19
16
|
required,
|
|
20
|
-
onValidate,
|
|
21
17
|
customValidity,
|
|
22
|
-
onChange,
|
|
23
18
|
markWhenOptional,
|
|
24
19
|
...restProps
|
|
25
20
|
}: Omit<
|
|
26
21
|
React.ComponentProps< typeof TextControl >,
|
|
27
22
|
'__next40pxDefaultSize' | '__nextHasNoMarginBottom'
|
|
28
23
|
> &
|
|
29
|
-
ValidatedControlProps
|
|
24
|
+
ValidatedControlProps,
|
|
30
25
|
forwardedRef: React.ForwardedRef< HTMLInputElement >
|
|
31
26
|
) => {
|
|
32
27
|
const validityTargetRef = useRef< HTMLInputElement >( null );
|
|
33
28
|
const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
|
|
34
|
-
const valueRef = useRef< Value >( restProps.value );
|
|
35
29
|
|
|
36
30
|
return (
|
|
37
31
|
<ControlWithError
|
|
38
32
|
required={ required }
|
|
39
33
|
markWhenOptional={ markWhenOptional }
|
|
40
|
-
onValidate={ () => {
|
|
41
|
-
return onValidate?.( valueRef.current );
|
|
42
|
-
} }
|
|
43
34
|
customValidity={ customValidity }
|
|
44
35
|
getValidityTarget={ () => validityTargetRef.current }
|
|
45
36
|
>
|
|
@@ -47,10 +38,6 @@ const UnforwardedValidatedTextControl = (
|
|
|
47
38
|
__next40pxDefaultSize
|
|
48
39
|
__nextHasNoMarginBottom
|
|
49
40
|
ref={ mergedRefs }
|
|
50
|
-
onChange={ ( value ) => {
|
|
51
|
-
valueRef.current = value;
|
|
52
|
-
onChange?.( value );
|
|
53
|
-
} }
|
|
54
41
|
{ ...restProps }
|
|
55
42
|
/>
|
|
56
43
|
</ControlWithError>
|
|
@@ -10,46 +10,33 @@ import { useMergeRefs } from '@wordpress/compose';
|
|
|
10
10
|
import { ControlWithError } from '../control-with-error';
|
|
11
11
|
import type { ValidatedControlProps } from './types';
|
|
12
12
|
import TextareaControl from '../../textarea-control';
|
|
13
|
-
import type { TextareaControlProps } from '../../textarea-control/types';
|
|
14
|
-
|
|
15
|
-
type Value = TextareaControlProps[ 'value' ];
|
|
16
13
|
|
|
17
14
|
const UnforwardedValidatedTextareaControl = (
|
|
18
15
|
{
|
|
19
16
|
required,
|
|
20
|
-
onValidate,
|
|
21
17
|
customValidity,
|
|
22
|
-
onChange,
|
|
23
18
|
markWhenOptional,
|
|
24
19
|
...restProps
|
|
25
20
|
}: Omit<
|
|
26
21
|
React.ComponentProps< typeof TextareaControl >,
|
|
27
22
|
'__nextHasNoMarginBottom'
|
|
28
23
|
> &
|
|
29
|
-
ValidatedControlProps
|
|
24
|
+
ValidatedControlProps,
|
|
30
25
|
forwardedRef: React.ForwardedRef< HTMLTextAreaElement >
|
|
31
26
|
) => {
|
|
32
27
|
const validityTargetRef = useRef< HTMLTextAreaElement >( null );
|
|
33
28
|
const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
|
|
34
|
-
const valueRef = useRef< Value >( restProps.value );
|
|
35
29
|
|
|
36
30
|
return (
|
|
37
31
|
<ControlWithError
|
|
38
32
|
required={ required }
|
|
39
33
|
markWhenOptional={ markWhenOptional }
|
|
40
|
-
onValidate={ () => {
|
|
41
|
-
return onValidate?.( valueRef.current );
|
|
42
|
-
} }
|
|
43
34
|
customValidity={ customValidity }
|
|
44
35
|
getValidityTarget={ () => validityTargetRef.current }
|
|
45
36
|
>
|
|
46
37
|
<TextareaControl
|
|
47
38
|
__nextHasNoMarginBottom
|
|
48
39
|
ref={ mergedRefs }
|
|
49
|
-
onChange={ ( value ) => {
|
|
50
|
-
valueRef.current = value;
|
|
51
|
-
onChange?.( value );
|
|
52
|
-
} }
|
|
53
40
|
{ ...restProps }
|
|
54
41
|
/>
|
|
55
42
|
</ControlWithError>
|
|
@@ -10,30 +10,24 @@ import { useMergeRefs } from '@wordpress/compose';
|
|
|
10
10
|
import { ControlWithError } from '../control-with-error';
|
|
11
11
|
import type { ValidatedControlProps } from './types';
|
|
12
12
|
import ToggleControl from '../../toggle-control';
|
|
13
|
-
import type { ToggleControlProps } from '../../toggle-control/types';
|
|
14
|
-
|
|
15
|
-
type Value = ToggleControlProps[ 'checked' ];
|
|
16
13
|
|
|
17
14
|
// TODO: Should we customize the default `missingValue` message? It says to "check this box".
|
|
18
15
|
|
|
19
16
|
const UnforwardedValidatedToggleControl = (
|
|
20
17
|
{
|
|
21
18
|
required,
|
|
22
|
-
onValidate,
|
|
23
19
|
customValidity,
|
|
24
|
-
onChange,
|
|
25
20
|
markWhenOptional,
|
|
26
21
|
...restProps
|
|
27
22
|
}: Omit<
|
|
28
23
|
React.ComponentProps< typeof ToggleControl >,
|
|
29
24
|
'__nextHasNoMarginBottom'
|
|
30
25
|
> &
|
|
31
|
-
ValidatedControlProps
|
|
26
|
+
ValidatedControlProps,
|
|
32
27
|
forwardedRef: React.ForwardedRef< HTMLInputElement >
|
|
33
28
|
) => {
|
|
34
29
|
const validityTargetRef = useRef< HTMLInputElement >( null );
|
|
35
30
|
const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
|
|
36
|
-
const valueRef = useRef< Value >( restProps.checked );
|
|
37
31
|
|
|
38
32
|
// TODO: Upstream limitation - The `required` attribute is not passed down to the input,
|
|
39
33
|
// so we need to set it manually.
|
|
@@ -47,19 +41,12 @@ const UnforwardedValidatedToggleControl = (
|
|
|
47
41
|
<ControlWithError
|
|
48
42
|
required={ required }
|
|
49
43
|
markWhenOptional={ markWhenOptional }
|
|
50
|
-
onValidate={ () => {
|
|
51
|
-
return onValidate?.( valueRef.current );
|
|
52
|
-
} }
|
|
53
44
|
customValidity={ customValidity }
|
|
54
45
|
getValidityTarget={ () => validityTargetRef.current }
|
|
55
46
|
>
|
|
56
47
|
<ToggleControl
|
|
57
48
|
__nextHasNoMarginBottom
|
|
58
49
|
ref={ mergedRefs }
|
|
59
|
-
onChange={ ( value ) => {
|
|
60
|
-
valueRef.current = value;
|
|
61
|
-
onChange?.( value );
|
|
62
|
-
} }
|
|
63
50
|
{ ...restProps }
|
|
64
51
|
/>
|
|
65
52
|
</ControlWithError>
|
|
@@ -9,27 +9,21 @@ import { forwardRef, useId, useRef } from '@wordpress/element';
|
|
|
9
9
|
import { ControlWithError } from '../control-with-error';
|
|
10
10
|
import type { ValidatedControlProps } from './types';
|
|
11
11
|
import { ToggleGroupControl } from '../../toggle-group-control';
|
|
12
|
-
import type { ToggleGroupControlProps } from '../../toggle-group-control/types';
|
|
13
|
-
|
|
14
|
-
type Value = ToggleGroupControlProps[ 'value' ];
|
|
15
12
|
|
|
16
13
|
const UnforwardedValidatedToggleGroupControl = (
|
|
17
14
|
{
|
|
18
15
|
required,
|
|
19
|
-
onValidate,
|
|
20
16
|
customValidity,
|
|
21
|
-
onChange,
|
|
22
17
|
markWhenOptional,
|
|
23
18
|
...restProps
|
|
24
19
|
}: Omit<
|
|
25
20
|
React.ComponentProps< typeof ToggleGroupControl >,
|
|
26
21
|
'__next40pxDefaultSize' | '__nextHasNoMarginBottom'
|
|
27
22
|
> &
|
|
28
|
-
ValidatedControlProps
|
|
23
|
+
ValidatedControlProps,
|
|
29
24
|
forwardedRef: React.ForwardedRef< HTMLInputElement >
|
|
30
25
|
) => {
|
|
31
26
|
const validityTargetRef = useRef< HTMLInputElement >( null );
|
|
32
|
-
const valueRef = useRef< Value >( restProps.value );
|
|
33
27
|
|
|
34
28
|
const nameAttr = useId();
|
|
35
29
|
|
|
@@ -38,9 +32,6 @@ const UnforwardedValidatedToggleGroupControl = (
|
|
|
38
32
|
<ControlWithError
|
|
39
33
|
required={ required }
|
|
40
34
|
markWhenOptional={ markWhenOptional }
|
|
41
|
-
onValidate={ () => {
|
|
42
|
-
return onValidate?.( valueRef.current );
|
|
43
|
-
} }
|
|
44
35
|
customValidity={ customValidity }
|
|
45
36
|
getValidityTarget={ () => validityTargetRef.current }
|
|
46
37
|
>
|
|
@@ -48,10 +39,6 @@ const UnforwardedValidatedToggleGroupControl = (
|
|
|
48
39
|
__nextHasNoMarginBottom
|
|
49
40
|
__next40pxDefaultSize
|
|
50
41
|
ref={ forwardedRef }
|
|
51
|
-
onChange={ ( value ) => {
|
|
52
|
-
valueRef.current = value;
|
|
53
|
-
onChange?.( value );
|
|
54
|
-
} }
|
|
55
42
|
{ ...restProps }
|
|
56
43
|
/>
|
|
57
44
|
</ControlWithError>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ValidatedControlProps
|
|
1
|
+
export type ValidatedControlProps = {
|
|
2
2
|
/**
|
|
3
3
|
* Whether the control is required.
|
|
4
4
|
* @default false
|
|
@@ -9,14 +9,6 @@ export type ValidatedControlProps< V > = {
|
|
|
9
9
|
* @default false
|
|
10
10
|
*/
|
|
11
11
|
markWhenOptional?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Optional callback to run when the input should be validated. Use this to set
|
|
14
|
-
* a `customValidity` as necessary.
|
|
15
|
-
*
|
|
16
|
-
* Always prefer using standard HTML attributes like `required` and `min`/`max` over
|
|
17
|
-
* custom validators when possible, as they are simpler and have localized error messages built in.
|
|
18
|
-
*/
|
|
19
|
-
onValidate?: ( currentValue: V ) => void;
|
|
20
12
|
/**
|
|
21
13
|
* Show a custom message based on the validation status.
|
|
22
14
|
*
|