@wordpress/components 23.2.0 → 23.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 (377) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/CONTRIBUTING.md +1 -1
  3. package/build/alignment-matrix-control/utils.js +2 -2
  4. package/build/alignment-matrix-control/utils.js.map +1 -1
  5. package/build/autocomplete/autocompleter-ui.js +1 -3
  6. package/build/autocomplete/autocompleter-ui.js.map +1 -1
  7. package/build/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  8. package/build/border-box-control/border-box-control-linked-button/hook.js.map +1 -1
  9. package/build/border-control/border-control-dropdown/component.js +8 -4
  10. package/build/border-control/border-control-dropdown/component.js.map +1 -1
  11. package/build/button/deprecated.js +8 -6
  12. package/build/button/deprecated.js.map +1 -1
  13. package/build/button/index.js +52 -23
  14. package/build/button/index.js.map +1 -1
  15. package/build/button/types.js +6 -0
  16. package/build/button/types.js.map +1 -0
  17. package/build/color-list-picker/index.js.map +1 -1
  18. package/build/color-list-picker/types.js +6 -0
  19. package/build/color-list-picker/types.js.map +1 -0
  20. package/build/color-palette/index.js +9 -61
  21. package/build/color-palette/index.js.map +1 -1
  22. package/build/color-palette/index.native.js +24 -9
  23. package/build/color-palette/index.native.js.map +1 -1
  24. package/build/color-palette/utils.js +103 -0
  25. package/build/color-palette/utils.js.map +1 -0
  26. package/build/custom-gradient-picker/gradient-bar/utils.js +1 -1
  27. package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  28. package/build/date-time/date/index.js.map +1 -1
  29. package/build/dropdown/index.js +20 -8
  30. package/build/dropdown/index.js.map +1 -1
  31. package/build/form-token-field/token.js +1 -1
  32. package/build/form-token-field/token.js.map +1 -1
  33. package/build/gradient-picker/index.js +9 -1
  34. package/build/gradient-picker/index.js.map +1 -1
  35. package/build/h-stack/component.js +0 -1
  36. package/build/h-stack/component.js.map +1 -1
  37. package/build/input-control/input-field.js +4 -2
  38. package/build/input-control/input-field.js.map +1 -1
  39. package/build/keyboard-shortcuts/index.js +44 -16
  40. package/build/keyboard-shortcuts/index.js.map +1 -1
  41. package/build/keyboard-shortcuts/types.js +6 -0
  42. package/build/keyboard-shortcuts/types.js.map +1 -0
  43. package/build/modal/index.js +1 -1
  44. package/build/modal/index.js.map +1 -1
  45. package/build/notice/index.js +16 -18
  46. package/build/notice/index.js.map +1 -1
  47. package/build/notice/list.js +23 -8
  48. package/build/notice/list.js.map +1 -1
  49. package/build/notice/types.js +6 -0
  50. package/build/notice/types.js.map +1 -0
  51. package/build/number-control/index.js +1 -1
  52. package/build/number-control/index.js.map +1 -1
  53. package/build/query-controls/author-select.js +7 -3
  54. package/build/query-controls/author-select.js.map +1 -1
  55. package/build/query-controls/category-select.js +7 -3
  56. package/build/query-controls/category-select.js.map +1 -1
  57. package/build/query-controls/index.js +68 -20
  58. package/build/query-controls/index.js.map +1 -1
  59. package/build/query-controls/terms.js +4 -3
  60. package/build/query-controls/terms.js.map +1 -1
  61. package/build/query-controls/types.js +6 -0
  62. package/build/query-controls/types.js.map +1 -0
  63. package/build/slot-fill/bubbles-virtually/fill.js +1 -0
  64. package/build/slot-fill/bubbles-virtually/fill.js.map +1 -1
  65. package/build/slot-fill/slot.js +1 -0
  66. package/build/slot-fill/slot.js.map +1 -1
  67. package/build/slot-fill/use-slot.js +1 -11
  68. package/build/slot-fill/use-slot.js.map +1 -1
  69. package/build/snackbar/index.js.map +1 -1
  70. package/build/snackbar/list.js.map +1 -1
  71. package/build/tab-panel/index.js +36 -8
  72. package/build/tab-panel/index.js.map +1 -1
  73. package/build/tree-grid/index.js +1 -1
  74. package/build/tree-grid/index.js.map +1 -1
  75. package/build/tree-select/index.js +2 -6
  76. package/build/tree-select/index.js.map +1 -1
  77. package/build-module/alignment-matrix-control/utils.js +2 -2
  78. package/build-module/alignment-matrix-control/utils.js.map +1 -1
  79. package/build-module/autocomplete/autocompleter-ui.js +1 -2
  80. package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
  81. package/build-module/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  82. package/build-module/border-box-control/border-box-control-linked-button/hook.js.map +1 -1
  83. package/build-module/border-control/border-control-dropdown/component.js +7 -4
  84. package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
  85. package/build-module/button/deprecated.js +8 -5
  86. package/build-module/button/deprecated.js.map +1 -1
  87. package/build-module/button/index.js +51 -22
  88. package/build-module/button/index.js.map +1 -1
  89. package/build-module/button/types.js +2 -0
  90. package/build-module/button/types.js.map +1 -0
  91. package/build-module/color-list-picker/index.js.map +1 -1
  92. package/build-module/color-list-picker/types.js +2 -0
  93. package/build-module/color-list-picker/types.js.map +1 -0
  94. package/build-module/color-palette/index.js +7 -54
  95. package/build-module/color-palette/index.js.map +1 -1
  96. package/build-module/color-palette/index.native.js +24 -8
  97. package/build-module/color-palette/index.native.js.map +1 -1
  98. package/build-module/color-palette/utils.js +79 -0
  99. package/build-module/color-palette/utils.js.map +1 -0
  100. package/build-module/custom-gradient-picker/gradient-bar/utils.js +1 -1
  101. package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  102. package/build-module/date-time/date/index.js +1 -1
  103. package/build-module/date-time/date/index.js.map +1 -1
  104. package/build-module/dropdown/index.js +19 -8
  105. package/build-module/dropdown/index.js.map +1 -1
  106. package/build-module/form-token-field/token.js +1 -1
  107. package/build-module/form-token-field/token.js.map +1 -1
  108. package/build-module/gradient-picker/index.js +9 -2
  109. package/build-module/gradient-picker/index.js.map +1 -1
  110. package/build-module/h-stack/component.js +0 -1
  111. package/build-module/h-stack/component.js.map +1 -1
  112. package/build-module/input-control/input-field.js +4 -2
  113. package/build-module/input-control/input-field.js.map +1 -1
  114. package/build-module/keyboard-shortcuts/index.js +48 -16
  115. package/build-module/keyboard-shortcuts/index.js.map +1 -1
  116. package/build-module/keyboard-shortcuts/types.js +2 -0
  117. package/build-module/keyboard-shortcuts/types.js.map +1 -0
  118. package/build-module/modal/index.js +1 -1
  119. package/build-module/modal/index.js.map +1 -1
  120. package/build-module/notice/index.js +14 -15
  121. package/build-module/notice/index.js.map +1 -1
  122. package/build-module/notice/list.js +23 -8
  123. package/build-module/notice/list.js.map +1 -1
  124. package/build-module/notice/types.js +2 -0
  125. package/build-module/notice/types.js.map +1 -0
  126. package/build-module/number-control/index.js +1 -1
  127. package/build-module/number-control/index.js.map +1 -1
  128. package/build-module/query-controls/author-select.js +7 -3
  129. package/build-module/query-controls/author-select.js.map +1 -1
  130. package/build-module/query-controls/category-select.js +8 -4
  131. package/build-module/query-controls/category-select.js.map +1 -1
  132. package/build-module/query-controls/index.js +64 -20
  133. package/build-module/query-controls/index.js.map +1 -1
  134. package/build-module/query-controls/terms.js +8 -4
  135. package/build-module/query-controls/terms.js.map +1 -1
  136. package/build-module/query-controls/types.js +2 -0
  137. package/build-module/query-controls/types.js.map +1 -0
  138. package/build-module/slot-fill/bubbles-virtually/fill.js +1 -0
  139. package/build-module/slot-fill/bubbles-virtually/fill.js.map +1 -1
  140. package/build-module/slot-fill/slot.js +1 -0
  141. package/build-module/slot-fill/slot.js.map +1 -1
  142. package/build-module/slot-fill/use-slot.js +2 -12
  143. package/build-module/slot-fill/use-slot.js.map +1 -1
  144. package/build-module/snackbar/index.js.map +1 -1
  145. package/build-module/snackbar/list.js.map +1 -1
  146. package/build-module/tab-panel/index.js +36 -8
  147. package/build-module/tab-panel/index.js.map +1 -1
  148. package/build-module/tree-grid/index.js +1 -1
  149. package/build-module/tree-grid/index.js.map +1 -1
  150. package/build-module/tree-select/index.js +2 -6
  151. package/build-module/tree-select/index.js.map +1 -1
  152. package/build-style/style-rtl.css +5 -0
  153. package/build-style/style.css +5 -0
  154. package/build-types/border-box-control/border-box-control/hook.d.ts +1 -1
  155. package/build-types/border-box-control/border-box-control-linked-button/component.d.ts +1 -1
  156. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +171 -160
  157. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts.map +1 -1
  158. package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +1 -1
  159. package/build-types/border-control/border-control/hook.d.ts +1 -1
  160. package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
  161. package/build-types/border-control/border-control-dropdown/hook.d.ts +1 -1
  162. package/build-types/button/deprecated.d.ts +143 -7
  163. package/build-types/button/deprecated.d.ts.map +1 -1
  164. package/build-types/button/index.d.ts +20 -3
  165. package/build-types/button/index.d.ts.map +1 -1
  166. package/build-types/button/stories/index.d.ts +20 -0
  167. package/build-types/button/stories/index.d.ts.map +1 -0
  168. package/build-types/button/test/index.d.ts +2 -0
  169. package/build-types/button/test/index.d.ts.map +1 -0
  170. package/build-types/button/types.d.ts +134 -0
  171. package/build-types/button/types.d.ts.map +1 -0
  172. package/build-types/color-list-picker/index.d.ts +5 -0
  173. package/build-types/color-list-picker/index.d.ts.map +1 -0
  174. package/build-types/color-list-picker/types.d.ts +42 -0
  175. package/build-types/color-list-picker/types.d.ts.map +1 -0
  176. package/build-types/color-palette/index.d.ts +2 -4
  177. package/build-types/color-palette/index.d.ts.map +1 -1
  178. package/build-types/color-palette/stories/index.d.ts +2 -2
  179. package/build-types/color-palette/styles.d.ts +1 -1
  180. package/build-types/color-palette/types.d.ts +1 -1
  181. package/build-types/color-palette/types.d.ts.map +1 -1
  182. package/build-types/color-palette/utils.d.ts +14 -0
  183. package/build-types/color-palette/utils.d.ts.map +1 -0
  184. package/build-types/color-picker/styles.d.ts +2 -2
  185. package/build-types/date-time/date/index.d.ts.map +1 -1
  186. package/build-types/date-time/date/styles.d.ts +3 -3
  187. package/build-types/dropdown/index.d.ts +4 -4
  188. package/build-types/dropdown/index.d.ts.map +1 -1
  189. package/build-types/dropdown/stories/index.d.ts.map +1 -1
  190. package/build-types/dropdown/types.d.ts +9 -10
  191. package/build-types/dropdown/types.d.ts.map +1 -1
  192. package/build-types/font-size-picker/styles.d.ts +2 -2
  193. package/build-types/h-stack/component.d.ts +0 -1
  194. package/build-types/h-stack/component.d.ts.map +1 -1
  195. package/build-types/input-control/input-field.d.ts.map +1 -1
  196. package/build-types/keyboard-shortcuts/index.d.ts +38 -0
  197. package/build-types/keyboard-shortcuts/index.d.ts.map +1 -0
  198. package/build-types/keyboard-shortcuts/stories/index.d.ts +12 -0
  199. package/build-types/keyboard-shortcuts/stories/index.d.ts.map +1 -0
  200. package/build-types/keyboard-shortcuts/test/index.d.ts +2 -0
  201. package/build-types/keyboard-shortcuts/test/index.d.ts.map +1 -0
  202. package/build-types/keyboard-shortcuts/types.d.ts +48 -0
  203. package/build-types/keyboard-shortcuts/types.d.ts.map +1 -0
  204. package/build-types/modal/index.d.ts.map +1 -1
  205. package/build-types/navigator/navigator-back-button/component.d.ts +1 -1
  206. package/build-types/navigator/navigator-back-button/hook.d.ts +2 -2
  207. package/build-types/navigator/navigator-button/component.d.ts +1 -1
  208. package/build-types/navigator/navigator-button/hook.d.ts +2 -2
  209. package/build-types/notice/index.d.ts +16 -0
  210. package/build-types/notice/index.d.ts.map +1 -0
  211. package/build-types/notice/list.d.ts +32 -0
  212. package/build-types/notice/list.d.ts.map +1 -0
  213. package/build-types/notice/stories/index.d.ts +17 -0
  214. package/build-types/notice/stories/index.d.ts.map +1 -0
  215. package/build-types/notice/test/index.d.ts +2 -0
  216. package/build-types/notice/test/index.d.ts.map +1 -0
  217. package/build-types/notice/test/list.d.ts +2 -0
  218. package/build-types/notice/test/list.d.ts.map +1 -0
  219. package/build-types/notice/types.d.ts +128 -0
  220. package/build-types/notice/types.d.ts.map +1 -0
  221. package/build-types/number-control/styles/number-control-styles.d.ts +2 -2
  222. package/build-types/number-control/styles/number-control-styles.d.ts.map +1 -1
  223. package/build-types/placeholder/stories/index.d.ts.map +1 -1
  224. package/build-types/query-controls/author-select.d.ts +4 -0
  225. package/build-types/query-controls/author-select.d.ts.map +1 -0
  226. package/build-types/query-controls/category-select.d.ts +4 -0
  227. package/build-types/query-controls/category-select.d.ts.map +1 -0
  228. package/build-types/query-controls/index.d.ts +30 -0
  229. package/build-types/query-controls/index.d.ts.map +1 -0
  230. package/build-types/query-controls/stories/index.d.ts +13 -0
  231. package/build-types/query-controls/stories/index.d.ts.map +1 -0
  232. package/build-types/query-controls/terms.d.ts +13 -0
  233. package/build-types/query-controls/terms.d.ts.map +1 -0
  234. package/build-types/query-controls/test/terms.d.ts +2 -0
  235. package/build-types/query-controls/test/terms.d.ts.map +1 -0
  236. package/build-types/query-controls/types.d.ts +131 -0
  237. package/build-types/query-controls/types.d.ts.map +1 -0
  238. package/build-types/range-control/index.d.ts +1 -1
  239. package/build-types/slot-fill/bubbles-virtually/fill.d.ts.map +1 -1
  240. package/build-types/slot-fill/use-slot.d.ts.map +1 -1
  241. package/build-types/snackbar/index.d.ts +9 -2
  242. package/build-types/snackbar/index.d.ts.map +1 -1
  243. package/build-types/snackbar/list.d.ts.map +1 -1
  244. package/build-types/snackbar/types.d.ts +15 -88
  245. package/build-types/snackbar/types.d.ts.map +1 -1
  246. package/build-types/tab-panel/index.d.ts.map +1 -1
  247. package/build-types/tab-panel/types.d.ts +1 -1
  248. package/build-types/tab-panel/types.d.ts.map +1 -1
  249. package/build-types/toggle-group-control/stories/index.d.ts.map +1 -1
  250. package/build-types/tree-select/index.d.ts.map +1 -1
  251. package/build-types/ui/form-group/form-group.d.ts +2 -2
  252. package/package.json +18 -17
  253. package/src/alignment-matrix-control/utils.tsx +2 -2
  254. package/src/autocomplete/autocompleter-ui.js +1 -2
  255. package/src/autocomplete/test/index.js +1 -5
  256. package/src/border-box-control/border-box-control-linked-button/component.tsx +1 -1
  257. package/src/border-box-control/border-box-control-linked-button/hook.ts +1 -1
  258. package/src/border-control/border-control-dropdown/component.tsx +9 -8
  259. package/src/box-control/test/index.js +11 -35
  260. package/src/button/README.md +49 -55
  261. package/src/button/{deprecated.js → deprecated.tsx} +19 -4
  262. package/src/button/{index.js → index.tsx} +95 -34
  263. package/src/button/stories/index.tsx +106 -0
  264. package/src/button/style.scss +3 -2
  265. package/src/button/test/{index.js → index.tsx} +30 -7
  266. package/src/button/types.ts +138 -0
  267. package/src/checkbox-control/test/index.tsx +1 -5
  268. package/src/color-list-picker/{index.js → index.tsx} +3 -2
  269. package/src/color-list-picker/types.ts +46 -0
  270. package/src/color-palette/README.md +1 -1
  271. package/src/color-palette/index.native.js +11 -4
  272. package/src/color-palette/index.tsx +11 -67
  273. package/src/color-palette/test/index.tsx +4 -14
  274. package/src/color-palette/test/utils.ts +1 -1
  275. package/src/color-palette/types.ts +1 -1
  276. package/src/color-palette/utils.ts +98 -0
  277. package/src/color-picker/test/index.js +6 -15
  278. package/src/combobox-control/test/index.js +1 -6
  279. package/src/confirm-dialog/test/index.js +9 -29
  280. package/src/custom-gradient-picker/gradient-bar/utils.js +1 -1
  281. package/src/date-time/date/index.tsx +2 -1
  282. package/src/date-time/date/test/index.tsx +2 -8
  283. package/src/date-time/time/test/index.tsx +9 -29
  284. package/src/dimension-control/test/index.test.js +2 -8
  285. package/src/disabled/test/index.tsx +1 -5
  286. package/src/draggable/test/index.native.js +4 -4
  287. package/src/dropdown/README.md +1 -8
  288. package/src/dropdown/index.tsx +17 -6
  289. package/src/dropdown/stories/index.tsx +3 -3
  290. package/src/dropdown/test/index.tsx +2 -8
  291. package/src/dropdown/types.ts +9 -10
  292. package/src/dropdown-menu/README.md +1 -1
  293. package/src/dropdown-menu/stories/index.js +96 -27
  294. package/src/dropdown-menu/test/index.js +2 -8
  295. package/src/external-link/test/index.tsx +1 -6
  296. package/src/focal-point-picker/test/index.js +3 -11
  297. package/src/font-size-picker/test/index.tsx +14 -44
  298. package/src/form-file-upload/test/index.tsx +2 -17
  299. package/src/form-toggle/test/index.tsx +1 -5
  300. package/src/form-token-field/test/index.tsx +80 -163
  301. package/src/form-token-field/token.tsx +1 -1
  302. package/src/gradient-picker/index.js +15 -4
  303. package/src/guide/test/index.js +5 -17
  304. package/src/h-stack/component.tsx +0 -1
  305. package/src/higher-order/with-filters/test/index.js +24 -24
  306. package/src/higher-order/with-focus-outside/test/index.js +11 -25
  307. package/src/higher-order/with-focus-return/test/index.js +1 -5
  308. package/src/input-control/input-field.tsx +3 -1
  309. package/src/input-control/test/index.js +1 -6
  310. package/src/isolated-event-container/test/index.js +2 -8
  311. package/src/keyboard-shortcuts/README.md +1 -1
  312. package/src/keyboard-shortcuts/index.tsx +93 -0
  313. package/src/keyboard-shortcuts/stories/index.tsx +60 -0
  314. package/src/keyboard-shortcuts/test/{index.js → index.tsx} +16 -6
  315. package/src/keyboard-shortcuts/types.ts +51 -0
  316. package/src/modal/index.tsx +1 -2
  317. package/src/navigable-container/test/navigable-menu.js +5 -17
  318. package/src/navigable-container/test/tababble-container.js +3 -11
  319. package/src/navigation/test/index.js +3 -11
  320. package/src/navigator/test/index.tsx +6 -20
  321. package/src/notice/README.md +89 -42
  322. package/src/notice/{index.js → index.tsx} +28 -20
  323. package/src/notice/list.tsx +72 -0
  324. package/src/notice/stories/index.tsx +119 -0
  325. package/src/notice/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
  326. package/src/notice/test/{index.js → index.tsx} +7 -4
  327. package/src/notice/test/{list.js → list.tsx} +0 -0
  328. package/src/notice/types.ts +136 -0
  329. package/src/number-control/index.tsx +1 -1
  330. package/src/number-control/test/index.tsx +28 -86
  331. package/src/panel/test/body.js +2 -8
  332. package/src/placeholder/stories/index.tsx +1 -0
  333. package/src/query-controls/README.md +56 -56
  334. package/src/query-controls/author-select.tsx +37 -0
  335. package/src/query-controls/category-select.tsx +46 -0
  336. package/src/query-controls/index.tsx +192 -0
  337. package/src/query-controls/stories/index.tsx +205 -0
  338. package/src/query-controls/terms.ts +57 -0
  339. package/src/query-controls/test/{terms.js → terms.ts} +36 -20
  340. package/src/query-controls/types.ts +150 -0
  341. package/src/select-control/test/select-control.tsx +1 -6
  342. package/src/slot-fill/bubbles-virtually/fill.js +1 -0
  343. package/src/slot-fill/slot.js +1 -1
  344. package/src/slot-fill/use-slot.js +6 -16
  345. package/src/snackbar/index.tsx +6 -5
  346. package/src/snackbar/list.tsx +4 -2
  347. package/src/snackbar/types.ts +18 -92
  348. package/src/tab-panel/index.tsx +38 -16
  349. package/src/tab-panel/style.scss +8 -0
  350. package/src/tab-panel/test/index.tsx +35 -7
  351. package/src/tab-panel/types.ts +1 -1
  352. package/src/theme/test/index.tsx +4 -4
  353. package/src/toggle-group-control/stories/index.tsx +1 -0
  354. package/src/toggle-group-control/test/index.tsx +7 -23
  355. package/src/toolbar/stories/index.js +75 -72
  356. package/src/tools-panel/stories/index.js +3 -0
  357. package/src/tools-panel/test/index.js +1 -1
  358. package/src/tree-grid/index.js +1 -1
  359. package/src/tree-select/index.tsx +3 -6
  360. package/src/ui/context/test/context-connect.tsx +2 -0
  361. package/src/ui/context/test/wordpress-component.tsx +2 -0
  362. package/src/unit-control/test/index.tsx +21 -74
  363. package/src/utils/hooks/test/use-latest-ref.js +15 -18
  364. package/tsconfig.json +1 -4
  365. package/tsconfig.tsbuildinfo +1 -1
  366. package/build-types/radio-context/index.d.ts +0 -6
  367. package/build-types/radio-context/index.d.ts.map +0 -1
  368. package/src/button/stories/index.js +0 -179
  369. package/src/keyboard-shortcuts/index.js +0 -56
  370. package/src/notice/list.js +0 -48
  371. package/src/notice/stories/index.js +0 -46
  372. package/src/query-controls/author-select.js +0 -23
  373. package/src/query-controls/category-select.js +0 -31
  374. package/src/query-controls/index.js +0 -122
  375. package/src/query-controls/terms.js +0 -40
  376. package/src/toolbar/stories/toolbar-button.js +0 -32
  377. package/src/toolbar/stories/toolbar-group.js +0 -33
@@ -14,8 +14,6 @@ import { useState } from '@wordpress/element';
14
14
  */
15
15
  import BoxControl from '../';
16
16
 
17
- jest.useFakeTimers();
18
-
19
17
  const Example = ( extraProps ) => {
20
18
  const [ state, setState ] = useState();
21
19
 
@@ -39,9 +37,7 @@ describe( 'BoxControl', () => {
39
37
  } );
40
38
 
41
39
  it( 'should update values when interacting with input', async () => {
42
- const user = userEvent.setup( {
43
- advanceTimers: jest.advanceTimersByTime,
44
- } );
40
+ const user = userEvent.setup();
45
41
 
46
42
  render( <BoxControl /> );
47
43
 
@@ -63,9 +59,7 @@ describe( 'BoxControl', () => {
63
59
 
64
60
  describe( 'Reset', () => {
65
61
  it( 'should reset values when clicking Reset', async () => {
66
- const user = userEvent.setup( {
67
- advanceTimers: jest.advanceTimersByTime,
68
- } );
62
+ const user = userEvent.setup();
69
63
 
70
64
  render( <BoxControl /> );
71
65
 
@@ -89,9 +83,7 @@ describe( 'BoxControl', () => {
89
83
  } );
90
84
 
91
85
  it( 'should reset values when clicking Reset, if controlled', async () => {
92
- const user = userEvent.setup( {
93
- advanceTimers: jest.advanceTimersByTime,
94
- } );
86
+ const user = userEvent.setup();
95
87
 
96
88
  render( <Example /> );
97
89
 
@@ -115,9 +107,7 @@ describe( 'BoxControl', () => {
115
107
  } );
116
108
 
117
109
  it( 'should reset values when clicking Reset, if controlled <-> uncontrolled state changes', async () => {
118
- const user = userEvent.setup( {
119
- advanceTimers: jest.advanceTimersByTime,
120
- } );
110
+ const user = userEvent.setup();
121
111
 
122
112
  render( <Example /> );
123
113
 
@@ -141,9 +131,7 @@ describe( 'BoxControl', () => {
141
131
  } );
142
132
 
143
133
  it( 'should persist cleared value when focus changes', async () => {
144
- const user = userEvent.setup( {
145
- advanceTimers: jest.advanceTimersByTime,
146
- } );
134
+ const user = userEvent.setup();
147
135
  const spyChange = jest.fn();
148
136
 
149
137
  render( <BoxControl onChange={ ( v ) => spyChange( v ) } /> );
@@ -179,9 +167,7 @@ describe( 'BoxControl', () => {
179
167
 
180
168
  describe( 'Unlinked sides', () => {
181
169
  it( 'should update a single side value when unlinked', async () => {
182
- const user = userEvent.setup( {
183
- advanceTimers: jest.advanceTimersByTime,
184
- } );
170
+ const user = userEvent.setup();
185
171
 
186
172
  render( <Example /> );
187
173
 
@@ -216,9 +202,7 @@ describe( 'BoxControl', () => {
216
202
  } );
217
203
 
218
204
  it( 'should update a whole axis when value is changed when unlinked', async () => {
219
- const user = userEvent.setup( {
220
- advanceTimers: jest.advanceTimersByTime,
221
- } );
205
+ const user = userEvent.setup();
222
206
 
223
207
  render( <Example splitOnAxis /> );
224
208
 
@@ -251,9 +235,7 @@ describe( 'BoxControl', () => {
251
235
 
252
236
  describe( 'Unit selections', () => {
253
237
  it( 'should update unlinked controls unit selection based on all input control', async () => {
254
- const user = userEvent.setup( {
255
- advanceTimers: jest.advanceTimersByTime,
256
- } );
238
+ const user = userEvent.setup();
257
239
 
258
240
  // Render control.
259
241
  render( <BoxControl /> );
@@ -285,9 +267,7 @@ describe( 'BoxControl', () => {
285
267
  } );
286
268
 
287
269
  it( 'should use individual side attribute unit when available', async () => {
288
- const user = userEvent.setup( {
289
- advanceTimers: jest.advanceTimersByTime,
290
- } );
270
+ const user = userEvent.setup();
291
271
 
292
272
  // Render control.
293
273
  const { rerender } = render( <BoxControl /> );
@@ -337,9 +317,7 @@ describe( 'BoxControl', () => {
337
317
 
338
318
  describe( 'onChange updates', () => {
339
319
  it( 'should call onChange when values contain more than just CSS units', async () => {
340
- const user = userEvent.setup( {
341
- advanceTimers: jest.advanceTimersByTime,
342
- } );
320
+ const user = userEvent.setup();
343
321
  const setState = jest.fn();
344
322
 
345
323
  render( <BoxControl onChange={ setState } /> );
@@ -361,9 +339,7 @@ describe( 'BoxControl', () => {
361
339
  } );
362
340
 
363
341
  it( 'should not pass invalid CSS unit only values to onChange', async () => {
364
- const user = userEvent.setup( {
365
- advanceTimers: jest.advanceTimersByTime,
366
- } );
342
+ const user = userEvent.setup();
367
343
  const setState = jest.fn();
368
344
 
369
345
  render( <BoxControl onChange={ setState } /> );
@@ -121,131 +121,125 @@ The presence of a `href` prop determines whether an `anchor` element is rendered
121
121
 
122
122
  Props not included in this set will be applied to the `a` or `button` element.
123
123
 
124
- #### disabled
124
+ #### `children`: `ReactNode`
125
125
 
126
- Whether the button is disabled. If `true`, this will force a `button` element to be rendered.
126
+ The button's children.
127
127
 
128
- - Type: `Boolean`
129
128
  - Required: No
130
129
 
131
- #### href
130
+ #### `className`: `string`
132
131
 
133
- If provided, renders `a` instead of `button`.
132
+ An optional additional class name to apply to the rendered button.
134
133
 
135
- - Type: `String`
136
134
  - Required: No
137
135
 
138
- #### variant
136
+ #### `describedBy`: `string`
139
137
 
140
- Specifies the button's style. The accepted values are `'primary'` (the primary button styles), `'secondary'` (the default button styles), `'tertiary'` (the text-based button styles), and `'link'` (the link button styles).
138
+ An accessible description for the button.
141
139
 
142
- - Type: `String`
143
140
  - Required: No
144
141
 
145
- #### isDestructive
142
+ #### `disabled`: `boolean`
146
143
 
147
- Renders a red text-based button style to indicate destructive behavior.
144
+ Whether the button is disabled. If `true`, this will force a `button` element to be rendered.
148
145
 
149
- - Type: `Boolean`
150
146
  - Required: No
151
147
 
152
- #### isSmall
148
+ #### `focus`: `boolean`
153
149
 
154
- Decreases the size of the button.
150
+ Whether the button is focused.
155
151
 
156
- - Type: `Boolean`
157
152
  - Required: No
158
153
 
159
- #### isPressed
154
+ #### `href`: `string`
160
155
 
161
- Renders a pressed button style.
156
+ If provided, renders `a` instead of `button`.
162
157
 
163
- - Type: `Boolean`
164
158
  - Required: No
165
159
 
166
- #### isBusy
160
+ #### `icon`: `IconProps< unknown >[ 'icon' ]`
167
161
 
168
- Indicates activity while a action is being performed.
162
+ If provided, renders an [Icon](/packages/components/src/icon/README.md) component inside the button.
169
163
 
170
- - Type: `Boolean`
171
164
  - Required: No
172
165
 
173
- #### focus
166
+ #### `iconPosition`: `'left' | 'right'`
174
167
 
175
- Whether the button is focused.
168
+ If provided with `icon`, sets the position of icon relative to the `text`. Available options are `left|right`.
176
169
 
177
- - Type: `Boolean`
178
170
  - Required: No
171
+ - Default: `left`
179
172
 
180
- #### target
173
+ #### `iconSize`: `IconProps< unknown >[ 'size' ]`
181
174
 
182
- If provided with `href`, sets the `target` attribute to the `a`.
175
+ If provided with `icon`, sets the icon size. Please refer to the [Icon](/packages/components/src/icon/README.md) component for more details regarding the default value of its `size` prop.
183
176
 
184
- - Type: `String`
185
177
  - Required: No
186
178
 
187
- #### className
179
+ #### `isBusy`: `boolean`
188
180
 
189
- An optional additional class name to apply to the rendered button.
181
+ Indicates activity while a action is being performed.
190
182
 
191
- - Type: `String`
192
183
  - Required: No
193
184
 
194
- #### icon
185
+ #### `isDestructive`: `boolean`
195
186
 
196
- If provided, renders an [Icon](/packages/components/src/icon/README.md) component inside the button.
187
+ Renders a red text-based button style to indicate destructive behavior.
197
188
 
198
- - Type: `String|Function|WPComponent|null`
199
189
  - Required: No
200
190
 
201
- #### iconSize
191
+ #### `isPressed`: `boolean`
202
192
 
203
- If provided with `icon`, sets the icon size. Please refer to the [Icon](/packages/components/src/icon/README.md) component for more details regarding the default value of its `size` prop.
193
+ Renders a pressed button style.
204
194
 
205
- - Type: `Number`
206
195
  - Required: No
207
196
 
208
- #### iconPosition
197
+ #### `isSmall`: `boolean`
209
198
 
210
- If provided with `icon`, sets the position of icon relative to the `text`. Available options are `left|right`.
199
+ Decreases the size of the button.
211
200
 
212
- - Type: `string`
213
201
  - Required: No
214
- - Default: `left`
215
202
 
216
- #### text
203
+ #### `label`: `string`
217
204
 
218
- If provided, displays the given text inside the button. If the button contains children elements, the text is displayed before them.
205
+ Sets the `aria-label` of the component, if none is provided. Sets the Tooltip content if `showTooltip` is provided.
219
206
 
220
- - Type: `String`
221
207
  - Required: No
222
208
 
223
- #### showTooltip
209
+ #### `shortcut`: `string | { display: string; ariaLabel: string; }`
210
+
211
+ If provided with `showTooltip`, appends the Shortcut label to the tooltip content. If an object is provided, it should contain `display` and `ariaLabel` keys.
212
+
213
+ - Required: No
214
+
215
+ #### `showTooltip`: `boolean`
224
216
 
225
217
  If provided, renders a [Tooltip](/packages/components/src/tooltip/README.md) component for the button.
226
218
 
227
- - Type: `Boolean`
228
219
  - Required: No
229
220
 
230
- #### tooltipPosition
221
+ #### `target`: `string`
231
222
 
232
- If provided with`showTooltip`, sets the position of the tooltip. Please refer to the [Tooltip](/packages/components/src/tooltip/README.md) component for more details regarding the defaults.
223
+ If provided with `href`, sets the `target` attribute to the `a`.
233
224
 
234
- - Type: `String`
235
- - Require: No
225
+ - Required: No
236
226
 
237
- #### shortcut
227
+ #### `text`: `string`
238
228
 
239
- If provided with `showTooltip`, appends the Shortcut label to the tooltip content. If an `Object` is provided, it should contain `display` and `ariaLabel` keys.
229
+ If provided, displays the given text inside the button. If the button contains children elements, the text is displayed before them.
240
230
 
241
- - Type: `String|Object`
242
231
  - Required: No
243
232
 
244
- #### label
233
+ #### `tooltipPosition`: `PopoverProps[ 'position' ]`
245
234
 
246
- Sets the `aria-label` of the component, if none is provided. Sets the Tooltip content if `showTooltip` is provided.
235
+ If provided with`showTooltip`, sets the position of the tooltip. Please refer to the [Tooltip](/packages/components/src/tooltip/README.md) component for more details regarding the defaults.
236
+
237
+ - Required: No
238
+
239
+ #### `variant`: `'primary' | 'secondary' | 'tertiary' | 'link'`
240
+
241
+ Specifies the button's style. The accepted values are `'primary'` (the primary button styles), `'secondary'` (the default button styles), `'tertiary'` (the text-based button styles), and `'link'` (the link button styles).
247
242
 
248
- - Type: `String`
249
243
  - Required: No
250
244
 
251
245
  ## Related components
@@ -1,4 +1,8 @@
1
- // @ts-nocheck
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ForwardedRef } from 'react';
5
+
2
6
  /**
3
7
  * WordPress dependencies
4
8
  */
@@ -8,9 +12,20 @@ import { forwardRef } from '@wordpress/element';
8
12
  /**
9
13
  * Internal dependencies
10
14
  */
11
- import Button from '../button';
15
+ import Button from '.';
16
+ import type { DeprecatedIconButtonProps } from './types';
12
17
 
13
- function IconButton( { labelPosition, size, tooltip, label, ...props }, ref ) {
18
+ function UnforwardedIconButton(
19
+ {
20
+ label,
21
+ labelPosition,
22
+ size,
23
+ tooltip,
24
+ ...props
25
+ }: React.ComponentPropsWithoutRef< typeof Button > &
26
+ DeprecatedIconButtonProps,
27
+ ref: ForwardedRef< any >
28
+ ) {
14
29
  deprecated( 'wp.components.IconButton', {
15
30
  since: '5.4',
16
31
  alternative: 'wp.components.Button',
@@ -29,4 +44,4 @@ function IconButton( { labelPosition, size, tooltip, label, ...props }, ref ) {
29
44
  );
30
45
  }
31
46
 
32
- export default forwardRef( IconButton );
47
+ export default forwardRef( UnforwardedIconButton );
@@ -1,8 +1,14 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * External dependencies
4
3
  */
5
4
  import classnames from 'classnames';
5
+ import type {
6
+ ComponentPropsWithoutRef,
7
+ ForwardedRef,
8
+ HTMLAttributes,
9
+ MouseEvent,
10
+ ReactElement,
11
+ } from 'react';
6
12
 
7
13
  /**
8
14
  * WordPress dependencies
@@ -17,8 +23,9 @@ import { useInstanceId } from '@wordpress/compose';
17
23
  import Tooltip from '../tooltip';
18
24
  import Icon from '../icon';
19
25
  import { VisuallyHidden } from '../visually-hidden';
26
+ import type { ButtonProps, DeprecatedButtonProps } from './types';
20
27
 
21
- const disabledEventsOnDisabledButton = [ 'onMouseDown', 'onClick' ];
28
+ const disabledEventsOnDisabledButton = [ 'onMouseDown', 'onClick' ] as const;
22
29
 
23
30
  function useDeprecatedProps( {
24
31
  isDefault,
@@ -28,7 +35,7 @@ function useDeprecatedProps( {
28
35
  isLink,
29
36
  variant,
30
37
  ...otherProps
31
- } ) {
38
+ }: ButtonProps & DeprecatedButtonProps ): ButtonProps {
32
39
  let computedVariant = variant;
33
40
 
34
41
  if ( isPrimary ) {
@@ -63,10 +70,11 @@ function useDeprecatedProps( {
63
70
  };
64
71
  }
65
72
 
66
- export function Button( props, ref ) {
73
+ export function UnforwardedButton(
74
+ props: ButtonProps,
75
+ ref: ForwardedRef< any >
76
+ ) {
67
77
  const {
68
- href,
69
- target,
70
78
  isSmall,
71
79
  isPressed,
72
80
  isBusy,
@@ -85,18 +93,26 @@ export function Button( props, ref ) {
85
93
  variant,
86
94
  __experimentalIsFocusable: isFocusable,
87
95
  describedBy,
88
- ...additionalProps
96
+ ...buttonOrAnchorProps
89
97
  } = useDeprecatedProps( props );
98
+
99
+ const { href, target, ...additionalProps } =
100
+ 'href' in buttonOrAnchorProps
101
+ ? buttonOrAnchorProps
102
+ : { href: undefined, target: undefined, ...buttonOrAnchorProps };
103
+
90
104
  const instanceId = useInstanceId(
91
105
  Button,
92
106
  'components-button__description'
93
107
  );
94
108
 
95
109
  const hasChildren =
96
- children?.[ 0 ] &&
97
- children[ 0 ] !== null &&
98
- // Tooltip should not considered as a child
99
- children?.[ 0 ]?.props?.className !== 'components-tooltip';
110
+ ( 'string' === typeof children && !! children ) ||
111
+ ( Array.isArray( children ) &&
112
+ children?.[ 0 ] &&
113
+ children[ 0 ] !== null &&
114
+ // Tooltip should not considered as a child
115
+ children?.[ 0 ]?.props?.className !== 'components-tooltip' );
100
116
 
101
117
  const classes = classnames( 'components-button', className, {
102
118
  'is-secondary': variant === 'secondary',
@@ -113,24 +129,29 @@ export function Button( props, ref ) {
113
129
 
114
130
  const trulyDisabled = disabled && ! isFocusable;
115
131
  const Tag = href !== undefined && ! trulyDisabled ? 'a' : 'button';
116
- const tagProps =
117
- Tag === 'a'
118
- ? { href, target }
119
- : {
132
+ const buttonProps: ComponentPropsWithoutRef< 'button' > =
133
+ Tag === 'button'
134
+ ? {
120
135
  type: 'button',
121
136
  disabled: trulyDisabled,
122
137
  'aria-pressed': isPressed,
123
- };
138
+ }
139
+ : {};
140
+ const anchorProps: ComponentPropsWithoutRef< 'a' > =
141
+ Tag === 'a' ? { href, target } : {};
124
142
 
125
143
  if ( disabled && isFocusable ) {
126
144
  // In this case, the button will be disabled, but still focusable and
127
145
  // perceivable by screen reader users.
128
- tagProps[ 'aria-disabled' ] = true;
146
+ buttonProps[ 'aria-disabled' ] = true;
147
+ anchorProps[ 'aria-disabled' ] = true;
129
148
 
130
149
  for ( const disabledEvent of disabledEventsOnDisabledButton ) {
131
- additionalProps[ disabledEvent ] = ( event ) => {
132
- event.stopPropagation();
133
- event.preventDefault();
150
+ additionalProps[ disabledEvent ] = ( event: MouseEvent ) => {
151
+ if ( event ) {
152
+ event.stopPropagation();
153
+ event.preventDefault();
154
+ }
134
155
  };
135
156
  }
136
157
  }
@@ -145,24 +166,24 @@ export function Button( props, ref ) {
145
166
  // There's a label and...
146
167
  ( !! label &&
147
168
  // The children are empty and...
148
- ! children?.length &&
169
+ ! ( children as string | ReactElement[] )?.length &&
149
170
  // The tooltip is not explicitly disabled.
150
171
  false !== showTooltip ) );
151
172
 
152
- const descriptionId = describedBy ? instanceId : null;
173
+ const descriptionId = describedBy ? instanceId : undefined;
153
174
 
154
175
  const describedById =
155
176
  additionalProps[ 'aria-describedby' ] || descriptionId;
156
177
 
157
- const element = (
158
- <Tag
159
- { ...tagProps }
160
- { ...additionalProps }
161
- className={ classes }
162
- aria-label={ additionalProps[ 'aria-label' ] || label }
163
- aria-describedby={ describedById }
164
- ref={ ref }
165
- >
178
+ const commonProps = {
179
+ className: classes,
180
+ 'aria-label': additionalProps[ 'aria-label' ] || label,
181
+ 'aria-describedby': describedById,
182
+ ref,
183
+ };
184
+
185
+ const elementChildren = (
186
+ <>
166
187
  { icon && iconPosition === 'left' && (
167
188
  <Icon icon={ icon } size={ iconSize } />
168
189
  ) }
@@ -171,9 +192,28 @@ export function Button( props, ref ) {
171
192
  <Icon icon={ icon } size={ iconSize } />
172
193
  ) }
173
194
  { children }
174
- </Tag>
195
+ </>
175
196
  );
176
197
 
198
+ const element =
199
+ Tag === 'a' ? (
200
+ <a
201
+ { ...anchorProps }
202
+ { ...( additionalProps as HTMLAttributes< HTMLAnchorElement > ) }
203
+ { ...commonProps }
204
+ >
205
+ { elementChildren }
206
+ </a>
207
+ ) : (
208
+ <button
209
+ { ...buttonProps }
210
+ { ...( additionalProps as HTMLAttributes< HTMLButtonElement > ) }
211
+ { ...commonProps }
212
+ >
213
+ { elementChildren }
214
+ </button>
215
+ );
216
+
177
217
  if ( ! shouldShowTooltip ) {
178
218
  return (
179
219
  <>
@@ -190,7 +230,12 @@ export function Button( props, ref ) {
190
230
  return (
191
231
  <>
192
232
  <Tooltip
193
- text={ children?.length && describedBy ? describedBy : label }
233
+ text={
234
+ ( children as string | ReactElement[] )?.length &&
235
+ describedBy
236
+ ? describedBy
237
+ : label
238
+ }
194
239
  shortcut={ shortcut }
195
240
  position={ tooltipPosition }
196
241
  >
@@ -205,4 +250,20 @@ export function Button( props, ref ) {
205
250
  );
206
251
  }
207
252
 
208
- export default forwardRef( Button );
253
+ /**
254
+ * Lets users take actions and make choices with a single click or tap.
255
+ *
256
+ * ```jsx
257
+ * import { Button } from '@wordpress/components';
258
+ * const Mybutton = () => (
259
+ * <Button
260
+ * variant="primary"
261
+ * onClick={ handleClick }
262
+ * >
263
+ * Click here
264
+ * </Button>
265
+ * );
266
+ * ```
267
+ */
268
+ export const Button = forwardRef( UnforwardedButton );
269
+ export default Button;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ComponentMeta, ComponentStory } from '@storybook/react';
5
+ import type { ReactNode } from 'react';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import {
11
+ formatBold,
12
+ formatItalic,
13
+ link,
14
+ more,
15
+ wordpress,
16
+ } from '@wordpress/icons';
17
+
18
+ /**
19
+ * Internal dependencies
20
+ */
21
+ import './style.css';
22
+ import Button from '..';
23
+
24
+ const meta: ComponentMeta< typeof Button > = {
25
+ title: 'Components/Button',
26
+ component: Button,
27
+ argTypes: {
28
+ // Overrides a limitation of the docgen interpreting our TS types for this as required.
29
+ href: { type: { name: 'string', required: false } },
30
+ icon: {
31
+ control: { type: 'select' },
32
+ options: [ 'wordpress', 'link', 'more' ],
33
+ mapping: {
34
+ wordpress,
35
+ link,
36
+ more,
37
+ },
38
+ },
39
+ },
40
+ parameters: {
41
+ controls: { expanded: true },
42
+ docs: { source: { state: 'open' } },
43
+ },
44
+ };
45
+ export default meta;
46
+
47
+ const Template: ComponentStory< typeof Button > = ( props ) => {
48
+ return <Button { ...props }></Button>;
49
+ };
50
+
51
+ export const Default: ComponentStory< typeof Button > = Template.bind( {} );
52
+ Default.args = {
53
+ children: 'Code is poetry',
54
+ };
55
+
56
+ export const Primary: ComponentStory< typeof Button > = Template.bind( {} );
57
+ Primary.args = {
58
+ ...Default.args,
59
+ variant: 'primary',
60
+ };
61
+
62
+ export const Secondary: ComponentStory< typeof Button > = Template.bind( {} );
63
+ Secondary.args = {
64
+ ...Default.args,
65
+ variant: 'secondary',
66
+ };
67
+
68
+ export const Tertiary: ComponentStory< typeof Button > = Template.bind( {} );
69
+ Tertiary.args = {
70
+ ...Default.args,
71
+ variant: 'tertiary',
72
+ };
73
+
74
+ export const Link: ComponentStory< typeof Button > = Template.bind( {} );
75
+ Link.args = {
76
+ ...Default.args,
77
+ variant: 'link',
78
+ };
79
+
80
+ export const IsDestructive: ComponentStory< typeof Button > = Template.bind(
81
+ {}
82
+ );
83
+ IsDestructive.args = {
84
+ ...Default.args,
85
+ isDestructive: true,
86
+ };
87
+
88
+ export const Icon: ComponentStory< typeof Button > = Template.bind( {} );
89
+ Icon.args = {
90
+ label: 'Code is poetry',
91
+ icon: 'wordpress',
92
+ };
93
+
94
+ export const GroupedIcons: ComponentStory< typeof Button > = () => {
95
+ const GroupContainer = ( { children }: { children: ReactNode } ) => (
96
+ <div style={ { display: 'inline-flex' } }>{ children }</div>
97
+ );
98
+
99
+ return (
100
+ <GroupContainer>
101
+ <Button icon={ formatBold } label="Bold" />
102
+ <Button icon={ formatItalic } label="Italic" />
103
+ <Button icon={ link } label="Link" />
104
+ </GroupContainer>
105
+ );
106
+ };
@@ -282,14 +282,15 @@
282
282
 
283
283
  &.has-text {
284
284
  justify-content: start;
285
+ padding-right: 12px;
285
286
  }
286
287
 
287
288
  &.has-text svg {
288
- margin-right: 8px;
289
+ margin-right: $grid-unit-10;
289
290
  }
290
291
 
291
292
  &.has-text .dashicon {
292
- margin-right: 10px;
293
+ margin-right: $grid-unit-10 + 2px;
293
294
  }
294
295
  }
295
296