@duro-app/ui 5.11.0 → 5.13.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/dist/Table-Bms2ftt3.js +1694 -0
- package/dist/Table-Bms2ftt3.js.map +1 -0
- package/dist/compiler-runtime-BuugS4D0.js.map +1 -1
- package/dist/components/Alert/Alert.d.ts.map +1 -1
- package/dist/components/AppShell/native.css.d.ts +53 -0
- package/dist/components/AppShell/native.css.d.ts.map +1 -0
- package/dist/components/Button/Button.d.ts +2 -1
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/components/Button/styles.css.d.ts +1 -0
- package/dist/components/Button/styles.css.d.ts.map +1 -1
- package/dist/components/Callout/Callout.d.ts.map +1 -1
- package/dist/components/Callout/styles.css.d.ts +3 -0
- package/dist/components/Callout/styles.css.d.ts.map +1 -1
- package/dist/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts.map +1 -1
- package/dist/components/DetailPanel/DetailPanel.d.ts.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +2 -17
- package/dist/components/Dialog/Dialog.d.ts.map +1 -1
- package/dist/components/Dialog/Dialog.stories.d.ts +4 -0
- package/dist/components/Dialog/Dialog.stories.d.ts.map +1 -1
- package/dist/components/Dialog/native.css.d.ts +82 -0
- package/dist/components/Dialog/native.css.d.ts.map +1 -0
- package/dist/components/Dialog/parts.css.d.ts +82 -0
- package/dist/components/Dialog/parts.css.d.ts.map +1 -0
- package/dist/components/Dialog/parts.d.ts +35 -0
- package/dist/components/Dialog/parts.d.ts.map +1 -0
- package/dist/components/Dialog/styles.css.d.ts +1 -74
- package/dist/components/Dialog/styles.css.d.ts.map +1 -1
- package/dist/components/Drawer/Drawer.d.ts +7 -35
- package/dist/components/Drawer/Drawer.d.ts.map +1 -1
- package/dist/components/Drawer/Drawer.meta.d.ts.map +1 -1
- package/dist/components/Drawer/DrawerScroll.stories.d.ts.map +1 -1
- package/dist/components/Drawer/DrawerSnap.stories.d.ts +20 -0
- package/dist/components/Drawer/DrawerSnap.stories.d.ts.map +1 -0
- package/dist/components/Drawer/native.css.d.ts +55 -0
- package/dist/components/Drawer/native.css.d.ts.map +1 -0
- package/dist/components/Drawer/parts.css.d.ts +96 -0
- package/dist/components/Drawer/parts.css.d.ts.map +1 -0
- package/dist/components/Drawer/parts.d.ts +56 -0
- package/dist/components/Drawer/parts.d.ts.map +1 -0
- package/dist/components/Drawer/sheetPhysics.d.ts +56 -0
- package/dist/components/Drawer/sheetPhysics.d.ts.map +1 -0
- package/dist/components/Drawer/styles.css.d.ts +15 -58
- package/dist/components/Drawer/styles.css.d.ts.map +1 -1
- package/dist/components/Drawer/touchInput.d.ts +35 -0
- package/dist/components/Drawer/touchInput.d.ts.map +1 -0
- package/dist/components/Drawer/useDrawerRoot.d.ts +33 -0
- package/dist/components/Drawer/useDrawerRoot.d.ts.map +1 -0
- package/dist/components/Drawer/useSheetHeights.d.ts +7 -0
- package/dist/components/Drawer/useSheetHeights.d.ts.map +1 -0
- package/dist/components/Drawer/useSwipeDismiss.d.ts +13 -2
- package/dist/components/Drawer/useSwipeDismiss.d.ts.map +1 -1
- package/dist/components/Grid/styles.css.d.ts +1 -0
- package/dist/components/Grid/styles.css.d.ts.map +1 -1
- package/dist/components/Icon/Icon.d.ts +3 -9
- package/dist/components/Icon/Icon.d.ts.map +1 -1
- package/dist/components/Icon/geometry.d.ts +60 -0
- package/dist/components/Icon/geometry.d.ts.map +1 -0
- package/dist/components/Icon/types.d.ts +15 -0
- package/dist/components/Icon/types.d.ts.map +1 -0
- package/dist/components/Input/Input.d.ts +5 -1
- package/dist/components/Input/Input.d.ts.map +1 -1
- package/dist/components/Input/styles.css.d.ts +1 -0
- package/dist/components/Input/styles.css.d.ts.map +1 -1
- package/dist/components/LinkButton/styles.css.d.ts +1 -0
- package/dist/components/LinkButton/styles.css.d.ts.map +1 -1
- package/dist/components/Menu/Menu.d.ts +7 -1
- package/dist/components/Menu/Menu.d.ts.map +1 -1
- package/dist/components/Menu/native.css.d.ts +14 -0
- package/dist/components/Menu/native.css.d.ts.map +1 -0
- package/dist/components/Menu/useMenuOpen.d.ts +16 -0
- package/dist/components/Menu/useMenuOpen.d.ts.map +1 -0
- package/dist/components/Menu/useMenuRoot.d.ts +3 -6
- package/dist/components/Menu/useMenuRoot.d.ts.map +1 -1
- package/dist/components/Meter/styles.css.d.ts +1 -0
- package/dist/components/Meter/styles.css.d.ts.map +1 -1
- package/dist/components/PageShell/styles.css.d.ts +2 -0
- package/dist/components/PageShell/styles.css.d.ts.map +1 -1
- package/dist/components/Popover/native.css.d.ts +11 -0
- package/dist/components/Popover/native.css.d.ts.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +1 -17
- package/dist/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts +3 -0
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts.map +1 -1
- package/dist/components/RadioGroup/group.d.ts +31 -0
- package/dist/components/RadioGroup/group.d.ts.map +1 -0
- package/dist/components/RadioGroup/styles.css.d.ts +10 -0
- package/dist/components/RadioGroup/styles.css.d.ts.map +1 -1
- package/dist/components/ScrollArea/styles.css.d.ts +1 -0
- package/dist/components/ScrollArea/styles.css.d.ts.map +1 -1
- package/dist/components/SideNav/Chevron.d.ts +4 -0
- package/dist/components/SideNav/Chevron.d.ts.map +1 -0
- package/dist/components/SideNav/SideNav.d.ts.map +1 -1
- package/dist/components/SideNav/styles.css.d.ts +6 -0
- package/dist/components/SideNav/styles.css.d.ts.map +1 -1
- package/dist/components/SideNav/types.d.ts +6 -0
- package/dist/components/SideNav/types.d.ts.map +1 -0
- package/dist/components/Spinner/Spinner.d.ts +2 -6
- package/dist/components/Spinner/Spinner.d.ts.map +1 -1
- package/dist/components/Spinner/Spinner.types.d.ts +6 -0
- package/dist/components/Spinner/Spinner.types.d.ts.map +1 -0
- package/dist/components/Spinner/ring.css.d.ts +39 -0
- package/dist/components/Spinner/ring.css.d.ts.map +1 -0
- package/dist/components/Spinner/styles.css.d.ts +1 -28
- package/dist/components/Spinner/styles.css.d.ts.map +1 -1
- package/dist/components/SplitPane/SplitPane.d.ts +38 -0
- package/dist/components/SplitPane/SplitPane.d.ts.map +1 -0
- package/dist/components/SplitPane/SplitPane.meta.d.ts +3 -0
- package/dist/components/SplitPane/SplitPane.meta.d.ts.map +1 -0
- package/dist/components/SplitPane/SplitPane.stories.d.ts +17 -0
- package/dist/components/SplitPane/SplitPane.stories.d.ts.map +1 -0
- package/dist/components/SplitPane/styles.css.d.ts +78 -0
- package/dist/components/SplitPane/styles.css.d.ts.map +1 -0
- package/dist/components/StatusIcon/StatusIcon.d.ts.map +1 -1
- package/dist/components/StatusIcon/styles.css.d.ts +3 -0
- package/dist/components/StatusIcon/styles.css.d.ts.map +1 -1
- package/dist/components/Switch/Switch.d.ts +2 -18
- package/dist/components/Switch/Switch.d.ts.map +1 -1
- package/dist/components/Switch/Switch.types.d.ts +18 -0
- package/dist/components/Switch/Switch.types.d.ts.map +1 -0
- package/dist/components/TableOfContents/styles.css.d.ts +1 -0
- package/dist/components/TableOfContents/styles.css.d.ts.map +1 -1
- package/dist/components/Tabs/TabLayout.d.ts +7 -0
- package/dist/components/Tabs/TabLayout.d.ts.map +1 -0
- package/dist/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/components/Tabs/indicator.d.ts +28 -0
- package/dist/components/Tabs/indicator.d.ts.map +1 -0
- package/dist/components/Tabs/styles.css.d.ts +4 -0
- package/dist/components/Tabs/styles.css.d.ts.map +1 -1
- package/dist/components/Tabs/useTabIndicator.d.ts +4 -0
- package/dist/components/Tabs/useTabIndicator.d.ts.map +1 -0
- package/dist/components/Tabs/useTabKeys.d.ts +13 -0
- package/dist/components/Tabs/useTabKeys.d.ts.map +1 -0
- package/dist/components/Tag/RemoveGlyph.d.ts +4 -0
- package/dist/components/Tag/RemoveGlyph.d.ts.map +1 -0
- package/dist/components/Tag/Tag.d.ts +2 -24
- package/dist/components/Tag/Tag.d.ts.map +1 -1
- package/dist/components/Tag/styles.css.d.ts +8 -0
- package/dist/components/Tag/styles.css.d.ts.map +1 -1
- package/dist/components/Tag/types.d.ts +39 -0
- package/dist/components/Tag/types.d.ts.map +1 -0
- package/dist/components/Textarea/styles.css.d.ts +1 -0
- package/dist/components/Textarea/styles.css.d.ts.map +1 -1
- package/dist/components/Toast/ToastProvider.d.ts +2 -21
- package/dist/components/Toast/ToastProvider.d.ts.map +1 -1
- package/dist/components/Toast/native.css.d.ts +81 -0
- package/dist/components/Toast/native.css.d.ts.map +1 -0
- package/dist/components/Toast/store.d.ts +47 -0
- package/dist/components/Toast/store.d.ts.map +1 -0
- package/dist/components/Toggle/Toggle.d.ts.map +1 -1
- package/dist/components/Toggle/styles.css.d.ts +11 -2
- package/dist/components/Toggle/styles.css.d.ts.map +1 -1
- package/dist/components/Tooltip/TooltipHint.d.ts +9 -0
- package/dist/components/Tooltip/TooltipHint.d.ts.map +1 -0
- package/dist/components/Tree/Tree.d.ts.map +1 -1
- package/dist/components/Tree/styles.css.d.ts +6 -0
- package/dist/components/Tree/styles.css.d.ts.map +1 -1
- package/dist/components/Tree/useTreeKeyboard.d.ts +19 -0
- package/dist/components/Tree/useTreeKeyboard.d.ts.map +1 -0
- package/dist/components/VirtualList/VirtualList.d.ts +33 -0
- package/dist/components/VirtualList/VirtualList.d.ts.map +1 -0
- package/dist/components/VirtualList/VirtualList.meta.d.ts +3 -0
- package/dist/components/VirtualList/VirtualList.meta.d.ts.map +1 -0
- package/dist/components/VirtualList/VirtualList.stories.d.ts +15 -0
- package/dist/components/VirtualList/VirtualList.stories.d.ts.map +1 -0
- package/dist/components/VirtualList/styles.css.d.ts +28 -0
- package/dist/components/VirtualList/styles.css.d.ts.map +1 -0
- package/dist/components/VirtualTable/styles.css.d.ts +6 -0
- package/dist/components/VirtualTable/styles.css.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6202 -4794
- package/dist/index.js.map +1 -1
- package/dist/shared/ButtonHost.d.ts +11 -0
- package/dist/shared/ButtonHost.d.ts.map +1 -0
- package/dist/shared/portal/hostRegistry.d.ts +33 -0
- package/dist/shared/portal/hostRegistry.d.ts.map +1 -0
- package/dist/shared/pressableChild.d.ts +14 -0
- package/dist/shared/pressableChild.d.ts.map +1 -0
- package/dist/shared/useOverlayOpenState.d.ts +40 -0
- package/dist/shared/useOverlayOpenState.d.ts.map +1 -0
- package/dist/table.js +141 -135
- package/dist/table.js.map +1 -1
- package/package.json +34 -4
- package/src/components/Alert/Alert.tsx +14 -2
- package/src/components/AppShell/AppShell.meta.ts +1 -1
- package/src/components/AppShell/AppShell.native.tsx +174 -0
- package/src/components/AppShell/native.css.ts +56 -0
- package/src/components/Button/Button.tsx +6 -5
- package/src/components/Button/styles.css.ts +2 -0
- package/src/components/Callout/Callout.tsx +17 -3
- package/src/components/Callout/styles.css.ts +5 -0
- package/src/components/Checkbox/Checkbox.native.tsx +67 -0
- package/src/components/Checkbox/Checkbox.tsx +1 -50
- package/src/components/ConfirmDialog/ConfirmDialog.tsx +3 -0
- package/src/components/DetailPanel/DetailPanel.tsx +9 -45
- package/src/components/Dialog/Dialog.native.tsx +296 -0
- package/src/components/Dialog/Dialog.stories.tsx +71 -0
- package/src/components/Dialog/Dialog.tsx +41 -130
- package/src/components/Dialog/native.css.ts +78 -0
- package/src/components/Dialog/parts.css.ts +101 -0
- package/src/components/Dialog/parts.tsx +61 -0
- package/src/components/Dialog/styles.css.ts +2 -89
- package/src/components/Drawer/Drawer.meta.ts +2 -1
- package/src/components/Drawer/Drawer.native.tsx +469 -0
- package/src/components/Drawer/Drawer.tsx +63 -179
- package/src/components/Drawer/DrawerScroll.stories.tsx +4 -54
- package/src/components/Drawer/DrawerSnap.stories.tsx +205 -0
- package/src/components/Drawer/native.css.ts +58 -0
- package/src/components/Drawer/parts.css.ts +125 -0
- package/src/components/Drawer/parts.tsx +110 -0
- package/src/components/Drawer/sheetPhysics.ts +103 -0
- package/src/components/Drawer/styles.css.ts +19 -74
- package/src/components/Drawer/touchInput.ts +81 -0
- package/src/components/Drawer/useDrawerRoot.ts +90 -0
- package/src/components/Drawer/useSheetHeights.ts +42 -0
- package/src/components/Drawer/useSwipeDismiss.ts +146 -23
- package/src/components/Grid/styles.css.ts +2 -0
- package/src/components/Icon/Icon.native.tsx +54 -0
- package/src/components/Icon/Icon.tsx +19 -430
- package/src/components/Icon/geometry.ts +456 -0
- package/src/components/Icon/types.ts +74 -0
- package/src/components/Input/Input.tsx +8 -0
- package/src/components/Input/styles.css.ts +2 -0
- package/src/components/LinkButton/styles.css.ts +2 -0
- package/src/components/Menu/Menu.meta.ts +1 -1
- package/src/components/Menu/Menu.native.tsx +268 -0
- package/src/components/Menu/Menu.tsx +11 -2
- package/src/components/Menu/native.css.ts +18 -0
- package/src/components/Menu/useMenuOpen.ts +33 -0
- package/src/components/Menu/useMenuRoot.ts +7 -26
- package/src/components/Meter/styles.css.ts +2 -0
- package/src/components/PageShell/styles.css.ts +4 -0
- package/src/components/Popover/Popover.meta.ts +1 -1
- package/src/components/Popover/Popover.native.tsx +205 -0
- package/src/components/Popover/native.css.ts +13 -0
- package/src/components/RadioGroup/RadioGroup.meta.ts +1 -1
- package/src/components/RadioGroup/RadioGroup.native.tsx +48 -0
- package/src/components/RadioGroup/RadioGroup.stories.tsx +64 -1
- package/src/components/RadioGroup/RadioGroup.tsx +8 -83
- package/src/components/RadioGroup/group.tsx +85 -0
- package/src/components/RadioGroup/styles.css.ts +13 -0
- package/src/components/ScrollArea/styles.css.ts +2 -0
- package/src/components/SideNav/Chevron.native.tsx +20 -0
- package/src/components/SideNav/Chevron.tsx +20 -0
- package/src/components/SideNav/SideNav.meta.ts +1 -1
- package/src/components/SideNav/SideNav.tsx +57 -41
- package/src/components/SideNav/styles.css.ts +8 -0
- package/src/components/SideNav/types.ts +6 -0
- package/src/components/Spinner/Spinner.native.tsx +37 -0
- package/src/components/Spinner/Spinner.tsx +6 -15
- package/src/components/Spinner/Spinner.types.ts +6 -0
- package/src/components/Spinner/ring.css.ts +45 -0
- package/src/components/Spinner/styles.css.ts +2 -32
- package/src/components/SplitPane/SplitPane.meta.ts +40 -0
- package/src/components/SplitPane/SplitPane.native.tsx +47 -0
- package/src/components/SplitPane/SplitPane.stories.tsx +148 -0
- package/src/components/SplitPane/SplitPane.tsx +218 -0
- package/src/components/SplitPane/styles.css.ts +81 -0
- package/src/components/StatusIcon/StatusIcon.tsx +13 -2
- package/src/components/StatusIcon/styles.css.ts +5 -0
- package/src/components/Switch/Switch.native.tsx +45 -0
- package/src/components/Switch/Switch.tsx +22 -44
- package/src/components/Switch/Switch.types.ts +18 -0
- package/src/components/TableOfContents/styles.css.ts +2 -0
- package/src/components/Tabs/TabLayout.native.tsx +9 -0
- package/src/components/Tabs/TabLayout.tsx +6 -0
- package/src/components/Tabs/Tabs.meta.ts +1 -1
- package/src/components/Tabs/Tabs.tsx +38 -136
- package/src/components/Tabs/indicator.ts +36 -0
- package/src/components/Tabs/styles.css.ts +7 -0
- package/src/components/Tabs/useTabIndicator.native.ts +35 -0
- package/src/components/Tabs/useTabIndicator.ts +49 -0
- package/src/components/Tabs/useTabKeys.native.ts +2 -0
- package/src/components/Tabs/useTabKeys.ts +99 -0
- package/src/components/Tag/RemoveGlyph.native.tsx +17 -0
- package/src/components/Tag/RemoveGlyph.tsx +10 -0
- package/src/components/Tag/Tag.meta.ts +1 -1
- package/src/components/Tag/Tag.native.tsx +70 -0
- package/src/components/Tag/Tag.tsx +9 -37
- package/src/components/Tag/styles.css.ts +9 -0
- package/src/components/Tag/types.ts +43 -0
- package/src/components/Textarea/styles.css.ts +2 -0
- package/src/components/ThemeProvider/ThemeProvider.native.tsx +70 -10
- package/src/components/Toast/Toast.meta.ts +1 -1
- package/src/components/Toast/ToastProvider.native.tsx +226 -0
- package/src/components/Toast/ToastProvider.tsx +22 -84
- package/src/components/Toast/native.css.ts +78 -0
- package/src/components/Toast/store.ts +96 -0
- package/src/components/Toggle/Toggle.tsx +5 -3
- package/src/components/Toggle/styles.css.ts +14 -2
- package/src/components/Tooltip/Tooltip.meta.ts +1 -1
- package/src/components/Tooltip/Tooltip.native.tsx +36 -0
- package/src/components/Tooltip/TooltipHint.ts +13 -0
- package/src/components/Tree/Tree.meta.ts +1 -1
- package/src/components/Tree/Tree.tsx +23 -135
- package/src/components/Tree/styles.css.ts +6 -0
- package/src/components/Tree/useTreeKeyboard.native.ts +5 -0
- package/src/components/Tree/useTreeKeyboard.ts +152 -0
- package/src/components/VirtualList/VirtualList.meta.ts +39 -0
- package/src/components/VirtualList/VirtualList.stories.tsx +95 -0
- package/src/components/VirtualList/VirtualList.tsx +103 -0
- package/src/components/VirtualList/styles.css.ts +31 -0
- package/src/components/VirtualTable/styles.css.ts +12 -0
- package/src/hooks/useContainerBelow.native.ts +30 -0
- package/src/index.native.ts +61 -1
- package/src/index.ts +8 -1
- package/src/native-guard/globals.d.ts +10 -0
- package/src/native-guard/react-dom.d.ts +3 -0
- package/src/shared/ButtonHost.native.tsx +70 -0
- package/src/shared/ButtonHost.tsx +12 -0
- package/src/shared/accessibilityFocus.native.ts +23 -0
- package/src/shared/portal/AnchoredOverlay.native.tsx +117 -0
- package/src/shared/portal/OverlayModal.native.tsx +51 -0
- package/src/shared/portal/PortalHost.native.tsx +102 -0
- package/src/shared/portal/hostRegistry.ts +76 -0
- package/src/shared/portal/themeScope.native.ts +18 -0
- package/src/shared/pressableChild.ts +33 -0
- package/src/shared/safeArea.native.ts +22 -0
- package/src/shared/useKeyboardHeight.native.ts +18 -0
- package/src/shared/useOverlayOpenState.ts +128 -0
- package/src/shared/useScreenReaderEnabled.native.ts +19 -0
- package/dist/Table-ColfpgKV.js +0 -1552
- package/dist/Table-ColfpgKV.js.map +0 -1
- package/dist/components/ThemeProvider/ThemeProvider.native.d.ts +0 -10
- package/dist/components/ThemeProvider/ThemeProvider.native.d.ts.map +0 -1
- package/dist/index.native.d.ts +0 -33
- package/dist/index.native.d.ts.map +0 -1
- package/dist/platform.native.d.ts +0 -2
- package/dist/platform.native.d.ts.map +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {useEffect, useMemo, useState} from 'react'
|
|
2
|
+
import {detentHeight, type SnapPoint} from './sheetPhysics'
|
|
3
|
+
|
|
4
|
+
interface Viewport {
|
|
5
|
+
height: number
|
|
6
|
+
topInset: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** The top safe-area inset, read through a probe: CSS knows it, JavaScript does not. */
|
|
10
|
+
function readTopInset(): number {
|
|
11
|
+
const probe = document.createElement('div')
|
|
12
|
+
probe.style.cssText = 'position:fixed;visibility:hidden;padding-top:env(safe-area-inset-top,0px)'
|
|
13
|
+
document.body.appendChild(probe)
|
|
14
|
+
const inset = parseFloat(getComputedStyle(probe).paddingTop) || 0
|
|
15
|
+
probe.remove()
|
|
16
|
+
return inset
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readViewport(): Viewport {
|
|
20
|
+
return {height: window.innerHeight, topInset: readTopInset()}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Web: each detent's height in px, ascending, following the window as it
|
|
25
|
+
* resizes (a rotated phone, an opened on-screen keyboard).
|
|
26
|
+
*/
|
|
27
|
+
export function useSheetHeights(points: readonly SnapPoint[], active: boolean): number[] {
|
|
28
|
+
const [viewport, setViewport] = useState<Viewport | null>(null)
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!active) return
|
|
32
|
+
setViewport(readViewport())
|
|
33
|
+
const onResize = () => setViewport(readViewport())
|
|
34
|
+
window.addEventListener('resize', onResize)
|
|
35
|
+
return () => window.removeEventListener('resize', onResize)
|
|
36
|
+
}, [active])
|
|
37
|
+
|
|
38
|
+
return useMemo(
|
|
39
|
+
() => (viewport ? points.map((p) => detentHeight(p, viewport.height, viewport.topInset)) : []),
|
|
40
|
+
[points, viewport],
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {useRef, useCallback, useEffect} from 'react'
|
|
2
|
-
import type {DrawerAnchor} from './
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import type {DrawerAnchor} from './parts'
|
|
3
|
+
import {
|
|
4
|
+
DISMISS_DURATION,
|
|
5
|
+
DRAG_SLOP,
|
|
6
|
+
SNAP_DURATION,
|
|
7
|
+
SNAP_MAX_OVERSHOOT,
|
|
8
|
+
rubberBand,
|
|
9
|
+
settleDetent,
|
|
10
|
+
shouldDismissEdge,
|
|
11
|
+
} from './sheetPhysics'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Max pixels the panel visually "grows" when dragged in the opposite direction.
|
|
@@ -17,6 +17,16 @@ const DISMISS_DURATION = 160
|
|
|
17
17
|
*/
|
|
18
18
|
const OPPOSITE_MAX_OVERSCROLL = 12
|
|
19
19
|
|
|
20
|
+
/** A bottom sheet's detents: the drag moves between them before it dismisses. */
|
|
21
|
+
export interface SwipeSnap {
|
|
22
|
+
/** Each detent's height in px, ascending */
|
|
23
|
+
heights: readonly number[]
|
|
24
|
+
/** The detent the sheet rests at */
|
|
25
|
+
index: number
|
|
26
|
+
/** A drag settled on another detent */
|
|
27
|
+
onSnap: (index: number) => void
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
interface UseSwipeDismissOptions {
|
|
21
31
|
anchor: DrawerAnchor
|
|
22
32
|
enabled: boolean
|
|
@@ -27,6 +37,8 @@ interface UseSwipeDismissOptions {
|
|
|
27
37
|
* exists, and listeners must follow the element that is actually shown.
|
|
28
38
|
*/
|
|
29
39
|
panel: HTMLDivElement | null
|
|
40
|
+
/** Bottom anchor with snapPoints: drag between detents, dismiss below the lowest */
|
|
41
|
+
snap?: SwipeSnap | null
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
interface SwipeState {
|
|
@@ -39,6 +51,8 @@ interface SwipeState {
|
|
|
39
51
|
panelSize: number
|
|
40
52
|
/** Inner Duro scroll viewport the gesture started in; capture is deferred until the axis is decided */
|
|
41
53
|
deferredScroll: HTMLElement | null
|
|
54
|
+
/** Started on a snap sheet's grabber: a tap stays its click, a drag moves the sheet */
|
|
55
|
+
fromGrabber: boolean
|
|
42
56
|
pointerId: number
|
|
43
57
|
}
|
|
44
58
|
|
|
@@ -49,7 +63,13 @@ interface SwipeState {
|
|
|
49
63
|
* Opposite direction: iOS-style — panel stays anchored, shows subtle
|
|
50
64
|
* overscroll feedback (box-shadow intensifies), then snaps back.
|
|
51
65
|
*/
|
|
52
|
-
export function useSwipeDismiss({
|
|
66
|
+
export function useSwipeDismiss({
|
|
67
|
+
anchor,
|
|
68
|
+
enabled,
|
|
69
|
+
onDismiss,
|
|
70
|
+
panel,
|
|
71
|
+
snap = null,
|
|
72
|
+
}: UseSwipeDismissOptions) {
|
|
53
73
|
const stateRef = useRef<SwipeState>({
|
|
54
74
|
startX: 0,
|
|
55
75
|
startY: 0,
|
|
@@ -59,8 +79,13 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
59
79
|
swiping: false,
|
|
60
80
|
panelSize: 0,
|
|
61
81
|
deferredScroll: null,
|
|
82
|
+
fromGrabber: false,
|
|
62
83
|
pointerId: 0,
|
|
63
84
|
})
|
|
85
|
+
// Read at event time, so a settle that re-renders mid-gesture is never stale.
|
|
86
|
+
const snapRef = useRef(snap)
|
|
87
|
+
snapRef.current = snap
|
|
88
|
+
const snapping = snap !== null
|
|
64
89
|
|
|
65
90
|
const isHorizontal = anchor === 'left' || anchor === 'right'
|
|
66
91
|
|
|
@@ -117,6 +142,8 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
117
142
|
const resetStyles = useCallback((panelEl: HTMLDivElement) => {
|
|
118
143
|
panelEl.style.transform = ''
|
|
119
144
|
panelEl.style.boxShadow = ''
|
|
145
|
+
panelEl.style.height = ''
|
|
146
|
+
panelEl.style.transition = ''
|
|
120
147
|
|
|
121
148
|
const backdrop = panelEl.closest('[data-drawer-viewport]')
|
|
122
149
|
?.previousElementSibling as HTMLElement | null
|
|
@@ -178,19 +205,79 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
178
205
|
setTimeout(cleanup, 250)
|
|
179
206
|
}, [])
|
|
180
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Snap sheet drag: the visible height follows the finger. Between the lowest
|
|
210
|
+
* and the largest detent the panel resizes; past the largest it resists;
|
|
211
|
+
* below the lowest it slides down and the backdrop fades.
|
|
212
|
+
*/
|
|
213
|
+
const applySnapDrag = useCallback((movement: number, panelEl: HTMLDivElement) => {
|
|
214
|
+
const current = snapRef.current
|
|
215
|
+
if (!current) return
|
|
216
|
+
const {heights, index} = current
|
|
217
|
+
const low = heights[0]
|
|
218
|
+
const high = heights[heights.length - 1]
|
|
219
|
+
const visible = heights[index] - movement
|
|
220
|
+
const backdrop = backdropOf(panelEl)
|
|
221
|
+
if (visible > high) {
|
|
222
|
+
panelEl.style.height = `${high + rubberBand(visible - high, SNAP_MAX_OVERSHOOT)}px`
|
|
223
|
+
panelEl.style.transform = ''
|
|
224
|
+
} else if (visible >= low) {
|
|
225
|
+
panelEl.style.height = `${visible}px`
|
|
226
|
+
panelEl.style.transform = ''
|
|
227
|
+
} else {
|
|
228
|
+
panelEl.style.height = `${low}px`
|
|
229
|
+
panelEl.style.transform = `translateY(${low - visible}px)`
|
|
230
|
+
}
|
|
231
|
+
if (backdrop) backdrop.style.opacity = String(Math.min(1, Math.max(0, visible / low)))
|
|
232
|
+
}, [])
|
|
233
|
+
|
|
234
|
+
/** Settle a snap sheet on a detent, then hand the height back to React */
|
|
235
|
+
const animateToDetent = useCallback((panelEl: HTMLDivElement, target: number) => {
|
|
236
|
+
const current = snapRef.current
|
|
237
|
+
if (!current) return
|
|
238
|
+
const ease = `${SNAP_DURATION}ms cubic-bezier(0.25, 1, 0.5, 1)`
|
|
239
|
+
panelEl.style.transition = `height ${ease}, transform ${ease}`
|
|
240
|
+
panelEl.style.height = `${current.heights[target]}px`
|
|
241
|
+
panelEl.style.transform = ''
|
|
242
|
+
const backdrop = backdropOf(panelEl)
|
|
243
|
+
if (backdrop) {
|
|
244
|
+
backdrop.style.transition = `opacity ${ease}`
|
|
245
|
+
backdrop.style.opacity = ''
|
|
246
|
+
}
|
|
247
|
+
let settled = false
|
|
248
|
+
const done = () => {
|
|
249
|
+
if (settled) return
|
|
250
|
+
settled = true
|
|
251
|
+
current.onSnap(target)
|
|
252
|
+
// React now sizes the panel at this detent: drop the inline copy.
|
|
253
|
+
requestAnimationFrame(() => {
|
|
254
|
+
panelEl.style.transition = ''
|
|
255
|
+
panelEl.style.height = ''
|
|
256
|
+
if (backdrop) backdrop.style.transition = ''
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
panelEl.addEventListener('transitionend', done, {once: true})
|
|
260
|
+
setTimeout(done, SNAP_DURATION + 50)
|
|
261
|
+
}, [])
|
|
262
|
+
|
|
181
263
|
useEffect(() => {
|
|
182
264
|
if (!enabled || !panel) return
|
|
183
265
|
|
|
184
266
|
function handlePointerDown(e: PointerEvent) {
|
|
185
267
|
if (e.button !== 0) return
|
|
186
268
|
const target = e.target as HTMLElement
|
|
187
|
-
const
|
|
269
|
+
const fromGrabber = snapping && target.closest('[data-drawer-grabber]') !== null
|
|
270
|
+
const scrollEl = fromGrabber ? null : target.closest<HTMLElement>('[data-duro-scroll]')
|
|
188
271
|
// Outside a ScrollArea a control keeps its press. Inside one the gesture
|
|
189
272
|
// is decided on the first move even from a control: a list of toggles is
|
|
190
273
|
// all buttons, and touch adjustment snaps a finger onto one. A tap
|
|
191
274
|
// (under the 8px slop) still presses it; a drag never captures before
|
|
192
275
|
// the decision, so the release lands on the panel, not the control.
|
|
193
|
-
if (
|
|
276
|
+
if (
|
|
277
|
+
!fromGrabber &&
|
|
278
|
+
!scrollEl &&
|
|
279
|
+
target.closest('button, a, input, textarea, select, [role="button"]')
|
|
280
|
+
) {
|
|
194
281
|
return
|
|
195
282
|
}
|
|
196
283
|
|
|
@@ -206,11 +293,13 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
206
293
|
|
|
207
294
|
state.pointerId = e.pointerId
|
|
208
295
|
state.deferredScroll = scrollEl
|
|
296
|
+
state.fromGrabber = fromGrabber
|
|
209
297
|
|
|
210
298
|
panel!.dataset.panelSize = String(state.panelSize)
|
|
211
299
|
|
|
212
|
-
// Inside a Duro ScrollArea the scroll may own the gesture
|
|
213
|
-
|
|
300
|
+
// Inside a Duro ScrollArea the scroll may own the gesture, and a press on
|
|
301
|
+
// the grabber may be a tap: wait for the first move.
|
|
302
|
+
if (!state.deferredScroll && !fromGrabber) beginCapture(e.pointerId)
|
|
214
303
|
}
|
|
215
304
|
|
|
216
305
|
function beginCapture(pointerId: number) {
|
|
@@ -219,6 +308,14 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
219
308
|
// Freeze CSS animation — we take over positioning.
|
|
220
309
|
// Never restore it; the panel is already at its final resting position.
|
|
221
310
|
panel!.style.animation = 'none'
|
|
311
|
+
// A snap sheet animates its height between detents; the finger drives it now.
|
|
312
|
+
if (snapping) panel!.style.transition = 'none'
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** A snap sheet below its largest detent grows when dragged up from its content */
|
|
316
|
+
function canGrow() {
|
|
317
|
+
const current = snapRef.current
|
|
318
|
+
return current !== null && current.index < current.heights.length - 1
|
|
222
319
|
}
|
|
223
320
|
|
|
224
321
|
/** True when the viewport can't scroll further against the dismiss direction */
|
|
@@ -240,7 +337,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
240
337
|
|
|
241
338
|
if (!state.swiping) {
|
|
242
339
|
const totalMovement = Math.sqrt(dx * dx + dy * dy)
|
|
243
|
-
if (totalMovement <
|
|
340
|
+
if (totalMovement < DRAG_SLOP) return
|
|
244
341
|
|
|
245
342
|
if (isHorizontal && dx > dy) {
|
|
246
343
|
state.swiping = true
|
|
@@ -250,13 +347,19 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
250
347
|
// Wrong axis — abort gesture
|
|
251
348
|
state.startTime = 0
|
|
252
349
|
state.deferredScroll = null
|
|
350
|
+
state.fromGrabber = false
|
|
253
351
|
return
|
|
254
352
|
}
|
|
255
353
|
|
|
256
354
|
const scrollEl = state.deferredScroll
|
|
257
|
-
if (
|
|
355
|
+
if (state.fromGrabber) {
|
|
356
|
+
beginCapture(state.pointerId)
|
|
357
|
+
} else if (scrollEl) {
|
|
258
358
|
state.deferredScroll = null
|
|
259
|
-
|
|
359
|
+
const movement = getMovement(state)
|
|
360
|
+
const sheetOwns =
|
|
361
|
+
movement > 0 ? isAtDismissEdge(scrollEl) : snapping && movement < 0 && canGrow()
|
|
362
|
+
if (!sheetOwns) {
|
|
260
363
|
// The scroll owns this gesture: no swiping, no capture, no preventDefault
|
|
261
364
|
state.swiping = false
|
|
262
365
|
state.startTime = 0
|
|
@@ -269,7 +372,8 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
269
372
|
if (state.swiping) {
|
|
270
373
|
e.preventDefault()
|
|
271
374
|
const movement = getMovement(state)
|
|
272
|
-
|
|
375
|
+
if (snapping) applySnapDrag(movement, panel!)
|
|
376
|
+
else applyTransform(movement, panel!)
|
|
273
377
|
}
|
|
274
378
|
}
|
|
275
379
|
|
|
@@ -283,6 +387,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
283
387
|
|
|
284
388
|
state.startTime = 0
|
|
285
389
|
state.deferredScroll = null
|
|
390
|
+
state.fromGrabber = false
|
|
286
391
|
|
|
287
392
|
if (!state.swiping) {
|
|
288
393
|
return
|
|
@@ -290,16 +395,26 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
290
395
|
|
|
291
396
|
state.swiping = false
|
|
292
397
|
|
|
398
|
+
const current = snapRef.current
|
|
399
|
+
if (current) {
|
|
400
|
+
const settled = settleDetent({
|
|
401
|
+
heights: current.heights,
|
|
402
|
+
from: current.index,
|
|
403
|
+
height: current.heights[current.index] - movement,
|
|
404
|
+
velocity,
|
|
405
|
+
})
|
|
406
|
+
if (settled === 'dismiss') animateDismiss(panel!)
|
|
407
|
+
else animateToDetent(panel!, settled)
|
|
408
|
+
return
|
|
409
|
+
}
|
|
410
|
+
|
|
293
411
|
if (movement <= 0) {
|
|
294
412
|
// Was dragging in opposite direction — just reset (no translate was applied)
|
|
295
413
|
resetStyles(panel!)
|
|
296
414
|
return
|
|
297
415
|
}
|
|
298
416
|
|
|
299
|
-
|
|
300
|
-
const shouldDismiss = fraction > DISMISS_THRESHOLD || velocity > VELOCITY_THRESHOLD
|
|
301
|
-
|
|
302
|
-
if (shouldDismiss) {
|
|
417
|
+
if (shouldDismissEdge(movement, state.panelSize, velocity)) {
|
|
303
418
|
animateDismiss(panel!)
|
|
304
419
|
} else {
|
|
305
420
|
animateSnapBack(panel!)
|
|
@@ -311,6 +426,7 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
311
426
|
state.startTime = 0
|
|
312
427
|
state.swiping = false
|
|
313
428
|
state.deferredScroll = null
|
|
429
|
+
state.fromGrabber = false
|
|
314
430
|
resetStyles(panel!)
|
|
315
431
|
}
|
|
316
432
|
|
|
@@ -340,8 +456,15 @@ export function useSwipeDismiss({anchor, enabled, onDismiss, panel}: UseSwipeDis
|
|
|
340
456
|
isHorizontal,
|
|
341
457
|
getMovement,
|
|
342
458
|
applyTransform,
|
|
459
|
+
applySnapDrag,
|
|
460
|
+
animateToDetent,
|
|
343
461
|
resetStyles,
|
|
344
462
|
animateSnapBack,
|
|
345
463
|
animateDismiss,
|
|
464
|
+
snapping,
|
|
346
465
|
])
|
|
347
466
|
}
|
|
467
|
+
|
|
468
|
+
function backdropOf(panelEl: HTMLDivElement) {
|
|
469
|
+
return panelEl.closest('[data-drawer-viewport]')?.previousElementSibling as HTMLElement | null
|
|
470
|
+
}
|
|
@@ -86,6 +86,8 @@ export const styles = css.create({
|
|
|
86
86
|
// against an auto width the line breaks come out wrong and the container
|
|
87
87
|
// under-reports its height (verified on the iOS simulator).
|
|
88
88
|
width: '100%',
|
|
89
|
+
// Native has no border-box reset (the web's global-reset.css); declare it.
|
|
90
|
+
boxSizing: 'border-box',
|
|
89
91
|
},
|
|
90
92
|
// border-box is explicit: react-strict-dom mirrors the web default
|
|
91
93
|
// (content-box) on native, which adds the gap padding on top of the basis
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {createElement} from 'react'
|
|
2
|
+
import Svg, {Circle, Ellipse, Line, Path, Polygon, Polyline, Rect} from 'react-native-svg'
|
|
3
|
+
import {ICON_SIZES, type ColorToken} from '@duro-app/tokens/keys'
|
|
4
|
+
import {useResolvedColors} from '../ThemeProvider/ThemeProvider'
|
|
5
|
+
import {GLYPHS, type Paint, type Shape} from './geometry'
|
|
6
|
+
import type {IconProps} from './types'
|
|
7
|
+
|
|
8
|
+
export type {IconName, IconProps, IconSize} from './types'
|
|
9
|
+
|
|
10
|
+
const elements = {
|
|
11
|
+
path: Path,
|
|
12
|
+
circle: Circle,
|
|
13
|
+
ellipse: Ellipse,
|
|
14
|
+
line: Line,
|
|
15
|
+
rect: Rect,
|
|
16
|
+
polyline: Polyline,
|
|
17
|
+
polygon: Polygon,
|
|
18
|
+
} as const
|
|
19
|
+
|
|
20
|
+
/** react-native-svg reads `currentColor` from the Svg's `color`, which is a resolved colour here. */
|
|
21
|
+
function nativeShape(shape: Shape, key: number) {
|
|
22
|
+
const {tag, ...attrs} = shape
|
|
23
|
+
return createElement(elements[tag] as never, {key, ...attrs})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Native Icon: the same geometry as the web, drawn with react-native-svg
|
|
28
|
+
* (plan N0, Decision 9; RSD has no `svg`). It cannot inherit a text colour,
|
|
29
|
+
* so its colour is a token resolved through the nearest ThemeProvider. It is
|
|
30
|
+
* decorative: the control that hosts it carries the label.
|
|
31
|
+
*/
|
|
32
|
+
export function Icon({name, size: sizeToken = 'lg', color = 'text'}: IconProps) {
|
|
33
|
+
const size = ICON_SIZES[sizeToken]
|
|
34
|
+
const glyph = GLYPHS[name]
|
|
35
|
+
const resolved = useResolvedColors()[color as ColorToken]
|
|
36
|
+
const paint: {fill: Paint; stroke?: Paint} =
|
|
37
|
+
glyph.style === 'fill' ? {fill: 'currentColor'} : {fill: 'none', stroke: 'currentColor'}
|
|
38
|
+
return (
|
|
39
|
+
<Svg
|
|
40
|
+
viewBox="0 0 24 24"
|
|
41
|
+
width={size}
|
|
42
|
+
height={size}
|
|
43
|
+
color={resolved}
|
|
44
|
+
{...paint}
|
|
45
|
+
strokeWidth={glyph.style === 'stroke' ? 2 : undefined}
|
|
46
|
+
strokeLinecap="round"
|
|
47
|
+
strokeLinejoin="round"
|
|
48
|
+
accessibilityElementsHidden
|
|
49
|
+
importantForAccessibility="no-hide-descendants"
|
|
50
|
+
>
|
|
51
|
+
{glyph.shapes.map(nativeShape)}
|
|
52
|
+
</Svg>
|
|
53
|
+
)
|
|
54
|
+
}
|