@ankhorage/surface 4.4.1 → 5.0.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 +6 -0
- package/dist/features/bottom-sheet/BottomSheetProvider.js +8 -6
- package/dist/features/bottom-sheet/BottomSheetProvider.js.map +1 -1
- package/dist/features/bottom-sheet/public.d.ts +2 -1
- package/dist/features/bottom-sheet/public.d.ts.map +1 -1
- package/dist/features/bottom-sheet/public.js +1 -0
- package/dist/features/bottom-sheet/public.js.map +1 -1
- package/dist/features/popover-menu/adapters/inbound/PopoverMenu.d.ts +5 -0
- package/dist/features/popover-menu/adapters/inbound/PopoverMenu.d.ts.map +1 -0
- package/dist/features/popover-menu/adapters/inbound/PopoverMenu.js +85 -0
- package/dist/features/popover-menu/adapters/inbound/PopoverMenu.js.map +1 -0
- package/dist/features/popover-menu/composition/usePopoverMenuController.d.ts +19 -0
- package/dist/features/popover-menu/composition/usePopoverMenuController.d.ts.map +1 -0
- package/dist/features/popover-menu/composition/usePopoverMenuController.js +35 -0
- package/dist/features/popover-menu/composition/usePopoverMenuController.js.map +1 -0
- package/dist/features/popover-menu/public.d.ts +3 -0
- package/dist/features/popover-menu/public.d.ts.map +1 -0
- package/dist/features/popover-menu/public.js +2 -0
- package/dist/features/popover-menu/public.js.map +1 -0
- package/dist/features/popover-menu/utils/resolveNextMenuIndex.d.ts +5 -0
- package/dist/features/popover-menu/utils/resolveNextMenuIndex.d.ts.map +1 -0
- package/dist/features/popover-menu/utils/resolveNextMenuIndex.js +18 -0
- package/dist/features/popover-menu/utils/resolveNextMenuIndex.js.map +1 -0
- package/dist/features/tooltip/adapters/inbound/Tooltip.d.ts +5 -0
- package/dist/features/tooltip/adapters/inbound/Tooltip.d.ts.map +1 -0
- package/dist/features/tooltip/adapters/inbound/Tooltip.js +25 -0
- package/dist/features/tooltip/adapters/inbound/Tooltip.js.map +1 -0
- package/dist/features/tooltip/composition/useTooltipVisibility.d.ts +9 -0
- package/dist/features/tooltip/composition/useTooltipVisibility.d.ts.map +1 -0
- package/dist/features/tooltip/composition/useTooltipVisibility.js +25 -0
- package/dist/features/tooltip/composition/useTooltipVisibility.js.map +1 -0
- package/dist/features/tooltip/public.d.ts +3 -0
- package/dist/features/tooltip/public.d.ts.map +1 -0
- package/dist/features/tooltip/public.js +2 -0
- package/dist/features/tooltip/public.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/bottomSheet.d.ts +3 -0
- package/dist/types/bottomSheet.d.ts.map +1 -1
- package/dist/types/bottomSheet.js.map +1 -1
- package/dist/types/popoverMenu.d.ts +24 -0
- package/dist/types/popoverMenu.d.ts.map +1 -0
- package/dist/types/popoverMenu.js +2 -0
- package/dist/types/popoverMenu.js.map +1 -0
- package/dist/{components/tooltip/types.d.ts → types/tooltip.d.ts} +2 -2
- package/dist/types/tooltip.d.ts.map +1 -0
- package/dist/types/tooltip.js +2 -0
- package/dist/types/tooltip.js.map +1 -0
- package/package.json +1 -1
- package/src/features/bottom-sheet/BottomSheetProvider.tsx +13 -8
- package/src/features/bottom-sheet/public.test.ts +23 -0
- package/src/features/bottom-sheet/public.ts +12 -1
- package/src/features/popover-menu/adapters/inbound/PopoverMenu.tsx +201 -0
- package/src/features/popover-menu/composition/usePopoverMenuController.ts +55 -0
- package/src/features/popover-menu/public.test.ts +13 -0
- package/src/features/popover-menu/public.ts +6 -0
- package/src/{components/menu/navigation.test.ts → features/popover-menu/utils/resolveNextMenuIndex.test.ts} +4 -4
- package/src/features/popover-menu/utils/resolveNextMenuIndex.ts +21 -0
- package/src/features/tooltip/adapters/inbound/Tooltip.tsx +56 -0
- package/src/features/tooltip/composition/useTooltipVisibility.ts +29 -0
- package/src/features/tooltip/public.test.ts +11 -0
- package/src/features/tooltip/public.ts +2 -0
- package/src/index.test.ts +8 -3
- package/src/index.ts +8 -4
- package/src/types/bottomSheet.ts +4 -0
- package/src/types/popoverMenu.ts +27 -0
- package/src/{components/tooltip/types.ts → types/tooltip.ts} +1 -1
- package/dist/components/menu/Menu.d.ts +0 -4
- package/dist/components/menu/Menu.d.ts.map +0 -1
- package/dist/components/menu/Menu.js +0 -152
- package/dist/components/menu/Menu.js.map +0 -1
- package/dist/components/menu/index.d.ts +0 -3
- package/dist/components/menu/index.d.ts.map +0 -1
- package/dist/components/menu/index.js +0 -2
- package/dist/components/menu/index.js.map +0 -1
- package/dist/components/menu/navigation.d.ts +0 -4
- package/dist/components/menu/navigation.d.ts.map +0 -1
- package/dist/components/menu/navigation.js +0 -25
- package/dist/components/menu/navigation.js.map +0 -1
- package/dist/components/menu/types.d.ts +0 -23
- package/dist/components/menu/types.d.ts.map +0 -1
- package/dist/components/menu/types.js +0 -2
- package/dist/components/menu/types.js.map +0 -1
- package/dist/components/tooltip/Tooltip.d.ts +0 -4
- package/dist/components/tooltip/Tooltip.d.ts.map +0 -1
- package/dist/components/tooltip/Tooltip.js +0 -75
- package/dist/components/tooltip/Tooltip.js.map +0 -1
- package/dist/components/tooltip/index.d.ts +0 -3
- package/dist/components/tooltip/index.d.ts.map +0 -1
- package/dist/components/tooltip/index.js +0 -2
- package/dist/components/tooltip/index.js.map +0 -1
- package/dist/components/tooltip/types.d.ts.map +0 -1
- package/dist/components/tooltip/types.js +0 -2
- package/dist/components/tooltip/types.js.map +0 -1
- package/src/components/menu/Menu.tsx +0 -228
- package/src/components/menu/index.ts +0 -2
- package/src/components/menu/navigation.ts +0 -34
- package/src/components/menu/types.ts +0 -26
- package/src/components/tooltip/Tooltip.tsx +0 -117
- package/src/components/tooltip/index.ts +0 -2
package/src/index.test.ts
CHANGED
|
@@ -28,8 +28,10 @@ const expectedFeatureRootExports = [
|
|
|
28
28
|
"export { Image } from './features/image/public';",
|
|
29
29
|
"export { KeyboardAvoidingView } from './features/keyboard-avoiding-view/public';",
|
|
30
30
|
"export { Box, Container, Divider, Grid, Stack } from './features/layout/public';",
|
|
31
|
+
"export { PopoverMenu } from './features/popover-menu/public';",
|
|
31
32
|
"export { Popover } from './features/popover/public';",
|
|
32
33
|
"export { Surface } from './features/surface/public';",
|
|
34
|
+
"export { Tooltip } from './features/tooltip/public';",
|
|
33
35
|
"export { Toast, ToastProvider, useToast } from './features/toast/public';",
|
|
34
36
|
"export { Heading, Text } from './features/typography/public';",
|
|
35
37
|
] as const;
|
|
@@ -39,12 +41,10 @@ const expectedLegacyRootExports = [
|
|
|
39
41
|
"export { HelperText } from './components/helper-text';",
|
|
40
42
|
"export { Label } from './components/label';",
|
|
41
43
|
"export { ListItem } from './components/list-item';",
|
|
42
|
-
"export { Menu } from './components/menu';",
|
|
43
44
|
"export { Modal } from './components/modal';",
|
|
44
45
|
"export { Switch } from './components/switch';",
|
|
45
46
|
"export { Tab, TabList, TabPanel, Tabs } from './components/tabs';",
|
|
46
47
|
"export { Textarea } from './components/textarea';",
|
|
47
|
-
"export { Tooltip } from './components/tooltip';",
|
|
48
48
|
"export type { InteractionPolicy, InteractionPolicyProps } from './interactionPolicy';",
|
|
49
49
|
"export * from './core/responsive';",
|
|
50
50
|
"export * from './layout';",
|
|
@@ -62,9 +62,11 @@ describe('feature-owned root barrel contract', () => {
|
|
|
62
62
|
'./components/card',
|
|
63
63
|
'./components/checkbox',
|
|
64
64
|
'./components/icon-button',
|
|
65
|
+
'./components/menu',
|
|
65
66
|
'./components/radio',
|
|
66
67
|
'./components/text-input',
|
|
67
68
|
'./components/toast',
|
|
69
|
+
'./components/tooltip',
|
|
68
70
|
'./primitives/heading',
|
|
69
71
|
'./primitives/icon',
|
|
70
72
|
'./primitives/image',
|
|
@@ -94,12 +96,15 @@ describe('remaining root barrel contract', () => {
|
|
|
94
96
|
expectedLegacyRootExports.forEach((line) => expect(indexSource).toContain(line));
|
|
95
97
|
});
|
|
96
98
|
|
|
97
|
-
it('does not retain obsolete action-sheet, drawer, or navigation chrome', () => {
|
|
99
|
+
it('does not retain obsolete action-sheet, drawer, menu aliases, or navigation chrome', () => {
|
|
98
100
|
expect(indexSource).not.toContain('ActionSheet');
|
|
99
101
|
expect(indexSource).not.toContain("'./components/action-sheet'");
|
|
100
102
|
expect(indexSource).not.toContain("'./components/drawer'");
|
|
101
103
|
expect(indexSource).not.toContain("'./components/navigation'");
|
|
102
104
|
expect(indexSource).not.toContain('DrawerNavigation');
|
|
105
|
+
expect(indexSource).not.toMatch(/\bMenuProps\b/u);
|
|
106
|
+
expect(indexSource).not.toMatch(/\bMenuAction\b/u);
|
|
107
|
+
expect(indexSource).not.toMatch(/export\s*\{\s*Menu\s*\}/u);
|
|
103
108
|
expect(indexSource).not.toContain('NavigationItem');
|
|
104
109
|
expect(indexSource).not.toContain('NavigationList');
|
|
105
110
|
expect(indexSource).not.toContain('TabBar');
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,6 @@ export type { LabelProps } from './components/label';
|
|
|
6
6
|
export { Label } from './components/label';
|
|
7
7
|
export type { ListItemProps } from './components/list-item';
|
|
8
8
|
export { ListItem } from './components/list-item';
|
|
9
|
-
export type { MenuAction, MenuActionIntent, MenuItem, MenuProps } from './components/menu';
|
|
10
|
-
export { Menu } from './components/menu';
|
|
11
9
|
export type { ModalProps } from './components/modal';
|
|
12
10
|
export { Modal } from './components/modal';
|
|
13
11
|
export type { SwitchProps } from './components/switch';
|
|
@@ -16,8 +14,6 @@ export type { TabListProps, TabPanelProps, TabProps, TabsProps } from './compone
|
|
|
16
14
|
export { Tab, TabList, TabPanel, Tabs } from './components/tabs';
|
|
17
15
|
export type { TextareaProps } from './components/textarea';
|
|
18
16
|
export { Textarea } from './components/textarea';
|
|
19
|
-
export type { TooltipProps } from './components/tooltip';
|
|
20
|
-
export { Tooltip } from './components/tooltip';
|
|
21
17
|
export type { FontRuntime } from './context/FontContext';
|
|
22
18
|
export { FontProvider, useFontContext } from './context/FontContext';
|
|
23
19
|
export type { I18nInstance, TranslationRuntime, Translator } from './context/TranslationContext';
|
|
@@ -80,6 +76,12 @@ export type {
|
|
|
80
76
|
PopoverProps,
|
|
81
77
|
} from './features/popover/public';
|
|
82
78
|
export { Popover } from './features/popover/public';
|
|
79
|
+
export type {
|
|
80
|
+
PopoverMenuAction,
|
|
81
|
+
PopoverMenuActionIntent,
|
|
82
|
+
PopoverMenuProps,
|
|
83
|
+
} from './features/popover-menu/public';
|
|
84
|
+
export { PopoverMenu } from './features/popover-menu/public';
|
|
83
85
|
export type { SurfaceProps, SurfaceVariant } from './features/surface/public';
|
|
84
86
|
export { Surface } from './features/surface/public';
|
|
85
87
|
export type {
|
|
@@ -90,6 +92,8 @@ export type {
|
|
|
90
92
|
ToastStatus,
|
|
91
93
|
} from './features/toast/public';
|
|
92
94
|
export { Toast, ToastProvider, useToast } from './features/toast/public';
|
|
95
|
+
export type { TooltipProps } from './features/tooltip/public';
|
|
96
|
+
export { Tooltip } from './features/tooltip/public';
|
|
93
97
|
export type { HeadingLevel, HeadingProps, TextProps } from './features/typography/public';
|
|
94
98
|
export { Heading, Text } from './features/typography/public';
|
|
95
99
|
export type { InteractionPolicy, InteractionPolicyProps } from './interactionPolicy';
|
package/src/types/bottomSheet.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
|
|
3
|
+
export type BottomSheetContentMode = 'view' | 'direct';
|
|
4
|
+
|
|
3
5
|
export interface BottomSheetPresentOptions {
|
|
4
6
|
content: React.ReactNode;
|
|
7
|
+
contentMode?: BottomSheetContentMode;
|
|
5
8
|
snapPoints?: readonly (number | string)[];
|
|
6
9
|
initialIndex?: number;
|
|
7
10
|
enableDynamicSizing?: boolean;
|
|
11
|
+
maxDynamicContentSize?: number;
|
|
8
12
|
enablePanDownToClose?: boolean;
|
|
9
13
|
dismissOnBackdropPress?: boolean;
|
|
10
14
|
keyboardBehavior?: 'extend' | 'fillParent' | 'interactive';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { InteractionPolicy } from '../interactionPolicy';
|
|
4
|
+
import type { PopoverAnchorRenderProps } from './popover';
|
|
5
|
+
|
|
6
|
+
export type PopoverMenuActionIntent = 'default' | 'danger';
|
|
7
|
+
|
|
8
|
+
export interface PopoverMenuAction {
|
|
9
|
+
id: string;
|
|
10
|
+
title: React.ReactNode;
|
|
11
|
+
description?: React.ReactNode;
|
|
12
|
+
leading?: React.ReactNode;
|
|
13
|
+
trailing?: React.ReactNode;
|
|
14
|
+
intent?: PopoverMenuActionIntent;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
selected?: boolean;
|
|
17
|
+
activate?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PopoverMenuProps {
|
|
21
|
+
trigger: (controls: PopoverAnchorRenderProps) => React.ReactNode;
|
|
22
|
+
actions: readonly PopoverMenuAction[];
|
|
23
|
+
dismiss?: () => void;
|
|
24
|
+
closeOnSelect?: boolean;
|
|
25
|
+
interactionPolicy?: InteractionPolicy;
|
|
26
|
+
testID?: string;
|
|
27
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../../src/components/menu/Menu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAe1B,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,SAAS,CAAC;AA6CrD,wBAAgB,IAAI,CAAC,EACnB,OAAO,EACP,OAAO,EACP,OAAO,EACP,aAAoB,EACpB,iBAA6B,EAC7B,MAAM,GACP,EAAE,SAAS,qBAgKX"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Pressable, View } from 'react-native';
|
|
3
|
-
import { Box, Stack } from '../../features/layout/public';
|
|
4
|
-
import { Surface } from '../../features/surface/public';
|
|
5
|
-
import { Text } from '../../features/typography/public';
|
|
6
|
-
import { FocusScope } from '../../internal/focus/FocusScope';
|
|
7
|
-
import { useFocusManager } from '../../internal/focus/useFocusManager';
|
|
8
|
-
import { Portal } from '../../internal/overlay/Portal';
|
|
9
|
-
import { resolvePointerEvents } from '../../internal/resolvePointerEvents';
|
|
10
|
-
import { resolveOverlayAnimation } from '../../internal/resolvers';
|
|
11
|
-
import { Inline } from '../../layout';
|
|
12
|
-
import { ButtonBase } from '../../primitives/button-base';
|
|
13
|
-
import { useTheme } from '../../theme/ThemeContext';
|
|
14
|
-
import { resolveNextMenuIndex } from './navigation';
|
|
15
|
-
const boxNonePointerEvents = resolvePointerEvents('box-none');
|
|
16
|
-
function measureNode(node, callback) {
|
|
17
|
-
const measurableNode = node;
|
|
18
|
-
measurableNode?.measureInWindow?.((x, y, width, height) => {
|
|
19
|
-
callback({ height, width, x, y });
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function renderActionContent(action, active) {
|
|
23
|
-
const titleColor = action.intent === 'danger' ? 'danger' : active || action.selected ? 'neutral' : undefined;
|
|
24
|
-
return (<Inline align="center" gap="s" justify="space-between" wrap="nowrap">
|
|
25
|
-
{action.leading ? <Box>{action.leading}</Box> : null}
|
|
26
|
-
<Box flex={1}>
|
|
27
|
-
<Stack gap="xxs">
|
|
28
|
-
<Text color={titleColor} variant="bodySmall" weight={action.selected ? 'semiBold' : 'medium'}>
|
|
29
|
-
{action.title}
|
|
30
|
-
</Text>
|
|
31
|
-
{action.description ? (<Text emphasis="muted" variant="caption">
|
|
32
|
-
{action.description}
|
|
33
|
-
</Text>) : null}
|
|
34
|
-
</Stack>
|
|
35
|
-
</Box>
|
|
36
|
-
{action.trailing ? <Box>{action.trailing}</Box> : null}
|
|
37
|
-
</Inline>);
|
|
38
|
-
}
|
|
39
|
-
export function Menu({ trigger, actions, dismiss, closeOnSelect = true, interactionPolicy = 'enabled', testID, }) {
|
|
40
|
-
const { theme } = useTheme();
|
|
41
|
-
const { bindKeydown } = useFocusManager();
|
|
42
|
-
const animation = resolveOverlayAnimation('menu');
|
|
43
|
-
const anchorRef = React.useRef(null);
|
|
44
|
-
const [open, setOpen] = React.useState(false);
|
|
45
|
-
const [layout, setLayout] = React.useState(null);
|
|
46
|
-
const [activeIndex, setActiveIndex] = React.useState(0);
|
|
47
|
-
const passive = interactionPolicy === 'passive';
|
|
48
|
-
const closeMenu = React.useCallback(() => {
|
|
49
|
-
setOpen(false);
|
|
50
|
-
if (dismiss) {
|
|
51
|
-
dismiss();
|
|
52
|
-
}
|
|
53
|
-
}, [dismiss]);
|
|
54
|
-
const activateAction = React.useCallback((action) => {
|
|
55
|
-
if (action.disabled) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (action.activate) {
|
|
59
|
-
action.activate();
|
|
60
|
-
}
|
|
61
|
-
if (closeOnSelect) {
|
|
62
|
-
closeMenu();
|
|
63
|
-
}
|
|
64
|
-
}, [closeMenu, closeOnSelect]);
|
|
65
|
-
const openMenu = React.useCallback(() => {
|
|
66
|
-
measureNode(anchorRef.current, setLayout);
|
|
67
|
-
const firstEnabledIndex = actions.findIndex((action) => !action.disabled);
|
|
68
|
-
setActiveIndex(firstEnabledIndex === -1 ? 0 : firstEnabledIndex);
|
|
69
|
-
setOpen(true);
|
|
70
|
-
}, [actions]);
|
|
71
|
-
React.useEffect(() => {
|
|
72
|
-
if (!open) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
return bindKeydown((event) => {
|
|
76
|
-
if (passive) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const { key } = event;
|
|
80
|
-
if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End') {
|
|
81
|
-
event.preventDefault();
|
|
82
|
-
setActiveIndex((current) => resolveNextMenuIndex(actions, current, key));
|
|
83
|
-
}
|
|
84
|
-
if (event.key === 'Enter') {
|
|
85
|
-
event.preventDefault();
|
|
86
|
-
const activeAction = actions[activeIndex];
|
|
87
|
-
if (activeAction) {
|
|
88
|
-
activateAction(activeAction);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (event.key === 'Escape') {
|
|
92
|
-
event.preventDefault();
|
|
93
|
-
closeMenu();
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}, [activateAction, actions, activeIndex, bindKeydown, closeMenu, open, passive]);
|
|
97
|
-
return (<View collapsable={false} ref={anchorRef}>
|
|
98
|
-
<ButtonBase onPress={passive ? undefined : open ? closeMenu : openMenu} testID={testID ? `${testID}-trigger` : undefined}>
|
|
99
|
-
{trigger}
|
|
100
|
-
</ButtonBase>
|
|
101
|
-
<Portal layer="menu" visible={open && Boolean(layout)}>
|
|
102
|
-
<View {...boxNonePointerEvents.props} style={[
|
|
103
|
-
boxNonePointerEvents.style,
|
|
104
|
-
{
|
|
105
|
-
bottom: 0,
|
|
106
|
-
left: 0,
|
|
107
|
-
position: 'absolute',
|
|
108
|
-
right: 0,
|
|
109
|
-
top: 0,
|
|
110
|
-
},
|
|
111
|
-
]}>
|
|
112
|
-
<Pressable onPress={passive ? undefined : closeMenu} style={{
|
|
113
|
-
bottom: 0,
|
|
114
|
-
left: 0,
|
|
115
|
-
position: 'absolute',
|
|
116
|
-
right: 0,
|
|
117
|
-
top: 0,
|
|
118
|
-
}}/>
|
|
119
|
-
<FocusScope active={open} onEscape={passive ? undefined : closeMenu}>
|
|
120
|
-
<View style={{
|
|
121
|
-
left: layout?.x ?? 0,
|
|
122
|
-
position: 'absolute',
|
|
123
|
-
top: (layout?.y ?? 0) + (layout?.height ?? 0) + animation.offset,
|
|
124
|
-
}}>
|
|
125
|
-
<Surface accessibilityRole="menu" p="xs" style={{
|
|
126
|
-
minWidth: Math.max(layout?.width ?? 0, 220),
|
|
127
|
-
shadowOpacity: 0.12,
|
|
128
|
-
shadowRadius: 12,
|
|
129
|
-
shadowOffset: { width: 0, height: 6 },
|
|
130
|
-
}} testID={testID} variant="raised">
|
|
131
|
-
{actions.map((action, index) => {
|
|
132
|
-
const active = index === activeIndex;
|
|
133
|
-
const selected = action.selected ?? active;
|
|
134
|
-
return (<Pressable accessibilityRole="menuitem" accessibilityState={{ disabled: action.disabled, selected }} disabled={action.disabled} key={action.id} onPress={passive ? undefined : () => activateAction(action)}>
|
|
135
|
-
<Box px="m" py="s" radius="s" style={{
|
|
136
|
-
backgroundColor: selected
|
|
137
|
-
? theme.semantics.action.neutral.softBg
|
|
138
|
-
: 'transparent',
|
|
139
|
-
opacity: action.disabled ? 0.56 : 1,
|
|
140
|
-
}} testID={testID ? `${testID}-item-${action.id}` : undefined}>
|
|
141
|
-
{renderActionContent(action, active)}
|
|
142
|
-
</Box>
|
|
143
|
-
</Pressable>);
|
|
144
|
-
})}
|
|
145
|
-
</Surface>
|
|
146
|
-
</View>
|
|
147
|
-
</FocusScope>
|
|
148
|
-
</View>
|
|
149
|
-
</Portal>
|
|
150
|
-
</View>);
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=Menu.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAG,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AACxD,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,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EA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AE3D;wBAAA,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CACtC;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 { Box, Stack } from '../../features/layout/public';\nimport { Surface } from '../../features/surface/public';\nimport { Text } from '../../features/typography/public';\nimport { FocusScope } from '../../internal/focus/FocusScope';\nimport { useFocusManager } from '../../internal/focus/useFocusManager';\nimport { Portal } from '../../internal/overlay/Portal';\nimport { resolvePointerEvents } from '../../internal/resolvePointerEvents';\nimport { resolveOverlayAnimation } from '../../internal/resolvers';\nimport { Inline } from '../../layout';\nimport { ButtonBase } from '../../primitives/button-base';\nimport { useTheme } from '../../theme/ThemeContext';\nimport { resolveNextMenuIndex } from './navigation';\nimport type { MenuAction, MenuProps } from './types';\n\nconst boxNonePointerEvents = resolvePointerEvents('box-none');\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({\n trigger,\n actions,\n dismiss,\n closeOnSelect = true,\n interactionPolicy = 'enabled',\n testID,\n}: 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 const passive = interactionPolicy === 'passive';\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 if (passive) {\n return;\n }\n\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, passive]);\n\n return (\n <View collapsable={false} ref={anchorRef}>\n <ButtonBase\n onPress={passive ? undefined : 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 {...boxNonePointerEvents.props}\n style={[\n boxNonePointerEvents.style,\n {\n bottom: 0,\n left: 0,\n position: 'absolute',\n right: 0,\n top: 0,\n },\n ]}\n >\n <Pressable\n onPress={passive ? undefined : 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={passive ? undefined : 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={passive ? undefined : () => 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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,25 +0,0 @@
|
|
|
1
|
-
export function resolveNextMenuIndex(items, currentIndex, key) {
|
|
2
|
-
const enabledIndexes = items.reduce((indexes, item, index) => {
|
|
3
|
-
if (!item.disabled) {
|
|
4
|
-
indexes.push(index);
|
|
5
|
-
}
|
|
6
|
-
return indexes;
|
|
7
|
-
}, []);
|
|
8
|
-
if (enabledIndexes.length === 0) {
|
|
9
|
-
return -1;
|
|
10
|
-
}
|
|
11
|
-
if (key === 'Home') {
|
|
12
|
-
return enabledIndexes[0] ?? -1;
|
|
13
|
-
}
|
|
14
|
-
if (key === 'End') {
|
|
15
|
-
return enabledIndexes[enabledIndexes.length - 1] ?? -1;
|
|
16
|
-
}
|
|
17
|
-
const activeEnabledIndex = enabledIndexes.indexOf(currentIndex);
|
|
18
|
-
const nextEnabledIndex = activeEnabledIndex === -1
|
|
19
|
-
? 0
|
|
20
|
-
: key === 'ArrowUp'
|
|
21
|
-
? (activeEnabledIndex - 1 + enabledIndexes.length) % enabledIndexes.length
|
|
22
|
-
: (activeEnabledIndex + 1) % enabledIndexes.length;
|
|
23
|
-
return enabledIndexes[nextEnabledIndex] ?? -1;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=navigation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,23 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
import type { InteractionPolicy } from '../../interactionPolicy';
|
|
3
|
-
export type MenuActionIntent = 'default' | 'danger';
|
|
4
|
-
export interface MenuAction {
|
|
5
|
-
id: string;
|
|
6
|
-
title: React.ReactNode;
|
|
7
|
-
description?: React.ReactNode;
|
|
8
|
-
leading?: React.ReactNode;
|
|
9
|
-
trailing?: React.ReactNode;
|
|
10
|
-
intent?: MenuActionIntent;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
selected?: boolean;
|
|
13
|
-
activate?: () => void;
|
|
14
|
-
}
|
|
15
|
-
export interface MenuProps {
|
|
16
|
-
trigger?: React.ReactNode;
|
|
17
|
-
actions: readonly MenuAction[];
|
|
18
|
-
dismiss?: () => void;
|
|
19
|
-
closeOnSelect?: boolean;
|
|
20
|
-
interactionPolicy?: InteractionPolicy;
|
|
21
|
-
testID?: string;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,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,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/menu/types.ts"],"names":[],"mappings":"","sourcesContent":["import type React from 'react';\n\nimport type { InteractionPolicy } from '../../interactionPolicy';\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 interactionPolicy?: InteractionPolicy;\n testID?: string;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../src/components/tooltip/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAiB5C,wBAAgB,OAAO,CAAC,EACtB,QAAQ,EACR,OAAO,EACP,KAAW,EACX,iBAA6B,EAC7B,SAAiB,EACjB,MAAM,GACP,EAAE,YAAY,qBAmFd"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Platform, Pressable, View } from 'react-native';
|
|
3
|
-
import { Surface } from '../../features/surface/public';
|
|
4
|
-
import { Text } from '../../features/typography/public';
|
|
5
|
-
import { Portal } from '../../internal/overlay/Portal';
|
|
6
|
-
import { resolvePointerEvents } from '../../internal/resolvePointerEvents';
|
|
7
|
-
import { resolveOverlayAnimation } from '../../internal/resolvers';
|
|
8
|
-
import { useTheme } from '../../theme/ThemeContext';
|
|
9
|
-
const noPointerEvents = resolvePointerEvents('none');
|
|
10
|
-
function measureNode(node, callback) {
|
|
11
|
-
const measurableNode = node;
|
|
12
|
-
measurableNode?.measureInWindow?.((x, y, width, height) => {
|
|
13
|
-
callback({ height, width, x, y });
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
export function Tooltip({ children, content, delay = 150, interactionPolicy = 'enabled', placement = 'top', testID, }) {
|
|
17
|
-
const { theme } = useTheme();
|
|
18
|
-
const animation = resolveOverlayAnimation('tooltip');
|
|
19
|
-
const anchorRef = React.useRef(null);
|
|
20
|
-
const timeoutRef = React.useRef(null);
|
|
21
|
-
const [visible, setVisible] = React.useState(false);
|
|
22
|
-
const [layout, setLayout] = React.useState(null);
|
|
23
|
-
const passive = interactionPolicy === 'passive';
|
|
24
|
-
const show = React.useCallback(() => {
|
|
25
|
-
if (timeoutRef.current) {
|
|
26
|
-
clearTimeout(timeoutRef.current);
|
|
27
|
-
}
|
|
28
|
-
timeoutRef.current = setTimeout(() => {
|
|
29
|
-
measureNode(anchorRef.current, setLayout);
|
|
30
|
-
setVisible(true);
|
|
31
|
-
}, delay);
|
|
32
|
-
}, [delay]);
|
|
33
|
-
const hide = React.useCallback(() => {
|
|
34
|
-
if (timeoutRef.current) {
|
|
35
|
-
clearTimeout(timeoutRef.current);
|
|
36
|
-
timeoutRef.current = null;
|
|
37
|
-
}
|
|
38
|
-
setVisible(false);
|
|
39
|
-
}, []);
|
|
40
|
-
React.useEffect(() => () => {
|
|
41
|
-
if (timeoutRef.current) {
|
|
42
|
-
clearTimeout(timeoutRef.current);
|
|
43
|
-
}
|
|
44
|
-
}, []);
|
|
45
|
-
const tooltipLeft = layout ? layout.x : 0;
|
|
46
|
-
const tooltipTop = layout && placement === 'top'
|
|
47
|
-
? layout.y - animation.offset
|
|
48
|
-
: layout
|
|
49
|
-
? layout.y + layout.height + animation.offset
|
|
50
|
-
: 0;
|
|
51
|
-
return (<View collapsable={false} ref={anchorRef} testID={testID ? `${testID}-anchor` : undefined}>
|
|
52
|
-
<Pressable onBlur={passive ? undefined : hide} onFocus={passive ? undefined : show} onHoverIn={Platform.OS === 'web' && !passive ? show : undefined} onHoverOut={Platform.OS === 'web' && !passive ? hide : undefined}>
|
|
53
|
-
{children}
|
|
54
|
-
</Pressable>
|
|
55
|
-
<Portal layer="tooltip" visible={visible && Boolean(layout)}>
|
|
56
|
-
<View {...noPointerEvents.props} style={[
|
|
57
|
-
noPointerEvents.style,
|
|
58
|
-
{
|
|
59
|
-
left: tooltipLeft,
|
|
60
|
-
position: 'absolute',
|
|
61
|
-
top: tooltipTop,
|
|
62
|
-
},
|
|
63
|
-
]}>
|
|
64
|
-
<Surface p="s" style={{
|
|
65
|
-
backgroundColor: theme.semantics.surface.inverse,
|
|
66
|
-
}} testID={testID} variant="raised">
|
|
67
|
-
<Text emphasis="inverse" variant="caption">
|
|
68
|
-
{content}
|
|
69
|
-
</Text>
|
|
70
|
-
</Surface>
|
|
71
|
-
</View>
|
|
72
|
-
</Portal>
|
|
73
|
-
</View>);
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/tooltip/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAwB,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGpD,MAAM,eAAe,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAQrD,SAAS,WAAW,CAAC,IAAa,EAAE,QAA2C;IAC7E,MAAM,cAAc,GAAG,IAA6B,CAAC;IACrD,cAAc,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAA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,CAAC,SAAS,CAAC,CAChE,UAAU,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAEjE;QAAA,CAAC,QAAQ,CACX;MAAA,EAAE,SAAS,CACX;MAAA,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAC1D;QAAA,CAAC,IAAI,CACH,IAAI,eAAe,CAAC,KAAK,CAAC,CAC1B,KAAK,CAAC,CAAC;YACL,eAAe,CAAC,KAAK;YACrB;gBACE,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,UAAU;gBACpB,GAAG,EAAE,UAAU;aAChB;SACF,CAAC,CAEF;UAAA,CAAC,OAAO,CACN,CAAC,CAAC,GAAG,CACL,KAAK,CAAC,CAAC;YACL,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO;SACjD,CAAC,CACF,MAAM,CAAC,CAAC,MAAM,CAAC,CACf,OAAO,CAAC,QAAQ,CAEhB;YAAA,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CACxC;cAAA,CAAC,OAAO,CACV;YAAA,EAAE,IAAI,CACR;UAAA,EAAE,OAAO,CACX;QAAA,EAAE,IAAI,CACR;MAAA,EAAE,MAAM,CACV;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC","sourcesContent":["import React from 'react';\nimport { type LayoutRectangle, Platform, Pressable, View } from 'react-native';\n\nimport { Surface } from '../../features/surface/public';\nimport { Text } from '../../features/typography/public';\nimport { Portal } from '../../internal/overlay/Portal';\nimport { resolvePointerEvents } from '../../internal/resolvePointerEvents';\nimport { resolveOverlayAnimation } from '../../internal/resolvers';\nimport { useTheme } from '../../theme/ThemeContext';\nimport type { TooltipProps } from './types';\n\nconst noPointerEvents = resolvePointerEvents('none');\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 Tooltip({\n children,\n content,\n delay = 150,\n interactionPolicy = 'enabled',\n placement = 'top',\n testID,\n}: TooltipProps) {\n const { theme } = useTheme();\n const animation = resolveOverlayAnimation('tooltip');\n const anchorRef = React.useRef<View | null>(null);\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n const [visible, setVisible] = React.useState(false);\n const [layout, setLayout] = React.useState<LayoutRectangle | null>(null);\n const passive = interactionPolicy === 'passive';\n\n const show = React.useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n timeoutRef.current = setTimeout(() => {\n measureNode(anchorRef.current, setLayout);\n setVisible(true);\n }, delay);\n }, [delay]);\n\n const hide = React.useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n setVisible(false);\n }, []);\n\n React.useEffect(\n () => () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n },\n [],\n );\n\n const tooltipLeft = layout ? layout.x : 0;\n const tooltipTop =\n layout && placement === 'top'\n ? layout.y - animation.offset\n : layout\n ? layout.y + layout.height + animation.offset\n : 0;\n\n return (\n <View collapsable={false} ref={anchorRef} testID={testID ? `${testID}-anchor` : undefined}>\n <Pressable\n onBlur={passive ? undefined : hide}\n onFocus={passive ? undefined : show}\n onHoverIn={Platform.OS === 'web' && !passive ? show : undefined}\n onHoverOut={Platform.OS === 'web' && !passive ? hide : undefined}\n >\n {children}\n </Pressable>\n <Portal layer=\"tooltip\" visible={visible && Boolean(layout)}>\n <View\n {...noPointerEvents.props}\n style={[\n noPointerEvents.style,\n {\n left: tooltipLeft,\n position: 'absolute',\n top: tooltipTop,\n },\n ]}\n >\n <Surface\n p=\"s\"\n style={{\n backgroundColor: theme.semantics.surface.inverse,\n }}\n testID={testID}\n variant=\"raised\"\n >\n <Text emphasis=\"inverse\" variant=\"caption\">\n {content}\n </Text>\n </Surface>\n </View>\n </Portal>\n </View>\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/tooltip/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/tooltip/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { Tooltip } from './Tooltip';\nexport type { TooltipProps } from './types';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/tooltip/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/tooltip/types.ts"],"names":[],"mappings":"","sourcesContent":["import type React from 'react';\n\nimport type { InteractionPolicy } from '../../interactionPolicy';\n\nexport interface TooltipProps {\n children?: React.ReactNode;\n content?: React.ReactNode;\n delay?: number;\n interactionPolicy?: InteractionPolicy;\n placement?: 'top' | 'bottom';\n testID?: string;\n}\n"]}
|