@wordpress/components 23.6.0 → 23.8.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 (484) hide show
  1. package/CHANGELOG.md +43 -4
  2. package/build/angle-picker-control/angle-circle.js +1 -4
  3. package/build/angle-picker-control/angle-circle.js.map +1 -1
  4. package/build/angle-picker-control/index.js +10 -22
  5. package/build/angle-picker-control/index.js.map +1 -1
  6. package/build/angle-picker-control/styles/angle-picker-control-styles.js +24 -15
  7. package/build/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
  8. package/build/animate/index.js +27 -19
  9. package/build/animate/index.js.map +1 -1
  10. package/build/animate/types.js.map +1 -0
  11. package/build/box-control/axial-input-controls.js.map +1 -1
  12. package/build/color-picker/color-input.js +0 -4
  13. package/build/color-picker/color-input.js.map +1 -1
  14. package/build/color-picker/component.js +5 -4
  15. package/build/color-picker/component.js.map +1 -1
  16. package/build/color-picker/hex-input.js.map +1 -1
  17. package/build/color-picker/hsl-input.js.map +1 -1
  18. package/build/color-picker/input-with-slider.js.map +1 -1
  19. package/build/color-picker/legacy-adapter.js.map +1 -1
  20. package/build/color-picker/picker.js.map +1 -1
  21. package/build/color-picker/rgb-input.js.map +1 -1
  22. package/build/color-picker/use-deprecated-props.js.map +1 -1
  23. package/build/custom-gradient-picker/constants.js +1 -1
  24. package/build/custom-gradient-picker/constants.js.map +1 -1
  25. package/build/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
  26. package/build/custom-gradient-picker/gradient-bar/control-points.js +9 -5
  27. package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
  28. package/build/custom-gradient-picker/gradient-bar/index.js +14 -9
  29. package/build/custom-gradient-picker/gradient-bar/index.js.map +1 -1
  30. package/build/custom-gradient-picker/gradient-bar/utils.js +34 -54
  31. package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  32. package/build/custom-gradient-picker/index.js +45 -16
  33. package/build/custom-gradient-picker/index.js.map +1 -1
  34. package/build/custom-gradient-picker/serializer.js +10 -4
  35. package/build/custom-gradient-picker/serializer.js.map +1 -1
  36. package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
  37. package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
  38. package/build/custom-gradient-picker/types.js +6 -0
  39. package/build/custom-gradient-picker/types.js.map +1 -0
  40. package/build/custom-gradient-picker/utils.js +17 -12
  41. package/build/custom-gradient-picker/utils.js.map +1 -1
  42. package/build/drop-zone/index.js +8 -8
  43. package/build/drop-zone/index.js.map +1 -1
  44. package/build/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  45. package/build/duotone-picker/color-list-picker/index.js.map +1 -0
  46. package/build/duotone-picker/color-list-picker/types.js +6 -0
  47. package/build/duotone-picker/color-list-picker/types.js.map +1 -0
  48. package/build/duotone-picker/custom-duotone-bar.js.map +1 -1
  49. package/build/duotone-picker/duotone-picker.js +39 -2
  50. package/build/duotone-picker/duotone-picker.js.map +1 -1
  51. package/build/duotone-picker/duotone-swatch.js.map +1 -1
  52. package/build/duotone-picker/index.js.map +1 -1
  53. package/build/duotone-picker/types.js +6 -0
  54. package/build/duotone-picker/types.js.map +1 -0
  55. package/build/duotone-picker/utils.js +13 -11
  56. package/build/duotone-picker/utils.js.map +1 -1
  57. package/build/form-token-field/index.js +9 -3
  58. package/build/form-token-field/index.js.map +1 -1
  59. package/build/gradient-picker/index.js +61 -9
  60. package/build/gradient-picker/index.js.map +1 -1
  61. package/build/gradient-picker/types.js +6 -0
  62. package/build/gradient-picker/types.js.map +1 -0
  63. package/build/index.js.map +1 -1
  64. package/build/mobile/keyboard-aware-flat-list/index.android.js +0 -4
  65. package/build/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  66. package/build/mobile/keyboard-aware-flat-list/index.ios.js +100 -55
  67. package/build/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  68. package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +82 -0
  69. package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
  70. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +85 -0
  71. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
  72. package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +44 -0
  73. package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
  74. package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +53 -0
  75. package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
  76. package/build/navigator/navigator-provider/component.js +4 -2
  77. package/build/navigator/navigator-provider/component.js.map +1 -1
  78. package/build/navigator/navigator-screen/component.js +4 -3
  79. package/build/navigator/navigator-screen/component.js.map +1 -1
  80. package/build/palette-edit/index.js +1 -2
  81. package/build/palette-edit/index.js.map +1 -1
  82. package/build/private-apis.js.map +1 -1
  83. package/build/query-controls/author-select.js +2 -1
  84. package/build/query-controls/author-select.js.map +1 -1
  85. package/build/query-controls/category-select.js +3 -1
  86. package/build/query-controls/category-select.js.map +1 -1
  87. package/build/query-controls/index.js +7 -1
  88. package/build/query-controls/index.js.map +1 -1
  89. package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
  90. package/build/sandbox/index.native.js +129 -93
  91. package/build/sandbox/index.native.js.map +1 -1
  92. package/build/tab-panel/index.js +1 -1
  93. package/build/tab-panel/index.js.map +1 -1
  94. package/build/tools-panel/tools-panel/hook.js +45 -6
  95. package/build/tools-panel/tools-panel/hook.js.map +1 -1
  96. package/build/utils/input/input-control.js +1 -1
  97. package/build/utils/input/input-control.js.map +1 -1
  98. package/build-module/angle-picker-control/angle-circle.js +1 -4
  99. package/build-module/angle-picker-control/angle-circle.js.map +1 -1
  100. package/build-module/angle-picker-control/index.js +12 -21
  101. package/build-module/angle-picker-control/index.js.map +1 -1
  102. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +20 -13
  103. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
  104. package/build-module/animate/index.js +25 -17
  105. package/build-module/animate/index.js.map +1 -1
  106. package/build-module/box-control/axial-input-controls.js.map +1 -1
  107. package/build-module/color-picker/color-input.js +0 -4
  108. package/build-module/color-picker/color-input.js.map +1 -1
  109. package/build-module/color-picker/component.js +3 -3
  110. package/build-module/color-picker/component.js.map +1 -1
  111. package/build-module/color-picker/hex-input.js.map +1 -1
  112. package/build-module/color-picker/hsl-input.js.map +1 -1
  113. package/build-module/color-picker/input-with-slider.js.map +1 -1
  114. package/build-module/color-picker/legacy-adapter.js.map +1 -1
  115. package/build-module/color-picker/picker.js +4 -0
  116. package/build-module/color-picker/picker.js.map +1 -1
  117. package/build-module/color-picker/rgb-input.js.map +1 -1
  118. package/build-module/color-picker/use-deprecated-props.js.map +1 -1
  119. package/build-module/custom-gradient-picker/constants.js +1 -1
  120. package/build-module/custom-gradient-picker/constants.js.map +1 -1
  121. package/build-module/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
  122. package/build-module/custom-gradient-picker/gradient-bar/control-points.js +9 -4
  123. package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
  124. package/build-module/custom-gradient-picker/gradient-bar/index.js +14 -8
  125. package/build-module/custom-gradient-picker/gradient-bar/index.js.map +1 -1
  126. package/build-module/custom-gradient-picker/gradient-bar/utils.js +34 -54
  127. package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  128. package/build-module/custom-gradient-picker/index.js +44 -17
  129. package/build-module/custom-gradient-picker/index.js.map +1 -1
  130. package/build-module/custom-gradient-picker/serializer.js +10 -4
  131. package/build-module/custom-gradient-picker/serializer.js.map +1 -1
  132. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
  133. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
  134. package/build-module/custom-gradient-picker/types.js +2 -0
  135. package/build-module/custom-gradient-picker/utils.js +17 -12
  136. package/build-module/custom-gradient-picker/utils.js.map +1 -1
  137. package/build-module/drop-zone/index.js +8 -8
  138. package/build-module/drop-zone/index.js.map +1 -1
  139. package/build-module/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  140. package/build-module/duotone-picker/color-list-picker/index.js.map +1 -0
  141. package/build-module/duotone-picker/color-list-picker/types.js +2 -0
  142. package/build-module/duotone-picker/color-list-picker/types.js.map +1 -0
  143. package/build-module/duotone-picker/custom-duotone-bar.js.map +1 -1
  144. package/build-module/duotone-picker/duotone-picker.js +38 -2
  145. package/build-module/duotone-picker/duotone-picker.js.map +1 -1
  146. package/build-module/duotone-picker/duotone-swatch.js.map +1 -1
  147. package/build-module/duotone-picker/index.js.map +1 -1
  148. package/build-module/duotone-picker/types.js +2 -0
  149. package/build-module/duotone-picker/types.js.map +1 -0
  150. package/build-module/duotone-picker/utils.js +17 -11
  151. package/build-module/duotone-picker/utils.js.map +1 -1
  152. package/build-module/form-token-field/index.js +9 -4
  153. package/build-module/form-token-field/index.js.map +1 -1
  154. package/build-module/gradient-picker/index.js +61 -10
  155. package/build-module/gradient-picker/index.js.map +1 -1
  156. package/build-module/gradient-picker/types.js +2 -0
  157. package/build-module/gradient-picker/types.js.map +1 -0
  158. package/build-module/index.js.map +1 -1
  159. package/build-module/mobile/keyboard-aware-flat-list/index.android.js +0 -4
  160. package/build-module/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  161. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js +97 -54
  162. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  163. package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +73 -0
  164. package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
  165. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +76 -0
  166. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
  167. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +33 -0
  168. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
  169. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +40 -0
  170. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
  171. package/build-module/navigator/navigator-provider/component.js +4 -2
  172. package/build-module/navigator/navigator-provider/component.js.map +1 -1
  173. package/build-module/navigator/navigator-screen/component.js +4 -3
  174. package/build-module/navigator/navigator-screen/component.js.map +1 -1
  175. package/build-module/palette-edit/index.js +1 -2
  176. package/build-module/palette-edit/index.js.map +1 -1
  177. package/build-module/private-apis.js.map +1 -1
  178. package/build-module/query-controls/author-select.js +2 -1
  179. package/build-module/query-controls/author-select.js.map +1 -1
  180. package/build-module/query-controls/category-select.js +3 -1
  181. package/build-module/query-controls/category-select.js.map +1 -1
  182. package/build-module/query-controls/index.js +7 -2
  183. package/build-module/query-controls/index.js.map +1 -1
  184. package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
  185. package/build-module/sandbox/index.native.js +121 -87
  186. package/build-module/sandbox/index.native.js.map +1 -1
  187. package/build-module/tab-panel/index.js +2 -2
  188. package/build-module/tab-panel/index.js.map +1 -1
  189. package/build-module/tools-panel/tools-panel/hook.js +45 -6
  190. package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
  191. package/build-module/utils/input/input-control.js +1 -1
  192. package/build-module/utils/input/input-control.js.map +1 -1
  193. package/build-style/style-rtl.css +41 -29
  194. package/build-style/style.css +43 -29
  195. package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
  196. package/build-types/angle-picker-control/index.d.ts.map +1 -1
  197. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +6 -1
  198. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -1
  199. package/build-types/animate/index.d.ts +27 -22
  200. package/build-types/animate/index.d.ts.map +1 -1
  201. package/build-types/animate/stories/index.d.ts +18 -0
  202. package/build-types/animate/stories/index.d.ts.map +1 -0
  203. package/build-types/animate/types.d.ts +30 -0
  204. package/build-types/animate/types.d.ts.map +1 -0
  205. package/build-types/border-box-control/border-box-control/hook.d.ts +2 -2
  206. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +2 -2
  207. package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +2 -2
  208. package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +2 -2
  209. package/build-types/border-control/border-control/hook.d.ts +2 -2
  210. package/build-types/border-control/border-control-dropdown/hook.d.ts +2 -2
  211. package/build-types/border-control/border-control-style-picker/hook.d.ts +2 -2
  212. package/build-types/box-control/styles/box-control-styles.d.ts +5 -5
  213. package/build-types/button/deprecated.d.ts +2 -2
  214. package/build-types/card/card/hook.d.ts +2 -2
  215. package/build-types/card/card-body/hook.d.ts +2 -2
  216. package/build-types/card/card-divider/hook.d.ts +2 -2
  217. package/build-types/card/card-footer/hook.d.ts +2 -2
  218. package/build-types/card/card-header/hook.d.ts +2 -2
  219. package/build-types/card/card-media/hook.d.ts +2 -2
  220. package/build-types/color-palette/styles.d.ts +1 -1
  221. package/build-types/color-picker/color-input.d.ts +1 -11
  222. package/build-types/color-picker/color-input.d.ts.map +1 -1
  223. package/build-types/color-picker/component.d.ts +8 -9
  224. package/build-types/color-picker/component.d.ts.map +1 -1
  225. package/build-types/color-picker/hex-input.d.ts +1 -10
  226. package/build-types/color-picker/hex-input.d.ts.map +1 -1
  227. package/build-types/color-picker/hsl-input.d.ts +1 -10
  228. package/build-types/color-picker/hsl-input.d.ts.map +1 -1
  229. package/build-types/color-picker/input-with-slider.d.ts +1 -9
  230. package/build-types/color-picker/input-with-slider.d.ts.map +1 -1
  231. package/build-types/color-picker/legacy-adapter.d.ts +1 -3
  232. package/build-types/color-picker/legacy-adapter.d.ts.map +1 -1
  233. package/build-types/color-picker/picker.d.ts +4 -7
  234. package/build-types/color-picker/picker.d.ts.map +1 -1
  235. package/build-types/color-picker/rgb-input.d.ts +1 -10
  236. package/build-types/color-picker/rgb-input.d.ts.map +1 -1
  237. package/build-types/color-picker/stories/index.d.ts +19 -0
  238. package/build-types/color-picker/stories/index.d.ts.map +1 -0
  239. package/build-types/color-picker/styles.d.ts +5 -5
  240. package/build-types/color-picker/test/index.d.ts +2 -0
  241. package/build-types/color-picker/test/index.d.ts.map +1 -0
  242. package/build-types/color-picker/types.d.ts +105 -1
  243. package/build-types/color-picker/types.d.ts.map +1 -1
  244. package/build-types/color-picker/use-deprecated-props.d.ts +1 -44
  245. package/build-types/color-picker/use-deprecated-props.d.ts.map +1 -1
  246. package/build-types/combobox-control/styles.d.ts +1 -1
  247. package/build-types/custom-gradient-picker/constants.d.ts +8 -8
  248. package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
  249. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts +7 -7
  250. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts.map +1 -1
  251. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts +5 -22
  252. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts.map +1 -1
  253. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts +3 -9
  254. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
  255. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts +2 -0
  256. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts.map +1 -0
  257. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts +44 -92
  258. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts.map +1 -1
  259. package/build-types/custom-gradient-picker/index.d.ts +27 -6
  260. package/build-types/custom-gradient-picker/index.d.ts.map +1 -1
  261. package/build-types/custom-gradient-picker/serializer.d.ts +9 -16
  262. package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
  263. package/build-types/custom-gradient-picker/stories/index.d.ts +12 -0
  264. package/build-types/custom-gradient-picker/stories/index.d.ts.map +1 -0
  265. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts +3 -2
  266. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts.map +1 -1
  267. package/build-types/custom-gradient-picker/test/serializer.d.ts +2 -0
  268. package/build-types/custom-gradient-picker/test/serializer.d.ts.map +1 -0
  269. package/build-types/custom-gradient-picker/types.d.ts +118 -0
  270. package/build-types/custom-gradient-picker/types.d.ts.map +1 -0
  271. package/build-types/custom-gradient-picker/utils.d.ts +12 -4
  272. package/build-types/custom-gradient-picker/utils.d.ts.map +1 -1
  273. package/build-types/date-time/date/styles.d.ts +2 -2
  274. package/build-types/date-time/date-time/styles.d.ts +1 -1
  275. package/build-types/date-time/time/styles.d.ts +8 -8
  276. package/build-types/drop-zone/index.d.ts.map +1 -1
  277. package/build-types/duotone-picker/color-list-picker/index.d.ts.map +1 -0
  278. package/build-types/{color-list-picker → duotone-picker/color-list-picker}/types.d.ts +2 -2
  279. package/build-types/duotone-picker/color-list-picker/types.d.ts.map +1 -0
  280. package/build-types/duotone-picker/custom-duotone-bar.d.ts +6 -0
  281. package/build-types/duotone-picker/custom-duotone-bar.d.ts.map +1 -0
  282. package/build-types/duotone-picker/duotone-picker.d.ts +38 -0
  283. package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -0
  284. package/build-types/duotone-picker/duotone-swatch.d.ts +5 -0
  285. package/build-types/duotone-picker/duotone-swatch.d.ts.map +1 -0
  286. package/build-types/duotone-picker/index.d.ts +3 -0
  287. package/build-types/duotone-picker/index.d.ts.map +1 -0
  288. package/build-types/duotone-picker/stories/duotone-picker.d.ts +12 -0
  289. package/build-types/duotone-picker/stories/duotone-picker.d.ts.map +1 -0
  290. package/build-types/duotone-picker/stories/duotone-swatch.d.ts +14 -0
  291. package/build-types/duotone-picker/stories/duotone-swatch.d.ts.map +1 -0
  292. package/build-types/duotone-picker/types.d.ts +60 -0
  293. package/build-types/duotone-picker/types.d.ts.map +1 -0
  294. package/build-types/duotone-picker/utils.d.ts +52 -0
  295. package/build-types/duotone-picker/utils.d.ts.map +1 -0
  296. package/build-types/elevation/hook.d.ts +2 -2
  297. package/build-types/external-link/styles/external-link-styles.d.ts +1 -1
  298. package/build-types/flex/flex/hook.d.ts +2 -2
  299. package/build-types/flex/flex-block/hook.d.ts +2 -2
  300. package/build-types/flex/flex-item/hook.d.ts +2 -2
  301. package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +2 -2
  302. package/build-types/form-token-field/index.d.ts.map +1 -1
  303. package/build-types/form-token-field/styles.d.ts +1 -1
  304. package/build-types/form-token-field/types.d.ts +6 -0
  305. package/build-types/form-token-field/types.d.ts.map +1 -1
  306. package/build-types/gradient-picker/index.d.ts +49 -11
  307. package/build-types/gradient-picker/index.d.ts.map +1 -1
  308. package/build-types/gradient-picker/stories/index.d.ts +14 -0
  309. package/build-types/gradient-picker/stories/index.d.ts.map +1 -0
  310. package/build-types/gradient-picker/types.d.ts +87 -0
  311. package/build-types/gradient-picker/types.d.ts.map +1 -0
  312. package/build-types/grid/hook.d.ts +2 -2
  313. package/build-types/h-stack/hook.d.ts +2 -2
  314. package/build-types/heading/hook.d.ts +2 -2
  315. package/build-types/index.d.ts +128 -0
  316. package/build-types/index.d.ts.map +1 -0
  317. package/build-types/input-control/styles/input-control-styles.d.ts +2 -2
  318. package/build-types/item-group/item/hook.d.ts +2 -2
  319. package/build-types/item-group/item-group/hook.d.ts +2 -2
  320. package/build-types/navigation/styles/navigation-styles.d.ts +2 -2
  321. package/build-types/navigator/navigator-back-button/hook.d.ts +2 -2
  322. package/build-types/navigator/navigator-button/hook.d.ts +2 -2
  323. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
  324. package/build-types/navigator/navigator-screen/component.d.ts +1 -1
  325. package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
  326. package/build-types/navigator/stories/index.d.ts +1 -0
  327. package/build-types/navigator/stories/index.d.ts.map +1 -1
  328. package/build-types/navigator/types.d.ts +2 -2
  329. package/build-types/navigator/types.d.ts.map +1 -1
  330. package/build-types/number-control/index.d.ts +2 -2
  331. package/build-types/number-control/stories/index.d.ts +2 -2
  332. package/build-types/palette-edit/index.d.ts.map +1 -1
  333. package/build-types/palette-edit/styles.d.ts +3 -3
  334. package/build-types/popover/index.d.ts +1 -1
  335. package/build-types/popover/stories/e2e/index.d.ts +1 -1
  336. package/build-types/private-apis.d.ts +2 -3
  337. package/build-types/private-apis.d.ts.map +1 -1
  338. package/build-types/query-controls/author-select.d.ts.map +1 -1
  339. package/build-types/query-controls/category-select.d.ts.map +1 -1
  340. package/build-types/query-controls/index.d.ts.map +1 -1
  341. package/build-types/range-control/index.d.ts +1 -1
  342. package/build-types/range-control/styles/range-control-styles.d.ts +2 -2
  343. package/build-types/resizable-box/index.d.ts +1 -1
  344. package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
  345. package/build-types/resizable-box/resize-tooltip/utils.d.ts +1 -1
  346. package/build-types/resizable-box/resize-tooltip/utils.d.ts.map +1 -1
  347. package/build-types/resizable-box/stories/index.d.ts +2 -2
  348. package/build-types/scrollable/hook.d.ts +2 -2
  349. package/build-types/search-control/index.d.ts +1 -1
  350. package/build-types/search-control/stories/index.d.ts +2 -2
  351. package/build-types/spacer/hook.d.ts +2 -2
  352. package/build-types/spinner/index.d.ts +1 -1
  353. package/build-types/surface/hook.d.ts +2 -2
  354. package/build-types/tab-panel/index.d.ts.map +1 -1
  355. package/build-types/text/hook.d.ts +2 -2
  356. package/build-types/text-control/index.d.ts +1 -1
  357. package/build-types/toolbar/toolbar-button/index.d.ts +2 -2
  358. package/build-types/tools-panel/tools-panel/hook.d.ts +2 -2
  359. package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
  360. package/build-types/tools-panel/tools-panel-header/hook.d.ts +2 -2
  361. package/build-types/tools-panel/tools-panel-item/hook.d.ts +2 -2
  362. package/build-types/tools-panel/types.d.ts +1 -0
  363. package/build-types/tools-panel/types.d.ts.map +1 -1
  364. package/build-types/truncate/hook.d.ts +2 -2
  365. package/build-types/ui/control-group/hook.d.ts +2 -2
  366. package/build-types/ui/control-label/hook.d.ts +2 -2
  367. package/build-types/ui/form-group/form-group.d.ts +2 -2
  368. package/build-types/ui/form-group/use-form-group.d.ts +2 -2
  369. package/build-types/unit-control/index.d.ts +1 -1
  370. package/build-types/unit-control/styles/unit-control-styles.d.ts +2 -2
  371. package/build-types/utils/input/input-control.d.ts.map +1 -1
  372. package/build-types/v-stack/hook.d.ts +2 -2
  373. package/package.json +20 -19
  374. package/src/angle-picker-control/angle-circle.tsx +0 -1
  375. package/src/angle-picker-control/index.tsx +14 -27
  376. package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +16 -9
  377. package/src/animate/index.tsx +75 -0
  378. package/src/animate/stories/index.tsx +102 -0
  379. package/src/animate/types.ts +32 -0
  380. package/src/border-box-control/stories/index.tsx +1 -1
  381. package/src/box-control/axial-input-controls.tsx +1 -1
  382. package/src/circular-option-picker/style.scss +10 -0
  383. package/src/color-indicator/style.scss +1 -0
  384. package/src/color-picker/README.md +2 -2
  385. package/src/color-picker/color-input.tsx +1 -12
  386. package/src/color-picker/component.tsx +9 -18
  387. package/src/color-picker/hex-input.tsx +2 -7
  388. package/src/color-picker/hsl-input.tsx +2 -7
  389. package/src/color-picker/input-with-slider.tsx +1 -9
  390. package/src/color-picker/legacy-adapter.tsx +1 -2
  391. package/src/color-picker/picker.tsx +5 -6
  392. package/src/color-picker/rgb-input.tsx +2 -7
  393. package/src/color-picker/stories/index.tsx +51 -0
  394. package/src/color-picker/test/{index.js → index.tsx} +36 -18
  395. package/src/color-picker/types.ts +128 -1
  396. package/src/color-picker/use-deprecated-props.ts +2 -53
  397. package/src/combobox-control/stories/index.tsx +1 -1
  398. package/src/custom-gradient-picker/{constants.js → constants.ts} +2 -2
  399. package/src/custom-gradient-picker/gradient-bar/{control-points.js → control-points.tsx} +171 -134
  400. package/src/custom-gradient-picker/gradient-bar/{index.js → index.tsx} +32 -10
  401. package/src/custom-gradient-picker/gradient-bar/test/{utils.js → utils.ts} +58 -31
  402. package/src/custom-gradient-picker/gradient-bar/utils.ts +193 -0
  403. package/src/custom-gradient-picker/{index.js → index.tsx} +63 -22
  404. package/src/custom-gradient-picker/serializer.ts +78 -0
  405. package/src/custom-gradient-picker/stories/index.tsx +45 -0
  406. package/src/custom-gradient-picker/style.scss +25 -4
  407. package/src/custom-gradient-picker/test/{serializer.js → serializer.ts} +39 -33
  408. package/src/custom-gradient-picker/types.ts +119 -0
  409. package/src/custom-gradient-picker/{utils.js → utils.ts} +37 -22
  410. package/src/custom-select-control/test/index.js +6 -4
  411. package/src/drop-zone/index.tsx +12 -8
  412. package/src/drop-zone/style.scss +1 -1
  413. package/src/{color-list-picker → duotone-picker/color-list-picker}/index.tsx +7 -6
  414. package/src/{color-list-picker → duotone-picker/color-list-picker}/types.ts +2 -2
  415. package/src/duotone-picker/{custom-duotone-bar.js → custom-duotone-bar.tsx} +7 -1
  416. package/src/duotone-picker/{duotone-picker.js → duotone-picker.tsx} +39 -2
  417. package/src/duotone-picker/{duotone-swatch.js → duotone-swatch.tsx} +2 -1
  418. package/src/duotone-picker/stories/{duotone-picker.js → duotone-picker.tsx} +15 -8
  419. package/src/duotone-picker/stories/{duotone-swatch.js → duotone-swatch.tsx} +9 -3
  420. package/src/duotone-picker/types.ts +61 -0
  421. package/src/duotone-picker/{utils.js → utils.ts} +29 -14
  422. package/src/flex/flex-item/README.md +1 -1
  423. package/src/form-token-field/README.md +1 -0
  424. package/src/form-token-field/index.tsx +10 -3
  425. package/src/form-token-field/style.scss +0 -7
  426. package/src/form-token-field/test/index.tsx +1 -0
  427. package/src/form-token-field/types.ts +6 -0
  428. package/src/gradient-picker/README.md +16 -23
  429. package/src/gradient-picker/{index.js → index.tsx} +70 -16
  430. package/src/gradient-picker/stories/{index.js → index.tsx} +19 -8
  431. package/src/gradient-picker/types.ts +89 -0
  432. package/src/item-group/test/index.js +5 -3
  433. package/src/mobile/keyboard-aware-flat-list/index.android.js +0 -4
  434. package/src/mobile/keyboard-aware-flat-list/index.ios.js +118 -67
  435. package/src/mobile/keyboard-aware-flat-list/test/use-keyboard-offset.native.js +203 -0
  436. package/src/mobile/keyboard-aware-flat-list/test/use-scroll-to-text-input.native.js +140 -0
  437. package/src/mobile/keyboard-aware-flat-list/test/use-text-input-caret-position.native.js +82 -0
  438. package/src/mobile/keyboard-aware-flat-list/test/use-text-input-offset.native.js +147 -0
  439. package/src/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +87 -0
  440. package/src/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +105 -0
  441. package/src/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +36 -0
  442. package/src/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +54 -0
  443. package/src/navigator/navigator-provider/component.tsx +2 -0
  444. package/src/navigator/navigator-screen/component.tsx +5 -2
  445. package/src/navigator/stories/index.tsx +68 -0
  446. package/src/navigator/test/index.tsx +52 -0
  447. package/src/navigator/types.ts +2 -1
  448. package/src/palette-edit/index.tsx +4 -5
  449. package/src/query-controls/author-select.tsx +1 -0
  450. package/src/query-controls/category-select.tsx +1 -0
  451. package/src/query-controls/index.tsx +4 -2
  452. package/src/resizable-box/resize-tooltip/utils.ts +1 -1
  453. package/src/sandbox/index.native.js +139 -112
  454. package/src/slot-fill/test/slot.js +8 -6
  455. package/src/style.scss +1 -1
  456. package/src/tab-panel/index.tsx +7 -2
  457. package/src/tools-panel/test/index.tsx +86 -0
  458. package/src/tools-panel/tools-panel/hook.ts +44 -4
  459. package/src/tools-panel/types.ts +1 -0
  460. package/src/tooltip/test/index.js +251 -301
  461. package/src/utils/input/input-control.js +1 -0
  462. package/tsconfig.json +1 -3
  463. package/tsconfig.tsbuildinfo +1 -1
  464. package/build/color-list-picker/index.js.map +0 -1
  465. package/build-module/color-list-picker/index.js.map +0 -1
  466. package/build-types/color-list-picker/index.d.ts.map +0 -1
  467. package/build-types/color-list-picker/types.d.ts.map +0 -1
  468. package/src/animate/index.js +0 -60
  469. package/src/animate/stories/index.js +0 -53
  470. package/src/color-picker/stories/index.js +0 -41
  471. package/src/custom-gradient-picker/gradient-bar/utils.js +0 -189
  472. package/src/custom-gradient-picker/serializer.js +0 -48
  473. package/src/custom-gradient-picker/stories/index.js +0 -33
  474. /package/build/{color-list-picker → animate}/types.js +0 -0
  475. /package/build-module/{color-list-picker → animate}/types.js +0 -0
  476. /package/build-module/{color-list-picker → animate}/types.js.map +0 -0
  477. /package/{build/color-list-picker → build-module/custom-gradient-picker}/types.js.map +0 -0
  478. /package/build-types/{color-list-picker → duotone-picker/color-list-picker}/index.d.ts +0 -0
  479. /package/src/custom-gradient-picker/gradient-bar/{constants.js → constants.ts} +0 -0
  480. /package/src/custom-gradient-picker/styles/{custom-gradient-picker-styles.js → custom-gradient-picker-styles.tsx} +0 -0
  481. /package/src/{color-list-picker → duotone-picker/color-list-picker}/style.scss +0 -0
  482. /package/src/duotone-picker/{index.js → index.ts} +0 -0
  483. /package/src/{index.js → index.ts} +0 -0
  484. /package/src/{private-apis.js → private-apis.ts} +0 -0
@@ -5,38 +5,54 @@ import { getHorizontalRelativeGradientPosition } from '../utils';
5
5
 
6
6
  describe( 'getHorizontalRelativeGradientPosition', () => {
7
7
  it( 'should return relative percentage position', () => {
8
- const containerElement = {
9
- getBoundingClientRect: () => ( {
10
- x: 0,
11
- width: 1000,
12
- } ),
13
- };
8
+ jest.spyOn(
9
+ window.HTMLElement.prototype,
10
+ 'getBoundingClientRect'
11
+ ).mockImplementationOnce(
12
+ () =>
13
+ ( {
14
+ x: 0,
15
+ width: 1000,
16
+ } as DOMRect )
17
+ );
14
18
 
19
+ const containerElement = document.createElement( 'div' );
15
20
  expect(
16
21
  getHorizontalRelativeGradientPosition( 500, containerElement )
17
22
  ).toBe( 50 );
18
23
  } );
19
24
 
20
25
  it( 'should subtract the x position of the container from the mouse position', () => {
21
- const containerElement = {
22
- getBoundingClientRect: () => ( {
23
- x: 50,
24
- width: 1000,
25
- } ),
26
- };
26
+ jest.spyOn(
27
+ window.HTMLElement.prototype,
28
+ 'getBoundingClientRect'
29
+ ).mockImplementationOnce(
30
+ () =>
31
+ ( {
32
+ x: 50,
33
+ width: 1000,
34
+ } as DOMRect )
35
+ );
27
36
 
37
+ const containerElement = document.createElement( 'div' );
28
38
  expect(
29
39
  getHorizontalRelativeGradientPosition( 550, containerElement )
30
40
  ).toBe( 50 );
31
41
  } );
32
42
 
33
43
  it( 'should clamp to a whole percentage number', () => {
34
- const containerElement = {
35
- getBoundingClientRect: () => ( {
36
- x: 0,
37
- width: 1000,
38
- } ),
39
- };
44
+ jest.spyOn(
45
+ window.HTMLElement.prototype,
46
+ 'getBoundingClientRect'
47
+ ).mockImplementationOnce(
48
+ () =>
49
+ ( {
50
+ x: 0,
51
+ width: 1000,
52
+ } as DOMRect )
53
+ );
54
+
55
+ const containerElement = document.createElement( 'div' );
40
56
 
41
57
  expect(
42
58
  getHorizontalRelativeGradientPosition( 333, containerElement )
@@ -44,12 +60,17 @@ describe( 'getHorizontalRelativeGradientPosition', () => {
44
60
  } );
45
61
 
46
62
  it( 'should clamp to zero when mouse position is less the x position', () => {
47
- const containerElement = {
48
- getBoundingClientRect: () => ( {
49
- x: 50,
50
- width: 1000,
51
- } ),
52
- };
63
+ jest.spyOn(
64
+ window.HTMLElement.prototype,
65
+ 'getBoundingClientRect'
66
+ ).mockImplementationOnce(
67
+ () =>
68
+ ( {
69
+ x: 50,
70
+ width: 1000,
71
+ } as DOMRect )
72
+ );
73
+ const containerElement = document.createElement( 'div' );
53
74
 
54
75
  expect(
55
76
  getHorizontalRelativeGradientPosition( 2, containerElement )
@@ -57,12 +78,18 @@ describe( 'getHorizontalRelativeGradientPosition', () => {
57
78
  } );
58
79
 
59
80
  it( 'should clamp to 100 when mouse position is greater than width', () => {
60
- const containerElement = {
61
- getBoundingClientRect: () => ( {
62
- x: 0,
63
- width: 1000,
64
- } ),
65
- };
81
+ jest.spyOn(
82
+ window.HTMLElement.prototype,
83
+ 'getBoundingClientRect'
84
+ ).mockImplementationOnce(
85
+ () =>
86
+ ( {
87
+ x: 50,
88
+ width: 1000,
89
+ } as DOMRect )
90
+ );
91
+
92
+ const containerElement = document.createElement( 'div' );
66
93
 
67
94
  expect(
68
95
  getHorizontalRelativeGradientPosition( 1500, containerElement )
@@ -70,7 +97,7 @@ describe( 'getHorizontalRelativeGradientPosition', () => {
70
97
  } );
71
98
 
72
99
  it( 'should return undefined if no containerElement is provided', () => {
73
- const containerElement = undefined;
100
+ const containerElement = null;
74
101
 
75
102
  expect(
76
103
  getHorizontalRelativeGradientPosition( 1500, containerElement )
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { MINIMUM_DISTANCE_BETWEEN_POINTS } from './constants';
5
+ import type { ControlPoint } from '../types';
6
+
7
+ /**
8
+ * Clamps a number between 0 and 100.
9
+ *
10
+ * @param value Value to clamp.
11
+ *
12
+ * @return Value clamped between 0 and 100.
13
+ */
14
+ export function clampPercent( value: number ) {
15
+ return Math.max( 0, Math.min( 100, value ) );
16
+ }
17
+
18
+ /**
19
+ * Check if a control point is overlapping with another.
20
+ *
21
+ * @param value Array of control points.
22
+ * @param initialIndex Index of the position to test.
23
+ * @param newPosition New position of the control point.
24
+ * @param minDistance Distance considered to be overlapping.
25
+ *
26
+ * @return True if the point is overlapping.
27
+ */
28
+ export function isOverlapping(
29
+ value: ControlPoint[],
30
+ initialIndex: number,
31
+ newPosition: number,
32
+ minDistance: number = MINIMUM_DISTANCE_BETWEEN_POINTS
33
+ ) {
34
+ const initialPosition = value[ initialIndex ].position;
35
+ const minPosition = Math.min( initialPosition, newPosition );
36
+ const maxPosition = Math.max( initialPosition, newPosition );
37
+
38
+ return value.some( ( { position }, index ) => {
39
+ return (
40
+ index !== initialIndex &&
41
+ ( Math.abs( position - newPosition ) < minDistance ||
42
+ ( minPosition < position && position < maxPosition ) )
43
+ );
44
+ } );
45
+ }
46
+
47
+ /**
48
+ * Adds a control point from an array and returns the new array.
49
+ *
50
+ * @param points Array of control points.
51
+ * @param position Position to insert the new point.
52
+ * @param color Color to update the control point at index.
53
+ *
54
+ * @return New array of control points.
55
+ */
56
+ export function addControlPoint(
57
+ points: ControlPoint[],
58
+ position: number,
59
+ color: ControlPoint[ 'color' ]
60
+ ) {
61
+ const nextIndex = points.findIndex(
62
+ ( point ) => point.position > position
63
+ );
64
+ const newPoint = { color, position };
65
+ const newPoints = points.slice();
66
+ newPoints.splice( nextIndex - 1, 0, newPoint );
67
+ return newPoints;
68
+ }
69
+
70
+ /**
71
+ * Removes a control point from an array and returns the new array.
72
+ *
73
+ * @param points Array of control points.
74
+ * @param index Index to remove.
75
+ *
76
+ * @return New array of control points.
77
+ */
78
+ export function removeControlPoint( points: ControlPoint[], index: number ) {
79
+ return points.filter( ( _point, pointIndex ) => {
80
+ return pointIndex !== index;
81
+ } );
82
+ }
83
+ /**
84
+ * Updates a control point from an array and returns the new array.
85
+ *
86
+ * @param points Array of control points.
87
+ * @param index Index to update.
88
+ * @param newPoint New control point to replace the index.
89
+ *
90
+ * @return New array of control points.
91
+ */
92
+ export function updateControlPoint(
93
+ points: ControlPoint[],
94
+ index: number,
95
+ newPoint: ControlPoint
96
+ ) {
97
+ const newValue = points.slice();
98
+ newValue[ index ] = newPoint;
99
+ return newValue;
100
+ }
101
+
102
+ /**
103
+ * Updates the position of a control point from an array and returns the new array.
104
+ *
105
+ * @param points Array of control points.
106
+ * @param index Index to update.
107
+ * @param newPosition Position to move the control point at index.
108
+ *
109
+ * @return New array of control points.
110
+ */
111
+ export function updateControlPointPosition(
112
+ points: ControlPoint[],
113
+ index: number,
114
+ newPosition: ControlPoint[ 'position' ]
115
+ ) {
116
+ if ( isOverlapping( points, index, newPosition ) ) {
117
+ return points;
118
+ }
119
+ const newPoint = {
120
+ ...points[ index ],
121
+ position: newPosition,
122
+ };
123
+ return updateControlPoint( points, index, newPoint );
124
+ }
125
+
126
+ /**
127
+ * Updates the position of a control point from an array and returns the new array.
128
+ *
129
+ * @param points Array of control points.
130
+ * @param index Index to update.
131
+ * @param newColor Color to update the control point at index.
132
+ *
133
+ * @return New array of control points.
134
+ */
135
+ export function updateControlPointColor(
136
+ points: ControlPoint[],
137
+ index: number,
138
+ newColor: ControlPoint[ 'color' ]
139
+ ) {
140
+ const newPoint = {
141
+ ...points[ index ],
142
+ color: newColor,
143
+ };
144
+ return updateControlPoint( points, index, newPoint );
145
+ }
146
+
147
+ /**
148
+ * Updates the position of a control point from an array and returns the new array.
149
+ *
150
+ * @param points Array of control points.
151
+ * @param position Position of the color stop.
152
+ * @param newColor Color to update the control point at index.
153
+ *
154
+ * @return New array of control points.
155
+ */
156
+ export function updateControlPointColorByPosition(
157
+ points: ControlPoint[],
158
+ position: ControlPoint[ 'position' ],
159
+ newColor: ControlPoint[ 'color' ]
160
+ ) {
161
+ const index = points.findIndex( ( point ) => point.position === position );
162
+ return updateControlPointColor( points, index, newColor );
163
+ }
164
+
165
+ /**
166
+ * Gets the horizontal coordinate when dragging a control point with the mouse.
167
+ *
168
+ * @param mouseXcoordinate Horizontal coordinate of the mouse position.
169
+ * @param containerElement Container for the gradient picker.
170
+ *
171
+ * @return Whole number percentage from the left.
172
+ */
173
+ export function getHorizontalRelativeGradientPosition(
174
+ mouseXcoordinate: number,
175
+ containerElement: HTMLDivElement
176
+ ): number;
177
+ export function getHorizontalRelativeGradientPosition(
178
+ mouseXcoordinate: number,
179
+ containerElement: null
180
+ ): undefined;
181
+ export function getHorizontalRelativeGradientPosition(
182
+ mouseXCoordinate: number,
183
+ containerElement: HTMLDivElement | null
184
+ ) {
185
+ if ( ! containerElement ) {
186
+ return;
187
+ }
188
+ const { x, width } = containerElement.getBoundingClientRect();
189
+ const absolutePositionValue = mouseXCoordinate - x;
190
+ return Math.round(
191
+ clampPercent( ( absolutePositionValue * 100 ) / width )
192
+ );
193
+ }
@@ -1,9 +1,8 @@
1
- // @ts-nocheck
2
-
3
1
  /**
4
2
  * External dependencies
5
3
  */
6
4
  import classnames from 'classnames';
5
+ import type gradientParser from 'gradient-parser';
7
6
 
8
7
  /**
9
8
  * WordPress dependencies
@@ -30,23 +29,31 @@ import {
30
29
  DEFAULT_LINEAR_GRADIENT_ANGLE,
31
30
  HORIZONTAL_GRADIENT_ORIENTATION,
32
31
  GRADIENT_OPTIONS,
33
- DEFAULT_GRADIENT,
34
32
  } from './constants';
35
33
  import {
36
34
  AccessoryWrapper,
37
35
  SelectWrapper,
38
36
  } from './styles/custom-gradient-picker-styles';
37
+ import type {
38
+ CustomGradientPickerProps,
39
+ GradientAnglePickerProps,
40
+ GradientTypePickerProps,
41
+ } from './types';
39
42
 
40
- const GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => {
43
+ const GradientAnglePicker = ( {
44
+ gradientAST,
45
+ hasGradient,
46
+ onChange,
47
+ }: GradientAnglePickerProps ) => {
41
48
  const angle =
42
49
  gradientAST?.orientation?.value ?? DEFAULT_LINEAR_GRADIENT_ANGLE;
43
- const onAngleChange = ( newAngle ) => {
50
+ const onAngleChange = ( newAngle: number ) => {
44
51
  onChange(
45
52
  serializeGradient( {
46
53
  ...gradientAST,
47
54
  orientation: {
48
55
  type: 'angular',
49
- value: newAngle,
56
+ value: `${ newAngle }`,
50
57
  },
51
58
  } )
52
59
  );
@@ -60,17 +67,22 @@ const GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => {
60
67
  );
61
68
  };
62
69
 
63
- const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
70
+ const GradientTypePicker = ( {
71
+ gradientAST,
72
+ hasGradient,
73
+ onChange,
74
+ }: GradientTypePickerProps ) => {
64
75
  const { type } = gradientAST;
76
+
65
77
  const onSetLinearGradient = () => {
66
78
  onChange(
67
79
  serializeGradient( {
68
80
  ...gradientAST,
69
- ...( gradientAST.orientation
70
- ? {}
71
- : { orientation: HORIZONTAL_GRADIENT_ORIENTATION } ),
81
+ orientation: gradientAST.orientation
82
+ ? undefined
83
+ : HORIZONTAL_GRADIENT_ORIENTATION,
72
84
  type: 'linear-gradient',
73
- } )
85
+ } as gradientParser.LinearGradientNode )
74
86
  );
75
87
  };
76
88
 
@@ -84,7 +96,7 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
84
96
  );
85
97
  };
86
98
 
87
- const handleOnChange = ( next ) => {
99
+ const handleOnChange = ( next: string ) => {
88
100
  if ( next === 'linear-gradient' ) {
89
101
  onSetLinearGradient();
90
102
  }
@@ -102,30 +114,57 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
102
114
  onChange={ handleOnChange }
103
115
  options={ GRADIENT_OPTIONS }
104
116
  size="__unstable-large"
105
- value={ hasGradient && type }
117
+ value={ hasGradient ? type : undefined }
106
118
  />
107
119
  );
108
120
  };
109
121
 
110
- export default function CustomGradientPicker( {
122
+ /**
123
+ * CustomGradientPicker is a React component that renders a UI for specifying
124
+ * linear or radial gradients. Radial gradients are displayed in the picker as
125
+ * a slice of the gradient from the center to the outside.
126
+ *
127
+ * ```jsx
128
+ * import { CustomGradientPicker } from '@wordpress/components';
129
+ * import { useState } from '@wordpress/element';
130
+ *
131
+ * const MyCustomGradientPicker = () => {
132
+ * const [ gradient, setGradient ] = useState();
133
+ *
134
+ * return (
135
+ * <CustomGradientPicker
136
+ * value={ gradient }
137
+ * onChange={ setGradient }
138
+ * />
139
+ * );
140
+ * };
141
+ * ```
142
+ */
143
+ export function CustomGradientPicker( {
111
144
  /** Start opting into the new margin-free styles that will become the default in a future version. */
112
145
  __nextHasNoMargin = false,
113
146
  value,
114
147
  onChange,
115
- __experimentalIsRenderedInSidebar,
116
- } ) {
117
- const gradientAST = getGradientAstWithDefault( value );
148
+ __experimentalIsRenderedInSidebar = false,
149
+ }: CustomGradientPickerProps ) {
150
+ const { gradientAST, hasGradient } = getGradientAstWithDefault( value );
151
+
118
152
  // On radial gradients the bar should display a linear gradient.
119
153
  // On radial gradients the bar represents a slice of the gradient from the center until the outside.
120
154
  // On liner gradients the bar represents the color stops from left to right independently of the angle.
121
155
  const background = getLinearGradientRepresentation( gradientAST );
122
- const hasGradient = gradientAST.value !== DEFAULT_GRADIENT;
156
+
123
157
  // Control points color option may be hex from presets, custom colors will be rgb.
124
158
  // The position should always be a percentage.
125
- const controlPoints = gradientAST.colorStops.map( ( colorStop ) => ( {
126
- color: getStopCssColor( colorStop ),
127
- position: parseInt( colorStop.length.value ),
128
- } ) );
159
+ const controlPoints = gradientAST.colorStops.map( ( colorStop ) => {
160
+ return {
161
+ color: getStopCssColor( colorStop ),
162
+ // Although it's already been checked by `hasUnsupportedLength` in `getGradientAstWithDefault`,
163
+ // TypeScript doesn't know that `colorStop.length` is not undefined here.
164
+ // @ts-expect-error
165
+ position: parseInt( colorStop.length.value ),
166
+ };
167
+ } );
129
168
 
130
169
  if ( ! __nextHasNoMargin ) {
131
170
  deprecated(
@@ -187,3 +226,5 @@ export default function CustomGradientPicker( {
187
226
  </VStack>
188
227
  );
189
228
  }
229
+
230
+ export default CustomGradientPicker;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type gradientParser from 'gradient-parser';
5
+
6
+ export function serializeGradientColor( {
7
+ type,
8
+ value,
9
+ }: gradientParser.ColorStop ) {
10
+ if ( type === 'literal' ) {
11
+ return value;
12
+ }
13
+ if ( type === 'hex' ) {
14
+ return `#${ value }`;
15
+ }
16
+ return `${ type }(${ value.join( ',' ) })`;
17
+ }
18
+
19
+ export function serializeGradientPosition(
20
+ position: gradientParser.ColorStop[ 'length' ]
21
+ ) {
22
+ if ( ! position ) {
23
+ return '';
24
+ }
25
+ const { value, type } = position;
26
+ return `${ value }${ type }`;
27
+ }
28
+
29
+ export function serializeGradientColorStop( {
30
+ type,
31
+ value,
32
+ length,
33
+ }: gradientParser.ColorStop ) {
34
+ return `${ serializeGradientColor( {
35
+ type,
36
+ value,
37
+ } as gradientParser.ColorStop ) } ${ serializeGradientPosition( length ) }`;
38
+ }
39
+
40
+ export function serializeGradientOrientation(
41
+ orientation: gradientParser.GradientNode[ 'orientation' ]
42
+ ) {
43
+ if (
44
+ Array.isArray( orientation ) ||
45
+ ! orientation ||
46
+ orientation.type !== 'angular'
47
+ ) {
48
+ return;
49
+ }
50
+ return `${ orientation.value }deg`;
51
+ }
52
+
53
+ export function serializeGradient( {
54
+ type,
55
+ orientation,
56
+ colorStops,
57
+ }: gradientParser.GradientNode ) {
58
+ const serializedOrientation = serializeGradientOrientation( orientation );
59
+ const serializedColorStops = colorStops
60
+ .sort( ( colorStop1, colorStop2 ) => {
61
+ const getNumericStopValue = (
62
+ colorStop: gradientParser.ColorStop
63
+ ) => {
64
+ return colorStop?.length?.value === undefined
65
+ ? 0
66
+ : parseInt( colorStop.length.value );
67
+ };
68
+
69
+ return (
70
+ getNumericStopValue( colorStop1 ) -
71
+ getNumericStopValue( colorStop2 )
72
+ );
73
+ } )
74
+ .map( serializeGradientColorStop );
75
+ return `${ type }(${ [ serializedOrientation, ...serializedColorStops ]
76
+ .filter( Boolean )
77
+ .join( ',' ) })`;
78
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ComponentMeta, ComponentStory } from '@storybook/react';
5
+ /**
6
+ * WordPress dependencies
7
+ */
8
+ import { useState } from '@wordpress/element';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import CustomGradientPicker from '../';
14
+
15
+ const meta: ComponentMeta< typeof CustomGradientPicker > = {
16
+ title: 'Components/CustomGradientPicker',
17
+ component: CustomGradientPicker,
18
+ parameters: {
19
+ actions: { argTypesRegex: '^on.*' },
20
+ controls: { expanded: true },
21
+ docs: { source: { state: 'open' } },
22
+ },
23
+ };
24
+ export default meta;
25
+
26
+ const CustomGradientPickerWithState: ComponentStory<
27
+ typeof CustomGradientPicker
28
+ > = ( { onChange, ...props } ) => {
29
+ const [ gradient, setGradient ] = useState< string >();
30
+ return (
31
+ <CustomGradientPicker
32
+ { ...props }
33
+ value={ gradient }
34
+ onChange={ ( newGradient ) => {
35
+ setGradient( newGradient );
36
+ onChange( newGradient );
37
+ } }
38
+ />
39
+ );
40
+ };
41
+
42
+ export const Default = CustomGradientPickerWithState.bind( {} );
43
+ Default.args = {
44
+ __nextHasNoMargin: true,
45
+ };
@@ -7,14 +7,30 @@ $components-custom-gradient-picker__padding: $grid-unit-20; // 48px container, 1
7
7
  }
8
8
  }
9
9
 
10
- .components-custom-gradient-picker__gradient-bar:not(.has-gradient) {
11
- opacity: 0.4;
12
- }
13
-
14
10
  .components-custom-gradient-picker__gradient-bar {
15
11
  border-radius: $radius-block-ui;
16
12
  width: 100%;
17
13
  height: $grid-unit-60;
14
+ position: relative;
15
+ z-index: 1;
16
+
17
+ &.has-gradient {
18
+ // The background image creates a checkerboard pattern. Ignore rtlcss to
19
+ // make it work both in LTR and RTL.
20
+ // See https://github.com/WordPress/gutenberg/pull/42510
21
+ /*rtl:begin:ignore*/
22
+ background-image:
23
+ repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200),
24
+ repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200);
25
+ background-position: 0 0, 12px 12px;
26
+ /*rtl:end:ignore*/
27
+ background-size: calc(2 * 12px) calc(2 * 12px);
28
+ }
29
+
30
+ .components-custom-gradient-picker__gradient-bar-background {
31
+ position: absolute;
32
+ inset: 0;
33
+ }
18
34
 
19
35
  .components-custom-gradient-picker__markers-container {
20
36
  position: relative;
@@ -109,3 +125,8 @@ $components-custom-gradient-picker__padding: $grid-unit-20; // 48px container, 1
109
125
  }
110
126
  }
111
127
  }
128
+
129
+ .components-custom-gradient-picker__ui-line {
130
+ position: relative;
131
+ z-index: 0;
132
+ }