@wordpress/components 28.0.3 → 28.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +133 -120
- package/build/custom-select-control-v2/custom-select.js +1 -3
- package/build/custom-select-control-v2/custom-select.js.map +1 -1
- package/build/custom-select-control-v2/legacy-component/index.js +16 -10
- package/build/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build/custom-select-control-v2/styles.js +34 -19
- package/build/custom-select-control-v2/styles.js.map +1 -1
- package/build/custom-select-control-v2/types.js.map +1 -1
- package/build/drop-zone/index.js +16 -79
- package/build/drop-zone/index.js.map +1 -1
- package/build/radio-control/index.js +1 -1
- package/build/radio-control/index.js.map +1 -1
- package/build-module/custom-select-control-v2/custom-select.js +1 -3
- package/build-module/custom-select-control-v2/custom-select.js.map +1 -1
- package/build-module/custom-select-control-v2/legacy-component/index.js +16 -11
- package/build-module/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build-module/custom-select-control-v2/styles.js +33 -18
- package/build-module/custom-select-control-v2/styles.js.map +1 -1
- package/build-module/custom-select-control-v2/types.js.map +1 -1
- package/build-module/drop-zone/index.js +17 -80
- package/build-module/drop-zone/index.js.map +1 -1
- package/build-module/radio-control/index.js +1 -1
- package/build-module/radio-control/index.js.map +1 -1
- package/build-style/style-rtl.css +30 -5
- package/build-style/style.css +30 -5
- package/build-types/checkbox-control/stories/index.story.d.ts.map +1 -1
- package/build-types/custom-select-control/stories/index.story.d.ts +15 -0
- package/build-types/custom-select-control/stories/index.story.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/legacy-component/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/styles.d.ts +4 -0
- package/build-types/custom-select-control-v2/styles.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/types.d.ts +1 -0
- package/build-types/custom-select-control-v2/types.d.ts.map +1 -1
- package/build-types/drop-zone/index.d.ts +3 -0
- package/build-types/drop-zone/index.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/checkbox-control/stories/index.story.tsx +3 -0
- package/src/checkbox-control/style.scss +4 -2
- package/src/custom-select-control/stories/index.story.tsx +32 -3
- package/src/custom-select-control/test/index.js +205 -22
- package/src/custom-select-control-v2/custom-select.tsx +1 -1
- package/src/custom-select-control-v2/legacy-component/index.tsx +18 -10
- package/src/custom-select-control-v2/legacy-component/test/index.tsx +220 -38
- package/src/custom-select-control-v2/styles.ts +22 -10
- package/src/custom-select-control-v2/types.ts +1 -0
- package/src/drop-zone/index.tsx +17 -76
- package/src/drop-zone/style.scss +51 -16
- package/src/radio-control/index.tsx +1 -1
- package/src/radio-control/style.scss +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/components/src/custom-select-control-v2/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type * as Ariakit from '@ariakit/react';\nimport type { FocusEventHandler, MouseEventHandler } from 'react';\n\nexport type CustomSelectStore = {\n\t/**\n\t * The store object returned by Ariakit's `useSelectStore` hook.\n\t */\n\tstore: Ariakit.SelectStore;\n};\n\nexport type CustomSelectContext = CustomSelectStore | undefined;\n\ntype CustomSelectSize< Size = 'compact' | 'default' > = {\n\t/**\n\t * The size of the control.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: Size;\n};\n\nexport type CustomSelectButtonSize = CustomSelectSize<\n\t'compact' | 'default' | 'small'\n>;\n\nexport type CustomSelectButtonProps = {\n\t/**\n\t * An optional default value for the control when used in uncontrolled mode.\n\t * If left `undefined`, the first non-disabled item will be used.\n\t */\n\tdefaultValue?: string | string[];\n\t/**\n\t * A function that receives the new value of the input.\n\t */\n\tonChange?: ( newValue: string | string[] ) => void;\n\t/**\n\t * Can be used to render select UI with custom styled values.\n\t */\n\trenderSelectedValue?: (\n\t\tselectedValue: string | string[]\n\t) => React.ReactNode;\n\t/**\n\t * The value of the control when used in uncontrolled mode.\n\t */\n\tvalue?: string | string[];\n};\n\nexport type _CustomSelectProps = CustomSelectButtonProps & {\n\t/**\n\t * The child elements. This should be composed of `CustomSelectItem` components.\n\t */\n\tchildren: React.ReactNode;\n\t/**\n\t * Used to visually hide the label. It will always be visible to screen readers.\n\t *\n\t * @default false\n\t */\n\thideLabelFromVision?: boolean;\n\t/**\n\t * Accessible label for the control.\n\t */\n\tlabel: string;\n};\n\nexport type CustomSelectProps = _CustomSelectProps &\n\tCustomSelectButtonProps &\n\tCustomSelectSize;\n\n/**\n * The legacy object structure for the options array.\n */\ntype LegacyOption = {\n\tkey: string;\n\tname: string;\n\tstyle?: React.CSSProperties;\n\tclassName?: string;\n\t__experimentalHint?: string;\n};\n\n/**\n * The legacy object returned from the onChange event.\n */\ntype LegacyOnChangeObject = {\n\thighlightedIndex?: number;\n\tinputValue?: string;\n\tisOpen?: boolean;\n\ttype?: string;\n\tselectedItem: LegacyOption;\n};\n\nexport type LegacyCustomSelectProps = {\n\t/**\n\t * Optional classname for the component.\n\t */\n\tclassName?: string;\n\t/**\n\t * Used to visually hide the label. It will always be visible to screen readers.\n\t *\n\t */\n\thideLabelFromVision?: boolean;\n\t/**\n\t * Pass in a description that will be shown to screen readers associated with the\n\t * select trigger button. If no value is passed, the text \"Currently selected:\n\t * selectedItem.name\" will be used fully translated.\n\t */\n\tdescribedBy?: string;\n\t/**\n\t * Label for the control.\n\t */\n\tlabel: string;\n\t/**\n\t * Function called with the control's internal state changes. The `selectedItem`\n\t * property contains the next selected item.\n\t */\n\tonChange?: ( newValue: LegacyOnChangeObject ) => void;\n\t/**\n\t * A handler for `onBlur` events.\n\t *\n\t * @ignore\n\t */\n\tonBlur?: FocusEventHandler< HTMLButtonElement >;\n\t/**\n\t * A handler for `onFocus` events.\n\t *\n\t * @ignore\n\t */\n\tonFocus?: FocusEventHandler< HTMLButtonElement >;\n\t/**\n\t * A handler for `onMouseOver` events.\n\t *\n\t * @ignore\n\t */\n\tonMouseOut?: MouseEventHandler< HTMLButtonElement >;\n\t/**\n\t * A handler for `onMouseOut` events.\n\t *\n\t * @ignore\n\t */\n\tonMouseOver?: MouseEventHandler< HTMLButtonElement >;\n\t/**\n\t * The options that can be chosen from.\n\t */\n\toptions: Array< LegacyOption >;\n\t/**\n\t * The size of the control.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: 'default' | 'small' | '__unstable-large';\n\t/**\n\t * Can be used to externally control the value of the control.\n\t */\n\tvalue?: LegacyOption;\n\t/**\n\t * Legacy way to add additional text to the right of each option.\n\t *\n\t * @default false\n\t */\n\t__experimentalShowSelectedHint?: boolean;\n\t/**\n\t * Opt-in prop for an unconstrained width style which became the default in\n\t * WordPress 6.5. The prop is no longer needed and can be safely removed.\n\t *\n\t * @deprecated\n\t * @ignore\n\t */\n\t__nextUnconstrainedWidth?: boolean;\n\t/**\n\t * Start opting into the larger default height that will become the default size in a future version.\n\t *\n\t * @default false\n\t */\n\t__next40pxDefaultSize?: boolean;\n};\n\nexport type CustomSelectItemProps = {\n\t/**\n\t * The value of the select item. This will be used as the children if\n\t * children are left `undefined`.\n\t */\n\tvalue: string;\n\t/**\n\t * The children to display for each select item. The `value` will be\n\t * used if left `undefined`.\n\t */\n\tchildren?: React.ReactNode;\n\t/**\n\t * If true, the item will be disabled.\n\t *\n\t * You will need to add your own styles (e.g. reduced opacity) to visually show that they are disabled.\n\t * @default false\n\t */\n\tdisabled?: boolean;\n};\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/components/src/custom-select-control-v2/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type * as Ariakit from '@ariakit/react';\nimport type { FocusEventHandler, MouseEventHandler } from 'react';\n\nexport type CustomSelectStore = {\n\t/**\n\t * The store object returned by Ariakit's `useSelectStore` hook.\n\t */\n\tstore: Ariakit.SelectStore;\n};\n\nexport type CustomSelectContext = CustomSelectStore | undefined;\n\ntype CustomSelectSize< Size = 'compact' | 'default' > = {\n\t/**\n\t * The size of the control.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: Size;\n};\n\nexport type CustomSelectButtonSize = CustomSelectSize<\n\t'compact' | 'default' | 'small'\n>;\n\nexport type CustomSelectButtonProps = {\n\t/**\n\t * An optional default value for the control when used in uncontrolled mode.\n\t * If left `undefined`, the first non-disabled item will be used.\n\t */\n\tdefaultValue?: string | string[];\n\t/**\n\t * A function that receives the new value of the input.\n\t */\n\tonChange?: ( newValue: string | string[] ) => void;\n\t/**\n\t * Can be used to render select UI with custom styled values.\n\t */\n\trenderSelectedValue?: (\n\t\tselectedValue: string | string[]\n\t) => React.ReactNode;\n\t/**\n\t * The value of the control when used in uncontrolled mode.\n\t */\n\tvalue?: string | string[];\n};\n\nexport type _CustomSelectProps = CustomSelectButtonProps & {\n\t/**\n\t * The child elements. This should be composed of `CustomSelectItem` components.\n\t */\n\tchildren: React.ReactNode;\n\t/**\n\t * Used to visually hide the label. It will always be visible to screen readers.\n\t *\n\t * @default false\n\t */\n\thideLabelFromVision?: boolean;\n\t/**\n\t * Accessible label for the control.\n\t */\n\tlabel: string;\n};\n\nexport type CustomSelectProps = _CustomSelectProps &\n\tCustomSelectButtonProps &\n\tCustomSelectSize;\n\n/**\n * The legacy object structure for the options array.\n */\ntype LegacyOption = {\n\tkey: string;\n\tname: string;\n\tstyle?: React.CSSProperties;\n\tclassName?: string;\n\t__experimentalHint?: string;\n\t[ key: string ]: any;\n};\n\n/**\n * The legacy object returned from the onChange event.\n */\ntype LegacyOnChangeObject = {\n\thighlightedIndex?: number;\n\tinputValue?: string;\n\tisOpen?: boolean;\n\ttype?: string;\n\tselectedItem: LegacyOption;\n};\n\nexport type LegacyCustomSelectProps = {\n\t/**\n\t * Optional classname for the component.\n\t */\n\tclassName?: string;\n\t/**\n\t * Used to visually hide the label. It will always be visible to screen readers.\n\t *\n\t */\n\thideLabelFromVision?: boolean;\n\t/**\n\t * Pass in a description that will be shown to screen readers associated with the\n\t * select trigger button. If no value is passed, the text \"Currently selected:\n\t * selectedItem.name\" will be used fully translated.\n\t */\n\tdescribedBy?: string;\n\t/**\n\t * Label for the control.\n\t */\n\tlabel: string;\n\t/**\n\t * Function called with the control's internal state changes. The `selectedItem`\n\t * property contains the next selected item.\n\t */\n\tonChange?: ( newValue: LegacyOnChangeObject ) => void;\n\t/**\n\t * A handler for `onBlur` events.\n\t *\n\t * @ignore\n\t */\n\tonBlur?: FocusEventHandler< HTMLButtonElement >;\n\t/**\n\t * A handler for `onFocus` events.\n\t *\n\t * @ignore\n\t */\n\tonFocus?: FocusEventHandler< HTMLButtonElement >;\n\t/**\n\t * A handler for `onMouseOver` events.\n\t *\n\t * @ignore\n\t */\n\tonMouseOut?: MouseEventHandler< HTMLButtonElement >;\n\t/**\n\t * A handler for `onMouseOut` events.\n\t *\n\t * @ignore\n\t */\n\tonMouseOver?: MouseEventHandler< HTMLButtonElement >;\n\t/**\n\t * The options that can be chosen from.\n\t */\n\toptions: Array< LegacyOption >;\n\t/**\n\t * The size of the control.\n\t *\n\t * @default 'default'\n\t */\n\tsize?: 'default' | 'small' | '__unstable-large';\n\t/**\n\t * Can be used to externally control the value of the control.\n\t */\n\tvalue?: LegacyOption;\n\t/**\n\t * Legacy way to add additional text to the right of each option.\n\t *\n\t * @default false\n\t */\n\t__experimentalShowSelectedHint?: boolean;\n\t/**\n\t * Opt-in prop for an unconstrained width style which became the default in\n\t * WordPress 6.5. The prop is no longer needed and can be safely removed.\n\t *\n\t * @deprecated\n\t * @ignore\n\t */\n\t__nextUnconstrainedWidth?: boolean;\n\t/**\n\t * Start opting into the larger default height that will become the default size in a future version.\n\t *\n\t * @default false\n\t */\n\t__next40pxDefaultSize?: boolean;\n};\n\nexport type CustomSelectItemProps = {\n\t/**\n\t * The value of the select item. This will be used as the children if\n\t * children are left `undefined`.\n\t */\n\tvalue: string;\n\t/**\n\t * The children to display for each select item. The `value` will be\n\t * used if left `undefined`.\n\t */\n\tchildren?: React.ReactNode;\n\t/**\n\t * If true, the item will be disabled.\n\t *\n\t * You will need to add your own styles (e.g. reduced opacity) to visually show that they are disabled.\n\t * @default false\n\t */\n\tdisabled?: boolean;\n};\n"],"mappings":"","ignoreList":[]}
|
package/build/drop-zone/index.js
CHANGED
|
@@ -12,7 +12,6 @@ var _element = require("@wordpress/element");
|
|
|
12
12
|
var _icons = require("@wordpress/icons");
|
|
13
13
|
var _dom = require("@wordpress/dom");
|
|
14
14
|
var _compose = require("@wordpress/compose");
|
|
15
|
-
var _animation = require("../animation");
|
|
16
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
16
|
/**
|
|
18
17
|
* External dependencies
|
|
@@ -26,80 +25,6 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
26
25
|
* Internal dependencies
|
|
27
26
|
*/
|
|
28
27
|
|
|
29
|
-
const backdrop = {
|
|
30
|
-
hidden: {
|
|
31
|
-
opacity: 0
|
|
32
|
-
},
|
|
33
|
-
show: {
|
|
34
|
-
opacity: 1,
|
|
35
|
-
transition: {
|
|
36
|
-
type: 'tween',
|
|
37
|
-
duration: 0.2,
|
|
38
|
-
delay: 0,
|
|
39
|
-
delayChildren: 0.1
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
exit: {
|
|
43
|
-
opacity: 0,
|
|
44
|
-
transition: {
|
|
45
|
-
duration: 0.2,
|
|
46
|
-
delayChildren: 0
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const foreground = {
|
|
51
|
-
hidden: {
|
|
52
|
-
opacity: 0,
|
|
53
|
-
scale: 0.9
|
|
54
|
-
},
|
|
55
|
-
show: {
|
|
56
|
-
opacity: 1,
|
|
57
|
-
scale: 1,
|
|
58
|
-
transition: {
|
|
59
|
-
duration: 0.1
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
exit: {
|
|
63
|
-
opacity: 0,
|
|
64
|
-
scale: 0.9
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
function DropIndicator({
|
|
68
|
-
label
|
|
69
|
-
}) {
|
|
70
|
-
const disableMotion = (0, _compose.useReducedMotion)();
|
|
71
|
-
const children = /*#__PURE__*/(0, _jsxRuntime.jsx)(_animation.__unstableMotion.div, {
|
|
72
|
-
variants: backdrop,
|
|
73
|
-
initial: disableMotion ? 'show' : 'hidden',
|
|
74
|
-
animate: "show",
|
|
75
|
-
exit: disableMotion ? 'show' : 'exit',
|
|
76
|
-
className: "components-drop-zone__content"
|
|
77
|
-
// Without this, when this div is shown,
|
|
78
|
-
// Safari calls a onDropZoneLeave causing a loop because of this bug
|
|
79
|
-
// https://bugs.webkit.org/show_bug.cgi?id=66547
|
|
80
|
-
,
|
|
81
|
-
style: {
|
|
82
|
-
pointerEvents: 'none'
|
|
83
|
-
},
|
|
84
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_animation.__unstableMotion.div, {
|
|
85
|
-
variants: foreground,
|
|
86
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
|
|
87
|
-
icon: _icons.upload,
|
|
88
|
-
className: "components-drop-zone__content-icon"
|
|
89
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
90
|
-
className: "components-drop-zone__content-text",
|
|
91
|
-
children: label ? label : (0, _i18n.__)('Drop files to upload')
|
|
92
|
-
})]
|
|
93
|
-
})
|
|
94
|
-
});
|
|
95
|
-
if (disableMotion) {
|
|
96
|
-
return children;
|
|
97
|
-
}
|
|
98
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_animation.__unstableAnimatePresence, {
|
|
99
|
-
children: children
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
28
|
/**
|
|
104
29
|
* `DropZone` is a component creating a drop zone area taking the full size of its parent element. It supports dropping files, HTML content or any other HTML drop event.
|
|
105
30
|
*
|
|
@@ -141,7 +66,7 @@ function DropZoneComponent({
|
|
|
141
66
|
|
|
142
67
|
/**
|
|
143
68
|
* From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.
|
|
144
|
-
* The order of the checks is important to
|
|
69
|
+
* The order of the checks is important to recognize the HTML drop.
|
|
145
70
|
*/
|
|
146
71
|
if (html && onHTMLDrop) {
|
|
147
72
|
onHTMLDrop(html);
|
|
@@ -157,7 +82,7 @@ function DropZoneComponent({
|
|
|
157
82
|
|
|
158
83
|
/**
|
|
159
84
|
* From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.
|
|
160
|
-
* The order of the checks is important to
|
|
85
|
+
* The order of the checks is important to recognize the HTML drop.
|
|
161
86
|
*/
|
|
162
87
|
if (event.dataTransfer?.types.includes('text/html')) {
|
|
163
88
|
_type = 'html';
|
|
@@ -182,6 +107,8 @@ function DropZoneComponent({
|
|
|
182
107
|
});
|
|
183
108
|
const classes = (0, _clsx.default)('components-drop-zone', className, {
|
|
184
109
|
'is-active': (isDraggingOverDocument || isDraggingOverElement) && (type === 'file' && onFilesDrop || type === 'html' && onHTMLDrop || type === 'default' && onDrop),
|
|
110
|
+
'has-dragged-out': !isDraggingOverElement,
|
|
111
|
+
// Keeping the following classnames for legacy purposes
|
|
185
112
|
'is-dragging-over-document': isDraggingOverDocument,
|
|
186
113
|
'is-dragging-over-element': isDraggingOverElement,
|
|
187
114
|
[`is-dragging-${type}`]: !!type
|
|
@@ -190,8 +117,18 @@ function DropZoneComponent({
|
|
|
190
117
|
...restProps,
|
|
191
118
|
ref: ref,
|
|
192
119
|
className: classes,
|
|
193
|
-
children:
|
|
194
|
-
|
|
120
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
121
|
+
className: "components-drop-zone__content",
|
|
122
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
123
|
+
className: "components-drop-zone__content-inner",
|
|
124
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
|
|
125
|
+
icon: _icons.upload,
|
|
126
|
+
className: "components-drop-zone__content-icon"
|
|
127
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
128
|
+
className: "components-drop-zone__content-text",
|
|
129
|
+
children: label ? label : (0, _i18n.__)('Drop files to upload')
|
|
130
|
+
})]
|
|
131
|
+
})
|
|
195
132
|
})
|
|
196
133
|
});
|
|
197
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_i18n","_element","_icons","_dom","_compose","_animation","_jsxRuntime","backdrop","hidden","opacity","show","transition","type","duration","delay","delayChildren","exit","foreground","scale","DropIndicator","label","disableMotion","useReducedMotion","children","jsx","__unstableMotion","div","variants","initial","animate","className","style","pointerEvents","jsxs","Icon","icon","upload","__","__unstableAnimatePresence","DropZoneComponent","onFilesDrop","onHTMLDrop","onDrop","restProps","isDraggingOverDocument","setIsDraggingOverDocument","useState","isDraggingOverElement","setIsDraggingOverElement","setType","ref","useDropZone","event","files","dataTransfer","getFilesFromDataTransfer","html","getData","length","onDragStart","_type","types","includes","onDragEnd","undefined","onDragEnter","onDragLeave","classes","clsx","_default","exports","default"],"sources":["@wordpress/components/src/drop-zone/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { upload, Icon } from '@wordpress/icons';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\nimport {\n\t__experimentalUseDropZone as useDropZone,\n\tuseReducedMotion,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '../animation';\nimport type { DropType, DropZoneProps } from './types';\nimport type { WordPressComponentProps } from '../context';\n\nconst backdrop = {\n\thidden: { opacity: 0 },\n\tshow: {\n\t\topacity: 1,\n\t\ttransition: {\n\t\t\ttype: 'tween',\n\t\t\tduration: 0.2,\n\t\t\tdelay: 0,\n\t\t\tdelayChildren: 0.1,\n\t\t},\n\t},\n\texit: {\n\t\topacity: 0,\n\t\ttransition: {\n\t\t\tduration: 0.2,\n\t\t\tdelayChildren: 0,\n\t\t},\n\t},\n};\n\nconst foreground = {\n\thidden: { opacity: 0, scale: 0.9 },\n\tshow: {\n\t\topacity: 1,\n\t\tscale: 1,\n\t\ttransition: {\n\t\t\tduration: 0.1,\n\t\t},\n\t},\n\texit: { opacity: 0, scale: 0.9 },\n};\n\nfunction DropIndicator( { label }: { label?: string } ) {\n\tconst disableMotion = useReducedMotion();\n\tconst children = (\n\t\t<motion.div\n\t\t\tvariants={ backdrop }\n\t\t\tinitial={ disableMotion ? 'show' : 'hidden' }\n\t\t\tanimate=\"show\"\n\t\t\texit={ disableMotion ? 'show' : 'exit' }\n\t\t\tclassName=\"components-drop-zone__content\"\n\t\t\t// Without this, when this div is shown,\n\t\t\t// Safari calls a onDropZoneLeave causing a loop because of this bug\n\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=66547\n\t\t\tstyle={ { pointerEvents: 'none' } }\n\t\t>\n\t\t\t<motion.div variants={ foreground }>\n\t\t\t\t<Icon\n\t\t\t\t\ticon={ upload }\n\t\t\t\t\tclassName=\"components-drop-zone__content-icon\"\n\t\t\t\t/>\n\t\t\t\t<span className=\"components-drop-zone__content-text\">\n\t\t\t\t\t{ label ? label : __( 'Drop files to upload' ) }\n\t\t\t\t</span>\n\t\t\t</motion.div>\n\t\t</motion.div>\n\t);\n\n\tif ( disableMotion ) {\n\t\treturn children;\n\t}\n\n\treturn <AnimatePresence>{ children }</AnimatePresence>;\n}\n\n/**\n * `DropZone` is a component creating a drop zone area taking the full size of its parent element. It supports dropping files, HTML content or any other HTML drop event.\n *\n * ```jsx\n * import { DropZone } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyDropZone = () => {\n * const [ hasDropped, setHasDropped ] = useState( false );\n *\n * return (\n * <div>\n * { hasDropped ? 'Dropped!' : 'Drop something here' }\n * <DropZone\n * onFilesDrop={ () => setHasDropped( true ) }\n * onHTMLDrop={ () => setHasDropped( true ) }\n * onDrop={ () => setHasDropped( true ) }\n * />\n * </div>\n * );\n * }\n * ```\n */\nexport function DropZoneComponent( {\n\tclassName,\n\tlabel,\n\tonFilesDrop,\n\tonHTMLDrop,\n\tonDrop,\n\t...restProps\n}: WordPressComponentProps< DropZoneProps, 'div', false > ) {\n\tconst [ isDraggingOverDocument, setIsDraggingOverDocument ] =\n\t\tuseState< boolean >();\n\tconst [ isDraggingOverElement, setIsDraggingOverElement ] =\n\t\tuseState< boolean >();\n\tconst [ type, setType ] = useState< DropType >();\n\tconst ref = useDropZone( {\n\t\tonDrop( event ) {\n\t\t\tconst files = event.dataTransfer\n\t\t\t\t? getFilesFromDataTransfer( event.dataTransfer )\n\t\t\t\t: [];\n\t\t\tconst html = event.dataTransfer?.getData( 'text/html' );\n\n\t\t\t/**\n\t\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t\t */\n\t\t\tif ( html && onHTMLDrop ) {\n\t\t\t\tonHTMLDrop( html );\n\t\t\t} else if ( files.length && onFilesDrop ) {\n\t\t\t\tonFilesDrop( files );\n\t\t\t} else if ( onDrop ) {\n\t\t\t\tonDrop( event );\n\t\t\t}\n\t\t},\n\t\tonDragStart( event ) {\n\t\t\tsetIsDraggingOverDocument( true );\n\n\t\t\tlet _type: DropType = 'default';\n\n\t\t\t/**\n\t\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t\t */\n\t\t\tif ( event.dataTransfer?.types.includes( 'text/html' ) ) {\n\t\t\t\t_type = 'html';\n\t\t\t} else if (\n\t\t\t\t// Check for the types because sometimes the files themselves\n\t\t\t\t// are only available on drop.\n\t\t\t\tevent.dataTransfer?.types.includes( 'Files' ) ||\n\t\t\t\t( event.dataTransfer\n\t\t\t\t\t? getFilesFromDataTransfer( event.dataTransfer )\n\t\t\t\t\t: []\n\t\t\t\t).length > 0\n\t\t\t) {\n\t\t\t\t_type = 'file';\n\t\t\t}\n\n\t\t\tsetType( _type );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tsetIsDraggingOverDocument( false );\n\t\t\tsetType( undefined );\n\t\t},\n\t\tonDragEnter() {\n\t\t\tsetIsDraggingOverElement( true );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tsetIsDraggingOverElement( false );\n\t\t},\n\t} );\n\tconst classes = clsx( 'components-drop-zone', className, {\n\t\t'is-active':\n\t\t\t( isDraggingOverDocument || isDraggingOverElement ) &&\n\t\t\t( ( type === 'file' && onFilesDrop ) ||\n\t\t\t\t( type === 'html' && onHTMLDrop ) ||\n\t\t\t\t( type === 'default' && onDrop ) ),\n\t\t'is-dragging-over-document': isDraggingOverDocument,\n\t\t'is-dragging-over-element': isDraggingOverElement,\n\t\t[ `is-dragging-${ type }` ]: !! type,\n\t} );\n\n\treturn (\n\t\t<div { ...restProps } ref={ ref } className={ classes }>\n\t\t\t{ isDraggingOverElement && <DropIndicator label={ label } /> }\n\t\t</div>\n\t);\n}\n\nexport default DropZoneComponent;\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAQA,IAAAM,UAAA,GAAAN,OAAA;AAGsB,IAAAO,WAAA,GAAAP,OAAA;AAvBtB;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;;AAQA,MAAMQ,QAAQ,GAAG;EAChBC,MAAM,EAAE;IAAEC,OAAO,EAAE;EAAE,CAAC;EACtBC,IAAI,EAAE;IACLD,OAAO,EAAE,CAAC;IACVE,UAAU,EAAE;MACXC,IAAI,EAAE,OA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eAAenC,IAAM,EAAC,GAAI,CAAC,CAAEA;EACjC,CAAE,CAAC;EAEH,oBACC,IAAAN,WAAA,CAAAkB,GAAA;IAAA,GAAUmB,SAAS;IAAGO,GAAG,EAAGA,GAAK;IAACpB,SAAS,EAAGqC,OAAS;IAAA5C,QAAA,EACpDwB,qBAAqB,iBAAI,IAAAzC,WAAA,CAAAkB,GAAA,EAACL,aAAa;MAACC,KAAK,EAAGA;IAAO,CAAE;EAAC,CACxD,CAAC;AAER;AAAC,IAAAiD,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEchC,iBAAiB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_i18n","_element","_icons","_dom","_compose","_jsxRuntime","DropZoneComponent","className","label","onFilesDrop","onHTMLDrop","onDrop","restProps","isDraggingOverDocument","setIsDraggingOverDocument","useState","isDraggingOverElement","setIsDraggingOverElement","type","setType","ref","useDropZone","event","files","dataTransfer","getFilesFromDataTransfer","html","getData","length","onDragStart","_type","types","includes","onDragEnd","undefined","onDragEnter","onDragLeave","classes","clsx","jsx","children","jsxs","Icon","icon","upload","__","_default","exports","default"],"sources":["@wordpress/components/src/drop-zone/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { upload, Icon } from '@wordpress/icons';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\nimport { __experimentalUseDropZone as useDropZone } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport type { DropType, DropZoneProps } from './types';\nimport type { WordPressComponentProps } from '../context';\n\n/**\n * `DropZone` is a component creating a drop zone area taking the full size of its parent element. It supports dropping files, HTML content or any other HTML drop event.\n *\n * ```jsx\n * import { DropZone } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyDropZone = () => {\n * const [ hasDropped, setHasDropped ] = useState( false );\n *\n * return (\n * <div>\n * { hasDropped ? 'Dropped!' : 'Drop something here' }\n * <DropZone\n * onFilesDrop={ () => setHasDropped( true ) }\n * onHTMLDrop={ () => setHasDropped( true ) }\n * onDrop={ () => setHasDropped( true ) }\n * />\n * </div>\n * );\n * }\n * ```\n */\nexport function DropZoneComponent( {\n\tclassName,\n\tlabel,\n\tonFilesDrop,\n\tonHTMLDrop,\n\tonDrop,\n\t...restProps\n}: WordPressComponentProps< DropZoneProps, 'div', false > ) {\n\tconst [ isDraggingOverDocument, setIsDraggingOverDocument ] =\n\t\tuseState< boolean >();\n\tconst [ isDraggingOverElement, setIsDraggingOverElement ] =\n\t\tuseState< boolean >();\n\tconst [ type, setType ] = useState< DropType >();\n\tconst ref = useDropZone( {\n\t\tonDrop( event ) {\n\t\t\tconst files = event.dataTransfer\n\t\t\t\t? getFilesFromDataTransfer( event.dataTransfer )\n\t\t\t\t: [];\n\t\t\tconst html = event.dataTransfer?.getData( 'text/html' );\n\n\t\t\t/**\n\t\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t\t * The order of the checks is important to recognize the HTML drop.\n\t\t\t */\n\t\t\tif ( html && onHTMLDrop ) {\n\t\t\t\tonHTMLDrop( html );\n\t\t\t} else if ( files.length && onFilesDrop ) {\n\t\t\t\tonFilesDrop( files );\n\t\t\t} else if ( onDrop ) {\n\t\t\t\tonDrop( event );\n\t\t\t}\n\t\t},\n\t\tonDragStart( event ) {\n\t\t\tsetIsDraggingOverDocument( true );\n\n\t\t\tlet _type: DropType = 'default';\n\n\t\t\t/**\n\t\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t\t * The order of the checks is important to recognize the HTML drop.\n\t\t\t */\n\t\t\tif ( event.dataTransfer?.types.includes( 'text/html' ) ) {\n\t\t\t\t_type = 'html';\n\t\t\t} else if (\n\t\t\t\t// Check for the types because sometimes the files themselves\n\t\t\t\t// are only available on drop.\n\t\t\t\tevent.dataTransfer?.types.includes( 'Files' ) ||\n\t\t\t\t( event.dataTransfer\n\t\t\t\t\t? getFilesFromDataTransfer( event.dataTransfer )\n\t\t\t\t\t: []\n\t\t\t\t).length > 0\n\t\t\t) {\n\t\t\t\t_type = 'file';\n\t\t\t}\n\n\t\t\tsetType( _type );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tsetIsDraggingOverDocument( false );\n\t\t\tsetType( undefined );\n\t\t},\n\t\tonDragEnter() {\n\t\t\tsetIsDraggingOverElement( true );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tsetIsDraggingOverElement( false );\n\t\t},\n\t} );\n\n\tconst classes = clsx( 'components-drop-zone', className, {\n\t\t'is-active':\n\t\t\t( isDraggingOverDocument || isDraggingOverElement ) &&\n\t\t\t( ( type === 'file' && onFilesDrop ) ||\n\t\t\t\t( type === 'html' && onHTMLDrop ) ||\n\t\t\t\t( type === 'default' && onDrop ) ),\n\t\t'has-dragged-out': ! isDraggingOverElement,\n\t\t// Keeping the following classnames for legacy purposes\n\t\t'is-dragging-over-document': isDraggingOverDocument,\n\t\t'is-dragging-over-element': isDraggingOverElement,\n\t\t[ `is-dragging-${ type }` ]: !! type,\n\t} );\n\n\treturn (\n\t\t<div { ...restProps } ref={ ref } className={ classes }>\n\t\t\t<div className=\"components-drop-zone__content\">\n\t\t\t\t<div className=\"components-drop-zone__content-inner\">\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={ upload }\n\t\t\t\t\t\tclassName=\"components-drop-zone__content-icon\"\n\t\t\t\t\t/>\n\t\t\t\t\t<span className=\"components-drop-zone__content-text\">\n\t\t\t\t\t\t{ label ? label : __( 'Drop files to upload' ) }\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default DropZoneComponent;\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,I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,GAAG,EAAGA,GAAK;IAACb,SAAS,EAAG8B,OAAS;IAAAG,QAAA,eACtD,IAAAnC,WAAA,CAAAkC,GAAA;MAAKhC,SAAS,EAAC,+BAA+B;MAAAiC,QAAA,eAC7C,IAAAnC,WAAA,CAAAoC,IAAA;QAAKlC,SAAS,EAAC,qCAAqC;QAAAiC,QAAA,gBACnD,IAAAnC,WAAA,CAAAkC,GAAA,EAACrC,MAAA,CAAAwC,IAAI;UACJC,IAAI,EAAGC,aAAQ;UACfrC,SAAS,EAAC;QAAoC,CAC9C,CAAC,eACF,IAAAF,WAAA,CAAAkC,GAAA;UAAMhC,SAAS,EAAC,oCAAoC;UAAAiC,QAAA,EACjDhC,KAAK,GAAGA,KAAK,GAAG,IAAAqC,QAAE,EAAE,sBAAuB;QAAC,CACzC,CAAC;MAAA,CACH;IAAC,CACF;EAAC,CACF,CAAC;AAER;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc1C,iBAAiB","ignoreList":[]}
|
|
@@ -73,7 +73,7 @@ function RadioControl(props) {
|
|
|
73
73
|
help: help,
|
|
74
74
|
className: (0, _clsx.default)(className, 'components-radio-control'),
|
|
75
75
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vStack.VStack, {
|
|
76
|
-
spacing:
|
|
76
|
+
spacing: 3,
|
|
77
77
|
children: options.map((option, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
78
78
|
className: "components-radio-control__option",
|
|
79
79
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_compose","_baseControl","_vStack","_jsxRuntime","RadioControl","props","label","className","selected","help","onChange","hideLabelFromVision","options","additionalProps","instanceId","useInstanceId","id","onChangeValue","event","target","value","length","jsx","default","__nextHasNoMarginBottom","clsx","children","VStack","spacing","map","option","index","jsxs","type","name","checked","undefined","htmlFor","_default","exports"],"sources":["@wordpress/components/src/radio-control/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ChangeEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '../base-control';\nimport type { WordPressComponentProps } from '../context';\nimport type { RadioControlProps } from './types';\nimport { VStack } from '../v-stack';\n\n/**\n * Render a user interface to select the user type using radio inputs.\n *\n * ```jsx\n * import { RadioControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyRadioControl = () => {\n * const [ option, setOption ] = useState( 'a' );\n *\n * return (\n * <RadioControl\n * label=\"User type\"\n * help=\"The type of the current user\"\n * selected={ option }\n * options={ [\n * { label: 'Author', value: 'a' },\n * { label: 'Editor', value: 'e' },\n * ] }\n * onChange={ ( value ) => setOption( value ) }\n * />\n * );\n * };\n * ```\n */\nexport function RadioControl(\n\tprops: WordPressComponentProps< RadioControlProps, 'input', false >\n) {\n\tconst {\n\t\tlabel,\n\t\tclassName,\n\t\tselected,\n\t\thelp,\n\t\tonChange,\n\t\thideLabelFromVision,\n\t\toptions = [],\n\t\t...additionalProps\n\t} = props;\n\tconst instanceId = useInstanceId( RadioControl );\n\tconst id = `inspector-radio-control-${ instanceId }`;\n\tconst onChangeValue = ( event: ChangeEvent< HTMLInputElement > ) =>\n\t\tonChange( event.target.value );\n\n\tif ( ! options?.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BaseControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ label }\n\t\t\tid={ id }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\thelp={ help }\n\t\t\tclassName={ clsx( className, 'components-radio-control' ) }\n\t\t>\n\t\t\t<VStack spacing={
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_compose","_baseControl","_vStack","_jsxRuntime","RadioControl","props","label","className","selected","help","onChange","hideLabelFromVision","options","additionalProps","instanceId","useInstanceId","id","onChangeValue","event","target","value","length","jsx","default","__nextHasNoMarginBottom","clsx","children","VStack","spacing","map","option","index","jsxs","type","name","checked","undefined","htmlFor","_default","exports"],"sources":["@wordpress/components/src/radio-control/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ChangeEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '../base-control';\nimport type { WordPressComponentProps } from '../context';\nimport type { RadioControlProps } from './types';\nimport { VStack } from '../v-stack';\n\n/**\n * Render a user interface to select the user type using radio inputs.\n *\n * ```jsx\n * import { RadioControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyRadioControl = () => {\n * const [ option, setOption ] = useState( 'a' );\n *\n * return (\n * <RadioControl\n * label=\"User type\"\n * help=\"The type of the current user\"\n * selected={ option }\n * options={ [\n * { label: 'Author', value: 'a' },\n * { label: 'Editor', value: 'e' },\n * ] }\n * onChange={ ( value ) => setOption( value ) }\n * />\n * );\n * };\n * ```\n */\nexport function RadioControl(\n\tprops: WordPressComponentProps< RadioControlProps, 'input', false >\n) {\n\tconst {\n\t\tlabel,\n\t\tclassName,\n\t\tselected,\n\t\thelp,\n\t\tonChange,\n\t\thideLabelFromVision,\n\t\toptions = [],\n\t\t...additionalProps\n\t} = props;\n\tconst instanceId = useInstanceId( RadioControl );\n\tconst id = `inspector-radio-control-${ instanceId }`;\n\tconst onChangeValue = ( event: ChangeEvent< HTMLInputElement > ) =>\n\t\tonChange( event.target.value );\n\n\tif ( ! options?.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BaseControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ label }\n\t\t\tid={ id }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\thelp={ help }\n\t\t\tclassName={ clsx( className, 'components-radio-control' ) }\n\t\t>\n\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t{ options.map( ( option, index ) => (\n\t\t\t\t\t<div\n\t\t\t\t\t\tkey={ `${ id }-${ index }` }\n\t\t\t\t\t\tclassName=\"components-radio-control__option\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tid={ `${ id }-${ index }` }\n\t\t\t\t\t\t\tclassName=\"components-radio-control__input\"\n\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\tname={ id }\n\t\t\t\t\t\t\tvalue={ option.value }\n\t\t\t\t\t\t\tonChange={ onChangeValue }\n\t\t\t\t\t\t\tchecked={ option.value === selected }\n\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\t!! help ? `${ id }__help` : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t{ ...additionalProps }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<label\n\t\t\t\t\t\t\tclassName=\"components-radio-control__label\"\n\t\t\t\t\t\t\thtmlFor={ `${ id }-${ index }` }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ option.label }\n\t\t\t\t\t\t</label>\n\t\t\t\t\t</div>\n\t\t\t\t) ) }\n\t\t\t</VStack>\n\t\t</BaseControl>\n\t);\n}\n\nexport default RadioControl;\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAMA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAGA,IAAAG,OAAA,GAAAH,OAAA;AAAoC,IAAAI,WAAA,GAAAJ,OAAA;AAjBpC;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,YAAYA,CAC3BC,KAAmE,EAClE;EACD,MAAM;IAC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EC,IAAI,GAAI,GAAGO,EAAI,QAAO,GAAGoB,SAC5B;UAAA,GACIvB;QAAe,CACpB,CAAC,eACF,IAAAV,WAAA,CAAAmB,GAAA;UACCf,SAAS,EAAC,iCAAiC;UAC3C8B,OAAO,EAAI,GAAGrB,EAAI,IAAIe,KAAO,EAAG;UAAAL,QAAA,EAE9BI,MAAM,CAACxB;QAAK,CACR,CAAC;MAAA,GArBD,GAAGU,EAAI,IAAIe,KAAO,EAsBrB,CACJ;IAAC,CACI;EAAC,CACG,CAAC;AAEhB;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAAhB,OAAA,GAEcnB,YAAY","ignoreList":[]}
|
|
@@ -46,9 +46,7 @@ const CustomSelectButton = ({
|
|
|
46
46
|
// move selection rather than open the popover
|
|
47
47
|
,
|
|
48
48
|
showOnKeyDown: false,
|
|
49
|
-
children:
|
|
50
|
-
children: computedRenderSelectedValue(currentValue)
|
|
51
|
-
})
|
|
49
|
+
children: computedRenderSelectedValue(currentValue)
|
|
52
50
|
});
|
|
53
51
|
};
|
|
54
52
|
function _CustomSelect(props) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useMemo","__","sprintf","VisuallyHidden","Styled","InputBase","SelectControlChevronDown","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","CustomSelectContext","undefined","defaultRenderSelectedValue","value","isValueEmpty","Array","isArray","length","CustomSelectButton","renderSelectedValue","size","store","restProps","currentValue","useState","computedRenderSelectedValue","Select","hasCustomRenderProp","showOnKeyDown","children","_CustomSelect","props","hideLabelFromVision","label","as","SelectLabel","__next40pxDefaultSize","suffix","SelectPopover","gutter","sameWidth","Provider"],"sources":["@wordpress/components/src/custom-select-control-v2/custom-select.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useMemo } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { VisuallyHidden } from '..';\nimport * as Styled from './styles';\nimport type {\n\tCustomSelectContext as CustomSelectContextType,\n\tCustomSelectStore,\n\tCustomSelectButtonProps,\n\tCustomSelectButtonSize,\n\t_CustomSelectProps,\n} from './types';\nimport type { WordPressComponentProps } from '../context';\nimport InputBase from '../input-control/input-base';\nimport SelectControlChevronDown from '../select-control/chevron-down';\n\nexport const CustomSelectContext =\n\tcreateContext< CustomSelectContextType >( undefined );\n\nfunction defaultRenderSelectedValue(\n\tvalue: CustomSelectButtonProps[ 'value' ]\n) {\n\tconst isValueEmpty = Array.isArray( value )\n\t\t? value.length === 0\n\t\t: value === undefined || value === null;\n\n\tif ( isValueEmpty ) {\n\t\treturn __( 'Select an item' );\n\t}\n\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.length === 1\n\t\t\t? value[ 0 ]\n\t\t\t: // translators: %s: number of items selected (it will always be 2 or more items)\n\t\t\t sprintf( __( '%s items selected' ), value.length );\n\t}\n\n\treturn value;\n}\n\nconst CustomSelectButton = ( {\n\trenderSelectedValue,\n\tsize = 'default',\n\tstore,\n\t...restProps\n}: Omit<\n\tWordPressComponentProps<\n\t\tCustomSelectButtonProps & CustomSelectButtonSize & CustomSelectStore,\n\t\t'button',\n\t\tfalse\n\t>,\n\t'onChange'\n> ) => {\n\tconst { value: currentValue } = store.useState();\n\n\tconst computedRenderSelectedValue = useMemo(\n\t\t() => renderSelectedValue ?? defaultRenderSelectedValue,\n\t\t[ renderSelectedValue ]\n\t);\n\n\treturn (\n\t\t<Styled.Select\n\t\t\t{ ...restProps }\n\t\t\tsize={ size }\n\t\t\thasCustomRenderProp={ !! renderSelectedValue }\n\t\t\tstore={ store }\n\t\t\t// to match legacy behavior where using arrow keys\n\t\t\t// move selection rather than open the popover\n\t\t\tshowOnKeyDown={ false }\n\t\t>\n\t\t\t
|
|
1
|
+
{"version":3,"names":["createContext","useMemo","__","sprintf","VisuallyHidden","Styled","InputBase","SelectControlChevronDown","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","CustomSelectContext","undefined","defaultRenderSelectedValue","value","isValueEmpty","Array","isArray","length","CustomSelectButton","renderSelectedValue","size","store","restProps","currentValue","useState","computedRenderSelectedValue","Select","hasCustomRenderProp","showOnKeyDown","children","_CustomSelect","props","hideLabelFromVision","label","as","SelectLabel","__next40pxDefaultSize","suffix","SelectPopover","gutter","sameWidth","Provider"],"sources":["@wordpress/components/src/custom-select-control-v2/custom-select.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useMemo } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { VisuallyHidden } from '..';\nimport * as Styled from './styles';\nimport type {\n\tCustomSelectContext as CustomSelectContextType,\n\tCustomSelectStore,\n\tCustomSelectButtonProps,\n\tCustomSelectButtonSize,\n\t_CustomSelectProps,\n} from './types';\nimport type { WordPressComponentProps } from '../context';\nimport InputBase from '../input-control/input-base';\nimport SelectControlChevronDown from '../select-control/chevron-down';\n\nexport const CustomSelectContext =\n\tcreateContext< CustomSelectContextType >( undefined );\n\nfunction defaultRenderSelectedValue(\n\tvalue: CustomSelectButtonProps[ 'value' ]\n) {\n\tconst isValueEmpty = Array.isArray( value )\n\t\t? value.length === 0\n\t\t: value === undefined || value === null;\n\n\tif ( isValueEmpty ) {\n\t\treturn __( 'Select an item' );\n\t}\n\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.length === 1\n\t\t\t? value[ 0 ]\n\t\t\t: // translators: %s: number of items selected (it will always be 2 or more items)\n\t\t\t sprintf( __( '%s items selected' ), value.length );\n\t}\n\n\treturn value;\n}\n\nconst CustomSelectButton = ( {\n\trenderSelectedValue,\n\tsize = 'default',\n\tstore,\n\t...restProps\n}: Omit<\n\tWordPressComponentProps<\n\t\tCustomSelectButtonProps & CustomSelectButtonSize & CustomSelectStore,\n\t\t'button',\n\t\tfalse\n\t>,\n\t'onChange'\n> ) => {\n\tconst { value: currentValue } = store.useState();\n\n\tconst computedRenderSelectedValue = useMemo(\n\t\t() => renderSelectedValue ?? defaultRenderSelectedValue,\n\t\t[ renderSelectedValue ]\n\t);\n\n\treturn (\n\t\t<Styled.Select\n\t\t\t{ ...restProps }\n\t\t\tsize={ size }\n\t\t\thasCustomRenderProp={ !! renderSelectedValue }\n\t\t\tstore={ store }\n\t\t\t// to match legacy behavior where using arrow keys\n\t\t\t// move selection rather than open the popover\n\t\t\tshowOnKeyDown={ false }\n\t\t>\n\t\t\t{ computedRenderSelectedValue( currentValue ) }\n\t\t</Styled.Select>\n\t);\n};\n\nfunction _CustomSelect(\n\tprops: _CustomSelectProps & CustomSelectStore & CustomSelectButtonSize\n) {\n\tconst {\n\t\tchildren,\n\t\thideLabelFromVision = false,\n\t\tlabel,\n\t\tsize,\n\t\tstore,\n\t\t...restProps\n\t} = props;\n\n\treturn (\n\t\t<>\n\t\t\t{ hideLabelFromVision ? ( // TODO: Replace with BaseControl\n\t\t\t\t<VisuallyHidden as=\"label\">{ label }</VisuallyHidden>\n\t\t\t) : (\n\t\t\t\t<Styled.SelectLabel store={ store }>\n\t\t\t\t\t{ label }\n\t\t\t\t</Styled.SelectLabel>\n\t\t\t) }\n\t\t\t<InputBase\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tsize={ size }\n\t\t\t\tsuffix={ <SelectControlChevronDown /> }\n\t\t\t>\n\t\t\t\t<CustomSelectButton\n\t\t\t\t\t{ ...restProps }\n\t\t\t\t\tsize={ size }\n\t\t\t\t\tstore={ store }\n\t\t\t\t/>\n\t\t\t\t<Styled.SelectPopover gutter={ 12 } store={ store } sameWidth>\n\t\t\t\t\t<CustomSelectContext.Provider value={ { store } }>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</CustomSelectContext.Provider>\n\t\t\t\t</Styled.SelectPopover>\n\t\t\t</InputBase>\n\t\t</>\n\t);\n}\n\nexport default _CustomSelect;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,OAAO,QAAQ,oBAAoB;AAC3D,SAASC,EAAE,EAAEC,OAA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ignoreList":[]}
|
|
@@ -12,10 +12,9 @@ import CustomSelectItem from '../item';
|
|
|
12
12
|
import * as Styled from '../styles';
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
15
|
function CustomSelectControl(props) {
|
|
17
16
|
const {
|
|
18
|
-
__experimentalShowSelectedHint,
|
|
17
|
+
__experimentalShowSelectedHint = false,
|
|
19
18
|
__next40pxDefaultSize = false,
|
|
20
19
|
describedBy,
|
|
21
20
|
options,
|
|
@@ -28,7 +27,8 @@ function CustomSelectControl(props) {
|
|
|
28
27
|
// Forward props + store from v2 implementation
|
|
29
28
|
const store = Ariakit.useSelectStore({
|
|
30
29
|
async setValue(nextValue) {
|
|
31
|
-
|
|
30
|
+
const nextOption = options.find(item => item.name === nextValue);
|
|
31
|
+
if (!onChange || !nextOption) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -40,20 +40,24 @@ function CustomSelectControl(props) {
|
|
|
40
40
|
highlightedIndex: state.renderedItems.findIndex(item => item.value === nextValue),
|
|
41
41
|
inputValue: '',
|
|
42
42
|
isOpen: state.open,
|
|
43
|
-
selectedItem:
|
|
44
|
-
name: nextValue,
|
|
45
|
-
key: nextValue
|
|
46
|
-
},
|
|
43
|
+
selectedItem: nextOption,
|
|
47
44
|
type: ''
|
|
48
45
|
};
|
|
49
46
|
onChange(changeObject);
|
|
50
|
-
}
|
|
47
|
+
},
|
|
48
|
+
value: value?.name,
|
|
49
|
+
// Setting the first option as a default value when no value is provided
|
|
50
|
+
// is already done natively by the underlying Ariakit component,
|
|
51
|
+
// but doing this explicitly avoids the `onChange` callback from firing
|
|
52
|
+
// on initial render, thus making this implementation closer to the v1.
|
|
53
|
+
defaultValue: options[0]?.name
|
|
51
54
|
});
|
|
52
55
|
const children = options.map(({
|
|
53
56
|
name,
|
|
54
57
|
key,
|
|
55
58
|
__experimentalHint,
|
|
56
|
-
|
|
59
|
+
style,
|
|
60
|
+
className
|
|
57
61
|
}) => {
|
|
58
62
|
const withHint = /*#__PURE__*/_jsxs(Styled.WithHintWrapper, {
|
|
59
63
|
children: [/*#__PURE__*/_jsx("span", {
|
|
@@ -66,7 +70,8 @@ function CustomSelectControl(props) {
|
|
|
66
70
|
return /*#__PURE__*/_jsx(CustomSelectItem, {
|
|
67
71
|
value: name,
|
|
68
72
|
children: __experimentalHint ? withHint : name,
|
|
69
|
-
|
|
73
|
+
style: style,
|
|
74
|
+
className: className
|
|
70
75
|
}, key);
|
|
71
76
|
});
|
|
72
77
|
const renderSelectedValueHint = () => {
|
|
@@ -76,7 +81,7 @@ function CustomSelectControl(props) {
|
|
|
76
81
|
const currentHint = options?.find(({
|
|
77
82
|
name
|
|
78
83
|
}) => currentValue === name);
|
|
79
|
-
return /*#__PURE__*/_jsxs(
|
|
84
|
+
return /*#__PURE__*/_jsxs(Styled.SelectedExperimentalHintWrapper, {
|
|
80
85
|
children: [currentValue, /*#__PURE__*/_jsx(Styled.SelectedExperimentalHintItem, {
|
|
81
86
|
className: "components-custom-select-control__hint",
|
|
82
87
|
children: currentHint?.__experimentalHint
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Ariakit","_CustomSelect","CustomSelectItem","Styled","jsx","_jsx","jsxs","_jsxs","
|
|
1
|
+
{"version":3,"names":["Ariakit","_CustomSelect","CustomSelectItem","Styled","jsx","_jsx","jsxs","_jsxs","CustomSelectControl","props","__experimentalShowSelectedHint","__next40pxDefaultSize","describedBy","options","onChange","size","value","restProps","store","useSelectStore","setValue","nextValue","nextOption","find","item","name","Promise","resolve","state","getState","changeObject","highlightedIndex","renderedItems","findIndex","inputValue","isOpen","open","selectedItem","type","defaultValue","children","map","key","__experimentalHint","style","className","withHint","WithHintWrapper","ExperimentalHintItem","renderSelectedValueHint","currentValue","currentHint","SelectedExperimentalHintWrapper","SelectedExperimentalHintItem","translatedSize","renderSelectedValue","undefined"],"sources":["@wordpress/components/src/custom-select-control-v2/legacy-component/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport * as Ariakit from '@ariakit/react';\n\n/**\n * Internal dependencies\n */\nimport _CustomSelect from '../custom-select';\nimport CustomSelectItem from '../item';\nimport type { LegacyCustomSelectProps } from '../types';\nimport * as Styled from '../styles';\n\nfunction CustomSelectControl( props: LegacyCustomSelectProps ) {\n\tconst {\n\t\t__experimentalShowSelectedHint = false,\n\t\t__next40pxDefaultSize = false,\n\t\tdescribedBy,\n\t\toptions,\n\t\tonChange,\n\t\tsize = 'default',\n\t\tvalue,\n\t\t...restProps\n\t} = props;\n\n\t// Forward props + store from v2 implementation\n\tconst store = Ariakit.useSelectStore( {\n\t\tasync setValue( nextValue ) {\n\t\t\tconst nextOption = options.find(\n\t\t\t\t( item ) => item.name === nextValue\n\t\t\t);\n\n\t\t\tif ( ! onChange || ! nextOption ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Executes the logic in a microtask after the popup is closed.\n\t\t\t// This is simply to ensure the isOpen state matches that in Downshift.\n\t\t\tawait Promise.resolve();\n\t\t\tconst state = store.getState();\n\n\t\t\tconst changeObject = {\n\t\t\t\thighlightedIndex: state.renderedItems.findIndex(\n\t\t\t\t\t( item ) => item.value === nextValue\n\t\t\t\t),\n\t\t\t\tinputValue: '',\n\t\t\t\tisOpen: state.open,\n\t\t\t\tselectedItem: nextOption,\n\t\t\t\ttype: '',\n\t\t\t};\n\t\t\tonChange( changeObject );\n\t\t},\n\t\tvalue: value?.name,\n\t\t// Setting the first option as a default value when no value is provided\n\t\t// is already done natively by the underlying Ariakit component,\n\t\t// but doing this explicitly avoids the `onChange` callback from firing\n\t\t// on initial render, thus making this implementation closer to the v1.\n\t\tdefaultValue: options[ 0 ]?.name,\n\t} );\n\n\tconst children = options.map(\n\t\t( { name, key, __experimentalHint, style, className } ) => {\n\t\t\tconst withHint = (\n\t\t\t\t<Styled.WithHintWrapper>\n\t\t\t\t\t<span>{ name }</span>\n\t\t\t\t\t<Styled.ExperimentalHintItem className=\"components-custom-select-control__item-hint\">\n\t\t\t\t\t\t{ __experimentalHint }\n\t\t\t\t\t</Styled.ExperimentalHintItem>\n\t\t\t\t</Styled.WithHintWrapper>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<CustomSelectItem\n\t\t\t\t\tkey={ key }\n\t\t\t\t\tvalue={ name }\n\t\t\t\t\tchildren={ __experimentalHint ? withHint : name }\n\t\t\t\t\tstyle={ style }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t);\n\n\tconst renderSelectedValueHint = () => {\n\t\tconst { value: currentValue } = store.getState();\n\n\t\tconst currentHint = options?.find(\n\t\t\t( { name } ) => currentValue === name\n\t\t);\n\n\t\treturn (\n\t\t\t<Styled.SelectedExperimentalHintWrapper>\n\t\t\t\t{ currentValue }\n\t\t\t\t<Styled.SelectedExperimentalHintItem className=\"components-custom-select-control__hint\">\n\t\t\t\t\t{ currentHint?.__experimentalHint }\n\t\t\t\t</Styled.SelectedExperimentalHintItem>\n\t\t\t</Styled.SelectedExperimentalHintWrapper>\n\t\t);\n\t};\n\n\tconst translatedSize = ( () => {\n\t\tif (\n\t\t\t( __next40pxDefaultSize && size === 'default' ) ||\n\t\t\tsize === '__unstable-large'\n\t\t) {\n\t\t\treturn 'default';\n\t\t}\n\t\tif ( ! __next40pxDefaultSize && size === 'default' ) {\n\t\t\treturn 'compact';\n\t\t}\n\t\treturn size;\n\t} )();\n\n\treturn (\n\t\t<_CustomSelect\n\t\t\taria-describedby={ describedBy }\n\t\t\trenderSelectedValue={\n\t\t\t\t__experimentalShowSelectedHint\n\t\t\t\t\t? renderSelectedValueHint\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tsize={ translatedSize }\n\t\t\tstore={ store }\n\t\t\t{ ...restProps }\n\t\t>\n\t\t\t{ children }\n\t\t</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