@cognitap/radiant 0.0.67 → 0.0.69
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 +8 -0
- package/dist/library/Carousel.d.ts +46 -0
- package/dist/library/Carousel.d.ts.map +1 -0
- package/dist/library/Carousel.js +317 -0
- package/dist/library/Carousel.js.map +1 -0
- package/dist/library/Form.d.ts +41 -0
- package/dist/library/Form.d.ts.map +1 -0
- package/dist/library/Form.js +171 -0
- package/dist/library/Form.js.map +1 -0
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +4 -0
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +2 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +8 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +2 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +11 -9
- package/package.json +1 -1
- package/src/Carousel.tsx +540 -0
- package/src/Form.tsx +260 -0
- package/src/cn.ts +4 -0
- package/src/index.ts +29 -0
- package/src/themes/components.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.0.69
|
|
8
|
+
|
|
9
|
+
- Add Carousel with native scroll snap, direction-aware controls, drag navigation and opt-in autoplay that pauses for interaction and reduced motion.
|
|
10
|
+
|
|
11
|
+
## 0.0.68
|
|
12
|
+
|
|
13
|
+
- Add Form with native validation, Field error mapping, asynchronous submission and optional form-library integration.
|
|
14
|
+
|
|
7
15
|
## 0.0.67
|
|
8
16
|
|
|
9
17
|
- Add Sidebar and AppShell with native landmarks, collapsible navigation, a responsive Drawer and application-owned layout persistence.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
import { type ButtonProps } from './Button.js';
|
|
3
|
+
import { type AccessibleName } from './internal/accessibleName.js';
|
|
4
|
+
import type { WithoutToggle } from './internal/types.js';
|
|
5
|
+
import type { ValueOwner } from './react/useNativeOwner.js';
|
|
6
|
+
import type { ThemeStyle } from './themes/defineTheme.js';
|
|
7
|
+
export type CarouselItem = {
|
|
8
|
+
value: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
export type CarouselProps = Omit<ComponentProps<'section'>, 'style' | 'role'> & AccessibleName & ValueOwner<string | null> & {
|
|
13
|
+
items: readonly CarouselItem[];
|
|
14
|
+
onValueChange?: (value: string | null) => void;
|
|
15
|
+
autoPlay?: boolean;
|
|
16
|
+
interval?: number;
|
|
17
|
+
slideLabel?: (index: number, count: number) => string;
|
|
18
|
+
style?: ThemeStyle;
|
|
19
|
+
'data-slot'?: string;
|
|
20
|
+
};
|
|
21
|
+
export type CarouselState = {
|
|
22
|
+
value: string | null;
|
|
23
|
+
index: number;
|
|
24
|
+
count: number;
|
|
25
|
+
playing: boolean;
|
|
26
|
+
setValue: (value: string) => void;
|
|
27
|
+
setPlaying: (playing: boolean) => void;
|
|
28
|
+
};
|
|
29
|
+
export declare function useCarousel(): CarouselState | null;
|
|
30
|
+
export declare function Carousel({ items, value, defaultValue, onValueChange, autoPlay, interval, slideLabel, children, ref, className, onPointerEnter, onPointerLeave, onFocus, onBlur, ...props }: CarouselProps): import("react").JSX.Element;
|
|
31
|
+
export type CarouselViewportProps = Omit<ComponentProps<'div'>, 'children' | 'id' | 'style' | 'role' | 'tabIndex'> & {
|
|
32
|
+
style?: ThemeStyle;
|
|
33
|
+
'data-slot'?: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function CarouselViewport({ ref, className, onKeyDown, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onLostPointerCapture, onClickCapture, ...props }: CarouselViewportProps): import("react").JSX.Element;
|
|
36
|
+
export type CarouselActionProps = WithoutToggle<ButtonProps>;
|
|
37
|
+
export declare function CarouselPrevious(props: CarouselActionProps): import("react").JSX.Element;
|
|
38
|
+
export declare function CarouselNext(props: CarouselActionProps): import("react").JSX.Element;
|
|
39
|
+
export type CarouselIndicatorsProps = Omit<ComponentProps<'div'>, 'children' | 'style'> & {
|
|
40
|
+
style?: ThemeStyle;
|
|
41
|
+
indicatorLabel?: (index: number, count: number) => string;
|
|
42
|
+
'data-slot'?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function CarouselIndicators({ indicatorLabel, className, ...props }: CarouselIndicatorsProps): import("react").JSX.Element;
|
|
45
|
+
export declare function CarouselAutoPlay({ onClick, ...props }: CarouselActionProps): import("react").JSX.Element;
|
|
46
|
+
//# sourceMappingURL=Carousel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Carousel.d.ts","sourceRoot":"","sources":["../../src/Carousel.tsx"],"names":[],"mappings":"AAGA,OAAO,EAQL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AACd,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAGtD,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAA;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAA;AACjF,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,GAC3E,cAAc,GACd,UAAU,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CAAC,EAC/B,GAAG,EACH,SAAS,EACT,SAAS,EACT,aAAa,EACb,aAAa,EACb,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,GAAG,KAAK,EACT,EAAE,qBAAqB,+BA+IvB;AAED,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;AAqB5D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,mBAAmB,+BAO1D;AACD,wBAAgB,YAAY,CAAC,KAAK,EAAE,mBAAmB,+BAOtD;AACD,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG;IACxF,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;IACzD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AACD,wBAAgB,kBAAkB,CAAC,EACjC,cAAwE,EACxE,SAAS,EACT,GAAG,KAAK,EACT,EAAE,uBAAuB,+BAuBzB;AACD,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,mBAAmB,+BAkB1E"}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/* oxlint-disable jsx-a11y/prefer-tag-over-role -- Slides and their viewport are non-form ARIA groups with native scrolling. */
|
|
4
|
+
import { createContext, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
5
|
+
import { Button } from './Button.js';
|
|
6
|
+
import { cn } from './cn.js';
|
|
7
|
+
import { joinIds } from './internal/ids.js';
|
|
8
|
+
import { requireAccessibleName } from './internal/accessibleName.js';
|
|
9
|
+
import { useControllableState } from './react/useControllableState.js';
|
|
10
|
+
import { useComposedRefs } from './react/useComposedRefs.js';
|
|
11
|
+
const Context = createContext(null);
|
|
12
|
+
export function useCarousel() {
|
|
13
|
+
return useContext(Context);
|
|
14
|
+
}
|
|
15
|
+
function binding() {
|
|
16
|
+
const value = useContext(Context);
|
|
17
|
+
if (!value)
|
|
18
|
+
throw new Error('Carousel parts must be inside Carousel.');
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function slides(viewport) {
|
|
22
|
+
return Array.from(viewport.children).filter((node) => node instanceof viewport.ownerDocument.defaultView.HTMLElement &&
|
|
23
|
+
node.hasAttribute('data-rad-carousel-value'));
|
|
24
|
+
}
|
|
25
|
+
function nearest(viewport) {
|
|
26
|
+
const bounds = viewport.getBoundingClientRect(), rtl = viewport.ownerDocument.defaultView.getComputedStyle(viewport).direction === 'rtl';
|
|
27
|
+
return slides(viewport).reduce((best, node) => {
|
|
28
|
+
const distance = (item) => Math.abs(rtl
|
|
29
|
+
? item.getBoundingClientRect().right - bounds.right
|
|
30
|
+
: item.getBoundingClientRect().left - bounds.left);
|
|
31
|
+
return !best || distance(node) < distance(best) ? node : best;
|
|
32
|
+
}, null);
|
|
33
|
+
}
|
|
34
|
+
function scrollTo(viewport, value, smooth = false) {
|
|
35
|
+
const node = slides(viewport).find(node => node.dataset.radCarouselValue === value);
|
|
36
|
+
if (!node)
|
|
37
|
+
return;
|
|
38
|
+
const view = viewport.ownerDocument.defaultView, box = viewport.getBoundingClientRect(), rect = node.getBoundingClientRect(), rtl = view.getComputedStyle(viewport).direction === 'rtl';
|
|
39
|
+
const delta = rtl ? rect.right - box.right : rect.left - box.left;
|
|
40
|
+
if (Math.abs(delta) < 0.5)
|
|
41
|
+
return false;
|
|
42
|
+
viewport.scrollTo({
|
|
43
|
+
left: viewport.scrollLeft + delta,
|
|
44
|
+
behavior: smooth && !view.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'smooth' : 'instant'
|
|
45
|
+
});
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
export function Carousel({ items, value, defaultValue, onValueChange, autoPlay = false, interval = 5000, slideLabel = (index, count) => `${index + 1} of ${count}`, children, ref, className, onPointerEnter, onPointerLeave, onFocus, onBlur, ...props }) {
|
|
49
|
+
requireAccessibleName('Carousel', props);
|
|
50
|
+
if (!Number.isFinite(interval) || interval < 1000)
|
|
51
|
+
throw new TypeError('Carousel interval must be at least 1000ms.');
|
|
52
|
+
const keys = items.map(item => item.value);
|
|
53
|
+
if (keys.some(key => !key.trim()) || new Set(keys).size !== keys.length)
|
|
54
|
+
throw new TypeError('Carousel items need unique nonempty values.');
|
|
55
|
+
const owner = useControllableState({
|
|
56
|
+
name: 'Carousel value',
|
|
57
|
+
value,
|
|
58
|
+
defaultValue,
|
|
59
|
+
initialValue: items[0]?.value ?? null,
|
|
60
|
+
onChange: onValueChange
|
|
61
|
+
});
|
|
62
|
+
if (owner.value !== null && !keys.includes(owner.value))
|
|
63
|
+
throw new TypeError('Carousel value must match an item.');
|
|
64
|
+
const [viewport, setViewport] = useState(null), [playing, setPlaying] = useState(autoPlay), [hovered, setHovered] = useState(false), [focused, setFocused] = useState(false), [reduced, setReduced] = useState(false), [hidden, setHidden] = useState(false);
|
|
65
|
+
const programmatic = useRef(null);
|
|
66
|
+
const current = useRef(owner.value), request = useRef(owner.request), controlled = useRef(owner.controlled);
|
|
67
|
+
useLayoutEffect(() => {
|
|
68
|
+
current.current = owner.value;
|
|
69
|
+
request.current = owner.request;
|
|
70
|
+
controlled.current = owner.controlled;
|
|
71
|
+
});
|
|
72
|
+
const id = useId(), index = keys.indexOf(owner.value ?? ''), viewportId = `${id}-viewport`;
|
|
73
|
+
const [priorAutoPlay, setPriorAutoPlay] = useState(autoPlay);
|
|
74
|
+
if (priorAutoPlay !== autoPlay) {
|
|
75
|
+
setPriorAutoPlay(autoPlay);
|
|
76
|
+
setPlaying(autoPlay);
|
|
77
|
+
}
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!viewport)
|
|
80
|
+
return;
|
|
81
|
+
const view = viewport.ownerDocument.defaultView, doc = viewport.ownerDocument, query = view.matchMedia('(prefers-reduced-motion: reduce)');
|
|
82
|
+
const preferences = () => {
|
|
83
|
+
setReduced(query.matches);
|
|
84
|
+
setHidden(doc.hidden);
|
|
85
|
+
};
|
|
86
|
+
preferences();
|
|
87
|
+
query.addEventListener('change', preferences);
|
|
88
|
+
doc.addEventListener('visibilitychange', preferences);
|
|
89
|
+
return () => {
|
|
90
|
+
query.removeEventListener('change', preferences);
|
|
91
|
+
doc.removeEventListener('visibilitychange', preferences);
|
|
92
|
+
};
|
|
93
|
+
}, [viewport]);
|
|
94
|
+
useLayoutEffect(() => {
|
|
95
|
+
if (viewport) {
|
|
96
|
+
programmatic.current = scrollTo(viewport, owner.value, true) ? owner.value : null;
|
|
97
|
+
}
|
|
98
|
+
}, [viewport, owner.value]);
|
|
99
|
+
const itemsKey = keys.join('\u0000');
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!viewport)
|
|
102
|
+
return;
|
|
103
|
+
const view = viewport.ownerDocument.defaultView;
|
|
104
|
+
let timer, frame;
|
|
105
|
+
let lastRequested = null;
|
|
106
|
+
const settled = () => {
|
|
107
|
+
view.clearTimeout(timer);
|
|
108
|
+
if (viewport.hasAttribute('data-dragging'))
|
|
109
|
+
return;
|
|
110
|
+
const next = nearest(viewport)?.dataset.radCarouselValue;
|
|
111
|
+
if (programmatic.current !== null) {
|
|
112
|
+
if (next === programmatic.current)
|
|
113
|
+
programmatic.current = null;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!next || next === current.current) {
|
|
117
|
+
lastRequested = null;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (next === lastRequested)
|
|
121
|
+
return;
|
|
122
|
+
lastRequested = next;
|
|
123
|
+
request.current(next);
|
|
124
|
+
if (controlled.current)
|
|
125
|
+
frame = view.requestAnimationFrame(() => scrollTo(viewport, current.current));
|
|
126
|
+
};
|
|
127
|
+
const scrolling = () => {
|
|
128
|
+
view.clearTimeout(timer);
|
|
129
|
+
timer = view.setTimeout(settled, 150);
|
|
130
|
+
};
|
|
131
|
+
const resize = new view.ResizeObserver(() => {
|
|
132
|
+
scrollTo(viewport, current.current);
|
|
133
|
+
});
|
|
134
|
+
const interrupt = () => {
|
|
135
|
+
programmatic.current = null;
|
|
136
|
+
};
|
|
137
|
+
viewport.addEventListener('pointerdown', interrupt);
|
|
138
|
+
viewport.addEventListener('wheel', interrupt);
|
|
139
|
+
viewport.addEventListener('keydown', interrupt);
|
|
140
|
+
resize.observe(viewport);
|
|
141
|
+
viewport.addEventListener('scroll', scrolling);
|
|
142
|
+
viewport.addEventListener('scrollend', settled);
|
|
143
|
+
return () => {
|
|
144
|
+
view.clearTimeout(timer);
|
|
145
|
+
if (frame !== undefined)
|
|
146
|
+
view.cancelAnimationFrame(frame);
|
|
147
|
+
resize.disconnect();
|
|
148
|
+
viewport.removeEventListener('pointerdown', interrupt);
|
|
149
|
+
viewport.removeEventListener('wheel', interrupt);
|
|
150
|
+
viewport.removeEventListener('keydown', interrupt);
|
|
151
|
+
viewport.removeEventListener('scroll', scrolling);
|
|
152
|
+
viewport.removeEventListener('scrollend', settled);
|
|
153
|
+
};
|
|
154
|
+
}, [viewport, itemsKey]);
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (!viewport || !playing || hovered || focused || reduced || hidden || items.length < 2)
|
|
157
|
+
return;
|
|
158
|
+
const view = viewport.ownerDocument.defaultView, timer = view.setTimeout(() => request.current(items[(index + 1) % items.length].value), interval);
|
|
159
|
+
return () => view.clearTimeout(timer);
|
|
160
|
+
}, [viewport, playing, hovered, focused, reduced, hidden, items, index, interval]);
|
|
161
|
+
const setValue = (next) => {
|
|
162
|
+
setPlaying(false);
|
|
163
|
+
owner.request(next);
|
|
164
|
+
};
|
|
165
|
+
return (_jsx(Context.Provider, { value: {
|
|
166
|
+
value: owner.value,
|
|
167
|
+
index,
|
|
168
|
+
count: items.length,
|
|
169
|
+
playing,
|
|
170
|
+
setValue,
|
|
171
|
+
setPlaying,
|
|
172
|
+
items,
|
|
173
|
+
viewportId,
|
|
174
|
+
setViewport,
|
|
175
|
+
slideLabel
|
|
176
|
+
}, children: _jsxs("section", { ...props, ref: ref, "aria-roledescription": "carousel", "data-slot": joinIds('carousel', props['data-slot']), "data-playing": playing && !hovered && !focused && !reduced && !hidden ? '' : undefined, className: cn('grid min-w-0 gap-[var(--rad-carousel-gap,var(--rad-spacing-group-gap,1rem))]', className), onPointerEnter: event => {
|
|
177
|
+
onPointerEnter?.(event);
|
|
178
|
+
setHovered(true);
|
|
179
|
+
}, onPointerLeave: event => {
|
|
180
|
+
onPointerLeave?.(event);
|
|
181
|
+
setHovered(false);
|
|
182
|
+
}, onFocus: event => {
|
|
183
|
+
onFocus?.(event);
|
|
184
|
+
setFocused(true);
|
|
185
|
+
}, onBlur: event => {
|
|
186
|
+
onBlur?.(event);
|
|
187
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
188
|
+
setFocused(false);
|
|
189
|
+
}, children: [children, _jsx("output", { className: "sr-only", "aria-live": playing ? 'off' : 'polite', "aria-atomic": "true", children: index >= 0 ? slideLabel(index, items.length) : '' })] }) }));
|
|
190
|
+
}
|
|
191
|
+
/* oxlint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/no-noninteractive-tabindex -- The named native scroll viewport is keyboard reachable and retains group semantics. */
|
|
192
|
+
export function CarouselViewport({ ref, className, onKeyDown, onPointerDown, onPointerMove, onPointerUp, onPointerCancel, onLostPointerCapture, onClickCapture, ...props }) {
|
|
193
|
+
const state = binding(), host = useRef(null), owned = useComposedRefs(host, state.setViewport), composed = useComposedRefs(owned, ref), gesture = useRef(null), suppress = useRef(false);
|
|
194
|
+
function finish(node) {
|
|
195
|
+
const active = gesture.current;
|
|
196
|
+
if (!active)
|
|
197
|
+
return;
|
|
198
|
+
gesture.current = null;
|
|
199
|
+
if (active.snap && node.style.getPropertyValue('scroll-snap-type') === 'none') {
|
|
200
|
+
if (active.snap.value)
|
|
201
|
+
node.style.setProperty('scroll-snap-type', active.snap.value, active.snap.priority);
|
|
202
|
+
else
|
|
203
|
+
node.style.removeProperty('scroll-snap-type');
|
|
204
|
+
}
|
|
205
|
+
node.removeAttribute('data-dragging');
|
|
206
|
+
if (node.hasPointerCapture(active.id))
|
|
207
|
+
node.releasePointerCapture(active.id);
|
|
208
|
+
if (active.moved) {
|
|
209
|
+
suppress.current = true;
|
|
210
|
+
node.dispatchEvent(new Event('scroll'));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return (_jsx("div", { ...props, ref: composed, id: state.viewportId, role: "group", "aria-label": props['aria-label'] ?? 'Slides', tabIndex: 0, "data-slot": joinIds('carousel-viewport', props['data-slot']), className: cn('flex min-w-0 overflow-x-auto overscroll-x-contain snap-x snap-mandatory [touch-action:pan-x_pan-y] gap-[var(--rad-carousel-slide-gap,0px)] rounded-[var(--rad-carousel-radius,var(--rad-surface-radius,0.75rem))] focus-visible:outline-[color:var(--rad-color-focus)] focus-visible:outline-[length:var(--rad-focus-width,2px)] focus-visible:outline-offset-2', className), onKeyDown: event => {
|
|
214
|
+
onKeyDown?.(event);
|
|
215
|
+
if (event.defaultPrevented ||
|
|
216
|
+
event.target !== event.currentTarget ||
|
|
217
|
+
event.altKey ||
|
|
218
|
+
event.metaKey ||
|
|
219
|
+
event.ctrlKey)
|
|
220
|
+
return;
|
|
221
|
+
const rtl = event.currentTarget.ownerDocument.defaultView.getComputedStyle(event.currentTarget)
|
|
222
|
+
.direction === 'rtl';
|
|
223
|
+
let next;
|
|
224
|
+
if (event.key === 'Home')
|
|
225
|
+
next = 0;
|
|
226
|
+
else if (event.key === 'End')
|
|
227
|
+
next = state.count - 1;
|
|
228
|
+
else if (event.key === 'ArrowRight')
|
|
229
|
+
next = state.index + (rtl ? -1 : 1);
|
|
230
|
+
else if (event.key === 'ArrowLeft')
|
|
231
|
+
next = state.index + (rtl ? 1 : -1);
|
|
232
|
+
if (next !== undefined) {
|
|
233
|
+
event.preventDefault();
|
|
234
|
+
const item = state.items[Math.max(0, Math.min(state.count - 1, next))];
|
|
235
|
+
if (item)
|
|
236
|
+
state.setValue(item.value);
|
|
237
|
+
}
|
|
238
|
+
}, onPointerDown: event => {
|
|
239
|
+
onPointerDown?.(event);
|
|
240
|
+
suppress.current = false;
|
|
241
|
+
if (event.defaultPrevented ||
|
|
242
|
+
event.pointerType === 'touch' ||
|
|
243
|
+
event.button !== 0 ||
|
|
244
|
+
!event.isPrimary ||
|
|
245
|
+
event.target.closest('a,button,input,textarea,select,[contenteditable="true"]'))
|
|
246
|
+
return;
|
|
247
|
+
gesture.current = {
|
|
248
|
+
id: event.pointerId,
|
|
249
|
+
x: event.clientX,
|
|
250
|
+
left: event.currentTarget.scrollLeft,
|
|
251
|
+
moved: false
|
|
252
|
+
};
|
|
253
|
+
}, onPointerMove: event => {
|
|
254
|
+
onPointerMove?.(event);
|
|
255
|
+
const active = gesture.current;
|
|
256
|
+
if (!active || active.id !== event.pointerId || event.defaultPrevented)
|
|
257
|
+
return;
|
|
258
|
+
const delta = event.clientX - active.x;
|
|
259
|
+
if (!active.moved && Math.abs(delta) < 5)
|
|
260
|
+
return;
|
|
261
|
+
if (!active.moved) {
|
|
262
|
+
active.moved = true;
|
|
263
|
+
active.snap = {
|
|
264
|
+
value: event.currentTarget.style.getPropertyValue('scroll-snap-type'),
|
|
265
|
+
priority: event.currentTarget.style.getPropertyPriority('scroll-snap-type')
|
|
266
|
+
};
|
|
267
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
268
|
+
event.currentTarget.style.scrollSnapType = 'none';
|
|
269
|
+
event.currentTarget.setAttribute('data-dragging', '');
|
|
270
|
+
}
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
event.currentTarget.scrollLeft = active.left - delta;
|
|
273
|
+
}, onPointerUp: event => {
|
|
274
|
+
onPointerUp?.(event);
|
|
275
|
+
finish(event.currentTarget);
|
|
276
|
+
}, onPointerCancel: event => {
|
|
277
|
+
onPointerCancel?.(event);
|
|
278
|
+
finish(event.currentTarget);
|
|
279
|
+
}, onLostPointerCapture: event => {
|
|
280
|
+
onLostPointerCapture?.(event);
|
|
281
|
+
finish(event.currentTarget);
|
|
282
|
+
}, onClickCapture: event => {
|
|
283
|
+
onClickCapture?.(event);
|
|
284
|
+
if (suppress.current) {
|
|
285
|
+
suppress.current = false;
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
event.stopPropagation();
|
|
288
|
+
}
|
|
289
|
+
}, children: state.items.map((item, index) => (_jsx("div", { role: "group", "aria-roledescription": "slide", "aria-label": `${item.label ? `${item.label}, ` : ''}${state.slideLabel(index, state.count)}`, "data-slot": "carousel-slide", inert: state.value !== item.value || undefined, "data-rad-carousel-value": item.value, "data-selected": state.value === item.value ? '' : undefined, className: "box-border min-w-0 flex-[0_0_100%] snap-start", children: item.children }, item.value))) }));
|
|
290
|
+
}
|
|
291
|
+
function Action({ direction, ...props }) {
|
|
292
|
+
const state = binding(), item = state.items[state.index + direction];
|
|
293
|
+
return (_jsx(Button, { ...props, pressed: undefined, defaultPressed: undefined, onPressedChange: undefined, "aria-pressed": undefined, disabled: props.disabled || !item, "aria-controls": state.viewportId, "data-slot": joinIds(direction < 0 ? 'carousel-previous' : 'carousel-next', props['data-slot']), onClick: event => {
|
|
294
|
+
props.onClick?.(event);
|
|
295
|
+
if (!event.defaultPrevented && item)
|
|
296
|
+
state.setValue(item.value);
|
|
297
|
+
} }));
|
|
298
|
+
}
|
|
299
|
+
export function CarouselPrevious(props) {
|
|
300
|
+
return (_jsx(Action, { ...props, direction: -1 }));
|
|
301
|
+
}
|
|
302
|
+
export function CarouselNext(props) {
|
|
303
|
+
return (_jsx(Action, { ...props, direction: 1 }));
|
|
304
|
+
}
|
|
305
|
+
export function CarouselIndicators({ indicatorLabel = (index, count) => `Show slide ${index + 1} of ${count}`, className, ...props }) {
|
|
306
|
+
const state = binding();
|
|
307
|
+
return (_jsx("div", { ...props, "data-slot": joinIds('carousel-indicators', props['data-slot']), className: cn('flex flex-wrap gap-2', className), children: state.items.map((item, index) => (_jsx(Button, { variant: "ghost", tone: "neutral", "aria-label": indicatorLabel(index, state.count), "aria-current": state.value === item.value ? 'true' : undefined, "aria-controls": state.viewportId, onClick: () => state.setValue(item.value), children: index + 1 }, item.value))) }));
|
|
308
|
+
}
|
|
309
|
+
export function CarouselAutoPlay({ onClick, ...props }) {
|
|
310
|
+
const state = binding();
|
|
311
|
+
return (_jsx(Button, { ...props, pressed: undefined, defaultPressed: undefined, onPressedChange: undefined, "aria-pressed": undefined, "data-slot": joinIds('carousel-auto-play', props['data-slot']), onClick: event => {
|
|
312
|
+
onClick?.(event);
|
|
313
|
+
if (!event.defaultPrevented)
|
|
314
|
+
state.setPlaying(!state.playing);
|
|
315
|
+
}, children: props.children ?? (state.playing ? 'Pause slides' : 'Play slides') }));
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=Carousel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Carousel.js","sourceRoot":"","sources":["../../src/Carousel.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,+HAA+H;AAC/H,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,KAAK,EACL,eAAe,EACf,MAAM,EACN,QAAQ,EAGT,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAuB,MAAM,8BAA8B,CAAA;AAEzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AA6B5D,MAAM,OAAO,GAAG,aAAa,CAAiB,IAAI,CAAC,CAAA;AACnD,MAAM,UAAU,WAAW;IACzB,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C,gBAAgB;gBAAE,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC/D,CAAC,YAEA,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,GAC5D,CACV,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
import { type FieldProps } from './Field.js';
|
|
3
|
+
import { type AlertProps } from './Alert.js';
|
|
4
|
+
import type { StateOwner } from './react/useNativeOwner.js';
|
|
5
|
+
import type { DistributiveOmit } from './internal/types.js';
|
|
6
|
+
import type { AccessibleName } from './internal/accessibleName.js';
|
|
7
|
+
import type { ThemeStyle } from './themes/defineTheme.js';
|
|
8
|
+
export type FormErrors = {
|
|
9
|
+
fields?: Record<string, string | undefined>;
|
|
10
|
+
form?: string;
|
|
11
|
+
};
|
|
12
|
+
export type FormSubmitContext = {
|
|
13
|
+
form: HTMLFormElement;
|
|
14
|
+
submitter: HTMLElement | null;
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
};
|
|
17
|
+
export type FormState = {
|
|
18
|
+
errors: FormErrors;
|
|
19
|
+
pending: boolean;
|
|
20
|
+
focusInvalid: () => void;
|
|
21
|
+
};
|
|
22
|
+
export type FormProps = Omit<ComponentProps<'form'>, 'children' | 'style' | 'noValidate'> & StateOwner<'errors', FormErrors> & AccessibleName & {
|
|
23
|
+
children?: ReactNode | ((state: Pick<FormState, 'errors' | 'pending'>) => ReactNode);
|
|
24
|
+
style?: ThemeStyle;
|
|
25
|
+
'data-slot'?: string;
|
|
26
|
+
onErrorsChange?: (errors: FormErrors) => void;
|
|
27
|
+
validate?: (data: FormData) => FormErrors | void;
|
|
28
|
+
onSubmitValues?: (data: FormData, context: FormSubmitContext) => FormErrors | void | Promise<FormErrors | void>;
|
|
29
|
+
submitErrorText?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function useForm(): FormState | null;
|
|
32
|
+
/** Native values stay in the browser or the application's form library. */
|
|
33
|
+
export declare function Form({ children, errors: errorsProp, defaultErrors, onErrorsChange, validate, onSubmitValues, submitErrorText, ref, className, onSubmit, onReset, onInput, onChange, ...props }: FormProps): import("react").JSX.Element;
|
|
34
|
+
export type FormFieldProps = DistributiveOmit<FieldProps, 'name'> & {
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
/** Name matches the real input's name; Field retains label and error relationships. */
|
|
38
|
+
export declare function FormField({ name, error, ...props }: FormFieldProps): import("react").JSX.Element;
|
|
39
|
+
export type FormErrorProps = Omit<AlertProps, 'children' | 'tabIndex'>;
|
|
40
|
+
export declare function FormError(props: FormErrorProps): import("react").JSX.Element | null;
|
|
41
|
+
//# sourceMappingURL=Form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../src/Form.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAInD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAElE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,MAAM,UAAU,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AACvF,MAAM,MAAM,iBAAiB,GAAG;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,GAAG,KAAK,EACT,EAAE,SAAS,+BA2IX;AACD,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AACpF,uFAAuF;AACvF,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,+BASlE;AACD,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC,CAAA;AACtE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,sCAa9C"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Field } from './Field.js';
|
|
5
|
+
import { Alert } from './Alert.js';
|
|
6
|
+
import { cn } from './cn.js';
|
|
7
|
+
import { joinIds } from './internal/ids.js';
|
|
8
|
+
import { useControllableState } from './react/useControllableState.js';
|
|
9
|
+
import { useComposedRefs } from './react/useComposedRefs.js';
|
|
10
|
+
import { requireAccessibleName } from './internal/accessibleName.js';
|
|
11
|
+
const emptyErrors = {};
|
|
12
|
+
const FormContext = createContext(null);
|
|
13
|
+
export function useForm() {
|
|
14
|
+
return useContext(FormContext);
|
|
15
|
+
}
|
|
16
|
+
function requiredForm() {
|
|
17
|
+
const state = useForm();
|
|
18
|
+
if (!state)
|
|
19
|
+
throw new Error('Form parts must be inside Form.');
|
|
20
|
+
return state;
|
|
21
|
+
}
|
|
22
|
+
function namedError(errors, name) {
|
|
23
|
+
const fields = errors.fields;
|
|
24
|
+
return fields && Object.hasOwn(fields, name) ? fields[name] : undefined;
|
|
25
|
+
}
|
|
26
|
+
function hasErrors(errors) {
|
|
27
|
+
return Boolean(errors.form || Object.values(errors.fields ?? {}).some(Boolean));
|
|
28
|
+
}
|
|
29
|
+
function eventName(target) {
|
|
30
|
+
return target && 'name' in target && typeof target.name === 'string' ? target.name : '';
|
|
31
|
+
}
|
|
32
|
+
function equalErrors(left, right) {
|
|
33
|
+
const entries = (errors) => Object.entries(errors.fields ?? {})
|
|
34
|
+
.filter(([, value]) => value)
|
|
35
|
+
.sort(([a], [b]) => a.localeCompare(b));
|
|
36
|
+
return ((left.form || '') === (right.form || '') &&
|
|
37
|
+
JSON.stringify(entries(left)) === JSON.stringify(entries(right)));
|
|
38
|
+
}
|
|
39
|
+
function controls(form) {
|
|
40
|
+
return Array.from(form.elements).filter((element) => /^(INPUT|SELECT|TEXTAREA)$/.test(element.tagName));
|
|
41
|
+
}
|
|
42
|
+
/** Native values stay in the browser or the application's form library. */
|
|
43
|
+
export function Form({ children, errors: errorsProp, defaultErrors, onErrorsChange, validate, onSubmitValues, submitErrorText = 'Unable to save. Try again.', ref, className, onSubmit, onReset, onInput, onChange, ...props }) {
|
|
44
|
+
requireAccessibleName('Form', props);
|
|
45
|
+
const localRef = useRef(null);
|
|
46
|
+
const composedRef = useComposedRefs(localRef, ref);
|
|
47
|
+
const { value: errors, request: setErrors } = useControllableState({
|
|
48
|
+
name: 'Form errors',
|
|
49
|
+
value: errorsProp,
|
|
50
|
+
defaultValue: defaultErrors,
|
|
51
|
+
initialValue: emptyErrors,
|
|
52
|
+
onChange: onErrorsChange,
|
|
53
|
+
equal: equalErrors
|
|
54
|
+
});
|
|
55
|
+
const [pending, setPending] = useState(false);
|
|
56
|
+
const operation = useRef(null);
|
|
57
|
+
const revision = useRef(0);
|
|
58
|
+
useEffect(() => () => operation.current?.abort(), []);
|
|
59
|
+
const focusInvalid = useCallback((next = errors) => {
|
|
60
|
+
const form = localRef.current;
|
|
61
|
+
if (!form)
|
|
62
|
+
return;
|
|
63
|
+
const target = controls(form).find(control => !control.disabled &&
|
|
64
|
+
control.type !== 'hidden' &&
|
|
65
|
+
Boolean(namedError(next, control.name) ||
|
|
66
|
+
(control.willValidate && !control.validity.valid) ||
|
|
67
|
+
control.getAttribute('aria-invalid') === 'true'));
|
|
68
|
+
if (target) {
|
|
69
|
+
const field = target.closest('[data-slot~="field"]');
|
|
70
|
+
const replacement = field?.querySelector('input:not([type="hidden"]):not([disabled]),textarea:not([disabled]),select:not([hidden]):not([disabled]),button[aria-haspopup]:not([disabled])');
|
|
71
|
+
(target.getClientRects().length ? target : replacement)?.focus();
|
|
72
|
+
}
|
|
73
|
+
else if (next.form)
|
|
74
|
+
form.querySelector('[data-slot~="form-error"]')?.focus();
|
|
75
|
+
}, [errors]);
|
|
76
|
+
const state = { errors, pending, focusInvalid: () => focusInvalid() };
|
|
77
|
+
function edited(name) {
|
|
78
|
+
revision.current++;
|
|
79
|
+
const old = errors;
|
|
80
|
+
if (old.form || namedError(old, name)) {
|
|
81
|
+
const fields = { ...old.fields };
|
|
82
|
+
delete fields[name];
|
|
83
|
+
setErrors({ fields });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return (_jsx(FormContext.Provider, { value: state, children: _jsx("form", { ...props, ref: composedRef, noValidate: true, "aria-busy": pending || props['aria-busy'] || undefined, "data-slot": joinIds('form', props['data-slot']), "data-pending": pending ? '' : undefined, "data-invalid": hasErrors(errors) ? '' : undefined, className: cn('grid min-w-0 gap-[var(--rad-form-gap,var(--rad-spacing-group-gap,1rem))]', className), onInput: event => {
|
|
87
|
+
onInput?.(event);
|
|
88
|
+
edited(eventName(event.target));
|
|
89
|
+
}, onChange: event => {
|
|
90
|
+
onChange?.(event);
|
|
91
|
+
edited(eventName(event.target));
|
|
92
|
+
}, onReset: event => {
|
|
93
|
+
onReset?.(event);
|
|
94
|
+
if (event.defaultPrevented)
|
|
95
|
+
return;
|
|
96
|
+
operation.current?.abort();
|
|
97
|
+
operation.current = null;
|
|
98
|
+
revision.current++;
|
|
99
|
+
setPending(false);
|
|
100
|
+
setErrors(emptyErrors);
|
|
101
|
+
}, onSubmit: event => {
|
|
102
|
+
if (operation.current) {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
onSubmit?.(event);
|
|
107
|
+
if (event.defaultPrevented)
|
|
108
|
+
return;
|
|
109
|
+
const form = event.currentTarget;
|
|
110
|
+
const submitter = event.nativeEvent.submitter;
|
|
111
|
+
const data = new FormData(form, submitter);
|
|
112
|
+
const nativeErrors = Object.create(null);
|
|
113
|
+
let unnamedError;
|
|
114
|
+
if (!submitter?.formNoValidate) {
|
|
115
|
+
for (const control of controls(form)) {
|
|
116
|
+
if (control.willValidate && !control.validity.valid) {
|
|
117
|
+
if (control.name)
|
|
118
|
+
nativeErrors[control.name] ??= control.validationMessage;
|
|
119
|
+
else
|
|
120
|
+
unnamedError ??= control.validationMessage;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const custom = validate?.(data) ?? emptyErrors;
|
|
125
|
+
const next = {
|
|
126
|
+
form: custom.form || unnamedError,
|
|
127
|
+
fields: { ...custom.fields, ...nativeErrors }
|
|
128
|
+
};
|
|
129
|
+
setErrors(next);
|
|
130
|
+
if (hasErrors(next)) {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
form.ownerDocument.defaultView?.requestAnimationFrame(() => focusInvalid(next));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (!onSubmitValues)
|
|
136
|
+
return;
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
const controller = new AbortController();
|
|
139
|
+
operation.current = controller;
|
|
140
|
+
const submittedRevision = revision.current;
|
|
141
|
+
setPending(true);
|
|
142
|
+
void Promise.resolve()
|
|
143
|
+
.then(() => onSubmitValues(data, { form, submitter, signal: controller.signal }))
|
|
144
|
+
.catch(() => ({ form: submitErrorText }))
|
|
145
|
+
.then(result => {
|
|
146
|
+
if (controller.signal.aborted || submittedRevision !== revision.current)
|
|
147
|
+
return;
|
|
148
|
+
const next = result ?? emptyErrors;
|
|
149
|
+
setErrors(next);
|
|
150
|
+
if (hasErrors(next))
|
|
151
|
+
form.ownerDocument.defaultView?.requestAnimationFrame(() => focusInvalid(next));
|
|
152
|
+
})
|
|
153
|
+
.finally(() => {
|
|
154
|
+
if (operation.current !== controller)
|
|
155
|
+
return;
|
|
156
|
+
operation.current = null;
|
|
157
|
+
if (!controller.signal.aborted)
|
|
158
|
+
setPending(false);
|
|
159
|
+
});
|
|
160
|
+
}, children: typeof children === 'function' ? children({ errors, pending }) : children }) }));
|
|
161
|
+
}
|
|
162
|
+
/** Name matches the real input's name; Field retains label and error relationships. */
|
|
163
|
+
export function FormField({ name, error, ...props }) {
|
|
164
|
+
const { errors } = requiredForm();
|
|
165
|
+
return (_jsx(Field, { ...props, error: error ?? namedError(errors, name), "data-slot": joinIds('form-field', props['data-slot']) }));
|
|
166
|
+
}
|
|
167
|
+
export function FormError(props) {
|
|
168
|
+
const { errors } = requiredForm();
|
|
169
|
+
return errors.form ? (_jsx(Alert, { ...props, tone: props.tone ?? 'danger', announce: props.announce ?? 'assertive', tabIndex: -1, "data-slot": joinIds('form-error', props['data-slot']), children: errors.form })) : null;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=Form.js.map
|