@skeletonlabs/skeleton-react 1.0.0-next.3 → 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 +38 -59
- package/dist/components/Accordion/types.d.ts +23 -24
- package/dist/components/Avatar/Avatar.js +17 -3
- package/dist/components/Avatar/types.d.ts +10 -5
- package/dist/components/Navigation/types.d.ts +0 -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 +18 -24
- package/dist/components/ProgressRing/types.d.ts +8 -12
- package/dist/components/Rating/Rating.d.ts +3 -3
- package/dist/components/Rating/Rating.js +50 -79
- package/dist/components/Rating/types.d.ts +35 -54
- package/dist/components/Segment/Segment.d.ts +4 -4
- package/dist/components/Segment/Segment.js +41 -39
- package/dist/components/Segment/types.d.ts +28 -25
- package/dist/components/Switch/Switch.js +31 -22
- package/dist/components/Switch/types.d.ts +27 -24
- package/dist/components/Tabs/Tabs.d.ts +12 -7
- package/dist/components/Tabs/Tabs.js +61 -102
- package/dist/components/Tabs/types.d.ts +48 -85
- 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 +24 -19
|
@@ -1,82 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
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 = ({
|
|
6
8
|
// Root
|
|
7
|
-
base = '
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
|
|
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,
|
|
16
20
|
// Children
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
valueRef.current = Math.min(max, valueRef.current + 1 / step);
|
|
50
|
-
onValueChange(valueRef.current);
|
|
51
|
-
refreshFocus();
|
|
52
|
-
}
|
|
53
|
-
function decreaseValue() {
|
|
54
|
-
valueRef.current = Math.max(0, valueRef.current - 1 / step);
|
|
55
|
-
onValueChange(valueRef.current);
|
|
56
|
-
refreshFocus();
|
|
57
|
-
}
|
|
58
|
-
function refreshFocus() {
|
|
59
|
-
if (!figureRef.current)
|
|
60
|
-
return;
|
|
61
|
-
const buttons = figureRef.current.querySelectorAll('button');
|
|
62
|
-
buttons[Math.max(0, Math.ceil(valueRef.current - 1))].focus();
|
|
63
|
-
}
|
|
64
|
-
if (!figureRef.current)
|
|
65
|
-
return;
|
|
66
|
-
const rtl = getComputedStyle(figureRef.current).direction === 'rtl';
|
|
67
|
-
if (['ArrowLeft', 'ArrowUp'].includes(event.key)) {
|
|
68
|
-
event.preventDefault();
|
|
69
|
-
rtl ? increaseValue() : decreaseValue();
|
|
70
|
-
}
|
|
71
|
-
if (['ArrowRight', 'ArrowDown'].includes(event.key)) {
|
|
72
|
-
event.preventDefault();
|
|
73
|
-
rtl ? decreaseValue() : increaseValue();
|
|
74
|
-
}
|
|
75
|
-
onKeyDown(event);
|
|
76
|
-
}, [onKeyDown, max, onValueChange, step]);
|
|
77
|
-
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: {
|
|
78
|
-
'--clipValue': `${(value - order) * 100}%`
|
|
79
|
-
}, "data-testid": "rating-iconempty", children: iconEmpty }), _jsx("span", { className: `${fullBase} ${fullClip} ${rxFullInteractive} ${fullClasses}`, style: {
|
|
80
|
-
'--clipValue': `${100 - (value - order) * 100}%`
|
|
81
|
-
}, "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" })] }));
|
|
82
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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FC } from 'react';
|
|
2
2
|
import type { SegmentContextState, SegmentProps, SegmentItemsProps } from './types.js';
|
|
3
|
-
export declare const SegmentContext:
|
|
4
|
-
export declare const Segment:
|
|
5
|
-
Item:
|
|
3
|
+
export declare const SegmentContext: import("react").Context<SegmentContextState>;
|
|
4
|
+
export declare const Segment: FC<SegmentProps> & {
|
|
5
|
+
Item: FC<SegmentItemsProps>;
|
|
6
6
|
};
|
|
@@ -1,59 +1,61 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext,
|
|
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';
|
|
4
7
|
// Contexts ---
|
|
5
8
|
export const SegmentContext = createContext({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
onSelectionHandler: () => { }
|
|
9
|
+
api: {},
|
|
10
|
+
indicatorText: ''
|
|
9
11
|
});
|
|
10
12
|
// Components ---
|
|
11
|
-
const SegmentRoot = ({
|
|
13
|
+
const SegmentRoot = ({ orientation = 'horizontal',
|
|
12
14
|
// Root
|
|
13
|
-
base = 'inline-flex items-stretch overflow-hidden', background = 'preset-outlined-surface-200-800', border = 'p-2',
|
|
14
|
-
|
|
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 = '',
|
|
15
20
|
// Events
|
|
16
|
-
|
|
21
|
+
onValueChange = noop,
|
|
17
22
|
// Children
|
|
18
|
-
children
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
24
33
|
// Set Context
|
|
25
|
-
const ctx = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return (
|
|
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 })] }));
|
|
31
40
|
};
|
|
32
|
-
const SegmentItem = ({
|
|
41
|
+
const SegmentItem = ({
|
|
33
42
|
// Root
|
|
34
|
-
base = 'btn
|
|
43
|
+
base = 'btn cursor-pointer z-[1]', classes = '',
|
|
35
44
|
// Label
|
|
36
|
-
labelBase = 'pointer-events-none', labelClasses = '',
|
|
37
|
-
//
|
|
38
|
-
|
|
45
|
+
labelBase = 'pointer-events-none transition-colors duration-100', labelClasses = '',
|
|
46
|
+
// State
|
|
47
|
+
stateDisabled = 'disabled',
|
|
39
48
|
// Children
|
|
40
|
-
children
|
|
49
|
+
children,
|
|
50
|
+
// Zag
|
|
51
|
+
...zagProps }) => {
|
|
41
52
|
// Get Context
|
|
42
53
|
const ctx = useContext(SegmentContext);
|
|
54
|
+
const state = ctx.api.getItemState(zagProps);
|
|
43
55
|
// Reactive
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
setSelected(value === ctx.value);
|
|
48
|
-
}, [value, ctx.value]);
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
setRxActive(selected ? active : hover);
|
|
51
|
-
}, [selected, active, hover]);
|
|
52
|
-
function onClickHandler() {
|
|
53
|
-
ctx.onSelectionHandler(value);
|
|
54
|
-
onClick?.(value);
|
|
55
|
-
}
|
|
56
|
-
return (_jsxs("button", { role: "radio", "aria-checked": selected, onClick: onClickHandler, type: "button", className: `${base} ${rxActive} ${classes}`, title: title, disabled: disabled, "data-testid": "segment-item", children: [selected ? _jsx("input", { type: "hidden", name: ctx.name, id: id, value: value }) : null, _jsx("label", { className: `${labelBase} ${labelClasses}`, children: children })] }));
|
|
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" })] }));
|
|
57
59
|
};
|
|
58
60
|
export const Segment = Object.assign(SegmentRoot, {
|
|
59
61
|
Item: SegmentItem
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import * as radio from '@zag-js/radio-group';
|
|
2
2
|
export interface SegmentContextState {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
onSelectionHandler: (value: string) => void;
|
|
3
|
+
api: ReturnType<typeof radio.connect>;
|
|
4
|
+
indicatorText: string;
|
|
6
5
|
}
|
|
7
|
-
export interface SegmentProps extends React.PropsWithChildren {
|
|
8
|
-
/** Set the
|
|
9
|
-
|
|
10
|
-
/** Provide the shared input name. */
|
|
11
|
-
name: string;
|
|
6
|
+
export interface SegmentProps extends React.PropsWithChildren, Omit<radio.Context, 'id' | 'orientation' | 'onValueChange'> {
|
|
7
|
+
/** Set the orientation. */
|
|
8
|
+
orientation?: radio.Context['orientation'];
|
|
12
9
|
/** Sets base classes. */
|
|
13
10
|
base?: string;
|
|
14
11
|
/** Set background classes. */
|
|
@@ -27,30 +24,36 @@ export interface SegmentProps extends React.PropsWithChildren {
|
|
|
27
24
|
width?: string;
|
|
28
25
|
/** Provide arbitrary CSS classes. */
|
|
29
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;
|
|
30
45
|
/** Triggers when the value state is changed. */
|
|
31
|
-
|
|
46
|
+
onValueChange?: (value: string) => void;
|
|
32
47
|
}
|
|
33
|
-
export interface SegmentItemsProps extends React.PropsWithChildren {
|
|
34
|
-
/** Provide a unique ID. */
|
|
35
|
-
id: string;
|
|
36
|
-
/** Provide the unique segment value. */
|
|
37
|
-
value: string;
|
|
38
|
-
/** Provide a hover title attribute. */
|
|
39
|
-
title?: string;
|
|
40
|
-
/** Set the disabled state. */
|
|
41
|
-
disabled?: boolean;
|
|
48
|
+
export interface SegmentItemsProps extends React.PropsWithChildren, Omit<radio.ItemProps, 'invalid'> {
|
|
42
49
|
/** Sets base classes. */
|
|
43
50
|
base?: string;
|
|
44
|
-
/** Sets active state classes. */
|
|
45
|
-
active?: string;
|
|
46
|
-
/** Sets hover state classes. */
|
|
47
|
-
hover?: string;
|
|
48
51
|
/** Provide arbitrary CSS classes. */
|
|
49
52
|
classes?: string;
|
|
53
|
+
/** Set claseses for the disabled state. */
|
|
54
|
+
stateDisabled?: string;
|
|
50
55
|
/** Sets base classes for the label element. */
|
|
51
56
|
labelBase?: string;
|
|
52
57
|
/** Provide arbitrary CSS classes for the label element. */
|
|
53
58
|
labelClasses?: string;
|
|
54
|
-
/** Triggers on items click event. */
|
|
55
|
-
onClick?: (group: string) => void;
|
|
56
59
|
}
|
|
@@ -1,39 +1,48 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import * as zagSwitch from '@zag-js/switch';
|
|
5
|
+
import { useMachine, normalizeProps } from '@zag-js/react';
|
|
6
|
+
import { noop } from '../../internal/noop.js';
|
|
7
|
+
export const Switch = ({ name = '', checked = false, disabled = false, compact = false,
|
|
6
8
|
// Root (Track)
|
|
7
|
-
base = 'flex
|
|
9
|
+
base = 'inline-flex items-center gap-4', classes = '',
|
|
10
|
+
// Control
|
|
11
|
+
controlBase = 'cursor-pointer transition duration-200', controlInactive = 'preset-filled-surface-200-800', controlActive = 'preset-filled-primary-500', controlDisabled = 'opacity-50 cursor-not-allowed', controlWidth = 'w-10', controlHeight = 'h-6', controlPadding = 'p-0.5', controlRounded = 'rounded-full', controlHover = 'hover:brightness-90 dark:hover:brightness-110', controlClasses = '',
|
|
8
12
|
// Thumb
|
|
9
|
-
thumbBase = 'right-0 aspect-square h-full flex justify-center items-center text-right', thumbInactive = 'preset-filled-surface-50-950', thumbActive = 'bg-surface-50 text-surface-contrast-50', thumbRounded = 'rounded-full', thumbTranslateX = 'translate-x-4', thumbTransition = 'transition', thumbEase = 'ease-in-out', thumbDuration = 'duration-200', thumbClasses = '',
|
|
13
|
+
thumbBase = 'right-0 aspect-square h-full flex justify-center items-center text-right cursor-pointer', thumbInactive = 'preset-filled-surface-50-950', thumbActive = 'bg-surface-50 text-surface-contrast-50', thumbRounded = 'rounded-full', thumbTranslateX = 'translate-x-4 rtl:-translate-x-4', thumbTransition = 'transition', thumbEase = 'ease-in-out', thumbDuration = 'duration-200', thumbClasses = '',
|
|
14
|
+
// Label
|
|
15
|
+
labelBase = '', labelClasses = '',
|
|
10
16
|
// Icons
|
|
11
17
|
iconInactiveBase = 'pointer-events-none', iconActiveBase = 'pointer-events-none',
|
|
12
18
|
// Events
|
|
13
|
-
|
|
19
|
+
onCheckedChange = noop,
|
|
14
20
|
// Children
|
|
15
|
-
inactiveChild, activeChild }) => {
|
|
21
|
+
children, inactiveChild, activeChild }) => {
|
|
22
|
+
// Zag
|
|
23
|
+
const [state, send] = useMachine(zagSwitch.machine({
|
|
24
|
+
id: useId(),
|
|
25
|
+
name,
|
|
26
|
+
disabled,
|
|
27
|
+
checked,
|
|
28
|
+
onCheckedChange: (details) => onCheckedChange(details.checked)
|
|
29
|
+
}));
|
|
30
|
+
const api = zagSwitch.connect(state, send, normalizeProps);
|
|
16
31
|
// Set Compact Mode
|
|
17
32
|
if (compact) {
|
|
18
|
-
|
|
33
|
+
controlBase = thumbBase;
|
|
19
34
|
// Removes the height class
|
|
20
|
-
|
|
35
|
+
controlHeight = '';
|
|
21
36
|
// Thumb inherits track styles
|
|
22
|
-
thumbInactive =
|
|
23
|
-
thumbActive =
|
|
37
|
+
thumbInactive = controlInactive;
|
|
38
|
+
thumbActive = controlActive;
|
|
24
39
|
// Remove X-axis translate
|
|
25
40
|
thumbTranslateX = '';
|
|
26
41
|
// Remove padding
|
|
27
|
-
|
|
42
|
+
controlPadding = '';
|
|
28
43
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
onChange(checked);
|
|
34
|
-
}
|
|
35
|
-
const rxTrackState = checked ? stateActive : stateInactive;
|
|
36
|
-
const rxThumbState = checked ? `${thumbActive} ${thumbTranslateX}` : thumbInactive;
|
|
37
|
-
const rxDisabled = disabled ? stateDisabled : '';
|
|
38
|
-
return (_jsxs("button", { type: "button", className: `${base} ${rxTrackState} ${width} ${height} ${padding} ${rounded} ${hover} ${rxDisabled} ${classes}`, role: "switch", "aria-checked": checked, "aria-labelledby": labelledby, "aria-describedby": describedby, onClick: toggle, "data-testid": "switch", children: [checked ?? _jsx("input", { type: "hidden", id: id, name: name, value: "on", disabled: disabled }), _jsxs("div", { className: `${thumbBase} ${rxThumbState} ${thumbRounded} ${thumbTransition} ${thumbEase} ${thumbDuration} ${thumbClasses}`, children: [!checked && inactiveChild ? _jsx("span", { className: iconInactiveBase, children: inactiveChild }) : null, checked && activeChild ? _jsx("span", { className: iconActiveBase, children: activeChild }) : null] })] }));
|
|
44
|
+
const rxTrackState = api.checked ? controlActive : controlInactive;
|
|
45
|
+
const rxThumbState = api.checked ? `${thumbActive} ${thumbTranslateX}` : thumbInactive;
|
|
46
|
+
const rxDisabled = api.disabled ? controlDisabled : '';
|
|
47
|
+
return (_jsxs("label", { ...api.getRootProps(), className: `${base} ${classes}`, "data-testid": "switch", children: [_jsx("input", { ...api.getHiddenInputProps(), "data-testid": "switch-input" }), _jsx("span", { ...api.getControlProps(), className: `${controlBase} ${rxTrackState} ${controlWidth} ${controlHeight} ${controlPadding} ${controlRounded} ${controlHover} ${rxDisabled} ${controlClasses}`, "data-testid": "switch-control", children: _jsxs("span", { ...api.getThumbProps(), className: `${thumbBase} ${rxThumbState} ${thumbRounded} ${thumbTransition} ${thumbEase} ${thumbDuration} ${thumbClasses}`, "data-testid": "switch-thumb", children: [!checked && inactiveChild ? (_jsx("span", { className: iconInactiveBase, "data-testid": "switch-icon-inactive", children: inactiveChild })) : null, checked && activeChild ? (_jsx("span", { className: iconActiveBase, "data-testid": "switch-icon-active", children: activeChild })) : null] }) }), _jsx("span", { ...api.getLabelProps(), className: `${labelBase} ${labelClasses}`, "data-testid": "switch-label", children: children })] }));
|
|
39
48
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
id: string;
|
|
2
|
+
import * as zagSwitch from '@zag-js/switch';
|
|
3
|
+
export interface SwitchProps extends React.PropsWithChildren, Omit<zagSwitch.Context, 'id' | 'onCheckedChange'> {
|
|
5
4
|
/** Set a unique name for the switch input. */
|
|
6
5
|
name: string;
|
|
7
6
|
/** Set the checked state. */
|
|
@@ -10,30 +9,30 @@ export interface SwitchProps {
|
|
|
10
9
|
disabled?: boolean;
|
|
11
10
|
/** Set the compact display mode. */
|
|
12
11
|
compact?: boolean;
|
|
13
|
-
/** Identifies the element that labels the switch. */
|
|
14
|
-
labelledby?: string | undefined;
|
|
15
|
-
/** Identifies the element that describes the switch. */
|
|
16
|
-
describedby?: string | undefined;
|
|
17
12
|
/** Set base classes for the root element. */
|
|
18
13
|
base?: string;
|
|
19
|
-
/** Set inactive state classes for the root element. */
|
|
20
|
-
stateInactive?: string;
|
|
21
|
-
/** Set active state classes for the root element. */
|
|
22
|
-
stateActive?: string;
|
|
23
|
-
/** Set disabled state classes for the root element. */
|
|
24
|
-
stateDisabled?: string;
|
|
25
|
-
/** Set width classes for the root element. */
|
|
26
|
-
width?: string;
|
|
27
|
-
/** Set height classes for the root element. */
|
|
28
|
-
height?: string;
|
|
29
|
-
/** Set padding classes for the root element. */
|
|
30
|
-
padding?: string;
|
|
31
|
-
/** Set rounded classes for the root element. */
|
|
32
|
-
rounded?: string;
|
|
33
|
-
/** Set hover classes for the root element. */
|
|
34
|
-
hover?: string;
|
|
35
14
|
/** Provide arbitrary classes to the root element. */
|
|
36
15
|
classes?: string;
|
|
16
|
+
/** Set base classes for the control element. */
|
|
17
|
+
controlBase?: string;
|
|
18
|
+
/** Set inactive state classes for the control element. */
|
|
19
|
+
controlInactive?: string;
|
|
20
|
+
/** Set active state classes for the control element. */
|
|
21
|
+
controlActive?: string;
|
|
22
|
+
/** Set disabled state classes for the control element. */
|
|
23
|
+
controlDisabled?: string;
|
|
24
|
+
/** Set width classes for the control element. */
|
|
25
|
+
controlWidth?: string;
|
|
26
|
+
/** Set height classes for the control element. */
|
|
27
|
+
controlHeight?: string;
|
|
28
|
+
/** Set padding classes for the control element. */
|
|
29
|
+
controlPadding?: string;
|
|
30
|
+
/** Set rounded classes for the control element. */
|
|
31
|
+
controlRounded?: string;
|
|
32
|
+
/** Set hover classes for the control element. */
|
|
33
|
+
controlHover?: string;
|
|
34
|
+
/** Provide arbitrary classes to the control element. */
|
|
35
|
+
controlClasses?: string;
|
|
37
36
|
/** Set base classes for the thumb element. */
|
|
38
37
|
thumbBase?: string;
|
|
39
38
|
/** Set inactive classes for the thumb element. */
|
|
@@ -52,12 +51,16 @@ export interface SwitchProps {
|
|
|
52
51
|
thumbDuration?: string;
|
|
53
52
|
/** Provide arbitrary classes to the thumb element. */
|
|
54
53
|
thumbClasses?: string;
|
|
54
|
+
/** Set base classes for the label element. */
|
|
55
|
+
labelBase?: string;
|
|
56
|
+
/** Provide arbitrary classes to the label element. */
|
|
57
|
+
labelClasses?: string;
|
|
55
58
|
/** Set base classes for the inactive icon child. */
|
|
56
59
|
iconInactiveBase?: string;
|
|
57
60
|
/** Set base classes for the active icon child. */
|
|
58
61
|
iconActiveBase?: string;
|
|
59
62
|
/** Triggers when the switch is toggled. */
|
|
60
|
-
|
|
63
|
+
onCheckedChange?: (value: boolean) => void;
|
|
61
64
|
/** The inactive state children. */
|
|
62
65
|
inactiveChild?: ReactNode;
|
|
63
66
|
/** The active state children. */
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { TabsContextState, TabsRootProps, TabsListProps, TabsControlProps, TabsContentProps, TabsPanelProps } from './types.js';
|
|
3
|
+
export declare const TabsContext: import("react").Context<TabsContextState>;
|
|
4
|
+
export declare const Tabs: FC<TabsRootProps> & {
|
|
5
|
+
/** A group of tab controls. */
|
|
6
|
+
List: FC<TabsListProps>;
|
|
7
|
+
/** An individual tab control. */
|
|
8
|
+
Control: FC<TabsControlProps>;
|
|
9
|
+
/** A group of tab panels. */
|
|
10
|
+
Content: FC<TabsContentProps>;
|
|
11
|
+
/** An individual tab panel. */
|
|
12
|
+
Panel: FC<TabsPanelProps>;
|
|
8
13
|
};
|