gooee 0.41.1 → 0.45.1
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/README.md +1 -1
- package/package.json +1 -1
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +3 -3
- package/src/components/Badge/Badge.module.css +1 -1
- package/src/components/Button/Button.module.css +4 -4
- package/src/components/Dial/Dial.module.css +2 -2
- package/src/components/Dialog/Dialog.module.css +10 -4
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +37 -52
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +146 -60
- package/src/components/Kbd/Kbd.module.css +1 -1
- package/src/components/LivePill/LivePill.module.css +211 -31
- package/src/components/LivePill/LivePill.tsx +45 -14
- package/src/components/MorphButton/MorphButton.module.css +8 -4
- package/src/components/PickerWheel/PickerWheel.module.css +1 -1
- package/src/components/Popover/Popover.module.css +11 -3
- package/src/components/Prose/Prose.module.css +4 -2
- package/src/components/RulerScrubber/RulerScrubber.module.css +1 -1
- package/src/components/SegmentedControl/SegmentedControl.module.css +3 -3
- package/src/components/Sheet/Sheet.module.css +10 -3
- package/src/components/Skeleton/Skeleton.module.css +1 -1
- package/src/components/SplitFlap/SplitFlap.module.css +1 -1
- package/src/components/Switch/Switch.module.css +1 -1
- package/src/components/Tabs/Tabs.module.css +34 -33
- package/src/components/Tabs/Tabs.tsx +64 -21
- package/src/components/ThemeToggle/ThemeToggle.module.css +6 -15
- package/src/components/ThemeToggle/ThemeToggle.tsx +108 -9
- package/src/components/Toast/Toast.module.css +6 -3
- package/src/components/Toast/Toast.tsx +2 -2
- package/src/components/Toggle/Toggle.module.css +1 -1
- package/src/internal/liquidMatter.ts +42 -11
- package/src/internal/motion.ts +1 -1
- package/src/internal/themeReveal.ts +63 -0
- package/src/tokens.css +53 -15
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ Setup for other tools: [MCP server](https://gooee.dev/mcp).
|
|
|
89
89
|
|
|
90
90
|
## Pro
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
80 more components (such as the AI chat parts AssistantThread and PromptBar, DataGrid, Calendar, Chart, KanbanBoard and Combobox), page blocks, full templates and brand themes are coming as Gooee UI Pro. You can see them on the [docs site](https://gooee.dev).
|
|
93
93
|
|
|
94
94
|
## Licence
|
|
95
95
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
display: inline-flex;
|
|
3
3
|
width: fit-content;
|
|
4
4
|
font-variant-numeric: tabular-nums;
|
|
5
|
-
line-height:
|
|
5
|
+
line-height: var(--gooee-leading-tight);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.visual {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
.digit {
|
|
14
14
|
display: inline-block;
|
|
15
|
-
height:
|
|
15
|
+
height: var(--gooee-leading-tight);
|
|
16
16
|
overflow: hidden;
|
|
17
17
|
animation: enter var(--gooee-motion-slow) var(--gooee-ease-out);
|
|
18
18
|
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
.cell {
|
|
27
27
|
display: block;
|
|
28
|
-
height:
|
|
28
|
+
height: var(--gooee-leading-tight);
|
|
29
29
|
text-align: center;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
place-items: center;
|
|
9
9
|
max-width: 100%;
|
|
10
10
|
min-height: var(--h);
|
|
11
|
-
padding: 0 var(--gooee-
|
|
11
|
+
padding: 0 var(--gooee-control-pad-md);
|
|
12
12
|
--bg: transparent;
|
|
13
13
|
--line: transparent;
|
|
14
14
|
border: var(--gooee-line) solid var(--line);
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
background: var(--bg);
|
|
17
17
|
font-size: var(--gooee-text-md);
|
|
18
18
|
font-weight: var(--gooee-weight-medium);
|
|
19
|
-
line-height:
|
|
19
|
+
line-height: var(--gooee-leading-none);
|
|
20
20
|
text-decoration: none;
|
|
21
21
|
white-space: nowrap;
|
|
22
22
|
cursor: pointer;
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
cursor: progress;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
.sm { --h: var(--gooee-control-h-sm); padding: 0 var(--gooee-
|
|
95
|
-
.lg { --h: var(--gooee-control-h-lg); padding: 0 var(--gooee-
|
|
94
|
+
.sm { --h: var(--gooee-control-h-sm); padding: 0 var(--gooee-control-pad-sm); font-size: var(--gooee-text-sm); }
|
|
95
|
+
.lg { --h: var(--gooee-control-h-lg); padding: 0 var(--gooee-control-pad-lg); font-size: var(--gooee-text-lg); }
|
|
96
96
|
.full { display: grid; width: 100%; }
|
|
97
97
|
|
|
98
98
|
.primary {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
font-size: var(--gooee-text-4xl);
|
|
23
23
|
font-weight: var(--gooee-weight-semibold);
|
|
24
24
|
letter-spacing: var(--gooee-tracking-tight);
|
|
25
|
-
line-height:
|
|
25
|
+
line-height: var(--gooee-leading-none);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
.detail {
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
font-size: var(--gooee-text-sm);
|
|
177
177
|
font-variant-numeric: tabular-nums;
|
|
178
178
|
white-space: nowrap;
|
|
179
|
-
line-height:
|
|
179
|
+
line-height: var(--gooee-leading-none);
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
.cap {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
align-items: flex-start;
|
|
60
60
|
justify-content: space-between;
|
|
61
61
|
gap: var(--gooee-space-4);
|
|
62
|
-
padding: var(--gooee-space-7) var(--gooee-space-
|
|
62
|
+
padding: var(--gooee-space-7) calc(calc(var(--gooee-radius-panel) - var(--gooee-control-h-sm) / 2) + var(--gooee-control-h-sm) + var(--gooee-space-3)) 0 var(--gooee-space-7);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
.titles {
|
|
@@ -85,12 +85,15 @@
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
.close {
|
|
88
|
+
/* On the corner's own centre, so it follows the curve: inset = corner - half its size, less the border. */
|
|
89
|
+
position: absolute;
|
|
90
|
+
top: calc(var(--gooee-radius-panel) - var(--gooee-control-h-sm) / 2 - var(--gooee-line));
|
|
91
|
+
right: calc(var(--gooee-radius-panel) - var(--gooee-control-h-sm) / 2 - var(--gooee-line));
|
|
88
92
|
display: grid;
|
|
89
93
|
place-items: center;
|
|
90
94
|
flex: none;
|
|
91
|
-
width: var(--gooee-
|
|
92
|
-
height: var(--gooee-
|
|
93
|
-
margin-top: calc(var(--gooee-space-3) * -1);
|
|
95
|
+
width: var(--gooee-control-h-sm);
|
|
96
|
+
height: var(--gooee-control-h-sm);
|
|
94
97
|
padding: 0;
|
|
95
98
|
border: 0;
|
|
96
99
|
border-radius: var(--gooee-radius-full);
|
|
@@ -101,6 +104,9 @@
|
|
|
101
104
|
transition: background-color var(--gooee-motion-fast) var(--gooee-ease-out);
|
|
102
105
|
}
|
|
103
106
|
|
|
107
|
+
/* Looks 32px, keeps a 44px touch area. */
|
|
108
|
+
.close::after { content: ""; position: absolute; inset: calc((var(--gooee-control-h-sm) - var(--gooee-hit-min)) / 2); border-radius: inherit; }
|
|
109
|
+
|
|
104
110
|
/* Only the icon turns and presses. The button is square to the pointer even though it looks round,
|
|
105
111
|
so turning it would move its corners out from under the pointer and make it flicker. */
|
|
106
112
|
.close svg { transition: transform var(--gooee-motion-slow) var(--gooee-ease-spring); }
|
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
min-width: 0;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
.row {
|
|
10
|
+
position: relative;
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: var(--gooee-space-2);
|
|
14
|
+
max-width: 100%;
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
.shell {
|
|
10
18
|
position: relative;
|
|
11
19
|
display: flex;
|
|
@@ -23,14 +31,19 @@
|
|
|
23
31
|
box-shadow var(--gooee-motion-fast) var(--gooee-ease-morph);
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
/* The
|
|
34
|
+
/* The confirm step: the button itself turns red in place and confirms on the next press. Its words stay. */
|
|
27
35
|
.shell[data-phase="step"] {
|
|
36
|
+
background: var(--gooee-color-danger-solid);
|
|
37
|
+
box-shadow: none;
|
|
28
38
|
transition:
|
|
29
|
-
|
|
30
|
-
height var(--gooee-motion-morph) var(--gooee-ease-morph),
|
|
31
|
-
border-radius var(--gooee-motion-morph) var(--gooee-ease-morph),
|
|
39
|
+
background-color var(--gooee-motion-base) var(--gooee-ease-morph),
|
|
32
40
|
box-shadow var(--gooee-motion-fast) var(--gooee-ease-morph);
|
|
33
41
|
}
|
|
42
|
+
.shell[data-phase="step"] .main { color: var(--gooee-color-on-danger); }
|
|
43
|
+
@media (hover: hover) {
|
|
44
|
+
.shell[data-phase="step"]:hover { background: var(--gooee-color-danger-solid-hover); }
|
|
45
|
+
}
|
|
46
|
+
.shell[data-phase="step"]:has(.main:focus-visible) { box-shadow: var(--gooee-focus-ring); }
|
|
34
47
|
|
|
35
48
|
.shell:has(.main:focus-visible) {
|
|
36
49
|
box-shadow: inset 0 0 0 var(--gooee-line-thick) var(--gooee-color-border-strong), var(--gooee-focus-ring);
|
|
@@ -60,19 +73,9 @@
|
|
|
60
73
|
outline: none;
|
|
61
74
|
}
|
|
62
75
|
|
|
63
|
-
.shell[data-phase="step"] .main,
|
|
64
76
|
.shell[data-phase="done"] .main { cursor: default; }
|
|
65
77
|
.shell[data-disabled] .main { cursor: not-allowed; }
|
|
66
78
|
|
|
67
|
-
.shell[data-stack] {
|
|
68
|
-
flex-direction: column;
|
|
69
|
-
align-items: flex-start;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.shell[data-stack][data-phase="step"] { border-radius: var(--gooee-radius-panel); }
|
|
73
|
-
.shell[data-stack] .main { height: var(--gooee-control-h-lg); }
|
|
74
|
-
.shell[data-stack] .step { padding: 0 var(--gooee-space-2) var(--gooee-space-2); }
|
|
75
|
-
|
|
76
79
|
.faces { display: grid; }
|
|
77
80
|
|
|
78
81
|
.face {
|
|
@@ -108,57 +111,39 @@
|
|
|
108
111
|
opacity: 0;
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
.
|
|
112
|
-
display: flex;
|
|
113
|
-
flex: none;
|
|
114
|
-
align-items: center;
|
|
115
|
-
gap: var(--gooee-space-2);
|
|
116
|
-
padding-right: var(--gooee-space-1);
|
|
117
|
-
}
|
|
114
|
+
.main { transition: color var(--gooee-motion-base) var(--gooee-ease-morph); }
|
|
118
115
|
|
|
119
|
-
.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
height: var(--gooee-
|
|
127
|
-
padding: 0
|
|
116
|
+
/* Cancel: a round button beside the red one, as tall as the pill. It buds out of the pill's edge
|
|
117
|
+
(HoldToConfirm.tsx draws the drop); closed, it takes no room and no focus. */
|
|
118
|
+
.cancel {
|
|
119
|
+
display: inline-grid;
|
|
120
|
+
flex: none;
|
|
121
|
+
place-items: center;
|
|
122
|
+
width: var(--gooee-control-h-lg);
|
|
123
|
+
height: var(--gooee-control-h-lg);
|
|
124
|
+
padding: 0;
|
|
128
125
|
border: 0;
|
|
129
126
|
border-radius: var(--gooee-radius-full);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
background: var(--gooee-color-surface);
|
|
128
|
+
box-shadow: inset 0 0 0 var(--gooee-line-thick) var(--gooee-color-border-strong);
|
|
129
|
+
color: var(--gooee-color-fg);
|
|
133
130
|
cursor: pointer;
|
|
134
131
|
outline: none;
|
|
135
132
|
transition: background-color var(--gooee-motion-fast) var(--gooee-ease-out);
|
|
136
133
|
}
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
color: var(--gooee-color-fg);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
.confirm {
|
|
144
|
-
background: var(--gooee-color-danger-solid);
|
|
145
|
-
color: var(--gooee-color-on-danger);
|
|
146
|
-
}
|
|
147
|
-
|
|
134
|
+
.cancel svg { width: var(--gooee-icon-md); height: var(--gooee-icon-md); }
|
|
135
|
+
/* Closed it takes no room, but stays on its open spot, so the drop flows back from where it was. */
|
|
136
|
+
.cancel[inert] { position: absolute; top: 0; left: calc(100% + var(--gooee-space-2)); visibility: hidden; }
|
|
148
137
|
@media (hover: hover) {
|
|
149
138
|
.cancel:hover { background: var(--gooee-color-surface-hover); }
|
|
150
|
-
.confirm:hover { background: var(--gooee-color-danger-solid-hover); }
|
|
151
139
|
}
|
|
140
|
+
.cancel:focus-visible { box-shadow: inset 0 0 0 var(--gooee-line-thick) var(--gooee-color-border-strong), var(--gooee-focus-ring); }
|
|
152
141
|
|
|
153
|
-
.
|
|
154
|
-
.
|
|
155
|
-
box-shadow:
|
|
156
|
-
inset 0 0 0 var(--gooee-line-focus) var(--gooee-color-fg),
|
|
157
|
-
inset 0 0 0 calc(var(--gooee-line-focus) * 2) var(--gooee-color-surface);
|
|
158
|
-
}
|
|
142
|
+
/* The drawn drop, over the row while it moves. */
|
|
143
|
+
.bud { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 1; }
|
|
159
144
|
|
|
160
145
|
.hint {
|
|
161
|
-
min-height: calc(var(--gooee-text-sm) * var(--gooee-leading-snug) * 2);
|
|
146
|
+
min-height: calc(round(nearest, var(--gooee-text-sm) * var(--gooee-leading-snug-ratio), 4px) * 2);
|
|
162
147
|
margin: 0;
|
|
163
148
|
color: var(--gooee-color-fg-muted);
|
|
164
149
|
font-size: var(--gooee-text-sm);
|
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useId, useLayoutEffect, useRef, useState, type KeyboardEvent, type MouseEvent, type PointerEvent, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
|
-
import { CheckIcon } from '../../internal/icons'
|
|
5
|
+
import { CheckIcon, XIcon } from '../../internal/icons'
|
|
6
6
|
import { bezier } from '../../internal/feel'
|
|
7
7
|
import { morphCurve, prefersReducedMotion, readMotionMs } from '../../internal/motion'
|
|
8
|
+
import { frames, layer, morphEase, motionFor } from '../../internal/liquidMatter'
|
|
9
|
+
import { body, boxPath, lerp, loopsPath, pincher, seg, trace, type Box } from '../../internal/liquidPath'
|
|
8
10
|
import styles from './HoldToConfirm.module.css'
|
|
9
11
|
|
|
10
12
|
export type HoldToConfirmProps = {
|
|
11
13
|
/** The action, as the button's label, such as "Delete workspace". */
|
|
12
14
|
children: ReactNode
|
|
13
|
-
/** Called once the hold runs to the end, or
|
|
15
|
+
/** Called once the hold runs to the end, or the button is pressed again in the confirm step. */
|
|
14
16
|
onConfirm: () => void
|
|
15
17
|
/** Called when a hold is let go early, or the confirm step is cancelled. */
|
|
16
18
|
onCancel?: () => void
|
|
17
|
-
/** The confirm step's
|
|
19
|
+
/** The action as a verb for the confirm step's line, such as "Delete": "Press it again to delete, or Cancel." */
|
|
18
20
|
confirmLabel?: string
|
|
19
|
-
/** The confirm step
|
|
21
|
+
/** The name of the round cancel button that buds out beside it in the confirm step. */
|
|
20
22
|
cancelLabel?: string
|
|
21
23
|
/** Shown in place of the label once it is done, such as "Workspace deleted". */
|
|
22
24
|
doneLabel?: ReactNode
|
|
@@ -40,6 +42,72 @@ const HINT_AFTER = 300
|
|
|
40
42
|
const LEAVE = 16
|
|
41
43
|
// How long the done state shows before the button can be used again.
|
|
42
44
|
const DONE_FOR = 2400
|
|
45
|
+
// A click this soon after the step opens is the rest of a double-click, not a choice.
|
|
46
|
+
const GUARD = 500
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The cancel drop buds out of the button's right edge, its neck stretches and breaks, and it grows into
|
|
50
|
+
* the round cancel button (`in`), or flows back into the button (`out`). The button keeps its own look:
|
|
51
|
+
* the drawing is cut out where it is. Returns a stop, or null when motion is reduced.
|
|
52
|
+
*/
|
|
53
|
+
function bud(row: HTMLElement, shell: HTMLElement, x: HTMLElement, way: 'in' | 'out') {
|
|
54
|
+
const ms = motionFor(way === 'in' ? 'morph' : 'morph-out')
|
|
55
|
+
if (!ms) return null
|
|
56
|
+
const box = (el: HTMLElement): Box => {
|
|
57
|
+
const r = el.getBoundingClientRect(),
|
|
58
|
+
o = row.getBoundingClientRect()
|
|
59
|
+
return { cx: r.left - o.left + r.width / 2, cy: r.top - o.top + r.height / 2, hw: r.width / 2, hh: r.height / 2, r: r.height / 2 }
|
|
60
|
+
}
|
|
61
|
+
const O = box(shell)
|
|
62
|
+
const look = getComputedStyle(x)
|
|
63
|
+
const line = parseFloat(look.getPropertyValue('--gooee-line-thick')) || 1.5
|
|
64
|
+
const T = box(x)
|
|
65
|
+
const T2: Box = { ...T, hw: T.hw - line / 2, hh: T.hh - line / 2, r: T.r - line / 2 }
|
|
66
|
+
const { svg, paths } = layer(row, styles.bud, null)
|
|
67
|
+
const path = paths[0]
|
|
68
|
+
path.style.fill = look.backgroundColor
|
|
69
|
+
path.style.stroke = look.getPropertyValue('--gooee-color-border-strong')
|
|
70
|
+
path.style.strokeWidth = `${line}px`
|
|
71
|
+
const clip = svg.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'clipPath'))
|
|
72
|
+
clip.id = `gooee-hold-${Math.random().toString(36).slice(2)}`
|
|
73
|
+
const hole = clip.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'path'))
|
|
74
|
+
hole.setAttribute('clip-rule', 'evenodd')
|
|
75
|
+
hole.setAttribute('d', `M-4000 -4000H4000V4000H-4000Z${boxPath({ ...O, hw: O.hw + 0.5, hh: O.hh + 0.5, r: O.r + 0.5 })}`)
|
|
76
|
+
path.setAttribute('clip-path', `url(#${clip.id})`)
|
|
77
|
+
const e = morphEase()
|
|
78
|
+
const pin = pincher(e, motionFor('fast'))
|
|
79
|
+
const edge = O.cx + O.hw - O.hh
|
|
80
|
+
const r0 = O.hh * 0.45
|
|
81
|
+
x.style.opacity = '0'
|
|
82
|
+
const stop = frames(
|
|
83
|
+
ms,
|
|
84
|
+
(k, now) => {
|
|
85
|
+
const u = way === 'in' ? k : 1 - k
|
|
86
|
+
const f = e(u)
|
|
87
|
+
const r = lerp(r0, T2.hh, e(seg(u, 0.25, 1)))
|
|
88
|
+
const D: Box = { cx: lerp(O.cx + O.hw - r0, T2.cx, f), cy: O.cy, hw: r, hh: r, r }
|
|
89
|
+
const p = pin(body(O, [edge, O.cy]), body(D), now)
|
|
90
|
+
path.setAttribute(
|
|
91
|
+
'd',
|
|
92
|
+
loopsPath(
|
|
93
|
+
trace(p.sdf, [
|
|
94
|
+
[edge, O.cy, 0, 1],
|
|
95
|
+
[D.cx, D.cy, 0, 1],
|
|
96
|
+
]),
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
},
|
|
100
|
+
() => {
|
|
101
|
+
svg.remove()
|
|
102
|
+
x.style.opacity = ''
|
|
103
|
+
},
|
|
104
|
+
)
|
|
105
|
+
return () => {
|
|
106
|
+
stop()
|
|
107
|
+
svg.remove()
|
|
108
|
+
x.style.opacity = ''
|
|
109
|
+
}
|
|
110
|
+
}
|
|
43
111
|
|
|
44
112
|
// The pill's outline as one closed path that starts on the bottom edge at x and runs left first. The
|
|
45
113
|
// line is drawn at both ends of the path at once, so it burns out both ways from x and meets opposite.
|
|
@@ -76,11 +144,12 @@ export function HoldToConfirm({
|
|
|
76
144
|
const rootRef = useRef<HTMLDivElement>(null)
|
|
77
145
|
const shellRef = useRef<HTMLDivElement>(null)
|
|
78
146
|
const mainRef = useRef<HTMLButtonElement>(null)
|
|
79
|
-
const
|
|
147
|
+
const rowRef = useRef<HTMLDivElement>(null)
|
|
148
|
+
const stepAt = useRef(0)
|
|
80
149
|
const cancelRef = useRef<HTMLButtonElement>(null)
|
|
81
150
|
const runRef = useRef<SVGPathElement>(null)
|
|
82
151
|
const [phase, setPhase] = useState<Phase>('idle')
|
|
83
|
-
const [size, setSize] = useState({ w: 0, h: 0,
|
|
152
|
+
const [size, setSize] = useState({ w: 0, h: 0, inset: 1 })
|
|
84
153
|
const [path, setPath] = useState('')
|
|
85
154
|
const [keep, setKeep] = useState(false)
|
|
86
155
|
const [said, setSaid] = useState('')
|
|
@@ -97,20 +166,17 @@ export function HoldToConfirm({
|
|
|
97
166
|
useLayoutEffect(() => {
|
|
98
167
|
const root = rootRef.current
|
|
99
168
|
const main = mainRef.current
|
|
100
|
-
|
|
101
|
-
if (!root || !main || !step) return
|
|
169
|
+
if (!root || !main) return
|
|
102
170
|
const measure = () => {
|
|
103
171
|
const w = main.offsetWidth
|
|
104
172
|
const h = main.offsetHeight
|
|
105
173
|
const inset = parseFloat(getComputedStyle(root).getPropertyValue('--gooee-hold-stroke')) / 2 || 1
|
|
106
|
-
setSize({ w, h,
|
|
174
|
+
setSize({ w, h, inset })
|
|
107
175
|
setPath(outline(w, h, inset, w / 2))
|
|
108
176
|
}
|
|
109
177
|
measure()
|
|
110
178
|
const ro = new ResizeObserver(measure)
|
|
111
179
|
ro.observe(main)
|
|
112
|
-
ro.observe(step)
|
|
113
|
-
ro.observe(root)
|
|
114
180
|
return () => ro.disconnect()
|
|
115
181
|
}, [])
|
|
116
182
|
|
|
@@ -172,6 +238,7 @@ export function HoldToConfirm({
|
|
|
172
238
|
tapTimer.current = 0
|
|
173
239
|
cancelAnimationFrame(raf.current)
|
|
174
240
|
paint(0)
|
|
241
|
+
stepAt.current = performance.now()
|
|
175
242
|
setPhase('step')
|
|
176
243
|
}
|
|
177
244
|
|
|
@@ -192,6 +259,19 @@ export function HoldToConfirm({
|
|
|
192
259
|
return () => window.clearTimeout(t)
|
|
193
260
|
}, [phase])
|
|
194
261
|
|
|
262
|
+
// The cancel drop buds out when the step opens and flows back when it closes, either way.
|
|
263
|
+
const wasOpen = useRef(false)
|
|
264
|
+
useLayoutEffect(() => {
|
|
265
|
+
const isOpen = phase === 'step'
|
|
266
|
+
if (isOpen === wasOpen.current) return
|
|
267
|
+
wasOpen.current = isOpen
|
|
268
|
+
const row = rowRef.current,
|
|
269
|
+
shell = shellRef.current,
|
|
270
|
+
x = cancelRef.current
|
|
271
|
+
if (!row || !shell || !x) return
|
|
272
|
+
return bud(row, shell, x, isOpen ? 'in' : 'out') ?? undefined
|
|
273
|
+
}, [phase])
|
|
274
|
+
|
|
195
275
|
useEffect(
|
|
196
276
|
() => () => {
|
|
197
277
|
cancelAnimationFrame(raf.current)
|
|
@@ -242,6 +322,11 @@ export function HoldToConfirm({
|
|
|
242
322
|
// Held Enter or Space works like a held finger, from the middle of the button. One press opens the
|
|
243
323
|
// confirm step, since holding a key is hard for many people.
|
|
244
324
|
const onKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
325
|
+
if (phaseRef.current === 'step') {
|
|
326
|
+
// In the step the button confirms with its own click; Escape steps back.
|
|
327
|
+
if (e.key === 'Escape') closeStep()
|
|
328
|
+
return
|
|
329
|
+
}
|
|
245
330
|
if (e.key !== 'Enter' && e.key !== ' ') return
|
|
246
331
|
e.preventDefault()
|
|
247
332
|
if (e.repeat || disabled || phaseRef.current !== 'idle' || press.current) return
|
|
@@ -249,79 +334,80 @@ export function HoldToConfirm({
|
|
|
249
334
|
}
|
|
250
335
|
|
|
251
336
|
const onKeyUp = (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
252
|
-
if (e.key !== 'Enter' && e.key !== ' ') return
|
|
337
|
+
if (phaseRef.current === 'step' || (e.key !== 'Enter' && e.key !== ' ')) return
|
|
253
338
|
e.preventDefault()
|
|
254
339
|
if (press.current?.key === e.key) letGo(true)
|
|
255
340
|
}
|
|
256
341
|
|
|
257
342
|
// A screen reader or voice control sends a click with no press: it opens the confirm step.
|
|
258
343
|
const onClick = (e: MouseEvent<HTMLButtonElement>) => {
|
|
344
|
+
// In the step, pressing the button again confirms it, unless it is the second half of a double-click.
|
|
345
|
+
if (phaseRef.current === 'step') {
|
|
346
|
+
if (e.detail === 0 || performance.now() - stepAt.current > GUARD) finish()
|
|
347
|
+
return
|
|
348
|
+
}
|
|
259
349
|
if (disabled || phaseRef.current !== 'idle' || press.current) return
|
|
260
350
|
if (e.detail === 0 || tapTimer.current) openStep()
|
|
261
351
|
}
|
|
262
352
|
|
|
263
|
-
const
|
|
353
|
+
const onCancelKey = (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
264
354
|
if (e.key !== 'Escape') return
|
|
265
355
|
e.stopPropagation()
|
|
266
356
|
closeStep()
|
|
267
357
|
}
|
|
268
358
|
|
|
269
|
-
// No room beside the label, as on a phone: the step opens under it and the pill grows into a card.
|
|
270
|
-
const stack = size.room > 0 && size.w + size.step > size.room
|
|
271
359
|
const open = phase === 'step'
|
|
272
|
-
const
|
|
273
|
-
const shellH = open && stack ? size.h + size.stepH : size.h
|
|
274
|
-
const line = open ? (stepHint ?? `Choose ${cancelLabel} or ${confirmLabel}.`) : phase === 'done' ? '' : keep ? 'Keep holding' : hint
|
|
360
|
+
const line = open ? (stepHint ?? `Press it again to ${confirmLabel.toLowerCase()}, or ${cancelLabel}.`) : phase === 'done' ? '' : keep ? 'Keep holding' : hint
|
|
275
361
|
|
|
276
362
|
return (
|
|
277
363
|
<div ref={rootRef} className={cx(styles.root, className)}>
|
|
278
|
-
<div
|
|
279
|
-
ref={shellRef}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
364
|
+
<div ref={rowRef} className={styles.row}>
|
|
365
|
+
<div ref={shellRef} className={styles.shell} data-phase={phase} data-disabled={disabled || undefined}>
|
|
366
|
+
<button
|
|
367
|
+
ref={mainRef}
|
|
368
|
+
type="button"
|
|
369
|
+
className={styles.main}
|
|
370
|
+
aria-describedby={`${id}-hint`}
|
|
371
|
+
aria-expanded={open}
|
|
372
|
+
aria-controls={`${id}-step`}
|
|
373
|
+
aria-disabled={disabled || undefined}
|
|
374
|
+
onPointerDown={onPointerDown}
|
|
375
|
+
onPointerMove={onPointerMove}
|
|
376
|
+
onPointerUp={onPointerEnd}
|
|
377
|
+
onPointerCancel={onPointerEnd}
|
|
378
|
+
onContextMenu={(e) => e.preventDefault()}
|
|
379
|
+
onKeyDown={onKeyDown}
|
|
380
|
+
onKeyUp={onKeyUp}
|
|
381
|
+
onBlur={() => press.current?.pointer === 'key' && letGo(false)}
|
|
382
|
+
onClick={onClick}
|
|
383
|
+
>
|
|
384
|
+
<span className={styles.faces}>
|
|
385
|
+
<span className={styles.face} data-face="idle" aria-hidden={phase === 'done' || undefined}>
|
|
386
|
+
{children}
|
|
387
|
+
</span>
|
|
388
|
+
<span className={styles.face} data-face="done" aria-hidden={phase !== 'done' || undefined}>
|
|
389
|
+
<CheckIcon />
|
|
390
|
+
{doneLabel}
|
|
391
|
+
</span>
|
|
392
|
+
</span>
|
|
393
|
+
<svg className={styles.fuse} width={size.w} height={size.h} aria-hidden="true">
|
|
394
|
+
<path ref={runRef} d={path} className={styles.run} pathLength={1} />
|
|
395
|
+
</svg>
|
|
396
|
+
</button>
|
|
397
|
+
</div>
|
|
286
398
|
<button
|
|
287
|
-
ref={
|
|
399
|
+
ref={cancelRef}
|
|
400
|
+
id={`${id}-step`}
|
|
288
401
|
type="button"
|
|
289
|
-
className={styles.
|
|
402
|
+
className={styles.cancel}
|
|
403
|
+
aria-label={cancelLabel}
|
|
290
404
|
aria-describedby={`${id}-hint`}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
onPointerDown={onPointerDown}
|
|
295
|
-
onPointerMove={onPointerMove}
|
|
296
|
-
onPointerUp={onPointerEnd}
|
|
297
|
-
onPointerCancel={onPointerEnd}
|
|
298
|
-
onContextMenu={(e) => e.preventDefault()}
|
|
299
|
-
onKeyDown={onKeyDown}
|
|
300
|
-
onKeyUp={onKeyUp}
|
|
301
|
-
onBlur={() => press.current?.pointer === 'key' && letGo(false)}
|
|
302
|
-
onClick={onClick}
|
|
405
|
+
inert={!open}
|
|
406
|
+
onClick={closeStep}
|
|
407
|
+
onKeyDown={onCancelKey}
|
|
303
408
|
>
|
|
304
|
-
<
|
|
305
|
-
<span className={styles.face} data-face="idle" aria-hidden={phase === 'done' || undefined}>
|
|
306
|
-
{children}
|
|
307
|
-
</span>
|
|
308
|
-
<span className={styles.face} data-face="done" aria-hidden={phase !== 'done' || undefined}>
|
|
309
|
-
<CheckIcon />
|
|
310
|
-
{doneLabel}
|
|
311
|
-
</span>
|
|
312
|
-
</span>
|
|
313
|
-
<svg className={styles.fuse} width={size.w} height={size.h} aria-hidden="true">
|
|
314
|
-
<path ref={runRef} d={path} className={styles.run} pathLength={1} />
|
|
315
|
-
</svg>
|
|
409
|
+
<XIcon />
|
|
316
410
|
</button>
|
|
317
|
-
<div ref={stepRef} id={`${id}-step`} className={styles.step} role="group" aria-labelledby={`${id}-hint`} inert={!open} onKeyDown={onStepKey}>
|
|
318
|
-
<button ref={cancelRef} type="button" className={styles.cancel} onClick={closeStep}>
|
|
319
|
-
{cancelLabel}
|
|
320
|
-
</button>
|
|
321
|
-
<button type="button" className={styles.confirm} onClick={finish}>
|
|
322
|
-
{confirmLabel}
|
|
323
|
-
</button>
|
|
324
|
-
</div>
|
|
325
411
|
</div>
|
|
326
412
|
<p id={`${id}-hint`} className={styles.hint}>
|
|
327
413
|
{line}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
color: var(--gooee-color-fg);
|
|
14
14
|
font-family: var(--gooee-font-mono);
|
|
15
15
|
font-size: var(--gooee-text-xs);
|
|
16
|
-
line-height:
|
|
16
|
+
line-height: var(--gooee-leading-none);
|
|
17
17
|
vertical-align: middle;
|
|
18
18
|
transition:
|
|
19
19
|
transform var(--gooee-motion-instant) var(--gooee-ease-out),
|