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,75 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
min-width: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.trigger {
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
align-self: flex-start;
|
|
11
|
+
max-width: 100%;
|
|
12
|
+
gap: var(--gooee-space-3);
|
|
13
|
+
min-height: var(--gooee-hit-min);
|
|
14
|
+
padding: 0 var(--gooee-space-4);
|
|
15
|
+
border: 0;
|
|
16
|
+
border-radius: var(--gooee-radius-control);
|
|
17
|
+
background: transparent;
|
|
18
|
+
color: inherit;
|
|
19
|
+
font: inherit;
|
|
20
|
+
font-size: var(--gooee-text-md);
|
|
21
|
+
font-weight: var(--gooee-weight-medium);
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
transition:
|
|
24
|
+
background-color var(--gooee-motion-fast) var(--gooee-ease-out),
|
|
25
|
+
transform var(--gooee-motion-slow) var(--gooee-ease-spring);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@media (hover: hover) {
|
|
29
|
+
.trigger:hover:not(:disabled) { background: var(--gooee-color-surface-hover); }
|
|
30
|
+
}
|
|
31
|
+
.trigger:active:not(:disabled) { transform: scale(var(--gooee-press-scale)); }
|
|
32
|
+
.trigger:disabled { opacity: var(--gooee-disabled-opacity); cursor: not-allowed; }
|
|
33
|
+
.trigger:focus-visible { outline: none; box-shadow: var(--gooee-focus-ring); }
|
|
34
|
+
|
|
35
|
+
.label {
|
|
36
|
+
min-width: 0;
|
|
37
|
+
overflow-wrap: anywhere;
|
|
38
|
+
text-align: start;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.chevron {
|
|
42
|
+
flex: none;
|
|
43
|
+
width: var(--gooee-icon-md);
|
|
44
|
+
height: var(--gooee-icon-md);
|
|
45
|
+
color: var(--gooee-color-fg-muted);
|
|
46
|
+
transition: transform var(--gooee-motion-slow) var(--gooee-ease-spring);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.root[data-open] .chevron { transform: rotate(180deg); }
|
|
50
|
+
|
|
51
|
+
.panel {
|
|
52
|
+
display: grid;
|
|
53
|
+
grid-template-rows: 0fr;
|
|
54
|
+
visibility: hidden;
|
|
55
|
+
transition:
|
|
56
|
+
grid-template-rows var(--gooee-motion-morph) var(--gooee-ease-morph),
|
|
57
|
+
visibility 0s linear var(--gooee-motion-morph);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.root[data-open] .panel {
|
|
61
|
+
grid-template-rows: 1fr;
|
|
62
|
+
visibility: visible;
|
|
63
|
+
transition:
|
|
64
|
+
grid-template-rows var(--gooee-motion-morph) var(--gooee-ease-morph),
|
|
65
|
+
visibility 0s;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.inner {
|
|
69
|
+
min-height: 0;
|
|
70
|
+
overflow: hidden;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.content {
|
|
74
|
+
padding-top: var(--gooee-space-3);
|
|
75
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { cloneElement, isValidElement, useId, type MouseEvent, type ReactElement, 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 './Collapsible.module.css'
|
|
8
|
+
|
|
9
|
+
type TriggerProps = {
|
|
10
|
+
onClick?: (e: MouseEvent<HTMLElement>) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type CollapsibleProps = {
|
|
14
|
+
/** Text for the built-in toggle button. */
|
|
15
|
+
label?: ReactNode
|
|
16
|
+
/** Your own button instead of the built-in one. It gets aria-expanded and aria-controls. */
|
|
17
|
+
trigger?: ReactElement<TriggerProps>
|
|
18
|
+
/** Open state, when you control it. */
|
|
19
|
+
open?: boolean
|
|
20
|
+
/** Starting open state when you do not control it. */
|
|
21
|
+
defaultOpen?: boolean
|
|
22
|
+
/** Called when the open state changes, with the new state. */
|
|
23
|
+
onOpenChange?: (open: boolean) => void
|
|
24
|
+
/** Stops the panel from opening or closing. */
|
|
25
|
+
disabled?: boolean
|
|
26
|
+
/** Extra class for the root element. */
|
|
27
|
+
className?: string
|
|
28
|
+
/** Content shown when open. */
|
|
29
|
+
children: ReactNode
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function Collapsible({ label, trigger, open: openProp, defaultOpen = false, onOpenChange, disabled, className, children }: CollapsibleProps) {
|
|
33
|
+
const id = useId()
|
|
34
|
+
const [open, setOpen] = useControllable(openProp, defaultOpen, onOpenChange)
|
|
35
|
+
const toggle = () => !disabled && setOpen(!open)
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className={cx(styles.root, className)} data-open={open || undefined}>
|
|
39
|
+
{trigger && isValidElement(trigger) ? (
|
|
40
|
+
cloneElement(trigger, {
|
|
41
|
+
'aria-expanded': open,
|
|
42
|
+
'aria-controls': `${id}-panel`,
|
|
43
|
+
// Only set when disabled, so a trigger's own disabled prop is kept otherwise.
|
|
44
|
+
...(disabled ? { disabled: true, 'aria-disabled': true } : null),
|
|
45
|
+
onClick: (e: MouseEvent<HTMLElement>) => {
|
|
46
|
+
trigger.props.onClick?.(e)
|
|
47
|
+
toggle()
|
|
48
|
+
},
|
|
49
|
+
} as TriggerProps)
|
|
50
|
+
) : (
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
className={styles.trigger}
|
|
54
|
+
aria-expanded={open}
|
|
55
|
+
aria-controls={`${id}-panel`}
|
|
56
|
+
disabled={disabled}
|
|
57
|
+
onClick={toggle}
|
|
58
|
+
>
|
|
59
|
+
<span className={styles.label}>{label}</span>
|
|
60
|
+
<ChevronDownIcon className={styles.chevron} />
|
|
61
|
+
</button>
|
|
62
|
+
)}
|
|
63
|
+
{/* Grid rows animate from 0fr to 1fr, so the height follows the content without measuring. */}
|
|
64
|
+
<div id={`${id}-panel`} className={styles.panel} inert={!open}>
|
|
65
|
+
<div className={styles.inner}>
|
|
66
|
+
<div className={styles.content}>{children}</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Collapsible'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* The max width adds the padding back, so the size token stays the content width. */
|
|
2
|
+
.root {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
max-width: calc(var(--container-max) + 2 * var(--container-pad));
|
|
5
|
+
margin-inline: auto;
|
|
6
|
+
padding-left: max(var(--container-pad), env(safe-area-inset-left, 0px));
|
|
7
|
+
padding-right: max(var(--container-pad), env(safe-area-inset-right, 0px));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.sm { --container-max: var(--gooee-container-sm); }
|
|
11
|
+
.md { --container-max: var(--gooee-container-md); }
|
|
12
|
+
.lg { --container-max: var(--gooee-container-lg); }
|
|
13
|
+
.xl { --container-max: var(--gooee-container-xl); }
|
|
14
|
+
.full { max-width: none; }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef, CSSProperties } from 'react'
|
|
2
|
+
import { cx } from '../../internal/cx'
|
|
3
|
+
import { space, type Space } from '../../internal/space'
|
|
4
|
+
import styles from './Container.module.css'
|
|
5
|
+
|
|
6
|
+
export type ContainerProps = ComponentPropsWithRef<'div'> & {
|
|
7
|
+
/** Widest the content gets, from the --gooee-container-* tokens. "full" never stops growing. */
|
|
8
|
+
size?: 'sm' | 'md' | 'lg' | 'xl' | 'full'
|
|
9
|
+
/** Space on the left and right, as a step of the space scale. The notch area on a phone wins when it is wider. */
|
|
10
|
+
padding?: Space
|
|
11
|
+
/** Element to render, such as main for the page body. */
|
|
12
|
+
as?: 'div' | 'main' | 'section' | 'article' | 'header' | 'footer'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Container({ size = 'lg', padding = 5, as = 'div', className, style, ...rest }: ContainerProps) {
|
|
16
|
+
// One cast keeps the ref and attribute types simple; every option is a block element.
|
|
17
|
+
const Tag = as as 'div'
|
|
18
|
+
return <Tag className={cx(styles.root, styles[size], className)} style={{ '--container-pad': space(padding), ...style } as CSSProperties} {...rest} />
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Container'
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
--s: var(--gooee-control-h-md);
|
|
3
|
+
position: relative;
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
width: fit-content;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
gap: var(--gooee-space-3);
|
|
9
|
+
min-width: var(--s);
|
|
10
|
+
height: var(--s);
|
|
11
|
+
padding: 0;
|
|
12
|
+
border: var(--gooee-line) solid var(--gooee-color-border);
|
|
13
|
+
border-radius: var(--gooee-radius-control);
|
|
14
|
+
background: var(--gooee-color-surface);
|
|
15
|
+
color: var(--gooee-color-fg);
|
|
16
|
+
font-size: var(--gooee-text-sm);
|
|
17
|
+
font-weight: var(--gooee-weight-medium);
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
transition:
|
|
20
|
+
background-color var(--gooee-motion-fast) var(--gooee-ease-out),
|
|
21
|
+
border-color var(--gooee-motion-base) var(--gooee-ease-out);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.root::after {
|
|
25
|
+
content: "";
|
|
26
|
+
position: absolute;
|
|
27
|
+
inset: min(0px, calc((100% - var(--gooee-hit-min)) / 2));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.sm { --s: var(--gooee-control-h-sm); }
|
|
31
|
+
.withLabel { padding: 0 var(--gooee-space-5) 0 var(--gooee-space-4); }
|
|
32
|
+
|
|
33
|
+
@media (hover: hover) {
|
|
34
|
+
.root:hover { background: var(--gooee-color-surface-hover); }
|
|
35
|
+
}
|
|
36
|
+
.root:focus-visible { outline: none; box-shadow: var(--gooee-focus-ring); }
|
|
37
|
+
.root[data-copied] { border-color: var(--gooee-color-fg); }
|
|
38
|
+
.root[data-failed] { border-color: var(--gooee-color-danger); color: var(--gooee-color-danger); }
|
|
39
|
+
|
|
40
|
+
/* With a label, CopyButton.tsx sets --cap-shift so the icon sits on the middle of the capitals. */
|
|
41
|
+
.icons {
|
|
42
|
+
position: relative;
|
|
43
|
+
display: grid;
|
|
44
|
+
width: var(--gooee-icon-md);
|
|
45
|
+
height: var(--gooee-icon-md);
|
|
46
|
+
translate: 0 var(--cap-shift, 0px);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* The copy, pour and check are drawn by internal/liquidMore.ts while they move; the icons below are
|
|
50
|
+
the resting states, so they swap at once. Reduced motion shows only the swap. */
|
|
51
|
+
.pour {
|
|
52
|
+
position: absolute;
|
|
53
|
+
left: 0;
|
|
54
|
+
top: 0;
|
|
55
|
+
overflow: visible;
|
|
56
|
+
pointer-events: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.icons[data-pouring] :is(.copy, .check) { visibility: hidden; }
|
|
60
|
+
|
|
61
|
+
.copy,
|
|
62
|
+
.check,
|
|
63
|
+
.fail {
|
|
64
|
+
grid-area: 1 / 1;
|
|
65
|
+
width: 100%;
|
|
66
|
+
height: 100%;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.fail,
|
|
70
|
+
.root[data-failed] .copy {
|
|
71
|
+
transition:
|
|
72
|
+
opacity var(--gooee-motion-fast) var(--gooee-ease-out),
|
|
73
|
+
transform var(--gooee-motion-slow) var(--gooee-ease-spring);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.check {
|
|
77
|
+
fill: none;
|
|
78
|
+
stroke: currentColor;
|
|
79
|
+
stroke-width: 2.25;
|
|
80
|
+
stroke-linecap: round;
|
|
81
|
+
stroke-linejoin: round;
|
|
82
|
+
/* Hidden just before the path starts. A zero-length dash would leave its round ends as a dot in Safari. */
|
|
83
|
+
stroke-dasharray: 1 2;
|
|
84
|
+
stroke-dashoffset: 1.01;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.fail { opacity: 0; transform: scale(0.4); }
|
|
88
|
+
|
|
89
|
+
.root[data-copied] .copy { opacity: 0; }
|
|
90
|
+
.root[data-failed] .copy { opacity: 0; transform: scale(0.4) rotate(-45deg); }
|
|
91
|
+
.root[data-failed] .fail { opacity: 1; transform: none; }
|
|
92
|
+
|
|
93
|
+
.root[data-copied] .check { stroke-dashoffset: 0; }
|
|
94
|
+
|
|
95
|
+
.labels {
|
|
96
|
+
display: grid;
|
|
97
|
+
overflow: hidden;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.labelIdle,
|
|
101
|
+
.labelDone,
|
|
102
|
+
.labelFailed {
|
|
103
|
+
grid-area: 1 / 1;
|
|
104
|
+
transition:
|
|
105
|
+
transform var(--gooee-motion-slow) var(--gooee-ease-spring),
|
|
106
|
+
opacity var(--gooee-motion-base) var(--gooee-ease-out);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.labelDone { transform: translateY(100%); opacity: 0; }
|
|
110
|
+
/* Out of the layout until a copy fails, so the longer words do not widen every button. */
|
|
111
|
+
.labelFailed { display: none; }
|
|
112
|
+
.root[data-failed] .labelFailed { display: block; }
|
|
113
|
+
.root[data-copied] .labelIdle,
|
|
114
|
+
.root[data-failed] .labelIdle { transform: translateY(-100%); opacity: 0; }
|
|
115
|
+
.root[data-copied] .labelDone,
|
|
116
|
+
.root[data-failed] .labelFailed { transform: none; opacity: 1; }
|
|
117
|
+
|
|
118
|
+
.srOnly {
|
|
119
|
+
position: absolute;
|
|
120
|
+
width: 1px;
|
|
121
|
+
height: 1px;
|
|
122
|
+
overflow: hidden;
|
|
123
|
+
clip-path: inset(50%);
|
|
124
|
+
white-space: nowrap;
|
|
125
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
4
|
+
import { cx } from '../../internal/cx'
|
|
5
|
+
import { CopyIcon, XIcon } from '../../internal/icons'
|
|
6
|
+
import { copyRun, type CopyRun } from '../../internal/liquidMore'
|
|
7
|
+
import styles from './CopyButton.module.css'
|
|
8
|
+
|
|
9
|
+
export type CopyButtonProps = {
|
|
10
|
+
/** Text to put on the clipboard. */
|
|
11
|
+
value: string
|
|
12
|
+
/** Accessible name, and the visible text when showLabel is on. */
|
|
13
|
+
label?: string
|
|
14
|
+
/** Shown and spoken after a successful copy. */
|
|
15
|
+
copiedLabel?: string
|
|
16
|
+
/** Shown and spoken when the browser blocks the copy. */
|
|
17
|
+
failedLabel?: string
|
|
18
|
+
/** Shows the label as text next to the icon. */
|
|
19
|
+
showLabel?: boolean
|
|
20
|
+
/** Size of the button. */
|
|
21
|
+
size?: 'sm' | 'md'
|
|
22
|
+
/** How long the check or the failed state stays, in ms. */
|
|
23
|
+
resetAfter?: number
|
|
24
|
+
/** Called after the text is copied, with the copied text. Not called if copying fails. */
|
|
25
|
+
onCopy?: (value: string) => void
|
|
26
|
+
/** Extra class for the button. */
|
|
27
|
+
className?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function writeText(text: string) {
|
|
31
|
+
try {
|
|
32
|
+
await navigator.clipboard.writeText(text)
|
|
33
|
+
return true
|
|
34
|
+
} catch {
|
|
35
|
+
// Fallback for http pages and older browsers.
|
|
36
|
+
const ta = document.createElement('textarea')
|
|
37
|
+
ta.value = text
|
|
38
|
+
ta.setAttribute('readonly', '')
|
|
39
|
+
ta.style.position = 'fixed'
|
|
40
|
+
ta.style.opacity = '0'
|
|
41
|
+
const prev = document.activeElement as HTMLElement | null
|
|
42
|
+
document.body.appendChild(ta)
|
|
43
|
+
ta.select()
|
|
44
|
+
const ok = document.execCommand('copy')
|
|
45
|
+
ta.remove()
|
|
46
|
+
prev?.focus()
|
|
47
|
+
return ok
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function CopyButton({
|
|
52
|
+
value,
|
|
53
|
+
label = 'Copy',
|
|
54
|
+
copiedLabel = 'Copied',
|
|
55
|
+
failedLabel = 'Could not copy',
|
|
56
|
+
showLabel = false,
|
|
57
|
+
size = 'md',
|
|
58
|
+
resetAfter = 1800,
|
|
59
|
+
onCopy,
|
|
60
|
+
className,
|
|
61
|
+
}: CopyButtonProps) {
|
|
62
|
+
const [status, setStatus] = useState<'idle' | 'copied' | 'failed'>('idle')
|
|
63
|
+
const timer = useRef<number | undefined>(undefined)
|
|
64
|
+
useEffect(() => () => window.clearTimeout(timer.current), [])
|
|
65
|
+
|
|
66
|
+
// A copy pours a drop from where it was pressed into the icon, which fills and turns into the check;
|
|
67
|
+
// going idle plays it back. internal/liquidMore.ts draws it.
|
|
68
|
+
const rootRef = useRef<HTMLButtonElement>(null)
|
|
69
|
+
const iconsRef = useRef<HTMLSpanElement>(null)
|
|
70
|
+
const labelRef = useRef<HTMLSpanElement>(null)
|
|
71
|
+
const pressedAt = useRef<[number, number] | null>(null)
|
|
72
|
+
const run = useRef<CopyRun | null>(null)
|
|
73
|
+
const copied = status === 'copied'
|
|
74
|
+
const wasCopied = useRef(copied)
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
if (wasCopied.current === copied) return
|
|
77
|
+
wasCopied.current = copied
|
|
78
|
+
const icons = iconsRef.current
|
|
79
|
+
// A failed copy shows its cross at once, with nothing poured.
|
|
80
|
+
if (!icons || status === 'failed') {
|
|
81
|
+
run.current?.stop()
|
|
82
|
+
run.current = null
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
const at = pressedAt.current
|
|
86
|
+
pressedAt.current = null
|
|
87
|
+
run.current = copyRun(icons, copied ? 1 : 0, at, styles.pour, run.current)
|
|
88
|
+
}, [copied, status])
|
|
89
|
+
useLayoutEffect(() => () => run.current?.stop(), [])
|
|
90
|
+
|
|
91
|
+
// With a label, the icon sits on the middle of the label's capital letters, not of its line.
|
|
92
|
+
useLayoutEffect(() => {
|
|
93
|
+
const root = rootRef.current
|
|
94
|
+
const icons = iconsRef.current
|
|
95
|
+
const text = labelRef.current?.firstChild
|
|
96
|
+
root?.style.removeProperty('--cap-shift')
|
|
97
|
+
if (!root || !icons || !text) return
|
|
98
|
+
const place = () => {
|
|
99
|
+
root.style.removeProperty('--cap-shift')
|
|
100
|
+
const range = document.createRange()
|
|
101
|
+
range.selectNodeContents(text)
|
|
102
|
+
const box = range.getBoundingClientRect()
|
|
103
|
+
const look = getComputedStyle(root)
|
|
104
|
+
const pen = document.createElement('canvas').getContext('2d')
|
|
105
|
+
if (!pen || !box.height) return
|
|
106
|
+
pen.font = `${look.fontWeight} ${look.fontSize} ${look.fontFamily}`
|
|
107
|
+
const m = pen.measureText('H')
|
|
108
|
+
const cap = box.top + m.fontBoundingBoxAscent - m.actualBoundingBoxAscent / 2
|
|
109
|
+
const r = icons.getBoundingClientRect()
|
|
110
|
+
root.style.setProperty('--cap-shift', `${Math.round((cap - r.top - r.height / 2) * 100) / 100}px`)
|
|
111
|
+
}
|
|
112
|
+
place()
|
|
113
|
+
let live = true
|
|
114
|
+
document.fonts?.ready.then(() => live && place())
|
|
115
|
+
return () => {
|
|
116
|
+
live = false
|
|
117
|
+
}
|
|
118
|
+
}, [showLabel, label, size])
|
|
119
|
+
|
|
120
|
+
const copy = async () => {
|
|
121
|
+
const ok = await writeText(value)
|
|
122
|
+
setStatus(ok ? 'copied' : 'failed')
|
|
123
|
+
if (ok) onCopy?.(value)
|
|
124
|
+
window.clearTimeout(timer.current)
|
|
125
|
+
timer.current = window.setTimeout(() => setStatus('idle'), resetAfter)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<button
|
|
130
|
+
ref={rootRef}
|
|
131
|
+
type="button"
|
|
132
|
+
className={cx(styles.root, styles[size], showLabel && styles.withLabel, className)}
|
|
133
|
+
data-copied={status === 'copied' || undefined}
|
|
134
|
+
data-failed={status === 'failed' || undefined}
|
|
135
|
+
aria-label={showLabel ? undefined : label}
|
|
136
|
+
onClick={(e) => {
|
|
137
|
+
const r = iconsRef.current?.getBoundingClientRect()
|
|
138
|
+
// A key press (no pointer) pours from the icon's middle.
|
|
139
|
+
pressedAt.current = r && e.detail ? [e.clientX - r.left, e.clientY - r.top] : null
|
|
140
|
+
copy()
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
<span ref={iconsRef} className={styles.icons} aria-hidden="true">
|
|
144
|
+
<CopyIcon className={styles.copy} />
|
|
145
|
+
<svg viewBox="0 0 24 24" className={styles.check}>
|
|
146
|
+
<path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1" />
|
|
147
|
+
</svg>
|
|
148
|
+
<XIcon className={styles.fail} />
|
|
149
|
+
</span>
|
|
150
|
+
{showLabel && (
|
|
151
|
+
<span className={styles.labels}>
|
|
152
|
+
<span ref={labelRef} className={styles.labelIdle}>{label}</span>
|
|
153
|
+
<span className={styles.labelDone} aria-hidden="true">{copiedLabel}</span>
|
|
154
|
+
<span className={styles.labelFailed} aria-hidden="true">{failedLabel}</span>
|
|
155
|
+
</span>
|
|
156
|
+
)}
|
|
157
|
+
<span className={styles.srOnly} aria-live="polite">{status === 'copied' ? copiedLabel : status === 'failed' ? failedLabel : ''}</span>
|
|
158
|
+
</button>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CopyButton'
|