@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.
Files changed (256) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/CONTRIBUTING.md +80 -7
  3. package/build/alignment-matrix-control/styles/alignment-matrix-control-styles.js +11 -11
  4. package/build/alignment-matrix-control/styles/alignment-matrix-control-styles.js.map +1 -1
  5. package/build/angle-picker-control/angle-circle.js +5 -7
  6. package/build/angle-picker-control/angle-circle.js.map +1 -1
  7. package/build/box-control/index.js +0 -21
  8. package/build/box-control/index.js.map +1 -1
  9. package/build/box-control/utils.js +1 -8
  10. package/build/box-control/utils.js.map +1 -1
  11. package/build/button/index.js +3 -5
  12. package/build/button/index.js.map +1 -1
  13. package/build/circular-option-picker/index.js +1 -2
  14. package/build/circular-option-picker/index.js.map +1 -1
  15. package/build/disabled/index.js +4 -76
  16. package/build/disabled/index.js.map +1 -1
  17. package/build/heading/hook.js +1 -1
  18. package/build/heading/hook.js.map +1 -1
  19. package/build/input-control/index.js +27 -4
  20. package/build/input-control/index.js.map +1 -1
  21. package/build/input-control/styles/input-control-styles.js +42 -30
  22. package/build/input-control/styles/input-control-styles.js.map +1 -1
  23. package/build/mobile/bottom-sheet-select-control/index.native.js +1 -0
  24. package/build/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
  25. package/build/navigation/styles/navigation-styles.js +12 -12
  26. package/build/navigation/styles/navigation-styles.js.map +1 -1
  27. package/build/notice/index.native.js +44 -40
  28. package/build/notice/index.native.js.map +1 -1
  29. package/build/notice/list.native.js +27 -45
  30. package/build/notice/list.native.js.map +1 -1
  31. package/build/popover/index.js +6 -52
  32. package/build/popover/index.js.map +1 -1
  33. package/build/sandbox/index.js +2 -2
  34. package/build/sandbox/index.js.map +1 -1
  35. package/build/select-control/index.js +31 -4
  36. package/build/select-control/index.js.map +1 -1
  37. package/build/select-control/styles/select-control-styles.js +8 -8
  38. package/build/select-control/styles/select-control-styles.js.map +1 -1
  39. package/build/surface/styles.js +8 -8
  40. package/build/surface/styles.js.map +1 -1
  41. package/build/text/hook.js +5 -5
  42. package/build/text/hook.js.map +1 -1
  43. package/build/text/styles/text-mixins.native.js +1 -1
  44. package/build/text/styles/text-mixins.native.js.map +1 -1
  45. package/build/text/styles.js +7 -7
  46. package/build/text/styles.js.map +1 -1
  47. package/build/text-control/index.js +35 -28
  48. package/build/text-control/index.js.map +1 -1
  49. package/build/text-control/types.js +6 -0
  50. package/build/text-control/types.js.map +1 -0
  51. package/build/toggle-group-control/toggle-group-control-option-icon/component.js +6 -4
  52. package/build/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
  53. package/build/tools-panel/tools-panel-header/component.js +52 -36
  54. package/build/tools-panel/tools-panel-header/component.js.map +1 -1
  55. package/build/ui/spinner/component.js +1 -1
  56. package/build/ui/spinner/component.js.map +1 -1
  57. package/build/unit-control/index.js +3 -3
  58. package/build/unit-control/index.js.map +1 -1
  59. package/build/unit-control/styles/unit-control-styles.js +11 -20
  60. package/build/unit-control/styles/unit-control-styles.js.map +1 -1
  61. package/build/unit-control/utils.js.map +1 -1
  62. package/build/utils/colors-values.js +9 -24
  63. package/build/utils/colors-values.js.map +1 -1
  64. package/build-module/alignment-matrix-control/styles/alignment-matrix-control-styles.js +11 -11
  65. package/build-module/alignment-matrix-control/styles/alignment-matrix-control-styles.js.map +1 -1
  66. package/build-module/angle-picker-control/angle-circle.js +5 -7
  67. package/build-module/angle-picker-control/angle-circle.js.map +1 -1
  68. package/build-module/box-control/index.js +1 -20
  69. package/build-module/box-control/index.js.map +1 -1
  70. package/build-module/box-control/utils.js +0 -6
  71. package/build-module/box-control/utils.js.map +1 -1
  72. package/build-module/button/index.js +3 -4
  73. package/build-module/button/index.js.map +1 -1
  74. package/build-module/circular-option-picker/index.js +1 -2
  75. package/build-module/circular-option-picker/index.js.map +1 -1
  76. package/build-module/disabled/index.js +5 -76
  77. package/build-module/disabled/index.js.map +1 -1
  78. package/build-module/heading/hook.js +1 -1
  79. package/build-module/heading/hook.js.map +1 -1
  80. package/build-module/input-control/index.js +24 -3
  81. package/build-module/input-control/index.js.map +1 -1
  82. package/build-module/input-control/styles/input-control-styles.js +42 -30
  83. package/build-module/input-control/styles/input-control-styles.js.map +1 -1
  84. package/build-module/mobile/bottom-sheet-select-control/index.native.js +1 -0
  85. package/build-module/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
  86. package/build-module/navigation/styles/navigation-styles.js +13 -13
  87. package/build-module/navigation/styles/navigation-styles.js.map +1 -1
  88. package/build-module/notice/index.native.js +45 -41
  89. package/build-module/notice/index.native.js.map +1 -1
  90. package/build-module/notice/list.native.js +28 -46
  91. package/build-module/notice/list.native.js.map +1 -1
  92. package/build-module/popover/index.js +6 -52
  93. package/build-module/popover/index.js.map +1 -1
  94. package/build-module/sandbox/index.js +2 -2
  95. package/build-module/sandbox/index.js.map +1 -1
  96. package/build-module/select-control/index.js +29 -3
  97. package/build-module/select-control/index.js.map +1 -1
  98. package/build-module/select-control/styles/select-control-styles.js +8 -8
  99. package/build-module/select-control/styles/select-control-styles.js.map +1 -1
  100. package/build-module/surface/styles.js +8 -8
  101. package/build-module/surface/styles.js.map +1 -1
  102. package/build-module/text/hook.js +5 -5
  103. package/build-module/text/hook.js.map +1 -1
  104. package/build-module/text/styles/text-mixins.native.js +2 -2
  105. package/build-module/text/styles/text-mixins.native.js.map +1 -1
  106. package/build-module/text/styles.js +7 -7
  107. package/build-module/text/styles.js.map +1 -1
  108. package/build-module/text-control/index.js +35 -27
  109. package/build-module/text-control/index.js.map +1 -1
  110. package/build-module/text-control/types.js +2 -0
  111. package/build-module/text-control/types.js.map +1 -0
  112. package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js +1 -5
  113. package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
  114. package/build-module/tools-panel/tools-panel-header/component.js +51 -36
  115. package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
  116. package/build-module/ui/spinner/component.js +1 -1
  117. package/build-module/ui/spinner/component.js.map +1 -1
  118. package/build-module/unit-control/index.js +3 -3
  119. package/build-module/unit-control/index.js.map +1 -1
  120. package/build-module/unit-control/styles/unit-control-styles.js +11 -20
  121. package/build-module/unit-control/styles/unit-control-styles.js.map +1 -1
  122. package/build-module/unit-control/utils.js.map +1 -1
  123. package/build-module/utils/colors-values.js +19 -23
  124. package/build-module/utils/colors-values.js.map +1 -1
  125. package/build-style/style-rtl.css +24 -0
  126. package/build-style/style.css +24 -0
  127. package/build-types/button/index.d.ts.map +1 -1
  128. package/build-types/circular-option-picker/index.d.ts.map +1 -1
  129. package/build-types/color-picker/styles.d.ts +3 -3
  130. package/build-types/disabled/index.d.ts.map +1 -1
  131. package/build-types/input-control/index.d.ts +23 -3
  132. package/build-types/input-control/index.d.ts.map +1 -1
  133. package/build-types/input-control/input-field.d.ts +1 -1
  134. package/build-types/input-control/input-field.d.ts.map +1 -1
  135. package/build-types/input-control/stories/index.d.ts +5 -5
  136. package/build-types/input-control/styles/input-control-styles.d.ts +1 -0
  137. package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
  138. package/build-types/input-control/types.d.ts +79 -3
  139. package/build-types/input-control/types.d.ts.map +1 -1
  140. package/build-types/number-control/styles/number-control-styles.d.ts +1 -1
  141. package/build-types/popover/index.d.ts +0 -1
  142. package/build-types/popover/index.d.ts.map +1 -1
  143. package/build-types/select-control/index.d.ts +30 -26
  144. package/build-types/select-control/index.d.ts.map +1 -1
  145. package/build-types/select-control/stories/index.d.ts +23 -0
  146. package/build-types/select-control/stories/index.d.ts.map +1 -0
  147. package/build-types/select-control/styles/select-control-styles.d.ts +3 -4
  148. package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
  149. package/build-types/select-control/test/select-control.d.ts +2 -0
  150. package/build-types/select-control/test/select-control.d.ts.map +1 -0
  151. package/build-types/select-control/types.d.ts +52 -1
  152. package/build-types/select-control/types.d.ts.map +1 -1
  153. package/build-types/text-control/index.d.ts +32 -0
  154. package/build-types/text-control/index.d.ts.map +1 -0
  155. package/build-types/text-control/stories/index.d.ts +13 -0
  156. package/build-types/text-control/stories/index.d.ts.map +1 -0
  157. package/build-types/text-control/types.d.ts +25 -0
  158. package/build-types/text-control/types.d.ts.map +1 -0
  159. package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts.map +1 -1
  160. package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
  161. package/build-types/tools-panel/types.d.ts +0 -1
  162. package/build-types/tools-panel/types.d.ts.map +1 -1
  163. package/build-types/unit-control/index.d.ts +2 -2
  164. package/build-types/unit-control/index.d.ts.map +1 -1
  165. package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
  166. package/build-types/unit-control/test/index.d.ts +2 -0
  167. package/build-types/unit-control/test/index.d.ts.map +1 -0
  168. package/build-types/unit-control/test/utils.d.ts +2 -0
  169. package/build-types/unit-control/test/utils.d.ts.map +1 -0
  170. package/build-types/unit-control/types.d.ts +1 -1
  171. package/build-types/unit-control/types.d.ts.map +1 -1
  172. package/build-types/unit-control/utils.d.ts +3 -3
  173. package/build-types/unit-control/utils.d.ts.map +1 -1
  174. package/build-types/utils/colors-values.d.ts +6 -146
  175. package/build-types/utils/colors-values.d.ts.map +1 -1
  176. package/package.json +17 -17
  177. package/src/alignment-matrix-control/styles/alignment-matrix-control-styles.js +5 -3
  178. package/src/angle-picker-control/angle-circle.js +3 -3
  179. package/src/box-control/README.md +0 -74
  180. package/src/box-control/index.js +0 -15
  181. package/src/box-control/stories/index.js +0 -29
  182. package/src/box-control/utils.js +0 -7
  183. package/src/button/index.js +2 -4
  184. package/src/button/test/index.js +16 -1
  185. package/src/circular-option-picker/index.js +1 -2
  186. package/src/color-palette/README.md +0 -1
  187. package/src/color-palette/test/__snapshots__/index.js.snap +2 -3
  188. package/src/confirm-dialog/stories/index.js +87 -99
  189. package/src/date-time/stories/index.js +19 -0
  190. package/src/date-time/test/date.js +107 -78
  191. package/src/dimension-control/test/__snapshots__/index.test.js.snap +4 -4
  192. package/src/disabled/index.js +5 -90
  193. package/src/form-file-upload/test/index.js +15 -12
  194. package/src/heading/hook.ts +1 -1
  195. package/src/heading/test/__snapshots__/index.js.snap +3 -3
  196. package/src/input-control/README.md +3 -3
  197. package/src/input-control/index.tsx +23 -3
  198. package/src/input-control/stories/index.tsx +63 -0
  199. package/src/input-control/styles/input-control-styles.tsx +20 -7
  200. package/src/input-control/types.ts +79 -2
  201. package/src/menu-item/style.scss +10 -0
  202. package/src/mobile/bottom-sheet/bottom-sheet-navigation/test/navigation-container.native.js +8 -1
  203. package/src/mobile/bottom-sheet-select-control/index.native.js +1 -0
  204. package/src/mobile/html-text-input/style.android.scss +1 -0
  205. package/src/mobile/html-text-input/style.ios.scss +1 -0
  206. package/src/mobile/link-settings/test/link-settings-navigation.native.js +9 -1
  207. package/src/navigation/styles/navigation-styles.js +5 -5
  208. package/src/notice/index.native.js +44 -54
  209. package/src/notice/list.native.js +27 -51
  210. package/src/notice/style.native.scss +1 -0
  211. package/src/popover/index.js +5 -51
  212. package/src/query-controls/README.md +2 -2
  213. package/src/sandbox/index.js +2 -2
  214. package/src/select-control/README.md +2 -2
  215. package/src/select-control/index.tsx +30 -29
  216. package/src/select-control/stories/index.tsx +90 -0
  217. package/src/select-control/styles/select-control-styles.ts +10 -9
  218. package/src/select-control/test/{select-control.js → select-control.tsx} +2 -2
  219. package/src/select-control/types.ts +66 -1
  220. package/src/surface/styles.js +1 -1
  221. package/src/text/hook.js +1 -1
  222. package/src/text/styles/text-mixins.native.js +2 -2
  223. package/src/text/styles.js +1 -1
  224. package/src/text/test/__snapshots__/{index.js.snap → index.tsx.snap} +16 -0
  225. package/src/text/test/{index.js → index.tsx} +12 -6
  226. package/src/text-control/index.tsx +84 -0
  227. package/src/text-control/stories/index.tsx +66 -0
  228. package/src/text-control/types.ts +29 -0
  229. package/src/toggle-group-control/toggle-group-control-option-icon/component.tsx +1 -5
  230. package/src/toolbar-group/style.scss +20 -0
  231. package/src/tools-panel/test/__snapshots__/index.js.snap +2 -2
  232. package/src/tools-panel/test/index.js +71 -18
  233. package/src/tools-panel/tools-panel-header/component.tsx +75 -33
  234. package/src/tools-panel/types.ts +0 -1
  235. package/src/tooltip/test/index.js +6 -0
  236. package/src/ui/spinner/component.js +1 -1
  237. package/src/ui/spinner/test/__snapshots__/index.js.snap +3 -3
  238. package/src/unit-control/index.tsx +2 -5
  239. package/src/unit-control/styles/unit-control-styles.ts +3 -13
  240. package/src/unit-control/test/__snapshots__/index.tsx.snap +33 -0
  241. package/src/unit-control/test/{index.js → index.tsx} +214 -165
  242. package/src/unit-control/test/{utils.js → utils.ts} +38 -19
  243. package/src/unit-control/types.ts +4 -1
  244. package/src/unit-control/utils.ts +5 -3
  245. package/src/utils/colors-values.js +18 -22
  246. package/tsconfig.json +9 -2
  247. package/tsconfig.tsbuildinfo +1 -1
  248. package/build/box-control/visualizer.js +0 -165
  249. package/build/box-control/visualizer.js.map +0 -1
  250. package/build-module/box-control/visualizer.js +0 -154
  251. package/build-module/box-control/visualizer.js.map +0 -1
  252. package/src/box-control/visualizer.js +0 -116
  253. package/src/input-control/stories/index.js +0 -71
  254. package/src/select-control/stories/index.js +0 -104
  255. package/src/text-control/index.js +0 -72
  256. 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 { Component } from '@wordpress/element';
10
- import { withDispatch, withSelect } from '@wordpress/data';
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
- class NoticeList extends Component {
20
- constructor() {
21
- super( ...arguments );
22
- this.removeNotice = this.removeNotice.bind( this );
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( id ) {
26
- const { removeNotice } = this.props;
26
+ const { removeNotice } = useDispatch( noticesStore );
27
+
28
+ function onRemoveNotice( id ) {
27
29
  removeNotice( id );
28
30
  }
29
31
 
30
- render() {
31
- const { notices, shouldStack } = this.props;
32
-
33
- if ( ! notices.length ) {
34
- return null;
35
- }
32
+ if ( ! notices.length ) {
33
+ return null;
34
+ }
36
35
 
37
- return (
38
- <View style={ styles.list } key={ notices.length }>
39
- { shouldStack ? (
40
- notices
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
- { ...notices[ notices.length - 1 ] }
52
- onNoticeHidden={ this.removeNotice }
41
+ { ...notice }
42
+ key={ notice.id }
43
+ onNoticeHidden={ onRemoveNotice }
53
44
  ></Notice>
54
- ) }
55
- </View>
56
- );
57
- }
45
+ );
46
+ } ) }
47
+ </View>
48
+ );
58
49
  }
59
50
 
60
- export default compose( [
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;
@@ -33,6 +33,7 @@
33
33
 
34
34
  .notice {
35
35
  justify-content: center;
36
+ position: absolute;
36
37
  }
37
38
 
38
39
  .noticeContent {
@@ -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
- if ( shouldAnchorIncludePadding ) {
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
- const rect = offsetIframe(
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
- const rect = offsetIframe(
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: newCategory } )
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: newCategory } )
107
+ updateQuery( { numberOfItems: newNumberOfItems } )
108
108
  }
109
109
  />
110
110
  );
@@ -227,11 +227,11 @@ export default function Sandbox( {
227
227
 
228
228
  useEffect( () => {
229
229
  trySandbox();
230
- }, [ title, type, styles, scripts ] );
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: null, label: 'Select a User', disabled: true },
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`: (Object) The internal value used to choose the selected value. This is also the value passed to onChange when the option is selected.
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, ReactNode, ForwardedRef } from 'react';
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
- export interface SelectControlProps
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
- const ForwardedComponent = forwardRef( SelectControl );
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 ForwardedComponent;
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 { Size } from '../types';
11
+ import type { SelectControlProps } from '../types';
12
12
 
13
- interface SelectProps {
14
- disabled?: boolean;
15
- selectSize?: Size;
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 as Size ];
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 as Size ] || sizes.default;
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.black };
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.queryByLabelText( 'Select' );
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.queryByLabelText( 'Select' );
71
+ const selectElement = screen.getByLabelText( 'Select' );
72
72
 
73
73
  fireEvent.change( selectElement, {
74
74
  target: { value: 'option-2' },
@@ -1 +1,66 @@
1
- export type Size = 'default' | 'small' | '__unstable-large';
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
+ }
@@ -10,7 +10,7 @@ import { CONFIG, COLORS } from '../utils';
10
10
 
11
11
  export const Surface = css`
12
12
  background-color: ${ CONFIG.surfaceColor };
13
- color: ${ COLORS.darkGray.primary };
13
+ color: ${ COLORS.gray[ 900 ] };
14
14
  position: relative;
15
15
  `;
16
16
 
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.black } )
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 { G2 } from '../../utils/colors-values';
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: ${ G2.gray[ 700 ] }
84
+ color: ${ COLORS.gray[ 700 ] }
85
85
  `;
86
86
 
87
87
  /**
@@ -9,7 +9,7 @@ import { css } from '@emotion/react';
9
9
  import { COLORS, CONFIG } from '../utils';
10
10
 
11
11
  export const Text = css`
12
- color: ${ COLORS.darkGray.primary };
12
+ color: ${ COLORS.gray[ 900 ] };
13
13
  line-height: ${ CONFIG.fontLineHeightBase };
14
14
  margin: 0;
15
15
  `;
@@ -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;