@ankhorage/surface 2.0.1 → 2.0.2
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 +6 -0
- package/dist/components/menu/Menu.d.ts +1 -1
- package/dist/components/menu/Menu.d.ts.map +1 -1
- package/dist/components/menu/Menu.js +50 -32
- package/dist/components/menu/Menu.js.map +1 -1
- package/dist/components/menu/index.d.ts +1 -1
- package/dist/components/menu/index.d.ts.map +1 -1
- package/dist/components/menu/index.js.map +1 -1
- package/dist/components/menu/navigation.d.ts +1 -1
- package/dist/components/menu/navigation.d.ts.map +1 -1
- package/dist/components/menu/navigation.js.map +1 -1
- package/dist/components/menu/types.d.ts +11 -5
- package/dist/components/menu/types.d.ts.map +1 -1
- package/dist/components/menu/types.js.map +1 -1
- package/dist/examples/DocsExamples.d.ts +3 -2
- package/dist/examples/DocsExamples.d.ts.map +1 -1
- package/dist/examples/DocsExamples.js +61 -37
- package/dist/examples/DocsExamples.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/menu/Menu.tsx +71 -36
- package/src/components/menu/index.ts +1 -1
- package/src/components/menu/navigation.ts +1 -1
- package/src/components/menu/types.ts +12 -5
- package/src/examples/DocsExamples.tsx +74 -60
- package/src/index.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { MenuProps } from './types';
|
|
3
|
-
export declare function Menu({ trigger,
|
|
3
|
+
export declare function Menu({ trigger, actions, dismiss, closeOnSelect, testID }: MenuProps): React.JSX.Element;
|
|
4
4
|
//# sourceMappingURL=Menu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../../src/components/menu/Menu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../../src/components/menu/Menu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,SAAS,CAAC;AA2CrD,wBAAgB,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAoB,EAAE,MAAM,EAAE,EAAE,SAAS,qBAwJ1F"}
|
|
@@ -4,7 +4,7 @@ import { FocusScope } from '../../internal/focus/FocusScope';
|
|
|
4
4
|
import { useFocusManager } from '../../internal/focus/useFocusManager';
|
|
5
5
|
import { Portal } from '../../internal/overlay/Portal';
|
|
6
6
|
import { resolveOverlayAnimation } from '../../internal/resolvers';
|
|
7
|
-
import { Box, Surface } from '../../layout';
|
|
7
|
+
import { Box, Inline, Stack, Surface } from '../../layout';
|
|
8
8
|
import { ButtonBase } from '../../primitives/button-base';
|
|
9
9
|
import { Text } from '../../primitives/text';
|
|
10
10
|
import { useTheme } from '../../theme/ThemeContext';
|
|
@@ -15,7 +15,24 @@ function measureNode(node, callback) {
|
|
|
15
15
|
callback({ height, width, x, y });
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
function renderActionContent(action, active) {
|
|
19
|
+
const titleColor = action.intent === 'danger' ? 'danger' : active || action.selected ? 'neutral' : undefined;
|
|
20
|
+
return (<Inline align="center" gap="s" justify="space-between" wrap="nowrap">
|
|
21
|
+
{action.leading ? <Box>{action.leading}</Box> : null}
|
|
22
|
+
<Box flex={1}>
|
|
23
|
+
<Stack gap="xxs">
|
|
24
|
+
<Text color={titleColor} variant="bodySmall" weight={action.selected ? 'semiBold' : 'medium'}>
|
|
25
|
+
{action.title}
|
|
26
|
+
</Text>
|
|
27
|
+
{action.description ? (<Text emphasis="muted" variant="caption">
|
|
28
|
+
{action.description}
|
|
29
|
+
</Text>) : null}
|
|
30
|
+
</Stack>
|
|
31
|
+
</Box>
|
|
32
|
+
{action.trailing ? <Box>{action.trailing}</Box> : null}
|
|
33
|
+
</Inline>);
|
|
34
|
+
}
|
|
35
|
+
export function Menu({ trigger, actions, dismiss, closeOnSelect = true, testID }) {
|
|
19
36
|
const { theme } = useTheme();
|
|
20
37
|
const { bindKeydown } = useFocusManager();
|
|
21
38
|
const animation = resolveOverlayAnimation('menu');
|
|
@@ -25,14 +42,27 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
25
42
|
const [activeIndex, setActiveIndex] = React.useState(0);
|
|
26
43
|
const closeMenu = React.useCallback(() => {
|
|
27
44
|
setOpen(false);
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
if (dismiss) {
|
|
46
|
+
dismiss();
|
|
47
|
+
}
|
|
48
|
+
}, [dismiss]);
|
|
49
|
+
const activateAction = React.useCallback((action) => {
|
|
50
|
+
if (action.disabled) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (action.activate) {
|
|
54
|
+
action.activate();
|
|
55
|
+
}
|
|
56
|
+
if (closeOnSelect) {
|
|
57
|
+
closeMenu();
|
|
58
|
+
}
|
|
59
|
+
}, [closeMenu, closeOnSelect]);
|
|
30
60
|
const openMenu = React.useCallback(() => {
|
|
31
61
|
measureNode(anchorRef.current, setLayout);
|
|
32
|
-
const firstEnabledIndex =
|
|
62
|
+
const firstEnabledIndex = actions.findIndex((action) => !action.disabled);
|
|
33
63
|
setActiveIndex(firstEnabledIndex === -1 ? 0 : firstEnabledIndex);
|
|
34
64
|
setOpen(true);
|
|
35
|
-
}, [
|
|
65
|
+
}, [actions]);
|
|
36
66
|
React.useEffect(() => {
|
|
37
67
|
if (!open) {
|
|
38
68
|
return undefined;
|
|
@@ -41,16 +71,13 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
41
71
|
const { key } = event;
|
|
42
72
|
if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End') {
|
|
43
73
|
event.preventDefault();
|
|
44
|
-
setActiveIndex((current) => resolveNextMenuIndex(
|
|
74
|
+
setActiveIndex((current) => resolveNextMenuIndex(actions, current, key));
|
|
45
75
|
}
|
|
46
76
|
if (event.key === 'Enter') {
|
|
47
77
|
event.preventDefault();
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
if (closeOnSelect) {
|
|
52
|
-
closeMenu();
|
|
53
|
-
}
|
|
78
|
+
const activeAction = actions[activeIndex];
|
|
79
|
+
if (activeAction) {
|
|
80
|
+
activateAction(activeAction);
|
|
54
81
|
}
|
|
55
82
|
}
|
|
56
83
|
if (event.key === 'Escape') {
|
|
@@ -58,7 +85,7 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
58
85
|
closeMenu();
|
|
59
86
|
}
|
|
60
87
|
});
|
|
61
|
-
}, [
|
|
88
|
+
}, [activateAction, actions, activeIndex, bindKeydown, closeMenu, open]);
|
|
62
89
|
return (<View collapsable={false} ref={anchorRef}>
|
|
63
90
|
<ButtonBase onPress={open ? closeMenu : openMenu} testID={testID ? `${testID}-trigger` : undefined}>
|
|
64
91
|
{trigger}
|
|
@@ -85,31 +112,22 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
85
112
|
top: (layout?.y ?? 0) + (layout?.height ?? 0) + animation.offset,
|
|
86
113
|
}}>
|
|
87
114
|
<Surface accessibilityRole="menu" p="xs" style={{
|
|
88
|
-
minWidth: Math.max(layout?.width ?? 0,
|
|
115
|
+
minWidth: Math.max(layout?.width ?? 0, 220),
|
|
89
116
|
shadowOpacity: 0.12,
|
|
90
117
|
shadowRadius: 12,
|
|
91
118
|
shadowOffset: { width: 0, height: 6 },
|
|
92
119
|
}} testID={testID} variant="raised">
|
|
93
|
-
{
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
item.onPress?.();
|
|
100
|
-
if (closeOnSelect) {
|
|
101
|
-
closeMenu();
|
|
102
|
-
}
|
|
103
|
-
}}>
|
|
104
|
-
<Box px="m" py="s" style={{
|
|
120
|
+
{actions.map((action, index) => {
|
|
121
|
+
const active = index === activeIndex;
|
|
122
|
+
const selected = action.selected ?? active;
|
|
123
|
+
return (<Pressable accessibilityRole="menuitem" accessibilityState={{ disabled: action.disabled, selected }} disabled={action.disabled} key={action.id} onPress={() => activateAction(action)}>
|
|
124
|
+
<Box px="m" py="s" radius="s" style={{
|
|
105
125
|
backgroundColor: selected
|
|
106
126
|
? theme.semantics.action.neutral.softBg
|
|
107
127
|
: 'transparent',
|
|
108
|
-
opacity:
|
|
109
|
-
}} testID={testID ? `${testID}-item-${
|
|
110
|
-
|
|
111
|
-
{item.label}
|
|
112
|
-
</Text>
|
|
128
|
+
opacity: action.disabled ? 0.56 : 1,
|
|
129
|
+
}} testID={testID ? `${testID}-item-${action.id}` : undefined}>
|
|
130
|
+
{renderActionContent(action, active)}
|
|
113
131
|
</Box>
|
|
114
132
|
</Pressable>);
|
|
115
133
|
})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../src/components/menu/Menu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAwB,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,IAAI,EA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EAAE,CAAC;oBACd,CAAC;gBACH,CAAC,CAAC,CAEF;sBAAA,CAAC,GAAG,CACF,EAAE,CAAC,GAAG,CACN,EAAE,CAAC,GAAG,CACN,KAAK,CAAC,CAAC;oBACL,eAAe,EAAE,QAAQ;wBACvB,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;wBACvC,CAAC,CAAC,aAAa;oBACjB,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBAClC,CAAC,CACF,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,SAAS,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAEzD;wBAAA,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,WAAW,CAChE;0BAAA,CAAC,IAAI,CAAC,KAAK,CACb;wBAAA,EAAE,IAAI,CACR;sBAAA,EAAE,GAAG,CACP;oBAAA,EAAE,SAAS,CAAC,CACb,CAAC;QACJ,CAAC,CAAC,CACJ;cAAA,EAAE,OAAO,CACX;YAAA,EAAE,IAAI,CACR;UAAA,EAAE,UAAU,CACd;QAAA,EAAE,IAAI,CACR;MAAA,EAAE,MAAM,CACV;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC","sourcesContent":["import React from 'react';\nimport { type LayoutRectangle, Pressable, View } from 'react-native';\n\nimport { FocusScope } from '../../internal/focus/FocusScope';\nimport { useFocusManager } from '../../internal/focus/useFocusManager';\nimport { Portal } from '../../internal/overlay/Portal';\nimport { resolveOverlayAnimation } from '../../internal/resolvers';\nimport { Box, Surface } from '../../layout';\nimport { ButtonBase } from '../../primitives/button-base';\nimport { Text } from '../../primitives/text';\nimport { useTheme } from '../../theme/ThemeContext';\nimport { resolveNextMenuIndex } from './navigation';\nimport type { MenuProps } from './types';\n\ninterface MeasurableNode {\n measureInWindow?: (\n callback: (x: number, y: number, width: number, height: number) => void,\n ) => void;\n}\n\nfunction measureNode(node: unknown, callback: (layout: LayoutRectangle) => void) {\n const measurableNode = node as MeasurableNode | null;\n measurableNode?.measureInWindow?.((x, y, width, height) => {\n callback({ height, width, x, y });\n });\n}\n\nexport function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }: MenuProps) {\n const { theme } = useTheme();\n const { bindKeydown } = useFocusManager();\n const animation = resolveOverlayAnimation('menu');\n const anchorRef = React.useRef<View | null>(null);\n const [open, setOpen] = React.useState(false);\n const [layout, setLayout] = React.useState<LayoutRectangle | null>(null);\n const [activeIndex, setActiveIndex] = React.useState(0);\n\n const closeMenu = React.useCallback(() => {\n setOpen(false);\n onDismiss?.();\n }, [onDismiss]);\n\n const openMenu = React.useCallback(() => {\n measureNode(anchorRef.current, setLayout);\n const firstEnabledIndex = items.findIndex((item) => !item.disabled);\n setActiveIndex(firstEnabledIndex === -1 ? 0 : firstEnabledIndex);\n setOpen(true);\n }, [items]);\n\n React.useEffect(() => {\n if (!open) {\n return undefined;\n }\n\n return bindKeydown((event) => {\n const { key } = event;\n if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End') {\n event.preventDefault();\n setActiveIndex((current) => resolveNextMenuIndex(items, current, key));\n }\n\n if (event.key === 'Enter') {\n event.preventDefault();\n const activeItem = items[activeIndex];\n if (activeItem && !activeItem.disabled) {\n activeItem.onPress?.();\n if (closeOnSelect) {\n closeMenu();\n }\n }\n }\n\n if (event.key === 'Escape') {\n event.preventDefault();\n closeMenu();\n }\n });\n }, [activeIndex, bindKeydown, closeMenu, closeOnSelect, items, open]);\n\n return (\n <View collapsable={false} ref={anchorRef}>\n <ButtonBase\n onPress={open ? closeMenu : openMenu}\n testID={testID ? `${testID}-trigger` : undefined}\n >\n {trigger}\n </ButtonBase>\n <Portal layer=\"menu\" visible={open && Boolean(layout)}>\n <View\n pointerEvents=\"box-none\"\n style={{\n bottom: 0,\n left: 0,\n position: 'absolute',\n right: 0,\n top: 0,\n }}\n >\n <Pressable\n onPress={closeMenu}\n style={{\n bottom: 0,\n left: 0,\n position: 'absolute',\n right: 0,\n top: 0,\n }}\n />\n <FocusScope active={open} onEscape={closeMenu}>\n <View\n style={{\n left: layout?.x ?? 0,\n position: 'absolute',\n top: (layout?.y ?? 0) + (layout?.height ?? 0) + animation.offset,\n }}\n >\n <Surface\n accessibilityRole=\"menu\"\n p=\"xs\"\n style={{\n minWidth: Math.max(layout?.width ?? 0, 180),\n shadowOpacity: 0.12,\n shadowRadius: 12,\n shadowOffset: { width: 0, height: 6 },\n }}\n testID={testID}\n variant=\"raised\"\n >\n {items.map((item, index) => {\n const selected = index === activeIndex;\n\n return (\n <Pressable\n accessibilityRole=\"menuitem\"\n accessibilityState={{ disabled: item.disabled, selected }}\n disabled={item.disabled}\n key={item.id}\n onPress={() => {\n if (item.disabled) {\n return;\n }\n\n item.onPress?.();\n if (closeOnSelect) {\n closeMenu();\n }\n }}\n >\n <Box\n px=\"m\"\n py=\"s\"\n style={{\n backgroundColor: selected\n ? theme.semantics.action.neutral.softBg\n : 'transparent',\n opacity: item.disabled ? 0.56 : 1,\n }}\n testID={testID ? `${testID}-item-${item.id}` : undefined}\n >\n <Text color={selected ? 'neutral' : undefined} variant=\"bodySmall\">\n {item.label}\n </Text>\n </Box>\n </Pressable>\n );\n })}\n </Surface>\n </View>\n </FocusScope>\n </View>\n </Portal>\n </View>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../src/components/menu/Menu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAwB,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,s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IAAI,CACR;UAAA,EAAE,UAAU,CACd;QAAA,EAAE,IAAI,CACR;MAAA,EAAE,MAAM,CACV;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC","sourcesContent":["import React from 'react';\nimport { type LayoutRectangle, Pressable, View } from 'react-native';\n\nimport { FocusScope } from '../../internal/focus/FocusScope';\nimport { useFocusManager } from '../../internal/focus/useFocusManager';\nimport { Portal } from '../../internal/overlay/Portal';\nimport { resolveOverlayAnimation } from '../../internal/resolvers';\nimport { Box, Inline, Stack, Surface } from '../../layout';\nimport { ButtonBase } from '../../primitives/button-base';\nimport { Text } from '../../primitives/text';\nimport { useTheme } from '../../theme/ThemeContext';\nimport { resolveNextMenuIndex } from './navigation';\nimport type { MenuAction, MenuProps } from './types';\n\ninterface MeasurableNode {\n measureInWindow?: (\n callback: (x: number, y: number, width: number, height: number) => void,\n ) => void;\n}\n\nfunction measureNode(node: unknown, callback: (layout: LayoutRectangle) => void) {\n const measurableNode = node as MeasurableNode | null;\n measurableNode?.measureInWindow?.((x, y, width, height) => {\n callback({ height, width, x, y });\n });\n}\n\nfunction renderActionContent(action: MenuAction, active: boolean) {\n const titleColor =\n action.intent === 'danger' ? 'danger' : active || action.selected ? 'neutral' : undefined;\n\n return (\n <Inline align=\"center\" gap=\"s\" justify=\"space-between\" wrap=\"nowrap\">\n {action.leading ? <Box>{action.leading}</Box> : null}\n <Box flex={1}>\n <Stack gap=\"xxs\">\n <Text\n color={titleColor}\n variant=\"bodySmall\"\n weight={action.selected ? 'semiBold' : 'medium'}\n >\n {action.title}\n </Text>\n {action.description ? (\n <Text emphasis=\"muted\" variant=\"caption\">\n {action.description}\n </Text>\n ) : null}\n </Stack>\n </Box>\n {action.trailing ? <Box>{action.trailing}</Box> : null}\n </Inline>\n );\n}\n\nexport function Menu({ trigger, actions, dismiss, closeOnSelect = true, testID }: MenuProps) {\n const { theme } = useTheme();\n const { bindKeydown } = useFocusManager();\n const animation = resolveOverlayAnimation('menu');\n const anchorRef = React.useRef<View | null>(null);\n const [open, setOpen] = React.useState(false);\n const [layout, setLayout] = React.useState<LayoutRectangle | null>(null);\n const [activeIndex, setActiveIndex] = React.useState(0);\n\n const closeMenu = React.useCallback(() => {\n setOpen(false);\n if (dismiss) {\n dismiss();\n }\n }, [dismiss]);\n\n const activateAction = React.useCallback(\n (action: MenuAction) => {\n if (action.disabled) {\n return;\n }\n\n if (action.activate) {\n action.activate();\n }\n\n if (closeOnSelect) {\n closeMenu();\n }\n },\n [closeMenu, closeOnSelect],\n );\n\n const openMenu = React.useCallback(() => {\n measureNode(anchorRef.current, setLayout);\n const firstEnabledIndex = actions.findIndex((action) => !action.disabled);\n setActiveIndex(firstEnabledIndex === -1 ? 0 : firstEnabledIndex);\n setOpen(true);\n }, [actions]);\n\n React.useEffect(() => {\n if (!open) {\n return undefined;\n }\n\n return bindKeydown((event) => {\n const { key } = event;\n if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End') {\n event.preventDefault();\n setActiveIndex((current) => resolveNextMenuIndex(actions, current, key));\n }\n\n if (event.key === 'Enter') {\n event.preventDefault();\n const activeAction = actions[activeIndex];\n if (activeAction) {\n activateAction(activeAction);\n }\n }\n\n if (event.key === 'Escape') {\n event.preventDefault();\n closeMenu();\n }\n });\n }, [activateAction, actions, activeIndex, bindKeydown, closeMenu, open]);\n\n return (\n <View collapsable={false} ref={anchorRef}>\n <ButtonBase\n onPress={open ? closeMenu : openMenu}\n testID={testID ? `${testID}-trigger` : undefined}\n >\n {trigger}\n </ButtonBase>\n <Portal layer=\"menu\" visible={open && Boolean(layout)}>\n <View\n pointerEvents=\"box-none\"\n style={{\n bottom: 0,\n left: 0,\n position: 'absolute',\n right: 0,\n top: 0,\n }}\n >\n <Pressable\n onPress={closeMenu}\n style={{\n bottom: 0,\n left: 0,\n position: 'absolute',\n right: 0,\n top: 0,\n }}\n />\n <FocusScope active={open} onEscape={closeMenu}>\n <View\n style={{\n left: layout?.x ?? 0,\n position: 'absolute',\n top: (layout?.y ?? 0) + (layout?.height ?? 0) + animation.offset,\n }}\n >\n <Surface\n accessibilityRole=\"menu\"\n p=\"xs\"\n style={{\n minWidth: Math.max(layout?.width ?? 0, 220),\n shadowOpacity: 0.12,\n shadowRadius: 12,\n shadowOffset: { width: 0, height: 6 },\n }}\n testID={testID}\n variant=\"raised\"\n >\n {actions.map((action, index) => {\n const active = index === activeIndex;\n const selected = action.selected ?? active;\n\n return (\n <Pressable\n accessibilityRole=\"menuitem\"\n accessibilityState={{ disabled: action.disabled, selected }}\n disabled={action.disabled}\n key={action.id}\n onPress={() => activateAction(action)}\n >\n <Box\n px=\"m\"\n py=\"s\"\n radius=\"s\"\n style={{\n backgroundColor: selected\n ? theme.semantics.action.neutral.softBg\n : 'transparent',\n opacity: action.disabled ? 0.56 : 1,\n }}\n testID={testID ? `${testID}-item-${action.id}` : undefined}\n >\n {renderActionContent(action, active)}\n </Box>\n </Pressable>\n );\n })}\n </Surface>\n </View>\n </FocusScope>\n </View>\n </Portal>\n </View>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/menu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/menu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,IAAI,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/menu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC","sourcesContent":["export { Menu } from './Menu';\nexport type { MenuItem, MenuProps } from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/menu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC","sourcesContent":["export { Menu } from './Menu';\nexport type { MenuAction, MenuActionIntent, MenuAction as MenuItem, MenuProps } from './types';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../src/components/menu/navigation.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../src/components/menu/navigation.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,EACxC,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,KAAK,GAC5C,MAAM,CA6BR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../../src/components/menu/navigation.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAClC,
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../../src/components/menu/navigation.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,oBAAoB,CAClC,KAAwC,EACxC,YAAoB,EACpB,GAA6C;IAE7C,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAW,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QACrE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IAED,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;QAClB,OAAO,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,kBAAkB,GAAG,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAChE,MAAM,gBAAgB,GACpB,kBAAkB,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,GAAG,KAAK,SAAS;YACjB,CAAC,CAAC,CAAC,kBAAkB,GAAG,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,MAAM;YAC1E,CAAC,CAAC,CAAC,kBAAkB,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC;IAEzD,OAAO,cAAc,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["export function resolveNextMenuIndex(\n items: readonly { disabled?: boolean }[],\n currentIndex: number,\n key: 'ArrowDown' | 'ArrowUp' | 'Home' | 'End',\n): number {\n const enabledIndexes = items.reduce<number[]>((indexes, item, index) => {\n if (!item.disabled) {\n indexes.push(index);\n }\n return indexes;\n }, []);\n\n if (enabledIndexes.length === 0) {\n return -1;\n }\n\n if (key === 'Home') {\n return enabledIndexes[0] ?? -1;\n }\n\n if (key === 'End') {\n return enabledIndexes[enabledIndexes.length - 1] ?? -1;\n }\n\n const activeEnabledIndex = enabledIndexes.indexOf(currentIndex);\n const nextEnabledIndex =\n activeEnabledIndex === -1\n ? 0\n : key === 'ArrowUp'\n ? (activeEnabledIndex - 1 + enabledIndexes.length) % enabledIndexes.length\n : (activeEnabledIndex + 1) % enabledIndexes.length;\n\n return enabledIndexes[nextEnabledIndex] ?? -1;\n}\n"]}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
export
|
|
2
|
+
export type MenuActionIntent = 'default' | 'danger';
|
|
3
|
+
export interface MenuAction {
|
|
3
4
|
id: string;
|
|
4
|
-
|
|
5
|
+
title: React.ReactNode;
|
|
6
|
+
description?: React.ReactNode;
|
|
7
|
+
leading?: React.ReactNode;
|
|
8
|
+
trailing?: React.ReactNode;
|
|
9
|
+
intent?: MenuActionIntent;
|
|
5
10
|
disabled?: boolean;
|
|
6
|
-
|
|
11
|
+
selected?: boolean;
|
|
12
|
+
activate?: () => void;
|
|
7
13
|
}
|
|
8
14
|
export interface MenuProps {
|
|
9
15
|
trigger?: React.ReactNode;
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
actions: readonly MenuAction[];
|
|
17
|
+
dismiss?: () => void;
|
|
12
18
|
closeOnSelect?: boolean;
|
|
13
19
|
testID?: string;
|
|
14
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/menu/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/menu/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEpD,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/menu/types.ts"],"names":[],"mappings":"","sourcesContent":["import type React from 'react';\n\nexport interface
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/menu/types.ts"],"names":[],"mappings":"","sourcesContent":["import type React from 'react';\n\nexport type MenuActionIntent = 'default' | 'danger';\n\nexport interface MenuAction {\n id: string;\n title: React.ReactNode;\n description?: React.ReactNode;\n leading?: React.ReactNode;\n trailing?: React.ReactNode;\n intent?: MenuActionIntent;\n disabled?: boolean;\n selected?: boolean;\n activate?: () => void;\n}\n\nexport interface MenuProps {\n trigger?: React.ReactNode;\n actions: readonly MenuAction[];\n dismiss?: () => void;\n closeOnSelect?: boolean;\n testID?: string;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
2
|
+
export declare function FormExample(): React.JSX.Element;
|
|
3
|
+
export declare function FeedbackExample(): React.JSX.Element;
|
|
4
|
+
export declare function OverlayExample(): React.JSX.Element;
|
|
4
5
|
export declare function NavigationExample(): React.JSX.Element;
|
|
5
6
|
//# sourceMappingURL=DocsExamples.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocsExamples.d.ts","sourceRoot":"","sources":["../../src/examples/DocsExamples.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DocsExamples.d.ts","sourceRoot":"","sources":["../../src/examples/DocsExamples.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA0B1B,wBAAgB,WAAW,sBAY1B;AAeD,wBAAgB,eAAe,sBAa9B;AAED,wBAAgB,cAAc,sBAyB7B;AAED,wBAAgB,iBAAiB,sBAgChC"}
|
|
@@ -1,48 +1,72 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Button } from '../components/button';
|
|
3
|
+
import { Card } from '../components/card';
|
|
4
|
+
import { Checkbox } from '../components/checkbox';
|
|
5
|
+
import { Drawer } from '../components/drawer';
|
|
6
|
+
import { Field } from '../components/field';
|
|
7
|
+
import { HelperText } from '../components/helper-text';
|
|
8
|
+
import { Menu } from '../components/menu';
|
|
9
|
+
import { Modal } from '../components/modal';
|
|
10
|
+
import { Tab, TabList, TabPanel, Tabs } from '../components/tabs';
|
|
11
|
+
import { TextInput } from '../components/text-input';
|
|
12
|
+
import { ToastProvider, useToast } from '../components/toast';
|
|
13
|
+
import { Tooltip } from '../components/tooltip';
|
|
14
|
+
import { Box, Stack } from '../layout';
|
|
15
|
+
import { Text } from '../primitives/text';
|
|
16
|
+
import { ThemeProvider } from '../theme';
|
|
3
17
|
const docsThemeConfig = {
|
|
4
|
-
id: 'docs
|
|
5
|
-
name: 'Docs
|
|
6
|
-
light: {
|
|
7
|
-
|
|
8
|
-
primaryColor: '#2563eb',
|
|
9
|
-
},
|
|
10
|
-
dark: {
|
|
11
|
-
harmony: 'monochromatic',
|
|
12
|
-
primaryColor: '#2563eb',
|
|
13
|
-
},
|
|
18
|
+
id: 'docs',
|
|
19
|
+
name: 'Docs',
|
|
20
|
+
light: { primaryColor: '#2563EB', harmony: 'analogous' },
|
|
21
|
+
dark: { primaryColor: '#60A5FA', harmony: 'analogous' },
|
|
14
22
|
};
|
|
15
|
-
export function
|
|
23
|
+
export function FormExample() {
|
|
16
24
|
return (<ThemeProvider initialConfig={docsThemeConfig}>
|
|
17
25
|
<Stack gap="m" p="l">
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
<Field helperText="Use your work email." label="Email" required>
|
|
27
|
+
<TextInput placeholder="you@example.com"/>
|
|
28
|
+
</Field>
|
|
29
|
+
<Checkbox checked>Accept terms</Checkbox>
|
|
30
|
+
<HelperText emphasis="muted">Looks good.</HelperText>
|
|
23
31
|
</Stack>
|
|
24
32
|
</ThemeProvider>);
|
|
25
33
|
}
|
|
26
|
-
|
|
34
|
+
function ToastButton() {
|
|
35
|
+
const { showToast } = useToast();
|
|
36
|
+
return (<Button onPress={() => showToast({ description: 'Your changes were saved.', status: 'success', title: 'Saved' })}>
|
|
37
|
+
Show toast
|
|
38
|
+
</Button>);
|
|
39
|
+
}
|
|
40
|
+
export function FeedbackExample() {
|
|
27
41
|
return (<ThemeProvider initialConfig={docsThemeConfig}>
|
|
28
|
-
<
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
</Field>
|
|
35
|
-
<Stack gap="s">
|
|
36
|
-
<Label required>Preferences</Label>
|
|
37
|
-
<Checkbox defaultChecked>Weekly updates</Checkbox>
|
|
38
|
-
<Radio>Product announcements</Radio>
|
|
39
|
-
<Switch readOnly>Read-only setting</Switch>
|
|
40
|
-
<HelperText color="error">Invalid fields should reuse the same error color.</HelperText>
|
|
42
|
+
<ToastProvider>
|
|
43
|
+
<Stack gap="m" p="l">
|
|
44
|
+
<Tooltip content="Helpful contextual information">
|
|
45
|
+
<Text>Hover for tooltip</Text>
|
|
46
|
+
</Tooltip>
|
|
47
|
+
<ToastButton />
|
|
41
48
|
</Stack>
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
</ToastProvider>
|
|
50
|
+
</ThemeProvider>);
|
|
51
|
+
}
|
|
52
|
+
export function OverlayExample() {
|
|
53
|
+
const [modalVisible, setModalVisible] = React.useState(false);
|
|
54
|
+
const [drawerVisible, setDrawerVisible] = React.useState(false);
|
|
55
|
+
return (<ThemeProvider initialConfig={docsThemeConfig}>
|
|
56
|
+
<Stack gap="m" p="l">
|
|
57
|
+
<Button onPress={() => setModalVisible(true)}>Open modal</Button>
|
|
58
|
+
<Button onPress={() => setDrawerVisible(true)}>Open drawer</Button>
|
|
59
|
+
<Modal onDismiss={() => setModalVisible(false)} visible={modalVisible}>
|
|
60
|
+
<Card>
|
|
61
|
+
<Stack gap="s">
|
|
62
|
+
<Text variant="label" weight="semiBold">
|
|
63
|
+
Modal title
|
|
64
|
+
</Text>
|
|
65
|
+
<Text>Modal content</Text>
|
|
66
|
+
</Stack>
|
|
67
|
+
</Card>
|
|
44
68
|
</Modal>
|
|
45
|
-
<Drawer
|
|
69
|
+
<Drawer onDismiss={() => setDrawerVisible(false)} visible={drawerVisible}>
|
|
46
70
|
<Text>Drawer content</Text>
|
|
47
71
|
</Drawer>
|
|
48
72
|
</Stack>
|
|
@@ -66,9 +90,9 @@ export function NavigationExample() {
|
|
|
66
90
|
<Text>Billing settings</Text>
|
|
67
91
|
</TabPanel>
|
|
68
92
|
</Tabs>
|
|
69
|
-
<Menu
|
|
70
|
-
{ id: 'edit',
|
|
71
|
-
{ disabled: true, id: 'archive',
|
|
93
|
+
<Menu actions={[
|
|
94
|
+
{ id: 'edit', title: 'Edit' },
|
|
95
|
+
{ disabled: true, id: 'archive', title: 'Archive' },
|
|
72
96
|
]} trigger={<Text>Open menu</Text>}/>
|
|
73
97
|
<Box>
|
|
74
98
|
<Text color="success">Theme overrides can stay semantic.</Text>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocsExamples.js","sourceRoot":"","sources":["../../src/examples/DocsExamples.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"DocsExamples.js","sourceRoot":"","sources":["../../src/examples/DocsExamples.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,eAAe,GAAgB;IACnC,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,EAAE,Y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,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,EAElC;QAAA,CAAC,GAAG,CACF;UAAA,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,kCAAkC,EAAE,IAAI,CAChE;QAAA,EAAE,GAAG,CACP;MAAA,EAAE,KAAK,CACT;IAAA,EAAE,aAAa,CAAC,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import React from 'react';\n\nimport { Button } from '../components/button';\nimport { Card } from '../components/card';\nimport { Checkbox } from '../components/checkbox';\nimport { Drawer } from '../components/drawer';\nimport { Field } from '../components/field';\nimport { HelperText } from '../components/helper-text';\nimport { Menu } from '../components/menu';\nimport { Modal } from '../components/modal';\nimport { Tab, TabList, TabPanel, Tabs } from '../components/tabs';\nimport { TextInput } from '../components/text-input';\nimport { ToastProvider, useToast } from '../components/toast';\nimport { Tooltip } from '../components/tooltip';\nimport { Box, Stack } from '../layout';\nimport { Text } from '../primitives/text';\nimport { ThemeProvider } from '../theme';\nimport type { ThemeConfig } from '../theme/types';\n\nconst docsThemeConfig: ThemeConfig = {\n id: 'docs',\n name: 'Docs',\n light: { primaryColor: '#2563EB', harmony: 'analogous' },\n dark: { primaryColor: '#60A5FA', harmony: 'analogous' },\n};\n\nexport function FormExample() {\n return (\n <ThemeProvider initialConfig={docsThemeConfig}>\n <Stack gap=\"m\" p=\"l\">\n <Field helperText=\"Use your work email.\" label=\"Email\" required>\n <TextInput placeholder=\"you@example.com\" />\n </Field>\n <Checkbox checked>Accept terms</Checkbox>\n <HelperText emphasis=\"muted\">Looks good.</HelperText>\n </Stack>\n </ThemeProvider>\n );\n}\n\nfunction ToastButton() {\n const { showToast } = useToast();\n return (\n <Button\n onPress={() =>\n showToast({ description: 'Your changes were saved.', status: 'success', title: 'Saved' })\n }\n >\n Show toast\n </Button>\n );\n}\n\nexport function FeedbackExample() {\n return (\n <ThemeProvider initialConfig={docsThemeConfig}>\n <ToastProvider>\n <Stack gap=\"m\" p=\"l\">\n <Tooltip content=\"Helpful contextual information\">\n <Text>Hover for tooltip</Text>\n </Tooltip>\n <ToastButton />\n </Stack>\n </ToastProvider>\n </ThemeProvider>\n );\n}\n\nexport function OverlayExample() {\n const [modalVisible, setModalVisible] = React.useState(false);\n const [drawerVisible, setDrawerVisible] = React.useState(false);\n\n return (\n <ThemeProvider initialConfig={docsThemeConfig}>\n <Stack gap=\"m\" p=\"l\">\n <Button onPress={() => setModalVisible(true)}>Open modal</Button>\n <Button onPress={() => setDrawerVisible(true)}>Open drawer</Button>\n <Modal onDismiss={() => setModalVisible(false)} visible={modalVisible}>\n <Card>\n <Stack gap=\"s\">\n <Text variant=\"label\" weight=\"semiBold\">\n Modal title\n </Text>\n <Text>Modal content</Text>\n </Stack>\n </Card>\n </Modal>\n <Drawer onDismiss={() => setDrawerVisible(false)} visible={drawerVisible}>\n <Text>Drawer content</Text>\n </Drawer>\n </Stack>\n </ThemeProvider>\n );\n}\n\nexport function NavigationExample() {\n return (\n <ThemeProvider initialConfig={docsThemeConfig}>\n <Stack gap=\"m\" p=\"l\">\n <Tabs defaultValue=\"account\">\n <TabList>\n <Tab value=\"account\">Account</Tab>\n <Tab disabled value=\"security\">\n Security\n </Tab>\n <Tab value=\"billing\">Billing</Tab>\n </TabList>\n <TabPanel value=\"account\">\n <Text>Account settings</Text>\n </TabPanel>\n <TabPanel value=\"billing\">\n <Text>Billing settings</Text>\n </TabPanel>\n </Tabs>\n <Menu\n actions={[\n { id: 'edit', title: 'Edit' },\n { disabled: true, id: 'archive', title: 'Archive' },\n ]}\n trigger={<Text>Open menu</Text>}\n />\n <Box>\n <Text color=\"success\">Theme overrides can stay semantic.</Text>\n </Box>\n </Stack>\n </ThemeProvider>\n );\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type { LabelProps } from './components/label';
|
|
|
20
20
|
export { Label } from './components/label';
|
|
21
21
|
export type { ListItemProps } from './components/list-item';
|
|
22
22
|
export { ListItem } from './components/list-item';
|
|
23
|
-
export type { MenuItem, MenuProps } from './components/menu';
|
|
23
|
+
export type { MenuAction, MenuActionIntent, MenuItem, MenuProps } from './components/menu';
|
|
24
24
|
export { Menu } from './components/menu';
|
|
25
25
|
export type { ModalProps } from './components/modal';
|
|
26
26
|
export { Modal } from './components/modal';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACzE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,U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UAAU,GACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1F,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAOzC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export type { ActionSheetItemProps, ActionSheetProps } from './components/action-sheet';\nexport { ActionSheet, ActionSheetItem } from './components/action-sheet';\nexport type { BadgeProps } from './components/badge';\nexport { Badge } from './components/badge';\nexport type { ButtonIconSpec, ButtonProps } from './components/button';\nexport { Button } from './components/button';\nexport type { CardProps } from './components/card';\nexport { Card } from './components/card';\nexport type { CheckboxProps } from './components/checkbox';\nexport { Checkbox } from './components/checkbox';\nexport type { DrawerProps } from './components/drawer';\nexport { Drawer } from './components/drawer';\nexport type { FieldProps } from './components/field';\nexport { Field } from './components/field';\nexport type { HelperTextProps } from './components/helper-text';\nexport { HelperText } from './components/helper-text';\nexport type { IconButtonProps } from './components/icon-button';\nexport { IconButton } from './components/icon-button';\nexport type { LabelProps } from './components/label';\nexport { Label } from './components/label';\nexport type { ListItemProps } from './components/list-item';\nexport { ListItem } from './components/list-item';\nexport type { MenuItem, MenuProps } from './components/menu';\nexport { Menu } from './components/menu';\nexport type { ModalProps } from './components/modal';\nexport { Modal } from './components/modal';\nexport type {\n DrawerNavigationItemProps,\n DrawerNavigationProps,\n NavigationItemIcon,\n NavigationItemProps,\n NavigationItemSpec,\n NavigationListProps,\n TabBarItemProps,\n TabBarProps,\n} from './components/navigation';\nexport {\n DrawerNavigation,\n DrawerNavigationItem,\n NavigationItem,\n NavigationList,\n TabBar,\n TabBarItem,\n} from './components/navigation';\nexport type { RadioProps } from './components/radio';\nexport { Radio } from './components/radio';\nexport type { SwitchProps } from './components/switch';\nexport { Switch } from './components/switch';\nexport type { TabListProps, TabPanelProps, TabProps, TabsProps } from './components/tabs';\nexport { Tab, TabList, TabPanel, Tabs } from './components/tabs';\nexport type { TextInputProps } from './components/text-input';\nexport { TextInput } from './components/text-input';\nexport type { TextareaProps } from './components/textarea';\nexport { Textarea } from './components/textarea';\nexport type { ToastOptions, ToastProps, ToastStatus } from './components/toast';\nexport { Toast, ToastProvider, useToast } from './components/toast';\nexport type { TooltipProps } from './components/tooltip';\nexport { Tooltip } from './components/tooltip';\nexport type { FontRuntime } from './context/FontContext';\nexport { FontProvider, useFontContext } from './context/FontContext';\nexport type { I18nInstance, TranslationRuntime, Translator } from './context/TranslationContext';\nexport { TranslationProvider, useTranslationContext } from './context/TranslationContext';\nexport * from './core/responsive';\nexport * from './layout';\nexport type { ButtonBaseProps } from './primitives/button-base';\nexport { ButtonBase } from './primitives/button-base';\nexport type { HeadingLevel, HeadingProps } from './primitives/heading';\nexport { Heading } from './primitives/heading';\nexport type { IconProps, IconProvider } from './primitives/icon';\nexport { Icon } from './primitives/icon';\nexport type { ImageFit, ImageProps, SurfaceImageSource } from './primitives/image';\nexport { Image } from './primitives/image';\nexport type { TextProps } from './primitives/text';\nexport { Text } from './primitives/text';\nexport type {\n SurfaceColor,\n SurfaceEmphasis,\n SurfacePaletteColor,\n SurfaceStatusColor,\n} from './surfaceColor';\nexport {\n SURFACE_COLORS,\n SURFACE_EMPHASES,\n SURFACE_PALETTE_COLORS,\n SURFACE_STATUS_COLORS,\n} from './surfaceColor';\nexport * from './theme';\nexport { isDeepEqual } from './utils/deepEqual';\nexport { deepMerge } from './utils/deepMerge';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAEzE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB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E,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export type { ActionSheetItemProps, ActionSheetProps } from './components/action-sheet';\nexport { ActionSheet, ActionSheetItem } from './components/action-sheet';\nexport type { BadgeProps } from './components/badge';\nexport { Badge } from './components/badge';\nexport type { ButtonIconSpec, ButtonProps } from './components/button';\nexport { Button } from './components/button';\nexport type { CardProps } from './components/card';\nexport { Card } from './components/card';\nexport type { CheckboxProps } from './components/checkbox';\nexport { Checkbox } from './components/checkbox';\nexport type { DrawerProps } from './components/drawer';\nexport { Drawer } from './components/drawer';\nexport type { FieldProps } from './components/field';\nexport { Field } from './components/field';\nexport type { HelperTextProps } from './components/helper-text';\nexport { HelperText } from './components/helper-text';\nexport type { IconButtonProps } from './components/icon-button';\nexport { IconButton } from './components/icon-button';\nexport type { LabelProps } from './components/label';\nexport { Label } from './components/label';\nexport type { ListItemProps } from './components/list-item';\nexport { ListItem } from './components/list-item';\nexport type { MenuAction, MenuActionIntent, MenuItem, MenuProps } from './components/menu';\nexport { Menu } from './components/menu';\nexport type { ModalProps } from './components/modal';\nexport { Modal } from './components/modal';\nexport type {\n DrawerNavigationItemProps,\n DrawerNavigationProps,\n NavigationItemIcon,\n NavigationItemProps,\n NavigationItemSpec,\n NavigationListProps,\n TabBarItemProps,\n TabBarProps,\n} from './components/navigation';\nexport {\n DrawerNavigation,\n DrawerNavigationItem,\n NavigationItem,\n NavigationList,\n TabBar,\n TabBarItem,\n} from './components/navigation';\nexport type { RadioProps } from './components/radio';\nexport { Radio } from './components/radio';\nexport type { SwitchProps } from './components/switch';\nexport { Switch } from './components/switch';\nexport type { TabListProps, TabPanelProps, TabProps, TabsProps } from './components/tabs';\nexport { Tab, TabList, TabPanel, Tabs } from './components/tabs';\nexport type { TextInputProps } from './components/text-input';\nexport { TextInput } from './components/text-input';\nexport type { TextareaProps } from './components/textarea';\nexport { Textarea } from './components/textarea';\nexport type { ToastOptions, ToastProps, ToastStatus } from './components/toast';\nexport { Toast, ToastProvider, useToast } from './components/toast';\nexport type { TooltipProps } from './components/tooltip';\nexport { Tooltip } from './components/tooltip';\nexport type { FontRuntime } from './context/FontContext';\nexport { FontProvider, useFontContext } from './context/FontContext';\nexport type { I18nInstance, TranslationRuntime, Translator } from './context/TranslationContext';\nexport { TranslationProvider, useTranslationContext } from './context/TranslationContext';\nexport * from './core/responsive';\nexport * from './layout';\nexport type { ButtonBaseProps } from './primitives/button-base';\nexport { ButtonBase } from './primitives/button-base';\nexport type { HeadingLevel, HeadingProps } from './primitives/heading';\nexport { Heading } from './primitives/heading';\nexport type { IconProps, IconProvider } from './primitives/icon';\nexport { Icon } from './primitives/icon';\nexport type { ImageFit, ImageProps, SurfaceImageSource } from './primitives/image';\nexport { Image } from './primitives/image';\nexport type { TextProps } from './primitives/text';\nexport { Text } from './primitives/text';\nexport type {\n SurfaceColor,\n SurfaceEmphasis,\n SurfacePaletteColor,\n SurfaceStatusColor,\n} from './surfaceColor';\nexport {\n SURFACE_COLORS,\n SURFACE_EMPHASES,\n SURFACE_PALETTE_COLORS,\n SURFACE_STATUS_COLORS,\n} from './surfaceColor';\nexport * from './theme';\nexport { isDeepEqual } from './utils/deepEqual';\nexport { deepMerge } from './utils/deepMerge';\n"]}
|
package/package.json
CHANGED
|
@@ -5,12 +5,12 @@ import { FocusScope } from '../../internal/focus/FocusScope';
|
|
|
5
5
|
import { useFocusManager } from '../../internal/focus/useFocusManager';
|
|
6
6
|
import { Portal } from '../../internal/overlay/Portal';
|
|
7
7
|
import { resolveOverlayAnimation } from '../../internal/resolvers';
|
|
8
|
-
import { Box, Surface } from '../../layout';
|
|
8
|
+
import { Box, Inline, Stack, Surface } from '../../layout';
|
|
9
9
|
import { ButtonBase } from '../../primitives/button-base';
|
|
10
10
|
import { Text } from '../../primitives/text';
|
|
11
11
|
import { useTheme } from '../../theme/ThemeContext';
|
|
12
12
|
import { resolveNextMenuIndex } from './navigation';
|
|
13
|
-
import type { MenuProps } from './types';
|
|
13
|
+
import type { MenuAction, MenuProps } from './types';
|
|
14
14
|
|
|
15
15
|
interface MeasurableNode {
|
|
16
16
|
measureInWindow?: (
|
|
@@ -25,7 +25,35 @@ function measureNode(node: unknown, callback: (layout: LayoutRectangle) => void)
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
function renderActionContent(action: MenuAction, active: boolean) {
|
|
29
|
+
const titleColor =
|
|
30
|
+
action.intent === 'danger' ? 'danger' : active || action.selected ? 'neutral' : undefined;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Inline align="center" gap="s" justify="space-between" wrap="nowrap">
|
|
34
|
+
{action.leading ? <Box>{action.leading}</Box> : null}
|
|
35
|
+
<Box flex={1}>
|
|
36
|
+
<Stack gap="xxs">
|
|
37
|
+
<Text
|
|
38
|
+
color={titleColor}
|
|
39
|
+
variant="bodySmall"
|
|
40
|
+
weight={action.selected ? 'semiBold' : 'medium'}
|
|
41
|
+
>
|
|
42
|
+
{action.title}
|
|
43
|
+
</Text>
|
|
44
|
+
{action.description ? (
|
|
45
|
+
<Text emphasis="muted" variant="caption">
|
|
46
|
+
{action.description}
|
|
47
|
+
</Text>
|
|
48
|
+
) : null}
|
|
49
|
+
</Stack>
|
|
50
|
+
</Box>
|
|
51
|
+
{action.trailing ? <Box>{action.trailing}</Box> : null}
|
|
52
|
+
</Inline>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function Menu({ trigger, actions, dismiss, closeOnSelect = true, testID }: MenuProps) {
|
|
29
57
|
const { theme } = useTheme();
|
|
30
58
|
const { bindKeydown } = useFocusManager();
|
|
31
59
|
const animation = resolveOverlayAnimation('menu');
|
|
@@ -36,15 +64,34 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
36
64
|
|
|
37
65
|
const closeMenu = React.useCallback(() => {
|
|
38
66
|
setOpen(false);
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
if (dismiss) {
|
|
68
|
+
dismiss();
|
|
69
|
+
}
|
|
70
|
+
}, [dismiss]);
|
|
71
|
+
|
|
72
|
+
const activateAction = React.useCallback(
|
|
73
|
+
(action: MenuAction) => {
|
|
74
|
+
if (action.disabled) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (action.activate) {
|
|
79
|
+
action.activate();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (closeOnSelect) {
|
|
83
|
+
closeMenu();
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
[closeMenu, closeOnSelect],
|
|
87
|
+
);
|
|
41
88
|
|
|
42
89
|
const openMenu = React.useCallback(() => {
|
|
43
90
|
measureNode(anchorRef.current, setLayout);
|
|
44
|
-
const firstEnabledIndex =
|
|
91
|
+
const firstEnabledIndex = actions.findIndex((action) => !action.disabled);
|
|
45
92
|
setActiveIndex(firstEnabledIndex === -1 ? 0 : firstEnabledIndex);
|
|
46
93
|
setOpen(true);
|
|
47
|
-
}, [
|
|
94
|
+
}, [actions]);
|
|
48
95
|
|
|
49
96
|
React.useEffect(() => {
|
|
50
97
|
if (!open) {
|
|
@@ -55,17 +102,14 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
55
102
|
const { key } = event;
|
|
56
103
|
if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End') {
|
|
57
104
|
event.preventDefault();
|
|
58
|
-
setActiveIndex((current) => resolveNextMenuIndex(
|
|
105
|
+
setActiveIndex((current) => resolveNextMenuIndex(actions, current, key));
|
|
59
106
|
}
|
|
60
107
|
|
|
61
108
|
if (event.key === 'Enter') {
|
|
62
109
|
event.preventDefault();
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
if (closeOnSelect) {
|
|
67
|
-
closeMenu();
|
|
68
|
-
}
|
|
110
|
+
const activeAction = actions[activeIndex];
|
|
111
|
+
if (activeAction) {
|
|
112
|
+
activateAction(activeAction);
|
|
69
113
|
}
|
|
70
114
|
}
|
|
71
115
|
|
|
@@ -74,7 +118,7 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
74
118
|
closeMenu();
|
|
75
119
|
}
|
|
76
120
|
});
|
|
77
|
-
}, [
|
|
121
|
+
}, [activateAction, actions, activeIndex, bindKeydown, closeMenu, open]);
|
|
78
122
|
|
|
79
123
|
return (
|
|
80
124
|
<View collapsable={false} ref={anchorRef}>
|
|
@@ -117,7 +161,7 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
117
161
|
accessibilityRole="menu"
|
|
118
162
|
p="xs"
|
|
119
163
|
style={{
|
|
120
|
-
minWidth: Math.max(layout?.width ?? 0,
|
|
164
|
+
minWidth: Math.max(layout?.width ?? 0, 220),
|
|
121
165
|
shadowOpacity: 0.12,
|
|
122
166
|
shadowRadius: 12,
|
|
123
167
|
shadowOffset: { width: 0, height: 6 },
|
|
@@ -125,40 +169,31 @@ export function Menu({ trigger, items, onDismiss, closeOnSelect = true, testID }
|
|
|
125
169
|
testID={testID}
|
|
126
170
|
variant="raised"
|
|
127
171
|
>
|
|
128
|
-
{
|
|
129
|
-
const
|
|
172
|
+
{actions.map((action, index) => {
|
|
173
|
+
const active = index === activeIndex;
|
|
174
|
+
const selected = action.selected ?? active;
|
|
130
175
|
|
|
131
176
|
return (
|
|
132
177
|
<Pressable
|
|
133
178
|
accessibilityRole="menuitem"
|
|
134
|
-
accessibilityState={{ disabled:
|
|
135
|
-
disabled={
|
|
136
|
-
key={
|
|
137
|
-
onPress={() =>
|
|
138
|
-
if (item.disabled) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
item.onPress?.();
|
|
143
|
-
if (closeOnSelect) {
|
|
144
|
-
closeMenu();
|
|
145
|
-
}
|
|
146
|
-
}}
|
|
179
|
+
accessibilityState={{ disabled: action.disabled, selected }}
|
|
180
|
+
disabled={action.disabled}
|
|
181
|
+
key={action.id}
|
|
182
|
+
onPress={() => activateAction(action)}
|
|
147
183
|
>
|
|
148
184
|
<Box
|
|
149
185
|
px="m"
|
|
150
186
|
py="s"
|
|
187
|
+
radius="s"
|
|
151
188
|
style={{
|
|
152
189
|
backgroundColor: selected
|
|
153
190
|
? theme.semantics.action.neutral.softBg
|
|
154
191
|
: 'transparent',
|
|
155
|
-
opacity:
|
|
192
|
+
opacity: action.disabled ? 0.56 : 1,
|
|
156
193
|
}}
|
|
157
|
-
testID={testID ? `${testID}-item-${
|
|
194
|
+
testID={testID ? `${testID}-item-${action.id}` : undefined}
|
|
158
195
|
>
|
|
159
|
-
|
|
160
|
-
{item.label}
|
|
161
|
-
</Text>
|
|
196
|
+
{renderActionContent(action, active)}
|
|
162
197
|
</Box>
|
|
163
198
|
</Pressable>
|
|
164
199
|
);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Menu } from './Menu';
|
|
2
|
-
export type { MenuItem, MenuProps } from './types';
|
|
2
|
+
export type { MenuAction, MenuActionIntent, MenuAction as MenuItem, MenuProps } from './types';
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type MenuActionIntent = 'default' | 'danger';
|
|
4
|
+
|
|
5
|
+
export interface MenuAction {
|
|
4
6
|
id: string;
|
|
5
|
-
|
|
7
|
+
title: React.ReactNode;
|
|
8
|
+
description?: React.ReactNode;
|
|
9
|
+
leading?: React.ReactNode;
|
|
10
|
+
trailing?: React.ReactNode;
|
|
11
|
+
intent?: MenuActionIntent;
|
|
6
12
|
disabled?: boolean;
|
|
7
|
-
|
|
13
|
+
selected?: boolean;
|
|
14
|
+
activate?: () => void;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
export interface MenuProps {
|
|
11
18
|
trigger?: React.ReactNode;
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
actions: readonly MenuAction[];
|
|
20
|
+
dismiss?: () => void;
|
|
14
21
|
closeOnSelect?: boolean;
|
|
15
22
|
testID?: string;
|
|
16
23
|
}
|
|
@@ -1,77 +1,91 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
TabPanel,
|
|
20
|
-
Tabs,
|
|
21
|
-
Text,
|
|
22
|
-
Textarea,
|
|
23
|
-
TextInput,
|
|
24
|
-
ThemeProvider,
|
|
25
|
-
} from '../index';
|
|
3
|
+
import { Button } from '../components/button';
|
|
4
|
+
import { Card } from '../components/card';
|
|
5
|
+
import { Checkbox } from '../components/checkbox';
|
|
6
|
+
import { Drawer } from '../components/drawer';
|
|
7
|
+
import { Field } from '../components/field';
|
|
8
|
+
import { HelperText } from '../components/helper-text';
|
|
9
|
+
import { Menu } from '../components/menu';
|
|
10
|
+
import { Modal } from '../components/modal';
|
|
11
|
+
import { Tab, TabList, TabPanel, Tabs } from '../components/tabs';
|
|
12
|
+
import { TextInput } from '../components/text-input';
|
|
13
|
+
import { ToastProvider, useToast } from '../components/toast';
|
|
14
|
+
import { Tooltip } from '../components/tooltip';
|
|
15
|
+
import { Box, Stack } from '../layout';
|
|
16
|
+
import { Text } from '../primitives/text';
|
|
17
|
+
import { ThemeProvider } from '../theme';
|
|
18
|
+
import type { ThemeConfig } from '../theme/types';
|
|
26
19
|
|
|
27
|
-
const docsThemeConfig = {
|
|
28
|
-
id: 'docs
|
|
29
|
-
name: 'Docs
|
|
30
|
-
light: {
|
|
31
|
-
|
|
32
|
-
primaryColor: '#2563eb',
|
|
33
|
-
},
|
|
34
|
-
dark: {
|
|
35
|
-
harmony: 'monochromatic' as const,
|
|
36
|
-
primaryColor: '#2563eb',
|
|
37
|
-
},
|
|
20
|
+
const docsThemeConfig: ThemeConfig = {
|
|
21
|
+
id: 'docs',
|
|
22
|
+
name: 'Docs',
|
|
23
|
+
light: { primaryColor: '#2563EB', harmony: 'analogous' },
|
|
24
|
+
dark: { primaryColor: '#60A5FA', harmony: 'analogous' },
|
|
38
25
|
};
|
|
39
26
|
|
|
40
|
-
export function
|
|
27
|
+
export function FormExample() {
|
|
41
28
|
return (
|
|
42
29
|
<ThemeProvider initialConfig={docsThemeConfig}>
|
|
43
30
|
<Stack gap="m" p="l">
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
<Field helperText="Use your work email." label="Email" required>
|
|
32
|
+
<TextInput placeholder="you@example.com" />
|
|
33
|
+
</Field>
|
|
34
|
+
<Checkbox checked>Accept terms</Checkbox>
|
|
35
|
+
<HelperText emphasis="muted">Looks good.</HelperText>
|
|
49
36
|
</Stack>
|
|
50
37
|
</ThemeProvider>
|
|
51
38
|
);
|
|
52
39
|
}
|
|
53
40
|
|
|
54
|
-
|
|
41
|
+
function ToastButton() {
|
|
42
|
+
const { showToast } = useToast();
|
|
43
|
+
return (
|
|
44
|
+
<Button
|
|
45
|
+
onPress={() =>
|
|
46
|
+
showToast({ description: 'Your changes were saved.', status: 'success', title: 'Saved' })
|
|
47
|
+
}
|
|
48
|
+
>
|
|
49
|
+
Show toast
|
|
50
|
+
</Button>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function FeedbackExample() {
|
|
55
55
|
return (
|
|
56
56
|
<ThemeProvider initialConfig={docsThemeConfig}>
|
|
57
|
-
<
|
|
58
|
-
<
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
<
|
|
63
|
-
</Field>
|
|
64
|
-
<Stack gap="s">
|
|
65
|
-
<Label required>Preferences</Label>
|
|
66
|
-
<Checkbox defaultChecked>Weekly updates</Checkbox>
|
|
67
|
-
<Radio>Product announcements</Radio>
|
|
68
|
-
<Switch readOnly>Read-only setting</Switch>
|
|
69
|
-
<HelperText color="error">Invalid fields should reuse the same error color.</HelperText>
|
|
57
|
+
<ToastProvider>
|
|
58
|
+
<Stack gap="m" p="l">
|
|
59
|
+
<Tooltip content="Helpful contextual information">
|
|
60
|
+
<Text>Hover for tooltip</Text>
|
|
61
|
+
</Tooltip>
|
|
62
|
+
<ToastButton />
|
|
70
63
|
</Stack>
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
</ToastProvider>
|
|
65
|
+
</ThemeProvider>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function OverlayExample() {
|
|
70
|
+
const [modalVisible, setModalVisible] = React.useState(false);
|
|
71
|
+
const [drawerVisible, setDrawerVisible] = React.useState(false);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<ThemeProvider initialConfig={docsThemeConfig}>
|
|
75
|
+
<Stack gap="m" p="l">
|
|
76
|
+
<Button onPress={() => setModalVisible(true)}>Open modal</Button>
|
|
77
|
+
<Button onPress={() => setDrawerVisible(true)}>Open drawer</Button>
|
|
78
|
+
<Modal onDismiss={() => setModalVisible(false)} visible={modalVisible}>
|
|
79
|
+
<Card>
|
|
80
|
+
<Stack gap="s">
|
|
81
|
+
<Text variant="label" weight="semiBold">
|
|
82
|
+
Modal title
|
|
83
|
+
</Text>
|
|
84
|
+
<Text>Modal content</Text>
|
|
85
|
+
</Stack>
|
|
86
|
+
</Card>
|
|
73
87
|
</Modal>
|
|
74
|
-
<Drawer
|
|
88
|
+
<Drawer onDismiss={() => setDrawerVisible(false)} visible={drawerVisible}>
|
|
75
89
|
<Text>Drawer content</Text>
|
|
76
90
|
</Drawer>
|
|
77
91
|
</Stack>
|
|
@@ -99,9 +113,9 @@ export function NavigationExample() {
|
|
|
99
113
|
</TabPanel>
|
|
100
114
|
</Tabs>
|
|
101
115
|
<Menu
|
|
102
|
-
|
|
103
|
-
{ id: 'edit',
|
|
104
|
-
{ disabled: true, id: 'archive',
|
|
116
|
+
actions={[
|
|
117
|
+
{ id: 'edit', title: 'Edit' },
|
|
118
|
+
{ disabled: true, id: 'archive', title: 'Archive' },
|
|
105
119
|
]}
|
|
106
120
|
trigger={<Text>Open menu</Text>}
|
|
107
121
|
/>
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type { LabelProps } from './components/label';
|
|
|
20
20
|
export { Label } from './components/label';
|
|
21
21
|
export type { ListItemProps } from './components/list-item';
|
|
22
22
|
export { ListItem } from './components/list-item';
|
|
23
|
-
export type { MenuItem, MenuProps } from './components/menu';
|
|
23
|
+
export type { MenuAction, MenuActionIntent, MenuItem, MenuProps } from './components/menu';
|
|
24
24
|
export { Menu } from './components/menu';
|
|
25
25
|
export type { ModalProps } from './components/modal';
|
|
26
26
|
export { Modal } from './components/modal';
|