@wordpress/components 29.1.1 → 29.2.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.
- package/CHANGELOG.md +19 -6
- package/CONTRIBUTING.md +4 -4
- package/README.md +1 -1
- package/build/badge/index.js +26 -22
- package/build/badge/index.js.map +1 -1
- package/build/circular-option-picker/circular-option-picker-option.js +9 -7
- package/build/circular-option-picker/circular-option-picker-option.js.map +1 -1
- package/build/circular-option-picker/circular-option-picker.js +0 -1
- package/build/circular-option-picker/circular-option-picker.js.map +1 -1
- package/build/color-palette/index.js +1 -6
- package/build/color-palette/index.js.map +1 -1
- package/build/font-size-picker/index.native.js +1 -1
- package/build/font-size-picker/index.native.js.map +1 -1
- package/build/higher-order/with-focus-return/index.js +1 -1
- package/build/higher-order/with-focus-return/index.js.map +1 -1
- package/build/input-control/styles/input-control-styles.js +22 -22
- package/build/input-control/styles/input-control-styles.js.map +1 -1
- package/build/menu/checkbox-item.js +6 -6
- package/build/menu/checkbox-item.js.map +1 -1
- package/build/menu/context.js +2 -2
- package/build/menu/context.js.map +1 -1
- package/build/menu/group-label.js +4 -4
- package/build/menu/group-label.js.map +1 -1
- package/build/menu/group.js +4 -4
- package/build/menu/group.js.map +1 -1
- package/build/menu/index.js +87 -14
- package/build/menu/index.js.map +1 -1
- package/build/menu/item-help-text.js +4 -4
- package/build/menu/item-help-text.js.map +1 -1
- package/build/menu/item-label.js +4 -4
- package/build/menu/item-label.js.map +1 -1
- package/build/menu/item.js +6 -6
- package/build/menu/item.js.map +1 -1
- package/build/menu/popover.js +5 -5
- package/build/menu/popover.js.map +1 -1
- package/build/menu/radio-item.js +6 -6
- package/build/menu/radio-item.js.map +1 -1
- package/build/menu/separator.js +4 -4
- package/build/menu/separator.js.map +1 -1
- package/build/menu/styles.js +41 -41
- package/build/menu/styles.js.map +1 -1
- package/build/menu/submenu-trigger-item.js +5 -5
- package/build/menu/submenu-trigger-item.js.map +1 -1
- package/build/menu/trigger-button.js +3 -3
- package/build/menu/trigger-button.js.map +1 -1
- package/build/menu/types.js.map +1 -1
- package/build/mobile/bottom-sheet/nav-bar/action-button.native.js +1 -1
- package/build/mobile/bottom-sheet/nav-bar/action-button.native.js.map +1 -1
- package/build/mobile/utils/get-px-from-css-unit.native.js +3 -3
- package/build/mobile/utils/get-px-from-css-unit.native.js.map +1 -1
- package/build/notice/types.js.map +1 -1
- package/build/search-control/index.js +1 -1
- package/build/search-control/index.js.map +1 -1
- package/build/text/hook.js +8 -6
- package/build/text/hook.js.map +1 -1
- package/build/text/utils.js +1 -1
- package/build/text/utils.js.map +1 -1
- package/build-module/badge/index.js +28 -22
- package/build-module/badge/index.js.map +1 -1
- package/build-module/circular-option-picker/circular-option-picker-option.js +9 -7
- package/build-module/circular-option-picker/circular-option-picker-option.js.map +1 -1
- package/build-module/circular-option-picker/circular-option-picker.js +0 -1
- package/build-module/circular-option-picker/circular-option-picker.js.map +1 -1
- package/build-module/color-palette/index.js +1 -6
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/font-size-picker/index.native.js +1 -1
- package/build-module/font-size-picker/index.native.js.map +1 -1
- package/build-module/higher-order/with-focus-return/index.js +1 -1
- package/build-module/higher-order/with-focus-return/index.js.map +1 -1
- package/build-module/input-control/styles/input-control-styles.js +22 -22
- package/build-module/input-control/styles/input-control-styles.js.map +1 -1
- package/build-module/menu/checkbox-item.js +6 -6
- package/build-module/menu/checkbox-item.js.map +1 -1
- package/build-module/menu/context.js +1 -1
- package/build-module/menu/context.js.map +1 -1
- package/build-module/menu/group-label.js +4 -4
- package/build-module/menu/group-label.js.map +1 -1
- package/build-module/menu/group.js +4 -4
- package/build-module/menu/group.js.map +1 -1
- package/build-module/menu/index.js +99 -26
- package/build-module/menu/index.js.map +1 -1
- package/build-module/menu/item-help-text.js +4 -4
- package/build-module/menu/item-help-text.js.map +1 -1
- package/build-module/menu/item-label.js +4 -4
- package/build-module/menu/item-label.js.map +1 -1
- package/build-module/menu/item.js +6 -6
- package/build-module/menu/item.js.map +1 -1
- package/build-module/menu/popover.js +5 -5
- package/build-module/menu/popover.js.map +1 -1
- package/build-module/menu/radio-item.js +6 -6
- package/build-module/menu/radio-item.js.map +1 -1
- package/build-module/menu/separator.js +4 -4
- package/build-module/menu/separator.js.map +1 -1
- package/build-module/menu/styles.js +40 -40
- package/build-module/menu/styles.js.map +1 -1
- package/build-module/menu/submenu-trigger-item.js +6 -6
- package/build-module/menu/submenu-trigger-item.js.map +1 -1
- package/build-module/menu/trigger-button.js +3 -3
- package/build-module/menu/trigger-button.js.map +1 -1
- package/build-module/menu/types.js.map +1 -1
- package/build-module/mobile/bottom-sheet/nav-bar/action-button.native.js +1 -1
- package/build-module/mobile/bottom-sheet/nav-bar/action-button.native.js.map +1 -1
- package/build-module/mobile/utils/get-px-from-css-unit.native.js +3 -3
- package/build-module/mobile/utils/get-px-from-css-unit.native.js.map +1 -1
- package/build-module/notice/types.js.map +1 -1
- package/build-module/search-control/index.js +1 -1
- package/build-module/search-control/index.js.map +1 -1
- package/build-module/text/hook.js +8 -6
- package/build-module/text/hook.js.map +1 -1
- package/build-module/text/utils.js +1 -1
- package/build-module/text/utils.js.map +1 -1
- package/build-style/style-rtl.css +89 -170
- package/build-style/style.css +89 -170
- package/build-types/badge/index.d.ts.map +1 -1
- package/build-types/circular-option-picker/circular-option-picker-option.d.ts.map +1 -1
- package/build-types/circular-option-picker/circular-option-picker.d.ts.map +1 -1
- package/build-types/circular-option-picker/stories/index.story.d.ts.map +1 -1
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/higher-order/with-focus-return/index.d.ts +1 -1
- package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
- package/build-types/menu/checkbox-item.d.ts +2 -2
- package/build-types/menu/checkbox-item.d.ts.map +1 -1
- package/build-types/menu/context.d.ts +2 -2
- package/build-types/menu/context.d.ts.map +1 -1
- package/build-types/menu/group-label.d.ts +2 -2
- package/build-types/menu/group-label.d.ts.map +1 -1
- package/build-types/menu/group.d.ts +2 -2
- package/build-types/menu/group.d.ts.map +1 -1
- package/build-types/menu/index.d.ts +84 -12
- package/build-types/menu/index.d.ts.map +1 -1
- package/build-types/menu/item-help-text.d.ts +1 -1
- package/build-types/menu/item-help-text.d.ts.map +1 -1
- package/build-types/menu/item-label.d.ts +1 -1
- package/build-types/menu/item-label.d.ts.map +1 -1
- package/build-types/menu/item.d.ts +2 -2
- package/build-types/menu/item.d.ts.map +1 -1
- package/build-types/menu/popover.d.ts +2 -2
- package/build-types/menu/popover.d.ts.map +1 -1
- package/build-types/menu/radio-item.d.ts +2 -2
- package/build-types/menu/radio-item.d.ts.map +1 -1
- package/build-types/menu/separator.d.ts +2 -2
- package/build-types/menu/separator.d.ts.map +1 -1
- package/build-types/menu/styles.d.ts +15 -15
- package/build-types/menu/styles.d.ts.map +1 -1
- package/build-types/menu/submenu-trigger-item.d.ts +2 -2
- package/build-types/menu/submenu-trigger-item.d.ts.map +1 -1
- package/build-types/menu/trigger-button.d.ts +2 -2
- package/build-types/menu/trigger-button.d.ts.map +1 -1
- package/build-types/menu/types.d.ts +10 -10
- package/build-types/menu/types.d.ts.map +1 -1
- package/build-types/menu-group/stories/index.story.d.ts +1 -1
- package/build-types/notice/types.d.ts +1 -1
- package/build-types/progress-bar/stories/index.story.d.ts +1 -1
- package/build-types/tabs/stories/index.story.d.ts +0 -3
- package/build-types/tabs/stories/index.story.d.ts.map +1 -1
- package/build-types/text/hook.d.ts.map +1 -1
- package/build-types/text/utils.d.ts +1 -1
- package/package.json +19 -19
- package/src/animate/style.scss +16 -12
- package/src/badge/index.tsx +28 -27
- package/src/border-control/test/index.js +12 -4
- package/src/button/style.scss +15 -12
- package/src/checkbox-control/style.scss +4 -2
- package/src/circular-option-picker/README.md +1 -2
- package/src/circular-option-picker/circular-option-picker-option.tsx +17 -10
- package/src/circular-option-picker/circular-option-picker.tsx +0 -1
- package/src/circular-option-picker/stories/index.story.tsx +0 -1
- package/src/circular-option-picker/style.scss +10 -5
- package/src/color-palette/index.tsx +0 -7
- package/src/color-palette/test/index.tsx +2 -8
- package/src/combobox-control/test/index.tsx +1 -1
- package/src/drop-zone/style.scss +6 -9
- package/src/font-size-picker/index.native.js +1 -1
- package/src/form-toggle/style.scss +17 -10
- package/src/form-token-field/style.scss +9 -4
- package/src/higher-order/navigate-regions/style.scss +2 -2
- package/src/higher-order/with-focus-return/index.tsx +1 -1
- package/src/input-control/styles/input-control-styles.tsx +6 -0
- package/src/menu/README.md +421 -174
- package/src/menu/checkbox-item.tsx +12 -12
- package/src/menu/context.tsx +2 -4
- package/src/menu/docs-manifest.json +62 -0
- package/src/menu/group-label.tsx +7 -7
- package/src/menu/group.tsx +7 -11
- package/src/menu/index.tsx +101 -31
- package/src/menu/item-help-text.tsx +5 -7
- package/src/menu/item-label.tsx +5 -7
- package/src/menu/item.tsx +12 -12
- package/src/menu/popover.tsx +9 -9
- package/src/menu/radio-item.tsx +12 -12
- package/src/menu/separator.tsx +7 -7
- package/src/menu/stories/best-practices.mdx +38 -0
- package/src/menu/stories/index.story.tsx +8 -8
- package/src/menu/styles.ts +24 -24
- package/src/menu/submenu-trigger-item.tsx +9 -9
- package/src/menu/trigger-button.tsx +6 -6
- package/src/menu/types.ts +10 -10
- package/src/menu-group/stories/index.story.tsx +2 -2
- package/src/mobile/bottom-sheet/nav-bar/action-button.native.js +1 -1
- package/src/mobile/utils/get-px-from-css-unit.native.js +3 -3
- package/src/modal/style.scss +4 -2
- package/src/modal/test/index.tsx +5 -4
- package/src/notice/README.md +3 -3
- package/src/notice/types.ts +1 -1
- package/src/palette-edit/test/index.tsx +1 -1
- package/src/panel/style.scss +14 -6
- package/src/placeholder/style.scss +5 -3
- package/src/progress-bar/stories/index.story.tsx +1 -1
- package/src/resizable-box/style.scss +14 -9
- package/src/search-control/index.tsx +1 -1
- package/src/tab-panel/style.scss +6 -4
- package/src/tabs/stories/index.story.tsx +0 -131
- package/src/text/README.md +1 -1
- package/src/text/hook.ts +3 -2
- package/src/text/stories/index.story.tsx +2 -2
- package/src/text/test/index.tsx +1 -1
- package/src/text/utils.ts +1 -1
- package/src/text-highlight/test/index.tsx +3 -3
- package/src/toolbar/toolbar/style.scss +4 -3
- 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 {
|
|
17
|
-
import type {
|
|
16
|
+
import { Context } from './context';
|
|
17
|
+
import type { CheckboxItemProps } from './types';
|
|
18
18
|
import * as Styled from './styles';
|
|
19
19
|
|
|
20
|
-
export const
|
|
20
|
+
export const CheckboxItem = forwardRef<
|
|
21
21
|
HTMLDivElement,
|
|
22
|
-
WordPressComponentProps<
|
|
23
|
-
>( function
|
|
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(
|
|
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.
|
|
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.
|
|
54
|
-
<Styled.
|
|
53
|
+
<Styled.ItemContentWrapper>
|
|
54
|
+
<Styled.ItemChildrenWrapper>
|
|
55
55
|
{ children }
|
|
56
|
-
</Styled.
|
|
56
|
+
</Styled.ItemChildrenWrapper>
|
|
57
57
|
|
|
58
58
|
{ suffix && (
|
|
59
59
|
<Styled.ItemSuffixWrapper>
|
|
60
60
|
{ suffix }
|
|
61
61
|
</Styled.ItemSuffixWrapper>
|
|
62
62
|
) }
|
|
63
|
-
</Styled.
|
|
64
|
-
</Styled.
|
|
63
|
+
</Styled.ItemContentWrapper>
|
|
64
|
+
</Styled.CheckboxItem>
|
|
65
65
|
);
|
|
66
66
|
} );
|
package/src/menu/context.tsx
CHANGED
|
@@ -6,8 +6,6 @@ import { createContext } from '@wordpress/element';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import type {
|
|
9
|
+
import type { ContextProps } from './types';
|
|
10
10
|
|
|
11
|
-
export const
|
|
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
|
+
}
|
package/src/menu/group-label.tsx
CHANGED
|
@@ -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 {
|
|
10
|
+
import { Context } from './context';
|
|
11
11
|
import { Text } from '../text';
|
|
12
|
-
import type {
|
|
12
|
+
import type { GroupLabelProps } from './types';
|
|
13
13
|
import * as Styled from './styles';
|
|
14
14
|
|
|
15
|
-
export const
|
|
15
|
+
export const GroupLabel = forwardRef<
|
|
16
16
|
HTMLDivElement,
|
|
17
|
-
WordPressComponentProps<
|
|
18
|
-
>( function
|
|
19
|
-
const menuContext = useContext(
|
|
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.
|
|
28
|
+
<Styled.GroupLabel
|
|
29
29
|
ref={ ref }
|
|
30
30
|
render={
|
|
31
31
|
// @ts-expect-error The `children` prop is passed
|
package/src/menu/group.tsx
CHANGED
|
@@ -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 {
|
|
11
|
-
import type {
|
|
10
|
+
import { Context } from './context';
|
|
11
|
+
import type { GroupProps } from './types';
|
|
12
12
|
import * as Styled from './styles';
|
|
13
13
|
|
|
14
|
-
export const
|
|
14
|
+
export const Group = forwardRef<
|
|
15
15
|
HTMLDivElement,
|
|
16
|
-
WordPressComponentProps<
|
|
17
|
-
>( function
|
|
18
|
-
const menuContext = useContext(
|
|
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.
|
|
28
|
-
ref={ ref }
|
|
29
|
-
{ ...props }
|
|
30
|
-
store={ menuContext.store }
|
|
31
|
-
/>
|
|
27
|
+
<Styled.Group ref={ ref } { ...props } store={ menuContext.store } />
|
|
32
28
|
);
|
|
33
29
|
} );
|
package/src/menu/index.tsx
CHANGED
|
@@ -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 {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
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:
|
|
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<
|
|
42
|
+
typeof props & Pick< ContextProps, 'variant' >
|
|
43
43
|
>( props, 'Menu' );
|
|
44
44
|
|
|
45
|
-
const parentContext = useContext(
|
|
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
|
-
<
|
|
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(
|
|
104
|
+
Context: Object.assign( Context, {
|
|
97
105
|
displayName: 'Menu.Context',
|
|
98
106
|
} ),
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
10
|
+
import { Context } from './context';
|
|
11
11
|
import * as Styled from './styles';
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const ItemHelpText = forwardRef<
|
|
14
14
|
HTMLSpanElement,
|
|
15
15
|
WordPressComponentProps< { children: React.ReactNode }, 'span', true >
|
|
16
|
-
>( function
|
|
17
|
-
const menuContext = useContext(
|
|
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
|
} );
|
package/src/menu/item-label.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 {
|
|
10
|
+
import { Context } from './context';
|
|
11
11
|
import * as Styled from './styles';
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const ItemLabel = forwardRef<
|
|
14
14
|
HTMLSpanElement,
|
|
15
15
|
WordPressComponentProps< { children: React.ReactNode }, 'span', true >
|
|
16
|
-
>( function
|
|
17
|
-
const menuContext = useContext(
|
|
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 {
|
|
10
|
+
import type { ItemProps } from './types';
|
|
11
11
|
import * as Styled from './styles';
|
|
12
|
-
import {
|
|
12
|
+
import { Context } from './context';
|
|
13
13
|
|
|
14
|
-
export const
|
|
14
|
+
export const Item = forwardRef<
|
|
15
15
|
HTMLDivElement,
|
|
16
|
-
WordPressComponentProps<
|
|
17
|
-
>( function
|
|
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(
|
|
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.
|
|
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.
|
|
55
|
-
<Styled.
|
|
54
|
+
<Styled.ItemContentWrapper>
|
|
55
|
+
<Styled.ItemChildrenWrapper>
|
|
56
56
|
{ children }
|
|
57
|
-
</Styled.
|
|
57
|
+
</Styled.ItemChildrenWrapper>
|
|
58
58
|
|
|
59
59
|
{ suffix && (
|
|
60
60
|
<Styled.ItemSuffixWrapper>
|
|
61
61
|
{ suffix }
|
|
62
62
|
</Styled.ItemSuffixWrapper>
|
|
63
63
|
) }
|
|
64
|
-
</Styled.
|
|
65
|
-
</Styled.
|
|
64
|
+
</Styled.ItemContentWrapper>
|
|
65
|
+
</Styled.Item>
|
|
66
66
|
);
|
|
67
67
|
} );
|
package/src/menu/popover.tsx
CHANGED
|
@@ -17,18 +17,18 @@ import {
|
|
|
17
17
|
* Internal dependencies
|
|
18
18
|
*/
|
|
19
19
|
import type { WordPressComponentProps } from '../context';
|
|
20
|
-
import type {
|
|
20
|
+
import type { PopoverProps } from './types';
|
|
21
21
|
import * as Styled from './styles';
|
|
22
|
-
import {
|
|
22
|
+
import { Context } from './context';
|
|
23
23
|
|
|
24
|
-
export const
|
|
24
|
+
export const Popover = forwardRef<
|
|
25
25
|
HTMLDivElement,
|
|
26
|
-
WordPressComponentProps<
|
|
27
|
-
>( function
|
|
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(
|
|
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.
|
|
96
|
-
<Styled.
|
|
97
|
-
</Styled.
|
|
95
|
+
<Styled.PopoverOuterWrapper variant={ menuContext.variant }>
|
|
96
|
+
<Styled.PopoverInnerWrapper { ...renderProps } />
|
|
97
|
+
</Styled.PopoverOuterWrapper>
|
|
98
98
|
) }
|
|
99
99
|
>
|
|
100
100
|
{ children }
|
package/src/menu/radio-item.tsx
CHANGED
|
@@ -13,8 +13,8 @@ import { Icon } from '@wordpress/icons';
|
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
15
|
import type { WordPressComponentProps } from '../context';
|
|
16
|
-
import {
|
|
17
|
-
import type {
|
|
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
|
|
27
|
+
export const RadioItem = forwardRef<
|
|
28
28
|
HTMLDivElement,
|
|
29
|
-
WordPressComponentProps<
|
|
30
|
-
>( function
|
|
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(
|
|
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.
|
|
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.
|
|
61
|
-
<Styled.
|
|
60
|
+
<Styled.ItemContentWrapper>
|
|
61
|
+
<Styled.ItemChildrenWrapper>
|
|
62
62
|
{ children }
|
|
63
|
-
</Styled.
|
|
63
|
+
</Styled.ItemChildrenWrapper>
|
|
64
64
|
|
|
65
65
|
{ suffix && (
|
|
66
66
|
<Styled.ItemSuffixWrapper>
|
|
67
67
|
{ suffix }
|
|
68
68
|
</Styled.ItemSuffixWrapper>
|
|
69
69
|
) }
|
|
70
|
-
</Styled.
|
|
71
|
-
</Styled.
|
|
70
|
+
</Styled.ItemContentWrapper>
|
|
71
|
+
</Styled.RadioItem>
|
|
72
72
|
);
|
|
73
73
|
} );
|
package/src/menu/separator.tsx
CHANGED
|
@@ -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 {
|
|
11
|
-
import type {
|
|
10
|
+
import { Context } from './context';
|
|
11
|
+
import type { SeparatorProps } from './types';
|
|
12
12
|
import * as Styled from './styles';
|
|
13
13
|
|
|
14
|
-
export const
|
|
14
|
+
export const Separator = forwardRef<
|
|
15
15
|
HTMLHRElement,
|
|
16
|
-
WordPressComponentProps<
|
|
17
|
-
>( function
|
|
18
|
-
const menuContext = useContext(
|
|
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.
|
|
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.
|