gooee 0.42.0 → 0.47.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/package.json +1 -1
- package/src/components/Alert/Alert.module.css +2 -2
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +3 -3
- package/src/components/Badge/Badge.module.css +2 -2
- package/src/components/Button/Button.module.css +4 -4
- package/src/components/Card/Card.module.css +7 -5
- package/src/components/CodeBlock/CodeBlock.module.css +4 -2
- package/src/components/CopyButton/CopyButton.module.css +1 -1
- package/src/components/Dial/Dial.module.css +4 -3
- package/src/components/Dial/Dial.tsx +32 -1
- package/src/components/Dialog/Dialog.module.css +10 -4
- package/src/components/DropdownMenu/DropdownMenu.module.css +1 -1
- package/src/components/FormField/FormField.module.css +23 -3
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +37 -52
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +146 -60
- package/src/components/Input/Input.module.css +6 -4
- package/src/components/InputGroup/InputGroup.module.css +3 -0
- package/src/components/Kbd/Kbd.module.css +2 -2
- package/src/components/LivePill/LivePill.module.css +213 -31
- package/src/components/LivePill/LivePill.tsx +45 -14
- package/src/components/MorphButton/MorphButton.module.css +8 -4
- package/src/components/NumberInput/NumberInput.module.css +9 -5
- package/src/components/Pagination/Pagination.module.css +1 -0
- package/src/components/PickerWheel/PickerWheel.module.css +1 -1
- package/src/components/Popover/Popover.module.css +12 -4
- package/src/components/Prose/Prose.module.css +5 -3
- package/src/components/RulerScrubber/RulerScrubber.module.css +2 -2
- package/src/components/SegmentedControl/SegmentedControl.module.css +5 -5
- package/src/components/Select/Select.module.css +6 -4
- package/src/components/Sheet/Sheet.module.css +12 -5
- package/src/components/Skeleton/Skeleton.module.css +1 -1
- package/src/components/SplitFlap/SplitFlap.module.css +1 -1
- package/src/components/SwipeDeck/SwipeDeck.module.css +1 -1
- package/src/components/Switch/Switch.module.css +7 -5
- package/src/components/Table/Table.module.css +8 -6
- package/src/components/Tabs/Tabs.module.css +34 -33
- package/src/components/Tabs/Tabs.tsx +64 -21
- package/src/components/Textarea/Textarea.module.css +5 -3
- package/src/components/ThemeToggle/ThemeToggle.module.css +6 -15
- package/src/components/ThemeToggle/ThemeToggle.tsx +108 -9
- package/src/components/Toast/Toast.module.css +8 -5
- package/src/components/Toggle/Toggle.module.css +4 -4
- package/src/internal/icons.tsx +7 -0
- package/src/internal/motion.ts +1 -1
- package/src/internal/themeReveal.ts +63 -0
- package/src/tokens.css +49 -15
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
.root {
|
|
2
|
+
/* The panel's surface; the chosen tab rises out of it in the same colour. */
|
|
3
|
+
--tabs-panel: var(--gooee-color-surface-sunken);
|
|
4
|
+
--tabs-r: var(--gooee-radius-md);
|
|
2
5
|
display: flex;
|
|
3
6
|
flex-direction: column;
|
|
4
7
|
min-width: 0;
|
|
@@ -7,7 +10,9 @@
|
|
|
7
10
|
.listScroll {
|
|
8
11
|
overflow-x: auto;
|
|
9
12
|
scrollbar-width: none;
|
|
10
|
-
|
|
13
|
+
/* Room under the row for the rise to reach into the panel's corner; the panel overlaps it. */
|
|
14
|
+
padding-bottom: var(--tabs-r);
|
|
15
|
+
margin-bottom: calc(var(--tabs-r) * -1);
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
.listScroll::-webkit-scrollbar { display: none; }
|
|
@@ -26,7 +31,8 @@
|
|
|
26
31
|
min-height: var(--gooee-hit-min);
|
|
27
32
|
padding: 0 var(--gooee-space-4);
|
|
28
33
|
border: 0;
|
|
29
|
-
|
|
34
|
+
z-index: 1;
|
|
35
|
+
border-radius: var(--tabs-r) var(--tabs-r) 0 0;
|
|
30
36
|
background: transparent;
|
|
31
37
|
color: var(--gooee-color-fg-muted);
|
|
32
38
|
font: inherit;
|
|
@@ -34,7 +40,7 @@
|
|
|
34
40
|
font-weight: var(--gooee-weight-medium);
|
|
35
41
|
white-space: nowrap;
|
|
36
42
|
cursor: pointer;
|
|
37
|
-
transition: color var(--gooee-motion-base) var(--gooee-ease-
|
|
43
|
+
transition: color var(--gooee-motion-base) var(--gooee-ease-morph);
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
/* Narrow screens: a little less room around each tab, so a short row fits instead of scrolling. */
|
|
@@ -43,7 +49,7 @@
|
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
@media (hover: hover) {
|
|
46
|
-
.tab:hover:not(:disabled) { color: var(--gooee-color-fg);
|
|
52
|
+
.tab:hover:not(:disabled) { color: var(--gooee-color-fg); }
|
|
47
53
|
}
|
|
48
54
|
.tab[aria-selected="true"] { color: var(--gooee-color-fg); }
|
|
49
55
|
.tab:disabled { opacity: var(--gooee-disabled-opacity); cursor: not-allowed; }
|
|
@@ -53,49 +59,44 @@
|
|
|
53
59
|
box-shadow: inset 0 0 0 var(--gooee-line-focus) var(--gooee-color-fg);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
/* The rise: the panel's surface grown up behind the chosen tab, with rounded top corners and soft inside
|
|
63
|
+
corners where it meets the panel. */
|
|
64
|
+
.rise {
|
|
57
65
|
position: absolute;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
top: 0;
|
|
67
|
+
/* Down past the row by one corner: wherever the rise is, it fills the panel's round corner under it,
|
|
68
|
+
so the corner squares and rounds with the rise itself, never on its own. */
|
|
69
|
+
bottom: calc(var(--tabs-r) * -1);
|
|
70
|
+
border-radius: var(--tabs-r) var(--tabs-r) 0 0;
|
|
71
|
+
background: var(--tabs-panel);
|
|
63
72
|
pointer-events: none;
|
|
64
73
|
}
|
|
65
74
|
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
width var(--gooee-motion-morph-out) var(--gooee-ease-out);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/* A new tab flows the underline instead (internal/liquidMatter.ts useFlow): .liquid draws it meanwhile. */
|
|
73
|
-
.indicator[data-flowing] {
|
|
74
|
-
opacity: 0;
|
|
75
|
-
transition: none;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.liquid {
|
|
75
|
+
.rise::before,
|
|
76
|
+
.rise::after {
|
|
77
|
+
content: "";
|
|
79
78
|
position: absolute;
|
|
80
|
-
|
|
81
|
-
top: 0;
|
|
82
|
-
width: 100%;
|
|
83
|
-
height: 100%;
|
|
84
|
-
overflow: visible;
|
|
85
|
-
pointer-events: none;
|
|
79
|
+
bottom: var(--tabs-r);
|
|
86
80
|
}
|
|
81
|
+
/* The inside corners: their size is set each frame (Tabs.tsx) from how far the rise is from each end. */
|
|
82
|
+
.rise::before { --s: var(--tabs-in-start, var(--tabs-r)); right: 100%; width: var(--s); height: var(--s); background: radial-gradient(circle at 0 0, transparent var(--s), var(--tabs-panel) calc(var(--s) + 0.5px)); }
|
|
83
|
+
.rise::after { --s: var(--tabs-in-end, var(--tabs-r)); left: 100%; width: var(--s); height: var(--s); background: radial-gradient(circle at 100% 0, transparent var(--s), var(--tabs-panel) calc(var(--s) + 0.5px)); }
|
|
84
|
+
/* Past either end of the row an inside corner is clipped by the row itself, so it never shows outside the panel. */
|
|
87
85
|
|
|
88
86
|
.panel {
|
|
89
|
-
padding
|
|
90
|
-
border-radius: var(--
|
|
91
|
-
|
|
87
|
+
padding: var(--gooee-space-6);
|
|
88
|
+
border-radius: var(--tabs-corner-start, var(--tabs-r)) var(--tabs-corner-end, var(--tabs-r)) var(--tabs-r) var(--tabs-r);
|
|
89
|
+
background: var(--tabs-panel);
|
|
92
90
|
}
|
|
93
91
|
|
|
92
|
+
/* Only the words fade in, in place. The panel never moves or fades, so it stays one shape with the rise. */
|
|
93
|
+
.panel > * { animation: panelIn var(--gooee-motion-slow) var(--gooee-ease-morph); }
|
|
94
|
+
|
|
94
95
|
.panel:focus-visible {
|
|
95
96
|
outline: none;
|
|
96
97
|
box-shadow: var(--gooee-focus-ring);
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
@keyframes panelIn {
|
|
100
|
-
from { opacity: 0;
|
|
101
|
+
from { opacity: 0; }
|
|
101
102
|
}
|
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
type KeyboardEvent,
|
|
11
11
|
type ReactNode,
|
|
12
12
|
} from 'react'
|
|
13
|
-
import { prefersReducedMotion } from '../../internal/motion'
|
|
13
|
+
import { morphCurve, motionMs, prefersReducedMotion } from '../../internal/motion'
|
|
14
|
+
import { bezier } from '../../internal/feel'
|
|
14
15
|
import { cx } from '../../internal/cx'
|
|
15
|
-
import { useFlow } from '../../internal/liquidMatter'
|
|
16
16
|
import { useControllable } from '../../internal/useControllable'
|
|
17
17
|
import styles from './Tabs.module.css'
|
|
18
18
|
|
|
@@ -44,7 +44,9 @@ export function Tabs({ value: valueProp, defaultValue, onValueChange, className,
|
|
|
44
44
|
const [value, set] = useControllable(valueProp, defaultValue, onValueChange)
|
|
45
45
|
return (
|
|
46
46
|
<TabsCtx.Provider value={{ value, set, baseId }}>
|
|
47
|
-
<div className={cx(styles.root, className)}>
|
|
47
|
+
<div className={cx(styles.root, className)} data-gooee-tabs="">
|
|
48
|
+
{children}
|
|
49
|
+
</div>
|
|
48
50
|
</TabsCtx.Provider>
|
|
49
51
|
)
|
|
50
52
|
}
|
|
@@ -61,15 +63,14 @@ export type TabListProps = {
|
|
|
61
63
|
export function TabList({ label, className, children }: TabListProps) {
|
|
62
64
|
const { value } = useTabs()
|
|
63
65
|
const listRef = useRef<HTMLDivElement>(null)
|
|
64
|
-
const [bar, setBar] = useState<{ x: number; w: number } | null>(null)
|
|
65
|
-
const [ready, setReady] = useState(false)
|
|
66
|
+
const [bar, setBar] = useState<{ x: number; w: number; room: number; value: string } | null>(null)
|
|
66
67
|
|
|
67
68
|
useLayoutEffect(() => {
|
|
68
69
|
const list = listRef.current
|
|
69
70
|
if (!list) return
|
|
70
71
|
const measure = () => {
|
|
71
72
|
const el = list.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
|
|
72
|
-
if (el) setBar({ x: el.offsetLeft, w: el.offsetWidth })
|
|
73
|
+
if (el) setBar({ x: el.offsetLeft, w: el.offsetWidth, room: list.offsetWidth, value })
|
|
73
74
|
}
|
|
74
75
|
measure()
|
|
75
76
|
const ro = new ResizeObserver(measure)
|
|
@@ -85,16 +86,64 @@ export function TabList({ label, className, children }: TabListProps) {
|
|
|
85
86
|
for (const t of tabs) t.tabIndex = t === stop ? 0 : -1
|
|
86
87
|
})
|
|
87
88
|
|
|
89
|
+
// The rise moves by script, so each frame knows how far each edge is from the row's ends. Near an end
|
|
90
|
+
// the panel's corner and the rise's inside corner shrink together; at the end the rise and the panel
|
|
91
|
+
// share one straight edge.
|
|
92
|
+
const riseRef = useRef<HTMLSpanElement>(null)
|
|
93
|
+
const drawn = useRef<{ l: number; r: number; value: string } | null>(null)
|
|
94
|
+
const raf = useRef(0)
|
|
95
|
+
// Where a running move is heading. A re-measure of the same tab (the size watcher reports once more
|
|
96
|
+
// after every change) only updates this; it never restarts or cuts the move short.
|
|
97
|
+
const aim = useRef<{ l: number; r: number; value: string } | null>(null)
|
|
88
98
|
useLayoutEffect(() => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
const rise = riseRef.current
|
|
100
|
+
const root = listRef.current?.closest<HTMLElement>('[data-gooee-tabs]')
|
|
101
|
+
if (!bar || !rise || !root) return
|
|
102
|
+
const R = parseFloat(getComputedStyle(root).getPropertyValue('--tabs-r')) || 0
|
|
103
|
+
// Within two corners of an end, the panel's corner and the inside corner each take half the room, so
|
|
104
|
+
// they meet as one even S; at the end both are gone.
|
|
105
|
+
const curve = (gap: number) => `${Math.max(0, Math.min(R, gap / 2))}px`
|
|
106
|
+
const draw = (l: number, r: number) => {
|
|
107
|
+
rise.style.left = `${l}px`
|
|
108
|
+
rise.style.right = `${r}px`
|
|
109
|
+
rise.style.setProperty('--tabs-in-start', curve(l))
|
|
110
|
+
rise.style.setProperty('--tabs-in-end', curve(r))
|
|
111
|
+
root.style.setProperty('--tabs-corner-start', curve(l))
|
|
112
|
+
root.style.setProperty('--tabs-corner-end', curve(r))
|
|
113
|
+
drawn.current = { l, r, value: aim.current?.value ?? bar.value }
|
|
92
114
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
115
|
+
const to = { l: bar.x, r: bar.room - bar.x - bar.w }
|
|
116
|
+
if (aim.current?.value === bar.value) {
|
|
117
|
+
aim.current = { ...to, value: bar.value }
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
const from = drawn.current
|
|
121
|
+
cancelAnimationFrame(raf.current)
|
|
122
|
+
aim.current = null
|
|
123
|
+
const length = motionMs('morph-out')
|
|
124
|
+
// Only a new choice moves; a resize or the first paint just puts it in place.
|
|
125
|
+
if (!from || from.value === bar.value || !length || prefersReducedMotion()) return draw(to.l, to.r)
|
|
126
|
+
// The edge on the way leads; the other follows a beat later, so the rise stretches, then settles.
|
|
127
|
+
const lag = motionMs('instant')
|
|
128
|
+
const ease = bezier(morphCurve())
|
|
129
|
+
const toEnd = to.l > from.l
|
|
130
|
+
const t0 = performance.now()
|
|
131
|
+
aim.current = { ...to, value: bar.value }
|
|
132
|
+
const step = (now: number) => {
|
|
133
|
+
const at = aim.current
|
|
134
|
+
if (!at) return
|
|
135
|
+
const t = now - t0
|
|
136
|
+
const lead = ease(Math.min(1, t / length))
|
|
137
|
+
const trail = ease(Math.min(1, Math.max(0, (t - lag) / length)))
|
|
138
|
+
const ul = toEnd ? trail : lead
|
|
139
|
+
const ur = toEnd ? lead : trail
|
|
140
|
+
draw(from.l + (at.l - from.l) * ul, from.r + (at.r - from.r) * ur)
|
|
141
|
+
if (t < length + lag) raf.current = requestAnimationFrame(step)
|
|
142
|
+
else aim.current = null
|
|
143
|
+
}
|
|
144
|
+
raf.current = requestAnimationFrame(step)
|
|
145
|
+
}, [bar])
|
|
146
|
+
useLayoutEffect(() => () => cancelAnimationFrame(raf.current), [])
|
|
98
147
|
|
|
99
148
|
// Automatic activation, per the WAI-ARIA tabs pattern
|
|
100
149
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
@@ -117,13 +166,7 @@ export function TabList({ label, className, children }: TabListProps) {
|
|
|
117
166
|
<div ref={listRef} role="tablist" aria-label={label} className={styles.list} onKeyDown={onKeyDown}>
|
|
118
167
|
{children}
|
|
119
168
|
{bar && (
|
|
120
|
-
<span
|
|
121
|
-
ref={barRef}
|
|
122
|
-
className={styles.indicator}
|
|
123
|
-
data-ready={ready || undefined}
|
|
124
|
-
style={{ transform: `translateX(${bar.x}px)`, width: bar.w }}
|
|
125
|
-
aria-hidden="true"
|
|
126
|
-
/>
|
|
169
|
+
<span ref={riseRef} className={styles.rise} aria-hidden="true" />
|
|
127
170
|
)}
|
|
128
171
|
</div>
|
|
129
172
|
</div>
|
|
@@ -27,8 +27,10 @@
|
|
|
27
27
|
display: block;
|
|
28
28
|
width: 100%;
|
|
29
29
|
resize: none;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
/* The line's width lives in --edge, so the padding takes it back and the words never move when it thickens. */
|
|
31
|
+
--edge: var(--gooee-line);
|
|
32
|
+
padding: calc(var(--gooee-space-4) - var(--edge)) calc(var(--gooee-space-5) - var(--edge));
|
|
33
|
+
border: var(--edge) solid var(--gooee-color-border-strong);
|
|
32
34
|
border-radius: var(--gooee-radius-md);
|
|
33
35
|
background: var(--gooee-color-surface);
|
|
34
36
|
font-size: var(--gooee-text-input);
|
|
@@ -67,7 +69,7 @@
|
|
|
67
69
|
.textarea[data-invalid] {
|
|
68
70
|
--gooee-flow-edge: var(--gooee-color-danger);
|
|
69
71
|
border-color: var(--gooee-color-danger);
|
|
70
|
-
|
|
72
|
+
--edge: var(--gooee-line-thick);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
.textarea[data-invalid][data-edge] { box-shadow: inset 0 0 0 calc(var(--gooee-line-focus) - var(--gooee-line-thick)) var(--gooee-flow-edge); }
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
1
|
+
/* One shape: the sun's disc grows and a bite slides over it into the moon's crescent, with the rays
|
|
2
|
+
drawing back in first (ThemeToggle.tsx draws every frame). */
|
|
3
3
|
.icon {
|
|
4
|
-
display: grid;
|
|
5
4
|
width: 1em;
|
|
6
5
|
height: 1em;
|
|
6
|
+
overflow: visible;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
width: 100%;
|
|
13
|
-
height: 100%;
|
|
14
|
-
transition:
|
|
15
|
-
transform var(--gooee-motion-slower) var(--gooee-ease-spring),
|
|
16
|
-
opacity var(--gooee-motion-base) var(--gooee-ease-out);
|
|
9
|
+
.rays {
|
|
10
|
+
transform-box: view-box;
|
|
11
|
+
transform-origin: 50% 50%;
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
/* Shows the theme the button switches to: the moon in light, the sun in dark. */
|
|
20
|
-
.icon:not([data-theme-shown="dark"]) .sun { opacity: 0; transform: rotate(90deg) scale(0.4); }
|
|
21
|
-
.icon[data-theme-shown="dark"] .moon { opacity: 0; transform: rotate(-90deg) scale(0.4); }
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useEffect, useState } from 'react'
|
|
4
|
-
import {
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef, useState, type MouseEvent } from 'react'
|
|
4
|
+
import { bezier } from '../../internal/feel'
|
|
5
|
+
import { morphCurve, motionMs, prefersReducedMotion } from '../../internal/motion'
|
|
6
|
+
import { themeReveal } from '../../internal/themeReveal'
|
|
5
7
|
import { IconButton } from '../IconButton'
|
|
6
8
|
import styles from './ThemeToggle.module.css'
|
|
7
9
|
|
|
@@ -14,6 +16,8 @@ export type ThemeToggleProps = {
|
|
|
14
16
|
onThemeChange?: (theme: Theme) => void
|
|
15
17
|
/** Where the choice is remembered when the toggle runs the page. Match it in themeScript. */
|
|
16
18
|
storageKey?: string
|
|
19
|
+
/** The new theme grows from the button in a circle over the screen. Turn it off for an instant change. */
|
|
20
|
+
reveal?: boolean
|
|
17
21
|
/** The button's size, the same as IconButton. */
|
|
18
22
|
size?: 'sm' | 'md' | 'lg'
|
|
19
23
|
/** Extra class for the button. */
|
|
@@ -24,10 +28,57 @@ export type ThemeToggleProps = {
|
|
|
24
28
|
export const themeScript = (storageKey = 'gooee-theme') =>
|
|
25
29
|
`try{var t=localStorage.getItem(${JSON.stringify(storageKey)});if(t!=='light'&&t!=='dark')t=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';document.documentElement.dataset.theme=t}catch(e){}`
|
|
26
30
|
|
|
31
|
+
// Sun to moon the way the real moon works: a round disc with a shadow passing over it. The disc stays
|
|
32
|
+
// round and grows from the sun's size to the moon's; a second circle, the bite, slides in from the top
|
|
33
|
+
// right and carves the crescent. The outline is drawn exactly each frame as "disc minus bite", so every
|
|
34
|
+
// frame is a true shape. The rays draw back into the disc and fade first, before it grows into them.
|
|
35
|
+
const C = 12
|
|
36
|
+
const lerp = (a: number, b: number, t: number) => a + (b - a) * t
|
|
37
|
+
const part = (t: number, a: number, b: number) => Math.min(1, Math.max(0, (t - a) / (b - a)))
|
|
38
|
+
const f = (n: number) => Math.round(n * 100) / 100
|
|
39
|
+
const BITE = 7
|
|
40
|
+
const TOWARD = -Math.PI / 4
|
|
41
|
+
function bodyAt(t: number) {
|
|
42
|
+
const r = lerp(4, 8, part(t, 0.2, 1))
|
|
43
|
+
// The bite starts clear of the disc and ends 5.6 from its centre.
|
|
44
|
+
const d = lerp(r + BITE + 1, 5.6, part(t, 0.15, 1))
|
|
45
|
+
if (d >= r + BITE) return `M${C - r} ${C}A${f(r)} ${f(r)} 0 1 1 ${C + r} ${C}A${f(r)} ${f(r)} 0 1 1 ${C - r} ${C}Z`
|
|
46
|
+
const half = Math.acos((r * r + d * d - BITE * BITE) / (2 * r * d))
|
|
47
|
+
const at = (o: [number, number], rad: number, ang: number): [number, number] => [o[0] + rad * Math.cos(ang), o[1] + rad * Math.sin(ang)]
|
|
48
|
+
const centre: [number, number] = [C, C]
|
|
49
|
+
const bite = at(centre, d, TOWARD)
|
|
50
|
+
const A = at(centre, r, TOWARD + half)
|
|
51
|
+
const B = at(centre, r, TOWARD - half)
|
|
52
|
+
// The disc's edge from A the long way round to B, then the bite's edge back to A through the disc.
|
|
53
|
+
const outer = 2 * Math.PI - 2 * half
|
|
54
|
+
// Of the two ways round the bite from B to A, the one whose middle lies inside the disc.
|
|
55
|
+
const angA = Math.atan2(A[1] - bite[1], A[0] - bite[0])
|
|
56
|
+
const angB = Math.atan2(B[1] - bite[1], B[0] - bite[0])
|
|
57
|
+
const up = (((angA - angB) % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI)
|
|
58
|
+
const mid = at(bite, BITE, angB + up / 2)
|
|
59
|
+
const sweep = Math.hypot(mid[0] - C, mid[1] - C) < r ? 1 : 0
|
|
60
|
+
const inner = sweep ? up : 2 * Math.PI - up
|
|
61
|
+
return `M${f(A[0])} ${f(A[1])}A${f(r)} ${f(r)} 0 ${outer > Math.PI ? 1 : 0} 1 ${f(B[0])} ${f(B[1])}A${BITE} ${BITE} 0 ${inner > Math.PI ? 1 : 0} ${sweep} ${f(A[0])} ${f(A[1])}Z`
|
|
62
|
+
}
|
|
63
|
+
const RAYS = Array.from({ length: 8 }, (_, i) => {
|
|
64
|
+
const a = (i * Math.PI) / 4
|
|
65
|
+
return `M${f(C + 7 * Math.cos(a))} ${f(C + 7 * Math.sin(a))}L${f(C + 9.5 * Math.cos(a))} ${f(C + 9.5 * Math.sin(a))}`
|
|
66
|
+
}).join('')
|
|
67
|
+
// The rays draw in toward the disc, turn a little and fade, all within the first 40%.
|
|
68
|
+
const raysAt = (t: number) => {
|
|
69
|
+
const k = part(t, 0, 0.4)
|
|
70
|
+
return { transform: `rotate(${f(-30 * k)}deg) scale(${f(1 - 0.45 * k)})`, opacity: String(f(1 - k)) }
|
|
71
|
+
}
|
|
72
|
+
function draw(body: SVGPathElement, t: number) {
|
|
73
|
+
body.setAttribute('d', bodyAt(t))
|
|
74
|
+
const rays = body.nextElementSibling as SVGPathElement | null
|
|
75
|
+
if (rays) Object.assign(rays.style, raysAt(t))
|
|
76
|
+
}
|
|
77
|
+
|
|
27
78
|
const pageTheme = (): Theme => (document.documentElement.dataset.theme === 'dark' ? 'dark' : 'light')
|
|
28
79
|
|
|
29
|
-
// One button that flips between the light and dark theme. The sun
|
|
30
|
-
export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'gooee-theme', size = 'sm', className }: ThemeToggleProps) {
|
|
80
|
+
// One button that flips between the light and dark theme. The sun morphs into the moon and back.
|
|
81
|
+
export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'gooee-theme', reveal = true, size = 'sm', className }: ThemeToggleProps) {
|
|
31
82
|
const controlled = themeProp !== undefined
|
|
32
83
|
const [own, setOwn] = useState<Theme>('light')
|
|
33
84
|
const theme = controlled ? themeProp : own
|
|
@@ -38,7 +89,55 @@ export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'goo
|
|
|
38
89
|
}, [controlled])
|
|
39
90
|
|
|
40
91
|
const next: Theme = theme === 'dark' ? 'light' : 'dark'
|
|
41
|
-
|
|
92
|
+
// Shows the theme the button switches to: the moon in light, the sun in dark. The body morphs on the
|
|
93
|
+
// morph curve, in the reveal's time, so the icon and the circle end together; the rays are drawn on
|
|
94
|
+
// the same frames.
|
|
95
|
+
const body = useRef<SVGPathElement>(null)
|
|
96
|
+
const shown = useRef(theme === 'dark' ? 0 : 1)
|
|
97
|
+
const aim = useRef(shown.current)
|
|
98
|
+
const raf = useRef(0)
|
|
99
|
+
const morphTo = (to: number) => {
|
|
100
|
+
const el = body.current
|
|
101
|
+
aim.current = to
|
|
102
|
+
cancelAnimationFrame(raf.current)
|
|
103
|
+
if (!el) return
|
|
104
|
+
const from = shown.current
|
|
105
|
+
const length = motionMs('reveal')
|
|
106
|
+
if (from === to || !length || prefersReducedMotion()) {
|
|
107
|
+
shown.current = to
|
|
108
|
+
draw(el, to)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
const ease = bezier(morphCurve())
|
|
112
|
+
const t0 = performance.now()
|
|
113
|
+
const step = (now: number) => {
|
|
114
|
+
const u = Math.min(1, (now - t0) / length)
|
|
115
|
+
shown.current = from + (to - from) * ease(u)
|
|
116
|
+
draw(el, shown.current)
|
|
117
|
+
if (u < 1) raf.current = requestAnimationFrame(step)
|
|
118
|
+
}
|
|
119
|
+
raf.current = requestAnimationFrame(step)
|
|
120
|
+
}
|
|
121
|
+
// A theme set from outside (or the first paint): morph to it, unless a press already started that morph.
|
|
122
|
+
useLayoutEffect(() => {
|
|
123
|
+
const to = theme === 'dark' ? 0 : 1
|
|
124
|
+
if (aim.current !== to) morphTo(to)
|
|
125
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
126
|
+
}, [theme])
|
|
127
|
+
useLayoutEffect(() => () => cancelAnimationFrame(raf.current), [])
|
|
128
|
+
// The icon answers the press at once; the theme change, and its circle, start two frames later, so
|
|
129
|
+
// the first motion is on screen before the page is held still to be photographed.
|
|
130
|
+
const flip = (e: MouseEvent<HTMLButtonElement>) => {
|
|
131
|
+
const origin = e.currentTarget
|
|
132
|
+
morphTo(next === 'dark' ? 0 : 1)
|
|
133
|
+
requestAnimationFrame(() =>
|
|
134
|
+
requestAnimationFrame(() => {
|
|
135
|
+
if (reveal) themeReveal(origin, apply)
|
|
136
|
+
else apply()
|
|
137
|
+
}),
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
const apply = () => {
|
|
42
141
|
if (!controlled) {
|
|
43
142
|
document.documentElement.dataset.theme = next
|
|
44
143
|
try {
|
|
@@ -59,10 +158,10 @@ export function ThemeToggle({ theme: themeProp, onThemeChange, storageKey = 'goo
|
|
|
59
158
|
className={className}
|
|
60
159
|
onClick={flip}
|
|
61
160
|
icon={
|
|
62
|
-
<
|
|
63
|
-
<
|
|
64
|
-
<
|
|
65
|
-
</
|
|
161
|
+
<svg className={styles.icon} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
|
|
162
|
+
<path ref={body} d={bodyAt(shown.current)} />
|
|
163
|
+
<path className={styles.rays} d={RAYS} style={raysAt(shown.current)} />
|
|
164
|
+
</svg>
|
|
66
165
|
}
|
|
67
166
|
/>
|
|
68
167
|
)
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
display: flex;
|
|
47
47
|
align-items: flex-start;
|
|
48
48
|
gap: var(--gooee-space-4);
|
|
49
|
-
padding: var(--gooee-space-5) var(--gooee-space-2) var(--gooee-space-5) var(--gooee-space-5);
|
|
49
|
+
padding: calc(var(--gooee-space-5) - var(--gooee-line)) calc(var(--gooee-space-2) - var(--gooee-line)) calc(var(--gooee-space-5) - var(--gooee-line)) calc(var(--gooee-space-5) - var(--gooee-line));
|
|
50
50
|
border: var(--gooee-line) solid var(--gooee-glass-edge, var(--gooee-color-border));
|
|
51
51
|
border-radius: var(--gooee-radius-md);
|
|
52
52
|
background: var(--gooee-glass-bg, var(--gooee-color-surface));
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
flex: none;
|
|
125
125
|
align-self: center;
|
|
126
126
|
min-height: var(--gooee-control-h-sm);
|
|
127
|
-
padding: 0 var(--gooee-space-4);
|
|
127
|
+
padding: 0 calc(var(--gooee-space-4) - var(--gooee-line));
|
|
128
128
|
border: var(--gooee-line) solid var(--gooee-color-border-strong);
|
|
129
129
|
border-radius: var(--gooee-radius-control);
|
|
130
130
|
background: transparent;
|
|
@@ -148,12 +148,12 @@
|
|
|
148
148
|
.action:focus-visible { outline: none; box-shadow: var(--gooee-focus-ring); }
|
|
149
149
|
|
|
150
150
|
.close {
|
|
151
|
+
position: relative;
|
|
151
152
|
display: grid;
|
|
152
153
|
place-items: center;
|
|
153
154
|
flex: none;
|
|
154
|
-
width: var(--gooee-
|
|
155
|
-
height: var(--gooee-
|
|
156
|
-
margin-block: calc(var(--gooee-space-4) * -1);
|
|
155
|
+
width: var(--gooee-control-h-sm);
|
|
156
|
+
height: var(--gooee-control-h-sm);
|
|
157
157
|
padding: 0;
|
|
158
158
|
border: 0;
|
|
159
159
|
border-radius: var(--gooee-radius-full);
|
|
@@ -164,6 +164,9 @@
|
|
|
164
164
|
transition: background-color var(--gooee-motion-fast) var(--gooee-ease-out);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
/* Looks 32px, keeps a 44px touch area. */
|
|
168
|
+
.close::after { content: ""; position: absolute; inset: calc((var(--gooee-control-h-sm) - var(--gooee-hit-min)) / 2); border-radius: inherit; }
|
|
169
|
+
|
|
167
170
|
@media (hover: hover) {
|
|
168
171
|
.close:hover { background: var(--gooee-color-surface-hover); color: var(--gooee-color-fg); }
|
|
169
172
|
}
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
gap: var(--gooee-space-3);
|
|
8
8
|
flex: none;
|
|
9
9
|
min-height: var(--h);
|
|
10
|
-
padding: 0 var(--gooee-space-6);
|
|
10
|
+
padding: 0 calc(var(--gooee-space-6) - var(--gooee-line));
|
|
11
11
|
border: var(--gooee-line) solid var(--gooee-color-border-strong);
|
|
12
12
|
border-radius: var(--gooee-radius-control);
|
|
13
13
|
background: var(--gooee-color-surface);
|
|
14
14
|
color: var(--gooee-color-fg);
|
|
15
15
|
font-size: var(--gooee-text-md);
|
|
16
16
|
font-weight: var(--gooee-weight-medium);
|
|
17
|
-
line-height:
|
|
17
|
+
line-height: var(--gooee-leading-none);
|
|
18
18
|
white-space: nowrap;
|
|
19
19
|
cursor: pointer;
|
|
20
20
|
user-select: none;
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
.root::after { inset-inline: min(0px, calc((100% - var(--gooee-hit-min)) / 2)); }
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
.sm { --h: var(--gooee-control-h-sm); padding: 0 var(--gooee-space-5); font-size: var(--gooee-text-sm); }
|
|
43
|
-
.lg { --h: var(--gooee-control-h-lg); padding: 0 var(--gooee-space-8); font-size: var(--gooee-text-lg); }
|
|
42
|
+
.sm { --h: var(--gooee-control-h-sm); padding: 0 calc(var(--gooee-space-5) - var(--gooee-line)); font-size: var(--gooee-text-sm); }
|
|
43
|
+
.lg { --h: var(--gooee-control-h-lg); padding: 0 calc(var(--gooee-space-8) - var(--gooee-line)); font-size: var(--gooee-text-lg); }
|
|
44
44
|
|
|
45
45
|
.iconOnly {
|
|
46
46
|
width: var(--h);
|
package/src/internal/icons.tsx
CHANGED
|
@@ -223,6 +223,13 @@ export const PaletteIcon = (p: IconProps) => (
|
|
|
223
223
|
<circle cx="14.75" cy="7.75" r="1.1" fill="currentColor" stroke="none" />
|
|
224
224
|
</Svg>
|
|
225
225
|
)
|
|
226
|
+
// Lucide's ruler: a rule laid on a slant with four marks.
|
|
227
|
+
export const RulerIcon = (p: IconProps) => (
|
|
228
|
+
<Svg m="draw" {...p}>
|
|
229
|
+
<path d="M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z" />
|
|
230
|
+
<path d="m14.5 12.5 2-2M11.5 9.5l2-2M8.5 6.5l2-2M17.5 15.5l2-2" />
|
|
231
|
+
</Svg>
|
|
232
|
+
)
|
|
226
233
|
export const SlidersIcon = (p: IconProps) => (
|
|
227
234
|
<Svg m="bounce" {...p}>
|
|
228
235
|
<path d="M4 7h9M17 7h3M4 17h3M11 17h9" />
|
package/src/internal/motion.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MORPH, type Curve } from './feel'
|
|
2
2
|
|
|
3
|
-
export type MotionToken = 'instant' | 'fast' | 'base' | 'slow' | 'slower' | 'liquid' | 'morph' | 'morph-out' | 'fling' | 'delay-tooltip'
|
|
3
|
+
export type MotionToken = 'instant' | 'fast' | 'base' | 'slow' | 'slower' | 'liquid' | 'morph' | 'morph-out' | 'reveal' | 'fling' | 'delay-tooltip'
|
|
4
4
|
|
|
5
5
|
// Reads a duration token at run time, so reduced motion (0ms) and Retime's speed are honoured by JS
|
|
6
6
|
// timers too.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { flushSync } from 'react-dom'
|
|
2
|
+
import { easing, motionMs, prefersReducedMotion } from './motion'
|
|
3
|
+
|
|
4
|
+
// The new theme grows from the spot you pressed: the page is snapshot as it is, and the new page opens
|
|
5
|
+
// over it in a circle from the button's centre to the farthest corner, at an even pace. The old snapshot
|
|
6
|
+
// stays still under it, and no element plays its own colour change meanwhile, so nothing flips piece by
|
|
7
|
+
// piece. A second press finishes the running one first. Without View Transitions the page fades in once;
|
|
8
|
+
// with reduced motion it changes at once.
|
|
9
|
+
|
|
10
|
+
let running: ViewTransition | null = null
|
|
11
|
+
|
|
12
|
+
// The radius whose circle covers `share` of the screen, by halving, counted on a coarse grid.
|
|
13
|
+
function radiusFor(share: number, x: number, y: number, reach: number) {
|
|
14
|
+
if (share >= 1) return reach
|
|
15
|
+
const cols = 48, rows = 32
|
|
16
|
+
const covered = (r: number) => {
|
|
17
|
+
let n = 0
|
|
18
|
+
for (let j = 0; j < rows; j++) for (let i = 0; i < cols; i++) if (Math.hypot(((i + 0.5) * innerWidth) / cols - x, ((j + 0.5) * innerHeight) / rows - y) <= r) n++
|
|
19
|
+
return n / (cols * rows)
|
|
20
|
+
}
|
|
21
|
+
let lo = 0, hi = reach
|
|
22
|
+
for (let k = 0; k < 18; k++) {
|
|
23
|
+
const m = (lo + hi) / 2
|
|
24
|
+
if (covered(m) < share) lo = m
|
|
25
|
+
else hi = m
|
|
26
|
+
}
|
|
27
|
+
return hi
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function themeReveal(origin: Element | null, apply: () => void) {
|
|
31
|
+
const root = document.documentElement
|
|
32
|
+
const ms = motionMs('reveal')
|
|
33
|
+
if (prefersReducedMotion() || !ms) return flushSync(apply)
|
|
34
|
+
running?.skipTransition()
|
|
35
|
+
root.dataset.gooeeThemeSwitch = ''
|
|
36
|
+
const done = () => delete root.dataset.gooeeThemeSwitch
|
|
37
|
+
if (typeof document.startViewTransition !== 'function') {
|
|
38
|
+
flushSync(apply)
|
|
39
|
+
document.body.animate([{ opacity: 0.4 }, { opacity: 1 }], { duration: ms * 0.6, easing: easing('morph') }).finished.then(done, done)
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
const r = origin?.getBoundingClientRect()
|
|
43
|
+
const x = r ? r.left + r.width / 2 : innerWidth / 2
|
|
44
|
+
const y = r ? r.top + r.height / 2 : 0
|
|
45
|
+
const reach = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y))
|
|
46
|
+
const vt = document.startViewTransition(() => flushSync(apply))
|
|
47
|
+
running = vt
|
|
48
|
+
vt.ready.then(
|
|
49
|
+
// The share of the screen covered grows at an even, calm pace (ease out): a circle's area grows with
|
|
50
|
+
// the radius squared, so each step's radius is solved for its share; linear in between.
|
|
51
|
+
() =>
|
|
52
|
+
root.animate(
|
|
53
|
+
{ clipPath: Array.from({ length: 21 }, (_, i) => `circle(${radiusFor(1 - (1 - i / 20) ** 2, x, y, reach)}px at ${x}px ${y}px)`) },
|
|
54
|
+
{ duration: ms, easing: 'linear', pseudoElement: '::view-transition-new(root)' },
|
|
55
|
+
),
|
|
56
|
+
() => {},
|
|
57
|
+
)
|
|
58
|
+
vt.finished.finally(() => {
|
|
59
|
+
if (running !== vt) return
|
|
60
|
+
running = null
|
|
61
|
+
done()
|
|
62
|
+
})
|
|
63
|
+
}
|