@wordpress/components 29.1.1 → 29.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/CHANGELOG.md +29 -6
  2. package/CONTRIBUTING.md +4 -4
  3. package/README.md +1 -1
  4. package/build/badge/index.js +26 -22
  5. package/build/badge/index.js.map +1 -1
  6. package/build/border-box-control/border-box-control-linked-button/component.js +8 -15
  7. package/build/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  8. package/build/box-control/index.js +6 -0
  9. package/build/box-control/index.js.map +1 -1
  10. package/build/box-control/linked-button.js +7 -11
  11. package/build/box-control/linked-button.js.map +1 -1
  12. package/build/box-control/types.js.map +1 -1
  13. package/build/circular-option-picker/circular-option-picker-option.js +9 -7
  14. package/build/circular-option-picker/circular-option-picker-option.js.map +1 -1
  15. package/build/circular-option-picker/circular-option-picker.js +0 -1
  16. package/build/circular-option-picker/circular-option-picker.js.map +1 -1
  17. package/build/color-palette/index.js +1 -6
  18. package/build/color-palette/index.js.map +1 -1
  19. package/build/font-size-picker/index.native.js +1 -1
  20. package/build/font-size-picker/index.native.js.map +1 -1
  21. package/build/higher-order/with-focus-return/index.js +1 -1
  22. package/build/higher-order/with-focus-return/index.js.map +1 -1
  23. package/build/input-control/styles/input-control-styles.js +22 -22
  24. package/build/input-control/styles/input-control-styles.js.map +1 -1
  25. package/build/menu/checkbox-item.js +6 -6
  26. package/build/menu/checkbox-item.js.map +1 -1
  27. package/build/menu/context.js +2 -2
  28. package/build/menu/context.js.map +1 -1
  29. package/build/menu/group-label.js +4 -4
  30. package/build/menu/group-label.js.map +1 -1
  31. package/build/menu/group.js +4 -4
  32. package/build/menu/group.js.map +1 -1
  33. package/build/menu/index.js +87 -14
  34. package/build/menu/index.js.map +1 -1
  35. package/build/menu/item-help-text.js +4 -4
  36. package/build/menu/item-help-text.js.map +1 -1
  37. package/build/menu/item-label.js +4 -4
  38. package/build/menu/item-label.js.map +1 -1
  39. package/build/menu/item.js +6 -6
  40. package/build/menu/item.js.map +1 -1
  41. package/build/menu/popover.js +5 -5
  42. package/build/menu/popover.js.map +1 -1
  43. package/build/menu/radio-item.js +6 -6
  44. package/build/menu/radio-item.js.map +1 -1
  45. package/build/menu/separator.js +4 -4
  46. package/build/menu/separator.js.map +1 -1
  47. package/build/menu/styles.js +41 -41
  48. package/build/menu/styles.js.map +1 -1
  49. package/build/menu/submenu-trigger-item.js +5 -5
  50. package/build/menu/submenu-trigger-item.js.map +1 -1
  51. package/build/menu/trigger-button.js +3 -3
  52. package/build/menu/trigger-button.js.map +1 -1
  53. package/build/menu/types.js.map +1 -1
  54. package/build/mobile/bottom-sheet/nav-bar/action-button.native.js +1 -1
  55. package/build/mobile/bottom-sheet/nav-bar/action-button.native.js.map +1 -1
  56. package/build/mobile/utils/get-px-from-css-unit.native.js +3 -3
  57. package/build/mobile/utils/get-px-from-css-unit.native.js.map +1 -1
  58. package/build/notice/types.js.map +1 -1
  59. package/build/search-control/index.js +1 -1
  60. package/build/search-control/index.js.map +1 -1
  61. package/build/text/hook.js +8 -6
  62. package/build/text/hook.js.map +1 -1
  63. package/build/text/utils.js +1 -1
  64. package/build/text/utils.js.map +1 -1
  65. package/build-module/badge/index.js +28 -22
  66. package/build-module/badge/index.js.map +1 -1
  67. package/build-module/border-box-control/border-box-control-linked-button/component.js +8 -15
  68. package/build-module/border-box-control/border-box-control-linked-button/component.js.map +1 -1
  69. package/build-module/box-control/index.js +6 -0
  70. package/build-module/box-control/index.js.map +1 -1
  71. package/build-module/box-control/linked-button.js +7 -11
  72. package/build-module/box-control/linked-button.js.map +1 -1
  73. package/build-module/box-control/types.js.map +1 -1
  74. package/build-module/circular-option-picker/circular-option-picker-option.js +9 -7
  75. package/build-module/circular-option-picker/circular-option-picker-option.js.map +1 -1
  76. package/build-module/circular-option-picker/circular-option-picker.js +0 -1
  77. package/build-module/circular-option-picker/circular-option-picker.js.map +1 -1
  78. package/build-module/color-palette/index.js +1 -6
  79. package/build-module/color-palette/index.js.map +1 -1
  80. package/build-module/font-size-picker/index.native.js +1 -1
  81. package/build-module/font-size-picker/index.native.js.map +1 -1
  82. package/build-module/higher-order/with-focus-return/index.js +1 -1
  83. package/build-module/higher-order/with-focus-return/index.js.map +1 -1
  84. package/build-module/input-control/styles/input-control-styles.js +22 -22
  85. package/build-module/input-control/styles/input-control-styles.js.map +1 -1
  86. package/build-module/menu/checkbox-item.js +6 -6
  87. package/build-module/menu/checkbox-item.js.map +1 -1
  88. package/build-module/menu/context.js +1 -1
  89. package/build-module/menu/context.js.map +1 -1
  90. package/build-module/menu/group-label.js +4 -4
  91. package/build-module/menu/group-label.js.map +1 -1
  92. package/build-module/menu/group.js +4 -4
  93. package/build-module/menu/group.js.map +1 -1
  94. package/build-module/menu/index.js +99 -26
  95. package/build-module/menu/index.js.map +1 -1
  96. package/build-module/menu/item-help-text.js +4 -4
  97. package/build-module/menu/item-help-text.js.map +1 -1
  98. package/build-module/menu/item-label.js +4 -4
  99. package/build-module/menu/item-label.js.map +1 -1
  100. package/build-module/menu/item.js +6 -6
  101. package/build-module/menu/item.js.map +1 -1
  102. package/build-module/menu/popover.js +5 -5
  103. package/build-module/menu/popover.js.map +1 -1
  104. package/build-module/menu/radio-item.js +6 -6
  105. package/build-module/menu/radio-item.js.map +1 -1
  106. package/build-module/menu/separator.js +4 -4
  107. package/build-module/menu/separator.js.map +1 -1
  108. package/build-module/menu/styles.js +40 -40
  109. package/build-module/menu/styles.js.map +1 -1
  110. package/build-module/menu/submenu-trigger-item.js +6 -6
  111. package/build-module/menu/submenu-trigger-item.js.map +1 -1
  112. package/build-module/menu/trigger-button.js +3 -3
  113. package/build-module/menu/trigger-button.js.map +1 -1
  114. package/build-module/menu/types.js.map +1 -1
  115. package/build-module/mobile/bottom-sheet/nav-bar/action-button.native.js +1 -1
  116. package/build-module/mobile/bottom-sheet/nav-bar/action-button.native.js.map +1 -1
  117. package/build-module/mobile/utils/get-px-from-css-unit.native.js +3 -3
  118. package/build-module/mobile/utils/get-px-from-css-unit.native.js.map +1 -1
  119. package/build-module/notice/types.js.map +1 -1
  120. package/build-module/search-control/index.js +1 -1
  121. package/build-module/search-control/index.js.map +1 -1
  122. package/build-module/text/hook.js +8 -6
  123. package/build-module/text/hook.js.map +1 -1
  124. package/build-module/text/utils.js +1 -1
  125. package/build-module/text/utils.js.map +1 -1
  126. package/build-style/style-rtl.css +89 -170
  127. package/build-style/style.css +89 -170
  128. package/build-types/badge/index.d.ts.map +1 -1
  129. package/build-types/border-box-control/border-box-control-linked-button/component.d.ts.map +1 -1
  130. package/build-types/box-control/index.d.ts.map +1 -1
  131. package/build-types/box-control/linked-button.d.ts.map +1 -1
  132. package/build-types/box-control/stories/index.story.d.ts +7 -2331
  133. package/build-types/box-control/stories/index.story.d.ts.map +1 -1
  134. package/build-types/box-control/types.d.ts +15 -3
  135. package/build-types/box-control/types.d.ts.map +1 -1
  136. package/build-types/circular-option-picker/circular-option-picker-option.d.ts.map +1 -1
  137. package/build-types/circular-option-picker/circular-option-picker.d.ts.map +1 -1
  138. package/build-types/circular-option-picker/stories/index.story.d.ts.map +1 -1
  139. package/build-types/color-palette/index.d.ts.map +1 -1
  140. package/build-types/higher-order/with-focus-return/index.d.ts +1 -1
  141. package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
  142. package/build-types/menu/checkbox-item.d.ts +2 -2
  143. package/build-types/menu/checkbox-item.d.ts.map +1 -1
  144. package/build-types/menu/context.d.ts +2 -2
  145. package/build-types/menu/context.d.ts.map +1 -1
  146. package/build-types/menu/group-label.d.ts +2 -2
  147. package/build-types/menu/group-label.d.ts.map +1 -1
  148. package/build-types/menu/group.d.ts +2 -2
  149. package/build-types/menu/group.d.ts.map +1 -1
  150. package/build-types/menu/index.d.ts +84 -12
  151. package/build-types/menu/index.d.ts.map +1 -1
  152. package/build-types/menu/item-help-text.d.ts +1 -1
  153. package/build-types/menu/item-help-text.d.ts.map +1 -1
  154. package/build-types/menu/item-label.d.ts +1 -1
  155. package/build-types/menu/item-label.d.ts.map +1 -1
  156. package/build-types/menu/item.d.ts +2 -2
  157. package/build-types/menu/item.d.ts.map +1 -1
  158. package/build-types/menu/popover.d.ts +2 -2
  159. package/build-types/menu/popover.d.ts.map +1 -1
  160. package/build-types/menu/radio-item.d.ts +2 -2
  161. package/build-types/menu/radio-item.d.ts.map +1 -1
  162. package/build-types/menu/separator.d.ts +2 -2
  163. package/build-types/menu/separator.d.ts.map +1 -1
  164. package/build-types/menu/styles.d.ts +15 -15
  165. package/build-types/menu/styles.d.ts.map +1 -1
  166. package/build-types/menu/submenu-trigger-item.d.ts +2 -2
  167. package/build-types/menu/submenu-trigger-item.d.ts.map +1 -1
  168. package/build-types/menu/trigger-button.d.ts +2 -2
  169. package/build-types/menu/trigger-button.d.ts.map +1 -1
  170. package/build-types/menu/types.d.ts +10 -10
  171. package/build-types/menu/types.d.ts.map +1 -1
  172. package/build-types/menu-group/stories/index.story.d.ts +1 -1
  173. package/build-types/notice/types.d.ts +1 -1
  174. package/build-types/progress-bar/stories/index.story.d.ts +1 -1
  175. package/build-types/tabs/stories/index.story.d.ts +0 -3
  176. package/build-types/tabs/stories/index.story.d.ts.map +1 -1
  177. package/build-types/text/hook.d.ts.map +1 -1
  178. package/build-types/text/utils.d.ts +1 -1
  179. package/package.json +19 -19
  180. package/src/animate/style.scss +16 -12
  181. package/src/badge/index.tsx +28 -27
  182. package/src/border-box-control/border-box-control-linked-button/component.tsx +9 -14
  183. package/src/border-control/test/index.js +12 -4
  184. package/src/box-control/index.tsx +9 -0
  185. package/src/box-control/linked-button.tsx +8 -11
  186. package/src/box-control/test/index.tsx +9 -2
  187. package/src/box-control/types.ts +26 -11
  188. package/src/button/style.scss +15 -12
  189. package/src/checkbox-control/style.scss +4 -2
  190. package/src/circular-option-picker/README.md +1 -2
  191. package/src/circular-option-picker/circular-option-picker-option.tsx +17 -10
  192. package/src/circular-option-picker/circular-option-picker.tsx +0 -1
  193. package/src/circular-option-picker/stories/index.story.tsx +0 -1
  194. package/src/circular-option-picker/style.scss +10 -5
  195. package/src/color-palette/index.tsx +0 -7
  196. package/src/color-palette/test/index.tsx +2 -8
  197. package/src/combobox-control/test/index.tsx +1 -1
  198. package/src/drop-zone/style.scss +6 -9
  199. package/src/font-size-picker/index.native.js +1 -1
  200. package/src/form-toggle/style.scss +17 -10
  201. package/src/form-token-field/style.scss +9 -4
  202. package/src/higher-order/navigate-regions/style.scss +2 -2
  203. package/src/higher-order/with-focus-return/index.tsx +1 -1
  204. package/src/input-control/styles/input-control-styles.tsx +6 -0
  205. package/src/menu/README.md +421 -174
  206. package/src/menu/checkbox-item.tsx +12 -12
  207. package/src/menu/context.tsx +2 -4
  208. package/src/menu/docs-manifest.json +62 -0
  209. package/src/menu/group-label.tsx +7 -7
  210. package/src/menu/group.tsx +7 -11
  211. package/src/menu/index.tsx +101 -31
  212. package/src/menu/item-help-text.tsx +5 -7
  213. package/src/menu/item-label.tsx +5 -7
  214. package/src/menu/item.tsx +12 -12
  215. package/src/menu/popover.tsx +9 -9
  216. package/src/menu/radio-item.tsx +12 -12
  217. package/src/menu/separator.tsx +7 -7
  218. package/src/menu/stories/best-practices.mdx +38 -0
  219. package/src/menu/stories/index.story.tsx +8 -8
  220. package/src/menu/styles.ts +24 -24
  221. package/src/menu/submenu-trigger-item.tsx +9 -9
  222. package/src/menu/trigger-button.tsx +6 -6
  223. package/src/menu/types.ts +10 -10
  224. package/src/menu-group/stories/index.story.tsx +2 -2
  225. package/src/mobile/bottom-sheet/nav-bar/action-button.native.js +1 -1
  226. package/src/mobile/utils/get-px-from-css-unit.native.js +3 -3
  227. package/src/modal/style.scss +4 -2
  228. package/src/modal/test/index.tsx +5 -4
  229. package/src/notice/README.md +3 -3
  230. package/src/notice/types.ts +1 -1
  231. package/src/palette-edit/test/index.tsx +1 -1
  232. package/src/panel/style.scss +14 -6
  233. package/src/placeholder/style.scss +5 -3
  234. package/src/progress-bar/stories/index.story.tsx +1 -1
  235. package/src/resizable-box/style.scss +14 -9
  236. package/src/search-control/index.tsx +1 -1
  237. package/src/tab-panel/style.scss +6 -4
  238. package/src/tabs/stories/index.story.tsx +0 -131
  239. package/src/text/README.md +1 -1
  240. package/src/text/hook.ts +3 -2
  241. package/src/text/stories/index.story.tsx +2 -2
  242. package/src/text/test/index.tsx +1 -1
  243. package/src/text/utils.ts +1 -1
  244. package/src/text-highlight/test/index.tsx +3 -3
  245. package/src/toolbar/toolbar/style.scss +4 -3
  246. package/tsconfig.tsbuildinfo +1 -1
@@ -13,18 +13,18 @@ import { Icon, check } from '@wordpress/icons';
13
13
  * Internal dependencies
14
14
  */
15
15
  import type { WordPressComponentProps } from '../context';
16
- import { MenuContext } from './context';
17
- import type { MenuCheckboxItemProps } from './types';
16
+ import { Context } from './context';
17
+ import type { CheckboxItemProps } from './types';
18
18
  import * as Styled from './styles';
19
19
 
20
- export const MenuCheckboxItem = forwardRef<
20
+ export const CheckboxItem = forwardRef<
21
21
  HTMLDivElement,
22
- WordPressComponentProps< MenuCheckboxItemProps, 'div', false >
23
- >( function MenuCheckboxItem(
22
+ WordPressComponentProps< CheckboxItemProps, 'div', false >
23
+ >( function CheckboxItem(
24
24
  { suffix, children, disabled = false, hideOnClick = false, ...props },
25
25
  ref
26
26
  ) {
27
- const menuContext = useContext( MenuContext );
27
+ const menuContext = useContext( Context );
28
28
 
29
29
  if ( ! menuContext?.store ) {
30
30
  throw new Error(
@@ -33,7 +33,7 @@ export const MenuCheckboxItem = forwardRef<
33
33
  }
34
34
 
35
35
  return (
36
- <Styled.MenuCheckboxItem
36
+ <Styled.CheckboxItem
37
37
  ref={ ref }
38
38
  { ...props }
39
39
  accessibleWhenDisabled
@@ -50,17 +50,17 @@ export const MenuCheckboxItem = forwardRef<
50
50
  <Icon icon={ check } size={ 24 } />
51
51
  </Ariakit.MenuItemCheck>
52
52
 
53
- <Styled.MenuItemContentWrapper>
54
- <Styled.MenuItemChildrenWrapper>
53
+ <Styled.ItemContentWrapper>
54
+ <Styled.ItemChildrenWrapper>
55
55
  { children }
56
- </Styled.MenuItemChildrenWrapper>
56
+ </Styled.ItemChildrenWrapper>
57
57
 
58
58
  { suffix && (
59
59
  <Styled.ItemSuffixWrapper>
60
60
  { suffix }
61
61
  </Styled.ItemSuffixWrapper>
62
62
  ) }
63
- </Styled.MenuItemContentWrapper>
64
- </Styled.MenuCheckboxItem>
63
+ </Styled.ItemContentWrapper>
64
+ </Styled.CheckboxItem>
65
65
  );
66
66
  } );
@@ -6,8 +6,6 @@ import { createContext } from '@wordpress/element';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import type { MenuContext as MenuContextType } from './types';
9
+ import type { ContextProps } from './types';
10
10
 
11
- export const MenuContext = createContext< MenuContextType | undefined >(
12
- undefined
13
- );
11
+ export const Context = createContext< ContextProps | undefined >( undefined );
@@ -0,0 +1,62 @@
1
+ {
2
+ "$schema": "../../schemas/docs-manifest.json",
3
+ "displayName": "Menu",
4
+ "filePath": "./index.tsx",
5
+ "subcomponents": [
6
+ {
7
+ "displayName": "TriggerButton",
8
+ "preferredDisplayName": "Menu.TriggerButton",
9
+ "filePath": "./trigger-button.tsx"
10
+ },
11
+ {
12
+ "displayName": "Popover",
13
+ "preferredDisplayName": "Menu.Popover",
14
+ "filePath": "./popover.tsx"
15
+ },
16
+ {
17
+ "displayName": "Item",
18
+ "preferredDisplayName": "Menu.Item",
19
+ "filePath": "./item.tsx"
20
+ },
21
+ {
22
+ "displayName": "RadioItem",
23
+ "preferredDisplayName": "Menu.RadioItem",
24
+ "filePath": "./radio-item.tsx"
25
+ },
26
+ {
27
+ "displayName": "CheckboxItem",
28
+ "preferredDisplayName": "Menu.CheckboxItem",
29
+ "filePath": "./checkbox-item.tsx"
30
+ },
31
+ {
32
+ "displayName": "ItemLabel",
33
+ "preferredDisplayName": "Menu.ItemLabel",
34
+ "filePath": "./item-label.tsx"
35
+ },
36
+ {
37
+ "displayName": "ItemHelpText",
38
+ "preferredDisplayName": "Menu.ItemHelpText",
39
+ "filePath": "./item-help-text.tsx"
40
+ },
41
+ {
42
+ "displayName": "Group",
43
+ "preferredDisplayName": "Menu.Group",
44
+ "filePath": "./group.tsx"
45
+ },
46
+ {
47
+ "displayName": "GroupLabel",
48
+ "preferredDisplayName": "Menu.GroupLabel",
49
+ "filePath": "./group-label.tsx"
50
+ },
51
+ {
52
+ "displayName": "Separator",
53
+ "preferredDisplayName": "Menu.Separator",
54
+ "filePath": "./separator.tsx"
55
+ },
56
+ {
57
+ "displayName": "SubmenuTriggerItem",
58
+ "preferredDisplayName": "Menu.SubmenuTriggerItem",
59
+ "filePath": "./submenu-trigger-item.tsx"
60
+ }
61
+ ]
62
+ }
@@ -7,16 +7,16 @@ import { forwardRef, useContext } from '@wordpress/element';
7
7
  * Internal dependencies
8
8
  */
9
9
  import type { WordPressComponentProps } from '../context';
10
- import { MenuContext } from './context';
10
+ import { Context } from './context';
11
11
  import { Text } from '../text';
12
- import type { MenuGroupLabelProps } from './types';
12
+ import type { GroupLabelProps } from './types';
13
13
  import * as Styled from './styles';
14
14
 
15
- export const MenuGroupLabel = forwardRef<
15
+ export const GroupLabel = forwardRef<
16
16
  HTMLDivElement,
17
- WordPressComponentProps< MenuGroupLabelProps, 'div', false >
18
- >( function MenuGroup( props, ref ) {
19
- const menuContext = useContext( MenuContext );
17
+ WordPressComponentProps< GroupLabelProps, 'div', false >
18
+ >( function Group( props, ref ) {
19
+ const menuContext = useContext( Context );
20
20
 
21
21
  if ( ! menuContext?.store ) {
22
22
  throw new Error(
@@ -25,7 +25,7 @@ export const MenuGroupLabel = forwardRef<
25
25
  }
26
26
 
27
27
  return (
28
- <Styled.MenuGroupLabel
28
+ <Styled.GroupLabel
29
29
  ref={ ref }
30
30
  render={
31
31
  // @ts-expect-error The `children` prop is passed
@@ -7,15 +7,15 @@ import { forwardRef, useContext } from '@wordpress/element';
7
7
  * Internal dependencies
8
8
  */
9
9
  import type { WordPressComponentProps } from '../context';
10
- import { MenuContext } from './context';
11
- import type { MenuGroupProps } from './types';
10
+ import { Context } from './context';
11
+ import type { GroupProps } from './types';
12
12
  import * as Styled from './styles';
13
13
 
14
- export const MenuGroup = forwardRef<
14
+ export const Group = forwardRef<
15
15
  HTMLDivElement,
16
- WordPressComponentProps< MenuGroupProps, 'div', false >
17
- >( function MenuGroup( props, ref ) {
18
- const menuContext = useContext( MenuContext );
16
+ WordPressComponentProps< GroupProps, 'div', false >
17
+ >( function Group( props, ref ) {
18
+ const menuContext = useContext( Context );
19
19
 
20
20
  if ( ! menuContext?.store ) {
21
21
  throw new Error(
@@ -24,10 +24,6 @@ export const MenuGroup = forwardRef<
24
24
  }
25
25
 
26
26
  return (
27
- <Styled.MenuGroup
28
- ref={ ref }
29
- { ...props }
30
- store={ menuContext.store }
31
- />
27
+ <Styled.Group ref={ ref } { ...props } store={ menuContext.store } />
32
28
  );
33
29
  } );
@@ -13,21 +13,21 @@ import { isRTL as isRTLFn } from '@wordpress/i18n';
13
13
  * Internal dependencies
14
14
  */
15
15
  import { useContextSystem, contextConnectWithoutRef } from '../context';
16
- import type { MenuContext as MenuContextType, MenuProps } from './types';
17
- import { MenuContext } from './context';
18
- import { MenuItem } from './item';
19
- import { MenuCheckboxItem } from './checkbox-item';
20
- import { MenuRadioItem } from './radio-item';
21
- import { MenuGroup } from './group';
22
- import { MenuGroupLabel } from './group-label';
23
- import { MenuSeparator } from './separator';
24
- import { MenuItemLabel } from './item-label';
25
- import { MenuItemHelpText } from './item-help-text';
26
- import { MenuTriggerButton } from './trigger-button';
27
- import { MenuSubmenuTriggerItem } from './submenu-trigger-item';
28
- import { MenuPopover } from './popover';
16
+ import type { ContextProps, Props } from './types';
17
+ import { Context } from './context';
18
+ import { Item } from './item';
19
+ import { CheckboxItem } from './checkbox-item';
20
+ import { RadioItem } from './radio-item';
21
+ import { Group } from './group';
22
+ import { GroupLabel } from './group-label';
23
+ import { Separator } from './separator';
24
+ import { ItemLabel } from './item-label';
25
+ import { ItemHelpText } from './item-help-text';
26
+ import { TriggerButton } from './trigger-button';
27
+ import { SubmenuTriggerItem } from './submenu-trigger-item';
28
+ import { Popover } from './popover';
29
29
 
30
- const UnconnectedMenu = ( props: MenuProps ) => {
30
+ const UnconnectedMenu = ( props: Props ) => {
31
31
  const {
32
32
  children,
33
33
  defaultOpen = false,
@@ -39,10 +39,10 @@ const UnconnectedMenu = ( props: MenuProps ) => {
39
39
  variant,
40
40
  } = useContextSystem<
41
41
  // @ts-expect-error TODO: missing 'className' in MenuProps
42
- typeof props & Pick< MenuContextType, 'variant' >
42
+ typeof props & Pick< ContextProps, 'variant' >
43
43
  >( props, 'Menu' );
44
44
 
45
- const parentContext = useContext( MenuContext );
45
+ const parentContext = useContext( Context );
46
46
 
47
47
  const rtl = isRTLFn();
48
48
 
@@ -84,49 +84,119 @@ const UnconnectedMenu = ( props: MenuProps ) => {
84
84
  );
85
85
 
86
86
  return (
87
- <MenuContext.Provider value={ contextValue }>
88
- { children }
89
- </MenuContext.Provider>
87
+ <Context.Provider value={ contextValue }>{ children }</Context.Provider>
90
88
  );
91
89
  };
92
90
 
91
+ /**
92
+ * Menu is a collection of React components that combine to render
93
+ * ARIA-compliant [menu](https://www.w3.org/WAI/ARIA/apg/patterns/menu/) and
94
+ * [menu button](https://www.w3.org/WAI/ARIA/apg/patterns/menubutton/) patterns.
95
+ *
96
+ * `Menu` itself is a wrapper component and context provider.
97
+ * It is responsible for managing the state of the menu and its items, and for
98
+ * rendering the `Menu.TriggerButton` (or the `Menu.SubmenuTriggerItem`)
99
+ * component, and the `Menu.Popover` component.
100
+ */
93
101
  export const Menu = Object.assign(
94
102
  contextConnectWithoutRef( UnconnectedMenu, 'Menu' ),
95
103
  {
96
- Context: Object.assign( MenuContext, {
104
+ Context: Object.assign( Context, {
97
105
  displayName: 'Menu.Context',
98
106
  } ),
99
- Item: Object.assign( MenuItem, {
107
+ /**
108
+ * Renders a menu item inside the `Menu.Popover` or `Menu.Group` components.
109
+ *
110
+ * It can optionally contain one instance of the `Menu.ItemLabel` component
111
+ * and one instance of the `Menu.ItemHelpText` component.
112
+ */
113
+ Item: Object.assign( Item, {
100
114
  displayName: 'Menu.Item',
101
115
  } ),
102
- RadioItem: Object.assign( MenuRadioItem, {
116
+ /**
117
+ * Renders a radio menu item inside the `Menu.Popover` or `Menu.Group`
118
+ * components.
119
+ *
120
+ * It can optionally contain one instance of the `Menu.ItemLabel` component
121
+ * and one instance of the `Menu.ItemHelpText` component.
122
+ */
123
+ RadioItem: Object.assign( RadioItem, {
103
124
  displayName: 'Menu.RadioItem',
104
125
  } ),
105
- CheckboxItem: Object.assign( MenuCheckboxItem, {
126
+ /**
127
+ * Renders a checkbox menu item inside the `Menu.Popover` or `Menu.Group`
128
+ * components.
129
+ *
130
+ * It can optionally contain one instance of the `Menu.ItemLabel` component
131
+ * and one instance of the `Menu.ItemHelpText` component.
132
+ */
133
+ CheckboxItem: Object.assign( CheckboxItem, {
106
134
  displayName: 'Menu.CheckboxItem',
107
135
  } ),
108
- Group: Object.assign( MenuGroup, {
136
+ /**
137
+ * Renders a group for menu items.
138
+ *
139
+ * It should contain one instance of `Menu.GroupLabel` and one or more
140
+ * instances of `Menu.Item`, `Menu.RadioItem`, or `Menu.CheckboxItem`.
141
+ */
142
+ Group: Object.assign( Group, {
109
143
  displayName: 'Menu.Group',
110
144
  } ),
111
- GroupLabel: Object.assign( MenuGroupLabel, {
145
+ /**
146
+ * Renders a label in a menu group.
147
+ *
148
+ * This component should be wrapped with `Menu.Group` so the
149
+ * `aria-labelledby` is correctly set on the group element.
150
+ */
151
+ GroupLabel: Object.assign( GroupLabel, {
112
152
  displayName: 'Menu.GroupLabel',
113
153
  } ),
114
- Separator: Object.assign( MenuSeparator, {
154
+ /**
155
+ * Renders a divider between menu items or menu groups.
156
+ */
157
+ Separator: Object.assign( Separator, {
115
158
  displayName: 'Menu.Separator',
116
159
  } ),
117
- ItemLabel: Object.assign( MenuItemLabel, {
160
+ /**
161
+ * Renders a menu item's label text. It should be wrapped with `Menu.Item`,
162
+ * `Menu.RadioItem`, or `Menu.CheckboxItem`.
163
+ */
164
+ ItemLabel: Object.assign( ItemLabel, {
118
165
  displayName: 'Menu.ItemLabel',
119
166
  } ),
120
- ItemHelpText: Object.assign( MenuItemHelpText, {
167
+ /**
168
+ * Renders a menu item's help text. It should be wrapped with `Menu.Item`,
169
+ * `Menu.RadioItem`, or `Menu.CheckboxItem`.
170
+ */
171
+ ItemHelpText: Object.assign( ItemHelpText, {
121
172
  displayName: 'Menu.ItemHelpText',
122
173
  } ),
123
- Popover: Object.assign( MenuPopover, {
174
+ /**
175
+ * Renders a dropdown menu element that's controlled by a sibling
176
+ * `Menu.TriggerButton` component. It renders a popover and automatically
177
+ * focuses on items when the menu is shown.
178
+ *
179
+ * The only valid children of `Menu.Popover` are `Menu.Item`,
180
+ * `Menu.RadioItem`, `Menu.CheckboxItem`, `Menu.Group`, `Menu.Separator`,
181
+ * and `Menu` (for nested dropdown menus).
182
+ */
183
+ Popover: Object.assign( Popover, {
124
184
  displayName: 'Menu.Popover',
125
185
  } ),
126
- TriggerButton: Object.assign( MenuTriggerButton, {
186
+ /**
187
+ * Renders a menu button that toggles the visibility of a sibling
188
+ * `Menu.Popover` component when clicked or when using arrow keys.
189
+ */
190
+ TriggerButton: Object.assign( TriggerButton, {
127
191
  displayName: 'Menu.TriggerButton',
128
192
  } ),
129
- SubmenuTriggerItem: Object.assign( MenuSubmenuTriggerItem, {
193
+ /**
194
+ * Renders a menu item that toggles the visibility of a sibling
195
+ * `Menu.Popover` component when clicked or when using arrow keys.
196
+ *
197
+ * This component is used to create a nested dropdown menu.
198
+ */
199
+ SubmenuTriggerItem: Object.assign( SubmenuTriggerItem, {
130
200
  displayName: 'Menu.SubmenuTriggerItem',
131
201
  } ),
132
202
  }
@@ -7,14 +7,14 @@ import { forwardRef, useContext } from '@wordpress/element';
7
7
  * Internal dependencies
8
8
  */
9
9
  import type { WordPressComponentProps } from '../context';
10
- import { MenuContext } from './context';
10
+ import { Context } from './context';
11
11
  import * as Styled from './styles';
12
12
 
13
- export const MenuItemHelpText = forwardRef<
13
+ export const ItemHelpText = forwardRef<
14
14
  HTMLSpanElement,
15
15
  WordPressComponentProps< { children: React.ReactNode }, 'span', true >
16
- >( function MenuItemHelpText( props, ref ) {
17
- const menuContext = useContext( MenuContext );
16
+ >( function ItemHelpText( props, ref ) {
17
+ const menuContext = useContext( Context );
18
18
 
19
19
  if ( ! menuContext?.store ) {
20
20
  throw new Error(
@@ -22,7 +22,5 @@ export const MenuItemHelpText = forwardRef<
22
22
  );
23
23
  }
24
24
 
25
- return (
26
- <Styled.MenuItemHelpText numberOfLines={ 2 } ref={ ref } { ...props } />
27
- );
25
+ return <Styled.ItemHelpText numberOfLines={ 2 } ref={ ref } { ...props } />;
28
26
  } );
@@ -7,14 +7,14 @@ import { forwardRef, useContext } from '@wordpress/element';
7
7
  * Internal dependencies
8
8
  */
9
9
  import type { WordPressComponentProps } from '../context';
10
- import { MenuContext } from './context';
10
+ import { Context } from './context';
11
11
  import * as Styled from './styles';
12
12
 
13
- export const MenuItemLabel = forwardRef<
13
+ export const ItemLabel = forwardRef<
14
14
  HTMLSpanElement,
15
15
  WordPressComponentProps< { children: React.ReactNode }, 'span', true >
16
- >( function MenuItemLabel( props, ref ) {
17
- const menuContext = useContext( MenuContext );
16
+ >( function ItemLabel( props, ref ) {
17
+ const menuContext = useContext( Context );
18
18
 
19
19
  if ( ! menuContext?.store ) {
20
20
  throw new Error(
@@ -22,7 +22,5 @@ export const MenuItemLabel = forwardRef<
22
22
  );
23
23
  }
24
24
 
25
- return (
26
- <Styled.MenuItemLabel numberOfLines={ 1 } ref={ ref } { ...props } />
27
- );
25
+ return <Styled.ItemLabel numberOfLines={ 1 } ref={ ref } { ...props } />;
28
26
  } );
package/src/menu/item.tsx CHANGED
@@ -7,14 +7,14 @@ import { forwardRef, useContext } from '@wordpress/element';
7
7
  * Internal dependencies
8
8
  */
9
9
  import type { WordPressComponentProps } from '../context';
10
- import type { MenuItemProps } from './types';
10
+ import type { ItemProps } from './types';
11
11
  import * as Styled from './styles';
12
- import { MenuContext } from './context';
12
+ import { Context } from './context';
13
13
 
14
- export const MenuItem = forwardRef<
14
+ export const Item = forwardRef<
15
15
  HTMLDivElement,
16
- WordPressComponentProps< MenuItemProps, 'div', false >
17
- >( function MenuItem(
16
+ WordPressComponentProps< ItemProps, 'div', false >
17
+ >( function Item(
18
18
  {
19
19
  prefix,
20
20
  suffix,
@@ -26,7 +26,7 @@ export const MenuItem = forwardRef<
26
26
  },
27
27
  ref
28
28
  ) {
29
- const menuContext = useContext( MenuContext );
29
+ const menuContext = useContext( Context );
30
30
 
31
31
  if ( ! menuContext?.store ) {
32
32
  throw new Error(
@@ -41,7 +41,7 @@ export const MenuItem = forwardRef<
41
41
  const computedStore = store ?? menuContext.store;
42
42
 
43
43
  return (
44
- <Styled.MenuItem
44
+ <Styled.Item
45
45
  ref={ ref }
46
46
  { ...props }
47
47
  accessibleWhenDisabled
@@ -51,17 +51,17 @@ export const MenuItem = forwardRef<
51
51
  >
52
52
  <Styled.ItemPrefixWrapper>{ prefix }</Styled.ItemPrefixWrapper>
53
53
 
54
- <Styled.MenuItemContentWrapper>
55
- <Styled.MenuItemChildrenWrapper>
54
+ <Styled.ItemContentWrapper>
55
+ <Styled.ItemChildrenWrapper>
56
56
  { children }
57
- </Styled.MenuItemChildrenWrapper>
57
+ </Styled.ItemChildrenWrapper>
58
58
 
59
59
  { suffix && (
60
60
  <Styled.ItemSuffixWrapper>
61
61
  { suffix }
62
62
  </Styled.ItemSuffixWrapper>
63
63
  ) }
64
- </Styled.MenuItemContentWrapper>
65
- </Styled.MenuItem>
64
+ </Styled.ItemContentWrapper>
65
+ </Styled.Item>
66
66
  );
67
67
  } );
@@ -17,18 +17,18 @@ import {
17
17
  * Internal dependencies
18
18
  */
19
19
  import type { WordPressComponentProps } from '../context';
20
- import type { MenuPopoverProps } from './types';
20
+ import type { PopoverProps } from './types';
21
21
  import * as Styled from './styles';
22
- import { MenuContext } from './context';
22
+ import { Context } from './context';
23
23
 
24
- export const MenuPopover = forwardRef<
24
+ export const Popover = forwardRef<
25
25
  HTMLDivElement,
26
- WordPressComponentProps< MenuPopoverProps, 'div', false >
27
- >( function MenuPopover(
26
+ WordPressComponentProps< PopoverProps, 'div', false >
27
+ >( function Popover(
28
28
  { gutter, children, shift, modal = true, ...otherProps },
29
29
  ref
30
30
  ) {
31
- const menuContext = useContext( MenuContext );
31
+ const menuContext = useContext( Context );
32
32
 
33
33
  // Extract the side from the applied placement — useful for animations.
34
34
  // Using `currentPlacement` instead of `placement` to make sure that we
@@ -92,9 +92,9 @@ export const MenuPopover = forwardRef<
92
92
  // container scales with a different factor than its contents.
93
93
  // The {...renderProps} are passed to the inner wrapper, so that the
94
94
  // menu element is the direct parent of the menu item elements.
95
- <Styled.MenuPopoverOuterWrapper variant={ menuContext.variant }>
96
- <Styled.MenuPopoverInnerWrapper { ...renderProps } />
97
- </Styled.MenuPopoverOuterWrapper>
95
+ <Styled.PopoverOuterWrapper variant={ menuContext.variant }>
96
+ <Styled.PopoverInnerWrapper { ...renderProps } />
97
+ </Styled.PopoverOuterWrapper>
98
98
  ) }
99
99
  >
100
100
  { children }
@@ -13,8 +13,8 @@ import { Icon } from '@wordpress/icons';
13
13
  * Internal dependencies
14
14
  */
15
15
  import type { WordPressComponentProps } from '../context';
16
- import { MenuContext } from './context';
17
- import type { MenuRadioItemProps } from './types';
16
+ import { Context } from './context';
17
+ import type { RadioItemProps } from './types';
18
18
  import * as Styled from './styles';
19
19
  import { SVG, Circle } from '@wordpress/primitives';
20
20
 
@@ -24,14 +24,14 @@ const radioCheck = (
24
24
  </SVG>
25
25
  );
26
26
 
27
- export const MenuRadioItem = forwardRef<
27
+ export const RadioItem = forwardRef<
28
28
  HTMLDivElement,
29
- WordPressComponentProps< MenuRadioItemProps, 'div', false >
30
- >( function MenuRadioItem(
29
+ WordPressComponentProps< RadioItemProps, 'div', false >
30
+ >( function RadioItem(
31
31
  { suffix, children, disabled = false, hideOnClick = false, ...props },
32
32
  ref
33
33
  ) {
34
- const menuContext = useContext( MenuContext );
34
+ const menuContext = useContext( Context );
35
35
 
36
36
  if ( ! menuContext?.store ) {
37
37
  throw new Error(
@@ -40,7 +40,7 @@ export const MenuRadioItem = forwardRef<
40
40
  }
41
41
 
42
42
  return (
43
- <Styled.MenuRadioItem
43
+ <Styled.RadioItem
44
44
  ref={ ref }
45
45
  { ...props }
46
46
  accessibleWhenDisabled
@@ -57,17 +57,17 @@ export const MenuRadioItem = forwardRef<
57
57
  <Icon icon={ radioCheck } size={ 24 } />
58
58
  </Ariakit.MenuItemCheck>
59
59
 
60
- <Styled.MenuItemContentWrapper>
61
- <Styled.MenuItemChildrenWrapper>
60
+ <Styled.ItemContentWrapper>
61
+ <Styled.ItemChildrenWrapper>
62
62
  { children }
63
- </Styled.MenuItemChildrenWrapper>
63
+ </Styled.ItemChildrenWrapper>
64
64
 
65
65
  { suffix && (
66
66
  <Styled.ItemSuffixWrapper>
67
67
  { suffix }
68
68
  </Styled.ItemSuffixWrapper>
69
69
  ) }
70
- </Styled.MenuItemContentWrapper>
71
- </Styled.MenuRadioItem>
70
+ </Styled.ItemContentWrapper>
71
+ </Styled.RadioItem>
72
72
  );
73
73
  } );
@@ -7,15 +7,15 @@ import { forwardRef, useContext } from '@wordpress/element';
7
7
  * Internal dependencies
8
8
  */
9
9
  import type { WordPressComponentProps } from '../context';
10
- import { MenuContext } from './context';
11
- import type { MenuSeparatorProps } from './types';
10
+ import { Context } from './context';
11
+ import type { SeparatorProps } from './types';
12
12
  import * as Styled from './styles';
13
13
 
14
- export const MenuSeparator = forwardRef<
14
+ export const Separator = forwardRef<
15
15
  HTMLHRElement,
16
- WordPressComponentProps< MenuSeparatorProps, 'hr', false >
17
- >( function MenuSeparator( props, ref ) {
18
- const menuContext = useContext( MenuContext );
16
+ WordPressComponentProps< SeparatorProps, 'hr', false >
17
+ >( function Separator( props, ref ) {
18
+ const menuContext = useContext( Context );
19
19
 
20
20
  if ( ! menuContext?.store ) {
21
21
  throw new Error(
@@ -24,7 +24,7 @@ export const MenuSeparator = forwardRef<
24
24
  }
25
25
 
26
26
  return (
27
- <Styled.MenuSeparator
27
+ <Styled.Separator
28
28
  ref={ ref }
29
29
  { ...props }
30
30
  store={ menuContext.store }
@@ -0,0 +1,38 @@
1
+ import { Meta } from '@storybook/blocks';
2
+
3
+ import * as MenuStories from './index.story';
4
+
5
+ <Meta of={ MenuStories } name="Best Practices" />
6
+
7
+ # Menu
8
+
9
+ ## Usage
10
+
11
+ ### When to use a `Menu`
12
+
13
+ Use a `Menu` when you want users to:
14
+
15
+ - Choose an action or change a setting from a list, AND
16
+ - Only see the available choices contextually.
17
+
18
+ `Menu` is a React component to render an expandable menu of buttons. It is similar in purpose to a `<select>` element, with the distinction that it does not maintain a value. Instead, each option behaves as an action button.
19
+
20
+ If you need to display all the available options at all times, consider using a Toolbar instead. Use a `Menu` to display a list of actions after the user interacts with a button.
21
+
22
+ **Do**
23
+ Use a `Menu` to display a list of actions after the user interacts with an icon.
24
+
25
+ **Don’t** use a `Menu` for important actions that should always be visible. Use a `Toolbar` instead.
26
+
27
+ **Don’t**
28
+ Don’t use a `Menu` for frequently used actions. Use a `Toolbar` instead.
29
+
30
+ ### Behavior
31
+
32
+ Generally, the parent button should indicate that interacting with it will show a `Menu`.
33
+
34
+ The parent button should retain the same visual styling regardless of whether the `Menu` is displayed or not.
35
+
36
+ ### Placement
37
+
38
+ The `Menu` should typically appear directly below, or below and to the left of, the parent button. If there isn’t enough space below to display the full `Menu`, it can be displayed instead above the parent button.