@candor-ui/react 2.1.0 → 2.3.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/dist/adapters/use-ag-ui.d.ts +1 -1
- package/dist/adapters/use-candor-chat.d.ts +1 -1
- package/dist/adapters/use-claude-agent.d.ts +1 -1
- package/dist/blocks/copy-field.js +4 -1
- package/dist/blocks/degraded-panel.js +3 -1
- package/dist/blocks/locked.js +5 -1
- package/dist/blocks/status-dot.d.ts +14 -3
- package/dist/blocks/status-dot.js +17 -22
- package/dist/blocks/step-list.d.ts +2 -1
- package/dist/blocks/step-list.js +19 -27
- package/dist/blocks/streaming-text.js +3 -1
- package/dist/blocks/surface.d.ts +1 -1
- package/dist/chat/attachment-preview.js +5 -2
- package/dist/chat/card-registry.js +3 -1
- package/dist/chat/citation.js +2 -2
- package/dist/chat/composer.js +19 -53
- package/dist/chat/context-meter.js +4 -1
- package/dist/chat/entity-chip.js +1 -1
- package/dist/chat/folded-turns.js +3 -1
- package/dist/chat/message-actions.js +5 -2
- package/dist/chat/message.js +9 -5
- package/dist/chat/payload.js +1 -1
- package/dist/chat/permission-prompt.js +6 -1
- package/dist/chat/prompt-suggestions.js +4 -1
- package/dist/chat/reasoning.js +6 -1
- package/dist/chat/thread.js +19 -8
- package/dist/chat/tool-call.js +6 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/lib/motion.d.ts +451 -0
- package/dist/lib/motion.js +350 -0
- package/dist/styles.css +543 -44
- package/dist/ui/accordion.d.ts +23 -0
- package/dist/ui/accordion.js +45 -0
- package/dist/ui/alert.d.ts +20 -0
- package/dist/ui/alert.js +51 -0
- package/dist/ui/button.d.ts +1 -1
- package/dist/ui/button.js +5 -3
- package/dist/ui/checkbox.d.ts +14 -0
- package/dist/ui/checkbox.js +32 -0
- package/dist/ui/collapsible.d.ts +3 -2
- package/dist/ui/collapsible.js +6 -3
- package/dist/ui/label.d.ts +10 -0
- package/dist/ui/label.js +16 -0
- package/dist/ui/popover.d.ts +1 -1
- package/dist/ui/popover.js +4 -2
- package/dist/ui/progress.d.ts +29 -0
- package/dist/ui/progress.js +27 -0
- package/dist/ui/skeleton.d.ts +1 -1
- package/dist/ui/skeleton.js +5 -2
- package/dist/ui/slider.d.ts +28 -0
- package/dist/ui/slider.js +41 -0
- package/dist/ui/switch.d.ts +14 -0
- package/dist/ui/switch.js +23 -0
- package/dist/ui/tooltip.d.ts +1 -1
- package/dist/ui/tooltip.js +4 -2
- package/package.json +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** The CSS each easing name stands for, as a brand file writes it. */
|
|
3
|
+
export const motionEases = {
|
|
4
|
+
standard: "var(--cd-ease)",
|
|
5
|
+
inout: "var(--cd-ease-inout)",
|
|
6
|
+
spring: "var(--cd-ease-spring)",
|
|
7
|
+
linear: "linear",
|
|
8
|
+
};
|
|
9
|
+
/** The family defaults. Durations, easings and amplitudes are 2.2's, so an app with no brand file looks the same. */
|
|
10
|
+
export const motionFamilies = {
|
|
11
|
+
reveal: {
|
|
12
|
+
reports: "Content opened or closed to its measured size; a chevron turns.",
|
|
13
|
+
spatial: true,
|
|
14
|
+
essential: false,
|
|
15
|
+
dur: { default: 200, min: 150, max: 300 },
|
|
16
|
+
outDur: null,
|
|
17
|
+
ease: "standard",
|
|
18
|
+
eases: ["standard", "inout"],
|
|
19
|
+
amp: null,
|
|
20
|
+
variants: ["size", "fade"],
|
|
21
|
+
calm: "Snaps to its measured size.",
|
|
22
|
+
},
|
|
23
|
+
arrive: {
|
|
24
|
+
reports: "Something new, added after the first draw.",
|
|
25
|
+
spatial: true,
|
|
26
|
+
essential: false,
|
|
27
|
+
dur: { default: 240, min: 150, max: 300 },
|
|
28
|
+
outDur: null,
|
|
29
|
+
ease: "standard",
|
|
30
|
+
eases: ["standard", "spring"],
|
|
31
|
+
amp: { name: "distance", default: "8px", min: 0, max: 16, unit: "px", subtle: 0.5 },
|
|
32
|
+
variants: ["rise", "fade", "pop"],
|
|
33
|
+
calm: "Fades in, up to 150 ms.",
|
|
34
|
+
},
|
|
35
|
+
pop: {
|
|
36
|
+
reports: "Added, removed, or a small mark appearing.",
|
|
37
|
+
spatial: true,
|
|
38
|
+
essential: false,
|
|
39
|
+
dur: { default: 200, min: 100, max: 300 },
|
|
40
|
+
outDur: { default: 120, min: 80, max: 300 },
|
|
41
|
+
ease: "standard",
|
|
42
|
+
eases: ["standard", "spring"],
|
|
43
|
+
amp: { name: "scale", default: "0.85", min: 0.8, max: 1, unit: "", subtle: 0 },
|
|
44
|
+
variants: ["scale", "fade"],
|
|
45
|
+
calm: "Fades, up to 150 ms.",
|
|
46
|
+
},
|
|
47
|
+
mark: {
|
|
48
|
+
reports: "A tick or cross drawn when a result settles.",
|
|
49
|
+
spatial: true,
|
|
50
|
+
essential: false,
|
|
51
|
+
dur: { default: 360, min: 200, max: 500 },
|
|
52
|
+
outDur: null,
|
|
53
|
+
ease: "standard",
|
|
54
|
+
eases: ["standard"],
|
|
55
|
+
amp: null,
|
|
56
|
+
variants: ["draw", "pop", "drop"],
|
|
57
|
+
calm: "The finished mark fades in, up to 150 ms.",
|
|
58
|
+
},
|
|
59
|
+
fill: {
|
|
60
|
+
reports: "A bar or ring moving between measured values.",
|
|
61
|
+
spatial: true,
|
|
62
|
+
essential: false,
|
|
63
|
+
dur: { default: 360, min: 200, max: 600 },
|
|
64
|
+
outDur: null,
|
|
65
|
+
ease: "standard",
|
|
66
|
+
eases: ["standard", "inout"],
|
|
67
|
+
amp: null,
|
|
68
|
+
variants: ["grow"],
|
|
69
|
+
calm: "Snaps to the new value; its colour may fade.",
|
|
70
|
+
},
|
|
71
|
+
value: {
|
|
72
|
+
reports: "A number or word changed in place.",
|
|
73
|
+
spatial: false,
|
|
74
|
+
essential: false,
|
|
75
|
+
dur: { default: 120, min: 80, max: 200 },
|
|
76
|
+
outDur: null,
|
|
77
|
+
ease: "standard",
|
|
78
|
+
eases: ["standard"],
|
|
79
|
+
amp: { name: "distance", default: "2px", min: 0, max: 4, unit: "px", subtle: 0 },
|
|
80
|
+
variants: ["fade", "slide"],
|
|
81
|
+
calm: "Crossfades, up to 150 ms.",
|
|
82
|
+
},
|
|
83
|
+
move: {
|
|
84
|
+
reports: "A thing changed place: a reorder, a tab indicator, a toast restacking, a scroll.",
|
|
85
|
+
spatial: true,
|
|
86
|
+
essential: false,
|
|
87
|
+
dur: { default: 200, min: 150, max: 300 },
|
|
88
|
+
outDur: null,
|
|
89
|
+
ease: "standard",
|
|
90
|
+
eases: ["standard", "spring"],
|
|
91
|
+
amp: null,
|
|
92
|
+
variants: ["slide"],
|
|
93
|
+
calm: "Jumps to its new place.",
|
|
94
|
+
},
|
|
95
|
+
overlay: {
|
|
96
|
+
reports: "A dialog, sheet, popover, menu or tooltip opened or closed.",
|
|
97
|
+
spatial: true,
|
|
98
|
+
essential: false,
|
|
99
|
+
dur: { default: 150, min: 100, max: 500 },
|
|
100
|
+
outDur: { default: 150, min: 80, max: 300 },
|
|
101
|
+
ease: "standard",
|
|
102
|
+
eases: ["standard", "inout", "spring"],
|
|
103
|
+
amp: { name: "scale", default: "0.95", min: 0.9, max: 1, unit: "", subtle: 1 },
|
|
104
|
+
variants: ["scale", "slide", "fade"],
|
|
105
|
+
calm: "Fades, up to 150 ms.",
|
|
106
|
+
},
|
|
107
|
+
press: {
|
|
108
|
+
reports: "A press registered.",
|
|
109
|
+
spatial: true,
|
|
110
|
+
essential: false,
|
|
111
|
+
dur: { default: 150, min: 80, max: 200 },
|
|
112
|
+
outDur: null,
|
|
113
|
+
ease: "standard",
|
|
114
|
+
eases: ["standard"],
|
|
115
|
+
amp: { name: "scale", default: "0.96", min: 0.9, max: 1, unit: "", subtle: 0.5 },
|
|
116
|
+
variants: ["scale"],
|
|
117
|
+
calm: "Doesn't scale; the colour still answers.",
|
|
118
|
+
},
|
|
119
|
+
tint: {
|
|
120
|
+
reports: "Hover, focus, selected, a drop target: a colour or opacity change.",
|
|
121
|
+
spatial: false,
|
|
122
|
+
essential: false,
|
|
123
|
+
dur: { default: 150, min: 0, max: 200 },
|
|
124
|
+
outDur: null,
|
|
125
|
+
ease: "standard",
|
|
126
|
+
eases: ["standard", "inout"],
|
|
127
|
+
amp: null,
|
|
128
|
+
variants: ["fade"],
|
|
129
|
+
calm: "Colour and opacity only, up to 150 ms.",
|
|
130
|
+
},
|
|
131
|
+
refuse: {
|
|
132
|
+
reports: "A locked control was pressed: the reason is shown, and under expressive it shakes.",
|
|
133
|
+
spatial: true,
|
|
134
|
+
essential: false,
|
|
135
|
+
dur: { default: 360, min: 200, max: 500 },
|
|
136
|
+
outDur: null,
|
|
137
|
+
ease: "standard",
|
|
138
|
+
eases: ["standard"],
|
|
139
|
+
amp: { name: "distance", default: "3px", min: 0, max: 6, unit: "px", subtle: 0 },
|
|
140
|
+
variants: ["shake"],
|
|
141
|
+
calm: "No shake; the reason's colour still changes.",
|
|
142
|
+
},
|
|
143
|
+
attention: {
|
|
144
|
+
reports: "Something new waits on the person: a ring that grows and fades.",
|
|
145
|
+
spatial: false,
|
|
146
|
+
essential: false,
|
|
147
|
+
dur: { default: 900, min: 600, max: 1600 },
|
|
148
|
+
outDur: null,
|
|
149
|
+
ease: "standard",
|
|
150
|
+
eases: ["standard"],
|
|
151
|
+
amp: { name: "count", default: "1", min: 1, max: 3, unit: "", subtle: 1 },
|
|
152
|
+
variants: ["ring"],
|
|
153
|
+
calm: "One ring that fades without growing, up to 150 ms.",
|
|
154
|
+
},
|
|
155
|
+
live: {
|
|
156
|
+
reports: "Work that is being heard from: a dot's pulse, a caret, a spinner, a shimmer, a skeleton.",
|
|
157
|
+
spatial: false,
|
|
158
|
+
essential: false,
|
|
159
|
+
dur: { default: 1600, min: 1000, max: 3000 },
|
|
160
|
+
outDur: null,
|
|
161
|
+
ease: "standard",
|
|
162
|
+
eases: ["standard", "inout", "linear"],
|
|
163
|
+
amp: null,
|
|
164
|
+
variants: ["pulse"],
|
|
165
|
+
calm: "Still, with its word.",
|
|
166
|
+
},
|
|
167
|
+
clock: {
|
|
168
|
+
reports: "Real time passing: a hold, a deadline, a replay. Painted from the clock.",
|
|
169
|
+
spatial: true,
|
|
170
|
+
essential: true,
|
|
171
|
+
dur: null,
|
|
172
|
+
outDur: null,
|
|
173
|
+
ease: "linear",
|
|
174
|
+
eases: ["linear"],
|
|
175
|
+
amp: null,
|
|
176
|
+
variants: ["glide"],
|
|
177
|
+
calm: "Steps instead of gliding; never off.",
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
/** The family names, in the order the docs and the theme builder list them. */
|
|
181
|
+
export const motionFamilyNames = Object.keys(motionFamilies);
|
|
182
|
+
/**
|
|
183
|
+
* The CSS value a variant is written as. CSS can only choose a drawing by keyframe name, so a variant's value is its
|
|
184
|
+
* keyframe's: the word with Candor's prefix, which keeps an app's own `@keyframes rise` from taking over.
|
|
185
|
+
*/
|
|
186
|
+
export const motionVariantValue = (variant) => `cd-${variant}`;
|
|
187
|
+
const momentKey = Symbol.for("candor.motion.moment");
|
|
188
|
+
const ms = (n) => `${n}ms`;
|
|
189
|
+
/**
|
|
190
|
+
* Builds a moment's chain. Call it once at module level and spread the result into the element's `style`, beside the
|
|
191
|
+
* family utility that the component adds at the honest moment:
|
|
192
|
+
*
|
|
193
|
+
* ```tsx
|
|
194
|
+
* const tick = motion("copy-field", "tick", "pop")
|
|
195
|
+
* <Check style={tick} className={cn(copied && "cd-pop")} />
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* The brand reaches the moment with `--cd-motion-copy-field-tick` (its level), `-dur`, `-ease`, the family's amplitude
|
|
199
|
+
* suffix and `-variant`; anything it doesn't set falls back to the family (`--cd-motion-pop-*`), then to `defaults`,
|
|
200
|
+
* then to Candor's. Two families on one element compose: `style={{ ...press, ...tint }}`.
|
|
201
|
+
*/
|
|
202
|
+
export function motion(item, moment, family, defaults = {}) {
|
|
203
|
+
const spec = motionFamilies[family];
|
|
204
|
+
const own = `--cd-motion-${item}-${moment}`;
|
|
205
|
+
const fam = `--cd-motion-${family}`;
|
|
206
|
+
const local = `--cd-m-${family}`;
|
|
207
|
+
const style = {
|
|
208
|
+
[local]: `var(${own}, var(${fam}, var(--cd-motion-preset)))`,
|
|
209
|
+
};
|
|
210
|
+
if (spec.dur)
|
|
211
|
+
style[`${local}-dur`] = `var(${own}-dur, var(${fam}-dur, ${ms(defaults.dur ?? spec.dur.default)}))`;
|
|
212
|
+
if (spec.outDur)
|
|
213
|
+
style[`${local}-out-dur`] = `var(${own}-out-dur, var(${fam}-out-dur, ${ms(defaults.outDur ?? spec.outDur.default)}))`;
|
|
214
|
+
if (spec.dur)
|
|
215
|
+
style[`${local}-ease`] = `var(${own}-ease, var(${fam}-ease, ${motionEases[defaults.ease ?? spec.ease]}))`;
|
|
216
|
+
if (spec.amp)
|
|
217
|
+
style[`${local}-amp`] = `var(${own}-${spec.amp.name}, var(${fam}-${spec.amp.name}, ${defaults.amp ?? spec.amp.default}))`;
|
|
218
|
+
if (spec.variants.length > 1) {
|
|
219
|
+
const variant = motionVariantValue(defaults.variant ?? spec.variants[0]);
|
|
220
|
+
style[`${local}-variant`] = `var(${own}-variant, var(${fam}-variant, ${variant}))`;
|
|
221
|
+
}
|
|
222
|
+
Object.defineProperty(style, momentKey, { value: { item, moment, family }, enumerable: false });
|
|
223
|
+
return style;
|
|
224
|
+
}
|
|
225
|
+
/** The moment a chain was built for, or `undefined` for a plain style object. */
|
|
226
|
+
export const motionMomentOf = (style) => style?.[momentKey];
|
|
227
|
+
/* ---------------------------------------------------------------- mount still */
|
|
228
|
+
const isFinished = (status) => status === "succeeded" || status === "failed";
|
|
229
|
+
const isOver = (status) => isFinished(status) || status === "cancelled" || status === "skipped";
|
|
230
|
+
const runTest = { settled: isFinished, over: isOver };
|
|
231
|
+
export function useSettled(value, test) {
|
|
232
|
+
const { settled: done, over = done } = (test ?? runTest);
|
|
233
|
+
const [settled, setSettled] = React.useState(0);
|
|
234
|
+
const previous = React.useRef(value);
|
|
235
|
+
React.useLayoutEffect(() => {
|
|
236
|
+
const was = previous.current;
|
|
237
|
+
previous.current = value;
|
|
238
|
+
if (was !== value && !over(was) && done(value))
|
|
239
|
+
setSettled((n) => n + 1);
|
|
240
|
+
}, [value, done, over]);
|
|
241
|
+
return settled;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Which keys were added after the component first drew. Keys present at the first render answer false, so a list
|
|
245
|
+
* that loads with fifty entries draws them still; a key added later answers true until it leaves (and true again if
|
|
246
|
+
* it comes back).
|
|
247
|
+
*/
|
|
248
|
+
export function useArrived(keys) {
|
|
249
|
+
const [arrived, setArrived] = React.useState(() => new Set());
|
|
250
|
+
const previous = React.useRef(null);
|
|
251
|
+
React.useLayoutEffect(() => {
|
|
252
|
+
const before = previous.current;
|
|
253
|
+
previous.current = keys;
|
|
254
|
+
if (!before)
|
|
255
|
+
return;
|
|
256
|
+
const was = new Set(before);
|
|
257
|
+
const now = new Set(keys);
|
|
258
|
+
const added = keys.filter((key) => !was.has(key));
|
|
259
|
+
const gone = before.filter((key) => !now.has(key));
|
|
260
|
+
if (!added.length && !gone.length)
|
|
261
|
+
return;
|
|
262
|
+
setArrived((set) => {
|
|
263
|
+
const next = new Set(set);
|
|
264
|
+
for (const key of gone)
|
|
265
|
+
next.delete(key);
|
|
266
|
+
for (const key of added)
|
|
267
|
+
next.add(key);
|
|
268
|
+
return next;
|
|
269
|
+
});
|
|
270
|
+
}, [keys]);
|
|
271
|
+
return React.useCallback((key) => arrived.has(key), [arrived]);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Items that just left, kept as inert ghosts for the length of their out moment. Each ghost goes when `left(item)` is
|
|
275
|
+
* called (from its `onAnimationEnd`), or after `fallbackMs` when nothing animated. An item that comes back while its
|
|
276
|
+
* ghost is still leaving takes the ghost's place.
|
|
277
|
+
*/
|
|
278
|
+
export function useLeaving(items, keyOf, fallbackMs = 400) {
|
|
279
|
+
const [leaving, setLeaving] = React.useState([]);
|
|
280
|
+
const previous = React.useRef(null);
|
|
281
|
+
React.useLayoutEffect(() => {
|
|
282
|
+
const before = previous.current;
|
|
283
|
+
previous.current = items;
|
|
284
|
+
if (!before)
|
|
285
|
+
return;
|
|
286
|
+
const now = new Set(items.map(keyOf));
|
|
287
|
+
const gone = before.filter((item) => !now.has(keyOf(item)));
|
|
288
|
+
setLeaving((list) => {
|
|
289
|
+
const kept = list.filter((item) => !now.has(keyOf(item)));
|
|
290
|
+
return kept.length === list.length && gone.length === 0 ? list : [...kept, ...gone];
|
|
291
|
+
});
|
|
292
|
+
}, [items, keyOf]);
|
|
293
|
+
React.useEffect(() => {
|
|
294
|
+
if (leaving.length === 0)
|
|
295
|
+
return;
|
|
296
|
+
const timer = window.setTimeout(() => setLeaving([]), fallbackMs);
|
|
297
|
+
return () => window.clearTimeout(timer);
|
|
298
|
+
}, [leaving, fallbackMs]);
|
|
299
|
+
const left = React.useCallback((item) => setLeaving((list) => list.filter((x) => x !== item)), []);
|
|
300
|
+
return { leaving, left };
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The person's setting where `el` is: `none` under `data-motion="none"`, `calm` under the OS's reduced-motion setting
|
|
304
|
+
* or `data-motion="calm"`, else `full`. `none` or `calm` anywhere above wins (the same reach as the CSS variants), the
|
|
305
|
+
* OS setting can't be raised by the app, and values that aren't Candor's (Radix writes its own `data-motion` on menu
|
|
306
|
+
* panels) are ignored.
|
|
307
|
+
*/
|
|
308
|
+
export function motionMode(el) {
|
|
309
|
+
if (el?.closest('[data-motion="none"]'))
|
|
310
|
+
return "none";
|
|
311
|
+
if (typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)
|
|
312
|
+
return "calm";
|
|
313
|
+
if (el?.closest('[data-motion="calm"]'))
|
|
314
|
+
return "calm";
|
|
315
|
+
return "full";
|
|
316
|
+
}
|
|
317
|
+
const number = (value) => {
|
|
318
|
+
const n = Number.parseFloat(value);
|
|
319
|
+
return Number.isFinite(n) ? n : undefined;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* The level a moment resolves to on `el`, read from its computed style: the moment's token, its family's, the preset,
|
|
323
|
+
* then capped by `data-motion`. A page without Candor's CSS reads as subtle.
|
|
324
|
+
*/
|
|
325
|
+
export function motionLevel(el, moment) {
|
|
326
|
+
if (!el || typeof getComputedStyle === "undefined")
|
|
327
|
+
return 1;
|
|
328
|
+
const style = getComputedStyle(el);
|
|
329
|
+
const read = (name) => number(style.getPropertyValue(name));
|
|
330
|
+
const { item, moment: name, family } = typeof moment === "string" ? { item: undefined, moment: undefined, family: moment } : moment;
|
|
331
|
+
const level = (item ? read(`--cd-motion-${item}-${name}`) : undefined) ?? read(`--cd-motion-${family}`) ?? read("--cd-motion-preset") ?? 1;
|
|
332
|
+
const cap = read("--cd-motion-cap") ?? 2;
|
|
333
|
+
const resolved = Math.max(0, Math.min(2, Math.round(Math.min(level, cap))));
|
|
334
|
+
return (motionFamilies[family].essential ? Math.max(1, resolved) : resolved);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* For motion that CSS can't stop (smooth scrolling, the Web Animations API, a bar painted from the clock): a stable
|
|
338
|
+
* function that answers, at the moment of the motion, whether it may play on `ref`'s element. False under
|
|
339
|
+
* `data-motion="none"`, under the calm level (reduced motion), and when the moment's resolved level is 0. Pass the
|
|
340
|
+
* moment's chain from `motion()`, or a family name for the family's level.
|
|
341
|
+
*/
|
|
342
|
+
export function useMotionAllowed(ref, moment) {
|
|
343
|
+
const target = typeof moment === "string" ? moment : motionMomentOf(moment);
|
|
344
|
+
return React.useCallback(() => {
|
|
345
|
+
const el = ref.current;
|
|
346
|
+
if (motionMode(el) !== "full")
|
|
347
|
+
return false;
|
|
348
|
+
return target ? motionLevel(el, target) > 0 : true;
|
|
349
|
+
}, [ref, target]);
|
|
350
|
+
}
|