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.
- package/LICENSE +21 -0
- package/README.md +99 -2
- package/package.json +36 -4
- package/scripts/add.js +533 -0
- package/scripts/pro-components.json +82 -0
- package/src/base.css +39 -0
- package/src/components/Accordion/Accordion.module.css +90 -0
- package/src/components/Accordion/Accordion.tsx +125 -0
- package/src/components/Accordion/index.ts +1 -0
- package/src/components/Alert/Alert.module.css +121 -0
- package/src/components/Alert/Alert.tsx +90 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/AlertDialog/AlertDialog.module.css +2 -0
- package/src/components/AlertDialog/AlertDialog.tsx +108 -0
- package/src/components/AlertDialog/index.ts +1 -0
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +48 -0
- package/src/components/AnimatedNumber/AnimatedNumber.tsx +52 -0
- package/src/components/AnimatedNumber/index.ts +1 -0
- package/src/components/AspectRatio/AspectRatio.module.css +15 -0
- package/src/components/AspectRatio/AspectRatio.tsx +12 -0
- package/src/components/AspectRatio/index.ts +1 -0
- package/src/components/Avatar/Avatar.module.css +62 -0
- package/src/components/Avatar/Avatar.tsx +55 -0
- package/src/components/Avatar/index.ts +3 -0
- package/src/components/AvatarGroup/AvatarGroup.module.css +53 -0
- package/src/components/AvatarGroup/AvatarGroup.tsx +43 -0
- package/src/components/AvatarGroup/index.ts +1 -0
- package/src/components/Badge/Badge.module.css +69 -0
- package/src/components/Badge/Badge.tsx +25 -0
- package/src/components/Badge/index.ts +1 -0
- package/src/components/Breadcrumb/Breadcrumb.module.css +104 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +76 -0
- package/src/components/Breadcrumb/index.ts +1 -0
- package/src/components/Button/Button.module.css +191 -0
- package/src/components/Button/Button.tsx +148 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/ButtonGroup/ButtonGroup.module.css +59 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +45 -0
- package/src/components/ButtonGroup/index.ts +1 -0
- package/src/components/Card/Card.module.css +82 -0
- package/src/components/Card/Card.tsx +34 -0
- package/src/components/Card/index.ts +1 -0
- package/src/components/Center/Center.module.css +15 -0
- package/src/components/Center/Center.tsx +28 -0
- package/src/components/Center/index.ts +1 -0
- package/src/components/Checkbox/Checkbox.module.css +120 -0
- package/src/components/Checkbox/Checkbox.tsx +133 -0
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/CheckboxGroup/CheckboxGroup.module.css +30 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +88 -0
- package/src/components/CheckboxGroup/index.ts +1 -0
- package/src/components/Cluster/Cluster.module.css +25 -0
- package/src/components/Cluster/Cluster.tsx +26 -0
- package/src/components/Cluster/index.ts +1 -0
- package/src/components/CodeBlock/CodeBlock.module.css +74 -0
- package/src/components/CodeBlock/CodeBlock.tsx +53 -0
- package/src/components/CodeBlock/highlight.ts +73 -0
- package/src/components/CodeBlock/index.ts +1 -0
- package/src/components/Collapsible/Collapsible.module.css +75 -0
- package/src/components/Collapsible/Collapsible.tsx +71 -0
- package/src/components/Collapsible/index.ts +1 -0
- package/src/components/Container/Container.module.css +14 -0
- package/src/components/Container/Container.tsx +19 -0
- package/src/components/Container/index.ts +1 -0
- package/src/components/CopyButton/CopyButton.module.css +125 -0
- package/src/components/CopyButton/CopyButton.tsx +160 -0
- package/src/components/CopyButton/index.ts +1 -0
- package/src/components/Dial/Dial.module.css +344 -0
- package/src/components/Dial/Dial.tsx +332 -0
- package/src/components/Dial/index.ts +1 -0
- package/src/components/Dialog/Dialog.module.css +190 -0
- package/src/components/Dialog/Dialog.tsx +100 -0
- package/src/components/Dialog/index.ts +1 -0
- package/src/components/Divider/Divider.module.css +39 -0
- package/src/components/Divider/Divider.tsx +34 -0
- package/src/components/Divider/index.ts +1 -0
- package/src/components/DropdownMenu/DropdownMenu.module.css +134 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +215 -0
- package/src/components/DropdownMenu/index.ts +1 -0
- package/src/components/EmptyState/EmptyState.module.css +66 -0
- package/src/components/EmptyState/EmptyState.tsx +38 -0
- package/src/components/EmptyState/index.ts +1 -0
- package/src/components/Fab/Fab.module.css +176 -0
- package/src/components/Fab/Fab.tsx +117 -0
- package/src/components/Fab/index.ts +1 -0
- package/src/components/Fieldset/Fieldset.module.css +34 -0
- package/src/components/Fieldset/Fieldset.tsx +41 -0
- package/src/components/Fieldset/index.ts +1 -0
- package/src/components/FormField/FormField.module.css +62 -0
- package/src/components/FormField/FormField.tsx +91 -0
- package/src/components/FormField/index.ts +2 -0
- package/src/components/Grid/Grid.module.css +39 -0
- package/src/components/Grid/Grid.tsx +35 -0
- package/src/components/Grid/index.ts +1 -0
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +175 -0
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +334 -0
- package/src/components/HoldToConfirm/index.ts +1 -0
- package/src/components/IconButton/IconButton.module.css +78 -0
- package/src/components/IconButton/IconButton.tsx +35 -0
- package/src/components/IconButton/index.ts +1 -0
- package/src/components/Input/Input.module.css +157 -0
- package/src/components/Input/Input.tsx +133 -0
- package/src/components/Input/index.ts +1 -0
- package/src/components/InputGroup/InputGroup.module.css +146 -0
- package/src/components/InputGroup/InputGroup.tsx +90 -0
- package/src/components/InputGroup/index.ts +1 -0
- package/src/components/Kbd/Kbd.module.css +28 -0
- package/src/components/Kbd/Kbd.tsx +38 -0
- package/src/components/Kbd/index.ts +1 -0
- package/src/components/Link/Link.module.css +65 -0
- package/src/components/Link/Link.tsx +41 -0
- package/src/components/Link/index.ts +1 -0
- package/src/components/LivePill/LivePill.module.css +207 -0
- package/src/components/LivePill/LivePill.tsx +182 -0
- package/src/components/LivePill/index.ts +1 -0
- package/src/components/Meter/Meter.module.css +91 -0
- package/src/components/Meter/Meter.tsx +109 -0
- package/src/components/Meter/index.ts +1 -0
- package/src/components/MorphButton/MorphButton.module.css +152 -0
- package/src/components/MorphButton/MorphButton.tsx +203 -0
- package/src/components/MorphButton/index.ts +1 -0
- package/src/components/NumberInput/NumberInput.module.css +104 -0
- package/src/components/NumberInput/NumberInput.tsx +252 -0
- package/src/components/NumberInput/index.ts +2 -0
- package/src/components/Pagination/Pagination.module.css +88 -0
- package/src/components/Pagination/Pagination.tsx +126 -0
- package/src/components/Pagination/index.ts +1 -0
- package/src/components/PasswordInput/PasswordInput.module.css +64 -0
- package/src/components/PasswordInput/PasswordInput.tsx +63 -0
- package/src/components/PasswordInput/index.ts +2 -0
- package/src/components/PickerWheel/PickerWheel.module.css +123 -0
- package/src/components/PickerWheel/PickerWheel.tsx +326 -0
- package/src/components/PickerWheel/index.ts +1 -0
- package/src/components/Popover/Popover.module.css +78 -0
- package/src/components/Popover/Popover.tsx +117 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/ProgressBar/ProgressBar.module.css +61 -0
- package/src/components/ProgressBar/ProgressBar.tsx +48 -0
- package/src/components/ProgressBar/index.ts +1 -0
- package/src/components/Prose/Prose.module.css +115 -0
- package/src/components/Prose/Prose.tsx +14 -0
- package/src/components/Prose/index.ts +1 -0
- package/src/components/Radio/Radio.module.css +106 -0
- package/src/components/Radio/Radio.tsx +115 -0
- package/src/components/Radio/index.ts +1 -0
- package/src/components/Retime/Retime.tsx +116 -0
- package/src/components/Retime/index.ts +1 -0
- package/src/components/RulerScrubber/RulerScrubber.module.css +146 -0
- package/src/components/RulerScrubber/RulerScrubber.tsx +209 -0
- package/src/components/RulerScrubber/index.ts +1 -0
- package/src/components/ScrollArea/ScrollArea.module.css +72 -0
- package/src/components/ScrollArea/ScrollArea.tsx +172 -0
- package/src/components/ScrollArea/index.ts +1 -0
- package/src/components/SearchInput/SearchInput.module.css +53 -0
- package/src/components/SearchInput/SearchInput.tsx +104 -0
- package/src/components/SearchInput/index.ts +2 -0
- package/src/components/SegmentedControl/SegmentedControl.module.css +150 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +169 -0
- package/src/components/SegmentedControl/index.ts +1 -0
- package/src/components/Select/Select.module.css +204 -0
- package/src/components/Select/Select.tsx +254 -0
- package/src/components/Select/index.ts +1 -0
- package/src/components/Sheet/Sheet.module.css +228 -0
- package/src/components/Sheet/Sheet.tsx +449 -0
- package/src/components/Sheet/index.ts +1 -0
- package/src/components/Skeleton/Skeleton.module.css +56 -0
- package/src/components/Skeleton/Skeleton.tsx +37 -0
- package/src/components/Skeleton/index.ts +1 -0
- package/src/components/Slider/Slider.module.css +155 -0
- package/src/components/Slider/Slider.tsx +200 -0
- package/src/components/Slider/index.ts +1 -0
- package/src/components/Spinner/Spinner.module.css +50 -0
- package/src/components/Spinner/Spinner.tsx +29 -0
- package/src/components/Spinner/index.ts +1 -0
- package/src/components/Split/Split.module.css +29 -0
- package/src/components/Split/Split.tsx +33 -0
- package/src/components/Split/index.ts +1 -0
- package/src/components/SplitFlap/SplitFlap.module.css +107 -0
- package/src/components/SplitFlap/SplitFlap.tsx +225 -0
- package/src/components/SplitFlap/index.ts +1 -0
- package/src/components/Stack/Stack.module.css +17 -0
- package/src/components/Stack/Stack.tsx +19 -0
- package/src/components/Stack/index.ts +1 -0
- package/src/components/SwipeDeck/SwipeDeck.module.css +250 -0
- package/src/components/SwipeDeck/SwipeDeck.tsx +350 -0
- package/src/components/SwipeDeck/index.ts +1 -0
- package/src/components/Switch/Switch.module.css +97 -0
- package/src/components/Switch/Switch.tsx +147 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Table/Table.module.css +369 -0
- package/src/components/Table/Table.tsx +368 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/TableOfContents/TableOfContents.module.css +107 -0
- package/src/components/TableOfContents/TableOfContents.tsx +93 -0
- package/src/components/TableOfContents/index.ts +1 -0
- package/src/components/Tabs/Tabs.module.css +101 -0
- package/src/components/Tabs/Tabs.tsx +190 -0
- package/src/components/Tabs/index.ts +1 -0
- package/src/components/Tag/Tag.module.css +120 -0
- package/src/components/Tag/Tag.tsx +109 -0
- package/src/components/Tag/index.ts +1 -0
- package/src/components/Textarea/Textarea.module.css +79 -0
- package/src/components/Textarea/Textarea.tsx +130 -0
- package/src/components/Textarea/index.ts +1 -0
- package/src/components/ThemeToggle/ThemeToggle.module.css +21 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +69 -0
- package/src/components/ThemeToggle/index.ts +1 -0
- package/src/components/Toast/Toast.module.css +202 -0
- package/src/components/Toast/Toast.tsx +473 -0
- package/src/components/Toast/index.ts +1 -0
- package/src/components/Toggle/Toggle.module.css +94 -0
- package/src/components/Toggle/Toggle.tsx +50 -0
- package/src/components/Toggle/index.ts +1 -0
- package/src/components/Tooltip/Tooltip.module.css +34 -0
- package/src/components/Tooltip/Tooltip.tsx +154 -0
- package/src/components/Tooltip/index.ts +1 -0
- package/src/components/VisuallyHidden/VisuallyHidden.module.css +13 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +12 -0
- package/src/components/VisuallyHidden/index.ts +1 -0
- package/src/internal/FieldMessage.module.css +49 -0
- package/src/internal/FieldMessage.tsx +44 -0
- package/src/internal/Portal.tsx +7 -0
- package/src/internal/Roll.module.css +31 -0
- package/src/internal/Roll.tsx +20 -0
- package/src/internal/cx.ts +3 -0
- package/src/internal/feel.ts +355 -0
- package/src/internal/fling.ts +118 -0
- package/src/internal/focus.ts +94 -0
- package/src/internal/icons.module.css +62 -0
- package/src/internal/icons.tsx +511 -0
- package/src/internal/keyboard.ts +62 -0
- package/src/internal/layers.ts +85 -0
- package/src/internal/liquid.ts +248 -0
- package/src/internal/liquidMatter.ts +168 -0
- package/src/internal/liquidMore.ts +686 -0
- package/src/internal/liquidPath.ts +519 -0
- package/src/internal/mergeRefs.ts +10 -0
- package/src/internal/motion.ts +37 -0
- package/src/internal/relativeTime.ts +26 -0
- package/src/internal/scrollFrame.ts +157 -0
- package/src/internal/softPress.ts +299 -0
- package/src/internal/space.ts +6 -0
- package/src/internal/useControllable.ts +21 -0
- package/src/internal/useFloating.ts +85 -0
- package/src/internal/usePresence.ts +15 -0
- package/src/internal/useScrub.ts +160 -0
- package/src/tokens.css +727 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
border-top: var(--gooee-line) solid var(--gooee-color-border);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.item {
|
|
8
|
+
border-bottom: var(--gooee-line) solid var(--gooee-color-border);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.heading {
|
|
12
|
+
margin: 0;
|
|
13
|
+
font-size: inherit;
|
|
14
|
+
font-weight: inherit;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.trigger {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: space-between;
|
|
21
|
+
gap: var(--gooee-space-5);
|
|
22
|
+
width: 100%;
|
|
23
|
+
min-height: var(--gooee-hit-min);
|
|
24
|
+
padding: var(--gooee-space-5) var(--gooee-space-2);
|
|
25
|
+
border: 0;
|
|
26
|
+
border-radius: var(--gooee-radius-sm);
|
|
27
|
+
background: transparent;
|
|
28
|
+
/* Without a colour, iPhone Safari draws button text in its own blue. */
|
|
29
|
+
color: var(--gooee-color-fg);
|
|
30
|
+
font-family: inherit;
|
|
31
|
+
font-size: var(--gooee-text-md);
|
|
32
|
+
font-weight: var(--gooee-weight-medium);
|
|
33
|
+
text-align: left;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
transition: background-color var(--gooee-motion-fast) var(--gooee-ease-out);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@media (hover: hover) {
|
|
39
|
+
.trigger:hover:not(:disabled) { background: var(--gooee-color-surface-hover); }
|
|
40
|
+
}
|
|
41
|
+
.trigger:disabled { opacity: var(--gooee-disabled-opacity); cursor: not-allowed; }
|
|
42
|
+
|
|
43
|
+
.trigger:focus-visible {
|
|
44
|
+
outline: none;
|
|
45
|
+
box-shadow: inset 0 0 0 var(--gooee-line-focus) var(--gooee-color-fg);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.title {
|
|
49
|
+
min-width: 0;
|
|
50
|
+
overflow-wrap: anywhere;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.chevron {
|
|
54
|
+
flex: none;
|
|
55
|
+
width: var(--gooee-icon-md);
|
|
56
|
+
height: var(--gooee-icon-md);
|
|
57
|
+
color: var(--gooee-color-fg-muted);
|
|
58
|
+
transition: transform var(--gooee-motion-slow) var(--gooee-ease-spring);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.item[data-open] .chevron { transform: rotate(180deg); }
|
|
62
|
+
|
|
63
|
+
/* Height animates with grid rows from 0fr to 1fr, so no JS measuring is needed. */
|
|
64
|
+
.panel {
|
|
65
|
+
display: grid;
|
|
66
|
+
grid-template-rows: 0fr;
|
|
67
|
+
visibility: hidden;
|
|
68
|
+
transition:
|
|
69
|
+
grid-template-rows var(--gooee-motion-morph) var(--gooee-ease-morph),
|
|
70
|
+
visibility 0s linear var(--gooee-motion-morph);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.item[data-open] .panel {
|
|
74
|
+
grid-template-rows: 1fr;
|
|
75
|
+
visibility: visible;
|
|
76
|
+
transition:
|
|
77
|
+
grid-template-rows var(--gooee-motion-morph) var(--gooee-ease-morph),
|
|
78
|
+
visibility 0s;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.panelInner {
|
|
82
|
+
min-height: 0;
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.content {
|
|
87
|
+
padding: 0 var(--gooee-space-2) var(--gooee-space-6);
|
|
88
|
+
color: var(--gooee-color-fg-muted);
|
|
89
|
+
line-height: var(--gooee-leading-normal);
|
|
90
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, useId, useRef, type KeyboardEvent, type ReactNode } from 'react'
|
|
4
|
+
import { cx } from '../../internal/cx'
|
|
5
|
+
import { ChevronDownIcon } from '../../internal/icons'
|
|
6
|
+
import { useControllable } from '../../internal/useControllable'
|
|
7
|
+
import styles from './Accordion.module.css'
|
|
8
|
+
|
|
9
|
+
type Ctx = { open: string[]; toggle: (v: string) => void }
|
|
10
|
+
const AccCtx = createContext<Ctx | null>(null)
|
|
11
|
+
|
|
12
|
+
export type AccordionProps = {
|
|
13
|
+
/** "single" keeps one item open at a time. */
|
|
14
|
+
type?: 'single' | 'multiple'
|
|
15
|
+
/** Values of the open items, when you control it. */
|
|
16
|
+
value?: string[]
|
|
17
|
+
/** Starting open items when you do not control it. */
|
|
18
|
+
defaultValue?: string[]
|
|
19
|
+
/** Called when the open items change, with the new list of values. */
|
|
20
|
+
onValueChange?: (value: string[]) => void
|
|
21
|
+
/** Heading level for item titles, to fit the page outline. */
|
|
22
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6
|
|
23
|
+
/** Extra class for the root element. */
|
|
24
|
+
className?: string
|
|
25
|
+
/** The AccordionItem elements. */
|
|
26
|
+
children: ReactNode
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const LevelCtx = createContext<number>(3)
|
|
30
|
+
|
|
31
|
+
export function Accordion({
|
|
32
|
+
type = 'single',
|
|
33
|
+
value,
|
|
34
|
+
defaultValue = [],
|
|
35
|
+
onValueChange,
|
|
36
|
+
headingLevel = 3,
|
|
37
|
+
className,
|
|
38
|
+
children,
|
|
39
|
+
}: AccordionProps) {
|
|
40
|
+
const [open, setOpen] = useControllable(value, defaultValue, onValueChange)
|
|
41
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
42
|
+
const toggle = (v: string) => {
|
|
43
|
+
const isOpen = open.includes(v)
|
|
44
|
+
if (type === 'single') setOpen(isOpen ? [] : [v])
|
|
45
|
+
else setOpen(isOpen ? open.filter((x) => x !== v) : [...open, v])
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
49
|
+
const root = rootRef.current
|
|
50
|
+
// Skips triggers of nested accordions, which handle their own keys.
|
|
51
|
+
const triggers = Array.from(root?.querySelectorAll<HTMLButtonElement>(`.${styles.trigger}:not(:disabled)`) ?? []).filter(
|
|
52
|
+
(t) => t.closest(`.${styles.root}`) === root,
|
|
53
|
+
)
|
|
54
|
+
const i = triggers.indexOf(document.activeElement as HTMLButtonElement)
|
|
55
|
+
if (i < 0) return
|
|
56
|
+
let next = -1
|
|
57
|
+
if (e.key === 'ArrowDown') next = (i + 1) % triggers.length
|
|
58
|
+
else if (e.key === 'ArrowUp') next = (i - 1 + triggers.length) % triggers.length
|
|
59
|
+
else if (e.key === 'Home') next = 0
|
|
60
|
+
else if (e.key === 'End') next = triggers.length - 1
|
|
61
|
+
if (next < 0) return
|
|
62
|
+
e.preventDefault()
|
|
63
|
+
e.stopPropagation()
|
|
64
|
+
triggers[next].focus()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<AccCtx.Provider value={{ open, toggle }}>
|
|
69
|
+
<LevelCtx.Provider value={headingLevel}>
|
|
70
|
+
<div ref={rootRef} className={cx(styles.root, className)} onKeyDown={onKeyDown}>
|
|
71
|
+
{children}
|
|
72
|
+
</div>
|
|
73
|
+
</LevelCtx.Provider>
|
|
74
|
+
</AccCtx.Provider>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type AccordionItemProps = {
|
|
79
|
+
/** Unique id for this item, used in the Accordion value list. */
|
|
80
|
+
value: string
|
|
81
|
+
/** Text on the button that opens and closes the item. */
|
|
82
|
+
title: ReactNode
|
|
83
|
+
/** Stops the item from opening or closing. */
|
|
84
|
+
disabled?: boolean
|
|
85
|
+
/** Content shown when the item is open. */
|
|
86
|
+
children: ReactNode
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function AccordionItem({ value, title, disabled, children }: AccordionItemProps) {
|
|
90
|
+
const ctx = useContext(AccCtx)
|
|
91
|
+
const level = useContext(LevelCtx)
|
|
92
|
+
if (!ctx) throw new Error('AccordionItem must be inside Accordion')
|
|
93
|
+
const id = useId()
|
|
94
|
+
const isOpen = ctx.open.includes(value)
|
|
95
|
+
const Heading = `h${level}` as 'h3'
|
|
96
|
+
return (
|
|
97
|
+
<div className={styles.item} data-open={isOpen || undefined}>
|
|
98
|
+
<Heading className={styles.heading}>
|
|
99
|
+
<button
|
|
100
|
+
id={`${id}-trigger`}
|
|
101
|
+
type="button"
|
|
102
|
+
className={styles.trigger}
|
|
103
|
+
aria-expanded={isOpen}
|
|
104
|
+
aria-controls={`${id}-panel`}
|
|
105
|
+
disabled={disabled}
|
|
106
|
+
onClick={() => ctx.toggle(value)}
|
|
107
|
+
>
|
|
108
|
+
<span className={styles.title}>{title}</span>
|
|
109
|
+
<ChevronDownIcon className={styles.chevron} />
|
|
110
|
+
</button>
|
|
111
|
+
</Heading>
|
|
112
|
+
<div
|
|
113
|
+
id={`${id}-panel`}
|
|
114
|
+
role="region"
|
|
115
|
+
aria-labelledby={`${id}-trigger`}
|
|
116
|
+
className={styles.panel}
|
|
117
|
+
inert={!isOpen}
|
|
118
|
+
>
|
|
119
|
+
<div className={styles.panelInner}>
|
|
120
|
+
<div className={styles.content}>{children}</div>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Accordion'
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: flex-start;
|
|
4
|
+
gap: var(--gooee-space-4);
|
|
5
|
+
padding: var(--gooee-space-5);
|
|
6
|
+
border: var(--gooee-line) solid var(--gooee-color-border);
|
|
7
|
+
border-radius: var(--gooee-radius-md);
|
|
8
|
+
background: var(--gooee-color-surface);
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
animation: alertIn var(--gooee-motion-slow) var(--gooee-ease-out);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* The icon shape also tells statuses apart, so colour is never alone. */
|
|
14
|
+
.success {
|
|
15
|
+
background: var(--gooee-color-success-soft);
|
|
16
|
+
border-color: color-mix(in srgb, var(--gooee-color-success) 45%, var(--gooee-color-border));
|
|
17
|
+
}
|
|
18
|
+
.warning {
|
|
19
|
+
background: var(--gooee-color-warning-soft);
|
|
20
|
+
border-color: color-mix(in srgb, var(--gooee-color-warning) 45%, var(--gooee-color-border));
|
|
21
|
+
}
|
|
22
|
+
.error {
|
|
23
|
+
background: var(--gooee-color-danger-soft);
|
|
24
|
+
border-color: color-mix(in srgb, var(--gooee-color-danger) 45%, var(--gooee-color-border));
|
|
25
|
+
}
|
|
26
|
+
.success .icon { color: var(--gooee-color-success); }
|
|
27
|
+
.warning .icon { color: var(--gooee-color-warning); }
|
|
28
|
+
.error .icon { color: var(--gooee-color-danger); }
|
|
29
|
+
.error .title { font-weight: var(--gooee-weight-semibold); }
|
|
30
|
+
|
|
31
|
+
.banner {
|
|
32
|
+
--strip: var(--gooee-color-inverse);
|
|
33
|
+
--strip-fg: var(--gooee-color-inverse-fg);
|
|
34
|
+
border-radius: 0;
|
|
35
|
+
border-width: 0 0 var(--gooee-line);
|
|
36
|
+
background: var(--strip);
|
|
37
|
+
color: var(--strip-fg);
|
|
38
|
+
align-items: center;
|
|
39
|
+
padding-block: var(--gooee-space-3);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* Swapped on the children, not the strip, so the strip still reads the page's own values. Links and buttons in the action stay visible. */
|
|
43
|
+
.banner > * {
|
|
44
|
+
--gooee-color-bg: var(--strip);
|
|
45
|
+
--gooee-color-surface: var(--strip);
|
|
46
|
+
--gooee-color-surface-hover: color-mix(in srgb, var(--strip-fg) 14%, var(--strip));
|
|
47
|
+
--gooee-color-surface-active: color-mix(in srgb, var(--strip-fg) 20%, var(--strip));
|
|
48
|
+
--gooee-color-fg: var(--strip-fg);
|
|
49
|
+
--gooee-color-fg-muted: color-mix(in srgb, var(--strip-fg) 80%, var(--strip));
|
|
50
|
+
--gooee-color-border: color-mix(in srgb, var(--strip-fg) 24%, var(--strip));
|
|
51
|
+
--gooee-color-border-strong: color-mix(in srgb, var(--strip-fg) 55%, var(--strip));
|
|
52
|
+
--gooee-color-inverse: var(--strip-fg);
|
|
53
|
+
--gooee-color-inverse-fg: var(--strip);
|
|
54
|
+
--gooee-color-inverse-hover: color-mix(in srgb, var(--strip-fg) 82%, var(--strip));
|
|
55
|
+
--gooee-color-accent: var(--strip-fg);
|
|
56
|
+
--gooee-color-accent-fg: var(--strip);
|
|
57
|
+
--gooee-focus-ring: 0 0 0 var(--gooee-line-focus) var(--strip), 0 0 0 calc(var(--gooee-line-focus) * 2) var(--strip-fg);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.icon {
|
|
61
|
+
flex: none;
|
|
62
|
+
width: var(--gooee-icon-lg);
|
|
63
|
+
height: var(--gooee-icon-lg);
|
|
64
|
+
margin-top: var(--gooee-space-1);
|
|
65
|
+
animation: iconIn var(--gooee-motion-slower) var(--gooee-ease-spring);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* On the inverse strip a status hue can drop under 3:1, so the banner icon keeps the strip's text colour. */
|
|
69
|
+
.banner .icon { margin-top: 0; color: inherit; }
|
|
70
|
+
|
|
71
|
+
.text {
|
|
72
|
+
flex: 1;
|
|
73
|
+
min-width: 0;
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
gap: var(--gooee-space-1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.title {
|
|
80
|
+
margin: 0;
|
|
81
|
+
font-weight: var(--gooee-weight-medium);
|
|
82
|
+
line-height: var(--gooee-leading-snug);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.body {
|
|
86
|
+
font-size: var(--gooee-text-sm);
|
|
87
|
+
color: var(--gooee-color-fg-muted);
|
|
88
|
+
line-height: var(--gooee-leading-normal);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.action { margin-top: var(--gooee-space-3); }
|
|
92
|
+
|
|
93
|
+
.close {
|
|
94
|
+
display: grid;
|
|
95
|
+
place-items: center;
|
|
96
|
+
flex: none;
|
|
97
|
+
width: var(--gooee-hit-min);
|
|
98
|
+
height: var(--gooee-hit-min);
|
|
99
|
+
margin: calc(var(--gooee-space-4) * -1) calc(var(--gooee-space-3) * -1) calc(var(--gooee-space-4) * -1) 0;
|
|
100
|
+
padding: 0;
|
|
101
|
+
border: 0;
|
|
102
|
+
border-radius: var(--gooee-radius-full);
|
|
103
|
+
background: transparent;
|
|
104
|
+
color: var(--gooee-color-fg-muted);
|
|
105
|
+
font-size: var(--gooee-icon-md);
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
transition: background-color var(--gooee-motion-fast) var(--gooee-ease-out);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@media (hover: hover) {
|
|
111
|
+
.close:hover { background: var(--gooee-color-surface-hover); color: var(--gooee-color-fg); }
|
|
112
|
+
}
|
|
113
|
+
.close:focus-visible { outline: none; box-shadow: var(--gooee-focus-ring); }
|
|
114
|
+
|
|
115
|
+
@keyframes alertIn {
|
|
116
|
+
from { opacity: 0; transform: translateY(calc(var(--gooee-shift-sm) * -1)); }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@keyframes iconIn {
|
|
120
|
+
from { opacity: 0; transform: scale(0.5) rotate(-20deg); }
|
|
121
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useRef, useState, type ReactNode } from 'react'
|
|
4
|
+
import { cx } from '../../internal/cx'
|
|
5
|
+
import { focusables } from '../../internal/focus'
|
|
6
|
+
import { CheckCircleIcon, ErrorIcon, InfoIcon, WarningIcon, XIcon } from '../../internal/icons'
|
|
7
|
+
import { easing, motionMs } from '../../internal/motion'
|
|
8
|
+
import styles from './Alert.module.css'
|
|
9
|
+
|
|
10
|
+
export type AlertVariant = 'info' | 'success' | 'warning' | 'error'
|
|
11
|
+
|
|
12
|
+
export type AlertProps = {
|
|
13
|
+
/** Sets the colour and icon. Error and warning are announced at once. */
|
|
14
|
+
variant?: AlertVariant
|
|
15
|
+
/** Short bold line at the top. */
|
|
16
|
+
title?: ReactNode
|
|
17
|
+
/** Body text under the title. */
|
|
18
|
+
children?: ReactNode
|
|
19
|
+
/** Shows a close button. Called after the collapse animation. */
|
|
20
|
+
onDismiss?: () => void
|
|
21
|
+
/** Screen reader name for the close button. */
|
|
22
|
+
dismissLabel?: string
|
|
23
|
+
/** Full-width strip for the top of a page. */
|
|
24
|
+
banner?: boolean
|
|
25
|
+
/** Button or link shown under the text. */
|
|
26
|
+
action?: ReactNode
|
|
27
|
+
/** Extra class for the root element. */
|
|
28
|
+
className?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const icons = { info: InfoIcon, success: CheckCircleIcon, warning: WarningIcon, error: ErrorIcon }
|
|
32
|
+
|
|
33
|
+
export function Alert({ variant = 'info', title, children, onDismiss, dismissLabel = 'Dismiss', banner, action, className }: AlertProps) {
|
|
34
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
35
|
+
const [leaving, setLeaving] = useState(false)
|
|
36
|
+
const Icon = icons[variant]
|
|
37
|
+
const urgent = variant === 'error' || variant === 'warning'
|
|
38
|
+
|
|
39
|
+
// The close button is about to unmount, so focus moves to the next control (or the one before) instead of the body.
|
|
40
|
+
const finish = () => {
|
|
41
|
+
const el = ref.current
|
|
42
|
+
if (el?.contains(document.activeElement)) {
|
|
43
|
+
const others = focusables(document.body).filter((n) => !el.contains(n))
|
|
44
|
+
const next = others.find((n) => el.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
45
|
+
const prev = [...others].reverse().find((n) => el.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_PRECEDING)
|
|
46
|
+
;(next ?? prev)?.focus({ preventScroll: true })
|
|
47
|
+
}
|
|
48
|
+
onDismiss?.()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Folds the height to zero, so content below slides up instead of jumping.
|
|
52
|
+
const dismiss = () => {
|
|
53
|
+
const el = ref.current
|
|
54
|
+
if (!el || leaving) return
|
|
55
|
+
setLeaving(true)
|
|
56
|
+
const ms = motionMs('slow')
|
|
57
|
+
if (ms === 0 || !el.animate) return finish()
|
|
58
|
+
const h = el.offsetHeight
|
|
59
|
+
const anim = el.animate(
|
|
60
|
+
[
|
|
61
|
+
{ height: `${h}px`, opacity: 1, transform: 'scale(1)' },
|
|
62
|
+
{ height: `${h}px`, opacity: 0, transform: 'scale(0.98)', offset: 0.45 },
|
|
63
|
+
{ height: '0px', opacity: 0, transform: 'scale(0.98)', paddingTop: '0px', paddingBottom: '0px', marginTop: '0px', marginBottom: '0px', borderWidth: '0px' },
|
|
64
|
+
],
|
|
65
|
+
{ duration: ms, easing: easing('morph'), fill: 'forwards' },
|
|
66
|
+
)
|
|
67
|
+
anim.onfinish = finish
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div
|
|
72
|
+
ref={ref}
|
|
73
|
+
role={urgent ? 'alert' : 'status'}
|
|
74
|
+
className={cx(styles.root, styles[variant], banner && styles.banner, className)}
|
|
75
|
+
data-leaving={leaving || undefined}
|
|
76
|
+
>
|
|
77
|
+
<Icon className={styles.icon} />
|
|
78
|
+
<div className={styles.text}>
|
|
79
|
+
{title && <p className={styles.title}>{title}</p>}
|
|
80
|
+
{children && <div className={styles.body}>{children}</div>}
|
|
81
|
+
{action && <div className={styles.action}>{action}</div>}
|
|
82
|
+
</div>
|
|
83
|
+
{onDismiss && (
|
|
84
|
+
<button type="button" className={styles.close} aria-label={dismissLabel} onClick={dismiss}>
|
|
85
|
+
<XIcon />
|
|
86
|
+
</button>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Alert'
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useId, useRef, type ReactNode } from 'react'
|
|
4
|
+
import { cx } from '../../internal/cx'
|
|
5
|
+
import { useFocusTrap } from '../../internal/focus'
|
|
6
|
+
import { useDismiss, useScrollLock } from '../../internal/layers'
|
|
7
|
+
import { useDialogMorph } from '../../internal/liquid'
|
|
8
|
+
import { Portal } from '../../internal/Portal'
|
|
9
|
+
import { usePresence } from '../../internal/usePresence'
|
|
10
|
+
import { Button } from '../Button'
|
|
11
|
+
import dialog from '../Dialog/Dialog.module.css'
|
|
12
|
+
import styles from './AlertDialog.module.css'
|
|
13
|
+
|
|
14
|
+
export type AlertDialogProps = {
|
|
15
|
+
/** Shows the dialog. You always control it. */
|
|
16
|
+
open: boolean
|
|
17
|
+
/** Called with false after Confirm, Cancel or Esc. A tap outside never closes it. */
|
|
18
|
+
onOpenChange: (open: boolean) => void
|
|
19
|
+
/** The question, such as "Delete this project?". Also the accessible name. */
|
|
20
|
+
title: ReactNode
|
|
21
|
+
/** What happens if they confirm. Read out with the title when the dialog opens. */
|
|
22
|
+
description: ReactNode
|
|
23
|
+
/** Extra content under the description, such as a list of what goes away. */
|
|
24
|
+
children?: ReactNode
|
|
25
|
+
/** Text of the confirm button. Name the action, such as "Delete project", not "OK". */
|
|
26
|
+
confirmLabel: string
|
|
27
|
+
/** Text of the cancel button. */
|
|
28
|
+
cancelLabel?: string
|
|
29
|
+
/** Called when they confirm, before the dialog closes. */
|
|
30
|
+
onConfirm: () => void
|
|
31
|
+
/** Called when they cancel with the button or Esc, before the dialog closes. */
|
|
32
|
+
onCancel?: () => void
|
|
33
|
+
/** "danger" gives the confirm button the solid red look, for actions that destroy something. */
|
|
34
|
+
tone?: 'default' | 'danger'
|
|
35
|
+
/** Extra class for the dialog panel. */
|
|
36
|
+
className?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function AlertDialog({
|
|
40
|
+
open,
|
|
41
|
+
onOpenChange,
|
|
42
|
+
title,
|
|
43
|
+
description,
|
|
44
|
+
children,
|
|
45
|
+
confirmLabel,
|
|
46
|
+
cancelLabel = 'Cancel',
|
|
47
|
+
onConfirm,
|
|
48
|
+
onCancel,
|
|
49
|
+
tone = 'default',
|
|
50
|
+
className,
|
|
51
|
+
}: AlertDialogProps) {
|
|
52
|
+
const id = useId()
|
|
53
|
+
const panelRef = useRef<HTMLDivElement>(null)
|
|
54
|
+
const cancelRef = useRef<HTMLButtonElement>(null)
|
|
55
|
+
const { mounted, state } = usePresence(open, 'morph-out')
|
|
56
|
+
useDialogMorph(panelRef, open, mounted, state)
|
|
57
|
+
|
|
58
|
+
const cancel = () => {
|
|
59
|
+
onCancel?.()
|
|
60
|
+
onOpenChange(false)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
useScrollLock(open)
|
|
64
|
+
useDismiss(open, [panelRef], cancel, { outside: false })
|
|
65
|
+
// Focus starts on the least destructive choice, so a stray Enter never confirms.
|
|
66
|
+
useFocusTrap(panelRef, open && mounted, { initialFocus: cancelRef })
|
|
67
|
+
|
|
68
|
+
if (!mounted) return null
|
|
69
|
+
return (
|
|
70
|
+
<Portal>
|
|
71
|
+
<div className={dialog.overlay} data-state={state} aria-hidden="true" />
|
|
72
|
+
<div className={dialog.positioner}>
|
|
73
|
+
<div
|
|
74
|
+
ref={panelRef}
|
|
75
|
+
role="alertdialog"
|
|
76
|
+
aria-modal="true"
|
|
77
|
+
aria-labelledby={`${id}-title`}
|
|
78
|
+
aria-describedby={`${id}-desc`}
|
|
79
|
+
tabIndex={-1}
|
|
80
|
+
className={cx(dialog.panel, dialog.sm, className)}
|
|
81
|
+
data-state={state}
|
|
82
|
+
>
|
|
83
|
+
<header className={cx(dialog.header, styles.header)}>
|
|
84
|
+
<div className={dialog.titles}>
|
|
85
|
+
<h2 id={`${id}-title`} className={dialog.title}>{title}</h2>
|
|
86
|
+
<p id={`${id}-desc`} className={dialog.description}>{description}</p>
|
|
87
|
+
</div>
|
|
88
|
+
</header>
|
|
89
|
+
{children && <div className={dialog.body}>{children}</div>}
|
|
90
|
+
<footer className={dialog.footer}>
|
|
91
|
+
<Button ref={cancelRef} variant="secondary" onClick={cancel}>
|
|
92
|
+
{cancelLabel}
|
|
93
|
+
</Button>
|
|
94
|
+
<Button
|
|
95
|
+
variant={tone === 'danger' ? 'danger' : 'primary'}
|
|
96
|
+
onClick={() => {
|
|
97
|
+
onConfirm()
|
|
98
|
+
onOpenChange(false)
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
{confirmLabel}
|
|
102
|
+
</Button>
|
|
103
|
+
</footer>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</Portal>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AlertDialog'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
width: fit-content;
|
|
4
|
+
font-variant-numeric: tabular-nums;
|
|
5
|
+
line-height: 1.15;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.visual {
|
|
9
|
+
display: inline-flex;
|
|
10
|
+
white-space: pre;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.digit {
|
|
14
|
+
display: inline-block;
|
|
15
|
+
height: 1.15em;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
animation: enter var(--gooee-motion-slow) var(--gooee-ease-out);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.strip {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
transition: transform var(--gooee-motion-slower) var(--gooee-ease-spring);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.cell {
|
|
27
|
+
display: block;
|
|
28
|
+
height: 1.15em;
|
|
29
|
+
text-align: center;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.symbol {
|
|
33
|
+
display: inline-block;
|
|
34
|
+
animation: enter var(--gooee-motion-slow) var(--gooee-ease-out);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.srOnly {
|
|
38
|
+
position: absolute;
|
|
39
|
+
width: 1px;
|
|
40
|
+
height: 1px;
|
|
41
|
+
overflow: hidden;
|
|
42
|
+
clip-path: inset(50%);
|
|
43
|
+
white-space: nowrap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@keyframes enter {
|
|
47
|
+
from { opacity: 0; transform: translateY(40%); }
|
|
48
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import { cx } from '../../internal/cx'
|
|
5
|
+
import styles from './AnimatedNumber.module.css'
|
|
6
|
+
|
|
7
|
+
export type AnimatedNumberProps = {
|
|
8
|
+
/** Number to show. Digits roll to the new value when it changes. */
|
|
9
|
+
value: number
|
|
10
|
+
/** Passed to Intl.NumberFormat, for currency, percent, decimals and so on. */
|
|
11
|
+
format?: Intl.NumberFormatOptions
|
|
12
|
+
/** Locale for number formatting. Undefined uses the browser locale. */
|
|
13
|
+
locale?: string
|
|
14
|
+
/** Extra class for the root element. */
|
|
15
|
+
className?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const DIGITS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
19
|
+
|
|
20
|
+
export function AnimatedNumber({ value, format, locale, className }: AnimatedNumberProps) {
|
|
21
|
+
const text = useMemo(() => new Intl.NumberFormat(locale, format).format(value), [value, format, locale])
|
|
22
|
+
const chars = text.split('')
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<span className={cx(styles.root, className)}>
|
|
26
|
+
<span className={styles.srOnly}>{text}</span>
|
|
27
|
+
<span className={styles.visual} aria-hidden="true">
|
|
28
|
+
{chars.map((ch, i) => {
|
|
29
|
+
// Keyed from the right, so the ones column stays the ones column when the number grows.
|
|
30
|
+
const key = chars.length - i
|
|
31
|
+
const d = Number(ch)
|
|
32
|
+
if (ch >= '0' && ch <= '9') {
|
|
33
|
+
return (
|
|
34
|
+
<span key={`d${key}`} className={styles.digit}>
|
|
35
|
+
<span className={styles.strip} style={{ transform: `translateY(${-d * 10}%)` }}>
|
|
36
|
+
{DIGITS.map((n) => (
|
|
37
|
+
<span key={n} className={styles.cell}>{n}</span>
|
|
38
|
+
))}
|
|
39
|
+
</span>
|
|
40
|
+
</span>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
return (
|
|
44
|
+
<span key={`s${key}${ch}`} className={styles.symbol}>
|
|
45
|
+
{ch}
|
|
46
|
+
</span>
|
|
47
|
+
)
|
|
48
|
+
})}
|
|
49
|
+
</span>
|
|
50
|
+
</span>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AnimatedNumber'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
position: relative;
|
|
3
|
+
aspect-ratio: var(--ratio);
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/* Children sit on top of the box, so their own size can never stretch it. */
|
|
8
|
+
.root > * {
|
|
9
|
+
position: absolute;
|
|
10
|
+
inset: 0;
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.root > :is(img, video) { object-fit: cover; }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef, CSSProperties } from 'react'
|
|
2
|
+
import { cx } from '../../internal/cx'
|
|
3
|
+
import styles from './AspectRatio.module.css'
|
|
4
|
+
|
|
5
|
+
export type AspectRatioProps = ComponentPropsWithRef<'div'> & {
|
|
6
|
+
/** Width over height, such as 16 / 9 or 1 for a square. */
|
|
7
|
+
ratio?: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AspectRatio({ ratio = 16 / 9, className, style, ...rest }: AspectRatioProps) {
|
|
11
|
+
return <div className={cx(styles.root, className)} style={{ '--ratio': ratio, ...style } as CSSProperties} {...rest} />
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AspectRatio'
|