@wordpress/components 21.2.0 → 21.3.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 (302) hide show
  1. package/CHANGELOG.md +35 -3
  2. package/CONTRIBUTING.md +20 -0
  3. package/build/border-box-control/border-box-control/component.js +2 -0
  4. package/build/border-box-control/border-box-control/component.js.map +1 -1
  5. package/build/border-box-control/border-box-control/hook.js +4 -1
  6. package/build/border-box-control/border-box-control/hook.js.map +1 -1
  7. package/build/border-control/border-control/component.js +2 -0
  8. package/build/border-control/border-control/component.js.map +1 -1
  9. package/build/disabled/index.js +6 -26
  10. package/build/disabled/index.js.map +1 -1
  11. package/build/font-size-picker/index.js +1 -1
  12. package/build/font-size-picker/index.js.map +1 -1
  13. package/build/font-size-picker/styles.js +5 -13
  14. package/build/font-size-picker/styles.js.map +1 -1
  15. package/build/font-size-picker/utils.js +1 -1
  16. package/build/font-size-picker/utils.js.map +1 -1
  17. package/build/form-token-field/suggestions-list.js +5 -5
  18. package/build/form-token-field/suggestions-list.js.map +1 -1
  19. package/build/higher-order/with-fallback-styles/index.js +1 -1
  20. package/build/higher-order/with-fallback-styles/index.js.map +1 -1
  21. package/build/index.js +8 -6
  22. package/build/index.js.map +1 -1
  23. package/build/modal/aria-helper.js +2 -3
  24. package/build/modal/aria-helper.js.map +1 -1
  25. package/build/modal/index.js +42 -11
  26. package/build/modal/index.js.map +1 -1
  27. package/build/modal/types.js +6 -0
  28. package/build/modal/types.js.map +1 -0
  29. package/build/navigator/index.js +8 -8
  30. package/build/navigator/index.js.map +1 -1
  31. package/build/navigator/navigator-back-button/component.js +5 -4
  32. package/build/navigator/navigator-back-button/component.js.map +1 -1
  33. package/build/navigator/navigator-back-button/index.js +1 -1
  34. package/build/navigator/navigator-back-button/index.js.map +1 -1
  35. package/build/navigator/navigator-button/component.js +5 -4
  36. package/build/navigator/navigator-button/component.js.map +1 -1
  37. package/build/navigator/navigator-button/index.js +1 -1
  38. package/build/navigator/navigator-button/index.js.map +1 -1
  39. package/build/navigator/navigator-provider/component.js +10 -7
  40. package/build/navigator/navigator-provider/component.js.map +1 -1
  41. package/build/navigator/navigator-provider/index.js +1 -1
  42. package/build/navigator/navigator-provider/index.js.map +1 -1
  43. package/build/navigator/navigator-screen/component.js +24 -27
  44. package/build/navigator/navigator-screen/component.js.map +1 -1
  45. package/build/navigator/navigator-screen/index.js +1 -1
  46. package/build/navigator/navigator-screen/index.js.map +1 -1
  47. package/build/sandbox/index.js +55 -59
  48. package/build/sandbox/index.js.map +1 -1
  49. package/build/sandbox/index.native.js +63 -62
  50. package/build/sandbox/index.native.js.map +1 -1
  51. package/build/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
  52. package/build/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
  53. package/build/tab-panel/index.js +4 -4
  54. package/build/tab-panel/index.js.map +1 -1
  55. package/build/theme/index.js +62 -0
  56. package/build/theme/index.js.map +1 -0
  57. package/build/theme/styles.js +33 -0
  58. package/build/theme/styles.js.map +1 -0
  59. package/build/theme/types.js +6 -0
  60. package/build/theme/types.js.map +1 -0
  61. package/build/tools-panel/tools-panel/hook.js +3 -3
  62. package/build/tools-panel/tools-panel/hook.js.map +1 -1
  63. package/build/tools-panel/tools-panel-item/hook.js +6 -6
  64. package/build/tools-panel/tools-panel-item/hook.js.map +1 -1
  65. package/build/tooltip/index.js +4 -1
  66. package/build/tooltip/index.js.map +1 -1
  67. package/build/tooltip/index.native.js +17 -4
  68. package/build/tooltip/index.native.js.map +1 -1
  69. package/build-module/border-box-control/border-box-control/component.js +2 -0
  70. package/build-module/border-box-control/border-box-control/component.js.map +1 -1
  71. package/build-module/border-box-control/border-box-control/hook.js +4 -1
  72. package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
  73. package/build-module/border-control/border-control/component.js +2 -0
  74. package/build-module/border-control/border-control/component.js.map +1 -1
  75. package/build-module/disabled/index.js +7 -26
  76. package/build-module/disabled/index.js.map +1 -1
  77. package/build-module/font-size-picker/index.js +1 -1
  78. package/build-module/font-size-picker/index.js.map +1 -1
  79. package/build-module/font-size-picker/styles.js +5 -13
  80. package/build-module/font-size-picker/styles.js.map +1 -1
  81. package/build-module/font-size-picker/utils.js +1 -1
  82. package/build-module/font-size-picker/utils.js.map +1 -1
  83. package/build-module/form-token-field/suggestions-list.js +5 -5
  84. package/build-module/form-token-field/suggestions-list.js.map +1 -1
  85. package/build-module/higher-order/with-fallback-styles/index.js +2 -2
  86. package/build-module/higher-order/with-fallback-styles/index.js.map +1 -1
  87. package/build-module/index.js +2 -1
  88. package/build-module/index.js.map +1 -1
  89. package/build-module/modal/aria-helper.js +2 -3
  90. package/build-module/modal/aria-helper.js.map +1 -1
  91. package/build-module/modal/index.js +44 -12
  92. package/build-module/modal/index.js.map +1 -1
  93. package/build-module/modal/types.js +2 -0
  94. package/build-module/modal/types.js.map +1 -0
  95. package/build-module/navigator/index.js +4 -4
  96. package/build-module/navigator/index.js.map +1 -1
  97. package/build-module/navigator/navigator-back-button/component.js +3 -3
  98. package/build-module/navigator/navigator-back-button/component.js.map +1 -1
  99. package/build-module/navigator/navigator-back-button/index.js +1 -1
  100. package/build-module/navigator/navigator-back-button/index.js.map +1 -1
  101. package/build-module/navigator/navigator-button/component.js +3 -3
  102. package/build-module/navigator/navigator-button/component.js.map +1 -1
  103. package/build-module/navigator/navigator-button/index.js +1 -1
  104. package/build-module/navigator/navigator-button/index.js.map +1 -1
  105. package/build-module/navigator/navigator-provider/component.js +8 -6
  106. package/build-module/navigator/navigator-provider/component.js.map +1 -1
  107. package/build-module/navigator/navigator-provider/index.js +1 -1
  108. package/build-module/navigator/navigator-provider/index.js.map +1 -1
  109. package/build-module/navigator/navigator-screen/component.js +12 -26
  110. package/build-module/navigator/navigator-screen/component.js.map +1 -1
  111. package/build-module/navigator/navigator-screen/index.js +1 -1
  112. package/build-module/navigator/navigator-screen/index.js.map +1 -1
  113. package/build-module/sandbox/index.js +56 -59
  114. package/build-module/sandbox/index.js.map +1 -1
  115. package/build-module/sandbox/index.native.js +54 -52
  116. package/build-module/sandbox/index.native.js.map +1 -1
  117. package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
  118. package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
  119. package/build-module/tab-panel/index.js +4 -4
  120. package/build-module/tab-panel/index.js.map +1 -1
  121. package/build-module/theme/index.js +52 -0
  122. package/build-module/theme/index.js.map +1 -0
  123. package/build-module/theme/styles.js +25 -0
  124. package/build-module/theme/styles.js.map +1 -0
  125. package/build-module/theme/types.js +2 -0
  126. package/build-module/theme/types.js.map +1 -0
  127. package/build-module/tools-panel/tools-panel/hook.js +3 -3
  128. package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
  129. package/build-module/tools-panel/tools-panel-item/hook.js +6 -6
  130. package/build-module/tools-panel/tools-panel-item/hook.js.map +1 -1
  131. package/build-module/tooltip/index.js +4 -1
  132. package/build-module/tooltip/index.js.map +1 -1
  133. package/build-module/tooltip/index.native.js +17 -4
  134. package/build-module/tooltip/index.native.js.map +1 -1
  135. package/build-style/style-rtl.css +26 -22
  136. package/build-style/style.css +26 -22
  137. package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
  138. package/build-types/border-box-control/border-box-control/hook.d.ts +1 -0
  139. package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
  140. package/build-types/border-control/border-control/component.d.ts +1 -0
  141. package/build-types/border-control/border-control/component.d.ts.map +1 -1
  142. package/build-types/border-control/border-control/hook.d.ts +1 -0
  143. package/build-types/border-control/border-control/hook.d.ts.map +1 -1
  144. package/build-types/border-control/stories/index.d.ts +6 -0
  145. package/build-types/border-control/stories/index.d.ts.map +1 -1
  146. package/build-types/border-control/types.d.ts +4 -0
  147. package/build-types/border-control/types.d.ts.map +1 -1
  148. package/build-types/confirm-dialog/types.d.ts +5 -1
  149. package/build-types/confirm-dialog/types.d.ts.map +1 -1
  150. package/build-types/disabled/index.d.ts.map +1 -1
  151. package/build-types/font-size-picker/styles.d.ts.map +1 -1
  152. package/build-types/modal/aria-helper.d.ts +4 -4
  153. package/build-types/modal/aria-helper.d.ts.map +1 -1
  154. package/build-types/modal/index.d.ts +35 -2
  155. package/build-types/modal/index.d.ts.map +1 -1
  156. package/build-types/modal/stories/index.d.ts +9 -0
  157. package/build-types/modal/stories/index.d.ts.map +1 -0
  158. package/build-types/modal/test/aria-helper.d.ts +2 -0
  159. package/build-types/modal/test/aria-helper.d.ts.map +1 -0
  160. package/build-types/modal/test/index.d.ts +2 -0
  161. package/build-types/modal/test/index.d.ts.map +1 -0
  162. package/build-types/modal/types.d.ts +134 -0
  163. package/build-types/modal/types.d.ts.map +1 -0
  164. package/build-types/navigator/index.d.ts +4 -4
  165. package/build-types/navigator/index.d.ts.map +1 -1
  166. package/build-types/navigator/navigator-back-button/component.d.ts +4 -2
  167. package/build-types/navigator/navigator-back-button/component.d.ts.map +1 -1
  168. package/build-types/navigator/navigator-back-button/hook.d.ts +1 -0
  169. package/build-types/navigator/navigator-back-button/hook.d.ts.map +1 -1
  170. package/build-types/navigator/navigator-back-button/index.d.ts +1 -1
  171. package/build-types/navigator/navigator-back-button/index.d.ts.map +1 -1
  172. package/build-types/navigator/navigator-button/component.d.ts +4 -2
  173. package/build-types/navigator/navigator-button/component.d.ts.map +1 -1
  174. package/build-types/navigator/navigator-button/hook.d.ts +1 -0
  175. package/build-types/navigator/navigator-button/hook.d.ts.map +1 -1
  176. package/build-types/navigator/navigator-button/index.d.ts +1 -1
  177. package/build-types/navigator/navigator-button/index.d.ts.map +1 -1
  178. package/build-types/navigator/navigator-provider/component.d.ts +2 -2
  179. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
  180. package/build-types/navigator/navigator-provider/index.d.ts +1 -1
  181. package/build-types/navigator/navigator-provider/index.d.ts.map +1 -1
  182. package/build-types/navigator/navigator-screen/component.d.ts +2 -2
  183. package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
  184. package/build-types/navigator/navigator-screen/index.d.ts +1 -1
  185. package/build-types/navigator/navigator-screen/index.d.ts.map +1 -1
  186. package/build-types/navigator/stories/index.d.ts +9 -0
  187. package/build-types/navigator/stories/index.d.ts.map +1 -0
  188. package/build-types/navigator/test/index.d.ts +2 -0
  189. package/build-types/navigator/test/index.d.ts.map +1 -0
  190. package/build-types/navigator/types.d.ts +4 -1
  191. package/build-types/navigator/types.d.ts.map +1 -1
  192. package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts.map +1 -1
  193. package/build-types/tab-panel/index.d.ts.map +1 -1
  194. package/build-types/theme/index.d.ts +31 -0
  195. package/build-types/theme/index.d.ts.map +1 -0
  196. package/build-types/theme/stories/index.d.ts +13 -0
  197. package/build-types/theme/stories/index.d.ts.map +1 -0
  198. package/build-types/theme/styles.d.ts +10 -0
  199. package/build-types/theme/styles.d.ts.map +1 -0
  200. package/build-types/theme/test/index.d.ts +2 -0
  201. package/build-types/theme/test/index.d.ts.map +1 -0
  202. package/build-types/theme/types.d.ts +21 -0
  203. package/build-types/theme/types.d.ts.map +1 -0
  204. package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
  205. package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
  206. package/build-types/tooltip/index.d.ts.map +1 -1
  207. package/package.json +17 -17
  208. package/src/base-field/test/index.js +4 -6
  209. package/src/border-box-control/border-box-control/component.tsx +2 -0
  210. package/src/border-box-control/border-box-control/hook.ts +4 -0
  211. package/src/border-box-control/test/index.js +7 -2
  212. package/src/border-control/border-control/README.md +6 -0
  213. package/src/border-control/border-control/component.tsx +2 -0
  214. package/src/border-control/types.ts +4 -0
  215. package/src/button/style.scss +25 -25
  216. package/src/button/test/index.js +3 -5
  217. package/src/combobox-control/test/index.js +1 -1
  218. package/src/confirm-dialog/types.ts +6 -0
  219. package/src/date-time/time/test/index.tsx +2 -6
  220. package/src/disabled/index.tsx +11 -33
  221. package/src/disabled/test/index.tsx +14 -82
  222. package/src/dropdown/test/index.js +4 -3
  223. package/src/font-size-picker/index.tsx +1 -1
  224. package/src/font-size-picker/styles.ts +3 -1
  225. package/src/font-size-picker/test/index.tsx +2 -2
  226. package/src/font-size-picker/test/utils.ts +5 -5
  227. package/src/font-size-picker/utils.ts +1 -1
  228. package/src/form-file-upload/test/index.tsx +1 -1
  229. package/src/form-token-field/suggestions-list.tsx +5 -5
  230. package/src/higher-order/with-fallback-styles/index.js +6 -2
  231. package/src/higher-order/with-focus-outside/test/index.js +44 -45
  232. package/src/higher-order/with-focus-return/test/index.js +34 -30
  233. package/src/higher-order/with-notices/test/index.js +1 -1
  234. package/src/index.js +2 -1
  235. package/src/input-control/test/index.js +2 -2
  236. package/src/item-group/test/index.js +2 -2
  237. package/src/menu-item/test/index.js +0 -3
  238. package/src/mobile/bottom-sheet/test/range-cell.native.js +16 -14
  239. package/src/modal/README.md +53 -54
  240. package/src/modal/{aria-helper.js → aria-helper.ts} +5 -7
  241. package/src/modal/{index.js → index.tsx} +48 -12
  242. package/src/modal/stories/{index.js → index.tsx} +47 -42
  243. package/src/modal/test/{aria-helper.js → aria-helper.ts} +0 -0
  244. package/src/modal/test/{index.js → index.tsx} +13 -3
  245. package/src/modal/types.ts +144 -0
  246. package/src/navigation/test/index.js +1 -1
  247. package/src/navigator/index.ts +4 -4
  248. package/src/navigator/navigator-back-button/component.tsx +4 -4
  249. package/src/navigator/navigator-back-button/index.ts +1 -1
  250. package/src/navigator/navigator-button/component.tsx +4 -4
  251. package/src/navigator/navigator-button/index.ts +1 -1
  252. package/src/navigator/navigator-provider/component.tsx +6 -4
  253. package/src/navigator/navigator-provider/index.ts +1 -1
  254. package/src/navigator/navigator-screen/component.tsx +20 -26
  255. package/src/navigator/navigator-screen/index.ts +1 -1
  256. package/src/navigator/stories/index.tsx +210 -0
  257. package/src/navigator/test/index.tsx +509 -0
  258. package/src/navigator/types.ts +2 -0
  259. package/src/notice/test/__snapshots__/index.js.snap +39 -38
  260. package/src/notice/test/index.js +15 -36
  261. package/src/notice/test/list.js +6 -14
  262. package/src/number-control/test/index.js +3 -2
  263. package/src/panel/test/body.js +2 -2
  264. package/src/placeholder/style.scss +5 -0
  265. package/src/sandbox/index.js +62 -47
  266. package/src/sandbox/index.native.js +72 -52
  267. package/src/sandbox/test/index.js +7 -10
  268. package/src/shortcut/test/index.tsx +1 -1
  269. package/src/slot-fill/bubbles-virtually/slot-fill-provider.js +5 -3
  270. package/src/style.scss +4 -0
  271. package/src/tab-panel/index.tsx +4 -7
  272. package/src/text-highlight/test/index.tsx +1 -3
  273. package/src/theme/README.md +34 -0
  274. package/src/theme/index.tsx +51 -0
  275. package/src/theme/stories/index.tsx +47 -0
  276. package/src/theme/styles.ts +28 -0
  277. package/src/theme/test/index.tsx +101 -0
  278. package/src/theme/types.ts +21 -0
  279. package/src/toolbar/test/index.js +2 -2
  280. package/src/toolbar-group/test/index.js +6 -10
  281. package/src/tools-panel/test/index.js +4 -6
  282. package/src/tools-panel/tools-panel/hook.ts +2 -9
  283. package/src/tools-panel/tools-panel-item/hook.ts +17 -3
  284. package/src/tooltip/index.js +3 -0
  285. package/src/tooltip/index.native.js +15 -0
  286. package/src/tooltip/test/index.native.js +1 -2
  287. package/src/tree-grid/test/__snapshots__/cell.js.snap +1 -3
  288. package/src/tree-grid/test/__snapshots__/roving-tab-index-item.js.snap +17 -15
  289. package/src/tree-grid/test/__snapshots__/row.js.snap +25 -21
  290. package/src/tree-grid/test/cell.js +4 -4
  291. package/src/tree-grid/test/roving-tab-index-item.js +8 -8
  292. package/src/tree-grid/test/roving-tab-index.js +3 -3
  293. package/src/tree-grid/test/row.js +20 -16
  294. package/src/truncate/test/index.tsx +4 -4
  295. package/src/ui/shortcut/test/index.js +2 -1
  296. package/src/ui/spinner/test/index.js +14 -13
  297. package/src/ui/tooltip/test/index.js +16 -14
  298. package/src/utils/theme-variables.scss +8 -0
  299. package/src/visually-hidden/README.md +4 -0
  300. package/tsconfig.tsbuildinfo +1 -1
  301. package/src/navigator/stories/index.js +0 -194
  302. package/src/navigator/test/index.js +0 -472
@@ -0,0 +1,51 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { colord, extend } from 'colord';
5
+ import a11yPlugin from 'colord/plugins/a11y';
6
+ import namesPlugin from 'colord/plugins/names';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import type { ThemeProps } from './types';
12
+ import type { WordPressComponentProps } from '../ui/context';
13
+ import { Wrapper } from './styles';
14
+
15
+ extend( [ namesPlugin, a11yPlugin ] );
16
+
17
+ /**
18
+ * `Theme` allows defining theme variables for components in the `@wordpress/components` package.
19
+ *
20
+ * Multiple `Theme` components can be nested in order to override specific theme variables.
21
+ *
22
+ *
23
+ * @example
24
+ * ```jsx
25
+ * import { __experimentalTheme as Theme } from '@wordpress/components';
26
+ *
27
+ * const Example = () => {
28
+ * return (
29
+ * <Theme accent="red">
30
+ * <Button variant="primary">I'm red</Button>
31
+ * <Theme accent="blue">
32
+ * <Button variant="primary">I'm blue</Button>
33
+ * </Theme>
34
+ * </Theme>
35
+ * );
36
+ * };
37
+ * ```
38
+ */
39
+ function Theme( props: WordPressComponentProps< ThemeProps, 'div', true > ) {
40
+ const { accent } = props;
41
+ if ( accent && ! colord( accent ).isValid() ) {
42
+ // eslint-disable-next-line no-console
43
+ console.warn(
44
+ `wp.components.Theme: "${ accent }" is not a valid color value for the 'accent' prop.`
45
+ );
46
+ }
47
+
48
+ return <Wrapper { ...props } />;
49
+ }
50
+
51
+ export default Theme;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ComponentMeta, ComponentStory } from '@storybook/react';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import Theme from '../index';
10
+ import Button from '../../button';
11
+
12
+ const meta: ComponentMeta< typeof Theme > = {
13
+ component: Theme,
14
+ title: 'Components (Experimental)/Theme',
15
+ argTypes: {
16
+ accent: { control: { type: 'color' } },
17
+ },
18
+ parameters: {
19
+ controls: { expanded: true },
20
+ docs: { source: { state: 'open' } },
21
+ },
22
+ };
23
+ export default meta;
24
+
25
+ const Template: ComponentStory< typeof Theme > = ( args ) => (
26
+ <Theme { ...args }>
27
+ <Button variant="primary">Hello</Button>
28
+ </Theme>
29
+ );
30
+
31
+ export const Default = Template.bind( {} );
32
+ Default.args = {};
33
+
34
+ export const Nested: ComponentStory< typeof Theme > = ( args ) => (
35
+ <Theme accent="tomato">
36
+ <Button variant="primary">Outer theme (hardcoded)</Button>
37
+
38
+ <Theme { ...args }>
39
+ <Button variant="primary">
40
+ Inner theme (set via Storybook controls)
41
+ </Button>
42
+ </Theme>
43
+ </Theme>
44
+ );
45
+ Nested.args = {
46
+ accent: 'blue',
47
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { colord } from 'colord';
5
+ import styled from '@emotion/styled';
6
+ import { css } from '@emotion/react';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import type { ThemeProps } from './types';
12
+
13
+ const accentColor = ( { accent }: ThemeProps ) =>
14
+ accent
15
+ ? css`
16
+ --wp-components-color-accent: ${ accent };
17
+ --wp-components-color-accent-darker-10: ${ colord( accent )
18
+ .darken( 0.1 )
19
+ .toHex() };
20
+ --wp-components-color-accent-darker-20: ${ colord( accent )
21
+ .darken( 0.2 )
22
+ .toHex() };
23
+ `
24
+ : undefined;
25
+
26
+ export const Wrapper = styled.div< ThemeProps >`
27
+ ${ accentColor }
28
+ `;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen } from '@testing-library/react';
5
+ import type { ReactNode } from 'react';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import Theme from '../';
11
+
12
+ type MyThemableComponentProps = {
13
+ children: ReactNode;
14
+ };
15
+
16
+ const MyThemableComponent = ( props: MyThemableComponentProps ) => {
17
+ return (
18
+ <div
19
+ { ...props }
20
+ style={ {
21
+ color: 'var(--wp-components-color-accent)',
22
+ } }
23
+ />
24
+ );
25
+ };
26
+
27
+ describe( 'Theme', () => {
28
+ describe( 'accent color', () => {
29
+ it( 'it does not define the accent color (and its variations) as a CSS variable when the `accent` prop is undefined', () => {
30
+ render(
31
+ <Theme>
32
+ <MyThemableComponent>Inner</MyThemableComponent>
33
+ </Theme>
34
+ );
35
+
36
+ const inner = screen.getByText( 'Inner' );
37
+
38
+ if ( inner?.parentElement === null ) {
39
+ throw new Error(
40
+ 'Somehow the `Theme` component does not render a DOM element?'
41
+ );
42
+ }
43
+
44
+ const innerElementStyles = window.getComputedStyle(
45
+ inner?.parentElement
46
+ );
47
+
48
+ expect(
49
+ innerElementStyles.getPropertyValue(
50
+ '--wp-components-color-accent'
51
+ )
52
+ ).toBe( '' );
53
+
54
+ expect(
55
+ innerElementStyles.getPropertyValue(
56
+ '--wp-components-color-accent-darker-10'
57
+ )
58
+ ).toBe( '' );
59
+
60
+ expect(
61
+ innerElementStyles.getPropertyValue(
62
+ '--wp-components-color-accent-darker-20'
63
+ )
64
+ ).toBe( '' );
65
+ } );
66
+
67
+ it( 'it defines the accent color (and its variations) as a CSS variable', () => {
68
+ render(
69
+ <Theme accent="#123abc">
70
+ <MyThemableComponent>Inner</MyThemableComponent>
71
+ </Theme>
72
+ );
73
+
74
+ const inner = screen.getByText( 'Inner' );
75
+
76
+ expect( inner?.parentElement ).toHaveStyle( {
77
+ '--wp-components-color-accent': '#123abc',
78
+ '--wp-components-color-accent-darker-10': '#0e2c8d',
79
+ '--wp-components-color-accent-darker-20': '#091d5f',
80
+ } );
81
+ } );
82
+
83
+ describe( 'unsupported values', () => {
84
+ it.each( [
85
+ // Keywords
86
+ 'currentcolor',
87
+ 'initial',
88
+ 'reset',
89
+ 'inherit',
90
+ 'revert',
91
+ 'unset',
92
+ // CSS Custom properties
93
+ 'var( --my-variable )',
94
+ ] )( 'should warn when the value is "%s"', ( accentValue ) => {
95
+ render( <Theme accent={ accentValue } /> );
96
+
97
+ expect( console ).toHaveWarned();
98
+ } );
99
+ } );
100
+ } );
101
+ } );
@@ -0,0 +1,21 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ReactNode } from 'react';
5
+
6
+ export type ThemeProps = {
7
+ /**
8
+ * Used to set the accent color (used by components as the primary color).
9
+ *
10
+ * If an accent color is not defined, the default fallback value is the original
11
+ * WP Admin main theme color. No all valid CSS color syntaxes are supported —
12
+ * in particular, keywords (like `'currentcolor'`, `'inherit'`, `'initial'`,
13
+ * `'revert'`, `'unset'`...) and CSS custom properties (e.g.
14
+ * `var(--my-custom-property)`) are _not_ supported values for this property.
15
+ */
16
+ accent?: string;
17
+ /**
18
+ * The children elements.
19
+ */
20
+ children?: ReactNode;
21
+ };
@@ -21,10 +21,10 @@ describe( 'Toolbar', () => {
21
21
 
22
22
  expect(
23
23
  screen.getByLabelText( 'control1', { selector: 'button' } )
24
- ).toBeTruthy();
24
+ ).toBeInTheDocument();
25
25
  expect(
26
26
  screen.getByLabelText( 'control2', { selector: 'button' } )
27
- ).toBeTruthy();
27
+ ).toBeInTheDocument();
28
28
  } );
29
29
  } );
30
30
  } );
@@ -13,13 +13,13 @@ describe( 'ToolbarGroup', () => {
13
13
  it( 'should render an empty node, when controls are not passed', () => {
14
14
  const { container } = render( <ToolbarGroup /> );
15
15
 
16
- expect( container.innerHTML ).toBe( '' );
16
+ expect( container ).toBeEmptyDOMElement();
17
17
  } );
18
18
 
19
19
  it( 'should render an empty node, when controls are empty', () => {
20
20
  const { container } = render( <ToolbarGroup controls={ [] } /> );
21
21
 
22
- expect( container.innerHTML ).toBe( '' );
22
+ expect( container ).toBeEmptyDOMElement();
23
23
  } );
24
24
 
25
25
  it( 'should render a list of controls with buttons', () => {
@@ -36,10 +36,8 @@ describe( 'ToolbarGroup', () => {
36
36
  render( <ToolbarGroup controls={ controls } /> );
37
37
 
38
38
  const toolbarButton = screen.getByLabelText( 'WordPress' );
39
- expect( toolbarButton.getAttribute( 'aria-pressed' ) ).toBe(
40
- 'false'
41
- );
42
- expect( toolbarButton.getAttribute( 'type' ) ).toBe( 'button' );
39
+ expect( toolbarButton ).toHaveAttribute( 'aria-pressed', 'false' );
40
+ expect( toolbarButton ).toHaveAttribute( 'type', 'button' );
43
41
  } );
44
42
 
45
43
  it( 'should render a list of controls with buttons and active control', () => {
@@ -56,10 +54,8 @@ describe( 'ToolbarGroup', () => {
56
54
  render( <ToolbarGroup controls={ controls } /> );
57
55
 
58
56
  const toolbarButton = screen.getByLabelText( 'WordPress' );
59
- expect( toolbarButton.getAttribute( 'aria-pressed' ) ).toBe(
60
- 'true'
61
- );
62
- expect( toolbarButton.getAttribute( 'type' ) ).toBe( 'button' );
57
+ expect( toolbarButton ).toHaveAttribute( 'aria-pressed', 'true' );
58
+ expect( toolbarButton ).toHaveAttribute( 'type', 'button' );
63
59
  } );
64
60
 
65
61
  it( 'should render a nested list of controls with separator between', () => {
@@ -295,7 +295,7 @@ describe( 'ToolsPanel', () => {
295
295
  expect( control ).toBeInTheDocument();
296
296
 
297
297
  // Test the aria live announcement.
298
- const announcement = await screen.getByText( 'Alt is now visible' );
298
+ const announcement = screen.getByText( 'Alt is now visible' );
299
299
  expect( announcement ).toHaveAttribute( 'aria-live', 'assertive' );
300
300
  } );
301
301
 
@@ -308,7 +308,7 @@ describe( 'ToolsPanel', () => {
308
308
  expect( control ).not.toBeInTheDocument();
309
309
 
310
310
  // Test the aria live announcement.
311
- const announcement = await screen.getByText(
311
+ const announcement = screen.getByText(
312
312
  'Example hidden and reset to default'
313
313
  );
314
314
  expect( announcement ).toHaveAttribute( 'aria-live', 'assertive' );
@@ -337,9 +337,7 @@ describe( 'ToolsPanel', () => {
337
337
  expect( resetControl ).toBeInTheDocument();
338
338
 
339
339
  // Test the aria live announcement.
340
- const announcement = await screen.getByText(
341
- 'Example reset to default'
342
- );
340
+ const announcement = screen.getByText( 'Example reset to default' );
343
341
  expect( announcement ).toHaveAttribute( 'aria-live', 'assertive' );
344
342
  } );
345
343
 
@@ -1057,7 +1055,7 @@ describe( 'ToolsPanel', () => {
1057
1055
  await selectMenuItem( 'Reset all' );
1058
1056
 
1059
1057
  // Test the aria live announcement.
1060
- const announcement = await screen.getByText( 'All options reset' );
1058
+ const announcement = screen.getByText( 'All options reset' );
1061
1059
  expect( announcement ).toHaveAttribute( 'aria-live', 'assertive' );
1062
1060
 
1063
1061
  const disabledResetAllItem = await screen.findByRole( 'menuitem', {
@@ -139,7 +139,7 @@ export function useToolsPanel(
139
139
  } );
140
140
  return items;
141
141
  } );
142
- }, [ generateMenuItems, panelItems, setMenuItems ] );
142
+ }, [ panelItems, setMenuItems ] );
143
143
 
144
144
  // Force a menu item to be checked.
145
145
  // This is intended for use with default panel items. They are displayed
@@ -255,13 +255,7 @@ export function useToolsPanel(
255
255
  shouldReset: true,
256
256
  } );
257
257
  setMenuItems( resetMenuItems );
258
- }, [
259
- generateMenuItems,
260
- isResetting.current,
261
- panelItems,
262
- resetAll,
263
- setMenuItems,
264
- ] );
258
+ }, [ panelItems, resetAll, setMenuItems ] );
265
259
 
266
260
  // Assist ItemGroup styling when there are potentially hidden placeholder
267
261
  // items by identifying first & last items that are toggled on for display.
@@ -300,7 +294,6 @@ export function useToolsPanel(
300
294
  deregisterPanelItem,
301
295
  firstDisplayedItem,
302
296
  flagItemCustomization,
303
- isResetting.current,
304
297
  lastDisplayedItem,
305
298
  menuItems,
306
299
  panelId,
@@ -42,8 +42,11 @@ export function useToolsPanelItem(
42
42
  __experimentalLastVisibleItemClass,
43
43
  } = useToolsPanelContext();
44
44
 
45
- const hasValueCallback = useCallback( hasValue, [ panelId ] );
46
- const resetAllFilterCallback = useCallback( resetAllFilter, [ panelId ] );
45
+ const hasValueCallback = useCallback( hasValue, [ panelId, hasValue ] );
46
+ const resetAllFilterCallback = useCallback( resetAllFilter, [
47
+ panelId,
48
+ resetAllFilter,
49
+ ] );
47
50
  const previousPanelId = usePrevious( currentPanelId );
48
51
 
49
52
  const hasMatchingPanel =
@@ -79,6 +82,8 @@ export function useToolsPanelItem(
79
82
  panelId,
80
83
  previousPanelId,
81
84
  resetAllFilterCallback,
85
+ registerPanelItem,
86
+ deregisterPanelItem,
82
87
  ] );
83
88
 
84
89
  const isValueSet = hasValue();
@@ -90,7 +95,13 @@ export function useToolsPanelItem(
90
95
  if ( isShownByDefault && isValueSet && ! wasValueSet ) {
91
96
  flagItemCustomization( label );
92
97
  }
93
- }, [ isValueSet, wasValueSet, isShownByDefault, label ] );
98
+ }, [
99
+ isValueSet,
100
+ wasValueSet,
101
+ isShownByDefault,
102
+ label,
103
+ flagItemCustomization,
104
+ ] );
94
105
 
95
106
  // Note: `label` is used as a key when building menu item state in
96
107
  // `ToolsPanel`.
@@ -118,6 +129,8 @@ export function useToolsPanelItem(
118
129
  isResetting,
119
130
  isValueSet,
120
131
  wasMenuItemChecked,
132
+ onSelect,
133
+ onDeselect,
121
134
  ] );
122
135
 
123
136
  // The item is shown if it is a default control regardless of whether it
@@ -153,6 +166,7 @@ export function useToolsPanelItem(
153
166
  lastDisplayedItem,
154
167
  __experimentalFirstVisibleItemClass,
155
168
  __experimentalLastVisibleItemClass,
169
+ label,
156
170
  ] );
157
171
 
158
172
  return {
@@ -228,6 +228,9 @@ function Tooltip( props ) {
228
228
  document.removeEventListener( 'mouseup', cancelIsMouseDown );
229
229
  };
230
230
 
231
+ // Ignore reason: updating the deps array here could cause unexpected changes in behavior.
232
+ // Deferring until a more detailed investigation/refactor can be performed.
233
+ // eslint-disable-next-line react-hooks/exhaustive-deps
231
234
  useEffect( () => clearOnUnmount, [] );
232
235
 
233
236
  if ( Children.count( children ) !== 1 ) {
@@ -62,6 +62,9 @@ const useKeyboardVisibility = () => {
62
62
  showListener.remove();
63
63
  hideListener.remove();
64
64
  };
65
+ // Disable reason: deferring this refactor to the native team.
66
+ // see https://github.com/WordPress/gutenberg/pull/41166
67
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
68
  }, [] );
66
69
 
67
70
  return keyboardVisible;
@@ -102,6 +105,9 @@ const Tooltip = ( {
102
105
  } );
103
106
  }
104
107
  return () => onHandleScreenTouch( null );
108
+ // Disable reason: deferring this refactor to the native team.
109
+ // see https://github.com/WordPress/gutenberg/pull/41166
110
+ // eslint-disable-next-line react-hooks/exhaustive-deps
105
111
  }, [ visible ] );
106
112
 
107
113
  // Manage visibility animation.
@@ -115,6 +121,9 @@ const Tooltip = ( {
115
121
  setAnimating( true );
116
122
  startAnimation();
117
123
  }
124
+ // Disable reason: deferring this refactor to the native team.
125
+ // see https://github.com/WordPress/gutenberg/pull/41166
126
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
127
  }, [ visible ] );
119
128
 
120
129
  // Manage tooltip visibility and position in relation to keyboard.
@@ -133,6 +142,9 @@ const Tooltip = ( {
133
142
  setAnimating( true );
134
143
  setVisible( false );
135
144
  }
145
+ // Disable reason: deferring this refactor to the native team.
146
+ // see https://github.com/WordPress/gutenberg/pull/41166
147
+ // eslint-disable-next-line react-hooks/exhaustive-deps
136
148
  }, [ visible, keyboardVisible ] );
137
149
 
138
150
  // Manage tooltip position during keyboard frame changes.
@@ -261,6 +273,9 @@ const TooltipSlot = ( { children, ...rest } ) => {
261
273
  setHandleScreenTouch( null );
262
274
  };
263
275
  // Memoize context value to avoid unnecessary rerenders of the Provider's children
276
+ // Disable reason: deferring this refactor to the native team.
277
+ // see https://github.com/WordPress/gutenberg/pull/41166
278
+ // eslint-disable-next-line react-hooks/exhaustive-deps
264
279
  const value = useMemo( () => ( { onHandleScreenTouch } ) );
265
280
 
266
281
  return (
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { act } from 'react-test-renderer';
5
- import { fireEvent, render } from 'test/helpers';
4
+ import { fireEvent, render, act } from 'test/helpers';
6
5
  import { Keyboard, Text } from 'react-native';
7
6
 
8
7
  /**
@@ -5,7 +5,6 @@ exports[`TreeGridCell uses a child render function to render children 1`] = `
5
5
  role="application"
6
6
  >
7
7
  <table
8
- onKeyDown={[Function]}
9
8
  role="treegrid"
10
9
  >
11
10
  <tbody>
@@ -14,8 +13,7 @@ exports[`TreeGridCell uses a child render function to render children 1`] = `
14
13
  role="gridcell"
15
14
  >
16
15
  <button
17
- className="my-button"
18
- onFocus={[Function]}
16
+ class="my-button"
19
17
  >
20
18
  Click Me!
21
19
  </button>
@@ -1,25 +1,27 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`RovingTabIndexItem allows another component to be specified as the rendered component using the \`as\` prop 1`] = `
4
- <button
5
- onFocus={[Function]}
6
- />
4
+ <div>
5
+ <button />
6
+ </div>
7
7
  `;
8
8
 
9
9
  exports[`RovingTabIndexItem allows children to be declared using a child render function as an alternative to \`as\` 1`] = `
10
- <button
11
- className="my-button"
12
- onFocus={[Function]}
13
- >
14
- Click Me!
15
- </button>
10
+ <div>
11
+ <button
12
+ class="my-button"
13
+ >
14
+ Click Me!
15
+ </button>
16
+ </div>
16
17
  `;
17
18
 
18
19
  exports[`RovingTabIndexItem forwards props to the \`as\` component 1`] = `
19
- <button
20
- className="my-button"
21
- onFocus={[Function]}
22
- >
23
- Click Me!
24
- </button>
20
+ <div>
21
+ <button
22
+ class="my-button"
23
+ >
24
+ Click Me!
25
+ </button>
26
+ </div>
25
27
  `;
@@ -2,31 +2,35 @@
2
2
 
3
3
  exports[`TreeGridRow forwards other props to the rendered tr element 1`] = `
4
4
  <table>
5
- <tr
6
- aria-level="1"
7
- aria-posinset="1"
8
- aria-setsize="1"
9
- className="my-row"
10
- role="row"
11
- >
12
- <td>
13
- Test
14
- </td>
15
- </tr>
5
+ <tbody>
6
+ <tr
7
+ aria-level="1"
8
+ aria-posinset="1"
9
+ aria-setsize="1"
10
+ class="my-row"
11
+ role="row"
12
+ >
13
+ <td>
14
+ Test
15
+ </td>
16
+ </tr>
17
+ </tbody>
16
18
  </table>
17
19
  `;
18
20
 
19
21
  exports[`TreeGridRow renders a tr with support for level, positionInSet and setSize props 1`] = `
20
22
  <table>
21
- <tr
22
- aria-level="1"
23
- aria-posinset="1"
24
- aria-setsize="1"
25
- role="row"
26
- >
27
- <td>
28
- Test
29
- </td>
30
- </tr>
23
+ <tbody>
24
+ <tr
25
+ aria-level="1"
26
+ aria-posinset="1"
27
+ aria-setsize="1"
28
+ role="row"
29
+ >
30
+ <td>
31
+ Test
32
+ </td>
33
+ </tr>
34
+ </tbody>
31
35
  </table>
32
36
  `;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import TestRenderer from 'react-test-renderer';
4
+ import { render } from '@testing-library/react';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -21,7 +21,7 @@ const TestButton = forwardRef( ( { ...props }, ref ) => (
21
21
  describe( 'TreeGridCell', () => {
22
22
  it( 'requires TreeGrid to be declared as a parent component somewhere in the component hierarchy', () => {
23
23
  expect( () =>
24
- TestRenderer.create(
24
+ render(
25
25
  <TreeGridCell>
26
26
  { ( props ) => (
27
27
  <TestButton className="my-button" { ...props }>
@@ -35,7 +35,7 @@ describe( 'TreeGridCell', () => {
35
35
  } );
36
36
 
37
37
  it( 'uses a child render function to render children', () => {
38
- const renderer = TestRenderer.create(
38
+ const { container } = render(
39
39
  <TreeGrid>
40
40
  <tr>
41
41
  <TreeGridCell>
@@ -49,6 +49,6 @@ describe( 'TreeGridCell', () => {
49
49
  </TreeGrid>
50
50
  );
51
51
 
52
- expect( renderer.toJSON() ).toMatchSnapshot();
52
+ expect( container.firstChild ).toMatchSnapshot();
53
53
  } );
54
54
  } );