@wordpress/components 25.14.0 → 25.15.1-next.79a6196f.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 (568) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/CONTRIBUTING.md +57 -115
  3. package/LICENSE.md +1 -1
  4. package/build/base-control/index.js +17 -13
  5. package/build/base-control/index.js.map +1 -1
  6. package/build/border-box-control/border-box-control-linked-button/component.js +1 -1
  7. package/build/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  8. package/build/border-control/border-control-style-picker/component.js +1 -1
  9. package/build/border-control/border-control-style-picker/component.js.map +1 -1
  10. package/build/box-control/index.js +1 -1
  11. package/build/box-control/index.js.map +1 -1
  12. package/build/box-control/linked-button.js +1 -1
  13. package/build/box-control/linked-button.js.map +1 -1
  14. package/build/button/index.js +1 -1
  15. package/build/button/index.js.map +1 -1
  16. package/build/color-palette/index.native.js +11 -7
  17. package/build/color-palette/index.native.js.map +1 -1
  18. package/build/color-picker/color-copy-button.js +1 -1
  19. package/build/color-picker/color-copy-button.js.map +1 -1
  20. package/build/context/wordpress-component.js.map +1 -1
  21. package/build/custom-select-control-v2/index.js +11 -10
  22. package/build/custom-select-control-v2/index.js.map +1 -1
  23. package/build/date-time/date/styles.js +8 -8
  24. package/build/date-time/date/styles.js.map +1 -1
  25. package/build/dropdown-menu-v2/index.js +205 -159
  26. package/build/dropdown-menu-v2/index.js.map +1 -1
  27. package/build/dropdown-menu-v2/styles.js +86 -77
  28. package/build/dropdown-menu-v2/styles.js.map +1 -1
  29. package/build/dropdown-menu-v2/types.js.map +1 -1
  30. package/build/duotone-picker/duotone-picker.js +4 -3
  31. package/build/duotone-picker/duotone-picker.js.map +1 -1
  32. package/build/font-size-picker/index.js +4 -2
  33. package/build/font-size-picker/index.js.map +1 -1
  34. package/build/font-size-picker/index.native.js +6 -3
  35. package/build/font-size-picker/index.native.js.map +1 -1
  36. package/build/form-token-field/index.js +10 -5
  37. package/build/form-token-field/index.js.map +1 -1
  38. package/build/form-token-field/token.js +1 -0
  39. package/build/form-token-field/token.js.map +1 -1
  40. package/build/gradient-picker/index.js +3 -2
  41. package/build/gradient-picker/index.js.map +1 -1
  42. package/build/index.native.js +20 -3
  43. package/build/index.native.js.map +1 -1
  44. package/build/input-control/styles/input-control-styles.js +32 -29
  45. package/build/input-control/styles/input-control-styles.js.map +1 -1
  46. package/build/input-control/types.js.map +1 -1
  47. package/build/lock-unlock.js +18 -0
  48. package/build/lock-unlock.js.map +1 -0
  49. package/build/mobile/bottom-sheet/index.native.js +8 -0
  50. package/build/mobile/bottom-sheet/index.native.js.map +1 -1
  51. package/build/mobile/color-settings/palette.screen.native.js +8 -4
  52. package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
  53. package/build/mobile/global-styles-context/utils.native.js +26 -13
  54. package/build/mobile/global-styles-context/utils.native.js.map +1 -1
  55. package/build/mobile/image/constants.js +12 -0
  56. package/build/mobile/image/constants.js.map +1 -0
  57. package/build/mobile/image/index.native.js +26 -18
  58. package/build/mobile/image/index.native.js.map +1 -1
  59. package/build/mobile/keyboard-aware-flat-list/index.android.js +40 -8
  60. package/build/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  61. package/build/mobile/keyboard-aware-flat-list/index.ios.js +44 -68
  62. package/build/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  63. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +39 -0
  64. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js.map +1 -0
  65. package/build/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +22 -29
  66. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -0
  67. package/build/mobile/keyboard-aware-flat-list/use-scroll.native.js +93 -0
  68. package/build/mobile/keyboard-aware-flat-list/use-scroll.native.js.map +1 -0
  69. package/build/mobile/utils/get-px-from-css-unit.native.js +302 -0
  70. package/build/mobile/utils/get-px-from-css-unit.native.js.map +1 -0
  71. package/build/modal/index.js +18 -13
  72. package/build/modal/index.js.map +1 -1
  73. package/build/navigation/menu/menu-title.js +1 -1
  74. package/build/navigation/menu/menu-title.js.map +1 -1
  75. package/build/navigator/navigator-provider/component.js +13 -15
  76. package/build/navigator/navigator-provider/component.js.map +1 -1
  77. package/build/navigator/navigator-screen/component.js +23 -63
  78. package/build/navigator/navigator-screen/component.js.map +1 -1
  79. package/build/navigator/styles.js +52 -0
  80. package/build/navigator/styles.js.map +1 -0
  81. package/build/number-control/index.js +4 -8
  82. package/build/number-control/index.js.map +1 -1
  83. package/build/number-control/types.js.map +1 -1
  84. package/build/palette-edit/index.js +15 -54
  85. package/build/palette-edit/index.js.map +1 -1
  86. package/build/private-apis.js +11 -26
  87. package/build/private-apis.js.map +1 -1
  88. package/build/private-apis.native.js +21 -0
  89. package/build/private-apis.native.js.map +1 -0
  90. package/build/radio-control/index.js +1 -0
  91. package/build/radio-control/index.js.map +1 -1
  92. package/build/range-control/index.js +1 -1
  93. package/build/range-control/index.js.map +1 -1
  94. package/build/select-control/styles/select-control-styles.js +15 -25
  95. package/build/select-control/styles/select-control-styles.js.map +1 -1
  96. package/build/slot-fill/index.js +3 -2
  97. package/build/slot-fill/index.js.map +1 -1
  98. package/build/slot-fill/types.js.map +1 -1
  99. package/build/snackbar/types.js.map +1 -1
  100. package/build/tabs/styles.js +3 -3
  101. package/build/tabs/styles.js.map +1 -1
  102. package/build/tabs/tabpanel.js +9 -7
  103. package/build/tabs/tabpanel.js.map +1 -1
  104. package/build/toggle-group-control/toggle-group-control/component.js +4 -4
  105. package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
  106. package/build/toggle-group-control/toggle-group-control/styles.js +29 -15
  107. package/build/toggle-group-control/toggle-group-control/styles.js.map +1 -1
  108. package/build/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
  109. package/build/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  110. package/build/tools-panel/tools-panel/component.js +3 -1
  111. package/build/tools-panel/tools-panel/component.js.map +1 -1
  112. package/build/tools-panel/tools-panel-header/component.js +9 -8
  113. package/build/tools-panel/tools-panel-header/component.js.map +1 -1
  114. package/build/tools-panel/types.js.map +1 -1
  115. package/build/tooltip/index.js +34 -10
  116. package/build/tooltip/index.js.map +1 -1
  117. package/build/tooltip/types.js.map +1 -1
  118. package/build/truncate/hook.js +10 -4
  119. package/build/truncate/hook.js.map +1 -1
  120. package/build/truncate/types.js.map +1 -1
  121. package/build/unit-control/index.js +1 -1
  122. package/build/unit-control/index.js.map +1 -1
  123. package/build/utils/strings.js +34 -3
  124. package/build/utils/strings.js.map +1 -1
  125. package/build-module/base-control/index.js +16 -12
  126. package/build-module/base-control/index.js.map +1 -1
  127. package/build-module/border-box-control/border-box-control-linked-button/component.js +1 -1
  128. package/build-module/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  129. package/build-module/border-control/border-control-style-picker/component.js +1 -1
  130. package/build-module/border-control/border-control-style-picker/component.js.map +1 -1
  131. package/build-module/box-control/index.js +1 -1
  132. package/build-module/box-control/index.js.map +1 -1
  133. package/build-module/box-control/linked-button.js +1 -1
  134. package/build-module/box-control/linked-button.js.map +1 -1
  135. package/build-module/button/index.js +1 -1
  136. package/build-module/button/index.js.map +1 -1
  137. package/build-module/color-palette/index.native.js +11 -7
  138. package/build-module/color-palette/index.native.js.map +1 -1
  139. package/build-module/color-picker/color-copy-button.js +1 -1
  140. package/build-module/color-picker/color-copy-button.js.map +1 -1
  141. package/build-module/context/wordpress-component.js.map +1 -1
  142. package/build-module/custom-select-control-v2/index.js +11 -10
  143. package/build-module/custom-select-control-v2/index.js.map +1 -1
  144. package/build-module/date-time/date/styles.js +8 -8
  145. package/build-module/date-time/date/styles.js.map +1 -1
  146. package/build-module/dropdown-menu-v2/index.js +201 -154
  147. package/build-module/dropdown-menu-v2/index.js.map +1 -1
  148. package/build-module/dropdown-menu-v2/styles.js +68 -61
  149. package/build-module/dropdown-menu-v2/styles.js.map +1 -1
  150. package/build-module/dropdown-menu-v2/types.js.map +1 -1
  151. package/build-module/duotone-picker/duotone-picker.js +4 -3
  152. package/build-module/duotone-picker/duotone-picker.js.map +1 -1
  153. package/build-module/font-size-picker/index.js +4 -2
  154. package/build-module/font-size-picker/index.js.map +1 -1
  155. package/build-module/font-size-picker/index.native.js +5 -2
  156. package/build-module/font-size-picker/index.native.js.map +1 -1
  157. package/build-module/form-token-field/index.js +10 -5
  158. package/build-module/form-token-field/index.js.map +1 -1
  159. package/build-module/form-token-field/token.js +1 -0
  160. package/build-module/form-token-field/token.js.map +1 -1
  161. package/build-module/gradient-picker/index.js +3 -2
  162. package/build-module/gradient-picker/index.js.map +1 -1
  163. package/build-module/index.native.js +6 -1
  164. package/build-module/index.native.js.map +1 -1
  165. package/build-module/input-control/styles/input-control-styles.js +31 -29
  166. package/build-module/input-control/styles/input-control-styles.js.map +1 -1
  167. package/build-module/input-control/types.js.map +1 -1
  168. package/build-module/lock-unlock.js +9 -0
  169. package/build-module/lock-unlock.js.map +1 -0
  170. package/build-module/mobile/bottom-sheet/index.native.js +9 -1
  171. package/build-module/mobile/bottom-sheet/index.native.js.map +1 -1
  172. package/build-module/mobile/color-settings/palette.screen.native.js +8 -4
  173. package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
  174. package/build-module/mobile/global-styles-context/utils.native.js +25 -13
  175. package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
  176. package/build-module/mobile/image/constants.js +5 -0
  177. package/build-module/mobile/image/constants.js.map +1 -0
  178. package/build-module/mobile/image/index.native.js +25 -16
  179. package/build-module/mobile/image/index.native.js.map +1 -1
  180. package/build-module/mobile/keyboard-aware-flat-list/index.android.js +40 -6
  181. package/build-module/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  182. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js +46 -68
  183. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  184. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +33 -0
  185. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js.map +1 -0
  186. package/build-module/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +21 -27
  187. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -0
  188. package/build-module/mobile/keyboard-aware-flat-list/use-scroll.native.js +86 -0
  189. package/build-module/mobile/keyboard-aware-flat-list/use-scroll.native.js.map +1 -0
  190. package/build-module/mobile/utils/get-px-from-css-unit.native.js +294 -0
  191. package/build-module/mobile/utils/get-px-from-css-unit.native.js.map +1 -0
  192. package/build-module/modal/index.js +18 -13
  193. package/build-module/modal/index.js.map +1 -1
  194. package/build-module/navigation/menu/menu-title.js +1 -1
  195. package/build-module/navigation/menu/menu-title.js.map +1 -1
  196. package/build-module/navigator/navigator-provider/component.js +3 -16
  197. package/build-module/navigator/navigator-provider/component.js.map +1 -1
  198. package/build-module/navigator/navigator-screen/component.js +16 -70
  199. package/build-module/navigator/navigator-screen/component.js.map +1 -1
  200. package/build-module/navigator/styles.js +47 -0
  201. package/build-module/navigator/styles.js.map +1 -0
  202. package/build-module/number-control/index.js +4 -8
  203. package/build-module/number-control/index.js.map +1 -1
  204. package/build-module/number-control/types.js.map +1 -1
  205. package/build-module/palette-edit/index.js +15 -51
  206. package/build-module/palette-edit/index.js.map +1 -1
  207. package/build-module/private-apis.js +10 -23
  208. package/build-module/private-apis.js.map +1 -1
  209. package/build-module/private-apis.native.js +14 -0
  210. package/build-module/private-apis.native.js.map +1 -0
  211. package/build-module/radio-control/index.js +1 -0
  212. package/build-module/radio-control/index.js.map +1 -1
  213. package/build-module/range-control/index.js +1 -1
  214. package/build-module/range-control/index.js.map +1 -1
  215. package/build-module/select-control/styles/select-control-styles.js +15 -25
  216. package/build-module/select-control/styles/select-control-styles.js.map +1 -1
  217. package/build-module/slot-fill/index.js +3 -2
  218. package/build-module/slot-fill/index.js.map +1 -1
  219. package/build-module/slot-fill/types.js.map +1 -1
  220. package/build-module/snackbar/types.js.map +1 -1
  221. package/build-module/tabs/styles.js +3 -3
  222. package/build-module/tabs/styles.js.map +1 -1
  223. package/build-module/tabs/tabpanel.js +9 -7
  224. package/build-module/tabs/tabpanel.js.map +1 -1
  225. package/build-module/toggle-group-control/toggle-group-control/component.js +4 -4
  226. package/build-module/toggle-group-control/toggle-group-control/component.js.map +1 -1
  227. package/build-module/toggle-group-control/toggle-group-control/styles.js +29 -15
  228. package/build-module/toggle-group-control/toggle-group-control/styles.js.map +1 -1
  229. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
  230. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  231. package/build-module/tools-panel/tools-panel/component.js +3 -1
  232. package/build-module/tools-panel/tools-panel/component.js.map +1 -1
  233. package/build-module/tools-panel/tools-panel-header/component.js +9 -8
  234. package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
  235. package/build-module/tools-panel/types.js.map +1 -1
  236. package/build-module/tooltip/index.js +34 -12
  237. package/build-module/tooltip/index.js.map +1 -1
  238. package/build-module/tooltip/types.js.map +1 -1
  239. package/build-module/truncate/hook.js +10 -4
  240. package/build-module/truncate/hook.js.map +1 -1
  241. package/build-module/truncate/types.js.map +1 -1
  242. package/build-module/unit-control/index.js +1 -1
  243. package/build-module/unit-control/index.js.map +1 -1
  244. package/build-module/utils/strings.js +32 -2
  245. package/build-module/utils/strings.js.map +1 -1
  246. package/build-style/style-rtl.css +29 -5
  247. package/build-style/style.css +29 -5
  248. package/build-types/base-control/index.d.ts +3 -27
  249. package/build-types/base-control/index.d.ts.map +1 -1
  250. package/build-types/base-control/stories/index.story.d.ts +4 -1
  251. package/build-types/base-control/stories/index.story.d.ts.map +1 -1
  252. package/build-types/border-box-control/border-box-control/hook.d.ts +4 -4
  253. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +6 -6
  254. package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +4 -4
  255. package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +4 -4
  256. package/build-types/border-box-control/stories/index.story.d.ts +1 -1
  257. package/build-types/border-control/border-control/hook.d.ts +4 -4
  258. package/build-types/border-control/border-control-dropdown/hook.d.ts +4 -4
  259. package/build-types/border-control/border-control-style-picker/hook.d.ts +4 -4
  260. package/build-types/border-control/stories/index.story.d.ts +6 -6
  261. package/build-types/box-control/stories/index.story.d.ts +42 -42
  262. package/build-types/box-control/styles/box-control-styles.d.ts +1 -1
  263. package/build-types/button/deprecated.d.ts +3 -3
  264. package/build-types/card/card/hook.d.ts +4 -4
  265. package/build-types/card/card-body/hook.d.ts +4 -4
  266. package/build-types/card/card-divider/hook.d.ts +4 -4
  267. package/build-types/card/card-footer/hook.d.ts +4 -4
  268. package/build-types/card/card-header/hook.d.ts +4 -4
  269. package/build-types/card/card-media/hook.d.ts +4 -4
  270. package/build-types/color-palette/styles.d.ts +2 -2
  271. package/build-types/color-picker/component.d.ts +2 -2
  272. package/build-types/color-picker/stories/index.story.d.ts +1 -1
  273. package/build-types/color-picker/stories/index.story.d.ts.map +1 -1
  274. package/build-types/color-picker/styles.d.ts +3 -3
  275. package/build-types/composite/test/index.d.ts.map +1 -0
  276. package/build-types/context/wordpress-component.d.ts +3 -3
  277. package/build-types/context/wordpress-component.d.ts.map +1 -1
  278. package/build-types/custom-select-control-v2/index.d.ts +3 -2
  279. package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
  280. package/build-types/custom-select-control-v2/stories/index.story.d.ts +4 -3
  281. package/build-types/custom-select-control-v2/stories/index.story.d.ts.map +1 -1
  282. package/build-types/date-time/date/styles.d.ts +3 -3
  283. package/build-types/date-time/date-time/styles.d.ts +1 -1
  284. package/build-types/date-time/time/styles.d.ts +4 -4
  285. package/build-types/dropdown/index.d.ts +1 -1
  286. package/build-types/dropdown/index.d.ts.map +1 -1
  287. package/build-types/dropdown/stories/index.story.d.ts +3 -3
  288. package/build-types/dropdown/stories/index.story.d.ts.map +1 -1
  289. package/build-types/dropdown-menu/index.d.ts +1 -1
  290. package/build-types/dropdown-menu/index.d.ts.map +1 -1
  291. package/build-types/dropdown-menu/stories/index.story.d.ts +2 -2
  292. package/build-types/dropdown-menu/stories/index.story.d.ts.map +1 -1
  293. package/build-types/dropdown-menu-v2/index.d.ts +18 -15
  294. package/build-types/dropdown-menu-v2/index.d.ts.map +1 -1
  295. package/build-types/dropdown-menu-v2/stories/index.story.d.ts +7 -2
  296. package/build-types/dropdown-menu-v2/stories/index.story.d.ts.map +1 -1
  297. package/build-types/dropdown-menu-v2/styles.d.ts +77 -23
  298. package/build-types/dropdown-menu-v2/styles.d.ts.map +1 -1
  299. package/build-types/dropdown-menu-v2/types.d.ts +89 -173
  300. package/build-types/dropdown-menu-v2/types.d.ts.map +1 -1
  301. package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -1
  302. package/build-types/elevation/hook.d.ts +4 -4
  303. package/build-types/flex/flex/hook.d.ts +4 -4
  304. package/build-types/flex/flex-block/hook.d.ts +4 -4
  305. package/build-types/flex/flex-item/hook.d.ts +4 -4
  306. package/build-types/focal-point-picker/stories/index.story.d.ts +4 -4
  307. package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +1 -1
  308. package/build-types/font-size-picker/index.d.ts.map +1 -1
  309. package/build-types/font-size-picker/styles.d.ts +1 -1
  310. package/build-types/form-token-field/index.d.ts.map +1 -1
  311. package/build-types/form-token-field/token.d.ts.map +1 -1
  312. package/build-types/grid/hook.d.ts +4 -4
  313. package/build-types/h-stack/hook.d.ts +4 -4
  314. package/build-types/heading/component.d.ts +1 -1
  315. package/build-types/heading/hook.d.ts +4 -4
  316. package/build-types/input-control/styles/input-control-styles.d.ts +11 -0
  317. package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
  318. package/build-types/input-control/types.d.ts +1 -1
  319. package/build-types/input-control/types.d.ts.map +1 -1
  320. package/build-types/item-group/item/hook.d.ts +4 -4
  321. package/build-types/item-group/item-group/hook.d.ts +4 -4
  322. package/build-types/lock-unlock.d.ts +3 -0
  323. package/build-types/lock-unlock.d.ts.map +1 -0
  324. package/build-types/menu-item/index.d.ts +1 -1
  325. package/build-types/menu-item/stories/index.story.d.ts +4 -4
  326. package/build-types/mobile/image/constants.d.ts +5 -0
  327. package/build-types/mobile/image/constants.d.ts.map +1 -0
  328. package/build-types/modal/index.d.ts.map +1 -1
  329. package/build-types/navigation/styles/navigation-styles.d.ts +3 -3
  330. package/build-types/navigator/navigator-back-button/hook.d.ts +6 -6
  331. package/build-types/navigator/navigator-button/hook.d.ts +6 -6
  332. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
  333. package/build-types/navigator/navigator-screen/component.d.ts +1 -7
  334. package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
  335. package/build-types/navigator/styles.d.ts +9 -0
  336. package/build-types/navigator/styles.d.ts.map +1 -0
  337. package/build-types/number-control/index.d.ts +1 -1
  338. package/build-types/number-control/index.d.ts.map +1 -1
  339. package/build-types/number-control/stories/index.story.d.ts +1 -1
  340. package/build-types/number-control/types.d.ts +1 -1
  341. package/build-types/palette-edit/index.d.ts +3 -8
  342. package/build-types/palette-edit/index.d.ts.map +1 -1
  343. package/build-types/palette-edit/styles.d.ts +3 -3
  344. package/build-types/popover/index.d.ts +1 -1
  345. package/build-types/popover/index.d.ts.map +1 -1
  346. package/build-types/popover/stories/e2e/index.story.d.ts +1 -1
  347. package/build-types/private-apis.d.ts +0 -1
  348. package/build-types/private-apis.d.ts.map +1 -1
  349. package/build-types/radio-control/index.d.ts.map +1 -1
  350. package/build-types/range-control/index.d.ts +1 -1
  351. package/build-types/range-control/styles/range-control-styles.d.ts +1 -1
  352. package/build-types/resizable-box/index.d.ts +1 -1
  353. package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
  354. package/build-types/resizable-box/stories/index.story.d.ts +2 -2
  355. package/build-types/scrollable/hook.d.ts +4 -4
  356. package/build-types/search-control/index.d.ts +1 -1
  357. package/build-types/search-control/stories/index.story.d.ts +2 -2
  358. package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
  359. package/build-types/slot-fill/index.d.ts +1 -1
  360. package/build-types/slot-fill/index.d.ts.map +1 -1
  361. package/build-types/slot-fill/types.d.ts +4 -0
  362. package/build-types/slot-fill/types.d.ts.map +1 -1
  363. package/build-types/snackbar/index.d.ts +2 -2
  364. package/build-types/snackbar/stories/index.story.d.ts +0 -3
  365. package/build-types/snackbar/stories/index.story.d.ts.map +1 -1
  366. package/build-types/snackbar/types.d.ts +1 -1
  367. package/build-types/snackbar/types.d.ts.map +1 -1
  368. package/build-types/spacer/hook.d.ts +4 -4
  369. package/build-types/surface/hook.d.ts +4 -4
  370. package/build-types/tabs/styles.d.ts.map +1 -1
  371. package/build-types/tabs/tabpanel.d.ts +1 -1
  372. package/build-types/tabs/tabpanel.d.ts.map +1 -1
  373. package/build-types/text/hook.d.ts +4 -4
  374. package/build-types/text-control/index.d.ts +1 -1
  375. package/build-types/textarea-control/index.d.ts +1 -1
  376. package/build-types/toggle-control/stories/index.story.d.ts +2 -2
  377. package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts +1 -1
  378. package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts +1 -1
  379. package/build-types/toggle-group-control/toggle-group-control/component.d.ts.map +1 -1
  380. package/build-types/toggle-group-control/toggle-group-control/styles.d.ts +2 -2
  381. package/build-types/toggle-group-control/toggle-group-control/styles.d.ts.map +1 -1
  382. package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts +1 -1
  383. package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts +1 -1
  384. package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
  385. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
  386. package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +1 -1
  387. package/build-types/toolbar/toolbar-button/index.d.ts +3 -3
  388. package/build-types/tools-panel/tools-panel/component.d.ts.map +1 -1
  389. package/build-types/tools-panel/tools-panel/hook.d.ts +5 -4
  390. package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
  391. package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
  392. package/build-types/tools-panel/tools-panel-header/hook.d.ts +5 -4
  393. package/build-types/tools-panel/tools-panel-header/hook.d.ts.map +1 -1
  394. package/build-types/tools-panel/tools-panel-item/hook.d.ts +4 -4
  395. package/build-types/tools-panel/types.d.ts +9 -0
  396. package/build-types/tools-panel/types.d.ts.map +1 -1
  397. package/build-types/tooltip/index.d.ts +1 -1
  398. package/build-types/tooltip/index.d.ts.map +1 -1
  399. package/build-types/tooltip/stories/index.story.d.ts +10 -1
  400. package/build-types/tooltip/stories/index.story.d.ts.map +1 -1
  401. package/build-types/tooltip/types.d.ts +3 -0
  402. package/build-types/tooltip/types.d.ts.map +1 -1
  403. package/build-types/truncate/hook.d.ts +5 -5
  404. package/build-types/truncate/hook.d.ts.map +1 -1
  405. package/build-types/truncate/types.d.ts +4 -0
  406. package/build-types/truncate/types.d.ts.map +1 -1
  407. package/build-types/unit-control/index.d.ts +1 -1
  408. package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -1
  409. package/build-types/utils/strings.d.ts +14 -2
  410. package/build-types/utils/strings.d.ts.map +1 -1
  411. package/build-types/v-stack/hook.d.ts +4 -4
  412. package/build-types/v-stack/stories/index.story.d.ts +1 -1
  413. package/package.json +20 -21
  414. package/src/alignment-matrix-control/test/index.tsx +10 -16
  415. package/src/base-control/index.tsx +21 -16
  416. package/src/border-box-control/border-box-control-linked-button/component.tsx +1 -1
  417. package/src/border-control/border-control-style-picker/component.tsx +1 -1
  418. package/src/box-control/index.tsx +1 -1
  419. package/src/box-control/linked-button.tsx +1 -1
  420. package/src/button/README.md +32 -6
  421. package/src/button/index.tsx +1 -1
  422. package/src/button-group/README.md +0 -6
  423. package/src/card/card/README.md +1 -1
  424. package/src/checkbox-control/README.md +1 -9
  425. package/src/color-palette/index.native.js +18 -7
  426. package/src/color-picker/color-copy-button.tsx +1 -1
  427. package/src/combobox-control/README.md +0 -6
  428. package/src/composite/test/index.tsx +576 -0
  429. package/src/context/wordpress-component.ts +11 -6
  430. package/src/custom-select-control/README.md +0 -6
  431. package/src/custom-select-control-v2/index.tsx +13 -12
  432. package/src/date-time/date/styles.ts +3 -3
  433. package/src/dropdown-menu/README.md +0 -5
  434. package/src/dropdown-menu-v2/README.md +75 -136
  435. package/src/dropdown-menu-v2/index.tsx +321 -231
  436. package/src/dropdown-menu-v2/stories/index.story.tsx +522 -126
  437. package/src/dropdown-menu-v2/styles.ts +226 -151
  438. package/src/dropdown-menu-v2/test/index.tsx +480 -188
  439. package/src/dropdown-menu-v2/types.ts +98 -184
  440. package/src/duotone-picker/duotone-picker.tsx +7 -3
  441. package/src/font-size-picker/index.native.js +8 -2
  442. package/src/font-size-picker/index.tsx +4 -2
  443. package/src/form-toggle/README.md +0 -6
  444. package/src/form-token-field/index.tsx +11 -7
  445. package/src/form-token-field/test/index.tsx +97 -0
  446. package/src/form-token-field/token.tsx +1 -0
  447. package/src/gradient-picker/index.tsx +2 -2
  448. package/src/index.native.js +6 -1
  449. package/src/input-control/styles/input-control-styles.tsx +10 -8
  450. package/src/input-control/types.ts +1 -1
  451. package/src/lock-unlock.js +10 -0
  452. package/src/menu-group/README.md +0 -8
  453. package/src/menu-items-choice/README.md +0 -7
  454. package/src/mobile/bottom-sheet/index.native.js +15 -1
  455. package/src/mobile/color-settings/palette.screen.native.js +7 -5
  456. package/src/mobile/global-styles-context/test/fixtures/theme.native.js +0 -20
  457. package/src/mobile/global-styles-context/utils.native.js +28 -19
  458. package/src/mobile/image/constants.js +1 -0
  459. package/src/mobile/image/index.native.js +55 -18
  460. package/src/mobile/image/style.native.scss +35 -9
  461. package/src/mobile/keyboard-aware-flat-list/index.android.js +50 -5
  462. package/src/mobile/keyboard-aware-flat-list/index.ios.js +65 -91
  463. package/src/mobile/keyboard-aware-flat-list/test/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +27 -25
  464. package/src/mobile/keyboard-aware-flat-list/test/use-scroll.native.js +71 -0
  465. package/src/mobile/keyboard-aware-flat-list/use-scroll-to-element.native.js +41 -0
  466. package/src/mobile/keyboard-aware-flat-list/{use-scroll-to-text-input.native.js → use-scroll-to-section.native.js} +22 -27
  467. package/src/mobile/keyboard-aware-flat-list/use-scroll.native.js +100 -0
  468. package/src/mobile/utils/get-px-from-css-unit.native.js +329 -0
  469. package/src/mobile/utils/test/get-px-from-css-unit.native.js +172 -0
  470. package/src/modal/README.md +0 -6
  471. package/src/modal/index.tsx +18 -16
  472. package/src/modal/test/index.tsx +90 -1
  473. package/src/navigation/menu/menu-title.tsx +1 -1
  474. package/src/navigator/navigator-provider/component.tsx +3 -4
  475. package/src/navigator/navigator-screen/component.tsx +15 -93
  476. package/src/navigator/styles.ts +71 -0
  477. package/src/navigator/test/index.tsx +0 -64
  478. package/src/notice/README.md +0 -6
  479. package/src/number-control/README.md +2 -2
  480. package/src/number-control/index.tsx +4 -8
  481. package/src/number-control/types.ts +1 -1
  482. package/src/palette-edit/index.tsx +15 -58
  483. package/src/palette-edit/test/index.tsx +1 -75
  484. package/src/panel/README.md +0 -6
  485. package/src/private-apis.native.js +13 -0
  486. package/src/private-apis.ts +12 -37
  487. package/src/radio-control/README.md +0 -6
  488. package/src/radio-control/index.tsx +4 -1
  489. package/src/radio-control/style.scss +29 -2
  490. package/src/radio-group/README.md +0 -6
  491. package/src/range-control/README.md +1 -9
  492. package/src/range-control/index.tsx +1 -1
  493. package/src/search-control/README.md +0 -6
  494. package/src/select-control/README.md +0 -6
  495. package/src/select-control/styles/select-control-styles.ts +10 -28
  496. package/src/slot-fill/index.tsx +5 -2
  497. package/src/slot-fill/types.ts +5 -0
  498. package/src/snackbar/README.md +0 -6
  499. package/src/snackbar/stories/index.story.tsx +7 -5
  500. package/src/snackbar/style.scss +4 -3
  501. package/src/snackbar/types.ts +2 -1
  502. package/src/spacer/README.md +0 -2
  503. package/src/tab-panel/README.md +0 -5
  504. package/src/tab-panel/test/index.tsx +39 -56
  505. package/src/tabs/styles.ts +7 -1
  506. package/src/tabs/tabpanel.tsx +7 -6
  507. package/src/tabs/test/index.tsx +56 -0
  508. package/src/text-control/README.md +0 -6
  509. package/src/textarea-control/README.md +0 -6
  510. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +12 -16
  511. package/src/toggle-group-control/test/index.tsx +58 -45
  512. package/src/toggle-group-control/toggle-group-control/component.tsx +5 -4
  513. package/src/toggle-group-control/toggle-group-control/styles.ts +13 -19
  514. package/src/toggle-group-control/toggle-group-control-option/README.md +1 -1
  515. package/src/toggle-group-control/toggle-group-control-option-base/README.md +1 -1
  516. package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +3 -2
  517. package/src/toggle-group-control/toggle-group-control-option-icon/README.md +1 -1
  518. package/src/toolbar/toolbar/README.md +0 -6
  519. package/src/tools-panel/test/index.tsx +12 -20
  520. package/src/tools-panel/tools-panel/README.md +7 -0
  521. package/src/tools-panel/tools-panel/component.tsx +2 -0
  522. package/src/tools-panel/tools-panel-header/README.md +7 -0
  523. package/src/tools-panel/tools-panel-header/component.tsx +20 -13
  524. package/src/tools-panel/types.ts +9 -0
  525. package/src/tooltip/README.md +4 -0
  526. package/src/tooltip/index.tsx +48 -10
  527. package/src/tooltip/stories/index.story.tsx +18 -1
  528. package/src/tooltip/test/index.tsx +404 -254
  529. package/src/tooltip/types.ts +4 -0
  530. package/src/tree-grid/README.md +0 -4
  531. package/src/truncate/README.md +8 -0
  532. package/src/truncate/hook.ts +17 -10
  533. package/src/truncate/test/index.tsx +54 -27
  534. package/src/truncate/types.ts +4 -0
  535. package/src/unit-control/index.tsx +1 -1
  536. package/src/utils/strings.ts +30 -2
  537. package/src/utils/test/strings.js +96 -1
  538. package/tsconfig.tsbuildinfo +1 -1
  539. package/build/dropdown-menu-v2-ariakit/index.js +0 -256
  540. package/build/dropdown-menu-v2-ariakit/index.js.map +0 -1
  541. package/build/dropdown-menu-v2-ariakit/styles.js +0 -180
  542. package/build/dropdown-menu-v2-ariakit/styles.js.map +0 -1
  543. package/build/dropdown-menu-v2-ariakit/types.js +0 -6
  544. package/build/dropdown-menu-v2-ariakit/types.js.map +0 -1
  545. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +0 -1
  546. package/build-module/dropdown-menu-v2-ariakit/index.js +0 -237
  547. package/build-module/dropdown-menu-v2-ariakit/index.js.map +0 -1
  548. package/build-module/dropdown-menu-v2-ariakit/styles.js +0 -165
  549. package/build-module/dropdown-menu-v2-ariakit/styles.js.map +0 -1
  550. package/build-module/dropdown-menu-v2-ariakit/types.js +0 -2
  551. package/build-module/dropdown-menu-v2-ariakit/types.js.map +0 -1
  552. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +0 -1
  553. package/build-types/dropdown-menu-v2-ariakit/index.d.ts +0 -20
  554. package/build-types/dropdown-menu-v2-ariakit/index.d.ts.map +0 -1
  555. package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts +0 -16
  556. package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts.map +0 -1
  557. package/build-types/dropdown-menu-v2-ariakit/styles.d.ts +0 -96
  558. package/build-types/dropdown-menu-v2-ariakit/styles.d.ts.map +0 -1
  559. package/build-types/dropdown-menu-v2-ariakit/test/index.d.ts.map +0 -1
  560. package/build-types/dropdown-menu-v2-ariakit/types.d.ts +0 -168
  561. package/build-types/dropdown-menu-v2-ariakit/types.d.ts.map +0 -1
  562. package/src/dropdown-menu-v2-ariakit/README.md +0 -331
  563. package/src/dropdown-menu-v2-ariakit/index.tsx +0 -383
  564. package/src/dropdown-menu-v2-ariakit/stories/index.story.tsx +0 -617
  565. package/src/dropdown-menu-v2-ariakit/styles.ts +0 -345
  566. package/src/dropdown-menu-v2-ariakit/test/index.tsx +0 -1108
  567. package/src/dropdown-menu-v2-ariakit/types.ts +0 -179
  568. /package/build-types/{dropdown-menu-v2-ariakit → composite}/test/index.d.ts +0 -0
@@ -0,0 +1,329 @@
1
+ /**
2
+ * Converts string to object { value, unit }.
3
+ *
4
+ * @param {string} cssUnit
5
+ * @return {Object} parsedUnit
6
+ */
7
+ function parseUnit( cssUnit ) {
8
+ const match = cssUnit
9
+ ?.trim()
10
+ .match(
11
+ /^(0?[-.]?\d*\.?\d+)(r?e[m|x]|v[h|w|min|max]+|p[x|t|c]|[c|m]m|%|in|ch|Q|lh)$/
12
+ );
13
+ if ( ! isNaN( cssUnit ) && ! isNaN( parseFloat( cssUnit ) ) ) {
14
+ return { value: parseFloat( cssUnit ), unit: 'px' };
15
+ }
16
+ return match
17
+ ? { value: parseFloat( match[ 1 ] ) || match[ 1 ], unit: match[ 2 ] }
18
+ : { value: cssUnit, unit: undefined };
19
+ }
20
+ /**
21
+ * Evaluate a math expression.
22
+ *
23
+ * @param {string} expression
24
+ * @return {number} evaluated expression.
25
+ */
26
+ function calculate( expression ) {
27
+ try {
28
+ return Function( `'use strict'; return (${ expression })` )();
29
+ } catch ( err ) {
30
+ return null;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Calculates the css function value for the supported css functions such as max, min, clamp and calc.
36
+ *
37
+ * @param {string} functionUnitValue string should be in a particular format (for example min(12px,12px) ) no nested loops.
38
+ * @param {Object} options
39
+ * @return {string} unit containing the unit in PX.
40
+ */
41
+ function getFunctionUnitValue( functionUnitValue, options ) {
42
+ const functionUnit = functionUnitValue.split( /[(),]/g ).filter( Boolean );
43
+
44
+ const units = functionUnit
45
+ .slice( 1 )
46
+ .map( ( unit ) => parseUnit( getPxFromCssUnit( unit, options ) ).value )
47
+ .filter( Boolean );
48
+
49
+ switch ( functionUnit[ 0 ] ) {
50
+ case 'min':
51
+ return Math.min( ...units ) + 'px';
52
+ case 'max':
53
+ return Math.max( ...units ) + 'px';
54
+ case 'clamp':
55
+ if ( units.length !== 3 ) {
56
+ return null;
57
+ }
58
+ if ( units[ 1 ] < units[ 0 ] ) {
59
+ return units[ 0 ] + 'px';
60
+ }
61
+ if ( units[ 1 ] > units[ 2 ] ) {
62
+ return units[ 2 ] + 'px';
63
+ }
64
+ return units[ 1 ] + 'px';
65
+ case 'calc':
66
+ return units[ 0 ] + 'px';
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Take a css function such as min, max, calc, clamp and returns parsedUnit
72
+ *
73
+ * How this works for the nested function is that it first replaces the inner function call.
74
+ * Then it tackles the outer onces.
75
+ * So for example: min( max(25px, 35px), 40px )
76
+ * in the first pass we would replace max(25px, 35px) with 35px.
77
+ * then we would try to evaluate min( 35px, 40px )
78
+ * and then finally return 35px.
79
+ *
80
+ * @param {string} cssUnit
81
+ * @return {Object} parsedUnit object.
82
+ */
83
+ function parseUnitFunction( cssUnit ) {
84
+ while ( true ) {
85
+ const currentCssUnit = cssUnit;
86
+ const regExp = /(max|min|calc|clamp)\(([^()]*)\)/g;
87
+ const matches = regExp.exec( cssUnit ) || [];
88
+ if ( matches[ 0 ] ) {
89
+ const functionUnitValue = getFunctionUnitValue( matches[ 0 ] );
90
+ cssUnit = cssUnit.replace( matches[ 0 ], functionUnitValue );
91
+ }
92
+
93
+ // If the unit hasn't been modified or we have a single value break free.
94
+ if ( cssUnit === currentCssUnit || parseFloat( cssUnit ) ) {
95
+ break;
96
+ }
97
+ }
98
+
99
+ return parseUnit( cssUnit );
100
+ }
101
+ /**
102
+ * Return true if we think this is a math expression.
103
+ *
104
+ * @param {string} cssUnit the cssUnit value being evaluted.
105
+ * @return {boolean} Whether the cssUnit is a math expression.
106
+ */
107
+ function isMathExpression( cssUnit ) {
108
+ for ( let i = 0; i < cssUnit.length; i++ ) {
109
+ if ( [ '+', '-', '/', '*' ].includes( cssUnit[ i ] ) ) {
110
+ return true;
111
+ }
112
+ }
113
+ return false;
114
+ }
115
+ /**
116
+ * Evaluates the math expression and return a px value.
117
+ *
118
+ * @param {string} cssUnit the cssUnit value being evaluted.
119
+ * @return {string} return a converfted value to px.
120
+ */
121
+ function evalMathExpression( cssUnit ) {
122
+ let errorFound = false;
123
+ // Convert every part of the expression to px values.
124
+ // The following regex matches numbers that have a following unit
125
+ // E.g. 5.25rem, 1vw
126
+ const cssUnitsBits = cssUnit.match( /\d+\.?\d*[a-zA-Z]+|\.\d+[a-zA-Z]+/g );
127
+ if ( cssUnitsBits ) {
128
+ for ( const unit of cssUnitsBits ) {
129
+ // Standardize the unit to px and extract the value.
130
+ const parsedUnit = parseUnit( getPxFromCssUnit( unit ) );
131
+ if ( ! parseFloat( parsedUnit.value ) ) {
132
+ errorFound = true;
133
+ // End early since we are dealing with a null value.
134
+ break;
135
+ }
136
+ cssUnit = cssUnit.replace( unit, parsedUnit.value );
137
+ }
138
+ } else {
139
+ errorFound = true;
140
+ }
141
+
142
+ // For mixed math expressions wrapped within CSS expressions
143
+ const expressionsMatches = cssUnit.match( /(max|min|clamp)/g );
144
+ if ( ! errorFound && expressionsMatches ) {
145
+ const values = cssUnit.split( ',' );
146
+ for ( const currentValue of values ) {
147
+ // Check for nested calc() and remove them to calculate the value.
148
+ const rawCurrentValue = currentValue.replace( /\s|calc/g, '' );
149
+
150
+ if ( isMathExpression( rawCurrentValue ) ) {
151
+ const calculatedExpression = calculate( rawCurrentValue );
152
+
153
+ if ( calculatedExpression ) {
154
+ const calculatedValue =
155
+ calculatedExpression.toFixed( 0 ) + 'px';
156
+ cssUnit = cssUnit.replace( currentValue, calculatedValue );
157
+ }
158
+ }
159
+ }
160
+ const parsedValue = parseUnitFunction( cssUnit );
161
+ return ! parsedValue ? null : parsedValue.value + parsedValue.unit;
162
+ }
163
+
164
+ if ( errorFound ) {
165
+ return null;
166
+ }
167
+
168
+ const calculatedResult = calculate( cssUnit );
169
+ return calculatedResult ? calculatedResult.toFixed( 0 ) + 'px' : null;
170
+ }
171
+
172
+ /**
173
+ * Convert a parsedUnit object to px value.
174
+ *
175
+ * @param {Object} parsedUnit
176
+ * @param {Object} options
177
+ * @return {string} or {null} returns the converted with in a px value format.
178
+ */
179
+ function convertParsedUnitToPx( parsedUnit, options ) {
180
+ const PIXELS_PER_INCH = 96;
181
+ const ONE_PERCENT = 0.01;
182
+
183
+ const defaultProperties = {
184
+ fontSize: 16,
185
+ lineHeight: 16,
186
+ width: 375,
187
+ height: 812,
188
+ type: 'font',
189
+ };
190
+
191
+ const setOptions = Object.assign( {}, defaultProperties, options );
192
+
193
+ const relativeUnits = {
194
+ em: setOptions.fontSize,
195
+ rem: setOptions.fontSize,
196
+ vh: setOptions.height * ONE_PERCENT,
197
+ vw: setOptions.width * ONE_PERCENT,
198
+ vmin:
199
+ ( setOptions.width < setOptions.height
200
+ ? setOptions.width
201
+ : setOptions.height ) * ONE_PERCENT,
202
+ vmax:
203
+ ( setOptions.width > setOptions.height
204
+ ? setOptions.width
205
+ : setOptions.height ) * ONE_PERCENT,
206
+ '%':
207
+ ( setOptions.type === 'font'
208
+ ? setOptions.fontSize
209
+ : setOptions.width ) * ONE_PERCENT,
210
+ ch: 8, // The advance measure (width) of the glyph "0" of the element's font. Approximate
211
+ ex: 7.15625, // X-height of the element's font. Approximate.
212
+ lh: setOptions.lineHeight,
213
+ };
214
+ relativeUnits.svw = relativeUnits.vmin;
215
+ relativeUnits.lvw = relativeUnits.vmax;
216
+ relativeUnits.dvw = relativeUnits.vw;
217
+ relativeUnits.svh = relativeUnits.vmin;
218
+ relativeUnits.lvh = relativeUnits.vmax;
219
+ relativeUnits.dvh = relativeUnits.vh;
220
+ relativeUnits.vi = relativeUnits.vh;
221
+ relativeUnits.svi = relativeUnits.vmin;
222
+ relativeUnits.lvi = relativeUnits.vmax;
223
+ relativeUnits.dvi = relativeUnits.vw;
224
+ relativeUnits.vb = relativeUnits.vh;
225
+ relativeUnits.svb = relativeUnits.vmin;
226
+ relativeUnits.lvb = relativeUnits.vmax;
227
+ relativeUnits.dvb = relativeUnits.vh;
228
+ relativeUnits.svmin = relativeUnits.vmin;
229
+ relativeUnits.lvmin = relativeUnits.vmin;
230
+ relativeUnits.dvmin = relativeUnits.vmin;
231
+ relativeUnits.svmax = relativeUnits.vmax;
232
+ relativeUnits.lvmax = relativeUnits.vmax;
233
+ relativeUnits.dvmax = relativeUnits.vmax;
234
+
235
+ const absoluteUnits = {
236
+ in: PIXELS_PER_INCH,
237
+ cm: PIXELS_PER_INCH / 2.54,
238
+ mm: PIXELS_PER_INCH / 25.4,
239
+ pt: PIXELS_PER_INCH / 72,
240
+ pc: PIXELS_PER_INCH / 6,
241
+ px: 1,
242
+ Q: PIXELS_PER_INCH / 2.54 / 40,
243
+ };
244
+
245
+ if ( relativeUnits[ parsedUnit.unit ] ) {
246
+ return (
247
+ ( relativeUnits[ parsedUnit.unit ] * parsedUnit.value ).toFixed(
248
+ 0
249
+ ) + 'px'
250
+ );
251
+ }
252
+
253
+ if ( absoluteUnits[ parsedUnit.unit ] ) {
254
+ return (
255
+ ( absoluteUnits[ parsedUnit.unit ] * parsedUnit.value ).toFixed(
256
+ 0
257
+ ) + 'px'
258
+ );
259
+ }
260
+
261
+ return null;
262
+ }
263
+
264
+ /**
265
+ * Returns the px value of a cssUnit.
266
+ *
267
+ * @param {string} cssUnit
268
+ * @param {Object} options
269
+ * @return {string} returns the cssUnit value in a simple px format.
270
+ */
271
+ export function getPxFromCssUnit( cssUnit, options = {} ) {
272
+ if ( Number.isFinite( cssUnit ) ) {
273
+ return cssUnit.toFixed( 0 ) + 'px';
274
+ }
275
+ if ( cssUnit === undefined ) {
276
+ return null;
277
+ }
278
+ let parsedUnit = parseUnit( cssUnit );
279
+
280
+ if ( ! parsedUnit.unit ) {
281
+ parsedUnit = parseUnitFunction( cssUnit );
282
+ }
283
+
284
+ if ( isMathExpression( cssUnit ) && ! parsedUnit.unit ) {
285
+ return evalMathExpression( cssUnit );
286
+ }
287
+
288
+ return convertParsedUnitToPx( parsedUnit, options );
289
+ }
290
+
291
+ // Use simple cache.
292
+ const cache = {};
293
+ /**
294
+ * Returns the px value of a cssUnit. The memoized version of getPxFromCssUnit;
295
+ *
296
+ * @param {string} cssUnit
297
+ * @param {Object} options
298
+ * @return {string} returns the cssUnit value in a simple px format.
299
+ */
300
+ function memoizedGetPxFromCssUnit( cssUnit, options = {} ) {
301
+ const hash = cssUnit + hashOptions( options );
302
+
303
+ if ( ! cache[ hash ] ) {
304
+ cache[ hash ] = getPxFromCssUnit( cssUnit, options );
305
+ }
306
+ return cache[ hash ];
307
+ }
308
+
309
+ function hashOptions( options ) {
310
+ let hash = '';
311
+ if ( options.hasOwnProperty( 'fontSize' ) ) {
312
+ hash = ':' + options.width;
313
+ }
314
+ if ( options.hasOwnProperty( 'lineHeight' ) ) {
315
+ hash = ':' + options.lineHeight;
316
+ }
317
+ if ( options.hasOwnProperty( 'width' ) ) {
318
+ hash = ':' + options.width;
319
+ }
320
+ if ( options.hasOwnProperty( 'height' ) ) {
321
+ hash = ':' + options.height;
322
+ }
323
+ if ( options.hasOwnProperty( 'type' ) ) {
324
+ hash = ':' + options.type;
325
+ }
326
+ return hash;
327
+ }
328
+
329
+ export default memoizedGetPxFromCssUnit;
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import {
5
+ default as memoizedGetPxFromCssUnit,
6
+ getPxFromCssUnit,
7
+ } from '../get-px-from-css-unit';
8
+
9
+ describe( 'getPxFromCssUnit', () => {
10
+ // Absolute units.
11
+ describe( 'absolute unites should return px values', () => {
12
+ const testData = [
13
+ [ '25px', '25px' ],
14
+ [ '25.5', '26px' ],
15
+ [ '1cm', '38px' ],
16
+ [ '10mm', '38px' ],
17
+ [ '1in', '96px' ],
18
+ [ '12pt', '16px' ],
19
+ [ '1pc', '16px' ],
20
+ [ '40Q', '38px' ], // 40 Q should be 1 cm.
21
+ ];
22
+
23
+ test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => {
24
+ expect( getPxFromCssUnit( unit ) ).toBe( expected );
25
+ } );
26
+ test.each( testData )(
27
+ 'memoizedGetPxFromCssUnit( %s )',
28
+ ( unit, expected ) => {
29
+ expect( memoizedGetPxFromCssUnit( unit ) ).toBe( expected );
30
+ }
31
+ );
32
+ test.each( testData )(
33
+ 'cached memoizedGetPxFromCssUnit( %s )',
34
+ ( unit, expected ) => {
35
+ expect( memoizedGetPxFromCssUnit( unit ) ).toBe( expected );
36
+ }
37
+ );
38
+ } );
39
+
40
+ describe( 'relative unites should return px values', () => {
41
+ const settings = {
42
+ fontSize: 10,
43
+ width: 100,
44
+ height: 200,
45
+ lineHeight: 2,
46
+ type: 'font',
47
+ };
48
+
49
+ const testData = [
50
+ [ '2em', '20px' ],
51
+ [ '2rem', '20px' ],
52
+ [ '1.125rem', '11px' ],
53
+ [ '20vw', '20px' ],
54
+ [ '20vh', '40px' ],
55
+ [ '20vmin', '20px' ],
56
+ [ '20vmax', '40px' ],
57
+ [ '20lh', '40px' ],
58
+ [ '120%', '12px' ],
59
+ ];
60
+
61
+ test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => {
62
+ expect( getPxFromCssUnit( unit, settings ) ).toBe( expected );
63
+ } );
64
+ test.each( testData )(
65
+ 'memoizedGetPxFromCssUnit( %s )',
66
+ ( unit, expected ) => {
67
+ expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
68
+ expected
69
+ );
70
+ }
71
+ );
72
+ test.each( testData )(
73
+ 'cached memoizedGetPxFromCssUnit( %s )',
74
+ ( unit, expected ) => {
75
+ expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
76
+ expected
77
+ );
78
+ }
79
+ );
80
+ } );
81
+
82
+ // Function units.
83
+
84
+ describe( 'function unites should return px values', () => {
85
+ const settings = {
86
+ fontSize: 10,
87
+ width: 100,
88
+ height: 200,
89
+ lineHeight: 2,
90
+ type: 'font',
91
+ };
92
+
93
+ const testData = [
94
+ [ 'min(20px, 25px)', '20px' ],
95
+ [ 'min(20px, 9px, 12pt, 25px)', '9px' ],
96
+ [ 'max(20px, 25px)', '25px' ],
97
+ [ 'clamp(10px, 9px, 25px)', '10px' ],
98
+ [ 'clamp(10px, 35px, 25px)', '25px' ],
99
+ [ 'clamp(10px, 15px, 25px)', '15px' ],
100
+ [ 'min(max(20px,25px), 35px)', '25px' ],
101
+ [ 'max(min(20px,25px), 35px)', '35px' ],
102
+ [ '10px + 25px', '35px' ],
103
+ [ 'calc(10px + 25px)', '35px' ],
104
+ [ 'calc( 2 * 20px)', '40px' ],
105
+ [ 'calc(25px - 10px)', '15px' ],
106
+ [ 'min(10px + 25px, 55pt)', '35px' ],
107
+ [ 'calc(12vw * 10px)', '450px' ],
108
+ [ 'calc(45vw / 10px)', '17px' ],
109
+ [ '', null ],
110
+ [ undefined, null ],
111
+ [ 123, '123px' ],
112
+ [ 123.456, '123px' ],
113
+ [ 'abc', null ],
114
+ [ 'console.log("howdy"); + 10px', null ],
115
+ [ 'calc(12vw * 10px', null ], // Missing closing bracket.
116
+ [ 'calc( 1em + 0.875rem )', '30px' ], // Decimals
117
+ [
118
+ 'clamp(1.8rem, 1.8rem + ((1vw / 0.48rem + 1rem) * 2.885), 3rem)',
119
+ '48px',
120
+ ],
121
+ [
122
+ 'clamp(5rem, 5.25rem + ((1vw - 0.48rem) * 9.096), 8rem)',
123
+ '80px',
124
+ ],
125
+ [
126
+ 'clamp(2.625rem, calc(2.625rem + ((1vw - 0.48rem) * 8.4135)), 3.25rem)',
127
+ '42px',
128
+ ],
129
+ [ 'var:preset|font-size|medium', null ],
130
+ ];
131
+
132
+ test.each( testData )( 'getPxFromCssUnit( %s )', ( unit, expected ) => {
133
+ expect( getPxFromCssUnit( unit, settings ) ).toBe( expected );
134
+ } );
135
+ test.each( testData )(
136
+ 'memoizedGetPxFromCssUnit( %s )',
137
+ ( unit, expected ) => {
138
+ expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
139
+ expected
140
+ );
141
+ }
142
+ );
143
+ test.each( testData )(
144
+ 'cached memoizedGetPxFromCssUnit( %s )',
145
+ ( unit, expected ) => {
146
+ expect( memoizedGetPxFromCssUnit( unit, settings ) ).toBe(
147
+ expected
148
+ );
149
+ }
150
+ );
151
+ } );
152
+ // Skip this test it might be useful in dev.
153
+ it.skip( 'test performance of memoizedGetPxFromCssUnit function', () => {
154
+ const start = Date.now();
155
+ let i = 0;
156
+ const intervals = 1000;
157
+ while ( i < intervals ) {
158
+ getPxFromCssUnit( 'max(25px, 35px)', { width: 200 } );
159
+ i++;
160
+ }
161
+ const rawDuration = Date.now() - start;
162
+
163
+ const startM = Date.now();
164
+ i = 0;
165
+ // The memoized Version should be at 10X better then the non default one.
166
+ while ( i < intervals * 10 ) {
167
+ memoizedGetPxFromCssUnit( 'max(25px, 35px)', { width: 201 } );
168
+ i++;
169
+ }
170
+ expect( rawDuration > Date.now() - startM ).toBe( true );
171
+ } );
172
+ } );
@@ -4,12 +4,6 @@ Modals give users information and choices related to a task they’re trying to
4
4
 
5
5
  ![An alert modal for trashing a post](https://wordpress.org/gutenberg/files/2019/04/Modal.png)
6
6
 
7
- ## Table of contents
8
-
9
- 1. [Design guidelines](#design-guidelines)
10
- 2. [Development guidelines](#development-guidelines)
11
- 3. [Related components](#related-components)
12
-
13
7
  ## Design guidelines
14
8
 
15
9
  ### Usage
@@ -43,12 +43,12 @@ import StyleProvider from '../style-provider';
43
43
  import type { ModalProps } from './types';
44
44
 
45
45
  // Used to track and dismiss the prior modal when another opens unless nested.
46
- const level0Dismissers: MutableRefObject<
47
- ModalProps[ 'onRequestClose' ] | undefined
48
- >[] = [];
49
- const ModalContext = createContext( level0Dismissers );
46
+ const ModalContext = createContext<
47
+ MutableRefObject< ModalProps[ 'onRequestClose' ] | undefined >[]
48
+ >( [] );
50
49
 
51
- let isBodyOpenClassActive = false;
50
+ // Used to track body class names applied while modals are open.
51
+ const bodyOpenClasses = new Map< string, number >();
52
52
 
53
53
  function UnforwardedModal(
54
54
  props: ModalProps,
@@ -146,7 +146,7 @@ function UnforwardedModal(
146
146
  // one should remain open at a time and the list enables closing prior ones.
147
147
  const dismissers = useContext( ModalContext );
148
148
  // Used for the tracking and dismissing any nested modals.
149
- const nestedDismissers = useRef< typeof level0Dismissers >( [] );
149
+ const nestedDismissers = useRef< typeof dismissers >( [] );
150
150
 
151
151
  // Updates the stack tracking open modals at this level and calls
152
152
  // onRequestClose for any prior and/or nested modals as applicable.
@@ -162,20 +162,22 @@ function UnforwardedModal(
162
162
  };
163
163
  }, [ dismissers ] );
164
164
 
165
- const isLevel0 = dismissers === level0Dismissers;
166
165
  // Adds/removes the value of bodyOpenClassName to body element.
167
166
  useEffect( () => {
168
- if ( ! isBodyOpenClassActive ) {
169
- isBodyOpenClassActive = true;
170
- document.body.classList.add( bodyOpenClassName );
171
- }
167
+ const theClass = bodyOpenClassName;
168
+ const oneMore = 1 + ( bodyOpenClasses.get( theClass ) ?? 0 );
169
+ bodyOpenClasses.set( theClass, oneMore );
170
+ document.body.classList.add( bodyOpenClassName );
172
171
  return () => {
173
- if ( isLevel0 && dismissers.length === 0 ) {
174
- document.body.classList.remove( bodyOpenClassName );
175
- isBodyOpenClassActive = false;
172
+ const oneLess = bodyOpenClasses.get( theClass )! - 1;
173
+ if ( oneLess === 0 ) {
174
+ document.body.classList.remove( theClass );
175
+ bodyOpenClasses.delete( theClass );
176
+ } else {
177
+ bodyOpenClasses.set( theClass, oneLess );
176
178
  }
177
179
  };
178
- }, [ bodyOpenClassName, dismissers, isLevel0 ] );
180
+ }, [ bodyOpenClassName ] );
179
181
 
180
182
  // Calls the isContentScrollable callback when the Modal children container resizes.
181
183
  useLayoutEffect( () => {
@@ -207,7 +209,7 @@ function UnforwardedModal(
207
209
 
208
210
  if (
209
211
  shouldCloseOnEsc &&
210
- event.code === 'Escape' &&
212
+ ( event.code === 'Escape' || event.key === 'Escape' ) &&
211
213
  ! event.defaultPrevented
212
214
  ) {
213
215
  event.preventDefault();
@@ -7,7 +7,7 @@ import userEvent from '@testing-library/user-event';
7
7
  /**
8
8
  * WordPress dependencies
9
9
  */
10
- import { useState } from '@wordpress/element';
10
+ import { useEffect, useState } from '@wordpress/element';
11
11
 
12
12
  /**
13
13
  * Internal dependencies
@@ -388,4 +388,93 @@ describe( 'Modal', () => {
388
388
  expect( opener ).toHaveFocus();
389
389
  } );
390
390
  } );
391
+
392
+ describe( 'Body class name', () => {
393
+ const overrideClass = 'is-any-open';
394
+ const BodyClassDemo = () => {
395
+ const [ isAShown, setIsAShown ] = useState( false );
396
+ const [ isA1Shown, setIsA1Shown ] = useState( false );
397
+ const [ isBShown, setIsBShown ] = useState( false );
398
+ const [ isClassOverriden, setIsClassOverriden ] = useState( false );
399
+ useEffect( () => {
400
+ const toggles: ( e: KeyboardEvent ) => void = ( {
401
+ key,
402
+ metaKey,
403
+ } ) => {
404
+ if ( key === 'a' ) {
405
+ if ( metaKey ) return setIsA1Shown( ( v ) => ! v );
406
+ return setIsAShown( ( v ) => ! v );
407
+ }
408
+ if ( key === 'b' ) return setIsBShown( ( v ) => ! v );
409
+ if ( key === 'c' )
410
+ return setIsClassOverriden( ( v ) => ! v );
411
+ };
412
+ document.addEventListener( 'keydown', toggles );
413
+ return () =>
414
+ void document.removeEventListener( 'keydown', toggles );
415
+ }, [] );
416
+ return (
417
+ <>
418
+ { isAShown && (
419
+ <Modal
420
+ bodyOpenClassName={
421
+ isClassOverriden ? overrideClass : 'is-A-open'
422
+ }
423
+ onRequestClose={ () => setIsAShown( false ) }
424
+ >
425
+ <p>Modal A contents</p>
426
+ { isA1Shown && (
427
+ <Modal
428
+ title="Nested"
429
+ onRequestClose={ () =>
430
+ setIsA1Shown( false )
431
+ }
432
+ >
433
+ <p>Modal A1 contents</p>
434
+ </Modal>
435
+ ) }
436
+ </Modal>
437
+ ) }
438
+ { isBShown && (
439
+ <Modal
440
+ bodyOpenClassName={
441
+ isClassOverriden ? overrideClass : 'is-B-open'
442
+ }
443
+ onRequestClose={ () => setIsBShown( false ) }
444
+ >
445
+ <p>Modal B contents</p>
446
+ </Modal>
447
+ ) }
448
+ </>
449
+ );
450
+ };
451
+
452
+ it( 'is added and removed when modal opens and closes including when closed due to another modal opening', async () => {
453
+ const user = userEvent.setup();
454
+
455
+ const { baseElement } = render( <BodyClassDemo /> );
456
+
457
+ await user.keyboard( 'a' ); // Opens modal A.
458
+ expect( baseElement ).toHaveClass( 'is-A-open' );
459
+
460
+ await user.keyboard( 'b' ); // Opens modal B > closes modal A.
461
+ expect( baseElement ).toHaveClass( 'is-B-open' );
462
+ expect( baseElement ).not.toHaveClass( 'is-A-open' );
463
+
464
+ await user.keyboard( 'b' ); // Closes modal B.
465
+ expect( baseElement ).not.toHaveClass( 'is-B-open' );
466
+ } );
467
+
468
+ it( 'is removed even when prop changes while nested modal is open', async () => {
469
+ const user = userEvent.setup();
470
+
471
+ const { baseElement } = render( <BodyClassDemo /> );
472
+
473
+ await user.keyboard( 'a' ); // Opens modal A.
474
+ await user.keyboard( '{Meta>}a{/Meta}' ); // Opens nested modal.
475
+ await user.keyboard( 'c' ); // Changes `bodyOpenClassName`.
476
+ await user.keyboard( 'a' ); // Closes modal A.
477
+ expect( baseElement ).not.toHaveClass( 'is-A-open' );
478
+ } );
479
+ } );
391
480
  } );
@@ -66,7 +66,7 @@ export default function NavigationMenuTitle( {
66
66
 
67
67
  { hasSearch && (
68
68
  <Button
69
- isSmall
69
+ size="small"
70
70
  variant="tertiary"
71
71
  label={ searchButtonLabel }
72
72
  onClick={ () => setIsSearching( true ) }