@wordpress/components 19.9.0 → 19.10.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 +30 -0
- package/CONTRIBUTING.md +80 -7
- package/build/angle-picker-control/angle-circle.js +5 -7
- package/build/angle-picker-control/angle-circle.js.map +1 -1
- package/build/box-control/index.js +0 -21
- package/build/box-control/index.js.map +1 -1
- package/build/box-control/utils.js +1 -8
- package/build/box-control/utils.js.map +1 -1
- package/build/button/index.js +3 -5
- package/build/button/index.js.map +1 -1
- package/build/circular-option-picker/index.js +1 -2
- package/build/circular-option-picker/index.js.map +1 -1
- package/build/disabled/index.js +4 -76
- package/build/disabled/index.js.map +1 -1
- package/build/input-control/index.js +3 -2
- package/build/input-control/index.js.map +1 -1
- package/build/input-control/styles/input-control-styles.js +42 -30
- package/build/input-control/styles/input-control-styles.js.map +1 -1
- package/build/mobile/bottom-sheet-select-control/index.native.js +1 -0
- package/build/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
- package/build/popover/index.js +6 -52
- package/build/popover/index.js.map +1 -1
- package/build/select-control/index.js +31 -4
- package/build/select-control/index.js.map +1 -1
- package/build/select-control/styles/select-control-styles.js +8 -8
- package/build/select-control/styles/select-control-styles.js.map +1 -1
- package/build/text-control/index.js +35 -28
- package/build/text-control/index.js.map +1 -1
- package/build/text-control/types.js +6 -0
- package/build/text-control/types.js.map +1 -0
- package/build/toggle-group-control/toggle-group-control-option-icon/component.js +6 -4
- package/build/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
- package/build/tools-panel/tools-panel-header/component.js +52 -36
- package/build/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build/unit-control/index.js +3 -3
- package/build/unit-control/index.js.map +1 -1
- package/build/unit-control/styles/unit-control-styles.js +11 -20
- package/build/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build/unit-control/utils.js.map +1 -1
- package/build-module/angle-picker-control/angle-circle.js +5 -7
- package/build-module/angle-picker-control/angle-circle.js.map +1 -1
- package/build-module/box-control/index.js +1 -20
- package/build-module/box-control/index.js.map +1 -1
- package/build-module/box-control/utils.js +0 -6
- package/build-module/box-control/utils.js.map +1 -1
- package/build-module/button/index.js +3 -4
- package/build-module/button/index.js.map +1 -1
- package/build-module/circular-option-picker/index.js +1 -2
- package/build-module/circular-option-picker/index.js.map +1 -1
- package/build-module/disabled/index.js +5 -76
- package/build-module/disabled/index.js.map +1 -1
- package/build-module/input-control/index.js +3 -2
- package/build-module/input-control/index.js.map +1 -1
- package/build-module/input-control/styles/input-control-styles.js +42 -30
- package/build-module/input-control/styles/input-control-styles.js.map +1 -1
- package/build-module/mobile/bottom-sheet-select-control/index.native.js +1 -0
- package/build-module/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
- package/build-module/popover/index.js +6 -52
- package/build-module/popover/index.js.map +1 -1
- package/build-module/select-control/index.js +29 -3
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/select-control/styles/select-control-styles.js +8 -8
- package/build-module/select-control/styles/select-control-styles.js.map +1 -1
- package/build-module/text-control/index.js +35 -27
- package/build-module/text-control/index.js.map +1 -1
- package/build-module/text-control/types.js +2 -0
- package/build-module/text-control/types.js.map +1 -0
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js +1 -5
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
- package/build-module/tools-panel/tools-panel-header/component.js +51 -36
- package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
- package/build-module/unit-control/index.js +3 -3
- package/build-module/unit-control/index.js.map +1 -1
- package/build-module/unit-control/styles/unit-control-styles.js +11 -20
- package/build-module/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build-module/unit-control/utils.js.map +1 -1
- package/build-style/style-rtl.css +7 -0
- package/build-style/style.css +7 -0
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/circular-option-picker/index.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +3 -3
- package/build-types/disabled/index.d.ts.map +1 -1
- package/build-types/input-control/index.d.ts +4 -3
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/stories/index.d.ts +5 -5
- package/build-types/input-control/stories/index.d.ts.map +1 -1
- package/build-types/input-control/styles/input-control-styles.d.ts +1 -0
- package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
- package/build-types/input-control/types.d.ts +6 -0
- package/build-types/input-control/types.d.ts.map +1 -1
- package/build-types/number-control/styles/number-control-styles.d.ts +1 -1
- package/build-types/popover/index.d.ts +0 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts +30 -26
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/stories/index.d.ts +23 -0
- package/build-types/select-control/stories/index.d.ts.map +1 -0
- package/build-types/select-control/styles/select-control-styles.d.ts +3 -4
- package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
- package/build-types/select-control/test/select-control.d.ts +2 -0
- package/build-types/select-control/test/select-control.d.ts.map +1 -0
- package/build-types/select-control/types.d.ts +52 -1
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/text-control/index.d.ts +32 -0
- package/build-types/text-control/index.d.ts.map +1 -0
- package/build-types/text-control/stories/index.d.ts +13 -0
- package/build-types/text-control/stories/index.d.ts.map +1 -0
- package/build-types/text-control/types.d.ts +25 -0
- package/build-types/text-control/types.d.ts.map +1 -0
- package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
- package/build-types/tools-panel/types.d.ts +0 -1
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/build-types/unit-control/index.d.ts +2 -2
- package/build-types/unit-control/index.d.ts.map +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
- package/build-types/unit-control/test/index.d.ts +2 -0
- package/build-types/unit-control/test/index.d.ts.map +1 -0
- package/build-types/unit-control/test/utils.d.ts +2 -0
- package/build-types/unit-control/test/utils.d.ts.map +1 -0
- package/build-types/unit-control/types.d.ts +1 -1
- package/build-types/unit-control/types.d.ts.map +1 -1
- package/build-types/unit-control/utils.d.ts +3 -3
- package/build-types/unit-control/utils.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/angle-picker-control/angle-circle.js +3 -3
- package/src/box-control/README.md +0 -74
- package/src/box-control/index.js +0 -15
- package/src/box-control/stories/index.js +0 -29
- package/src/box-control/utils.js +0 -7
- package/src/button/index.js +2 -4
- package/src/button/test/index.js +16 -1
- package/src/circular-option-picker/index.js +1 -2
- package/src/color-palette/README.md +0 -1
- package/src/color-palette/test/__snapshots__/index.js.snap +2 -3
- package/src/confirm-dialog/stories/index.js +87 -99
- package/src/date-time/stories/index.js +19 -0
- package/src/date-time/test/date.js +107 -78
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +4 -4
- package/src/disabled/index.js +5 -90
- package/src/form-file-upload/test/index.js +15 -12
- package/src/input-control/README.md +1 -1
- package/src/input-control/index.tsx +3 -2
- package/src/input-control/stories/index.tsx +1 -1
- package/src/input-control/styles/input-control-styles.tsx +19 -5
- package/src/input-control/types.ts +6 -0
- package/src/menu-item/style.scss +10 -0
- package/src/mobile/bottom-sheet/bottom-sheet-navigation/test/navigation-container.native.js +8 -1
- package/src/mobile/bottom-sheet-select-control/index.native.js +1 -0
- package/src/mobile/html-text-input/style.android.scss +1 -0
- package/src/mobile/html-text-input/style.ios.scss +1 -0
- package/src/mobile/link-settings/test/link-settings-navigation.native.js +9 -1
- package/src/popover/index.js +5 -51
- package/src/select-control/README.md +2 -2
- package/src/select-control/index.tsx +30 -29
- package/src/select-control/stories/index.tsx +90 -0
- package/src/select-control/styles/select-control-styles.ts +9 -8
- package/src/select-control/test/{select-control.js → select-control.tsx} +2 -2
- package/src/select-control/types.ts +66 -1
- package/src/text-control/index.tsx +84 -0
- package/src/text-control/stories/index.tsx +66 -0
- package/src/text-control/types.ts +29 -0
- package/src/toggle-group-control/toggle-group-control-option-icon/component.tsx +1 -5
- package/src/tools-panel/test/__snapshots__/index.js.snap +1 -1
- package/src/tools-panel/test/index.js +71 -18
- package/src/tools-panel/tools-panel-header/component.tsx +75 -33
- package/src/tools-panel/types.ts +0 -1
- package/src/tooltip/test/index.js +6 -0
- package/src/unit-control/index.tsx +2 -5
- package/src/unit-control/styles/unit-control-styles.ts +3 -13
- package/src/unit-control/test/__snapshots__/index.tsx.snap +33 -0
- package/src/unit-control/test/{index.js → index.tsx} +214 -165
- package/src/unit-control/test/{utils.js → utils.ts} +38 -19
- package/src/unit-control/types.ts +4 -1
- package/src/unit-control/utils.ts +5 -3
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/box-control/visualizer.js +0 -165
- package/build/box-control/visualizer.js.map +0 -1
- package/build-module/box-control/visualizer.js +0 -154
- package/build-module/box-control/visualizer.js.map +0 -1
- package/src/box-control/visualizer.js +0 -116
- package/src/select-control/stories/index.js +0 -104
- package/src/text-control/index.js +0 -72
- package/src/text-control/stories/index.js +0 -46
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/select-control/styles/select-control-styles.ts"],"names":["disabledStyles","disabled","color","COLORS","ui","textDisabled","fontSizeStyles","selectSize","sizes","default","small","fontSize","fontSizeMobile","css","sizeStyles","height","lineHeight","minHeight","style","sizePaddings","paddingLeft","paddingRight","Select","gray","DownArrowWrapper","right"],"mappings":";;;;;;;;;;;AAGA;;AAMA;;AATA;AACA;AACA;;AAIA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/select-control/styles/select-control-styles.ts"],"names":["disabledStyles","disabled","color","COLORS","ui","textDisabled","fontSizeStyles","selectSize","sizes","default","small","fontSize","fontSizeMobile","css","sizeStyles","height","lineHeight","minHeight","style","sizePaddings","paddingLeft","paddingRight","Select","gray","DownArrowWrapper","right"],"mappings":";;;;;;;;;;;AAGA;;AAMA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAU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,MAA7C;AAAEZ,IAAAA,UAAU,GAAG;AAAf,GAA6C;AACnE,QAAMC,KAAK,GAAG;AACbC,IAAAA,OAAO,EAAE;AACRW,MAAAA,WAAW,EAAE,CADL;AAERC,MAAAA,YAAY,EAAE;AAFN,KADI;AAKbX,IAAAA,KAAK,EAAE;AACNU,MAAAA,WAAW,EAAE,CADP;AAENC,MAAAA,YAAY,EAAE;AAFR,KALM;AASb,wBAAoB;AACnBD,MAAAA,WAAW,EAAE,EADM;AAEnBC,MAAAA,YAAY,EAAE;AAFK;AATP,GAAd;AAcA,SAAO,gBAAKb,KAAK,CAAED,UAAF,CAAV,CAAP;AACA,CAhBD,C,CAkBA;AACA;;;AAEO,MAAMe,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oHAOPnB,cAAOoB,IAAP,CAAa,GAAb,CAPO,6DAadvB,cAbc,OAcdM,cAdc,OAedQ,UAfc,OAgBdK,YAhBc,09HAAZ;;AAoBA,MAAMK,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,gIAUzB,gBAAK;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAAL,CAVyB,4+HAAtB","sourcesContent":["/**\n * External dependencies\n */\nimport { css } from '@emotion/react';\nimport styled from '@emotion/styled';\n\n/**\n * Internal dependencies\n */\nimport { COLORS, rtl } from '../../utils';\nimport type { SelectControlProps } from '../types';\n\ninterface SelectProps extends Pick< SelectControlProps, 'disabled' > {\n\t// Using `selectSize` instead of `size` to avoid a type conflict with the\n\t// `size` HTML attribute of the `select` element.\n\tselectSize?: SelectControlProps[ 'size' ];\n}\n\nconst disabledStyles = ( { disabled }: SelectProps ) => {\n\tif ( ! disabled ) return '';\n\n\treturn css( {\n\t\tcolor: COLORS.ui.textDisabled,\n\t} );\n};\n\nconst fontSizeStyles = ( { selectSize = 'default' }: SelectProps ) => {\n\tconst sizes = {\n\t\tdefault: '13px',\n\t\tsmall: '11px',\n\t\t'__unstable-large': '13px',\n\t};\n\n\tconst fontSize = sizes[ selectSize ];\n\tconst fontSizeMobile = '16px';\n\n\tif ( ! fontSize ) return '';\n\n\treturn css`\n\t\tfont-size: ${ fontSizeMobile };\n\n\t\t@media ( min-width: 600px ) {\n\t\t\tfont-size: ${ fontSize };\n\t\t}\n\t`;\n};\n\nconst sizeStyles = ( { selectSize = 'default' }: SelectProps ) => {\n\tconst sizes = {\n\t\tdefault: {\n\t\t\theight: 30,\n\t\t\tlineHeight: 1,\n\t\t\tminHeight: 30,\n\t\t},\n\t\tsmall: {\n\t\t\theight: 24,\n\t\t\tlineHeight: 1,\n\t\t\tminHeight: 24,\n\t\t},\n\t\t'__unstable-large': {\n\t\t\theight: 40,\n\t\t\tlineHeight: 1,\n\t\t\tminHeight: 40,\n\t\t},\n\t};\n\n\tconst style = sizes[ selectSize ];\n\n\treturn css( style );\n};\n\nconst sizePaddings = ( { selectSize = 'default' }: SelectProps ) => {\n\tconst sizes = {\n\t\tdefault: {\n\t\t\tpaddingLeft: 8,\n\t\t\tpaddingRight: 24,\n\t\t},\n\t\tsmall: {\n\t\t\tpaddingLeft: 8,\n\t\t\tpaddingRight: 24,\n\t\t},\n\t\t'__unstable-large': {\n\t\t\tpaddingLeft: 16,\n\t\t\tpaddingRight: 32,\n\t\t},\n\t};\n\treturn rtl( sizes[ selectSize ] );\n};\n\n// TODO: Resolve need to use &&& to increase specificity\n// https://github.com/WordPress/gutenberg/issues/18483\n\nexport const Select = styled.select< SelectProps >`\n\t&&& {\n\t\tappearance: none;\n\t\tbackground: transparent;\n\t\tbox-sizing: border-box;\n\t\tborder: none;\n\t\tbox-shadow: none !important;\n\t\tcolor: ${ COLORS.gray[ 900 ] };\n\t\tdisplay: block;\n\t\tfont-family: inherit;\n\t\tmargin: 0;\n\t\twidth: 100%;\n\n\t\t${ disabledStyles };\n\t\t${ fontSizeStyles };\n\t\t${ sizeStyles };\n\t\t${ sizePaddings };\n\t}\n`;\n\nexport const DownArrowWrapper = styled.div`\n\talign-items: center;\n\tbottom: 0;\n\tbox-sizing: border-box;\n\tdisplay: flex;\n\tpadding: 0 4px;\n\tpointer-events: none;\n\tposition: absolute;\n\ttop: 0;\n\n\t${ rtl( { right: 0 } ) }\n\n\tsvg {\n\t\tdisplay: block;\n\t}\n`;\n"]}
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default = void 0;
|
|
8
|
+
exports.default = exports.TextControl = void 0;
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
@@ -16,33 +16,18 @@ var _compose = require("@wordpress/compose");
|
|
|
16
16
|
var _baseControl = _interopRequireDefault(require("../base-control"));
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
19
|
+
* External dependencies
|
|
24
20
|
*/
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @property {string} label Label for the control.
|
|
29
|
-
* @property {boolean} [hideLabelFromVision] Whether to accessibly hide the label.
|
|
30
|
-
* @property {string} value Value of the input.
|
|
31
|
-
* @property {string} [help] Optional help text for the control.
|
|
32
|
-
* @property {string} [className] Classname passed to BaseControl wrapper
|
|
33
|
-
* @property {(value: string) => void} onChange Handle changes.
|
|
34
|
-
* @property {string} [type='text'] Type of the input.
|
|
23
|
+
* WordPress dependencies
|
|
35
24
|
*/
|
|
36
25
|
|
|
37
|
-
/** @typedef {OwnProps & import('react').ComponentProps<'input'>} Props */
|
|
38
|
-
|
|
39
26
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param {Props} props Props
|
|
42
|
-
* @param {import('react').ForwardedRef<HTMLInputElement>} ref
|
|
27
|
+
* Internal dependencies
|
|
43
28
|
*/
|
|
44
|
-
function
|
|
45
|
-
|
|
29
|
+
function UnforwardedTextControl(props, ref) {
|
|
30
|
+
const {
|
|
46
31
|
label,
|
|
47
32
|
hideLabelFromVision,
|
|
48
33
|
value,
|
|
@@ -50,14 +35,12 @@ function TextControl(_ref, ref) {
|
|
|
50
35
|
className,
|
|
51
36
|
onChange,
|
|
52
37
|
type = 'text',
|
|
53
|
-
...
|
|
54
|
-
} =
|
|
38
|
+
...additionalProps
|
|
39
|
+
} = props;
|
|
55
40
|
const instanceId = (0, _compose.useInstanceId)(TextControl);
|
|
56
41
|
const id = `inspector-text-control-${instanceId}`;
|
|
57
42
|
|
|
58
|
-
const onChangeValue = (
|
|
59
|
-
/** @type {import('react').ChangeEvent<HTMLInputElement>} */
|
|
60
|
-
event) => onChange(event.target.value);
|
|
43
|
+
const onChangeValue = event => onChange(event.target.value);
|
|
61
44
|
|
|
62
45
|
return (0, _element.createElement)(_baseControl.default, {
|
|
63
46
|
label: label,
|
|
@@ -73,10 +56,34 @@ function TextControl(_ref, ref) {
|
|
|
73
56
|
onChange: onChangeValue,
|
|
74
57
|
"aria-describedby": !!help ? id + '__help' : undefined,
|
|
75
58
|
ref: ref
|
|
76
|
-
},
|
|
59
|
+
}, additionalProps)));
|
|
77
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* TextControl components let users enter and edit text.
|
|
63
|
+
*
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```jsx
|
|
67
|
+
* import { TextControl } from '@wordpress/components';
|
|
68
|
+
* import { useState } from '@wordpress/element';
|
|
69
|
+
*
|
|
70
|
+
* const MyTextControl = () => {
|
|
71
|
+
* const [ className, setClassName ] = useState( '' );
|
|
72
|
+
*
|
|
73
|
+
* return (
|
|
74
|
+
* <TextControl
|
|
75
|
+
* label="Additional CSS Class"
|
|
76
|
+
* value={ className }
|
|
77
|
+
* onChange={ ( value ) => setClassName( value ) }
|
|
78
|
+
* />
|
|
79
|
+
* );
|
|
80
|
+
* };
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
78
83
|
|
|
79
|
-
var _default = (0, _element.forwardRef)(TextControl);
|
|
80
84
|
|
|
85
|
+
const TextControl = (0, _element.forwardRef)(UnforwardedTextControl);
|
|
86
|
+
exports.TextControl = TextControl;
|
|
87
|
+
var _default = TextControl;
|
|
81
88
|
exports.default = _default;
|
|
82
89
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/text-control/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/text-control/index.tsx"],"names":["UnforwardedTextControl","props","ref","label","hideLabelFromVision","value","help","className","onChange","type","additionalProps","instanceId","TextControl","id","onChangeValue","event","target","undefined"],"mappings":";;;;;;;;;AASA;;;;AADA;;AAMA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAKA,SAASA,sBAAT,CACCC,KADD,EAECC,GAFD,EAGE;AACD,QAAM;AACLC,IAAAA,KADK;AAELC,IAAAA,mBAFK;AAGLC,IAAAA,KAHK;AAILC,IAAAA,IAJK;AAKLC,IAAAA,SALK;AAMLC,IAAAA,QANK;AAOLC,IAAAA,IAAI,GAAG,MAPF;AAQL,OAAGC;AARE,MASFT,KATJ;AAUA,QAAMU,UAAU,GAAG,4BAAeC,WAAf,CAAnB;AACA,QAAMC,EAAE,GAAI,0BAA0BF,UAAY,EAAlD;;AACA,QAAMG,aAAa,GAAKC,KAAF,IACrBP,QAAQ,CAAEO,KAAK,CAACC,MAAN,CAAaX,KAAf,CADT;;AAGA,SACC,4BAAC,oBAAD;AACC,IAAA,KAAK,EAAGF,KADT;AAEC,IAAA,mBAAmB,EAAGC,mBAFvB;AAGC,IAAA,EAAE,EAAGS,EAHN;AAIC,IAAA,IAAI,EAAGP,IAJR;AAKC,IAAA,SAAS,EAAGC;AALb,KAOC;AACC,IAAA,SAAS,EAAC,gCADX;AAEC,IAAA,IAAI,EAAGE,IAFR;AAGC,IAAA,EAAE,EAAGI,EAHN;AAIC,IAAA,KAAK,EAAGR,KAJT;AAKC,IAAA,QAAQ,EAAGS,aALZ;AAMC,wBAAmB,CAAC,CAAER,IAAH,GAAUO,EAAE,GAAG,QAAf,GAA0BI,SAN9C;AAOC,IAAA,GAAG,EAAGf;AAPP,KAQMQ,eARN,EAPD,CADD;AAoBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,WAAW,GAAG,yBAAYZ,sBAAZ,CAApB;;eAEQY,W","sourcesContent":["/**\n * External dependencies\n */\nimport type { ChangeEvent, ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '../base-control';\nimport type { WordPressComponentProps } from '../ui/context';\nimport type { TextControlProps } from './types';\n\nfunction UnforwardedTextControl(\n\tprops: WordPressComponentProps< TextControlProps, 'input', false >,\n\tref: ForwardedRef< HTMLInputElement >\n) {\n\tconst {\n\t\tlabel,\n\t\thideLabelFromVision,\n\t\tvalue,\n\t\thelp,\n\t\tclassName,\n\t\tonChange,\n\t\ttype = 'text',\n\t\t...additionalProps\n\t} = props;\n\tconst instanceId = useInstanceId( TextControl );\n\tconst id = `inspector-text-control-${ instanceId }`;\n\tconst onChangeValue = ( event: ChangeEvent< HTMLInputElement > ) =>\n\t\tonChange( event.target.value );\n\n\treturn (\n\t\t<BaseControl\n\t\t\tlabel={ label }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\tid={ id }\n\t\t\thelp={ help }\n\t\t\tclassName={ className }\n\t\t>\n\t\t\t<input\n\t\t\t\tclassName=\"components-text-control__input\"\n\t\t\t\ttype={ type }\n\t\t\t\tid={ id }\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChangeValue }\n\t\t\t\taria-describedby={ !! help ? id + '__help' : undefined }\n\t\t\t\tref={ ref }\n\t\t\t\t{ ...additionalProps }\n\t\t\t/>\n\t\t</BaseControl>\n\t);\n}\n\n/**\n * TextControl components let users enter and edit text.\n *\n *\n * @example\n * ```jsx\n * import { TextControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTextControl = () => {\n * const [ className, setClassName ] = useState( '' );\n *\n * return (\n * <TextControl\n * label=\"Additional CSS Class\"\n * value={ className }\n * onChange={ ( value ) => setClassName( value ) }\n * />\n * );\n * };\n * ```\n */\nexport const TextControl = forwardRef( UnforwardedTextControl );\n\nexport default TextControl;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -7,19 +9,19 @@ exports.default = ToggleGroupControlOptionIcon;
|
|
|
7
9
|
|
|
8
10
|
var _element = require("@wordpress/element");
|
|
9
11
|
|
|
10
|
-
var _icons = require("@wordpress/icons");
|
|
11
|
-
|
|
12
12
|
var _toggleGroupControlOptionBase = require("../toggle-group-control-option-base");
|
|
13
13
|
|
|
14
|
+
var _icon = _interopRequireDefault(require("../../icon"));
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
17
|
+
* Internal dependencies
|
|
16
18
|
*/
|
|
17
19
|
function ToggleGroupControlOptionIcon(props) {
|
|
18
20
|
const {
|
|
19
21
|
icon,
|
|
20
22
|
...restProps
|
|
21
23
|
} = props;
|
|
22
|
-
return (0, _element.createElement)(_toggleGroupControlOptionBase.ToggleGroupControlOptionBase, restProps, (0, _element.createElement)(
|
|
24
|
+
return (0, _element.createElement)(_toggleGroupControlOptionBase.ToggleGroupControlOptionBase, restProps, (0, _element.createElement)(_icon.default, {
|
|
23
25
|
icon: icon
|
|
24
26
|
}));
|
|
25
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/toggle-group-control/toggle-group-control-option-icon/component.tsx"],"names":["ToggleGroupControlOptionIcon","props","icon","restProps"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/toggle-group-control/toggle-group-control-option-icon/component.tsx"],"names":["ToggleGroupControlOptionIcon","props","icon","restProps"],"mappings":";;;;;;;;;;;AAKA;;AACA;;AANA;AACA;AACA;AAMe,SAASA,4BAAT,CACdC,KADc,EAMb;AACD,QAAM;AAAEC,IAAAA,IAAF;AAAQ,OAAGC;AAAX,MAAyBF,KAA/B;AACA,SACC,4BAAC,0DAAD,EAAmCE,SAAnC,EACC,4BAAC,aAAD;AAAM,IAAA,IAAI,EAAGD;AAAb,IADD,CADD;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../ui/context';\nimport type { ToggleGroupControlOptionIconProps } from '../types';\nimport { ToggleGroupControlOptionBase } from '../toggle-group-control-option-base';\nimport Icon from '../../icon';\n\nexport default function ToggleGroupControlOptionIcon(\n\tprops: WordPressComponentProps<\n\t\tToggleGroupControlOptionIconProps,\n\t\t'button',\n\t\tfalse\n\t>\n) {\n\tconst { icon, ...restProps } = props;\n\treturn (\n\t\t<ToggleGroupControlOptionBase { ...restProps }>\n\t\t\t<Icon icon={ icon } />\n\t\t</ToggleGroupControlOptionBase>\n\t);\n}\n\n/**\n * `ToggleGroupControlOptionIcon` is a form component which is meant to be used as a\n * child of `ToggleGroupControl` and displays an icon.\n *\n * @example\n * ```jsx\n *\n * import {\n *\t__experimentalToggleGroupControl as ToggleGroupControl,\n *\t__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,\n * from '@wordpress/components';\n * import { formatLowercase, formatUppercase } from '@wordpress/icons';\n *\n * function Example() {\n *\treturn (\n *\t\t<ToggleGroupControl label=\"my label\" value=\"vertical\" isBlock>\n *\t\t\t<ToggleGroupControlOptionIcon\n *\t\t\t\tvalue=\"uppercase\"\n *\t\t\t\ticon={ formatUppercase }\n *\t\t\t/>\n *\t\t\t<ToggleGroupControlOptionIcon\n *\t\t\t\tvalue=\"lowercase\"\n *\t\t\t\ticon={ formatLowercase }\n *\t\t\t/>\n *\t\t</ToggleGroupControl>\n *\t);\n * }\n ** ```\n */\n"]}
|
|
@@ -11,6 +11,8 @@ var _element = require("@wordpress/element");
|
|
|
11
11
|
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
13
|
|
|
14
|
+
var _a11y = require("@wordpress/a11y");
|
|
15
|
+
|
|
14
16
|
var _icons = require("@wordpress/icons");
|
|
15
17
|
|
|
16
18
|
var _i18n = require("@wordpress/i18n");
|
|
@@ -40,12 +42,9 @@ var _context = require("../../ui/context");
|
|
|
40
42
|
/**
|
|
41
43
|
* Internal dependencies
|
|
42
44
|
*/
|
|
43
|
-
const noop = () => {};
|
|
44
|
-
|
|
45
45
|
const DefaultControlsGroup = _ref => {
|
|
46
46
|
let {
|
|
47
47
|
items,
|
|
48
|
-
onClose,
|
|
49
48
|
toggleItem
|
|
50
49
|
} = _ref;
|
|
51
50
|
|
|
@@ -55,20 +54,28 @@ const DefaultControlsGroup = _ref => {
|
|
|
55
54
|
|
|
56
55
|
return (0, _element.createElement)(_menuGroup.default, null, items.map(_ref2 => {
|
|
57
56
|
let [label, hasValue] = _ref2;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
|
|
58
|
+
if (hasValue) {
|
|
59
|
+
return (0, _element.createElement)(_menuItem.default, {
|
|
60
|
+
key: label,
|
|
61
|
+
role: "menuitem",
|
|
62
|
+
icon: _icons.reset,
|
|
63
|
+
label: (0, _i18n.sprintf)( // translators: %s: The name of the control being reset e.g. "Padding".
|
|
64
|
+
(0, _i18n.__)('Reset %s'), label),
|
|
65
|
+
onClick: () => {
|
|
66
|
+
toggleItem(label);
|
|
67
|
+
(0, _a11y.speak)((0, _i18n.sprintf)( // translators: %s: The name of the control being reset e.g. "Padding".
|
|
68
|
+
(0, _i18n.__)('%s reset to default'), label), 'assertive');
|
|
69
|
+
}
|
|
70
|
+
}, label);
|
|
71
|
+
}
|
|
72
|
+
|
|
61
73
|
return (0, _element.createElement)(_menuItem.default, {
|
|
62
74
|
key: label,
|
|
63
|
-
|
|
75
|
+
role: "menuitemcheckbox",
|
|
76
|
+
icon: _icons.check,
|
|
64
77
|
isSelected: true,
|
|
65
|
-
disabled:
|
|
66
|
-
label: itemLabel,
|
|
67
|
-
onClick: () => {
|
|
68
|
-
toggleItem(label);
|
|
69
|
-
onClose();
|
|
70
|
-
},
|
|
71
|
-
role: "menuitemcheckbox"
|
|
78
|
+
"aria-disabled": true
|
|
72
79
|
}, label);
|
|
73
80
|
}));
|
|
74
81
|
};
|
|
@@ -76,7 +83,6 @@ const DefaultControlsGroup = _ref => {
|
|
|
76
83
|
const OptionalControlsGroup = _ref3 => {
|
|
77
84
|
let {
|
|
78
85
|
items,
|
|
79
|
-
onClose,
|
|
80
86
|
toggleItem
|
|
81
87
|
} = _ref3;
|
|
82
88
|
|
|
@@ -95,8 +101,15 @@ const OptionalControlsGroup = _ref3 => {
|
|
|
95
101
|
isSelected: isSelected,
|
|
96
102
|
label: itemLabel,
|
|
97
103
|
onClick: () => {
|
|
104
|
+
if (isSelected) {
|
|
105
|
+
(0, _a11y.speak)((0, _i18n.sprintf)( // translators: %s: The name of the control being reset e.g. "Padding".
|
|
106
|
+
(0, _i18n.__)('%s hidden and reset to default'), label), 'assertive');
|
|
107
|
+
} else {
|
|
108
|
+
(0, _a11y.speak)((0, _i18n.sprintf)( // translators: %s: The name of the control being reset e.g. "Padding".
|
|
109
|
+
(0, _i18n.__)('%s is now visible'), label), 'assertive');
|
|
110
|
+
}
|
|
111
|
+
|
|
98
112
|
toggleItem(label);
|
|
99
|
-
onClose();
|
|
100
113
|
},
|
|
101
114
|
role: "menuitemcheckbox"
|
|
102
115
|
}, label);
|
|
@@ -123,7 +136,13 @@ const ToolsPanelHeader = (props, forwardedRef) => {
|
|
|
123
136
|
const defaultItems = Object.entries((menuItems === null || menuItems === void 0 ? void 0 : menuItems.default) || {});
|
|
124
137
|
const optionalItems = Object.entries((menuItems === null || menuItems === void 0 ? void 0 : menuItems.optional) || {});
|
|
125
138
|
const dropDownMenuIcon = areAllOptionalControlsHidden ? _icons.plus : _icons.moreVertical;
|
|
126
|
-
const dropDownMenuLabelText =
|
|
139
|
+
const dropDownMenuLabelText = (0, _i18n.sprintf)( // translators: %s: The name of the tool e.g. "Color" or "Typography".
|
|
140
|
+
(0, _i18n._x)('%s options', 'Button label to reveal tool panel options'), labelText);
|
|
141
|
+
const dropdownMenuDescriptionText = areAllOptionalControlsHidden ? (0, _i18n.__)('All options are currently hidden') : undefined;
|
|
142
|
+
const canResetAll = [...defaultItems, ...optionalItems].some(_ref5 => {
|
|
143
|
+
let [, isSelected] = _ref5;
|
|
144
|
+
return isSelected;
|
|
145
|
+
});
|
|
127
146
|
return (0, _element.createElement)(_hStack.HStack, (0, _extends2.default)({}, headerProps, {
|
|
128
147
|
ref: forwardedRef
|
|
129
148
|
}), (0, _element.createElement)(_heading.Heading, {
|
|
@@ -136,28 +155,25 @@ const ToolsPanelHeader = (props, forwardedRef) => {
|
|
|
136
155
|
className: dropdownMenuClassName
|
|
137
156
|
},
|
|
138
157
|
toggleProps: {
|
|
139
|
-
isSmall: true
|
|
158
|
+
isSmall: true,
|
|
159
|
+
describedBy: dropdownMenuDescriptionText
|
|
140
160
|
}
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
toggleItem: toggleItem
|
|
153
|
-
}), (0, _element.createElement)(_menuGroup.default, null, (0, _element.createElement)(_menuItem.default, {
|
|
154
|
-
variant: 'tertiary',
|
|
155
|
-
onClick: () => {
|
|
161
|
+
}, () => (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(DefaultControlsGroup, {
|
|
162
|
+
items: defaultItems,
|
|
163
|
+
toggleItem: toggleItem
|
|
164
|
+
}), (0, _element.createElement)(OptionalControlsGroup, {
|
|
165
|
+
items: optionalItems,
|
|
166
|
+
toggleItem: toggleItem
|
|
167
|
+
}), (0, _element.createElement)(_menuGroup.default, null, (0, _element.createElement)(_menuItem.default, {
|
|
168
|
+
"aria-disabled": !canResetAll,
|
|
169
|
+
variant: 'tertiary',
|
|
170
|
+
onClick: () => {
|
|
171
|
+
if (canResetAll) {
|
|
156
172
|
resetAll();
|
|
157
|
-
|
|
173
|
+
(0, _a11y.speak)((0, _i18n.__)('All options reset'), 'assertive');
|
|
158
174
|
}
|
|
159
|
-
}
|
|
160
|
-
}));
|
|
175
|
+
}
|
|
176
|
+
}, (0, _i18n.__)('Reset all'))))));
|
|
161
177
|
};
|
|
162
178
|
|
|
163
179
|
const ConnectedToolsPanelHeader = (0, _context.contextConnect)(ToolsPanelHeader, 'ToolsPanelHeader');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/tools-panel/tools-panel-header/component.tsx"],"names":["noop","DefaultControlsGroup","items","onClose","toggleItem","length","map","label","hasValue","icon","reset","check","itemLabel","undefined","OptionalControlsGroup","isSelected","ToolsPanelHeader","props","forwardedRef","areAllOptionalControlsHidden","dropdownMenuClassName","hasMenuItems","headingClassName","labelText","menuItems","resetAll","headerProps","defaultItems","Object","entries","default","optionalItems","optional","dropDownMenuIcon","plus","moreVertical","dropDownMenuLabelText","className","isSmall","ConnectedToolsPanelHeader"],"mappings":";;;;;;;;;;;;;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mBAA/D;AACA,QAAMC,qBAAqB,GAAGjB,4BAA4B,GACvD,cACA,sBADA,EAEA,2CAFA,CADuD,GAKvD,cAAI,cAAJ,EAAoB,2CAApB,CALH;AAOA,SACC,4BAAC,cAAD,6BAAaO,WAAb;AAA2B,IAAA,GAAG,EAAGR;AAAjC,MACC,4BAAC,gBAAD;AAAS,IAAA,KAAK,EAAG,CAAjB;AAAqB,IAAA,SAAS,EAAGI;AAAjC,KACGC,SADH,CADD,EAIGF,YAAY,IACb,4BAAC,qBAAD;AACC,IAAA,IAAI,EAAGY,gBADR;AAEC,IAAA,KAAK,EAAGG,qBAFT;AAGC,IAAA,SAAS,EAAG;AAAEC,MAAAA,SAAS,EAAEjB;AAAb,KAHb;AAIC,IAAA,WAAW,EAAG;AAAEkB,MAAAA,OAAO,EAAE;AAAX;AAJf,KAMG;AAAA,QAAE;AAAEnC,MAAAA,OAAO,GAAGH;AAAZ,KAAF;AAAA,WACD,qDACC,4BAAC,oBAAD;AACC,MAAA,KAAK,EAAG2B,YADT;AAEC,MAAA,OAAO,EAAGxB,OAFX;AAGC,MAAA,UAAU,EAAGC;AAHd,MADD,EAMC,4BAAC,qBAAD;AACC,MAAA,KAAK,EAAG2B,aADT;AAEC,MAAA,OAAO,EAAG5B,OAFX;AAGC,MAAA,UAAU,EAAGC;AAHd,MAND,EAWC,4BAAC,kBAAD,QACC,4BAAC,iBAAD;AACC,MAAA,OAAO,EAAG,UADX;AAEC,MAAA,OAAO,EAAG,MAAM;AACfqB,QAAAA,QAAQ;AACRtB,QAAAA,OAAO;AACP;AALF,OAOG,cAAI,WAAJ,CAPH,CADD,CAXD,CADC;AAAA,GANH,CALF,CADD;AAyCA,CAvED;;AAyEA,MAAMoC,yBAAyB,GAAG,6BACjCvB,gBADiC,EAEjC,kBAFiC,CAAlC;eAKeuB,yB","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { check, reset, moreVertical, plus } from '@wordpress/icons';\nimport { __, _x, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport DropdownMenu from '../../dropdown-menu';\nimport MenuGroup from '../../menu-group';\nimport MenuItem from '../../menu-item';\nimport { HStack } from '../../h-stack';\nimport { Heading } from '../../heading';\nimport { useToolsPanelHeader } from './hook';\nimport { contextConnect, WordPressComponentProps } from '../../ui/context';\nimport type {\n\tToolsPanelControlsGroupProps,\n\tToolsPanelHeaderProps,\n} from '../types';\n\nconst noop = () => {};\n\nconst DefaultControlsGroup = ( {\n\titems,\n\tonClose,\n\ttoggleItem,\n}: ToolsPanelControlsGroupProps ) => {\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuGroup>\n\t\t\t{ items.map( ( [ label, hasValue ] ) => {\n\t\t\t\tconst icon = hasValue ? reset : check;\n\t\t\t\tconst itemLabel = hasValue\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: The name of the control being reset e.g. \"Padding\".\n\t\t\t\t\t\t\t__( 'Reset %s' ),\n\t\t\t\t\t\t\tlabel\n\t\t\t\t\t )\n\t\t\t\t\t: undefined;\n\n\t\t\t\treturn (\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tkey={ label }\n\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\tisSelected={ true }\n\t\t\t\t\t\tdisabled={ ! hasValue }\n\t\t\t\t\t\tlabel={ itemLabel }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\ttoggleItem( label );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</MenuGroup>\n\t);\n};\n\nconst OptionalControlsGroup = ( {\n\titems,\n\tonClose,\n\ttoggleItem,\n}: ToolsPanelControlsGroupProps ) => {\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuGroup>\n\t\t\t{ items.map( ( [ label, isSelected ] ) => {\n\t\t\t\tconst itemLabel = isSelected\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: The name of the control being hidden and reset e.g. \"Padding\".\n\t\t\t\t\t\t\t__( 'Hide and reset %s' ),\n\t\t\t\t\t\t\tlabel\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// translators: %s: The name of the control to display e.g. \"Padding\".\n\t\t\t\t\t\t\t__( 'Show %s' ),\n\t\t\t\t\t\t\tlabel\n\t\t\t\t\t );\n\n\t\t\t\treturn (\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tkey={ label }\n\t\t\t\t\t\ticon={ isSelected && check }\n\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\tlabel={ itemLabel }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\ttoggleItem( label );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</MenuGroup>\n\t);\n};\n\nconst ToolsPanelHeader = (\n\tprops: WordPressComponentProps< ToolsPanelHeaderProps, 'h2' >,\n\tforwardedRef: ForwardedRef< any >\n) => {\n\tconst {\n\t\tareAllOptionalControlsHidden,\n\t\tdropdownMenuClassName,\n\t\thasMenuItems,\n\t\theadingClassName,\n\t\tlabel: labelText,\n\t\tmenuItems,\n\t\tresetAll,\n\t\ttoggleItem,\n\t\t...headerProps\n\t} = useToolsPanelHeader( props );\n\n\tif ( ! labelText ) {\n\t\treturn null;\n\t}\n\n\tconst defaultItems = Object.entries( menuItems?.default || {} );\n\tconst optionalItems = Object.entries( menuItems?.optional || {} );\n\tconst dropDownMenuIcon = areAllOptionalControlsHidden ? plus : moreVertical;\n\tconst dropDownMenuLabelText = areAllOptionalControlsHidden\n\t\t? _x(\n\t\t\t\t'View and add options',\n\t\t\t\t'Button label to reveal tool panel options'\n\t\t )\n\t\t: _x( 'View options', 'Button label to reveal tool panel options' );\n\n\treturn (\n\t\t<HStack { ...headerProps } ref={ forwardedRef }>\n\t\t\t<Heading level={ 2 } className={ headingClassName }>\n\t\t\t\t{ labelText }\n\t\t\t</Heading>\n\t\t\t{ hasMenuItems && (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\ticon={ dropDownMenuIcon }\n\t\t\t\t\tlabel={ dropDownMenuLabelText }\n\t\t\t\t\tmenuProps={ { className: dropdownMenuClassName } }\n\t\t\t\t\ttoggleProps={ { isSmall: true } }\n\t\t\t\t>\n\t\t\t\t\t{ ( { onClose = noop } ) => (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<DefaultControlsGroup\n\t\t\t\t\t\t\t\titems={ defaultItems }\n\t\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\t\ttoggleItem={ toggleItem }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<OptionalControlsGroup\n\t\t\t\t\t\t\t\titems={ optionalItems }\n\t\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\t\ttoggleItem={ toggleItem }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tvariant={ 'tertiary' }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tresetAll();\n\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Reset all' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\n\t\t</HStack>\n\t);\n};\n\nconst ConnectedToolsPanelHeader = contextConnect(\n\tToolsPanelHeader,\n\t'ToolsPanelHeader'\n);\n\nexport default ConnectedToolsPanelHeader;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/tools-panel/tools-panel-header/component.tsx"],"names":["DefaultControlsGroup","items","toggleItem","length","map","label","hasValue","reset","check","OptionalControlsGroup","isSelected","itemLabel","ToolsPanelHeader","props","forwardedRef","areAllOptionalControlsHidden","dropdownMenuClassName","hasMenuItems","headingClassName","labelText","menuItems","resetAll","headerProps","defaultItems","Object","entries","default","optionalItems","optional","dropDownMenuIcon","plus","moreVertical","dropDownMenuLabelText","dropdownMenuDescriptionText","undefined","canResetAll","some","className","isSmall","describedBy","ConnectedToolsPanelHeader"],"mappings":";;;;;;;;;;;;;AAQA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AArBA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAaA,MAAMA,oBAAoB,GAAG,QAGQ;AAAA,MAHN;AAC9BC,IAAAA,KAD8B;AAE9BC,IAAAA;AAF8B,GAGM;;AACpC,MAAK,CAAED,KAAK,CAACE,MAAb,EAAsB;AACrB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,kBAAD,QACGF,KAAK,CAACG,GAAN,CAAW,SAA2B;AAAA,QAAzB,CAAEC,KAAF,EAASC,QAAT,CAAyB;;AACvC,QAAKA,QAAL,EAAgB;AACf,aACC,4BAAC,iBAAD;AACC,QAAA,GAAG,EAAGD,KADP;AAEC,QAAA,IAAI,EAAC,UAFN;AAGC,QAAA,IAAI,EAAGE,YAHR;AAIC,QAAA,KAAK,EAAG,oBACP;AACA,sBAAI,UAAJ,CAFO,EAGPF,KAHO,CAJT;AASC,QAAA,OAAO,EAAG,MAAM;AACfH,UAAAA,UAAU,CAAEG,KAAF,CAAV;AACA,2BACC,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,CADD,EAIGF,YAAY,IACb,4BAAC,qBAAD;AACC,IAAA,IAAI,EAAGY,gBADR;AAEC,IAAA,KAAK,EAAGG,qBAFT;AAGC,IAAA,SAAS,EAAG;AAAEK,MAAAA,SAAS,EAAErB;AAAb,KAHb;AAIC,IAAA,WAAW,EAAG;AACbsB,MAAAA,OAAO,EAAE,IADI;AAEbC,MAAAA,WAAW,EAAEN;AAFA;AAJf,KASG,MACD,qDACC,4BAAC,oBAAD;AACC,IAAA,KAAK,EAAGV,YADT;AAEC,IAAA,UAAU,EAAGrB;AAFd,IADD,EAKC,4BAAC,qBAAD;AACC,IAAA,KAAK,EAAGyB,aADT;AAEC,IAAA,UAAU,EAAGzB;AAFd,IALD,EASC,4BAAC,kBAAD,QACC,4BAAC,iBAAD;AACC,qBAAgB,CAAEiC,WADnB;AAEC,IAAA,OAAO,EAAG,UAFX;AAGC,IAAA,OAAO,EAAG,MAAM;AACf,UAAKA,WAAL,EAAmB;AAClBd,QAAAA,QAAQ;AACR,yBACC,cAAI,mBAAJ,CADD,EAEC,WAFD;AAIA;AACD;AAXF,KAaG,cAAI,WAAJ,CAbH,CADD,CATD,CAVF,CALF,CADD;AAgDA,CApFD;;AAsFA,MAAMmB,yBAAyB,GAAG,6BACjC5B,gBADiC,EAEjC,kBAFiC,CAAlC;eAKe4B,yB","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { speak } from '@wordpress/a11y';\nimport { check, reset, moreVertical, plus } from '@wordpress/icons';\nimport { __, _x, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport DropdownMenu from '../../dropdown-menu';\nimport MenuGroup from '../../menu-group';\nimport MenuItem from '../../menu-item';\nimport { HStack } from '../../h-stack';\nimport { Heading } from '../../heading';\nimport { useToolsPanelHeader } from './hook';\nimport { contextConnect, WordPressComponentProps } from '../../ui/context';\nimport type {\n\tToolsPanelControlsGroupProps,\n\tToolsPanelHeaderProps,\n} from '../types';\n\nconst DefaultControlsGroup = ( {\n\titems,\n\ttoggleItem,\n}: ToolsPanelControlsGroupProps ) => {\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuGroup>\n\t\t\t{ items.map( ( [ label, hasValue ] ) => {\n\t\t\t\tif ( hasValue ) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tkey={ label }\n\t\t\t\t\t\t\trole=\"menuitem\"\n\t\t\t\t\t\t\ticon={ reset }\n\t\t\t\t\t\t\tlabel={ sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The name of the control being reset e.g. \"Padding\".\n\t\t\t\t\t\t\t\t__( 'Reset %s' ),\n\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\ttoggleItem( label );\n\t\t\t\t\t\t\t\tspeak(\n\t\t\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: %s: The name of the control being reset e.g. \"Padding\".\n\t\t\t\t\t\t\t\t\t\t__( '%s reset to default' ),\n\t\t\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t'assertive'\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn (\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tkey={ label }\n\t\t\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t\t\t\ticon={ check }\n\t\t\t\t\t\tisSelected\n\t\t\t\t\t\taria-disabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</MenuGroup>\n\t);\n};\n\nconst OptionalControlsGroup = ( {\n\titems,\n\ttoggleItem,\n}: ToolsPanelControlsGroupProps ) => {\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuGroup>\n\t\t\t{ items.map( ( [ label, isSelected ] ) => {\n\t\t\t\tconst itemLabel = isSelected\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: The name of the control being hidden and reset e.g. \"Padding\".\n\t\t\t\t\t\t\t__( 'Hide and reset %s' ),\n\t\t\t\t\t\t\tlabel\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// translators: %s: The name of the control to display e.g. \"Padding\".\n\t\t\t\t\t\t\t__( 'Show %s' ),\n\t\t\t\t\t\t\tlabel\n\t\t\t\t\t );\n\n\t\t\t\treturn (\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tkey={ label }\n\t\t\t\t\t\ticon={ isSelected && check }\n\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\tlabel={ itemLabel }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( isSelected ) {\n\t\t\t\t\t\t\t\tspeak(\n\t\t\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: %s: The name of the control being reset e.g. \"Padding\".\n\t\t\t\t\t\t\t\t\t\t__( '%s hidden and reset to default' ),\n\t\t\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t'assertive'\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tspeak(\n\t\t\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: %s: The name of the control being reset e.g. \"Padding\".\n\t\t\t\t\t\t\t\t\t\t__( '%s is now visible' ),\n\t\t\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t'assertive'\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttoggleItem( label );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</MenuGroup>\n\t);\n};\n\nconst ToolsPanelHeader = (\n\tprops: WordPressComponentProps< ToolsPanelHeaderProps, 'h2' >,\n\tforwardedRef: ForwardedRef< any >\n) => {\n\tconst {\n\t\tareAllOptionalControlsHidden,\n\t\tdropdownMenuClassName,\n\t\thasMenuItems,\n\t\theadingClassName,\n\t\tlabel: labelText,\n\t\tmenuItems,\n\t\tresetAll,\n\t\ttoggleItem,\n\t\t...headerProps\n\t} = useToolsPanelHeader( props );\n\n\tif ( ! labelText ) {\n\t\treturn null;\n\t}\n\n\tconst defaultItems = Object.entries( menuItems?.default || {} );\n\tconst optionalItems = Object.entries( menuItems?.optional || {} );\n\tconst dropDownMenuIcon = areAllOptionalControlsHidden ? plus : moreVertical;\n\tconst dropDownMenuLabelText = sprintf(\n\t\t// translators: %s: The name of the tool e.g. \"Color\" or \"Typography\".\n\t\t_x( '%s options', 'Button label to reveal tool panel options' ),\n\t\tlabelText\n\t);\n\tconst dropdownMenuDescriptionText = areAllOptionalControlsHidden\n\t\t? __( 'All options are currently hidden' )\n\t\t: undefined;\n\n\tconst canResetAll = [ ...defaultItems, ...optionalItems ].some(\n\t\t( [ , isSelected ] ) => isSelected\n\t);\n\n\treturn (\n\t\t<HStack { ...headerProps } ref={ forwardedRef }>\n\t\t\t<Heading level={ 2 } className={ headingClassName }>\n\t\t\t\t{ labelText }\n\t\t\t</Heading>\n\t\t\t{ hasMenuItems && (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\ticon={ dropDownMenuIcon }\n\t\t\t\t\tlabel={ dropDownMenuLabelText }\n\t\t\t\t\tmenuProps={ { className: dropdownMenuClassName } }\n\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\tisSmall: true,\n\t\t\t\t\t\tdescribedBy: dropdownMenuDescriptionText,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ () => (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<DefaultControlsGroup\n\t\t\t\t\t\t\t\titems={ defaultItems }\n\t\t\t\t\t\t\t\ttoggleItem={ toggleItem }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<OptionalControlsGroup\n\t\t\t\t\t\t\t\titems={ optionalItems }\n\t\t\t\t\t\t\t\ttoggleItem={ toggleItem }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\taria-disabled={ ! canResetAll }\n\t\t\t\t\t\t\t\t\tvariant={ 'tertiary' }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tif ( canResetAll ) {\n\t\t\t\t\t\t\t\t\t\t\tresetAll();\n\t\t\t\t\t\t\t\t\t\t\tspeak(\n\t\t\t\t\t\t\t\t\t\t\t\t__( 'All options reset' ),\n\t\t\t\t\t\t\t\t\t\t\t\t'assertive'\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Reset all' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\n\t\t</HStack>\n\t);\n};\n\nconst ConnectedToolsPanelHeader = contextConnect(\n\tToolsPanelHeader,\n\t'ToolsPanelHeader'\n);\n\nexport default ConnectedToolsPanelHeader;\n"]}
|
|
@@ -88,7 +88,7 @@ function UnforwardedUnitControl(unitControlProps, forwardedRef) {
|
|
|
88
88
|
const nonNullValueProp = valueProp !== null && valueProp !== void 0 ? valueProp : undefined;
|
|
89
89
|
const units = (0, _element.useMemo)(() => (0, _utils.getUnitsWithCurrentUnit)(nonNullValueProp, unitProp, unitsProp), [nonNullValueProp, unitProp, unitsProp]);
|
|
90
90
|
const [parsedQuantity, parsedUnit] = (0, _utils.getParsedQuantityAndUnit)(nonNullValueProp, unitProp, units);
|
|
91
|
-
const [unit, setUnit] = (0, _hooks.useControlledState)(unitProp, {
|
|
91
|
+
const [unit, setUnit] = (0, _hooks.useControlledState)(units.length === 1 ? units[0].value : unitProp, {
|
|
92
92
|
initial: parsedUnit,
|
|
93
93
|
fallback: ''
|
|
94
94
|
});
|
|
@@ -145,8 +145,8 @@ function UnforwardedUnitControl(unitControlProps, forwardedRef) {
|
|
|
145
145
|
const changeProps = {
|
|
146
146
|
event,
|
|
147
147
|
data
|
|
148
|
-
};
|
|
149
|
-
|
|
148
|
+
}; // The `onChange` callback already gets called, no need to call it explicitely.
|
|
149
|
+
|
|
150
150
|
onUnitChange === null || onUnitChange === void 0 ? void 0 : onUnitChange(validParsedUnit, changeProps);
|
|
151
151
|
setUnit(validParsedUnit);
|
|
152
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/unit-control/index.tsx"],"names":["UnforwardedUnitControl","unitControlProps","forwardedRef","__unstableStateReducer","stateReducerProp","autoComplete","className","disabled","disableUnits","isPressEnterToChange","isResetValueOnUnitChange","isUnitSelectTabbable","label","onChange","onChangeProp","onUnitChange","size","style","unit","unitProp","units","unitsProp","CSS_UNITS","value","valueProp","onBlur","onBlurProp","props","since","hint","version","nonNullValueProp","undefined","parsedQuantity","parsedUnit","setUnit","initial","fallback","refParsedQuantity","classes","handleOnQuantityChange","nextQuantityValue","changeProps","onChangeValue","join","handleOnUnitChange","nextUnitValue","data","nextValue","default","mayUpdateUnit","event","isNaN","Number","currentTarget","current","validParsedQuantity","validParsedUnit","Array","isArray","find","option","handleOnBlur","handleOnKeyDown","key","unitControlStateReducer","state","action","nextState","type","inputControlActionTypes","COMMIT","toString","stateReducer","baseState","inputSuffix","step","activeUnit","UnitControl"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBA;;;;AAPA;;AACA;;AAKA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AAMA;;;;;;AAlCA;AACA;AACA;;AAYA;AACA;AACA;AAsBA,SAASA,sBAAT,CACCC,gBADD,EAMCC,YAND,EAOE;AACD,QAAM;AACLC,IAAAA,sBAAsB,EAAEC,gBADnB;AAELC,IAAAA,YAAY,GAAG,KAFV;AAGLC,IAAAA,SAHK;AAILC,IAAAA,QAAQ,GAAG,KAJN;AAKLC,IAAAA,YAAY,GAAG,KALV;AAMLC,IAAAA,oBAAoB,GAAG,KANlB;AAOLC,IAAAA,wBAAwB,GAAG,KAPtB;AAQLC,IAAAA,oBAAoB,GAAG,IARlB;AASLC,IAAAA,KATK;AAULC,IAAAA,QAAQ,EAAEC,YAVL;AAWLC,IAAAA,YAXK;AAYLC,IAAAA,IAAI,GAAG,SAZF;AAaLC,IAAAA,KAbK;AAcLC,IAAAA,IAAI,EAAEC,QAdD;AAeLC,IAAAA,KAAK,EAAEC,SAAS,GAAGC,gBAfd;AAgBLC,IAAAA,KAAK,EAAEC,SAhBF;AAiBLC,IAAAA,MAAM,EAAEC,UAjBH;AAkBL,OAAGC;AAlBE,MAmBF1B,gBAnBJ;;AAqBA,MAAK,UAAUA,gBAAf,EAAkC;AACjC,6BAAY,uBAAZ,EAAqC;AACpC2B,MAAAA,KAAK,EAAE,KAD6B;AAEpCC,MAAAA,IAAI,EAAE,sDAF8B;AAGpCC,MAAAA,OAAO,EAAE;AAH2B,KAArC;AAKA,GA5BA,CA8BD;AACA;AACA;;;AACA,QAAMC,gBAAgB,GAAGP,SAAH,aAAGA,SAAH,cAAGA,SAAH,GAAgBQ,SAAtC;AACA,QAAMZ,KAAK,GAAG,sBACb,MAAM,oCA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AAY,EAAGtB,YAJhB;AAKC,IAAA,SAAS,EAAGkC,OALb;AAMC,IAAA,QAAQ,EAAGhC,QANZ;AAOC,IAAA,YAAY,EAAGC,YAPhB;AAQC,IAAA,oBAAoB,EAAGC,oBARxB;AASC,IAAA,KAAK,EAAGG,KATT;AAUC,IAAA,MAAM,EAAGkD,YAVV;AAWC,IAAA,SAAS,EAAGC,eAXb;AAYC,IAAA,QAAQ,EAAGvB,sBAZZ;AAaC,IAAA,GAAG,EAAGtC,YAbP;AAcC,IAAA,IAAI,EAAGc,IAdR;AAeC,IAAA,MAAM,EAAG2D,WAfV;AAgBC,IAAA,KAAK,EAAG1C,cAAH,aAAGA,cAAH,cAAGA,cAAH,GAAqB,EAhB3B;AAiBC,IAAA,IAAI,EAAG2C,IAjBR;AAkBC,IAAA,sBAAsB,EAAGH;AAlB1B,KADD,CADD;AAwBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMK,WAAW,GAAG,yBAAY9E,sBAAZ,CAApB;;eAGQ8E,W","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tFocusEventHandler,\n\tKeyboardEvent,\n\tForwardedRef,\n\tSyntheticEvent,\n\tChangeEvent,\n\tPointerEvent,\n} from 'react';\nimport { omit } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { forwardRef, useMemo, useRef, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../ui/context';\nimport * as inputControlActionTypes from '../input-control/reducer/actions';\nimport { Root, ValueInput } from './styles/unit-control-styles';\nimport UnitSelectControl from './unit-select-control';\nimport {\n\tCSS_UNITS,\n\tgetParsedQuantityAndUnit,\n\tgetUnitsWithCurrentUnit,\n\tgetValidParsedQuantityAndUnit,\n} from './utils';\nimport { useControlledState } from '../utils/hooks';\nimport type { UnitControlProps, UnitControlOnChangeCallback } from './types';\nimport type { StateReducer } from '../input-control/reducer/state';\n\nfunction UnforwardedUnitControl(\n\tunitControlProps: WordPressComponentProps<\n\t\tUnitControlProps,\n\t\t'input',\n\t\tfalse\n\t>,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst {\n\t\t__unstableStateReducer: stateReducerProp,\n\t\tautoComplete = 'off',\n\t\tclassName,\n\t\tdisabled = false,\n\t\tdisableUnits = false,\n\t\tisPressEnterToChange = false,\n\t\tisResetValueOnUnitChange = false,\n\t\tisUnitSelectTabbable = true,\n\t\tlabel,\n\t\tonChange: onChangeProp,\n\t\tonUnitChange,\n\t\tsize = 'default',\n\t\tstyle,\n\t\tunit: unitProp,\n\t\tunits: unitsProp = CSS_UNITS,\n\t\tvalue: valueProp,\n\t\tonBlur: onBlurProp,\n\t\t...props\n\t} = unitControlProps;\n\n\tif ( 'unit' in unitControlProps ) {\n\t\tdeprecated( 'UnitControl unit prop', {\n\t\t\tsince: '5.6',\n\t\t\thint: 'The unit should be provided within the `value` prop.',\n\t\t\tversion: '6.2',\n\t\t} );\n\t}\n\n\t// The `value` prop, in theory, should not be `null`, but the following line\n\t// ensures it fallback to `undefined` in case a consumer of `UnitControl`\n\t// still passes `null` as a `value`.\n\tconst nonNullValueProp = valueProp ?? undefined;\n\tconst units = useMemo(\n\t\t() => getUnitsWithCurrentUnit( nonNullValueProp, unitProp, unitsProp ),\n\t\t[ nonNullValueProp, unitProp, unitsProp ]\n\t);\n\tconst [ parsedQuantity, parsedUnit ] = getParsedQuantityAndUnit(\n\t\tnonNullValueProp,\n\t\tunitProp,\n\t\tunits\n\t);\n\n\tconst [ unit, setUnit ] = useControlledState< string | undefined >(\n\t\tunitProp,\n\t\t{\n\t\t\tinitial: parsedUnit,\n\t\t\tfallback: '',\n\t\t}\n\t);\n\n\tuseEffect( () => {\n\t\tif ( parsedUnit !== undefined ) {\n\t\t\tsetUnit( parsedUnit );\n\t\t}\n\t}, [ parsedUnit ] );\n\n\t// Stores parsed value for hand-off in state reducer.\n\tconst refParsedQuantity = useRef< number | undefined >( undefined );\n\n\tconst classes = classnames( 'components-unit-control', className );\n\n\tconst handleOnQuantityChange = (\n\t\tnextQuantityValue: number | string | undefined,\n\t\tchangeProps: {\n\t\t\tevent:\n\t\t\t\t| ChangeEvent< HTMLInputElement >\n\t\t\t\t| PointerEvent< HTMLInputElement >;\n\t\t}\n\t) => {\n\t\tif (\n\t\t\tnextQuantityValue === '' ||\n\t\t\ttypeof nextQuantityValue === 'undefined' ||\n\t\t\tnextQuantityValue === null\n\t\t) {\n\t\t\tonChangeProp?.( '', changeProps );\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * Customizing the onChange callback.\n\t\t * This allows as to broadcast a combined value+unit to onChange.\n\t\t */\n\t\tconst onChangeValue = getValidParsedQuantityAndUnit(\n\t\t\tnextQuantityValue,\n\t\t\tunits,\n\t\t\tparsedQuantity,\n\t\t\tunit\n\t\t).join( '' );\n\n\t\tonChangeProp?.( onChangeValue, changeProps );\n\t};\n\n\tconst handleOnUnitChange: UnitControlOnChangeCallback = (\n\t\tnextUnitValue,\n\t\tchangeProps\n\t) => {\n\t\tconst { data } = changeProps;\n\n\t\tlet nextValue = `${ parsedQuantity ?? '' }${ nextUnitValue }`;\n\n\t\tif ( isResetValueOnUnitChange && data?.default !== undefined ) {\n\t\t\tnextValue = `${ data.default }${ nextUnitValue }`;\n\t\t}\n\n\t\tonChangeProp?.( nextValue, changeProps );\n\t\tonUnitChange?.( nextUnitValue, changeProps );\n\n\t\tsetUnit( nextUnitValue );\n\t};\n\n\tconst mayUpdateUnit = ( event: SyntheticEvent< HTMLInputElement > ) => {\n\t\tif ( ! isNaN( Number( event.currentTarget.value ) ) ) {\n\t\t\trefParsedQuantity.current = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst [\n\t\t\tvalidParsedQuantity,\n\t\t\tvalidParsedUnit,\n\t\t] = getValidParsedQuantityAndUnit(\n\t\t\tevent.currentTarget.value,\n\t\t\tunits,\n\t\t\tparsedQuantity,\n\t\t\tunit\n\t\t);\n\n\t\trefParsedQuantity.current = validParsedQuantity;\n\n\t\tif ( isPressEnterToChange && validParsedUnit !== unit ) {\n\t\t\tconst data = Array.isArray( units )\n\t\t\t\t? units.find( ( option ) => option.value === validParsedUnit )\n\t\t\t\t: undefined;\n\t\t\tconst changeProps = { event, data };\n\n\t\t\tonChangeProp?.(\n\t\t\t\t`${ validParsedQuantity ?? '' }${ validParsedUnit }`,\n\t\t\t\tchangeProps\n\t\t\t);\n\t\t\tonUnitChange?.( validParsedUnit, changeProps );\n\n\t\t\tsetUnit( validParsedUnit );\n\t\t}\n\t};\n\n\tconst handleOnBlur: FocusEventHandler< HTMLInputElement > = ( event ) => {\n\t\tmayUpdateUnit( event );\n\t\tonBlurProp?.( event );\n\t};\n\n\tconst handleOnKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\tconst { key } = event;\n\t\tif ( key === 'Enter' ) {\n\t\t\tmayUpdateUnit( event );\n\t\t}\n\t};\n\n\t/**\n\t * \"Middleware\" function that intercepts updates from InputControl.\n\t * This allows us to tap into actions to transform the (next) state for\n\t * InputControl.\n\t *\n\t * @param state State from InputControl\n\t * @param action Action triggering state change\n\t * @return The updated state to apply to InputControl\n\t */\n\tconst unitControlStateReducer: StateReducer = ( state, action ) => {\n\t\tconst nextState = { ...state };\n\n\t\t/*\n\t\t * On commits (when pressing ENTER and on blur if\n\t\t * isPressEnterToChange is true), if a parse has been performed\n\t\t * then use that result to update the state.\n\t\t */\n\t\tif ( action.type === inputControlActionTypes.COMMIT ) {\n\t\t\tif ( refParsedQuantity.current !== undefined ) {\n\t\t\t\tnextState.value = (\n\t\t\t\t\trefParsedQuantity.current ?? ''\n\t\t\t\t).toString();\n\t\t\t\trefParsedQuantity.current = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn nextState;\n\t};\n\n\tlet stateReducer: StateReducer = unitControlStateReducer;\n\tif ( stateReducerProp ) {\n\t\tstateReducer = ( state, action ) => {\n\t\t\tconst baseState = unitControlStateReducer( state, action );\n\t\t\treturn stateReducerProp( baseState, action );\n\t\t};\n\t}\n\n\tconst inputSuffix = ! disableUnits ? (\n\t\t<UnitSelectControl\n\t\t\taria-label={ __( 'Select unit' ) }\n\t\t\tdisabled={ disabled }\n\t\t\tisUnitSelectTabbable={ isUnitSelectTabbable }\n\t\t\tonChange={ handleOnUnitChange }\n\t\t\tsize={ size }\n\t\t\tunit={ unit }\n\t\t\tunits={ units }\n\t\t\tonBlur={ onBlurProp }\n\t\t/>\n\t) : null;\n\n\tlet step = props.step;\n\n\t/*\n\t * If no step prop has been passed, lookup the active unit and\n\t * try to get step from `units`, or default to a value of `1`\n\t */\n\tif ( ! step && units ) {\n\t\tconst activeUnit = units.find( ( option ) => option.value === unit );\n\t\tstep = activeUnit?.step ?? 1;\n\t}\n\n\treturn (\n\t\t<Root className=\"components-unit-control-wrapper\" style={ style }>\n\t\t\t<ValueInput\n\t\t\t\taria-label={ label }\n\t\t\t\ttype={ isPressEnterToChange ? 'text' : 'number' }\n\t\t\t\t{ ...omit( props, [ 'children' ] ) }\n\t\t\t\tautoComplete={ autoComplete }\n\t\t\t\tclassName={ classes }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\tdisableUnits={ disableUnits }\n\t\t\t\tisPressEnterToChange={ isPressEnterToChange }\n\t\t\t\tlabel={ label }\n\t\t\t\tonBlur={ handleOnBlur }\n\t\t\t\tonKeyDown={ handleOnKeyDown }\n\t\t\t\tonChange={ handleOnQuantityChange }\n\t\t\t\tref={ forwardedRef }\n\t\t\t\tsize={ size }\n\t\t\t\tsuffix={ inputSuffix }\n\t\t\t\tvalue={ parsedQuantity ?? '' }\n\t\t\t\tstep={ step }\n\t\t\t\t__unstableStateReducer={ stateReducer }\n\t\t\t/>\n\t\t</Root>\n\t);\n}\n\n/**\n * `UnitControl` allows the user to set a numeric quantity as well as a unit (e.g. `px`).\n *\n *\n * @example\n * ```jsx\n * import { __experimentalUnitControl as UnitControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const Example = () => {\n * const [ value, setValue ] = useState( '10px' );\n *\n * return <UnitControl onChange={ setValue } value={ value } />;\n * };\n * ```\n */\nexport const UnitControl = forwardRef( UnforwardedUnitControl );\n\nexport { parseQuantityAndUnitFromRawValue, useCustomUnits } from './utils';\nexport default UnitControl;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/unit-control/index.tsx"],"names":["UnforwardedUnitControl","unitControlProps","forwardedRef","__unstableStateReducer","stateReducerProp","autoComplete","className","disabled","disableUnits","isPressEnterToChange","isResetValueOnUnitChange","isUnitSelectTabbable","label","onChange","onChangeProp","onUnitChange","size","style","unit","unitProp","units","unitsProp","CSS_UNITS","value","valueProp","onBlur","onBlurProp","props","since","hint","version","nonNullValueProp","undefined","parsedQuantity","parsedUnit","setUnit","length","initial","fallback","refParsedQuantity","classes","handleOnQuantityChange","nextQuantityValue","changeProps","onChangeValue","join","handleOnUnitChange","nextUnitValue","data","nextValue","default","mayUpdateUnit","event","isNaN","Number","currentTarget","current","validParsedQuantity","validParsedUnit","Array","isArray","find","option","handleOnBlur","handleOnKeyDown","key","unitControlStateReducer","state","action","nextState","type","inputControlActionTypes","COMMIT","toString","stateReducer","baseState","inputSuffix","step","activeUnit","UnitControl"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBA;;;;AAPA;;AACA;;AAKA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AAMA;;;;;;AAlCA;AACA;AACA;;AAYA;AACA;AACA;AAsBA,SAASA,sBAAT,CACCC,gBADD,EAMCC,YAND,EAOE;AACD,QAAM;AACLC,IAAAA,sBAAsB,EAAEC,gBADnB;AAELC,IAAAA,YAAY,GAAG,KAFV;AAGLC,IAAAA,SAHK;AAILC,IAAAA,QAAQ,GAAG,KAJN;AAKLC,IAAAA,YAAY,GAAG,KALV;AAMLC,IAAAA,oBAAoB,GAAG,KANlB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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMK,WAAW,GAAG,yBAAY/E,sBAAZ,CAApB;;eAGQ+E,W","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tFocusEventHandler,\n\tKeyboardEvent,\n\tForwardedRef,\n\tSyntheticEvent,\n\tChangeEvent,\n\tPointerEvent,\n} from 'react';\nimport { omit } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { forwardRef, useMemo, useRef, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../ui/context';\nimport * as inputControlActionTypes from '../input-control/reducer/actions';\nimport { Root, ValueInput } from './styles/unit-control-styles';\nimport UnitSelectControl from './unit-select-control';\nimport {\n\tCSS_UNITS,\n\tgetParsedQuantityAndUnit,\n\tgetUnitsWithCurrentUnit,\n\tgetValidParsedQuantityAndUnit,\n} from './utils';\nimport { useControlledState } from '../utils/hooks';\nimport type { UnitControlProps, UnitControlOnChangeCallback } from './types';\nimport type { StateReducer } from '../input-control/reducer/state';\n\nfunction UnforwardedUnitControl(\n\tunitControlProps: WordPressComponentProps<\n\t\tUnitControlProps,\n\t\t'input',\n\t\tfalse\n\t>,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst {\n\t\t__unstableStateReducer: stateReducerProp,\n\t\tautoComplete = 'off',\n\t\tclassName,\n\t\tdisabled = false,\n\t\tdisableUnits = false,\n\t\tisPressEnterToChange = false,\n\t\tisResetValueOnUnitChange = false,\n\t\tisUnitSelectTabbable = true,\n\t\tlabel,\n\t\tonChange: onChangeProp,\n\t\tonUnitChange,\n\t\tsize = 'default',\n\t\tstyle,\n\t\tunit: unitProp,\n\t\tunits: unitsProp = CSS_UNITS,\n\t\tvalue: valueProp,\n\t\tonBlur: onBlurProp,\n\t\t...props\n\t} = unitControlProps;\n\n\tif ( 'unit' in unitControlProps ) {\n\t\tdeprecated( 'UnitControl unit prop', {\n\t\t\tsince: '5.6',\n\t\t\thint: 'The unit should be provided within the `value` prop.',\n\t\t\tversion: '6.2',\n\t\t} );\n\t}\n\n\t// The `value` prop, in theory, should not be `null`, but the following line\n\t// ensures it fallback to `undefined` in case a consumer of `UnitControl`\n\t// still passes `null` as a `value`.\n\tconst nonNullValueProp = valueProp ?? undefined;\n\tconst units = useMemo(\n\t\t() => getUnitsWithCurrentUnit( nonNullValueProp, unitProp, unitsProp ),\n\t\t[ nonNullValueProp, unitProp, unitsProp ]\n\t);\n\tconst [ parsedQuantity, parsedUnit ] = getParsedQuantityAndUnit(\n\t\tnonNullValueProp,\n\t\tunitProp,\n\t\tunits\n\t);\n\n\tconst [ unit, setUnit ] = useControlledState< string | undefined >(\n\t\tunits.length === 1 ? units[ 0 ].value : unitProp,\n\t\t{\n\t\t\tinitial: parsedUnit,\n\t\t\tfallback: '',\n\t\t}\n\t);\n\n\tuseEffect( () => {\n\t\tif ( parsedUnit !== undefined ) {\n\t\t\tsetUnit( parsedUnit );\n\t\t}\n\t}, [ parsedUnit ] );\n\n\t// Stores parsed value for hand-off in state reducer.\n\tconst refParsedQuantity = useRef< number | undefined >( undefined );\n\n\tconst classes = classnames( 'components-unit-control', className );\n\n\tconst handleOnQuantityChange = (\n\t\tnextQuantityValue: number | string | undefined,\n\t\tchangeProps: {\n\t\t\tevent:\n\t\t\t\t| ChangeEvent< HTMLInputElement >\n\t\t\t\t| PointerEvent< HTMLInputElement >;\n\t\t}\n\t) => {\n\t\tif (\n\t\t\tnextQuantityValue === '' ||\n\t\t\ttypeof nextQuantityValue === 'undefined' ||\n\t\t\tnextQuantityValue === null\n\t\t) {\n\t\t\tonChangeProp?.( '', changeProps );\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * Customizing the onChange callback.\n\t\t * This allows as to broadcast a combined value+unit to onChange.\n\t\t */\n\t\tconst onChangeValue = getValidParsedQuantityAndUnit(\n\t\t\tnextQuantityValue,\n\t\t\tunits,\n\t\t\tparsedQuantity,\n\t\t\tunit\n\t\t).join( '' );\n\n\t\tonChangeProp?.( onChangeValue, changeProps );\n\t};\n\n\tconst handleOnUnitChange: UnitControlOnChangeCallback = (\n\t\tnextUnitValue,\n\t\tchangeProps\n\t) => {\n\t\tconst { data } = changeProps;\n\n\t\tlet nextValue = `${ parsedQuantity ?? '' }${ nextUnitValue }`;\n\n\t\tif ( isResetValueOnUnitChange && data?.default !== undefined ) {\n\t\t\tnextValue = `${ data.default }${ nextUnitValue }`;\n\t\t}\n\n\t\tonChangeProp?.( nextValue, changeProps );\n\t\tonUnitChange?.( nextUnitValue, changeProps );\n\n\t\tsetUnit( nextUnitValue );\n\t};\n\n\tconst mayUpdateUnit = ( event: SyntheticEvent< HTMLInputElement > ) => {\n\t\tif ( ! isNaN( Number( event.currentTarget.value ) ) ) {\n\t\t\trefParsedQuantity.current = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst [\n\t\t\tvalidParsedQuantity,\n\t\t\tvalidParsedUnit,\n\t\t] = getValidParsedQuantityAndUnit(\n\t\t\tevent.currentTarget.value,\n\t\t\tunits,\n\t\t\tparsedQuantity,\n\t\t\tunit\n\t\t);\n\n\t\trefParsedQuantity.current = validParsedQuantity;\n\n\t\tif ( isPressEnterToChange && validParsedUnit !== unit ) {\n\t\t\tconst data = Array.isArray( units )\n\t\t\t\t? units.find( ( option ) => option.value === validParsedUnit )\n\t\t\t\t: undefined;\n\t\t\tconst changeProps = { event, data };\n\n\t\t\t// The `onChange` callback already gets called, no need to call it explicitely.\n\t\t\tonUnitChange?.( validParsedUnit, changeProps );\n\n\t\t\tsetUnit( validParsedUnit );\n\t\t}\n\t};\n\n\tconst handleOnBlur: FocusEventHandler< HTMLInputElement > = ( event ) => {\n\t\tmayUpdateUnit( event );\n\t\tonBlurProp?.( event );\n\t};\n\n\tconst handleOnKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\tconst { key } = event;\n\t\tif ( key === 'Enter' ) {\n\t\t\tmayUpdateUnit( event );\n\t\t}\n\t};\n\n\t/**\n\t * \"Middleware\" function that intercepts updates from InputControl.\n\t * This allows us to tap into actions to transform the (next) state for\n\t * InputControl.\n\t *\n\t * @param state State from InputControl\n\t * @param action Action triggering state change\n\t * @return The updated state to apply to InputControl\n\t */\n\tconst unitControlStateReducer: StateReducer = ( state, action ) => {\n\t\tconst nextState = { ...state };\n\n\t\t/*\n\t\t * On commits (when pressing ENTER and on blur if\n\t\t * isPressEnterToChange is true), if a parse has been performed\n\t\t * then use that result to update the state.\n\t\t */\n\t\tif ( action.type === inputControlActionTypes.COMMIT ) {\n\t\t\tif ( refParsedQuantity.current !== undefined ) {\n\t\t\t\tnextState.value = (\n\t\t\t\t\trefParsedQuantity.current ?? ''\n\t\t\t\t).toString();\n\t\t\t\trefParsedQuantity.current = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn nextState;\n\t};\n\n\tlet stateReducer: StateReducer = unitControlStateReducer;\n\tif ( stateReducerProp ) {\n\t\tstateReducer = ( state, action ) => {\n\t\t\tconst baseState = unitControlStateReducer( state, action );\n\t\t\treturn stateReducerProp( baseState, action );\n\t\t};\n\t}\n\n\tconst inputSuffix = ! disableUnits ? (\n\t\t<UnitSelectControl\n\t\t\taria-label={ __( 'Select unit' ) }\n\t\t\tdisabled={ disabled }\n\t\t\tisUnitSelectTabbable={ isUnitSelectTabbable }\n\t\t\tonChange={ handleOnUnitChange }\n\t\t\tsize={ size }\n\t\t\tunit={ unit }\n\t\t\tunits={ units }\n\t\t\tonBlur={ onBlurProp }\n\t\t/>\n\t) : null;\n\n\tlet step = props.step;\n\n\t/*\n\t * If no step prop has been passed, lookup the active unit and\n\t * try to get step from `units`, or default to a value of `1`\n\t */\n\tif ( ! step && units ) {\n\t\tconst activeUnit = units.find( ( option ) => option.value === unit );\n\t\tstep = activeUnit?.step ?? 1;\n\t}\n\n\treturn (\n\t\t<Root className=\"components-unit-control-wrapper\" style={ style }>\n\t\t\t<ValueInput\n\t\t\t\taria-label={ label }\n\t\t\t\ttype={ isPressEnterToChange ? 'text' : 'number' }\n\t\t\t\t{ ...omit( props, [ 'children' ] ) }\n\t\t\t\tautoComplete={ autoComplete }\n\t\t\t\tclassName={ classes }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\tdisableUnits={ disableUnits }\n\t\t\t\tisPressEnterToChange={ isPressEnterToChange }\n\t\t\t\tlabel={ label }\n\t\t\t\tonBlur={ handleOnBlur }\n\t\t\t\tonKeyDown={ handleOnKeyDown }\n\t\t\t\tonChange={ handleOnQuantityChange }\n\t\t\t\tref={ forwardedRef }\n\t\t\t\tsize={ size }\n\t\t\t\tsuffix={ inputSuffix }\n\t\t\t\tvalue={ parsedQuantity ?? '' }\n\t\t\t\tstep={ step }\n\t\t\t\t__unstableStateReducer={ stateReducer }\n\t\t\t/>\n\t\t</Root>\n\t);\n}\n\n/**\n * `UnitControl` allows the user to set a numeric quantity as well as a unit (e.g. `px`).\n *\n *\n * @example\n * ```jsx\n * import { __experimentalUnitControl as UnitControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const Example = () => {\n * const [ value, setValue ] = useState( '10px' );\n *\n * return <UnitControl onChange={ setValue } value={ value } />;\n * };\n * ```\n */\nexport const UnitControl = forwardRef( UnforwardedUnitControl );\n\nexport { parseQuantityAndUnitFromRawValue, useCustomUnits } from './utils';\nexport default UnitControl;\n"]}
|