@ankhorage/surface 4.2.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -4
  3. package/dist/components/tabs/Tabs.js +2 -2
  4. package/dist/components/tabs/Tabs.js.map +1 -1
  5. package/dist/components/tabs/context.js +1 -1
  6. package/dist/components/tabs/context.js.map +1 -1
  7. package/dist/context/FontContext.d.ts.map +1 -1
  8. package/dist/context/FontContext.js +3 -3
  9. package/dist/context/FontContext.js.map +1 -1
  10. package/dist/context/TranslationContext.d.ts.map +1 -1
  11. package/dist/context/TranslationContext.js +3 -4
  12. package/dist/context/TranslationContext.js.map +1 -1
  13. package/dist/core/responsive/ResponsiveProvider.d.ts.map +1 -1
  14. package/dist/core/responsive/ResponsiveProvider.js +3 -3
  15. package/dist/core/responsive/ResponsiveProvider.js.map +1 -1
  16. package/dist/examples/DocsExamples.js +1 -1
  17. package/dist/examples/DocsExamples.js.map +1 -1
  18. package/dist/features/accordion/adapters/inbound/Accordion.d.ts +5 -0
  19. package/dist/features/accordion/adapters/inbound/Accordion.d.ts.map +1 -0
  20. package/dist/features/accordion/adapters/inbound/Accordion.js +46 -0
  21. package/dist/features/accordion/adapters/inbound/Accordion.js.map +1 -0
  22. package/dist/features/accordion/adapters/inbound/AccordionContent.d.ts +5 -0
  23. package/dist/features/accordion/adapters/inbound/AccordionContent.d.ts.map +1 -0
  24. package/dist/features/accordion/adapters/inbound/AccordionContent.js +16 -0
  25. package/dist/features/accordion/adapters/inbound/AccordionContent.js.map +1 -0
  26. package/dist/features/accordion/adapters/inbound/AccordionContext.d.ts +4 -0
  27. package/dist/features/accordion/adapters/inbound/AccordionContext.d.ts.map +1 -0
  28. package/dist/features/accordion/adapters/inbound/AccordionContext.js +3 -0
  29. package/dist/features/accordion/adapters/inbound/AccordionContext.js.map +1 -0
  30. package/dist/features/accordion/adapters/inbound/AccordionItem.d.ts +5 -0
  31. package/dist/features/accordion/adapters/inbound/AccordionItem.d.ts.map +1 -0
  32. package/dist/features/accordion/adapters/inbound/AccordionItem.js +28 -0
  33. package/dist/features/accordion/adapters/inbound/AccordionItem.js.map +1 -0
  34. package/dist/features/accordion/adapters/inbound/AccordionItemContext.d.ts +4 -0
  35. package/dist/features/accordion/adapters/inbound/AccordionItemContext.d.ts.map +1 -0
  36. package/dist/features/accordion/adapters/inbound/AccordionItemContext.js +3 -0
  37. package/dist/features/accordion/adapters/inbound/AccordionItemContext.js.map +1 -0
  38. package/dist/features/accordion/adapters/inbound/AccordionTrigger.d.ts +5 -0
  39. package/dist/features/accordion/adapters/inbound/AccordionTrigger.d.ts.map +1 -0
  40. package/dist/features/accordion/adapters/inbound/AccordionTrigger.js +17 -0
  41. package/dist/features/accordion/adapters/inbound/AccordionTrigger.js.map +1 -0
  42. package/dist/features/accordion/public.d.ts +6 -0
  43. package/dist/features/accordion/public.d.ts.map +1 -0
  44. package/dist/features/accordion/public.js +5 -0
  45. package/dist/features/accordion/public.js.map +1 -0
  46. package/dist/features/accordion/utils/resolveAccordionToggle.d.ts +11 -0
  47. package/dist/features/accordion/utils/resolveAccordionToggle.d.ts.map +1 -0
  48. package/dist/features/accordion/utils/resolveAccordionToggle.js +13 -0
  49. package/dist/features/accordion/utils/resolveAccordionToggle.js.map +1 -0
  50. package/dist/features/bottom-sheet/BottomSheetProvider.js +2 -2
  51. package/dist/features/bottom-sheet/BottomSheetProvider.js.map +1 -1
  52. package/dist/features/bottom-sheet/useBottomSheet.js +1 -1
  53. package/dist/features/bottom-sheet/useBottomSheet.js.map +1 -1
  54. package/dist/features/popover/adapters/inbound/Popover.d.ts +5 -0
  55. package/dist/features/popover/adapters/inbound/Popover.d.ts.map +1 -0
  56. package/dist/features/popover/adapters/inbound/Popover.js +31 -0
  57. package/dist/features/popover/adapters/inbound/Popover.js.map +1 -0
  58. package/dist/features/popover/adapters/inbound/PopoverOverlay.d.ts +17 -0
  59. package/dist/features/popover/adapters/inbound/PopoverOverlay.d.ts.map +1 -0
  60. package/dist/features/popover/adapters/inbound/PopoverOverlay.js +34 -0
  61. package/dist/features/popover/adapters/inbound/PopoverOverlay.js.map +1 -0
  62. package/dist/features/popover/adapters/inbound/usePopoverLayout.d.ts +21 -0
  63. package/dist/features/popover/adapters/inbound/usePopoverLayout.d.ts.map +1 -0
  64. package/dist/features/popover/adapters/inbound/usePopoverLayout.js +33 -0
  65. package/dist/features/popover/adapters/inbound/usePopoverLayout.js.map +1 -0
  66. package/dist/features/popover/public.d.ts +3 -0
  67. package/dist/features/popover/public.d.ts.map +1 -0
  68. package/dist/features/popover/public.js +2 -0
  69. package/dist/features/popover/public.js.map +1 -0
  70. package/dist/features/popover/utils/resolvePopoverPosition.d.ts +25 -0
  71. package/dist/features/popover/utils/resolvePopoverPosition.d.ts.map +1 -0
  72. package/dist/features/popover/utils/resolvePopoverPosition.js +23 -0
  73. package/dist/features/popover/utils/resolvePopoverPosition.js.map +1 -0
  74. package/dist/{components/toast → features/toast/adapters/inbound}/Toast.d.ts +2 -1
  75. package/dist/features/toast/adapters/inbound/Toast.d.ts.map +1 -0
  76. package/dist/{components/toast → features/toast/adapters/inbound}/Toast.js +37 -32
  77. package/dist/features/toast/adapters/inbound/Toast.js.map +1 -0
  78. package/dist/features/toast/adapters/inbound/ToastProvider.d.ts +5 -0
  79. package/dist/features/toast/adapters/inbound/ToastProvider.d.ts.map +1 -0
  80. package/dist/features/toast/adapters/inbound/ToastProvider.js +29 -0
  81. package/dist/features/toast/adapters/inbound/ToastProvider.js.map +1 -0
  82. package/dist/features/toast/adapters/inbound/useToast.d.ts +4 -0
  83. package/dist/features/toast/adapters/inbound/useToast.d.ts.map +1 -0
  84. package/dist/features/toast/adapters/inbound/useToast.js +11 -0
  85. package/dist/features/toast/adapters/inbound/useToast.js.map +1 -0
  86. package/dist/features/toast/composition/ToastContext.d.ts +4 -0
  87. package/dist/features/toast/composition/ToastContext.d.ts.map +1 -0
  88. package/dist/features/toast/composition/ToastContext.js +4 -0
  89. package/dist/features/toast/composition/ToastContext.js.map +1 -0
  90. package/dist/features/toast/composition/useToastRuntime.d.ts +11 -0
  91. package/dist/features/toast/composition/useToastRuntime.d.ts.map +1 -0
  92. package/dist/features/toast/composition/useToastRuntime.js +50 -0
  93. package/dist/features/toast/composition/useToastRuntime.js.map +1 -0
  94. package/dist/features/toast/public.d.ts +5 -0
  95. package/dist/features/toast/public.d.ts.map +1 -0
  96. package/dist/features/toast/public.js +4 -0
  97. package/dist/features/toast/public.js.map +1 -0
  98. package/dist/index.d.ts +6 -2
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +3 -1
  101. package/dist/index.js.map +1 -1
  102. package/dist/internal/overlay/OverlayProvider.d.ts +1 -0
  103. package/dist/internal/overlay/OverlayProvider.d.ts.map +1 -1
  104. package/dist/internal/overlay/OverlayProvider.js +9 -7
  105. package/dist/internal/overlay/OverlayProvider.js.map +1 -1
  106. package/dist/internal/overlay/useOverlayStack.js +1 -1
  107. package/dist/internal/overlay/useOverlayStack.js.map +1 -1
  108. package/dist/internal/resolvers/resolveOverlayZIndex.d.ts +1 -1
  109. package/dist/internal/resolvers/resolveOverlayZIndex.d.ts.map +1 -1
  110. package/dist/internal/resolvers/resolveOverlayZIndex.js +1 -0
  111. package/dist/internal/resolvers/resolveOverlayZIndex.js.map +1 -1
  112. package/dist/layout/AppBar.js +1 -1
  113. package/dist/layout/AppBar.js.map +1 -1
  114. package/dist/theme/ThemeContext.d.ts.map +1 -1
  115. package/dist/theme/ThemeContext.js +4 -5
  116. package/dist/theme/ThemeContext.js.map +1 -1
  117. package/dist/types/accordion.d.ts +54 -0
  118. package/dist/types/accordion.d.ts.map +1 -0
  119. package/dist/types/accordion.js +2 -0
  120. package/dist/types/accordion.js.map +1 -0
  121. package/dist/types/popover.d.ts +21 -0
  122. package/dist/types/popover.d.ts.map +1 -0
  123. package/dist/types/popover.js +2 -0
  124. package/dist/types/popover.js.map +1 -0
  125. package/dist/{components/toast/types.d.ts → types/toast.d.ts} +11 -3
  126. package/dist/types/toast.d.ts.map +1 -0
  127. package/dist/types/toast.js +2 -0
  128. package/dist/types/toast.js.map +1 -0
  129. package/package.json +1 -1
  130. package/src/components/tabs/Tabs.tsx +2 -2
  131. package/src/components/tabs/context.tsx +1 -1
  132. package/src/context/FontContext.tsx +3 -3
  133. package/src/context/TranslationContext.tsx +3 -4
  134. package/src/core/responsive/ResponsiveProvider.tsx +3 -3
  135. package/src/examples/DocsExamples.tsx +1 -1
  136. package/src/features/accordion/adapters/inbound/Accordion.tsx +83 -0
  137. package/src/features/accordion/adapters/inbound/AccordionContent.tsx +30 -0
  138. package/src/features/accordion/adapters/inbound/AccordionContext.ts +5 -0
  139. package/src/features/accordion/adapters/inbound/AccordionItem.tsx +42 -0
  140. package/src/features/accordion/adapters/inbound/AccordionItemContext.ts +5 -0
  141. package/src/features/accordion/adapters/inbound/AccordionTrigger.tsx +34 -0
  142. package/src/features/accordion/public.ts +13 -0
  143. package/src/features/accordion/utils/resolveAccordionToggle.test.ts +57 -0
  144. package/src/features/accordion/utils/resolveAccordionToggle.ts +28 -0
  145. package/src/features/bottom-sheet/BottomSheetProvider.tsx +2 -2
  146. package/src/features/bottom-sheet/useBottomSheet.ts +1 -1
  147. package/src/features/popover/adapters/inbound/Popover.tsx +49 -0
  148. package/src/features/popover/adapters/inbound/PopoverOverlay.tsx +72 -0
  149. package/src/features/popover/adapters/inbound/usePopoverLayout.ts +51 -0
  150. package/src/features/popover/public.ts +2 -0
  151. package/src/features/popover/utils/resolvePopoverPosition.test.ts +31 -0
  152. package/src/features/popover/utils/resolvePopoverPosition.ts +40 -0
  153. package/src/{components/toast → features/toast/adapters/inbound}/Toast.tsx +58 -54
  154. package/src/features/toast/adapters/inbound/ToastProvider.tsx +47 -0
  155. package/src/features/toast/adapters/inbound/useToast.test.tsx +18 -0
  156. package/src/features/toast/adapters/inbound/useToast.ts +15 -0
  157. package/src/features/toast/composition/ToastContext.ts +6 -0
  158. package/src/features/toast/composition/useToastRuntime.ts +76 -0
  159. package/src/features/toast/public.ts +10 -0
  160. package/src/index.test.ts +3 -1
  161. package/src/index.ts +29 -2
  162. package/src/internal/overlay/OverlayProvider.tsx +10 -8
  163. package/src/internal/overlay/useOverlayStack.ts +1 -1
  164. package/src/internal/resolvers/resolveOverlayZIndex.test.ts +2 -1
  165. package/src/internal/resolvers/resolveOverlayZIndex.ts +2 -1
  166. package/src/layout/AppBar.tsx +1 -1
  167. package/src/theme/ThemeContext.tsx +4 -5
  168. package/src/types/accordion.ts +69 -0
  169. package/src/types/popover.ts +25 -0
  170. package/src/{components/toast/types.ts → types/toast.ts} +12 -2
  171. package/dist/components/toast/Toast.d.ts.map +0 -1
  172. package/dist/components/toast/Toast.js.map +0 -1
  173. package/dist/components/toast/ToastProvider.d.ts +0 -13
  174. package/dist/components/toast/ToastProvider.d.ts.map +0 -1
  175. package/dist/components/toast/ToastProvider.js +0 -70
  176. package/dist/components/toast/ToastProvider.js.map +0 -1
  177. package/dist/components/toast/index.d.ts +0 -4
  178. package/dist/components/toast/index.d.ts.map +0 -1
  179. package/dist/components/toast/index.js +0 -3
  180. package/dist/components/toast/index.js.map +0 -1
  181. package/dist/components/toast/types.d.ts.map +0 -1
  182. package/dist/components/toast/types.js +0 -2
  183. package/dist/components/toast/types.js.map +0 -1
  184. package/src/components/toast/ToastProvider.tsx +0 -115
  185. package/src/components/toast/index.ts +0 -3
@@ -1 +0,0 @@
1
- {"version":3,"file":"Toast.js","sourceRoot":"","sources":["../../../src/components/toast/Toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;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E,SAAS,CAAC,CACb,CAAC,CAAC,CAAC,IAAI,CACV;MAAA,EAAE,MAAM,CACV;IAAA,EAAE,OAAO,CAAC,CACX,CAAC;AACJ,CAAC","sourcesContent":["import React from 'react';\nimport { Pressable } from 'react-native';\n\nimport { Box } from '../../features/layout/public';\nimport { Surface } from '../../features/surface/public';\nimport { Text } from '../../features/typography/public';\nimport { Inline } from '../../layout';\nimport type { SurfaceColor } from '../../surfaceColor';\nimport { useTheme } from '../../theme/ThemeContext';\nimport type { SurfaceTheme } from '../../theme/types';\nimport type { ToastProps } from './types';\n\nfunction resolveToastStatusColor(theme: SurfaceTheme, status: ToastProps['status']) {\n switch (status) {\n case 'success':\n return theme.semantics.success.base;\n case 'warning':\n return theme.semantics.warning.base;\n case 'error':\n return theme.semantics.error.base;\n case 'info':\n return theme.semantics.info.base;\n default:\n return theme.semantics.action.primary.base;\n }\n}\n\nfunction resolveToastStatusTextColor(status: ToastProps['status']): SurfaceColor {\n switch (status) {\n case 'success':\n return 'success';\n case 'warning':\n return 'warning';\n case 'error':\n return 'error';\n case 'info':\n return 'info';\n default:\n return 'primary';\n }\n}\n\nexport function Toast({\n title,\n description,\n status = 'default',\n onDismiss,\n interactionPolicy = 'enabled',\n testID,\n}: ToastProps) {\n const { theme } = useTheme();\n const statusColor = resolveToastStatusColor(theme, status);\n const statusTextColor = resolveToastStatusTextColor(status);\n const passive = interactionPolicy === 'passive';\n\n return (\n <Surface\n p=\"m\"\n style={{\n borderLeftColor: statusColor,\n borderLeftWidth: 3,\n minWidth: 280,\n shadowOpacity: 0.14,\n shadowRadius: 12,\n shadowOffset: { width: 0, height: 6 },\n }}\n testID={testID}\n variant=\"raised\"\n >\n <Inline align=\"center\" justify=\"space-between\">\n <Box flex={1}>\n {title ? (\n <Text variant=\"label\" weight=\"medium\">\n {title}\n </Text>\n ) : null}\n {description ? <Text emphasis=\"muted\">{description}</Text> : null}\n </Box>\n {onDismiss ? (\n <Pressable\n accessibilityLabel=\"Dismiss notification\"\n accessibilityRole=\"button\"\n onPress={passive ? undefined : onDismiss}\n testID={testID ? `${testID}-dismiss` : undefined}\n >\n <Text color={statusTextColor}>×</Text>\n </Pressable>\n ) : null}\n </Inline>\n </Surface>\n );\n}\n"]}
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import type { ToastOptions } from './types';
3
- interface ToastContextValue {
4
- dismissToast: (id: string) => void;
5
- showToast: (options: ToastOptions) => string;
6
- }
7
- export declare function ToastProvider({ children, defaultDuration, }: {
8
- children: React.ReactNode;
9
- defaultDuration?: number;
10
- }): React.JSX.Element;
11
- export declare function useToast(): ToastContextValue;
12
- export {};
13
- //# sourceMappingURL=ToastProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToastProvider.d.ts","sourceRoot":"","sources":["../../../src/components/toast/ToastProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAM5C,UAAU,iBAAiB;IACzB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,MAAM,CAAC;CAC9C;AAMD,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,eAAsB,GACvB,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,qBA6EA;AAED,wBAAgB,QAAQ,sBAQvB"}
@@ -1,70 +0,0 @@
1
- import React from 'react';
2
- import { Stack } from '../../features/layout/public';
3
- import { Portal } from '../../internal/overlay/Portal';
4
- import { resolveOverlayAnimation } from '../../internal/resolvers';
5
- import { Toast } from './Toast';
6
- const ToastContext = React.createContext(null);
7
- let toastCounter = 0;
8
- export function ToastProvider({ children, defaultDuration = 4000, }) {
9
- const [toasts, setToasts] = React.useState([]);
10
- const animation = resolveOverlayAnimation('toast');
11
- const timersRef = React.useRef(new Map());
12
- const dismissToast = React.useCallback((id) => {
13
- const timer = timersRef.current.get(id);
14
- if (timer) {
15
- clearTimeout(timer);
16
- timersRef.current.delete(id);
17
- }
18
- setToasts((current) => current.filter((toast) => toast.id !== id));
19
- }, []);
20
- const showToast = React.useCallback((options) => {
21
- const id = options.id ?? `toast-${toastCounter++}`;
22
- setToasts((current) => [...current, { ...options, id }]);
23
- return id;
24
- }, []);
25
- React.useEffect(() => {
26
- toasts.forEach((toast) => {
27
- if (timersRef.current.has(toast.id)) {
28
- return;
29
- }
30
- const timer = setTimeout(() => {
31
- dismissToast(toast.id);
32
- }, toast.duration ?? defaultDuration);
33
- timersRef.current.set(toast.id, timer);
34
- });
35
- const activeToastIds = new Set(toasts.map((toast) => toast.id));
36
- timersRef.current.forEach((timer, id) => {
37
- if (!activeToastIds.has(id)) {
38
- clearTimeout(timer);
39
- timersRef.current.delete(id);
40
- }
41
- });
42
- }, [defaultDuration, dismissToast, toasts]);
43
- React.useEffect(() => {
44
- const timers = timersRef.current;
45
- return () => {
46
- timers.forEach((timer) => clearTimeout(timer));
47
- timers.clear();
48
- };
49
- }, []);
50
- return (<ToastContext.Provider value={{ dismissToast, showToast }}>
51
- {children}
52
- <Portal layer="toast" visible={toasts.length > 0}>
53
- <Stack gap="s" pointerEvents="box-none" style={{
54
- alignItems: 'flex-end',
55
- padding: 16,
56
- paddingTop: 16 + animation.offset,
57
- }}>
58
- {toasts.map((toast) => (<Toast description={toast.description} key={toast.id} onDismiss={() => dismissToast(toast.id)} status={toast.status} testID={toast.testID} title={toast.title}/>))}
59
- </Stack>
60
- </Portal>
61
- </ToastContext.Provider>);
62
- }
63
- export function useToast() {
64
- const context = React.useContext(ToastContext);
65
- if (!context) {
66
- throw new Error('useToast must be used within <ToastProvider>.');
67
- }
68
- return context;
69
- }
70
- //# sourceMappingURL=ToastProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToastProvider.js","sourceRoot":"","sources":["../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,CAAC,QAAQ,CAAC,CACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAE/C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import React from 'react';\n\nimport { Stack } from '../../features/layout/public';\nimport { Portal } from '../../internal/overlay/Portal';\nimport { resolveOverlayAnimation } from '../../internal/resolvers';\nimport { Toast } from './Toast';\nimport type { ToastOptions } from './types';\n\ninterface ToastEntry extends ToastOptions {\n id: string;\n}\n\ninterface ToastContextValue {\n dismissToast: (id: string) => void;\n showToast: (options: ToastOptions) => string;\n}\n\nconst ToastContext = React.createContext<ToastContextValue | null>(null);\n\nlet toastCounter = 0;\n\nexport function ToastProvider({\n children,\n defaultDuration = 4000,\n}: {\n children: React.ReactNode;\n defaultDuration?: number;\n}) {\n const [toasts, setToasts] = React.useState<ToastEntry[]>([]);\n const animation = resolveOverlayAnimation('toast');\n const timersRef = React.useRef(new Map<string, ReturnType<typeof setTimeout>>());\n\n const dismissToast = React.useCallback((id: string) => {\n const timer = timersRef.current.get(id);\n if (timer) {\n clearTimeout(timer);\n timersRef.current.delete(id);\n }\n setToasts((current) => current.filter((toast) => toast.id !== id));\n }, []);\n\n const showToast = React.useCallback((options: ToastOptions) => {\n const id = options.id ?? `toast-${toastCounter++}`;\n setToasts((current) => [...current, { ...options, id }]);\n return id;\n }, []);\n\n React.useEffect(() => {\n toasts.forEach((toast) => {\n if (timersRef.current.has(toast.id)) {\n return;\n }\n\n const timer = setTimeout(() => {\n dismissToast(toast.id);\n }, toast.duration ?? defaultDuration);\n\n timersRef.current.set(toast.id, timer);\n });\n\n const activeToastIds = new Set(toasts.map((toast) => toast.id));\n timersRef.current.forEach((timer, id) => {\n if (!activeToastIds.has(id)) {\n clearTimeout(timer);\n timersRef.current.delete(id);\n }\n });\n }, [defaultDuration, dismissToast, toasts]);\n\n React.useEffect(() => {\n const timers = timersRef.current;\n return () => {\n timers.forEach((timer) => clearTimeout(timer));\n timers.clear();\n };\n }, []);\n\n return (\n <ToastContext.Provider value={{ dismissToast, showToast }}>\n {children}\n <Portal layer=\"toast\" visible={toasts.length > 0}>\n <Stack\n gap=\"s\"\n pointerEvents=\"box-none\"\n style={{\n alignItems: 'flex-end',\n padding: 16,\n paddingTop: 16 + animation.offset,\n }}\n >\n {toasts.map((toast) => (\n <Toast\n description={toast.description}\n key={toast.id}\n onDismiss={() => dismissToast(toast.id)}\n status={toast.status}\n testID={toast.testID}\n title={toast.title}\n />\n ))}\n </Stack>\n </Portal>\n </ToastContext.Provider>\n );\n}\n\nexport function useToast() {\n const context = React.useContext(ToastContext);\n\n if (!context) {\n throw new Error('useToast must be used within <ToastProvider>.');\n }\n\n return context;\n}\n"]}
@@ -1,4 +0,0 @@
1
- export { Toast } from './Toast';
2
- export { ToastProvider, useToast } from './ToastProvider';
3
- export type { ToastOptions, ToastProps, ToastStatus } from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/toast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC1D,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
@@ -1,3 +0,0 @@
1
- export { Toast } from './Toast';
2
- export { ToastProvider, useToast } from './ToastProvider';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/toast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { Toast } from './Toast';\nexport { ToastProvider, useToast } from './ToastProvider';\nexport type { ToastOptions, ToastProps, ToastStatus } from './types';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/toast/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,kBAAkB,CAAC;AAEzD,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACrC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/components/toast/types.ts"],"names":[],"mappings":"","sourcesContent":["import type React from 'react';\n\nimport type { InteractionPolicy } from '../../interactionPolicy';\nimport type { SurfaceStatusColor } from '../../surfaceColor';\n\nexport type ToastStatus = 'default' | SurfaceStatusColor;\n\nexport interface ToastProps {\n title?: React.ReactNode;\n description?: React.ReactNode;\n status?: ToastStatus;\n onDismiss?: (() => void) | undefined;\n interactionPolicy?: InteractionPolicy;\n testID?: string;\n}\n\nexport interface ToastOptions extends Omit<ToastProps, 'onDismiss'> {\n duration?: number;\n id?: string;\n}\n"]}
@@ -1,115 +0,0 @@
1
- import React from 'react';
2
-
3
- import { Stack } from '../../features/layout/public';
4
- import { Portal } from '../../internal/overlay/Portal';
5
- import { resolveOverlayAnimation } from '../../internal/resolvers';
6
- import { Toast } from './Toast';
7
- import type { ToastOptions } from './types';
8
-
9
- interface ToastEntry extends ToastOptions {
10
- id: string;
11
- }
12
-
13
- interface ToastContextValue {
14
- dismissToast: (id: string) => void;
15
- showToast: (options: ToastOptions) => string;
16
- }
17
-
18
- const ToastContext = React.createContext<ToastContextValue | null>(null);
19
-
20
- let toastCounter = 0;
21
-
22
- export function ToastProvider({
23
- children,
24
- defaultDuration = 4000,
25
- }: {
26
- children: React.ReactNode;
27
- defaultDuration?: number;
28
- }) {
29
- const [toasts, setToasts] = React.useState<ToastEntry[]>([]);
30
- const animation = resolveOverlayAnimation('toast');
31
- const timersRef = React.useRef(new Map<string, ReturnType<typeof setTimeout>>());
32
-
33
- const dismissToast = React.useCallback((id: string) => {
34
- const timer = timersRef.current.get(id);
35
- if (timer) {
36
- clearTimeout(timer);
37
- timersRef.current.delete(id);
38
- }
39
- setToasts((current) => current.filter((toast) => toast.id !== id));
40
- }, []);
41
-
42
- const showToast = React.useCallback((options: ToastOptions) => {
43
- const id = options.id ?? `toast-${toastCounter++}`;
44
- setToasts((current) => [...current, { ...options, id }]);
45
- return id;
46
- }, []);
47
-
48
- React.useEffect(() => {
49
- toasts.forEach((toast) => {
50
- if (timersRef.current.has(toast.id)) {
51
- return;
52
- }
53
-
54
- const timer = setTimeout(() => {
55
- dismissToast(toast.id);
56
- }, toast.duration ?? defaultDuration);
57
-
58
- timersRef.current.set(toast.id, timer);
59
- });
60
-
61
- const activeToastIds = new Set(toasts.map((toast) => toast.id));
62
- timersRef.current.forEach((timer, id) => {
63
- if (!activeToastIds.has(id)) {
64
- clearTimeout(timer);
65
- timersRef.current.delete(id);
66
- }
67
- });
68
- }, [defaultDuration, dismissToast, toasts]);
69
-
70
- React.useEffect(() => {
71
- const timers = timersRef.current;
72
- return () => {
73
- timers.forEach((timer) => clearTimeout(timer));
74
- timers.clear();
75
- };
76
- }, []);
77
-
78
- return (
79
- <ToastContext.Provider value={{ dismissToast, showToast }}>
80
- {children}
81
- <Portal layer="toast" visible={toasts.length > 0}>
82
- <Stack
83
- gap="s"
84
- pointerEvents="box-none"
85
- style={{
86
- alignItems: 'flex-end',
87
- padding: 16,
88
- paddingTop: 16 + animation.offset,
89
- }}
90
- >
91
- {toasts.map((toast) => (
92
- <Toast
93
- description={toast.description}
94
- key={toast.id}
95
- onDismiss={() => dismissToast(toast.id)}
96
- status={toast.status}
97
- testID={toast.testID}
98
- title={toast.title}
99
- />
100
- ))}
101
- </Stack>
102
- </Portal>
103
- </ToastContext.Provider>
104
- );
105
- }
106
-
107
- export function useToast() {
108
- const context = React.useContext(ToastContext);
109
-
110
- if (!context) {
111
- throw new Error('useToast must be used within <ToastProvider>.');
112
- }
113
-
114
- return context;
115
- }
@@ -1,3 +0,0 @@
1
- export { Toast } from './Toast';
2
- export { ToastProvider, useToast } from './ToastProvider';
3
- export type { ToastOptions, ToastProps, ToastStatus } from './types';