@wordpress/components 19.8.3 → 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 +42 -0
- package/CONTRIBUTING.md +80 -7
- package/build/alignment-matrix-control/styles/alignment-matrix-control-styles.js +11 -11
- package/build/alignment-matrix-control/styles/alignment-matrix-control-styles.js.map +1 -1
- 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/heading/hook.js +1 -1
- package/build/heading/hook.js.map +1 -1
- package/build/input-control/index.js +27 -4
- 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/navigation/styles/navigation-styles.js +12 -12
- package/build/navigation/styles/navigation-styles.js.map +1 -1
- package/build/notice/index.native.js +44 -40
- package/build/notice/index.native.js.map +1 -1
- package/build/notice/list.native.js +27 -45
- package/build/notice/list.native.js.map +1 -1
- package/build/popover/index.js +6 -52
- package/build/popover/index.js.map +1 -1
- package/build/sandbox/index.js +2 -2
- package/build/sandbox/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/surface/styles.js +8 -8
- package/build/surface/styles.js.map +1 -1
- package/build/text/hook.js +5 -5
- package/build/text/hook.js.map +1 -1
- package/build/text/styles/text-mixins.native.js +1 -1
- package/build/text/styles/text-mixins.native.js.map +1 -1
- package/build/text/styles.js +7 -7
- package/build/text/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/ui/spinner/component.js +1 -1
- package/build/ui/spinner/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/utils/colors-values.js +9 -24
- package/build/utils/colors-values.js.map +1 -1
- package/build-module/alignment-matrix-control/styles/alignment-matrix-control-styles.js +11 -11
- package/build-module/alignment-matrix-control/styles/alignment-matrix-control-styles.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/heading/hook.js +1 -1
- package/build-module/heading/hook.js.map +1 -1
- package/build-module/input-control/index.js +24 -3
- 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/navigation/styles/navigation-styles.js +13 -13
- package/build-module/navigation/styles/navigation-styles.js.map +1 -1
- package/build-module/notice/index.native.js +45 -41
- package/build-module/notice/index.native.js.map +1 -1
- package/build-module/notice/list.native.js +28 -46
- package/build-module/notice/list.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/sandbox/index.js +2 -2
- package/build-module/sandbox/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/surface/styles.js +8 -8
- package/build-module/surface/styles.js.map +1 -1
- package/build-module/text/hook.js +5 -5
- package/build-module/text/hook.js.map +1 -1
- package/build-module/text/styles/text-mixins.native.js +2 -2
- package/build-module/text/styles/text-mixins.native.js.map +1 -1
- package/build-module/text/styles.js +7 -7
- package/build-module/text/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/ui/spinner/component.js +1 -1
- package/build-module/ui/spinner/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-module/utils/colors-values.js +19 -23
- package/build-module/utils/colors-values.js.map +1 -1
- package/build-style/style-rtl.css +24 -0
- package/build-style/style.css +24 -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 +23 -3
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/input-control/stories/index.d.ts +5 -5
- 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 +79 -3
- 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/build-types/utils/colors-values.d.ts +6 -146
- package/build-types/utils/colors-values.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/alignment-matrix-control/styles/alignment-matrix-control-styles.js +5 -3
- 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/heading/hook.ts +1 -1
- package/src/heading/test/__snapshots__/index.js.snap +3 -3
- package/src/input-control/README.md +3 -3
- package/src/input-control/index.tsx +23 -3
- package/src/input-control/stories/index.tsx +63 -0
- package/src/input-control/styles/input-control-styles.tsx +20 -7
- package/src/input-control/types.ts +79 -2
- 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/navigation/styles/navigation-styles.js +5 -5
- package/src/notice/index.native.js +44 -54
- package/src/notice/list.native.js +27 -51
- package/src/notice/style.native.scss +1 -0
- package/src/popover/index.js +5 -51
- package/src/query-controls/README.md +2 -2
- package/src/sandbox/index.js +2 -2
- 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 +10 -9
- package/src/select-control/test/{select-control.js → select-control.tsx} +2 -2
- package/src/select-control/types.ts +66 -1
- package/src/surface/styles.js +1 -1
- package/src/text/hook.js +1 -1
- package/src/text/styles/text-mixins.native.js +2 -2
- package/src/text/styles.js +1 -1
- package/src/text/test/__snapshots__/{index.js.snap → index.tsx.snap} +16 -0
- package/src/text/test/{index.js → index.tsx} +12 -6
- 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/toolbar-group/style.scss +20 -0
- package/src/tools-panel/test/__snapshots__/index.js.snap +2 -2
- 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/ui/spinner/component.js +1 -1
- package/src/ui/spinner/test/__snapshots__/index.js.snap +3 -3
- 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/src/utils/colors-values.js +18 -22
- package/tsconfig.json +9 -2
- 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/input-control/stories/index.js +0 -71
- 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
|
@@ -6,9 +6,8 @@ import { View } from 'react-native';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { compose } from '@wordpress/compose';
|
|
9
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
10
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Internal dependencies
|
|
@@ -16,60 +15,37 @@ import { compose } from '@wordpress/compose';
|
|
|
16
15
|
import Notice from './';
|
|
17
16
|
import styles from './style.scss';
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
function NoticeList() {
|
|
19
|
+
const { notices } = useSelect( ( select ) => {
|
|
20
|
+
const { getNotices } = select( noticesStore );
|
|
21
|
+
return {
|
|
22
|
+
notices: getNotices(),
|
|
23
|
+
};
|
|
24
|
+
}, [] );
|
|
24
25
|
|
|
25
|
-
removeNotice(
|
|
26
|
-
|
|
26
|
+
const { removeNotice } = useDispatch( noticesStore );
|
|
27
|
+
|
|
28
|
+
function onRemoveNotice( id ) {
|
|
27
29
|
removeNotice( id );
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if ( ! notices.length ) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
32
|
+
if ( ! notices.length ) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.reverse()
|
|
42
|
-
.map( ( notice ) => (
|
|
43
|
-
<Notice
|
|
44
|
-
{ ...notice }
|
|
45
|
-
key={ notice.id }
|
|
46
|
-
onNoticeHidden={ this.removeNotice }
|
|
47
|
-
></Notice>
|
|
48
|
-
) )
|
|
49
|
-
) : (
|
|
36
|
+
return (
|
|
37
|
+
<View style={ styles.list }>
|
|
38
|
+
{ notices.map( ( notice ) => {
|
|
39
|
+
return (
|
|
50
40
|
<Notice
|
|
51
|
-
{ ...
|
|
52
|
-
|
|
41
|
+
{ ...notice }
|
|
42
|
+
key={ notice.id }
|
|
43
|
+
onNoticeHidden={ onRemoveNotice }
|
|
53
44
|
></Notice>
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
);
|
|
46
|
+
} ) }
|
|
47
|
+
</View>
|
|
48
|
+
);
|
|
58
49
|
}
|
|
59
50
|
|
|
60
|
-
export default
|
|
61
|
-
withSelect( ( select ) => {
|
|
62
|
-
const { getNotices } = select( 'core/notices' );
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
notices: getNotices(),
|
|
66
|
-
};
|
|
67
|
-
} ),
|
|
68
|
-
withDispatch( ( dispatch ) => {
|
|
69
|
-
const { removeNotice } = dispatch( 'core/notices' );
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
removeNotice,
|
|
73
|
-
};
|
|
74
|
-
} ),
|
|
75
|
-
] )( NoticeList );
|
|
51
|
+
export default NoticeList;
|
package/src/popover/index.js
CHANGED
|
@@ -47,7 +47,6 @@ function computeAnchorRect(
|
|
|
47
47
|
anchorRect,
|
|
48
48
|
getAnchorRect,
|
|
49
49
|
anchorRef = false,
|
|
50
|
-
shouldAnchorIncludePadding,
|
|
51
50
|
container
|
|
52
51
|
) {
|
|
53
52
|
if ( anchorRect ) {
|
|
@@ -98,17 +97,14 @@ function computeAnchorRect(
|
|
|
98
97
|
container
|
|
99
98
|
);
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
return rect;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return withoutPadding( rect, anchorRef );
|
|
100
|
+
return rect;
|
|
106
101
|
}
|
|
107
102
|
|
|
108
103
|
const { top, bottom } = anchorRef;
|
|
109
104
|
const topRect = top.getBoundingClientRect();
|
|
110
105
|
const bottomRect = bottom.getBoundingClientRect();
|
|
111
|
-
|
|
106
|
+
|
|
107
|
+
return offsetIframe(
|
|
112
108
|
new window.DOMRect(
|
|
113
109
|
topRect.left,
|
|
114
110
|
topRect.top,
|
|
@@ -118,12 +114,6 @@ function computeAnchorRect(
|
|
|
118
114
|
top.ownerDocument,
|
|
119
115
|
container
|
|
120
116
|
);
|
|
121
|
-
|
|
122
|
-
if ( shouldAnchorIncludePadding ) {
|
|
123
|
-
return rect;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return withoutPadding( rect, anchorRef );
|
|
127
117
|
}
|
|
128
118
|
|
|
129
119
|
if ( ! anchorRefFallback.current ) {
|
|
@@ -131,45 +121,12 @@ function computeAnchorRect(
|
|
|
131
121
|
}
|
|
132
122
|
|
|
133
123
|
const { parentNode } = anchorRefFallback.current;
|
|
134
|
-
|
|
124
|
+
|
|
125
|
+
return offsetIframe(
|
|
135
126
|
parentNode.getBoundingClientRect(),
|
|
136
127
|
parentNode.ownerDocument,
|
|
137
128
|
container
|
|
138
129
|
);
|
|
139
|
-
|
|
140
|
-
if ( shouldAnchorIncludePadding ) {
|
|
141
|
-
return rect;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return withoutPadding( rect, parentNode );
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function getComputedStyle( node ) {
|
|
148
|
-
return node.ownerDocument.defaultView.getComputedStyle( node );
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function withoutPadding( rect, element ) {
|
|
152
|
-
const {
|
|
153
|
-
paddingTop,
|
|
154
|
-
paddingBottom,
|
|
155
|
-
paddingLeft,
|
|
156
|
-
paddingRight,
|
|
157
|
-
} = getComputedStyle( element );
|
|
158
|
-
const top = paddingTop ? parseInt( paddingTop, 10 ) : 0;
|
|
159
|
-
const bottom = paddingBottom ? parseInt( paddingBottom, 10 ) : 0;
|
|
160
|
-
const left = paddingLeft ? parseInt( paddingLeft, 10 ) : 0;
|
|
161
|
-
const right = paddingRight ? parseInt( paddingRight, 10 ) : 0;
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
x: rect.left + left,
|
|
165
|
-
y: rect.top + top,
|
|
166
|
-
width: rect.width - left - right,
|
|
167
|
-
height: rect.height - top - bottom,
|
|
168
|
-
left: rect.left + left,
|
|
169
|
-
right: rect.right - right,
|
|
170
|
-
top: rect.top + top,
|
|
171
|
-
bottom: rect.bottom - bottom,
|
|
172
|
-
};
|
|
173
130
|
}
|
|
174
131
|
|
|
175
132
|
/**
|
|
@@ -252,7 +209,6 @@ const Popover = (
|
|
|
252
209
|
range,
|
|
253
210
|
focusOnMount = 'firstElement',
|
|
254
211
|
anchorRef,
|
|
255
|
-
shouldAnchorIncludePadding,
|
|
256
212
|
anchorRect,
|
|
257
213
|
getAnchorRect,
|
|
258
214
|
expandOnMobile,
|
|
@@ -304,7 +260,6 @@ const Popover = (
|
|
|
304
260
|
anchorRect,
|
|
305
261
|
getAnchorRect,
|
|
306
262
|
anchorRef,
|
|
307
|
-
shouldAnchorIncludePadding,
|
|
308
263
|
containerRef.current
|
|
309
264
|
);
|
|
310
265
|
|
|
@@ -480,7 +435,6 @@ const Popover = (
|
|
|
480
435
|
anchorRect,
|
|
481
436
|
getAnchorRect,
|
|
482
437
|
anchorRef,
|
|
483
|
-
shouldAnchorIncludePadding,
|
|
484
438
|
position,
|
|
485
439
|
contentSize,
|
|
486
440
|
__unstableStickyBoundaryElement,
|
|
@@ -51,7 +51,7 @@ const MyQueryControls = () => {
|
|
|
51
51
|
selectedCategoryId={ category }
|
|
52
52
|
onCategoryChange={ ( newCategory ) => updateQuery( { category: newCategory } ) }
|
|
53
53
|
onNumberOfItemsChange={ ( newNumberOfItems ) =>
|
|
54
|
-
updateQuery( { numberOfItems:
|
|
54
|
+
updateQuery( { numberOfItems: newNumberOfItems } )
|
|
55
55
|
}
|
|
56
56
|
/>
|
|
57
57
|
);
|
|
@@ -104,7 +104,7 @@ const MyQueryControls = () => {
|
|
|
104
104
|
selectedCategories={ selectedCategories }
|
|
105
105
|
onCategoryChange={ ( category ) => updateQuery( { selectedCategories: category } ) }
|
|
106
106
|
onNumberOfItemsChange={ ( newNumberOfItems ) =>
|
|
107
|
-
updateQuery( { numberOfItems:
|
|
107
|
+
updateQuery( { numberOfItems: newNumberOfItems } )
|
|
108
108
|
}
|
|
109
109
|
/>
|
|
110
110
|
);
|
package/src/sandbox/index.js
CHANGED
|
@@ -227,11 +227,11 @@ export default function Sandbox( {
|
|
|
227
227
|
|
|
228
228
|
useEffect( () => {
|
|
229
229
|
trySandbox();
|
|
230
|
-
}, [ title,
|
|
230
|
+
}, [ title, styles, scripts ] );
|
|
231
231
|
|
|
232
232
|
useEffect( () => {
|
|
233
233
|
trySandbox( true );
|
|
234
|
-
}, [ html ] );
|
|
234
|
+
}, [ html, type ] );
|
|
235
235
|
|
|
236
236
|
return (
|
|
237
237
|
<iframe
|
|
@@ -114,7 +114,7 @@ Render a user interface to select multiple users from a list.
|
|
|
114
114
|
this.setState( { users } );
|
|
115
115
|
} }
|
|
116
116
|
options={ [
|
|
117
|
-
{ value:
|
|
117
|
+
{ value: '', label: 'Select a User', disabled: true },
|
|
118
118
|
{ value: 'a', label: 'User A' },
|
|
119
119
|
{ value: 'b', label: 'User B' },
|
|
120
120
|
{ value: 'c', label: 'User c' },
|
|
@@ -194,7 +194,7 @@ If this property is added, multiple values can be selected. The value passed sho
|
|
|
194
194
|
An array of objects containing the following properties:
|
|
195
195
|
|
|
196
196
|
- `label`: (string) The label to be shown to the user.
|
|
197
|
-
- `value`: (
|
|
197
|
+
- `value`: (string) The internal value used to choose the selected value. This is also the value passed to onChange when the option is selected.
|
|
198
198
|
- `disabled`: (boolean) Whether or not the option should have the disabled attribute.
|
|
199
199
|
- Type: `Array`
|
|
200
200
|
- Required: No
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { isEmpty, noop } from 'lodash';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
|
-
import type { ChangeEvent, FocusEvent,
|
|
6
|
+
import type { ChangeEvent, FocusEvent, ForwardedRef } from 'react';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* WordPress dependencies
|
|
@@ -17,10 +17,9 @@ import { Icon, chevronDown } from '@wordpress/icons';
|
|
|
17
17
|
*/
|
|
18
18
|
import BaseControl from '../base-control';
|
|
19
19
|
import InputBase from '../input-control/input-base';
|
|
20
|
-
import type { InputBaseProps, LabelPosition } from '../input-control/types';
|
|
21
20
|
import { Select, DownArrowWrapper } from './styles/select-control-styles';
|
|
22
|
-
import type { Size } from './types';
|
|
23
21
|
import type { WordPressComponentProps } from '../ui/context';
|
|
22
|
+
import type { SelectControlProps } from './types';
|
|
24
23
|
|
|
25
24
|
function useUniqueId( idProp?: string ) {
|
|
26
25
|
const instanceId = useInstanceId( SelectControl );
|
|
@@ -29,30 +28,7 @@ function useUniqueId( idProp?: string ) {
|
|
|
29
28
|
return idProp || id;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
extends Omit< InputBaseProps, 'children' | 'isFocused' > {
|
|
34
|
-
help?: string;
|
|
35
|
-
hideLabelFromVision?: boolean;
|
|
36
|
-
multiple?: boolean;
|
|
37
|
-
onBlur?: ( event: FocusEvent< HTMLSelectElement > ) => void;
|
|
38
|
-
onFocus?: ( event: FocusEvent< HTMLSelectElement > ) => void;
|
|
39
|
-
onChange?: (
|
|
40
|
-
value: string | string[],
|
|
41
|
-
extra?: { event?: ChangeEvent< HTMLSelectElement > }
|
|
42
|
-
) => void;
|
|
43
|
-
options?: {
|
|
44
|
-
label: string;
|
|
45
|
-
value: string;
|
|
46
|
-
id?: string;
|
|
47
|
-
disabled?: boolean;
|
|
48
|
-
}[];
|
|
49
|
-
size?: Size;
|
|
50
|
-
value?: string | string[];
|
|
51
|
-
labelPosition?: LabelPosition;
|
|
52
|
-
children?: ReactNode;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function SelectControl(
|
|
31
|
+
function UnforwardedSelectControl(
|
|
56
32
|
{
|
|
57
33
|
className,
|
|
58
34
|
disabled = false,
|
|
@@ -165,6 +141,31 @@ function SelectControl(
|
|
|
165
141
|
/* eslint-enable jsx-a11y/no-onchange */
|
|
166
142
|
}
|
|
167
143
|
|
|
168
|
-
|
|
144
|
+
/**
|
|
145
|
+
* `SelectControl` allows users to select from a single or multiple option menu.
|
|
146
|
+
* It functions as a wrapper around the browser's native `<select>` element.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* import { SelectControl } from '@wordpress/components';
|
|
150
|
+
* import { useState } from '@wordpress/element';
|
|
151
|
+
*
|
|
152
|
+
* const MySelectControl = () => {
|
|
153
|
+
* const [ size, setSize ] = useState( '50%' );
|
|
154
|
+
*
|
|
155
|
+
* return (
|
|
156
|
+
* <SelectControl
|
|
157
|
+
* label="Size"
|
|
158
|
+
* value={ size }
|
|
159
|
+
* options={ [
|
|
160
|
+
* { label: 'Big', value: '100%' },
|
|
161
|
+
* { label: 'Medium', value: '50%' },
|
|
162
|
+
* { label: 'Small', value: '25%' },
|
|
163
|
+
* ] }
|
|
164
|
+
* onChange={ setSize }
|
|
165
|
+
* />
|
|
166
|
+
* );
|
|
167
|
+
* };
|
|
168
|
+
*/
|
|
169
|
+
export const SelectControl = forwardRef( UnforwardedSelectControl );
|
|
169
170
|
|
|
170
|
-
export default
|
|
171
|
+
export default SelectControl;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
import type { ComponentProps } from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useState } from '@wordpress/element';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import SelectControl from '..';
|
|
16
|
+
|
|
17
|
+
const meta: ComponentMeta< typeof SelectControl > = {
|
|
18
|
+
title: 'Components/SelectControl',
|
|
19
|
+
component: SelectControl,
|
|
20
|
+
argTypes: {
|
|
21
|
+
help: { control: { type: 'text' } },
|
|
22
|
+
label: { control: { type: 'text' } },
|
|
23
|
+
prefix: { control: { type: 'text' } },
|
|
24
|
+
suffix: { control: { type: 'text' } },
|
|
25
|
+
value: { control: { type: null } },
|
|
26
|
+
},
|
|
27
|
+
parameters: {
|
|
28
|
+
controls: { expanded: true },
|
|
29
|
+
docs: { source: { state: 'open' } },
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
export default meta;
|
|
33
|
+
|
|
34
|
+
const SelectControlWithState: ComponentStory< typeof SelectControl > = (
|
|
35
|
+
args
|
|
36
|
+
) => {
|
|
37
|
+
const [ selection, setSelection ] = useState<
|
|
38
|
+
ComponentProps< typeof SelectControl >[ 'value' ]
|
|
39
|
+
>();
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<SelectControl
|
|
43
|
+
{ ...args }
|
|
44
|
+
value={ selection }
|
|
45
|
+
onChange={ setSelection }
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const Default = SelectControlWithState.bind( {} );
|
|
51
|
+
Default.args = {
|
|
52
|
+
options: [
|
|
53
|
+
{ value: '', label: 'Select an Option', disabled: true },
|
|
54
|
+
{ value: 'a', label: 'Option A' },
|
|
55
|
+
{ value: 'b', label: 'Option B' },
|
|
56
|
+
{ value: 'c', label: 'Option C' },
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const WithLabelAndHelpText = SelectControlWithState.bind( {} );
|
|
61
|
+
WithLabelAndHelpText.args = {
|
|
62
|
+
...Default.args,
|
|
63
|
+
help: 'Help text to explain the select control.',
|
|
64
|
+
label: 'Value',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* As an alternative to the `options` prop, `optgroup`s and `options` can be
|
|
69
|
+
* passed in as `children` for more customizability.
|
|
70
|
+
*/
|
|
71
|
+
export const WithCustomChildren: ComponentStory< typeof SelectControl > = (
|
|
72
|
+
args
|
|
73
|
+
) => {
|
|
74
|
+
return (
|
|
75
|
+
<SelectControlWithState { ...args }>
|
|
76
|
+
<option value="option-1">Option 1</option>
|
|
77
|
+
<option value="option-2" disabled>
|
|
78
|
+
Option 2 - Disabled
|
|
79
|
+
</option>
|
|
80
|
+
<optgroup label="Option Group 1">
|
|
81
|
+
<option value="option-group-1-option-1">
|
|
82
|
+
Option Group 1 - Option 1
|
|
83
|
+
</option>
|
|
84
|
+
<option value="option-group-1-option-2" disabled>
|
|
85
|
+
Option Group 1 - Option 2 - Disabled
|
|
86
|
+
</option>
|
|
87
|
+
</optgroup>
|
|
88
|
+
</SelectControlWithState>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
@@ -8,11 +8,12 @@ import styled from '@emotion/styled';
|
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { COLORS, rtl } from '../../utils';
|
|
11
|
-
import type {
|
|
11
|
+
import type { SelectControlProps } from '../types';
|
|
12
12
|
|
|
13
|
-
interface SelectProps {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
interface SelectProps extends Pick< SelectControlProps, 'disabled' > {
|
|
14
|
+
// Using `selectSize` instead of `size` to avoid a type conflict with the
|
|
15
|
+
// `size` HTML attribute of the `select` element.
|
|
16
|
+
selectSize?: SelectControlProps[ 'size' ];
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
const disabledStyles = ( { disabled }: SelectProps ) => {
|
|
@@ -23,14 +24,14 @@ const disabledStyles = ( { disabled }: SelectProps ) => {
|
|
|
23
24
|
} );
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
const fontSizeStyles = ( { selectSize }: SelectProps ) => {
|
|
27
|
+
const fontSizeStyles = ( { selectSize = 'default' }: SelectProps ) => {
|
|
27
28
|
const sizes = {
|
|
28
29
|
default: '13px',
|
|
29
30
|
small: '11px',
|
|
30
31
|
'__unstable-large': '13px',
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
const fontSize = sizes[ selectSize
|
|
34
|
+
const fontSize = sizes[ selectSize ];
|
|
34
35
|
const fontSizeMobile = '16px';
|
|
35
36
|
|
|
36
37
|
if ( ! fontSize ) return '';
|
|
@@ -44,7 +45,7 @@ const fontSizeStyles = ( { selectSize }: SelectProps ) => {
|
|
|
44
45
|
`;
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
const sizeStyles = ( { selectSize }: SelectProps ) => {
|
|
48
|
+
const sizeStyles = ( { selectSize = 'default' }: SelectProps ) => {
|
|
48
49
|
const sizes = {
|
|
49
50
|
default: {
|
|
50
51
|
height: 30,
|
|
@@ -63,7 +64,7 @@ const sizeStyles = ( { selectSize }: SelectProps ) => {
|
|
|
63
64
|
},
|
|
64
65
|
};
|
|
65
66
|
|
|
66
|
-
const style = sizes[ selectSize
|
|
67
|
+
const style = sizes[ selectSize ];
|
|
67
68
|
|
|
68
69
|
return css( style );
|
|
69
70
|
};
|
|
@@ -96,7 +97,7 @@ export const Select = styled.select< SelectProps >`
|
|
|
96
97
|
box-sizing: border-box;
|
|
97
98
|
border: none;
|
|
98
99
|
box-shadow: none !important;
|
|
99
|
-
color: ${ COLORS.
|
|
100
|
+
color: ${ COLORS.gray[ 900 ] };
|
|
100
101
|
display: block;
|
|
101
102
|
font-family: inherit;
|
|
102
103
|
margin: 0;
|
|
@@ -32,7 +32,7 @@ describe( 'SelectControl', () => {
|
|
|
32
32
|
|
|
33
33
|
expect( screen.getByText( 'Option 1' ) ).toBeInTheDocument();
|
|
34
34
|
|
|
35
|
-
const selectElement = screen.
|
|
35
|
+
const selectElement = screen.getByLabelText( 'Select' );
|
|
36
36
|
|
|
37
37
|
fireEvent.change( selectElement, {
|
|
38
38
|
target: { value: 'option-group-option-1' },
|
|
@@ -68,7 +68,7 @@ describe( 'SelectControl', () => {
|
|
|
68
68
|
|
|
69
69
|
expect( screen.getByText( 'Option 1' ) ).toBeInTheDocument();
|
|
70
70
|
|
|
71
|
-
const selectElement = screen.
|
|
71
|
+
const selectElement = screen.getByLabelText( 'Select' );
|
|
72
72
|
|
|
73
73
|
fireEvent.change( selectElement, {
|
|
74
74
|
target: { value: 'option-2' },
|
|
@@ -1 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ChangeEvent, FocusEvent, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { InputBaseProps } from '../input-control/types';
|
|
10
|
+
import type { BaseControlProps } from '../base-control/types';
|
|
11
|
+
|
|
12
|
+
export interface SelectControlProps
|
|
13
|
+
extends Pick<
|
|
14
|
+
InputBaseProps,
|
|
15
|
+
| 'disabled'
|
|
16
|
+
| 'hideLabelFromVision'
|
|
17
|
+
| 'label'
|
|
18
|
+
| 'labelPosition'
|
|
19
|
+
| 'prefix'
|
|
20
|
+
| 'size'
|
|
21
|
+
| 'suffix'
|
|
22
|
+
>,
|
|
23
|
+
Pick< BaseControlProps, 'help' > {
|
|
24
|
+
/**
|
|
25
|
+
* If this property is added, multiple values can be selected. The value passed should be an array.
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
multiple?: boolean;
|
|
30
|
+
onBlur?: ( event: FocusEvent< HTMLSelectElement > ) => void;
|
|
31
|
+
onFocus?: ( event: FocusEvent< HTMLSelectElement > ) => void;
|
|
32
|
+
/**
|
|
33
|
+
* A function that receives the value of the new option that is being selected as input.
|
|
34
|
+
*
|
|
35
|
+
* If `multiple` is `true`, the value received is an array of the selected value.
|
|
36
|
+
* Otherwise, the value received is a single value with the new selected value.
|
|
37
|
+
*/
|
|
38
|
+
onChange?: (
|
|
39
|
+
value: string | string[],
|
|
40
|
+
extra?: { event?: ChangeEvent< HTMLSelectElement > }
|
|
41
|
+
) => void;
|
|
42
|
+
options?: {
|
|
43
|
+
/**
|
|
44
|
+
* The label to be shown to the user.
|
|
45
|
+
*/
|
|
46
|
+
label: string;
|
|
47
|
+
/**
|
|
48
|
+
* The internal value used to choose the selected value.
|
|
49
|
+
* This is also the value passed to `onChange` when the option is selected.
|
|
50
|
+
*/
|
|
51
|
+
value: string;
|
|
52
|
+
id?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Whether or not the option should have the disabled attribute.
|
|
55
|
+
*
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
}[];
|
|
60
|
+
value?: string | string[];
|
|
61
|
+
/**
|
|
62
|
+
* As an alternative to the `options` prop, `optgroup`s and `options` can be
|
|
63
|
+
* passed in as `children` for more customizability.
|
|
64
|
+
*/
|
|
65
|
+
children?: ReactNode;
|
|
66
|
+
}
|
package/src/surface/styles.js
CHANGED
package/src/text/hook.js
CHANGED
|
@@ -105,7 +105,7 @@ export default function useText( props ) {
|
|
|
105
105
|
getOptimalTextShade( optimizeReadabilityFor ) === 'dark';
|
|
106
106
|
|
|
107
107
|
sx.optimalTextColor = isOptimalTextColorDark
|
|
108
|
-
? css( { color: COLORS.
|
|
108
|
+
? css( { color: COLORS.gray[ 900 ] } )
|
|
109
109
|
: css( { color: COLORS.white } );
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { fontFamily } from './font-family';
|
|
5
5
|
import css from './emotion-css';
|
|
6
|
-
import {
|
|
6
|
+
import { COLORS } from '../../utils/colors-values';
|
|
7
7
|
|
|
8
8
|
const fontWeightNormal = `font-weight: 400;`;
|
|
9
9
|
const fontWeightMedium = `font-weight: 500;`;
|
|
@@ -81,7 +81,7 @@ const sectionHeading = `
|
|
|
81
81
|
font-size: 11px;
|
|
82
82
|
line-height: 1.4;
|
|
83
83
|
text-transform: uppercase;
|
|
84
|
-
color: ${
|
|
84
|
+
color: ${ COLORS.gray[ 700 ] }
|
|
85
85
|
`;
|
|
86
86
|
|
|
87
87
|
/**
|
package/src/text/styles.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`Text should render align 1`] = `
|
|
4
|
+
Snapshot Diff:
|
|
5
|
+
- Received styles
|
|
6
|
+
+ Base styles
|
|
7
|
+
|
|
8
|
+
@@ -3,7 +3,8 @@
|
|
9
|
+
"color": "#1e1e1e",
|
|
10
|
+
"font-size": "calc((13 / 13) * 13px)",
|
|
11
|
+
"font-weight": "normal",
|
|
12
|
+
"line-height": "1.2",
|
|
13
|
+
"margin": "0",
|
|
14
|
+
+ "text-align": "center",
|
|
15
|
+
},
|
|
16
|
+
]
|
|
17
|
+
`;
|
|
18
|
+
|
|
3
19
|
exports[`Text should render highlighted words with highlightCaseSensitive 1`] = `
|
|
4
20
|
.emotion-0 {
|
|
5
21
|
color: #1e1e1e;
|