@skeletonlabs/skeleton-react 1.0.0-next.2 → 1.0.0-next.4
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/components/Accordion/Accordion.d.ts +9 -8
- package/dist/components/Accordion/Accordion.js +47 -68
- package/dist/components/Accordion/types.d.ts +24 -25
- package/dist/components/AppBar/AppBar.d.ts +2 -2
- package/dist/components/AppBar/AppBar.js +18 -20
- package/dist/components/AppBar/types.d.ts +1 -1
- package/dist/components/Avatar/Avatar.d.ts +2 -2
- package/dist/components/Avatar/Avatar.js +21 -7
- package/dist/components/Avatar/types.d.ts +10 -5
- package/dist/components/Navigation/Navigation.d.ts +2 -2
- package/dist/components/Navigation/Navigation.js +53 -30
- package/dist/components/Navigation/types.d.ts +6 -1
- package/dist/components/Progress/Progress.d.ts +2 -2
- package/dist/components/Progress/Progress.js +21 -14
- package/dist/components/Progress/types.d.ts +20 -8
- package/dist/components/ProgressRing/ProgressRing.d.ts +2 -2
- package/dist/components/ProgressRing/ProgressRing.js +22 -27
- package/dist/components/ProgressRing/types.d.ts +9 -13
- package/dist/components/Rating/Rating.d.ts +3 -3
- package/dist/components/Rating/Rating.js +50 -76
- package/dist/components/Rating/types.d.ts +35 -54
- package/dist/components/Segment/Segment.d.ts +6 -0
- package/dist/components/Segment/Segment.js +62 -0
- package/dist/components/Segment/types.d.ts +59 -0
- package/dist/components/Segment/types.js +2 -0
- package/dist/components/Switch/Switch.d.ts +2 -2
- package/dist/components/Switch/Switch.js +34 -27
- package/dist/components/Switch/types.d.ts +28 -25
- package/dist/components/Tabs/Tabs.d.ts +12 -7
- package/dist/components/Tabs/Tabs.js +65 -99
- package/dist/components/Tabs/types.d.ts +48 -81
- package/dist/components/Test/Test.js +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.js +11 -10
- package/dist/internal/nodes.d.ts +3 -0
- package/dist/internal/nodes.js +4 -0
- package/dist/internal/noop.d.ts +1 -0
- package/dist/internal/noop.js +2 -0
- package/package.json +36 -35
- package/dist/utils/react-compose.d.ts +0 -4
- package/dist/utils/react-compose.js +0 -3
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as progress from '@zag-js/progress';
|
|
3
|
+
import { normalizeProps, useMachine } from '@zag-js/react';
|
|
4
|
+
import { useId } from 'react';
|
|
5
|
+
export const Progress = ({
|
|
4
6
|
// Root
|
|
5
|
-
base =
|
|
7
|
+
base = 'flex items-center gap-4', height = 'h-2', width = 'w-full', classes = '',
|
|
8
|
+
// Label
|
|
9
|
+
labelBase = 'whitespace-nowrap', labelText = 'text-xs', labelClasses = '',
|
|
10
|
+
// Track
|
|
11
|
+
trackBase = 'h-full w-full overflow-x-hidden', trackBg = 'bg-surface-200-800', trackRounded = 'rounded', trackClasses = '',
|
|
6
12
|
// Meter
|
|
7
|
-
meterBase =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
meterBase = 'h-full w-full', meterBg = 'bg-surface-950-50', meterRounded = 'rounded', meterTransition = 'transition-[width]', meterAnimate = 'animate-progress-indeterminate', meterClasses = '',
|
|
14
|
+
// Children
|
|
15
|
+
children,
|
|
16
|
+
// Zag
|
|
17
|
+
...zagProps }) => {
|
|
18
|
+
// Zag
|
|
19
|
+
const [state, send] = useMachine(progress.machine({ id: useId() }), { context: zagProps });
|
|
20
|
+
const api = progress.connect(state, send, normalizeProps);
|
|
21
|
+
// Reactive
|
|
22
|
+
const rxIndeterminate = api.indeterminate ? meterAnimate : '';
|
|
23
|
+
return (_jsxs("figure", { ...api.getRootProps(), className: `${base} ${height} ${width} ${classes}`, "data-testid": "progress", children: [!!children && (_jsx("div", { ...api.getLabelProps(), className: `${labelBase} ${labelText} ${labelClasses}`, "data-testid": "progress-label", children: children })), _jsx("div", { ...api.getTrackProps(), className: `${trackBase} ${trackBg} ${trackRounded} ${trackClasses}`, "data-testid": "progress-track", children: _jsx("div", { ...api.getRangeProps(), className: `${meterBase} ${meterBg} ${meterRounded} ${meterTransition} ${rxIndeterminate} ${meterClasses}`, "data-testid": "progress-meter" }) })] }));
|
|
17
24
|
};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/** Set the maximum value */
|
|
5
|
-
max?: number;
|
|
6
|
-
/** Set the aria-labelledby */
|
|
7
|
-
labelledBy?: string;
|
|
1
|
+
import * as progress from '@zag-js/progress';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export interface ProgressProps extends React.PropsWithChildren, Omit<progress.Context, 'id'> {
|
|
8
4
|
/** Set root base classes */
|
|
9
5
|
base?: string;
|
|
10
6
|
/** Set root background classes */
|
|
@@ -17,6 +13,20 @@ export interface ProgressProps {
|
|
|
17
13
|
rounded?: string;
|
|
18
14
|
/** Set root arbitrary classes */
|
|
19
15
|
classes?: string;
|
|
16
|
+
/** Set label base classes. */
|
|
17
|
+
labelBase?: string;
|
|
18
|
+
/** Set label text classes. */
|
|
19
|
+
labelText?: string;
|
|
20
|
+
/** Set label classes. */
|
|
21
|
+
labelClasses?: string;
|
|
22
|
+
/** Set the track base classes. */
|
|
23
|
+
trackBase?: string;
|
|
24
|
+
/** Set the track background classes. */
|
|
25
|
+
trackBg?: string;
|
|
26
|
+
/** Set the track border radius classes. */
|
|
27
|
+
trackRounded?: string;
|
|
28
|
+
/** Set arbitrary track classes. */
|
|
29
|
+
trackClasses?: string;
|
|
20
30
|
/** Set meter base classes. */
|
|
21
31
|
meterBase?: string;
|
|
22
32
|
/** Set meter bg classes */
|
|
@@ -25,8 +35,10 @@ export interface ProgressProps {
|
|
|
25
35
|
meterRounded?: string;
|
|
26
36
|
/** Set meter transition classes. */
|
|
27
37
|
meterTransition?: string;
|
|
28
|
-
/** Set meter animation classes for indeterminate mode. */
|
|
38
|
+
/** Set meter animation classes for indeterminate mode. (value === undefined) */
|
|
29
39
|
meterAnimate?: string;
|
|
30
40
|
/** Set meter arbitrary classes. */
|
|
31
41
|
meterClasses?: string;
|
|
42
|
+
/** Set the label */
|
|
43
|
+
label?: ReactNode;
|
|
32
44
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ProgressRingProps } from
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { ProgressRingProps } from './types.js';
|
|
3
3
|
export declare const ProgressRing: FC<ProgressRingProps>;
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { normalizeProps, useMachine } from '@zag-js/react';
|
|
4
|
+
import * as progress from '@zag-js/progress';
|
|
5
|
+
export const ProgressRing = ({ label, strokeWidth = '10px', strokeLinecap = 'round',
|
|
6
|
+
// Root
|
|
7
|
+
base = 'relative', size = 'size-32', classes = '',
|
|
7
8
|
// Slot
|
|
8
|
-
childrenBase =
|
|
9
|
+
childrenBase = 'absolute top-0 left-0 z-[1] flex justify-center items-center', childrenClasses = '',
|
|
9
10
|
// SVG
|
|
10
|
-
svgBase =
|
|
11
|
+
svgBase = 'absolute top-0 left-0 size-full rounded-full', svgClasses = '',
|
|
11
12
|
// Track
|
|
12
|
-
trackBase =
|
|
13
|
+
trackBase = 'fill-none', trackStroke = 'stroke-surface-200-800', trackClasses = '',
|
|
13
14
|
// Meter
|
|
14
|
-
meterBase =
|
|
15
|
+
meterBase = 'fill-none', meterStroke = 'stroke-primary-500', meterTransition = 'transition-[stroke-dashoffset] transition-[stroke-dashoffset]', meterAnimate = 'animate-ring-indeterminate', meterDuration = 'duration-200', meterClasses = '',
|
|
15
16
|
// Label
|
|
16
|
-
|
|
17
|
-
labelFontWeight =
|
|
17
|
+
labelBase = '', labelFill = 'fill-surface-950-50', labelFontSize = 24, // px
|
|
18
|
+
labelFontWeight = 'bold', labelClasses = '',
|
|
18
19
|
// Children
|
|
19
|
-
children,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const v = value !== undefined ? value : 25;
|
|
30
|
-
const percent = (100 * v) / max;
|
|
31
|
-
setCircumference(radius * 2 * Math.PI);
|
|
32
|
-
return circumference - (percent / 100) * circumference;
|
|
33
|
-
}
|
|
34
|
-
return (_jsxs("figure", { className: `${base} ${size} ${classes}`, role: "meter", "aria-labelledby": labelledby, "aria-valuenow": value || 0, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuetext": `${value} / ${max}`, "data-testid": "progress-ring", children: [children ? (_jsx("div", { className: `${childrenBase} ${size} ${childrenClasses}`, children: children })) : null, _jsxs("svg", { viewBox: `0 0 ${baseSize} ${baseSize}`, className: `${svgBase} ${svgClasses} ${value === undefined ? "animate-spin" : ""}`, children: [_jsx("circle", { className: `${trackBase} ${trackStroke} ${trackClasses}`, strokeWidth: strokeWidth, r: radius, cx: "50%", cy: "50%" }), _jsx("circle", { className: `${meterBase} ${meterStroke} ${meterTransition} ${meterDuration} ${meterClasses}`, r: radius, cx: "50%", cy: "50%", strokeWidth: strokeWidth, strokeLinecap: strokeLinecap, strokeDasharray: `${circumference} ${circumference}`, strokeDashoffset: dashoffset, transform: `rotate(-90 ${baseSize / 2} ${baseSize / 2})` }), value !== undefined && !children ? (_jsx("text", { className: `${labelBase} ${labelFill} ${labelClasses}`, x: "50%", y: "50%", fontSize: labelFontSize, fontWeight: labelFontWeight, textAnchor: "middle", dominantBaseline: "central", children: label ?? `${value}%` })) : null] })] }));
|
|
20
|
+
children,
|
|
21
|
+
// Zag
|
|
22
|
+
...zagProps }) => {
|
|
23
|
+
// Zag
|
|
24
|
+
const [state, send] = useMachine(progress.machine({ id: useId() }), { context: zagProps });
|
|
25
|
+
const api = progress.connect(state, send, normalizeProps);
|
|
26
|
+
// Reactive Classes
|
|
27
|
+
const rxAnimCircle = api.indeterminate && 'animate-spin';
|
|
28
|
+
const rxAnimMeter = api.indeterminate && meterAnimate;
|
|
29
|
+
return (_jsxs("figure", { ...api.getRootProps(), className: `${base} ${size} ${classes}`, "data-testid": "progress-ring", children: [_jsx("div", { ...api.getLabelProps(), className: `${childrenBase} ${size} ${childrenClasses}`, "data-testid": "progress-ring-children", children: children }), _jsxs("svg", { ...api.getCircleProps(), className: `${svgBase} ${svgClasses} ${rxAnimCircle}`, style: { '--size': '100%', '--thickness': strokeWidth }, "data-testid": "progress-ring-svg", children: [_jsx("circle", { ...api.getCircleTrackProps(), className: `${trackBase} ${trackStroke} ${trackClasses}`, "data-testid": "progress-ring-track" }), _jsx("circle", { ...api.getCircleRangeProps(), className: `${meterBase} ${meterStroke} ${meterTransition} ${meterDuration} ${meterClasses} ${rxAnimMeter}`, strokeLinecap: strokeLinecap, "data-testid": "progress-ring-meter" }), api.value !== null && !children && (_jsx("text", { className: `${labelBase} ${labelFill} ${labelClasses}`, x: "50%", y: "50%", fontSize: labelFontSize, fontWeight: labelFontWeight, textAnchor: "middle", dominantBaseline: "central", "data-testid": "progress-ring-label", children: label ?? `${api.value}%` }))] })] }));
|
|
35
30
|
};
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export interface ProgressRingProps extends React.PropsWithChildren {
|
|
3
|
-
/** Set the
|
|
4
|
-
|
|
5
|
-
/** Set the
|
|
6
|
-
|
|
7
|
-
/** Set the stroke size (px) */
|
|
8
|
-
strokeWidth?: number;
|
|
1
|
+
import * as progress from '@zag-js/progress';
|
|
2
|
+
export interface ProgressRingProps extends React.PropsWithChildren, Omit<progress.Context, 'id'> {
|
|
3
|
+
/** Set the text for the scalable label */
|
|
4
|
+
label?: string;
|
|
5
|
+
/** Set the stroke size (ex: 15px) */
|
|
6
|
+
strokeWidth?: string;
|
|
9
7
|
/** Defines the shape of the meter */
|
|
10
|
-
strokeLinecap?:
|
|
11
|
-
/** Set the aria-labelledby value */
|
|
12
|
-
labelledby?: string;
|
|
8
|
+
strokeLinecap?: 'inherit' | 'butt' | 'round' | 'square';
|
|
13
9
|
/** Set the root base classes */
|
|
14
10
|
base?: string;
|
|
15
11
|
/** Set the root size classes */
|
|
@@ -36,12 +32,12 @@ export interface ProgressRingProps extends React.PropsWithChildren {
|
|
|
36
32
|
meterStroke?: string;
|
|
37
33
|
/** Set the meter transition classes */
|
|
38
34
|
meterTransition?: string;
|
|
35
|
+
/** Set the meter animation classes */
|
|
36
|
+
meterAnimate?: string;
|
|
39
37
|
/** Set the meter transition duration classes */
|
|
40
38
|
meterDuration?: string;
|
|
41
39
|
/** Provide arbitrary classes to the meter element */
|
|
42
40
|
meterClasses?: string;
|
|
43
|
-
/** Set the text for the scalable label */
|
|
44
|
-
label?: string;
|
|
45
41
|
/** Set the label classes */
|
|
46
42
|
labelBase?: string;
|
|
47
43
|
/** Set the label fill color classes */
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RatingProps } from
|
|
3
|
-
export declare const Rating:
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
import type { RatingProps } from './types';
|
|
3
|
+
export declare const Rating: FC<RatingProps>;
|
|
@@ -1,79 +1,53 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as rating from '@zag-js/rating-group';
|
|
3
|
+
import { useMachine, normalizeProps } from '@zag-js/react';
|
|
4
|
+
import { useId } from 'react';
|
|
5
|
+
import { starEmpty, starHalf, starFull } from '../../internal/nodes';
|
|
6
|
+
import { noop } from '../../internal/noop';
|
|
7
|
+
export const Rating = ({
|
|
5
8
|
// Root
|
|
6
|
-
base =
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
9
|
+
base = '', classes = '',
|
|
10
|
+
// Control
|
|
11
|
+
controlBase = 'flex', controlGap = 'gap-2', controlClasses,
|
|
12
|
+
// Label
|
|
13
|
+
labelBase = '', labelClasses = '',
|
|
14
|
+
// Item
|
|
15
|
+
itemBase = '', itemClasses = '',
|
|
16
|
+
// State
|
|
17
|
+
stateInteractive = 'cursor-pointer', stateReadOnly = '', stateDisabled = 'cursor-not-allowed opacity-50',
|
|
18
|
+
// Icons
|
|
19
|
+
iconEmpty = starEmpty, iconHalf = starHalf, iconFull = starFull,
|
|
15
20
|
// Children
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (["ArrowLeft", "ArrowUp"].includes(event.key)) {
|
|
49
|
-
event.preventDefault();
|
|
50
|
-
rtl ? increaseValue() : decreaseValue();
|
|
51
|
-
}
|
|
52
|
-
if (["ArrowRight", "ArrowDown"].includes(event.key)) {
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
rtl ? decreaseValue() : increaseValue();
|
|
55
|
-
}
|
|
56
|
-
onKeyDown(event);
|
|
57
|
-
}, []);
|
|
58
|
-
function refreshFocus() {
|
|
59
|
-
if (!figureRef.current)
|
|
60
|
-
return;
|
|
61
|
-
const buttons = figureRef.current.querySelectorAll("button");
|
|
62
|
-
buttons[Math.max(0, Math.ceil(value - 1))].focus();
|
|
63
|
-
}
|
|
64
|
-
function increaseValue() {
|
|
65
|
-
value = Math.min(max, value + 1 / step);
|
|
66
|
-
onValueChange(value);
|
|
67
|
-
refreshFocus();
|
|
68
|
-
}
|
|
69
|
-
function decreaseValue() {
|
|
70
|
-
value = Math.max(0, value - 1 / step);
|
|
71
|
-
onValueChange(value);
|
|
72
|
-
refreshFocus();
|
|
73
|
-
}
|
|
74
|
-
return (_jsx("figure", { ref: figureRef, className: `${base} ${width} ${justify} ${spaceX} ${classes}`, "data-testid": "rating", children: [...Array(max)].map((_, order) => (_jsxs("button", { className: `${buttonBase} ${buttonPosition} ${buttonAspect} ${buttonClasses} ${interactive ? undefined : "pointer-events-none"}`, tabIndex: interactive && order === focusedButtonIndex ? 0 : -1, onMouseDown: (event) => interactive ? onRatingMouseDown(event, order) : undefined, onKeyDown: (event) => interactive ? onRatingKeyDown(event) : undefined, type: "button", children: [_jsx("span", { className: `${emptyBase} ${emptyClip} ${rxEmptyInteractive} ${emptyClasses}`, style: {
|
|
75
|
-
"--clipValue": `${(value - order) * 100}%`,
|
|
76
|
-
}, "data-testid": "rating-iconempty", children: iconEmpty }), _jsx("span", { className: `${fullBase} ${fullClip} ${rxFullInteractive} ${fullClasses}`, style: {
|
|
77
|
-
"--clipValue": `${100 - (value - order) * 100}%`,
|
|
78
|
-
}, "data-testid": "rating-iconfull", children: iconFull })] }, order))) }));
|
|
21
|
+
label,
|
|
22
|
+
// Events
|
|
23
|
+
onValueChange = noop,
|
|
24
|
+
// Zag
|
|
25
|
+
...zagProps }) => {
|
|
26
|
+
// Zag
|
|
27
|
+
const [state, send] = useMachine(rating.machine({
|
|
28
|
+
id: useId(),
|
|
29
|
+
onValueChange: (details) => onValueChange(details.value)
|
|
30
|
+
}), {
|
|
31
|
+
context: zagProps
|
|
32
|
+
});
|
|
33
|
+
const api = rating.connect(state, send, normalizeProps);
|
|
34
|
+
// Reactive
|
|
35
|
+
const rxInteractive = state.context.isInteractive ? stateInteractive : '';
|
|
36
|
+
const rxReadOnly = state.context.readOnly ? stateReadOnly : '';
|
|
37
|
+
const rxDisabled = state.context.disabled ? stateDisabled : '';
|
|
38
|
+
return (_jsxs("div", { ...api.getRootProps(), className: `${base} ${classes}`, "data-testid": "rating", children: [!!label && (_jsx("label", { ...api.getLabelProps(), className: `${labelBase} ${labelClasses}`, "data-testid": "rating-label", children: label })), _jsx("div", { ...api.getControlProps(), className: `${controlBase} ${controlGap} ${rxInteractive} ${rxReadOnly} ${rxDisabled} ${controlClasses}`, "data-testid": "rating-control", children: api.items.map((index) => {
|
|
39
|
+
const itemState = api.getItemState({ index });
|
|
40
|
+
const icon = (() => {
|
|
41
|
+
if (!itemState.highlighted) {
|
|
42
|
+
return iconEmpty;
|
|
43
|
+
}
|
|
44
|
+
else if (itemState.half) {
|
|
45
|
+
return iconHalf;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return iconFull;
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
return (_jsx(_Fragment, { children: _jsx("span", { ...api.getItemProps({ index }), className: `${itemBase} ${itemClasses}`, "data-testid": "rating-item", children: icon }, index) }));
|
|
52
|
+
}) }), _jsx("input", { ...api.getHiddenInputProps(), "data-testid": "rating-input" })] }));
|
|
79
53
|
};
|
|
@@ -1,59 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** Sets the maximum rating value. */
|
|
6
|
-
max?: number;
|
|
7
|
-
/** Sets interactive mode. */
|
|
8
|
-
interactive?: boolean;
|
|
9
|
-
/** Sets the rating fractional granularity. */
|
|
10
|
-
step?: number;
|
|
11
|
-
/** Sets base styles. */
|
|
1
|
+
import * as rating from '@zag-js/rating-group';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export interface RatingProps extends Omit<rating.Context, 'id' | 'onValueChange'> {
|
|
4
|
+
/** Set root base classes */
|
|
12
5
|
base?: string;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
justify?: string;
|
|
17
|
-
/** Sets horizontal spacing styles. */
|
|
18
|
-
spaceX?: string;
|
|
19
|
-
/** Provide arbitrary CSS classes. */
|
|
6
|
+
/** Set root gap classes */
|
|
7
|
+
gap?: string;
|
|
8
|
+
/** Set root arbitrary classes */
|
|
20
9
|
classes?: string;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
/** Set
|
|
30
|
-
|
|
31
|
-
/** Set
|
|
32
|
-
|
|
33
|
-
/** Set
|
|
34
|
-
|
|
35
|
-
/** Set
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
/** Set
|
|
40
|
-
|
|
41
|
-
/** Set the
|
|
42
|
-
fullClip?: string;
|
|
43
|
-
/** Set interactive state styles for the full icon. */
|
|
44
|
-
fullInteractive?: string;
|
|
45
|
-
/** Set non-interactive state styles for the full icon. */
|
|
46
|
-
fullStatic?: string;
|
|
47
|
-
/** Provide arbitrary CSS classes for the full icon. */
|
|
48
|
-
fullClasses?: string;
|
|
49
|
-
/** Triggers on rating mouse down. */
|
|
50
|
-
onMouseDown?: (event: React.MouseEvent<HTMLButtonElement>, value: number) => void;
|
|
51
|
-
/** Triggers on rating key down. */
|
|
52
|
-
onKeyDown?: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
|
|
53
|
-
/** Triggers on rating value change. */
|
|
54
|
-
onValueChange?: (value: number) => void;
|
|
55
|
-
/** The empty icon children. */
|
|
10
|
+
/** Set control base classes */
|
|
11
|
+
controlBase?: string;
|
|
12
|
+
/** Set control gap classes */
|
|
13
|
+
controlGap?: string;
|
|
14
|
+
/** Set control arbitrary classes */
|
|
15
|
+
controlClasses?: string;
|
|
16
|
+
/** Set label base classes */
|
|
17
|
+
labelBase?: string;
|
|
18
|
+
/** Set label arbitrary classes */
|
|
19
|
+
labelClasses?: string;
|
|
20
|
+
/** Set item base classes */
|
|
21
|
+
itemBase?: string;
|
|
22
|
+
/** Set item arbitrary classes */
|
|
23
|
+
itemClasses?: string;
|
|
24
|
+
/** Set item interactive state classes */
|
|
25
|
+
stateInteractive?: string;
|
|
26
|
+
/** Set item read-only state classes */
|
|
27
|
+
stateReadOnly?: string;
|
|
28
|
+
/** Set item disabled state classes */
|
|
29
|
+
stateDisabled?: string;
|
|
30
|
+
/** Set the empty icon node */
|
|
56
31
|
iconEmpty?: ReactNode;
|
|
57
|
-
/**
|
|
32
|
+
/** Set the half icon node */
|
|
33
|
+
iconHalf?: ReactNode;
|
|
34
|
+
/** Set the full icon node */
|
|
58
35
|
iconFull?: ReactNode;
|
|
36
|
+
/** Set the label node */
|
|
37
|
+
label?: ReactNode;
|
|
38
|
+
/** Set the onValueChange callback */
|
|
39
|
+
onValueChange?: (value: number) => void;
|
|
59
40
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import type { SegmentContextState, SegmentProps, SegmentItemsProps } from './types.js';
|
|
3
|
+
export declare const SegmentContext: import("react").Context<SegmentContextState>;
|
|
4
|
+
export declare const Segment: FC<SegmentProps> & {
|
|
5
|
+
Item: FC<SegmentItemsProps>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useId } from 'react';
|
|
4
|
+
import * as radio from '@zag-js/radio-group';
|
|
5
|
+
import { useMachine, normalizeProps } from '@zag-js/react';
|
|
6
|
+
import { noop } from '../../internal/noop.js';
|
|
7
|
+
// Contexts ---
|
|
8
|
+
export const SegmentContext = createContext({
|
|
9
|
+
api: {},
|
|
10
|
+
indicatorText: ''
|
|
11
|
+
});
|
|
12
|
+
// Components ---
|
|
13
|
+
const SegmentRoot = ({ orientation = 'horizontal',
|
|
14
|
+
// Root
|
|
15
|
+
base = 'inline-flex items-stretch overflow-hidden', background = 'preset-outlined-surface-200-800', border = 'p-2', gap = 'gap-2', padding = '', rounded = 'rounded-container', width = '', classes = '',
|
|
16
|
+
// States
|
|
17
|
+
orientVertical = 'flex-col', orientHorizontal = 'flex-row', stateDisabled = 'disabled', stateReadOnly = 'pointer-events-none',
|
|
18
|
+
// Indicator
|
|
19
|
+
indicatorBase = 'top-[var(--top)] left-[var(--left)] w-[var(--width)] h-[var(--height)]', indicatorBg = 'preset-filled', indicatorText = 'text-surface-contrast-950 dark:text-surface-contrast-50', indicatorRounded = 'rounded', indicatorClasses = '',
|
|
20
|
+
// Events
|
|
21
|
+
onValueChange = noop,
|
|
22
|
+
// Children
|
|
23
|
+
children,
|
|
24
|
+
// Zag
|
|
25
|
+
...zagProps }) => {
|
|
26
|
+
// Zag
|
|
27
|
+
const [state, send] = useMachine(radio.machine({
|
|
28
|
+
id: useId(),
|
|
29
|
+
onValueChange: (details) => onValueChange(details.value),
|
|
30
|
+
orientation
|
|
31
|
+
}), { context: zagProps });
|
|
32
|
+
const api = radio.connect(state, send, normalizeProps);
|
|
33
|
+
// Set Context
|
|
34
|
+
const ctx = { api, indicatorText };
|
|
35
|
+
// Reactive
|
|
36
|
+
const rxOrientation = state.context.orientation === 'vertical' ? orientVertical : orientHorizontal;
|
|
37
|
+
const rxDisabled = state.context.disabled ? stateDisabled : '';
|
|
38
|
+
const rxReadOnly = state.context.readOnly ? stateReadOnly : '';
|
|
39
|
+
return (_jsxs("div", { ...api.getRootProps(), className: `${base} ${rxOrientation} ${background} ${border} ${padding} ${gap} ${rounded} ${width} ${rxDisabled} ${rxReadOnly} ${classes}`, "data-testid": "segment", children: [_jsx("div", { ...api.getIndicatorProps(), className: `${indicatorBase} ${indicatorBg} ${indicatorRounded} ${indicatorClasses}`, "data-testid": "segment-indicator" }), _jsx(SegmentContext.Provider, { value: ctx, children: children })] }));
|
|
40
|
+
};
|
|
41
|
+
const SegmentItem = ({
|
|
42
|
+
// Root
|
|
43
|
+
base = 'btn cursor-pointer z-[1]', classes = '',
|
|
44
|
+
// Label
|
|
45
|
+
labelBase = 'pointer-events-none transition-colors duration-100', labelClasses = '',
|
|
46
|
+
// State
|
|
47
|
+
stateDisabled = 'disabled',
|
|
48
|
+
// Children
|
|
49
|
+
children,
|
|
50
|
+
// Zag
|
|
51
|
+
...zagProps }) => {
|
|
52
|
+
// Get Context
|
|
53
|
+
const ctx = useContext(SegmentContext);
|
|
54
|
+
const state = ctx.api.getItemState(zagProps);
|
|
55
|
+
// Reactive
|
|
56
|
+
const rxDisabled = state.disabled ? stateDisabled : '';
|
|
57
|
+
const rxActiveText = state.checked ? ctx.indicatorText : '';
|
|
58
|
+
return (_jsxs("label", { ...ctx.api.getItemProps(zagProps), className: `${base} ${rxDisabled} ${classes}`, "data-testid": "segment-item", children: [_jsx("span", { ...ctx.api.getItemTextProps(zagProps), className: `${labelBase} ${rxActiveText} ${labelClasses}`, "data-testid": "segment-item-label", children: children }), _jsx("input", { ...ctx.api.getItemHiddenInputProps(zagProps), "data-testid": "segment-item-input" })] }));
|
|
59
|
+
};
|
|
60
|
+
export const Segment = Object.assign(SegmentRoot, {
|
|
61
|
+
Item: SegmentItem
|
|
62
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as radio from '@zag-js/radio-group';
|
|
2
|
+
export interface SegmentContextState {
|
|
3
|
+
api: ReturnType<typeof radio.connect>;
|
|
4
|
+
indicatorText: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SegmentProps extends React.PropsWithChildren, Omit<radio.Context, 'id' | 'orientation' | 'onValueChange'> {
|
|
7
|
+
/** Set the orientation. */
|
|
8
|
+
orientation?: radio.Context['orientation'];
|
|
9
|
+
/** Sets base classes. */
|
|
10
|
+
base?: string;
|
|
11
|
+
/** Set background classes. */
|
|
12
|
+
background?: string;
|
|
13
|
+
/** Set border classes. */
|
|
14
|
+
border?: string;
|
|
15
|
+
/** Set flex direction classes. */
|
|
16
|
+
flexDirection?: string;
|
|
17
|
+
/** Set gap classes. */
|
|
18
|
+
gap?: string;
|
|
19
|
+
/** Set padding classes. */
|
|
20
|
+
padding?: string;
|
|
21
|
+
/** Set rounded classes. */
|
|
22
|
+
rounded?: string;
|
|
23
|
+
/** Set width classes. */
|
|
24
|
+
width?: string;
|
|
25
|
+
/** Provide arbitrary CSS classes. */
|
|
26
|
+
classes?: string;
|
|
27
|
+
/** Set classes to provide a vertical layout. */
|
|
28
|
+
orientVertical?: string;
|
|
29
|
+
/** Set classes to provide a horizintal layout. */
|
|
30
|
+
orientHorizontal?: string;
|
|
31
|
+
/** Set claseses for the disabled state. */
|
|
32
|
+
stateDisabled?: string;
|
|
33
|
+
/** Set claseses for the read-only state. */
|
|
34
|
+
stateReadOnly?: string;
|
|
35
|
+
/** Sets base classes to the indicator. */
|
|
36
|
+
indicatorBase?: string;
|
|
37
|
+
/** Sets background classes to the indicator. */
|
|
38
|
+
indicatorBg?: string;
|
|
39
|
+
/** Sets text classes to the indicator. */
|
|
40
|
+
indicatorText?: string;
|
|
41
|
+
/** Sets border radius classes to the indicator. */
|
|
42
|
+
indicatorRounded?: string;
|
|
43
|
+
/** Provide arbitrary CSS classes to the indicator. */
|
|
44
|
+
indicatorClasses?: string;
|
|
45
|
+
/** Triggers when the value state is changed. */
|
|
46
|
+
onValueChange?: (value: string) => void;
|
|
47
|
+
}
|
|
48
|
+
export interface SegmentItemsProps extends React.PropsWithChildren, Omit<radio.ItemProps, 'invalid'> {
|
|
49
|
+
/** Sets base classes. */
|
|
50
|
+
base?: string;
|
|
51
|
+
/** Provide arbitrary CSS classes. */
|
|
52
|
+
classes?: string;
|
|
53
|
+
/** Set claseses for the disabled state. */
|
|
54
|
+
stateDisabled?: string;
|
|
55
|
+
/** Sets base classes for the label element. */
|
|
56
|
+
labelBase?: string;
|
|
57
|
+
/** Provide arbitrary CSS classes for the label element. */
|
|
58
|
+
labelClasses?: string;
|
|
59
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { SwitchProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SwitchProps } from './types.js';
|
|
3
3
|
export declare const Switch: React.FC<SwitchProps>;
|