@cognitap/radiant 0.0.86 → 0.0.88
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/CHANGELOG.md +14 -0
- package/dist/library/components/Dropzone/Dropzone.js +1 -1
- package/dist/library/components/Dropzone/Dropzone.js.map +1 -1
- package/dist/library/components/Indicator/Indicator.d.ts +27 -0
- package/dist/library/components/Indicator/Indicator.d.ts.map +1 -0
- package/dist/library/components/Indicator/Indicator.js +25 -0
- package/dist/library/components/Indicator/Indicator.js.map +1 -0
- package/dist/library/components/NumberFormatter/NumberFormatter.d.ts +13 -0
- package/dist/library/components/NumberFormatter/NumberFormatter.d.ts.map +1 -0
- package/dist/library/components/NumberFormatter/NumberFormatter.js +18 -0
- package/dist/library/components/NumberFormatter/NumberFormatter.js.map +1 -0
- package/dist/library/components/Rating/Rating.js +1 -1
- package/dist/library/components/Rating/Rating.js.map +1 -1
- package/dist/library/components/RingProgress/RingProgress.d.ts +42 -0
- package/dist/library/components/RingProgress/RingProgress.d.ts.map +1 -0
- package/dist/library/components/RingProgress/RingProgress.js +63 -0
- package/dist/library/components/RingProgress/RingProgress.js.map +1 -0
- package/dist/library/index.d.ts +6 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +3 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/motion/host.d.ts +2 -1
- package/dist/library/motion/host.d.ts.map +1 -1
- package/dist/library/motion/host.js.map +1 -1
- package/dist/library/motion/react.d.ts.map +1 -1
- package/dist/library/motion/react.js +2 -0
- package/dist/library/motion/react.js.map +1 -1
- package/dist/library/motion/ring.d.ts +5 -0
- package/dist/library/motion/ring.d.ts.map +1 -0
- package/dist/library/motion/ring.js +92 -0
- package/dist/library/motion/ring.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/docs/architecture.md +1 -1
- package/docs/motion.md +8 -7
- package/package.json +1 -1
- package/src/components/Dropzone/Dropzone.tsx +1 -1
- package/src/components/Indicator/Indicator.tsx +88 -0
- package/src/components/NumberFormatter/NumberFormatter.tsx +43 -0
- package/src/components/Rating/Rating.tsx +1 -1
- package/src/components/RingProgress/RingProgress.tsx +226 -0
- package/src/index.ts +13 -0
- package/src/motion/host.ts +2 -1
- package/src/motion/react.ts +2 -0
- package/src/motion/ring.ts +89 -0
package/docs/architecture.md
CHANGED
|
@@ -73,7 +73,7 @@ Resolve the locale in the app and use the same value for `<html {...getLocaleAtt
|
|
|
73
73
|
|
|
74
74
|
Omitting the locale inherits the closest provider and the native document attributes. Formatting and matching fall back to `en-US` when there is no configured locale or no supported locale match. A component's explicit `locale` overrides its formatting. Popups carry their anchor's language and direction across a portal, with explicit content attributes taking precedence.
|
|
75
75
|
|
|
76
|
-
`NumberField` localizes its display and parsing. Select and Menu use locale-aware prefix search. Combobox, Autocomplete and their composed families use locale-aware substring search. Built-in matching ignores case and distinguishes accents. Caller filters and text props still apply.
|
|
76
|
+
`NumberField` localizes its display and parsing. `NumberFormatter` preserves server text when browser locale data differs during hydration. Select and Menu use locale-aware prefix search. Combobox, Autocomplete and their composed families use locale-aware substring search. Built-in matching ignores case and distinguishes accents. Caller filters and text props still apply.
|
|
77
77
|
|
|
78
78
|
## Customization limits
|
|
79
79
|
|
package/docs/motion.md
CHANGED
|
@@ -53,13 +53,14 @@ export function AccountActions() {
|
|
|
53
53
|
|
|
54
54
|
Examples:
|
|
55
55
|
|
|
56
|
-
| Component | Motion
|
|
57
|
-
| ---------------------------------------- |
|
|
58
|
-
| `Button`, `DialogTrigger`, `DialogClose` | Compress on press to `--rad-button-press-scale` (default `0.97`, range `0.5`–`1`)
|
|
59
|
-
| `MotionLink` | Press scale on button-styled links. `Link` stays server-renderable
|
|
60
|
-
| `Collapsible`, `Accordion` | Animate height. Closed content is inert immediately
|
|
61
|
-
| `Dialog` | Springs open. The `<dialog>` closes immediately. An inert clone finishes the exit
|
|
62
|
-
| `Select` | Fade the popup in. Close immediately
|
|
56
|
+
| Component | Motion |
|
|
57
|
+
| ---------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
58
|
+
| `Button`, `DialogTrigger`, `DialogClose` | Compress on press to `--rad-button-press-scale` (default `0.97`, range `0.5`–`1`) |
|
|
59
|
+
| `MotionLink` | Press scale on button-styled links. `Link` stays server-renderable |
|
|
60
|
+
| `Collapsible`, `Accordion` | Animate height. Closed content is inert immediately |
|
|
61
|
+
| `Dialog` | Springs open. The `<dialog>` closes immediately. An inert clone finishes the exit |
|
|
62
|
+
| `Select` | Fade the popup in. Close immediately |
|
|
63
|
+
| `RingProgress` | Follow changes to circular arc endpoints while the native reading updates immediately |
|
|
63
64
|
|
|
64
65
|
The exit clone is skipped when the dialog has more than 500 descendants, or when it contains a nested dialog, media, a canvas, an embed, or a custom element. The clone stops after 2 seconds.
|
|
65
66
|
|
package/package.json
CHANGED
|
@@ -135,7 +135,7 @@ export function Dropzone({
|
|
|
135
135
|
data-state={state}
|
|
136
136
|
data-disabled={disabled ? '' : undefined}
|
|
137
137
|
className={cn(
|
|
138
|
-
'relative grid min-w-0 w-full gap-1 rounded-[var(--rad-control-radius,0.5rem)] [corner-shape:var(--rad-control-corner-shape,round)] border-2 border-dashed border-[var(--rad-color-border)] bg-[var(--rad-color-surface)] px-4 py-5 text-center [color:var(--rad-color-foreground)]',
|
|
138
|
+
'relative box-border grid min-w-0 w-full gap-1 rounded-[var(--rad-control-radius,0.5rem)] [corner-shape:var(--rad-control-corner-shape,round)] border-2 border-dashed border-[var(--rad-color-border)] bg-[var(--rad-color-surface)] px-4 py-5 text-center [color:var(--rad-color-foreground)]',
|
|
139
139
|
'has-[input:enabled]:hover:bg-[var(--rad-color-neutral)] data-[state=drag-over]:border-[var(--rad-color-accent)] data-[state=drag-over]:bg-[var(--rad-color-neutral)] data-[state=rejected]:border-[var(--rad-color-invalid)] data-disabled:opacity-60 forced-colors:border-[CanvasText] forced-colors:data-[state=drag-over]:border-[Highlight]',
|
|
140
140
|
focusWithinRingClass,
|
|
141
141
|
className
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ComponentProps, ReactElement } from 'react'
|
|
2
|
+
import { cn } from 'cn'
|
|
3
|
+
import { joinIds } from '../../internal/ids.js'
|
|
4
|
+
import type { PartStyle, Tone } from '../../presentation.js'
|
|
5
|
+
import { Badge } from '../Badge/Badge.js'
|
|
6
|
+
|
|
7
|
+
export type IndicatorPosition = 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end'
|
|
8
|
+
export type IndicatorTargetProps = { 'aria-label': string }
|
|
9
|
+
export type IndicatorProps = Omit<
|
|
10
|
+
ComponentProps<'span'>,
|
|
11
|
+
'children' | 'style' | 'dangerouslySetInnerHTML' | 'aria-label' | 'aria-labelledby'
|
|
12
|
+
> & {
|
|
13
|
+
/** Base accessible name of the decorated target. */
|
|
14
|
+
label: string
|
|
15
|
+
/** Full status, including the uncapped count when rendering a number. */
|
|
16
|
+
statusText: string
|
|
17
|
+
children: (target: IndicatorTargetProps) => ReactElement
|
|
18
|
+
/** Omit to render a dot. */
|
|
19
|
+
count?: number
|
|
20
|
+
maxCount?: number
|
|
21
|
+
position?: IndicatorPosition
|
|
22
|
+
/** CSS pixels outward from the corner. Negative values move inward. */
|
|
23
|
+
offset?: number
|
|
24
|
+
tone?: Tone
|
|
25
|
+
style?: PartStyle['style']
|
|
26
|
+
parts?: { marker?: PartStyle }
|
|
27
|
+
'data-slot'?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function Indicator({
|
|
31
|
+
label,
|
|
32
|
+
statusText,
|
|
33
|
+
children,
|
|
34
|
+
count,
|
|
35
|
+
maxCount = 99,
|
|
36
|
+
position = 'top-end',
|
|
37
|
+
offset = 0,
|
|
38
|
+
tone = 'accent',
|
|
39
|
+
parts,
|
|
40
|
+
className,
|
|
41
|
+
...props
|
|
42
|
+
}: IndicatorProps) {
|
|
43
|
+
if (!label.trim() || !statusText.trim())
|
|
44
|
+
throw new TypeError('Indicator requires a label and status text.')
|
|
45
|
+
if (count !== undefined && (!Number.isSafeInteger(count) || count < 0))
|
|
46
|
+
throw new RangeError('Indicator count must be a nonnegative safe integer.')
|
|
47
|
+
if (!Number.isSafeInteger(maxCount) || maxCount < 0)
|
|
48
|
+
throw new RangeError('Indicator maxCount must be a nonnegative safe integer.')
|
|
49
|
+
if (!Number.isFinite(offset)) throw new RangeError('Indicator offset must be finite.')
|
|
50
|
+
|
|
51
|
+
const dot = count === undefined
|
|
52
|
+
const end = position.endsWith('end')
|
|
53
|
+
const top = position.startsWith('top')
|
|
54
|
+
return (
|
|
55
|
+
<span
|
|
56
|
+
{...props}
|
|
57
|
+
data-slot={joinIds('indicator', props['data-slot'])}
|
|
58
|
+
data-position={position}
|
|
59
|
+
className={cn('relative inline-flex min-w-0 max-w-full align-middle', className)}
|
|
60
|
+
>
|
|
61
|
+
{children({ 'aria-label': `${label}, ${statusText}` })}
|
|
62
|
+
<Badge
|
|
63
|
+
decorative
|
|
64
|
+
data-slot="indicator-marker"
|
|
65
|
+
data-kind={dot ? 'dot' : 'count'}
|
|
66
|
+
tone={tone}
|
|
67
|
+
className={cn(
|
|
68
|
+
'pointer-events-none absolute z-10 max-w-none justify-center',
|
|
69
|
+
top
|
|
70
|
+
? '[inset-block-start:var(--_rad-indicator-inset)] -translate-y-1/2'
|
|
71
|
+
: '[inset-block-end:var(--_rad-indicator-inset)] translate-y-1/2',
|
|
72
|
+
end
|
|
73
|
+
? '[inset-inline-end:var(--_rad-indicator-inset)] translate-x-1/2 [&:dir(rtl)]:-translate-x-1/2'
|
|
74
|
+
: '[inset-inline-start:var(--_rad-indicator-inset)] -translate-x-1/2 [&:dir(rtl)]:translate-x-1/2',
|
|
75
|
+
dot
|
|
76
|
+
? 'size-2.5 p-0 bg-[var(--_action-color)] forced-colors:bg-[Highlight]'
|
|
77
|
+
: 'min-w-5 px-1 py-0 whitespace-nowrap text-xs tabular-nums',
|
|
78
|
+
parts?.marker?.className
|
|
79
|
+
)}
|
|
80
|
+
style={{ '--_rad-indicator-inset': `${-offset}px`, ...parts?.marker?.style }}
|
|
81
|
+
>
|
|
82
|
+
{count === undefined ? null : (
|
|
83
|
+
<bdi dir="ltr">{count > maxCount ? `${maxCount}+` : count}</bdi>
|
|
84
|
+
)}
|
|
85
|
+
</Badge>
|
|
86
|
+
</span>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMemo, type ComponentProps } from 'react'
|
|
4
|
+
import { joinIds } from '../../internal/ids.js'
|
|
5
|
+
import { supportedLocale } from '../../internal/locale.js'
|
|
6
|
+
import type { PartStyle } from '../../presentation.js'
|
|
7
|
+
import { useLocale } from '../../react/useLocale.js'
|
|
8
|
+
|
|
9
|
+
export type NumberFormatterProps = Omit<
|
|
10
|
+
ComponentProps<'bdi'>,
|
|
11
|
+
'children' | 'dangerouslySetInnerHTML' | 'style'
|
|
12
|
+
> & {
|
|
13
|
+
value: number | bigint
|
|
14
|
+
/** Overrides the nearest LocaleProvider for this value. */
|
|
15
|
+
locale?: string
|
|
16
|
+
options?: Intl.NumberFormatOptions
|
|
17
|
+
style?: PartStyle['style']
|
|
18
|
+
'data-slot'?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Inline formatted text with native bidi isolation. */
|
|
22
|
+
export function NumberFormatter({ value, locale, options, lang, ...props }: NumberFormatterProps) {
|
|
23
|
+
const requested = useLocale(locale)
|
|
24
|
+
const formatter = useMemo(
|
|
25
|
+
() =>
|
|
26
|
+
new Intl.NumberFormat(supportedLocale(Intl.NumberFormat, requested), {
|
|
27
|
+
localeMatcher: 'lookup',
|
|
28
|
+
...options
|
|
29
|
+
}),
|
|
30
|
+
[requested, options]
|
|
31
|
+
)
|
|
32
|
+
return (
|
|
33
|
+
<bdi
|
|
34
|
+
{...props}
|
|
35
|
+
// Locale data can differ between engines. Preserve the server text through hydration.
|
|
36
|
+
suppressHydrationWarning
|
|
37
|
+
lang={lang ?? formatter.resolvedOptions().locale}
|
|
38
|
+
data-slot={joinIds('number-formatter', props['data-slot'])}
|
|
39
|
+
>
|
|
40
|
+
{formatter.format(value)}
|
|
41
|
+
</bdi>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from 'react'
|
|
4
|
+
import { cn } from 'cn'
|
|
5
|
+
import { requireAccessibleName, type AccessibleName } from '../../internal/accessibleName.js'
|
|
6
|
+
import { joinIds } from '../../internal/ids.js'
|
|
7
|
+
import { useTransitionHost } from '../../motion/host.js'
|
|
8
|
+
import type { PartStyle, Tone } from '../../presentation.js'
|
|
9
|
+
import { Meter } from '../Meter/Meter.js'
|
|
10
|
+
import { Progress } from '../Progress/Progress.js'
|
|
11
|
+
import { actionTone } from '../shared/actionStyles.js'
|
|
12
|
+
|
|
13
|
+
export type RingProgressSegment = {
|
|
14
|
+
/** Contribution to the total above the minimum. */
|
|
15
|
+
value: number
|
|
16
|
+
tone?: Tone
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Segments = { segments: readonly RingProgressSegment[]; value?: never }
|
|
20
|
+
type Reading<Value> = { value: Value; segments?: never }
|
|
21
|
+
|
|
22
|
+
export type RingProgressProps = AccessibleName &
|
|
23
|
+
Omit<
|
|
24
|
+
ComponentProps<'span'>,
|
|
25
|
+
| 'children'
|
|
26
|
+
| 'dangerouslySetInnerHTML'
|
|
27
|
+
| 'role'
|
|
28
|
+
| 'style'
|
|
29
|
+
| 'aria-valuemin'
|
|
30
|
+
| 'aria-valuemax'
|
|
31
|
+
| 'aria-valuenow'
|
|
32
|
+
> & {
|
|
33
|
+
max?: number
|
|
34
|
+
/** Visual text inside the ring. Name the indicator separately. */
|
|
35
|
+
label?: string
|
|
36
|
+
tone?: Tone
|
|
37
|
+
motion?: 'inherit' | 'off'
|
|
38
|
+
style?: PartStyle['style']
|
|
39
|
+
parts?: { track?: PartStyle; segment?: PartStyle; label?: PartStyle }
|
|
40
|
+
'data-slot'?: string
|
|
41
|
+
} & (
|
|
42
|
+
| ({ kind?: 'progress'; min?: never } & (
|
|
43
|
+
| { value?: number | null; segments?: never }
|
|
44
|
+
| Segments
|
|
45
|
+
))
|
|
46
|
+
| ({ kind: 'meter'; min?: number } & (Reading<number> | Segments))
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
function ringLayout(
|
|
50
|
+
value: number | null | undefined,
|
|
51
|
+
segments: readonly RingProgressSegment[] | undefined,
|
|
52
|
+
min: number,
|
|
53
|
+
max: number,
|
|
54
|
+
tone: Tone
|
|
55
|
+
) {
|
|
56
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || min >= max)
|
|
57
|
+
throw new RangeError('RingProgress needs a finite range with max greater than min.')
|
|
58
|
+
if (segments !== undefined && value !== undefined)
|
|
59
|
+
throw new TypeError('RingProgress accepts a value or segments.')
|
|
60
|
+
const range = max - min
|
|
61
|
+
const percent = (point: number) =>
|
|
62
|
+
100 *
|
|
63
|
+
(Number.isFinite(range) ? (point - min) / range : (point / 2 - min / 2) / (max / 2 - min / 2))
|
|
64
|
+
function withinRange(point: number) {
|
|
65
|
+
if (!Number.isFinite(point) || point < min || point > max)
|
|
66
|
+
throw new RangeError('RingProgress value must be within its range.')
|
|
67
|
+
return point
|
|
68
|
+
}
|
|
69
|
+
if (!segments) {
|
|
70
|
+
const reading = value == null ? null : withinRange(value)
|
|
71
|
+
return { reading, arcs: reading === null ? [] : [{ from: 0, to: percent(reading), tone }] }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let reading = min
|
|
75
|
+
const rounding = Number.EPSILON * Math.max(Math.abs(max), Math.abs(min)) * segments.length
|
|
76
|
+
const arcs = segments.map((segment, index) => {
|
|
77
|
+
if (!Number.isFinite(segment.value) || segment.value < 0)
|
|
78
|
+
throw new RangeError('RingProgress segment values must be finite and nonnegative.')
|
|
79
|
+
const from = percent(reading)
|
|
80
|
+
const next = reading + segment.value
|
|
81
|
+
reading = withinRange(next > max && next - max <= rounding ? max : next)
|
|
82
|
+
const to = percent(reading)
|
|
83
|
+
const gap = Math.min(0.75, (to - from) / 4)
|
|
84
|
+
return {
|
|
85
|
+
from: index ? from + gap : from,
|
|
86
|
+
to: index < segments.length - 1 ? to - gap : to,
|
|
87
|
+
tone: segment.tone ?? tone
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
return { reading, arcs }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function RingProgress({
|
|
94
|
+
kind = 'progress',
|
|
95
|
+
value,
|
|
96
|
+
segments,
|
|
97
|
+
min,
|
|
98
|
+
max = 100,
|
|
99
|
+
label,
|
|
100
|
+
tone = 'accent',
|
|
101
|
+
motion = 'inherit',
|
|
102
|
+
parts,
|
|
103
|
+
ref,
|
|
104
|
+
className,
|
|
105
|
+
'aria-label': ariaLabel,
|
|
106
|
+
'aria-labelledby': labelledBy,
|
|
107
|
+
'aria-describedby': describedBy,
|
|
108
|
+
'aria-valuetext': valueText,
|
|
109
|
+
...props
|
|
110
|
+
}: RingProgressProps) {
|
|
111
|
+
const name = { 'aria-label': ariaLabel, 'aria-labelledby': labelledBy }
|
|
112
|
+
requireAccessibleName('RingProgress', name)
|
|
113
|
+
const minimum = kind === 'meter' ? (min ?? 0) : 0
|
|
114
|
+
const { reading, arcs } = ringLayout(value, segments, minimum, max, tone)
|
|
115
|
+
if (kind === 'meter' && reading === null)
|
|
116
|
+
throw new TypeError('RingProgress in meter mode needs a value or segments.')
|
|
117
|
+
const { ref: ringRef } = useTransitionHost('ring', ref, motion === 'off')
|
|
118
|
+
const native = {
|
|
119
|
+
...name,
|
|
120
|
+
'aria-describedby': describedBy,
|
|
121
|
+
'aria-valuetext': valueText,
|
|
122
|
+
'data-slot': 'ring-progress-value',
|
|
123
|
+
className: 'sr-only',
|
|
124
|
+
max
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<span
|
|
129
|
+
{...props}
|
|
130
|
+
ref={ringRef}
|
|
131
|
+
data-slot={joinIds('ring-progress', props['data-slot'])}
|
|
132
|
+
data-kind={kind}
|
|
133
|
+
data-state={reading === null ? 'indeterminate' : reading === max ? 'complete' : 'determinate'}
|
|
134
|
+
className={cn(
|
|
135
|
+
'relative inline-grid box-border aspect-square w-[var(--rad-ring-progress-size,6rem)] max-w-full shrink-0 place-items-center align-middle',
|
|
136
|
+
className
|
|
137
|
+
)}
|
|
138
|
+
>
|
|
139
|
+
{kind === 'meter' && reading !== null ? (
|
|
140
|
+
<Meter
|
|
141
|
+
{...native}
|
|
142
|
+
value={reading}
|
|
143
|
+
min={minimum}
|
|
144
|
+
/>
|
|
145
|
+
) : (
|
|
146
|
+
<Progress
|
|
147
|
+
{...native}
|
|
148
|
+
value={reading}
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
<svg
|
|
152
|
+
aria-hidden="true"
|
|
153
|
+
focusable="false"
|
|
154
|
+
viewBox="0 0 100 100"
|
|
155
|
+
fill="none"
|
|
156
|
+
className="block size-full [grid-area:1/1]"
|
|
157
|
+
data-slot="ring-progress-graphic"
|
|
158
|
+
>
|
|
159
|
+
<circle
|
|
160
|
+
cx="50"
|
|
161
|
+
cy="50"
|
|
162
|
+
r="43"
|
|
163
|
+
strokeWidth="10"
|
|
164
|
+
data-slot="ring-progress-track"
|
|
165
|
+
className={cn(
|
|
166
|
+
'[stroke:var(--rad-ring-progress-track,var(--rad-color-border))] forced-colors:[stroke:GrayText]',
|
|
167
|
+
parts?.track?.className
|
|
168
|
+
)}
|
|
169
|
+
style={parts?.track?.style}
|
|
170
|
+
/>
|
|
171
|
+
{reading === null && (
|
|
172
|
+
<circle
|
|
173
|
+
cx="50"
|
|
174
|
+
cy="50"
|
|
175
|
+
r="43"
|
|
176
|
+
strokeWidth="10"
|
|
177
|
+
pathLength="100"
|
|
178
|
+
strokeDasharray="4 4"
|
|
179
|
+
data-slot="ring-progress-unknown"
|
|
180
|
+
className={cn(
|
|
181
|
+
actionTone({ tone }),
|
|
182
|
+
'[stroke:var(--rad-ring-progress-color,var(--_action-color))] forced-colors:[stroke:Highlight]',
|
|
183
|
+
parts?.segment?.className
|
|
184
|
+
)}
|
|
185
|
+
style={parts?.segment?.style}
|
|
186
|
+
/>
|
|
187
|
+
)}
|
|
188
|
+
{arcs.map((arc, index) => (
|
|
189
|
+
<circle
|
|
190
|
+
key={index}
|
|
191
|
+
cx="50"
|
|
192
|
+
cy="50"
|
|
193
|
+
r="43"
|
|
194
|
+
strokeWidth="10"
|
|
195
|
+
pathLength="100"
|
|
196
|
+
transform="rotate(-90 50 50)"
|
|
197
|
+
strokeDasharray={`${arc.to - arc.from} 100`}
|
|
198
|
+
strokeDashoffset={-arc.from}
|
|
199
|
+
data-slot="ring-progress-segment"
|
|
200
|
+
data-tone={arc.tone}
|
|
201
|
+
data-rad-ring-arc={`${arc.from} ${arc.to}`}
|
|
202
|
+
className={cn(
|
|
203
|
+
actionTone({ tone: arc.tone }),
|
|
204
|
+
'[stroke:var(--rad-ring-progress-color,var(--_action-color))] forced-colors:[stroke:Highlight]',
|
|
205
|
+
parts?.segment?.className
|
|
206
|
+
)}
|
|
207
|
+
style={parts?.segment?.style}
|
|
208
|
+
/>
|
|
209
|
+
))}
|
|
210
|
+
</svg>
|
|
211
|
+
{label && (
|
|
212
|
+
<span
|
|
213
|
+
aria-hidden="true"
|
|
214
|
+
data-slot="ring-progress-label"
|
|
215
|
+
className={cn(
|
|
216
|
+
'max-w-[65%] text-center text-xs leading-tight [grid-area:1/1] [overflow-wrap:anywhere]',
|
|
217
|
+
parts?.label?.className
|
|
218
|
+
)}
|
|
219
|
+
style={parts?.label?.style}
|
|
220
|
+
>
|
|
221
|
+
{label}
|
|
222
|
+
</span>
|
|
223
|
+
)}
|
|
224
|
+
</span>
|
|
225
|
+
)
|
|
226
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -883,3 +883,16 @@ export { Spoiler } from './components/Spoiler/Spoiler.js'
|
|
|
883
883
|
export type { SpoilerProps } from './components/Spoiler/Spoiler.js'
|
|
884
884
|
export { Highlight } from './components/Highlight/Highlight.js'
|
|
885
885
|
export type { HighlightProps } from './components/Highlight/Highlight.js'
|
|
886
|
+
export { Indicator } from './components/Indicator/Indicator.js'
|
|
887
|
+
export type {
|
|
888
|
+
IndicatorProps,
|
|
889
|
+
IndicatorPosition,
|
|
890
|
+
IndicatorTargetProps
|
|
891
|
+
} from './components/Indicator/Indicator.js'
|
|
892
|
+
export { NumberFormatter } from './components/NumberFormatter/NumberFormatter.js'
|
|
893
|
+
export type { NumberFormatterProps } from './components/NumberFormatter/NumberFormatter.js'
|
|
894
|
+
export { RingProgress } from './components/RingProgress/RingProgress.js'
|
|
895
|
+
export type {
|
|
896
|
+
RingProgressProps,
|
|
897
|
+
RingProgressSegment
|
|
898
|
+
} from './components/RingProgress/RingProgress.js'
|
package/src/motion/host.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface MotionHostRuntime {
|
|
|
23
23
|
popup?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
24
24
|
layout?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
25
25
|
indicator?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
26
|
+
ring?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
26
27
|
}
|
|
27
28
|
export const MotionHostContext = createContext<MotionHostRuntime | null>(null)
|
|
28
29
|
|
|
@@ -105,7 +106,7 @@ export function usePressHost<Node extends HTMLElement>(
|
|
|
105
106
|
|
|
106
107
|
/** Shared lifecycle for native presentation adapters; no engine enters the root path. */
|
|
107
108
|
export function useTransitionHost<Node extends HTMLElement>(
|
|
108
|
-
kind: 'disclosure' | 'dialog' | 'popup' | 'indicator' | 'layout',
|
|
109
|
+
kind: 'disclosure' | 'dialog' | 'popup' | 'indicator' | 'layout' | 'ring',
|
|
109
110
|
ref: Ref<Node> | undefined,
|
|
110
111
|
disabled: boolean
|
|
111
112
|
) {
|
package/src/motion/react.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { bindDisclosureMotion, bindDialogMotion } from './transitions.js'
|
|
|
14
14
|
import { bindPressMotion } from './press.js'
|
|
15
15
|
import { bindPopupMotion } from './popup.js'
|
|
16
16
|
import { bindIndicatorMotion } from './indicator.js'
|
|
17
|
+
import { bindRingMotion } from './ring.js'
|
|
17
18
|
import { bindLayoutMotion } from './layoutHost.js'
|
|
18
19
|
import { bindDrawerMotion } from './drawer.js'
|
|
19
20
|
import { MotionProfileContext } from './context.js'
|
|
@@ -142,6 +143,7 @@ const hostRuntime = {
|
|
|
142
143
|
dialog: bindDialogMotion,
|
|
143
144
|
popup: bindPopupMotion,
|
|
144
145
|
indicator: bindIndicatorMotion,
|
|
146
|
+
ring: bindRingMotion,
|
|
145
147
|
layout: bindLayoutMotion
|
|
146
148
|
}
|
|
147
149
|
/** Opt into native Radiant spring interactions without adding a DOM wrapper. */
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { resolveMotion, type MotionProfile } from './config.js'
|
|
2
|
+
import type { MotionHostBinding } from './host.js'
|
|
3
|
+
import { createSpring, type SpringOptions } from './runtime.js'
|
|
4
|
+
|
|
5
|
+
function range(arc: SVGCircleElement) {
|
|
6
|
+
const [from, to] = arc.dataset.radRingArc!.split(' ').map(Number)
|
|
7
|
+
return { from, to }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function bindArc(arc: SVGCircleElement, options: SpringOptions) {
|
|
11
|
+
const start = range(arc)
|
|
12
|
+
const from = createSpring(start.from, options)
|
|
13
|
+
const to = createSpring(start.to, options)
|
|
14
|
+
const clamp = (value: number) => Math.max(0, Math.min(100, value))
|
|
15
|
+
const previousArray = arc.style.strokeDasharray
|
|
16
|
+
const previousOffset = arc.style.strokeDashoffset
|
|
17
|
+
let array = ''
|
|
18
|
+
let offset = ''
|
|
19
|
+
const draw = () => {
|
|
20
|
+
const position = clamp(from.get())
|
|
21
|
+
arc.style.strokeDasharray = `${Math.max(0, clamp(to.get()) - position)} 100`
|
|
22
|
+
arc.style.strokeDashoffset = String(-position)
|
|
23
|
+
array = arc.style.strokeDasharray
|
|
24
|
+
offset = arc.style.strokeDashoffset
|
|
25
|
+
}
|
|
26
|
+
const offFrom = from.subscribe(draw)
|
|
27
|
+
const offTo = to.subscribe(draw)
|
|
28
|
+
draw()
|
|
29
|
+
return {
|
|
30
|
+
update(next: SpringOptions) {
|
|
31
|
+
const target = range(arc)
|
|
32
|
+
from.configure(next)
|
|
33
|
+
to.configure(next)
|
|
34
|
+
from.to(target.from)
|
|
35
|
+
to.to(target.to)
|
|
36
|
+
},
|
|
37
|
+
destroy() {
|
|
38
|
+
offFrom()
|
|
39
|
+
offTo()
|
|
40
|
+
from.destroy()
|
|
41
|
+
to.destroy()
|
|
42
|
+
if (arc.style.strokeDasharray === array) arc.style.strokeDasharray = previousArray
|
|
43
|
+
if (arc.style.strokeDashoffset === offset) arc.style.strokeDashoffset = previousOffset
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Follow arc endpoints without changing the native semantic reading. */
|
|
49
|
+
export function bindRingMotion(host: HTMLElement, initial: MotionProfile): MotionHostBinding {
|
|
50
|
+
const view = host.ownerDocument.defaultView!
|
|
51
|
+
const preference = view.matchMedia('(prefers-reduced-motion: reduce)')
|
|
52
|
+
const arcs = new Map<SVGCircleElement, ReturnType<typeof bindArc>>()
|
|
53
|
+
let profile = initial
|
|
54
|
+
function sync() {
|
|
55
|
+
const options = resolveMotion(profile, 'follow', preference.matches)
|
|
56
|
+
const current = new Set(host.querySelectorAll<SVGCircleElement>('circle[data-rad-ring-arc]'))
|
|
57
|
+
for (const [arc, binding] of arcs) {
|
|
58
|
+
if (current.has(arc)) continue
|
|
59
|
+
binding.destroy()
|
|
60
|
+
arcs.delete(arc)
|
|
61
|
+
}
|
|
62
|
+
for (const arc of current) {
|
|
63
|
+
const existing = arcs.get(arc)
|
|
64
|
+
if (existing) existing.update(options)
|
|
65
|
+
else arcs.set(arc, bindArc(arc, options))
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const observer = new view.MutationObserver(sync)
|
|
69
|
+
observer.observe(host, {
|
|
70
|
+
subtree: true,
|
|
71
|
+
childList: true,
|
|
72
|
+
attributes: true,
|
|
73
|
+
attributeFilter: ['data-rad-ring-arc']
|
|
74
|
+
})
|
|
75
|
+
preference.addEventListener('change', sync)
|
|
76
|
+
sync()
|
|
77
|
+
return {
|
|
78
|
+
update(next) {
|
|
79
|
+
profile = next
|
|
80
|
+
sync()
|
|
81
|
+
},
|
|
82
|
+
destroy() {
|
|
83
|
+
observer.disconnect()
|
|
84
|
+
preference.removeEventListener('change', sync)
|
|
85
|
+
for (const binding of arcs.values()) binding.destroy()
|
|
86
|
+
arcs.clear()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|