gooee 0.0.0-stage → 0.41.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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -2
  3. package/package.json +36 -4
  4. package/scripts/add.js +533 -0
  5. package/scripts/pro-components.json +82 -0
  6. package/src/base.css +39 -0
  7. package/src/components/Accordion/Accordion.module.css +90 -0
  8. package/src/components/Accordion/Accordion.tsx +125 -0
  9. package/src/components/Accordion/index.ts +1 -0
  10. package/src/components/Alert/Alert.module.css +121 -0
  11. package/src/components/Alert/Alert.tsx +90 -0
  12. package/src/components/Alert/index.ts +1 -0
  13. package/src/components/AlertDialog/AlertDialog.module.css +2 -0
  14. package/src/components/AlertDialog/AlertDialog.tsx +108 -0
  15. package/src/components/AlertDialog/index.ts +1 -0
  16. package/src/components/AnimatedNumber/AnimatedNumber.module.css +48 -0
  17. package/src/components/AnimatedNumber/AnimatedNumber.tsx +52 -0
  18. package/src/components/AnimatedNumber/index.ts +1 -0
  19. package/src/components/AspectRatio/AspectRatio.module.css +15 -0
  20. package/src/components/AspectRatio/AspectRatio.tsx +12 -0
  21. package/src/components/AspectRatio/index.ts +1 -0
  22. package/src/components/Avatar/Avatar.module.css +62 -0
  23. package/src/components/Avatar/Avatar.tsx +55 -0
  24. package/src/components/Avatar/index.ts +3 -0
  25. package/src/components/AvatarGroup/AvatarGroup.module.css +53 -0
  26. package/src/components/AvatarGroup/AvatarGroup.tsx +43 -0
  27. package/src/components/AvatarGroup/index.ts +1 -0
  28. package/src/components/Badge/Badge.module.css +69 -0
  29. package/src/components/Badge/Badge.tsx +25 -0
  30. package/src/components/Badge/index.ts +1 -0
  31. package/src/components/Breadcrumb/Breadcrumb.module.css +104 -0
  32. package/src/components/Breadcrumb/Breadcrumb.tsx +76 -0
  33. package/src/components/Breadcrumb/index.ts +1 -0
  34. package/src/components/Button/Button.module.css +191 -0
  35. package/src/components/Button/Button.tsx +148 -0
  36. package/src/components/Button/index.ts +1 -0
  37. package/src/components/ButtonGroup/ButtonGroup.module.css +59 -0
  38. package/src/components/ButtonGroup/ButtonGroup.tsx +45 -0
  39. package/src/components/ButtonGroup/index.ts +1 -0
  40. package/src/components/Card/Card.module.css +82 -0
  41. package/src/components/Card/Card.tsx +34 -0
  42. package/src/components/Card/index.ts +1 -0
  43. package/src/components/Center/Center.module.css +15 -0
  44. package/src/components/Center/Center.tsx +28 -0
  45. package/src/components/Center/index.ts +1 -0
  46. package/src/components/Checkbox/Checkbox.module.css +120 -0
  47. package/src/components/Checkbox/Checkbox.tsx +133 -0
  48. package/src/components/Checkbox/index.ts +1 -0
  49. package/src/components/CheckboxGroup/CheckboxGroup.module.css +30 -0
  50. package/src/components/CheckboxGroup/CheckboxGroup.tsx +88 -0
  51. package/src/components/CheckboxGroup/index.ts +1 -0
  52. package/src/components/Cluster/Cluster.module.css +25 -0
  53. package/src/components/Cluster/Cluster.tsx +26 -0
  54. package/src/components/Cluster/index.ts +1 -0
  55. package/src/components/CodeBlock/CodeBlock.module.css +74 -0
  56. package/src/components/CodeBlock/CodeBlock.tsx +53 -0
  57. package/src/components/CodeBlock/highlight.ts +73 -0
  58. package/src/components/CodeBlock/index.ts +1 -0
  59. package/src/components/Collapsible/Collapsible.module.css +75 -0
  60. package/src/components/Collapsible/Collapsible.tsx +71 -0
  61. package/src/components/Collapsible/index.ts +1 -0
  62. package/src/components/Container/Container.module.css +14 -0
  63. package/src/components/Container/Container.tsx +19 -0
  64. package/src/components/Container/index.ts +1 -0
  65. package/src/components/CopyButton/CopyButton.module.css +125 -0
  66. package/src/components/CopyButton/CopyButton.tsx +160 -0
  67. package/src/components/CopyButton/index.ts +1 -0
  68. package/src/components/Dial/Dial.module.css +344 -0
  69. package/src/components/Dial/Dial.tsx +332 -0
  70. package/src/components/Dial/index.ts +1 -0
  71. package/src/components/Dialog/Dialog.module.css +190 -0
  72. package/src/components/Dialog/Dialog.tsx +100 -0
  73. package/src/components/Dialog/index.ts +1 -0
  74. package/src/components/Divider/Divider.module.css +39 -0
  75. package/src/components/Divider/Divider.tsx +34 -0
  76. package/src/components/Divider/index.ts +1 -0
  77. package/src/components/DropdownMenu/DropdownMenu.module.css +134 -0
  78. package/src/components/DropdownMenu/DropdownMenu.tsx +215 -0
  79. package/src/components/DropdownMenu/index.ts +1 -0
  80. package/src/components/EmptyState/EmptyState.module.css +66 -0
  81. package/src/components/EmptyState/EmptyState.tsx +38 -0
  82. package/src/components/EmptyState/index.ts +1 -0
  83. package/src/components/Fab/Fab.module.css +176 -0
  84. package/src/components/Fab/Fab.tsx +117 -0
  85. package/src/components/Fab/index.ts +1 -0
  86. package/src/components/Fieldset/Fieldset.module.css +34 -0
  87. package/src/components/Fieldset/Fieldset.tsx +41 -0
  88. package/src/components/Fieldset/index.ts +1 -0
  89. package/src/components/FormField/FormField.module.css +62 -0
  90. package/src/components/FormField/FormField.tsx +91 -0
  91. package/src/components/FormField/index.ts +2 -0
  92. package/src/components/Grid/Grid.module.css +39 -0
  93. package/src/components/Grid/Grid.tsx +35 -0
  94. package/src/components/Grid/index.ts +1 -0
  95. package/src/components/HoldToConfirm/HoldToConfirm.module.css +175 -0
  96. package/src/components/HoldToConfirm/HoldToConfirm.tsx +334 -0
  97. package/src/components/HoldToConfirm/index.ts +1 -0
  98. package/src/components/IconButton/IconButton.module.css +78 -0
  99. package/src/components/IconButton/IconButton.tsx +35 -0
  100. package/src/components/IconButton/index.ts +1 -0
  101. package/src/components/Input/Input.module.css +157 -0
  102. package/src/components/Input/Input.tsx +133 -0
  103. package/src/components/Input/index.ts +1 -0
  104. package/src/components/InputGroup/InputGroup.module.css +146 -0
  105. package/src/components/InputGroup/InputGroup.tsx +90 -0
  106. package/src/components/InputGroup/index.ts +1 -0
  107. package/src/components/Kbd/Kbd.module.css +28 -0
  108. package/src/components/Kbd/Kbd.tsx +38 -0
  109. package/src/components/Kbd/index.ts +1 -0
  110. package/src/components/Link/Link.module.css +65 -0
  111. package/src/components/Link/Link.tsx +41 -0
  112. package/src/components/Link/index.ts +1 -0
  113. package/src/components/LivePill/LivePill.module.css +207 -0
  114. package/src/components/LivePill/LivePill.tsx +182 -0
  115. package/src/components/LivePill/index.ts +1 -0
  116. package/src/components/Meter/Meter.module.css +91 -0
  117. package/src/components/Meter/Meter.tsx +109 -0
  118. package/src/components/Meter/index.ts +1 -0
  119. package/src/components/MorphButton/MorphButton.module.css +152 -0
  120. package/src/components/MorphButton/MorphButton.tsx +203 -0
  121. package/src/components/MorphButton/index.ts +1 -0
  122. package/src/components/NumberInput/NumberInput.module.css +104 -0
  123. package/src/components/NumberInput/NumberInput.tsx +252 -0
  124. package/src/components/NumberInput/index.ts +2 -0
  125. package/src/components/Pagination/Pagination.module.css +88 -0
  126. package/src/components/Pagination/Pagination.tsx +126 -0
  127. package/src/components/Pagination/index.ts +1 -0
  128. package/src/components/PasswordInput/PasswordInput.module.css +64 -0
  129. package/src/components/PasswordInput/PasswordInput.tsx +63 -0
  130. package/src/components/PasswordInput/index.ts +2 -0
  131. package/src/components/PickerWheel/PickerWheel.module.css +123 -0
  132. package/src/components/PickerWheel/PickerWheel.tsx +326 -0
  133. package/src/components/PickerWheel/index.ts +1 -0
  134. package/src/components/Popover/Popover.module.css +78 -0
  135. package/src/components/Popover/Popover.tsx +117 -0
  136. package/src/components/Popover/index.ts +1 -0
  137. package/src/components/ProgressBar/ProgressBar.module.css +61 -0
  138. package/src/components/ProgressBar/ProgressBar.tsx +48 -0
  139. package/src/components/ProgressBar/index.ts +1 -0
  140. package/src/components/Prose/Prose.module.css +115 -0
  141. package/src/components/Prose/Prose.tsx +14 -0
  142. package/src/components/Prose/index.ts +1 -0
  143. package/src/components/Radio/Radio.module.css +106 -0
  144. package/src/components/Radio/Radio.tsx +115 -0
  145. package/src/components/Radio/index.ts +1 -0
  146. package/src/components/Retime/Retime.tsx +116 -0
  147. package/src/components/Retime/index.ts +1 -0
  148. package/src/components/RulerScrubber/RulerScrubber.module.css +146 -0
  149. package/src/components/RulerScrubber/RulerScrubber.tsx +209 -0
  150. package/src/components/RulerScrubber/index.ts +1 -0
  151. package/src/components/ScrollArea/ScrollArea.module.css +72 -0
  152. package/src/components/ScrollArea/ScrollArea.tsx +172 -0
  153. package/src/components/ScrollArea/index.ts +1 -0
  154. package/src/components/SearchInput/SearchInput.module.css +53 -0
  155. package/src/components/SearchInput/SearchInput.tsx +104 -0
  156. package/src/components/SearchInput/index.ts +2 -0
  157. package/src/components/SegmentedControl/SegmentedControl.module.css +150 -0
  158. package/src/components/SegmentedControl/SegmentedControl.tsx +169 -0
  159. package/src/components/SegmentedControl/index.ts +1 -0
  160. package/src/components/Select/Select.module.css +204 -0
  161. package/src/components/Select/Select.tsx +254 -0
  162. package/src/components/Select/index.ts +1 -0
  163. package/src/components/Sheet/Sheet.module.css +228 -0
  164. package/src/components/Sheet/Sheet.tsx +449 -0
  165. package/src/components/Sheet/index.ts +1 -0
  166. package/src/components/Skeleton/Skeleton.module.css +56 -0
  167. package/src/components/Skeleton/Skeleton.tsx +37 -0
  168. package/src/components/Skeleton/index.ts +1 -0
  169. package/src/components/Slider/Slider.module.css +155 -0
  170. package/src/components/Slider/Slider.tsx +200 -0
  171. package/src/components/Slider/index.ts +1 -0
  172. package/src/components/Spinner/Spinner.module.css +50 -0
  173. package/src/components/Spinner/Spinner.tsx +29 -0
  174. package/src/components/Spinner/index.ts +1 -0
  175. package/src/components/Split/Split.module.css +29 -0
  176. package/src/components/Split/Split.tsx +33 -0
  177. package/src/components/Split/index.ts +1 -0
  178. package/src/components/SplitFlap/SplitFlap.module.css +107 -0
  179. package/src/components/SplitFlap/SplitFlap.tsx +225 -0
  180. package/src/components/SplitFlap/index.ts +1 -0
  181. package/src/components/Stack/Stack.module.css +17 -0
  182. package/src/components/Stack/Stack.tsx +19 -0
  183. package/src/components/Stack/index.ts +1 -0
  184. package/src/components/SwipeDeck/SwipeDeck.module.css +250 -0
  185. package/src/components/SwipeDeck/SwipeDeck.tsx +350 -0
  186. package/src/components/SwipeDeck/index.ts +1 -0
  187. package/src/components/Switch/Switch.module.css +97 -0
  188. package/src/components/Switch/Switch.tsx +147 -0
  189. package/src/components/Switch/index.ts +1 -0
  190. package/src/components/Table/Table.module.css +369 -0
  191. package/src/components/Table/Table.tsx +368 -0
  192. package/src/components/Table/index.ts +1 -0
  193. package/src/components/TableOfContents/TableOfContents.module.css +107 -0
  194. package/src/components/TableOfContents/TableOfContents.tsx +93 -0
  195. package/src/components/TableOfContents/index.ts +1 -0
  196. package/src/components/Tabs/Tabs.module.css +101 -0
  197. package/src/components/Tabs/Tabs.tsx +190 -0
  198. package/src/components/Tabs/index.ts +1 -0
  199. package/src/components/Tag/Tag.module.css +120 -0
  200. package/src/components/Tag/Tag.tsx +109 -0
  201. package/src/components/Tag/index.ts +1 -0
  202. package/src/components/Textarea/Textarea.module.css +79 -0
  203. package/src/components/Textarea/Textarea.tsx +130 -0
  204. package/src/components/Textarea/index.ts +1 -0
  205. package/src/components/ThemeToggle/ThemeToggle.module.css +21 -0
  206. package/src/components/ThemeToggle/ThemeToggle.tsx +69 -0
  207. package/src/components/ThemeToggle/index.ts +1 -0
  208. package/src/components/Toast/Toast.module.css +202 -0
  209. package/src/components/Toast/Toast.tsx +473 -0
  210. package/src/components/Toast/index.ts +1 -0
  211. package/src/components/Toggle/Toggle.module.css +94 -0
  212. package/src/components/Toggle/Toggle.tsx +50 -0
  213. package/src/components/Toggle/index.ts +1 -0
  214. package/src/components/Tooltip/Tooltip.module.css +34 -0
  215. package/src/components/Tooltip/Tooltip.tsx +154 -0
  216. package/src/components/Tooltip/index.ts +1 -0
  217. package/src/components/VisuallyHidden/VisuallyHidden.module.css +13 -0
  218. package/src/components/VisuallyHidden/VisuallyHidden.tsx +12 -0
  219. package/src/components/VisuallyHidden/index.ts +1 -0
  220. package/src/internal/FieldMessage.module.css +49 -0
  221. package/src/internal/FieldMessage.tsx +44 -0
  222. package/src/internal/Portal.tsx +7 -0
  223. package/src/internal/Roll.module.css +31 -0
  224. package/src/internal/Roll.tsx +20 -0
  225. package/src/internal/cx.ts +3 -0
  226. package/src/internal/feel.ts +355 -0
  227. package/src/internal/fling.ts +118 -0
  228. package/src/internal/focus.ts +94 -0
  229. package/src/internal/icons.module.css +62 -0
  230. package/src/internal/icons.tsx +511 -0
  231. package/src/internal/keyboard.ts +62 -0
  232. package/src/internal/layers.ts +85 -0
  233. package/src/internal/liquid.ts +248 -0
  234. package/src/internal/liquidMatter.ts +168 -0
  235. package/src/internal/liquidMore.ts +686 -0
  236. package/src/internal/liquidPath.ts +519 -0
  237. package/src/internal/mergeRefs.ts +10 -0
  238. package/src/internal/motion.ts +37 -0
  239. package/src/internal/relativeTime.ts +26 -0
  240. package/src/internal/scrollFrame.ts +157 -0
  241. package/src/internal/softPress.ts +299 -0
  242. package/src/internal/space.ts +6 -0
  243. package/src/internal/useControllable.ts +21 -0
  244. package/src/internal/useFloating.ts +85 -0
  245. package/src/internal/usePresence.ts +15 -0
  246. package/src/internal/useScrub.ts +160 -0
  247. package/src/tokens.css +727 -0
@@ -0,0 +1,449 @@
1
+ 'use client'
2
+
3
+ import { useEffect, useId, useLayoutEffect, useRef, useState, type FocusEvent, type KeyboardEvent, type PointerEvent, type ReactNode, type RefObject } from 'react'
4
+ import { cx } from '../../internal/cx'
5
+ import { release, rubber, speedTracker, useDragClose } from '../../internal/fling'
6
+ import { returnTarget, useFocusTrap } from '../../internal/focus'
7
+ import { XIcon } from '../../internal/icons'
8
+ import { useDismiss, useScrollLock } from '../../internal/layers'
9
+ import { Portal } from '../../internal/Portal'
10
+ import { usePresence } from '../../internal/usePresence'
11
+ import styles from './Sheet.module.css'
12
+
13
+ /** A height a sheet can rest at: low with only its title showing, half the screen, or nearly all of it. */
14
+ export type SheetDetent = 'peek' | 'half' | 'full'
15
+
16
+ export type SheetProps = {
17
+ /** Whether the sheet is open. You always control it. */
18
+ open: boolean
19
+ /** Called when the sheet asks to close, by Esc, outside tap, drag or close button, with false. */
20
+ onOpenChange: (open: boolean) => void
21
+ /** Visible heading, also the dialog's accessible name. */
22
+ title: ReactNode
23
+ /** Text under the title, also read as the dialog's description. */
24
+ description?: ReactNode
25
+ /** Main content of the sheet. */
26
+ children?: ReactNode
27
+ /** Sticky actions at the bottom of the sheet. */
28
+ footer?: ReactNode
29
+ /** Screen reader name for the close button. */
30
+ closeLabel?: string
31
+ /** Element to focus first. Defaults to the first focusable element in the content. */
32
+ initialFocus?: RefObject<HTMLElement | null>
33
+ /** Extra class for the panel. */
34
+ className?: string
35
+ /** Heights the sheet rests at, such as ['peek', 'half', 'full']. Below the highest one it is not modal: the page behind stays usable. */
36
+ detents?: SheetDetent[]
37
+ /** The height it rests at, when you control it. */
38
+ detent?: SheetDetent
39
+ /** The height it opens at when you do not control it. Defaults to the lowest. */
40
+ defaultDetent?: SheetDetent
41
+ /** Called with the new height after a drag, a tap or a key on the grabber, or Esc. */
42
+ onDetentChange?: (detent: SheetDetent) => void
43
+ /** Screen reader name for the grabber, which sets the height. */
44
+ heightLabel?: string
45
+ }
46
+
47
+ type BaseProps = Omit<SheetProps, 'detents' | 'detent' | 'defaultDetent' | 'onDetentChange' | 'heightLabel' | 'closeLabel'> & { closeLabel: string }
48
+
49
+ /** With detents, the grabber becomes a control for the height, and the sheet is modal only at its highest. */
50
+ export function Sheet({
51
+ open,
52
+ onOpenChange,
53
+ title,
54
+ description,
55
+ children,
56
+ footer,
57
+ closeLabel = 'Close',
58
+ initialFocus,
59
+ className,
60
+ detents,
61
+ detent,
62
+ defaultDetent,
63
+ onDetentChange,
64
+ heightLabel = 'Sheet height',
65
+ }: SheetProps) {
66
+ const base = { open, onOpenChange, title, description, children, footer, closeLabel, initialFocus, className }
67
+ if (!detents?.length) return <PlainSheet {...base} />
68
+ return <DetentSheet {...base} detents={detents} detent={detent} defaultDetent={defaultDetent} onDetentChange={onDetentChange} heightLabel={heightLabel} />
69
+ }
70
+
71
+ function PlainSheet({ open, onOpenChange, title, description, children, footer, closeLabel, initialFocus, className }: BaseProps) {
72
+ const id = useId()
73
+ const panelRef = useRef<HTMLDivElement>(null)
74
+ const { mounted, state } = usePresence(open, 'morph-out')
75
+ const grab = useDragClose(panelRef, open, () => onOpenChange(false))
76
+
77
+ useScrollLock(open)
78
+ useDismiss(open, [panelRef], () => onOpenChange(false))
79
+ useFocusTrap(panelRef, open && mounted, { initialFocus })
80
+
81
+ if (!mounted) return null
82
+ return (
83
+ <Portal>
84
+ <div className={styles.overlay} data-state={state} aria-hidden="true" />
85
+ <div
86
+ ref={panelRef}
87
+ role="dialog"
88
+ aria-modal="true"
89
+ aria-labelledby={`${id}-title`}
90
+ aria-describedby={description ? `${id}-desc` : undefined}
91
+ tabIndex={-1}
92
+ className={cx(styles.sheet, className)}
93
+ data-state={state}
94
+ onAnimationEnd={(e) => {
95
+ if (e.target === panelRef.current && state === 'open') panelRef.current.style.transform = ''
96
+ }}
97
+ >
98
+ <div
99
+ className={styles.grab}
100
+ {...grab}
101
+ >
102
+ <span className={styles.handle} aria-hidden="true" />
103
+ <header className={styles.header}>
104
+ <div className={styles.titles}>
105
+ <h2 id={`${id}-title`} className={styles.title}>{title}</h2>
106
+ {description && <p id={`${id}-desc`} className={styles.description}>{description}</p>}
107
+ </div>
108
+ <button type="button" className={styles.close} aria-label={closeLabel} data-skip-initial-focus onClick={() => onOpenChange(false)}>
109
+ <XIcon />
110
+ </button>
111
+ </header>
112
+ </div>
113
+ {children && <div className={styles.body}>{children}</div>}
114
+ {footer && <footer className={styles.footer}>{footer}</footer>}
115
+ </div>
116
+ </Portal>
117
+ )
118
+ }
119
+
120
+ // Shares of the screen, from the heights Apple Maps on the web and Vaul rest at.
121
+ const SHARE: Record<SheetDetent, number> = { peek: 0.19, half: 0.5, full: 0.96 }
122
+ const ORDER: SheetDetent[] = ['peek', 'half', 'full']
123
+ const NAME: Record<SheetDetent, string> = { peek: 'Low', half: 'Half', full: 'Full' }
124
+ // px per second: faster than this, a let-go is a flick and moves one height its way.
125
+ const FLICK = 400
126
+ // How far ahead, in seconds, a slow let-go is carried before the nearest height is picked.
127
+ const PROJECT = 0.2
128
+ // A press is not a drag until it moves this far, so taps on the content still work.
129
+ const SLOP = 6
130
+
131
+ const nearest = (v: number, hs: number[]) => hs.reduce((best, h, i) => (Math.abs(h - v) < Math.abs(hs[best] - v) ? i : best), 0)
132
+
133
+ // A flick moves one height from where the drag began, never two, even when the hand has already
134
+ // passed the next one. Real sheets measured all do this.
135
+ function pick(pos: number, v: number, start: number, hs: number[]) {
136
+ if (Math.abs(v) <= FLICK) return nearest(pos + v * PROJECT, hs)
137
+ return Math.max(0, Math.min(hs.length - 1, start + Math.sign(v)))
138
+ }
139
+
140
+ type DetentProps = BaseProps & Required<Pick<SheetProps, 'detents' | 'heightLabel'>> & Pick<SheetProps, 'detent' | 'defaultDetent' | 'onDetentChange'>
141
+
142
+ function DetentSheet({ open, onOpenChange, title, description, children, footer, closeLabel, initialFocus, className, detents, detent, defaultDetent, onDetentChange, heightLabel }: DetentProps) {
143
+ const id = useId()
144
+ const order = ORDER.filter((d) => detents.includes(d))
145
+ const top = order.length - 1
146
+ const [inner, setInner] = useState<SheetDetent>(defaultDetent ?? order[0])
147
+ const index = Math.max(0, order.indexOf(detent ?? inner))
148
+ const atTop = index === top
149
+ const { mounted, state } = usePresence(open, 'morph-out')
150
+ const [vh, setVh] = useState(() => (typeof window === 'undefined' ? 0 : window.innerHeight))
151
+ const heights = order.map((d) => Math.round(vh * SHARE[d]))
152
+ const [dragging, setDragging] = useState(false)
153
+ const [target, setTarget] = useState(index)
154
+ const [said, setSaid] = useState('')
155
+
156
+ const panelRef = useRef<HTMLDivElement>(null)
157
+ const overlayRef = useRef<HTMLDivElement>(null)
158
+ const grabRef = useRef<HTMLDivElement>(null)
159
+ const bodyRef = useRef<HTMLDivElement>(null)
160
+ const at = useRef(0)
161
+ const aimed = useRef(-1)
162
+ const stopGlide = useRef(() => {})
163
+ const unlisten = useRef(() => {})
164
+ const opener = useRef<HTMLElement | null>(null)
165
+ const trapStart = useRef<HTMLElement | null>(null)
166
+ const drag = useRef<{ y0: number; at0: number; start: number; pointer: number; live: boolean; speed: ReturnType<typeof speedTracker> } | null>(null)
167
+ const live = useRef({ heights, index, open })
168
+ live.current = { heights, index, open }
169
+
170
+ const change = (i: number) => {
171
+ if (detent === undefined) setInner(order[i])
172
+ onDetentChange?.(order[i])
173
+ }
174
+
175
+ const paint = (v: number) => {
176
+ at.current = v
177
+ const hs = live.current.heights
178
+ const panel = panelRef.current
179
+ if (!panel) return
180
+ panel.style.transform = `translateY(${hs[hs.length - 1] - v}px)`
181
+ // The dim follows the height between the two highest, so it never jumps.
182
+ const lo = hs.length > 1 ? hs[hs.length - 2] : 0
183
+ const dim = Math.max(0, Math.min(1, (v - lo) / (hs[hs.length - 1] - lo || 1)))
184
+ overlayRef.current?.style.setProperty('opacity', String(dim))
185
+ }
186
+
187
+ const settle = (to: number, v: number, done?: () => void) => {
188
+ stopGlide.current()
189
+ stopGlide.current = release(at.current, to, v, paint, done)
190
+ }
191
+
192
+ const shownHidden = () => {
193
+ const active = document.activeElement as HTMLElement | null
194
+ return !!active && !!bodyRef.current?.contains(active) && active.getBoundingClientRect().top > window.innerHeight - 8
195
+ }
196
+
197
+ const go = (i: number, v = 0, spoken = true) => {
198
+ const hs = live.current.heights
199
+ if (i < 0) {
200
+ // A glide carries it off at the hand's speed, so the CSS close stays out of the way.
201
+ panelRef.current?.setAttribute('data-fluid', '')
202
+ settle(0, v)
203
+ onOpenChange(false)
204
+ requestAnimationFrame(() => {
205
+ if (live.current.open) {
206
+ panelRef.current?.removeAttribute('data-fluid')
207
+ settle(hs[live.current.index], 0)
208
+ }
209
+ })
210
+ return
211
+ }
212
+ aimed.current = i
213
+ setTarget(i)
214
+ if (i !== live.current.index) {
215
+ change(i)
216
+ if (spoken) setSaid(`${NAME[order[i]]} height`)
217
+ }
218
+ // Shrunk below a focused control: focus goes to the grabber, so it never sits on something hidden.
219
+ settle(hs[i], v, () => shownHidden() && grabRef.current?.focus({ preventScroll: true }))
220
+ }
221
+
222
+ const stepDown = () => (live.current.index > 0 ? go(live.current.index - 1) : onOpenChange(false))
223
+
224
+ useEffect(() => {
225
+ const onResize = () => setVh(window.innerHeight)
226
+ window.addEventListener('resize', onResize)
227
+ return () => window.removeEventListener('resize', onResize)
228
+ }, [])
229
+
230
+ useLayoutEffect(() => {
231
+ if (!open) return
232
+ opener.current = returnTarget()
233
+ aimed.current = -1
234
+ }, [open])
235
+
236
+ useLayoutEffect(() => {
237
+ if (!open || !mounted) return
238
+ if (aimed.current === -1) {
239
+ aimed.current = index
240
+ setTarget(index)
241
+ paint(heights[index])
242
+ if (!atTop) (initialFocus?.current ?? grabRef.current)?.focus({ preventScroll: true })
243
+ return
244
+ }
245
+ if (drag.current?.live) return
246
+ if (aimed.current !== index) {
247
+ aimed.current = index
248
+ setTarget(index)
249
+ settle(heights[index], 0)
250
+ } else paint(heights[index])
251
+ }, [open, mounted, index, vh])
252
+
253
+ // Closed, it gives focus back to its opener, and opens next time at the default height.
254
+ useEffect(() => {
255
+ if (open) return
256
+ setInner(defaultDetent ?? order[0])
257
+ const panel = panelRef.current
258
+ const active = document.activeElement
259
+ if (panel && opener.current?.isConnected && (!active || active === document.body || panel.contains(active))) opener.current.focus({ preventScroll: true })
260
+ }, [open])
261
+
262
+ useEffect(() => () => stopGlide.current(), [])
263
+
264
+ // Before the trap's own effect: at the top, focus stays where it is in the sheet.
265
+ useLayoutEffect(() => {
266
+ if (!atTop || !open) return
267
+ const active = document.activeElement as HTMLElement | null
268
+ trapStart.current = active && panelRef.current?.contains(active) ? active : (initialFocus?.current ?? null)
269
+ }, [atTop, open])
270
+ useScrollLock(open && atTop)
271
+ useFocusTrap(panelRef, open && mounted && atTop, { initialFocus: trapStart, restore: false })
272
+ useDismiss(open, [panelRef], stepDown, { outside: atTop })
273
+
274
+ const onPointerMove = (e: globalThis.PointerEvent) => {
275
+ const d = drag.current
276
+ const hs = live.current.heights
277
+ if (!d || d.pointer !== e.pointerId) return
278
+ const dy = d.y0 - e.clientY
279
+ if (!d.live) {
280
+ if (Math.abs(dy) < SLOP) return
281
+ if (bodyRef.current?.contains(e.target as Node) && live.current.index === top && dy > 0) return endDrag()
282
+ // A tap must not stop a settle half way, so the glide is caught only once it is a drag.
283
+ stopGlide.current()
284
+ d.live = true
285
+ d.at0 = at.current
286
+ d.start = nearest(at.current, hs)
287
+ d.speed.add(at.current)
288
+ d.y0 = e.clientY + (dy > 0 ? SLOP : -SLOP)
289
+ // Only now, so a tap on a button inside still clicks it.
290
+ if (e.target instanceof Element && panelRef.current?.contains(e.target)) panelRef.current.setPointerCapture?.(e.pointerId)
291
+ window.addEventListener('selectstart', block)
292
+ setDragging(true)
293
+ }
294
+ // A drag moves the sheet, never selects the page's text: a selection left over from one drag
295
+ // would turn the next press on it into the browser's own drag, which cancels the pointer. Safari
296
+ // keeps growing the selection it began on the press, so it is cleared on every move.
297
+ const selection = window.getSelection()
298
+ if (selection && !selection.isCollapsed) selection.removeAllRanges()
299
+ let raw = d.at0 + (d.y0 - e.clientY)
300
+ const full = hs[hs.length - 1]
301
+ if (raw > full) raw = full + rubber(raw - full, window.innerHeight - full)
302
+ if (raw < 0) raw = 0
303
+ d.speed.add(raw)
304
+ paint(raw)
305
+ const next = pick(raw, d.speed.speed(), d.start, hs)
306
+ setTarget((t) => (t === next ? t : next))
307
+ }
308
+
309
+ const onPointerUp = (e: globalThis.PointerEvent) => {
310
+ const d = drag.current
311
+ if (!d || d.pointer !== e.pointerId) return
312
+ endDrag()
313
+ if (!d.live) return
314
+ setDragging(false)
315
+ const hs = live.current.heights
316
+ const cancelled = e.type === 'pointercancel'
317
+ const v = cancelled ? 0 : d.speed.speed()
318
+ const pos = at.current
319
+ if (!cancelled && d.start === 0 && (v < -FLICK || pos < hs[0] * 0.5)) return go(-1, v)
320
+ go(pick(pos, v, d.start, hs), v)
321
+ }
322
+
323
+ // The hand often leaves the sheet before the drag counts as one, so the moves are followed on the window.
324
+ const block = (e: Event) => e.preventDefault()
325
+
326
+ const endDrag = () => {
327
+ drag.current = null
328
+ unlisten.current()
329
+ }
330
+
331
+ const onPointerDown = (e: PointerEvent<HTMLDivElement>) => {
332
+ if ((e.pointerType === 'mouse' && e.button !== 0) || drag.current) return
333
+ const el = e.target as Element
334
+ if (el.closest('input, textarea, select, [contenteditable="true"]')) return
335
+ const hs = live.current.heights
336
+ // At the top the content scrolls; a drag on it moves the sheet only from the top of the content.
337
+ if (bodyRef.current?.contains(el) && live.current.index === top && (bodyRef.current?.scrollTop ?? 0) > 0) return
338
+ drag.current = { y0: e.clientY, at0: at.current, start: nearest(at.current, hs), pointer: e.pointerId, live: false, speed: speedTracker() }
339
+ const move = onPointerMove
340
+ const up = onPointerUp
341
+ window.addEventListener('pointermove', move)
342
+ window.addEventListener('pointerup', up)
343
+ window.addEventListener('pointercancel', up)
344
+ window.addEventListener('dragstart', block)
345
+ // Safari starts a text selection on the press itself, so a press outside the content (the grabber,
346
+ // the edges) blocks it at once. Text in the content can still be selected by dragging inside it.
347
+ if (!bodyRef.current?.contains(el)) window.addEventListener('selectstart', block)
348
+ unlisten.current = () => {
349
+ window.removeEventListener('pointermove', move)
350
+ window.removeEventListener('pointerup', up)
351
+ window.removeEventListener('pointercancel', up)
352
+ window.removeEventListener('dragstart', block)
353
+ window.removeEventListener('selectstart', block)
354
+ }
355
+ }
356
+
357
+ useEffect(() => () => unlisten.current(), [])
358
+
359
+ // A touch at the top of the content, moving down, belongs to the sheet: the browser would scroll it.
360
+ useEffect(() => {
361
+ const body = bodyRef.current
362
+ if (!body) return
363
+ let y = 0
364
+ const start = (e: TouchEvent) => (y = e.touches[0].clientY)
365
+ const move = (e: TouchEvent) => {
366
+ if (drag.current?.live || (live.current.index === live.current.heights.length - 1 && body.scrollTop <= 0 && e.touches[0].clientY > y)) e.preventDefault()
367
+ }
368
+ body.addEventListener('touchstart', start, { passive: true })
369
+ body.addEventListener('touchmove', move, { passive: false })
370
+ return () => {
371
+ body.removeEventListener('touchstart', start)
372
+ body.removeEventListener('touchmove', move)
373
+ }
374
+ }, [mounted])
375
+
376
+ const onGrabKey = (e: KeyboardEvent<HTMLDivElement>) => {
377
+ const i = live.current.index
378
+ if (e.key === 'Enter' || e.key === ' ') {
379
+ e.preventDefault()
380
+ return go(i === top ? 0 : i + 1, 0, false)
381
+ }
382
+ const keys: Record<string, number> = { ArrowUp: i + 1, ArrowRight: i + 1, ArrowDown: i - 1, ArrowLeft: i - 1, Home: 0, End: top, PageUp: top, PageDown: 0 }
383
+ if (!(e.key in keys)) return
384
+ e.preventDefault()
385
+ go(Math.max(0, Math.min(top, keys[e.key])), 0, false)
386
+ }
387
+
388
+ // Tabbing onto a control hidden below the screen's edge grows the sheet to the top, so it shows.
389
+ const onFocus = (e: FocusEvent<HTMLDivElement>) => {
390
+ if (!bodyRef.current?.contains(e.target) || live.current.index === top) return
391
+ if (e.target.getBoundingClientRect().bottom > window.innerHeight - 4) go(top)
392
+ }
393
+
394
+ if (!mounted) return null
395
+ const shown = order[dragging ? target : index]
396
+ return (
397
+ <Portal>
398
+ <div ref={overlayRef} className={styles.overlay} data-state={state} data-detents data-top={atTop || undefined} aria-hidden="true" />
399
+ <div
400
+ ref={panelRef}
401
+ role="dialog"
402
+ aria-modal={atTop || undefined}
403
+ aria-labelledby={`${id}-title`}
404
+ aria-describedby={description ? `${id}-desc` : undefined}
405
+ tabIndex={-1}
406
+ id={`${id}-sheet`}
407
+ className={cx(styles.sheet, className)}
408
+ data-state={state}
409
+ data-detents
410
+ data-top={atTop || undefined}
411
+ data-dragging={dragging || undefined}
412
+ style={{ height: heights[top] }}
413
+ onPointerDown={onPointerDown}
414
+ onFocus={onFocus}
415
+ >
416
+ <div
417
+ ref={grabRef}
418
+ className={styles.grabber}
419
+ role="slider"
420
+ tabIndex={0}
421
+ aria-label={heightLabel}
422
+ aria-orientation="vertical"
423
+ aria-valuemin={0}
424
+ aria-valuemax={top}
425
+ aria-valuenow={index}
426
+ aria-valuetext={NAME[order[index]]}
427
+ aria-controls={`${id}-sheet`}
428
+ data-detent={shown}
429
+ onKeyDown={onGrabKey}
430
+ onClick={() => go(index === top ? 0 : index + 1)}
431
+ >
432
+ <span className={styles.pill} />
433
+ </div>
434
+ <header className={styles.header}>
435
+ <div className={styles.titles}>
436
+ <h2 id={`${id}-title`} className={styles.title}>{title}</h2>
437
+ {description && <p id={`${id}-desc`} className={styles.description}>{description}</p>}
438
+ </div>
439
+ <button type="button" className={styles.close} aria-label={closeLabel} data-skip-initial-focus onClick={() => onOpenChange(false)}>
440
+ <XIcon />
441
+ </button>
442
+ </header>
443
+ {children && <div ref={bodyRef} className={styles.body}>{children}</div>}
444
+ {footer && <footer className={styles.footer}>{footer}</footer>}
445
+ <p className={styles.srOnly} aria-live="polite">{said}</p>
446
+ </div>
447
+ </Portal>
448
+ )
449
+ }
@@ -0,0 +1 @@
1
+ export * from './Sheet'
@@ -0,0 +1,56 @@
1
+ .lines {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: var(--gooee-space-3);
5
+ }
6
+
7
+ .bone {
8
+ position: relative;
9
+ display: block;
10
+ overflow: hidden;
11
+ background: var(--gooee-color-surface-active);
12
+ border-radius: var(--gooee-radius-sm);
13
+ }
14
+
15
+ .bone::after {
16
+ content: "";
17
+ position: absolute;
18
+ inset: 0;
19
+ transform: translateX(-100%);
20
+ background: linear-gradient(90deg, transparent, var(--gooee-color-shimmer), transparent);
21
+ animation: shimmer var(--gooee-motion-shimmer) var(--gooee-ease-in-out) infinite;
22
+ animation-delay: calc(var(--i, 0) * var(--gooee-motion-stagger) * 3);
23
+ }
24
+
25
+ .text { height: 0.8em; border-radius: var(--gooee-radius-xs); }
26
+ .rect { width: 100%; height: var(--gooee-skeleton-block); border-radius: var(--gooee-radius-md); }
27
+ .circle { width: var(--gooee-skeleton-avatar); height: var(--gooee-skeleton-avatar); border-radius: var(--gooee-radius-full); }
28
+
29
+ /* A sketch: the shapes as dashed pencil outlines, no fill. Text becomes dashed baselines. The lines
30
+ themselves fade gently instead of a shimmer, which would light up the empty box behind them. */
31
+ .sketch {
32
+ background: none;
33
+ border: var(--gooee-line) dashed var(--gooee-color-border-strong);
34
+ animation: sketching var(--gooee-motion-shimmer) var(--gooee-ease-in-out) infinite alternate;
35
+ animation-delay: calc(var(--i, 0) * var(--gooee-motion-stagger) * 3);
36
+ }
37
+
38
+ .sketch::after { display: none; }
39
+
40
+ .sketch.text {
41
+ border-width: 0 0 var(--gooee-line);
42
+ border-radius: 0;
43
+ }
44
+
45
+ @keyframes sketching {
46
+ from { border-color: var(--gooee-color-border); }
47
+ }
48
+
49
+ @keyframes shimmer {
50
+ to { transform: translateX(100%); }
51
+ }
52
+
53
+ @media (prefers-reduced-motion: reduce) {
54
+ .bone::after { animation: none; display: none; }
55
+ .sketch { animation: none; }
56
+ }
@@ -0,0 +1,37 @@
1
+ import type { CSSProperties } from 'react'
2
+ import { cx } from '../../internal/cx'
3
+ import styles from './Skeleton.module.css'
4
+
5
+ export type SkeletonProps = {
6
+ /** Text draws lines, rect a box, circle a round shape such as an avatar. */
7
+ shape?: 'text' | 'rect' | 'circle'
8
+ /** Any CSS width, such as 120 or "50%". */
9
+ width?: CSSProperties['width']
10
+ /** Any CSS height. Ignored for text, where lines set the height. */
11
+ height?: CSSProperties['height']
12
+ /** For text: number of lines. The last one is shorter, like real text. */
13
+ lines?: number
14
+ /** Solid grey shapes, or a sketch: the same shapes as dashed outlines, like a pencil layout. */
15
+ variant?: 'solid' | 'sketch'
16
+ /** Extra class for the root element. */
17
+ className?: string
18
+ }
19
+
20
+ // Decorative only. Mark the loading container with aria-busy and a label instead.
21
+ export function Skeleton({ shape = 'rect', width, height, lines = 1, variant = 'solid', className }: SkeletonProps) {
22
+ const look = variant === 'sketch' && styles.sketch
23
+ if (shape === 'text') {
24
+ return (
25
+ <span className={cx(styles.lines, className)} style={{ width }} aria-hidden="true">
26
+ {Array.from({ length: lines }, (_, i) => (
27
+ <span
28
+ key={i}
29
+ className={cx(styles.bone, styles.text, look)}
30
+ style={{ width: lines > 1 && i === lines - 1 ? '62%' : '100%', ['--i' as string]: i }}
31
+ />
32
+ ))}
33
+ </span>
34
+ )
35
+ }
36
+ return <span className={cx(styles.bone, styles[shape], look, className)} style={{ width, height }} aria-hidden="true" />
37
+ }
@@ -0,0 +1 @@
1
+ export * from './Skeleton'