@skeletonlabs/skeleton-react 1.0.0-next.0 → 1.0.0-next.10
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 +6 -8
- package/dist/components/AppBar/AppBar.js +28 -32
- package/dist/components/AppBar/types.d.ts +5 -5
- 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/FileUpload/FileUpload.d.ts +3 -0
- package/dist/components/FileUpload/FileUpload.js +41 -0
- package/dist/components/FileUpload/types.d.ts +73 -0
- package/dist/components/FileUpload/types.js +1 -0
- package/dist/components/Navigation/Navigation.d.ts +11 -0
- package/dist/components/Navigation/Navigation.js +103 -0
- package/dist/components/Navigation/types.d.ts +132 -0
- package/dist/components/Navigation/types.js +2 -0
- package/dist/components/Pagination/Pagination.d.ts +3 -0
- package/dist/components/Pagination/Pagination.js +38 -0
- package/dist/components/Pagination/types.d.ts +52 -0
- package/dist/components/Pagination/types.js +1 -0
- package/dist/components/Progress/Progress.d.ts +2 -2
- package/dist/components/Progress/Progress.js +22 -14
- package/dist/components/Progress/types.d.ts +20 -8
- package/dist/components/ProgressRing/ProgressRing.d.ts +3 -0
- package/dist/components/ProgressRing/ProgressRing.js +31 -0
- package/dist/components/ProgressRing/types.d.ts +51 -0
- package/dist/components/ProgressRing/types.js +1 -0
- package/dist/components/Rating/Rating.d.ts +3 -0
- package/dist/components/Rating/Rating.js +52 -0
- package/dist/components/Rating/types.d.ts +40 -0
- package/dist/components/Rating/types.js +1 -0
- package/dist/components/Segment/Segment.d.ts +6 -0
- package/dist/components/Segment/Segment.js +63 -0
- package/dist/components/Segment/types.d.ts +61 -0
- package/dist/components/Segment/types.js +2 -0
- package/dist/components/Slider/Slider.d.ts +3 -0
- package/dist/components/Slider/Slider.js +43 -0
- package/dist/components/Slider/types.d.ts +72 -0
- package/dist/components/Slider/types.js +1 -0
- package/dist/components/Switch/Switch.d.ts +3 -0
- package/dist/components/Switch/Switch.js +51 -0
- package/dist/components/Switch/types.d.ts +70 -0
- package/dist/components/Switch/types.js +1 -0
- 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/TagsInput/TagsInput.d.ts +3 -0
- package/dist/components/TagsInput/TagsInput.js +42 -0
- package/dist/components/TagsInput/types.d.ts +44 -0
- package/dist/components/TagsInput/types.js +1 -0
- package/dist/index.d.ts +15 -6
- package/dist/index.js +14 -6
- 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 +46 -40
- package/dist/components/Test/Test.d.ts +0 -2
- package/dist/components/Test/Test.js +0 -10
- package/dist/utils/react-compose.d.ts +0 -4
- package/dist/utils/react-compose.js +0 -3
|
@@ -0,0 +1,63 @@
|
|
|
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', stateFocused = 'focused',
|
|
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
|
+
const rxFocused = state.focused ? stateFocused : '';
|
|
59
|
+
return (_jsxs("label", { ...ctx.api.getItemProps(zagProps), className: `${base} ${rxDisabled} ${rxFocused} ${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" })] }));
|
|
60
|
+
};
|
|
61
|
+
export const Segment = Object.assign(SegmentRoot, {
|
|
62
|
+
Item: SegmentItem
|
|
63
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
/** Set claseses for the focus state. */
|
|
56
|
+
stateFocused?: string;
|
|
57
|
+
/** Sets base classes for the label element. */
|
|
58
|
+
labelBase?: string;
|
|
59
|
+
/** Provide arbitrary CSS classes for the label element. */
|
|
60
|
+
labelClasses?: string;
|
|
61
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import * as slider from '@zag-js/slider';
|
|
5
|
+
import { useMachine, normalizeProps } from '@zag-js/react';
|
|
6
|
+
import { noop } from '../../internal/noop.js';
|
|
7
|
+
export const Slider = ({ height = 'h-1.5', markers = [],
|
|
8
|
+
// Root ---
|
|
9
|
+
base = 'w-full', classes = '',
|
|
10
|
+
// Control ---
|
|
11
|
+
controlBase = '', controlClasses = '',
|
|
12
|
+
// Track ---
|
|
13
|
+
trackBase = 'overflow-hidden', trackBg = 'bg-surface-200-800', trackRounded = 'rounded-full', trackClasses = '',
|
|
14
|
+
// Meter ---
|
|
15
|
+
meterBase = '', meterBg = 'bg-surface-950-50', materRounded = 'rounded-container', meterClasses = '',
|
|
16
|
+
// Thumb ---
|
|
17
|
+
thumbBase = 'ring-inset transition-scale duration-100 ease-in-out', thumbSize = 'size-8 md:size-5', thumbBg = 'bg-surface-50-950', thumbRingSize = 'ring-2', thumbRingColor = 'ring-surface-950-50', thumbRounded = 'rounded-full', thumbScale = 'hover:scale-125', thumbCursor = 'hover:cursor-pointer', thumbClasses = '',
|
|
18
|
+
// Markers ---
|
|
19
|
+
markersBase = '', markerslasses = '',
|
|
20
|
+
// Mark ---
|
|
21
|
+
markBase = '', markText = 'text-[10px]', markOpacity = 'opacity-50', markClasses = '',
|
|
22
|
+
// State ---
|
|
23
|
+
stateDisabled = 'disabled', stateReadOnly = 'cursor-not-allowed',
|
|
24
|
+
// Events ---
|
|
25
|
+
onValueChange = noop, onValueChangeEnd = noop,
|
|
26
|
+
// Children ---
|
|
27
|
+
mark,
|
|
28
|
+
// Zag ---
|
|
29
|
+
...zagProps }) => {
|
|
30
|
+
// Zag
|
|
31
|
+
const [state, send] = useMachine(slider.machine({
|
|
32
|
+
id: useId(),
|
|
33
|
+
onValueChange: (details) => onValueChange(details.value),
|
|
34
|
+
onValueChangeEnd: (details) => onValueChangeEnd(details.value)
|
|
35
|
+
}), { context: zagProps });
|
|
36
|
+
const api = slider.connect(state, send, normalizeProps);
|
|
37
|
+
// Reactive
|
|
38
|
+
const rxDisabled = state.context.disabled ? stateDisabled : '';
|
|
39
|
+
const rxReadOnly = state.context.readOnly ? stateReadOnly : `${thumbScale} ${thumbCursor}`;
|
|
40
|
+
return (_jsxs("div", { ...api.getRootProps(), className: `${base} ${height} ${rxDisabled} ${classes}`, "data-testid": "slider", children: [_jsxs("div", { ...api.getControlProps(), className: `${controlBase} ${controlClasses}`, "data-testid": "slider-control", children: [_jsx("div", { ...api.getTrackProps(), className: `${trackBase} ${trackBg} ${height} ${trackRounded} ${trackClasses}`, "data-testid": "slider-track", children: _jsx("div", { ...api.getRangeProps(), className: `${meterBase} ${height} ${meterBg} ${materRounded} ${meterClasses}`, "data-testid": "slider-meter" }) }), _jsx("div", { className: `${height}`, style: { display: 'flex', alignItems: 'center', transform: 'translateY(-100%)' }, "data-testid": "slider-thumb-wrapper", children: api.value.map((_, index) => (_jsxs("div", { ...api.getThumbProps({ index }), children: [_jsx("div", { className: `${thumbBase} ${thumbSize} ${thumbBg} ${thumbRingSize} ${thumbRingColor} ${thumbRounded} ${rxReadOnly} ${thumbClasses}`, "data-testid": "slider-thumb" }), _jsx("input", { ...api.getHiddenInputProps({ index }), "data-testid": "slider-input" })] }, index))) })] }), markers.length > 0 && (_jsx("div", { ...api.getMarkerGroupProps(), className: `${markersBase} ${markerslasses}`, "data-testid": "slider-markers", children: markers.map((value) => (
|
|
41
|
+
// Mark
|
|
42
|
+
_jsx("span", { ...api.getMarkerProps({ value }), className: `${markBase} ${markText} ${markOpacity} ${markClasses}`, "data-testid": "slider-mark", children: mark ? mark : value }, value))) }))] }));
|
|
43
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as slider from '@zag-js/slider';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export interface SliderProps extends Omit<slider.Context, 'id' | 'onValueChange' | `onValueChangeEnd` | 'thumbSize'> {
|
|
4
|
+
/** Provide an array of value markers */
|
|
5
|
+
markers?: number[];
|
|
6
|
+
/** Set height classes for the overall slider. */
|
|
7
|
+
height?: string;
|
|
8
|
+
/** Set base classes. */
|
|
9
|
+
base?: string;
|
|
10
|
+
/** Provide arbitrary classes for the root. */
|
|
11
|
+
classes?: string;
|
|
12
|
+
/** Set base classes for the control. */
|
|
13
|
+
controlBase?: string;
|
|
14
|
+
/** Provide arbitrary classes for the control. */
|
|
15
|
+
controlClasses?: string;
|
|
16
|
+
/** Set base classes for the track. */
|
|
17
|
+
trackBase?: string;
|
|
18
|
+
/** Set background classes for the track. */
|
|
19
|
+
trackBg?: string;
|
|
20
|
+
/** Set border radius classes for the track. */
|
|
21
|
+
trackRounded?: string;
|
|
22
|
+
/** Provide arbitrary classes for the track. */
|
|
23
|
+
trackClasses?: string;
|
|
24
|
+
/** Set base classes for the meter. */
|
|
25
|
+
meterBase?: string;
|
|
26
|
+
/** Set background classes for the meter. */
|
|
27
|
+
meterBg?: string;
|
|
28
|
+
/** Set border radius classes for the meter. */
|
|
29
|
+
materRounded?: string;
|
|
30
|
+
/** Provide arbitrary classes for the meter. */
|
|
31
|
+
meterClasses?: string;
|
|
32
|
+
/** Set base classes for the thumb. */
|
|
33
|
+
thumbBase?: string;
|
|
34
|
+
/** Set size classes for the thumb. */
|
|
35
|
+
thumbSize?: string;
|
|
36
|
+
/** Set background classes for the thumb. */
|
|
37
|
+
thumbBg?: string;
|
|
38
|
+
/** Set ring size classes for the thumb. */
|
|
39
|
+
thumbRingSize?: string;
|
|
40
|
+
/** Set ring color classes for the thumb. */
|
|
41
|
+
thumbRingColor?: string;
|
|
42
|
+
/** Set border-radius classes for the thumb. */
|
|
43
|
+
thumbRounded?: string;
|
|
44
|
+
/** Set scale classes for the thumb. */
|
|
45
|
+
thumbScale?: string;
|
|
46
|
+
/** Set cursor classes for the thumb. */
|
|
47
|
+
thumbCursor?: string;
|
|
48
|
+
/** Provide arbitrary classes for the thumb. */
|
|
49
|
+
thumbClasses?: string;
|
|
50
|
+
/** Set base classes for the markers. */
|
|
51
|
+
markersBase?: string;
|
|
52
|
+
/** Provide arbitrary classes for the markers. */
|
|
53
|
+
markerslasses?: string;
|
|
54
|
+
/** Set base classes for each mark. */
|
|
55
|
+
markBase?: string;
|
|
56
|
+
/** Set text size classes for each mark. */
|
|
57
|
+
markText?: string;
|
|
58
|
+
/** Set opacity classes for each mark. */
|
|
59
|
+
markOpacity?: string;
|
|
60
|
+
/** Provide arbitrary classes for each mark. */
|
|
61
|
+
markClasses?: string;
|
|
62
|
+
/** Set disabled state classes for the root element. */
|
|
63
|
+
stateDisabled?: string;
|
|
64
|
+
/** Set read-only state classes for the root element. */
|
|
65
|
+
stateReadOnly?: string;
|
|
66
|
+
/** Triggers when the value state is being changed. */
|
|
67
|
+
onValueChange?: (value: number[]) => void;
|
|
68
|
+
/** Triggers when the value change has ended. */
|
|
69
|
+
onValueChangeEnd?: (value: number[]) => void;
|
|
70
|
+
/** Replace numeric markers with symbol, such as a icon. */
|
|
71
|
+
mark?: ReactNode;
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
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,
|
|
8
|
+
// Root (Track)
|
|
9
|
+
base = 'inline-flex items-center gap-4',
|
|
10
|
+
// State
|
|
11
|
+
stateFocused = '[&>span]:focused', classes = '',
|
|
12
|
+
// Control
|
|
13
|
+
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 = '',
|
|
14
|
+
// Thumb
|
|
15
|
+
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 = '',
|
|
16
|
+
// Label
|
|
17
|
+
labelBase = '', labelClasses = '',
|
|
18
|
+
// Icons
|
|
19
|
+
iconInactiveBase = 'pointer-events-none', iconActiveBase = 'pointer-events-none',
|
|
20
|
+
// Events
|
|
21
|
+
onCheckedChange = noop,
|
|
22
|
+
// Children
|
|
23
|
+
children, inactiveChild, activeChild }) => {
|
|
24
|
+
// Zag
|
|
25
|
+
const [state, send] = useMachine(zagSwitch.machine({
|
|
26
|
+
id: useId(),
|
|
27
|
+
name,
|
|
28
|
+
disabled,
|
|
29
|
+
checked,
|
|
30
|
+
onCheckedChange: (details) => onCheckedChange(details.checked)
|
|
31
|
+
}));
|
|
32
|
+
const api = zagSwitch.connect(state, send, normalizeProps);
|
|
33
|
+
// Set Compact Mode
|
|
34
|
+
if (compact) {
|
|
35
|
+
controlBase = thumbBase;
|
|
36
|
+
// Removes the height class
|
|
37
|
+
controlHeight = '';
|
|
38
|
+
// Thumb inherits track styles
|
|
39
|
+
thumbInactive = controlInactive;
|
|
40
|
+
thumbActive = controlActive;
|
|
41
|
+
// Remove X-axis translate
|
|
42
|
+
thumbTranslateX = '';
|
|
43
|
+
// Remove padding
|
|
44
|
+
controlPadding = '';
|
|
45
|
+
}
|
|
46
|
+
const rxTrackState = api.checked ? controlActive : controlInactive;
|
|
47
|
+
const rxThumbState = api.checked ? `${thumbActive} ${thumbTranslateX}` : thumbInactive;
|
|
48
|
+
const rxDisabled = api.disabled ? controlDisabled : '';
|
|
49
|
+
const rxFocused = api.focused ? stateFocused : '';
|
|
50
|
+
return (_jsxs("label", { ...api.getRootProps(), className: `${base} ${rxFocused} ${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 })] }));
|
|
51
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import * as zagSwitch from '@zag-js/switch';
|
|
3
|
+
export interface SwitchProps extends React.PropsWithChildren, Omit<zagSwitch.Context, 'id' | 'onCheckedChange'> {
|
|
4
|
+
/** Set a unique name for the switch input. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Set the checked state. */
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
/** Set the disabled state. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Set the compact display mode. */
|
|
11
|
+
compact?: boolean;
|
|
12
|
+
/** Set base classes for the root element. */
|
|
13
|
+
base?: string;
|
|
14
|
+
/** Provide arbitrary classes to the root element. */
|
|
15
|
+
classes?: string;
|
|
16
|
+
/** Set claseses for the focus state. */
|
|
17
|
+
stateFocused?: string;
|
|
18
|
+
/** Set base classes for the control element. */
|
|
19
|
+
controlBase?: string;
|
|
20
|
+
/** Set inactive state classes for the control element. */
|
|
21
|
+
controlInactive?: string;
|
|
22
|
+
/** Set active state classes for the control element. */
|
|
23
|
+
controlActive?: string;
|
|
24
|
+
/** Set disabled state classes for the control element. */
|
|
25
|
+
controlDisabled?: string;
|
|
26
|
+
/** Set width classes for the control element. */
|
|
27
|
+
controlWidth?: string;
|
|
28
|
+
/** Set height classes for the control element. */
|
|
29
|
+
controlHeight?: string;
|
|
30
|
+
/** Set padding classes for the control element. */
|
|
31
|
+
controlPadding?: string;
|
|
32
|
+
/** Set rounded classes for the control element. */
|
|
33
|
+
controlRounded?: string;
|
|
34
|
+
/** Set hover classes for the control element. */
|
|
35
|
+
controlHover?: string;
|
|
36
|
+
/** Provide arbitrary classes to the control element. */
|
|
37
|
+
controlClasses?: string;
|
|
38
|
+
/** Set base classes for the thumb element. */
|
|
39
|
+
thumbBase?: string;
|
|
40
|
+
/** Set inactive classes for the thumb element. */
|
|
41
|
+
thumbInactive?: string;
|
|
42
|
+
/** Set active classes for the thumb element. */
|
|
43
|
+
thumbActive?: string;
|
|
44
|
+
/** Set rounded classes for the thumb element. */
|
|
45
|
+
thumbRounded?: string;
|
|
46
|
+
/** Set animation X-axis translate classes for the thumb element. */
|
|
47
|
+
thumbTranslateX?: string;
|
|
48
|
+
/** Set animation transition classes for the thumb element. */
|
|
49
|
+
thumbTransition?: string;
|
|
50
|
+
/** Set animation easing classes for the thumb element. */
|
|
51
|
+
thumbEase?: string;
|
|
52
|
+
/** Set animation duration classes for the thumb element. */
|
|
53
|
+
thumbDuration?: string;
|
|
54
|
+
/** Provide arbitrary classes to the thumb element. */
|
|
55
|
+
thumbClasses?: string;
|
|
56
|
+
/** Set base classes for the label element. */
|
|
57
|
+
labelBase?: string;
|
|
58
|
+
/** Provide arbitrary classes to the label element. */
|
|
59
|
+
labelClasses?: string;
|
|
60
|
+
/** Set base classes for the inactive icon child. */
|
|
61
|
+
iconInactiveBase?: string;
|
|
62
|
+
/** Set base classes for the active icon child. */
|
|
63
|
+
iconActiveBase?: string;
|
|
64
|
+
/** Triggers when the switch is toggled. */
|
|
65
|
+
onCheckedChange?: (value: boolean) => void;
|
|
66
|
+
/** The inactive state children. */
|
|
67
|
+
inactiveChild?: ReactNode;
|
|
68
|
+
/** The active state children. */
|
|
69
|
+
activeChild?: ReactNode;
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
};
|
|
@@ -1,121 +1,87 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
+
import { createContext, useContext, useId } from 'react';
|
|
4
|
+
import * as tabs from '@zag-js/tabs';
|
|
5
|
+
import { useMachine, normalizeProps } from '@zag-js/react';
|
|
6
|
+
import { noop } from '../../internal/noop.js';
|
|
7
|
+
// Context ---
|
|
8
|
+
export const TabsContext = createContext({
|
|
9
|
+
fluid: false,
|
|
10
|
+
api: {}
|
|
11
|
+
});
|
|
3
12
|
// Components ---
|
|
4
|
-
const TabsRoot = ({
|
|
13
|
+
const TabsRoot = ({ fluid = false,
|
|
5
14
|
// Root
|
|
6
|
-
base =
|
|
15
|
+
base = 'w-full', classes = '',
|
|
16
|
+
// Events
|
|
17
|
+
onValueChange = noop,
|
|
7
18
|
// Children
|
|
8
|
-
children,
|
|
9
|
-
|
|
19
|
+
children,
|
|
20
|
+
// Zag
|
|
21
|
+
...zagProps }) => {
|
|
22
|
+
// Zag
|
|
23
|
+
const [state, send] = useMachine(tabs.machine({
|
|
24
|
+
id: useId(),
|
|
25
|
+
onValueChange: (details) => onValueChange(details.value)
|
|
26
|
+
}), { context: zagProps });
|
|
27
|
+
const api = tabs.connect(state, send, normalizeProps);
|
|
28
|
+
return (_jsx("div", { ...api.getRootProps(), className: `${base} ${classes}`, "data-testid": "tabs", children: _jsx(TabsContext.Provider, { value: { fluid, api }, children: children }) }));
|
|
10
29
|
};
|
|
11
30
|
const TabsList = ({
|
|
12
31
|
// Root
|
|
13
|
-
base =
|
|
32
|
+
base = 'flex', justify = 'justify-start', border = 'border-b-[1px] border-surface-200-800', margin = 'mb-4', gap = 'gap-2', classes = '',
|
|
14
33
|
// Children
|
|
15
|
-
children
|
|
16
|
-
|
|
34
|
+
children }) => {
|
|
35
|
+
const ctx = useContext(TabsContext);
|
|
36
|
+
return (_jsx("div", { ...ctx.api.getListProps(), className: `${base} ${justify} ${border} ${margin} ${gap} ${classes}`, "data-testid": "tabs-list", children: children }));
|
|
17
37
|
};
|
|
18
|
-
const TabsControl = ({
|
|
19
|
-
// A11y
|
|
20
|
-
label = "", controls = "",
|
|
38
|
+
const TabsControl = ({
|
|
21
39
|
// Root
|
|
22
|
-
base =
|
|
23
|
-
//
|
|
24
|
-
|
|
40
|
+
base = 'border-b-[1px] border-transparent', padding = 'pb-2', translateX = 'translate-y-[1px]', classes = '',
|
|
41
|
+
// Label
|
|
42
|
+
labelBase = 'btn hover:preset-tonal-primary', labelClasses = '',
|
|
43
|
+
// State
|
|
44
|
+
stateInactive = '[&:not(:hover)]:opacity-50', stateActive = 'border-surface-950-50 opacity-100', stateLabelInactive = '', stateLabelActive = '',
|
|
45
|
+
// Nodes
|
|
46
|
+
lead,
|
|
25
47
|
// Children
|
|
26
|
-
children,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
const elemInputRef = useRef(null);
|
|
39
|
-
function onKeyDownHandler(event) {
|
|
40
|
-
// Fire Event Handler
|
|
41
|
-
onKeydown(event);
|
|
42
|
-
// If select key events
|
|
43
|
-
if (!["ArrowRight", "ArrowLeft", "Home", "End"].includes(event.code))
|
|
44
|
-
return;
|
|
45
|
-
const elemInput = elemInputRef.current;
|
|
46
|
-
if (!elemInput)
|
|
47
|
-
return;
|
|
48
|
-
// Prevent default behavior
|
|
49
|
-
event.preventDefault();
|
|
50
|
-
// Find the closest tab/tablelist
|
|
51
|
-
const currTab = elemInput.closest('[role="tab"]');
|
|
52
|
-
if (!currTab)
|
|
53
|
-
return;
|
|
54
|
-
const tabList = elemInput.closest('[role="tablist"]');
|
|
55
|
-
if (!tabList)
|
|
56
|
-
return;
|
|
57
|
-
// Get RTL mode
|
|
58
|
-
const isRTL = getComputedStyle(tabList).direction === "rtl";
|
|
59
|
-
// Get list of tab elements
|
|
60
|
-
const tabs = Array.from(tabList.querySelectorAll('[role="tab"]'));
|
|
61
|
-
// Get a reference to the current tab
|
|
62
|
-
const currIndex = tabs.indexOf(currTab);
|
|
63
|
-
// Determine the index of the next tab
|
|
64
|
-
let nextIndex = -1;
|
|
65
|
-
switch (event.code) {
|
|
66
|
-
case "ArrowRight":
|
|
67
|
-
if (isRTL) {
|
|
68
|
-
nextIndex = currIndex - 1 < 0 ? tabs.length - 1 : currIndex - 1;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
nextIndex = currIndex + 1 >= tabs.length ? 0 : currIndex + 1;
|
|
72
|
-
break;
|
|
73
|
-
case "ArrowLeft":
|
|
74
|
-
if (isRTL) {
|
|
75
|
-
nextIndex = currIndex + 1 >= tabs.length ? 0 : currIndex + 1;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
nextIndex = currIndex - 1 < 0 ? tabs.length - 1 : currIndex - 1;
|
|
79
|
-
break;
|
|
80
|
-
case "Home":
|
|
81
|
-
nextIndex = 0;
|
|
82
|
-
break;
|
|
83
|
-
case "End":
|
|
84
|
-
nextIndex = tabs.length - 1;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
if (nextIndex < 0)
|
|
88
|
-
return;
|
|
89
|
-
// Set Active Tab
|
|
90
|
-
const nextTab = tabs[nextIndex];
|
|
91
|
-
const nextTabInput = nextTab?.querySelector("input");
|
|
92
|
-
if (nextTabInput) {
|
|
93
|
-
nextTabInput.click();
|
|
94
|
-
nextTab.focus();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return (_jsx("label", { id: id, className: `${base} ${width} ${rxActive} ${flex} ${background} ${border} ${text} ${padding} ${rounded} ${gap} ${cursor} ${classes}`, "aria-label": label, title: title, children: _jsxs("div", { className: "size-full", role: "tab", "aria-controls": controls, "aria-selected": selected, "data-testid": "tabs-control", tabIndex: selected ? 0 : -1, onKeyDown: onKeyDownHandler, onKeyUp: onKeyup, children: [_jsx("div", { className: "h-0 w-0 flex-none overflow-hidden", children: _jsx("input", { ref: elemInputRef, type: "radio", name: name, value: name, checked: selected, onChange: handleOnChange, onClick: onClick, tabIndex: -1 }) }), children] }) }));
|
|
48
|
+
children,
|
|
49
|
+
// Zag
|
|
50
|
+
...zagProps }) => {
|
|
51
|
+
const ctx = useContext(TabsContext);
|
|
52
|
+
const state = ctx.api.getTriggerState(zagProps);
|
|
53
|
+
// Reactive
|
|
54
|
+
const rxActive = state.selected ? stateActive : stateInactive;
|
|
55
|
+
const rxLabelActive = state.selected ? stateLabelActive : stateLabelInactive;
|
|
56
|
+
// Styles
|
|
57
|
+
const commonStyles = { width: ctx.fluid ? '100%' : '' };
|
|
58
|
+
return (_jsx("button", { ...ctx.api.getTriggerProps(zagProps), className: `${base} ${padding} ${translateX} ${rxActive} ${classes}`, style: commonStyles, "data-testid": "tabs-control", children: _jsxs("div", { className: `${labelBase} ${rxLabelActive} ${labelClasses}`, style: commonStyles, "data-testid": "tabs-control-label", children: [lead && _jsx("span", { "data-testid": "tabs-control-lead", children: lead }), _jsx("span", { "data-testid": "tabs-control-children", children: children })] }) }));
|
|
98
59
|
};
|
|
99
|
-
const
|
|
60
|
+
const TabsContent = ({
|
|
100
61
|
// Root
|
|
101
|
-
base =
|
|
62
|
+
base = '', classes = '',
|
|
102
63
|
// Children
|
|
103
|
-
children
|
|
104
|
-
return (_jsx("div", { className: `${base} ${
|
|
64
|
+
children }) => {
|
|
65
|
+
return (_jsx("div", { className: `${base} ${classes}`, "data-testid": "tabs-content", children: children }));
|
|
105
66
|
};
|
|
106
|
-
const
|
|
107
|
-
// A11y
|
|
108
|
-
labelledBy,
|
|
67
|
+
const TabsPanel = ({
|
|
109
68
|
// Root
|
|
110
|
-
classes =
|
|
69
|
+
base = '', classes = '',
|
|
111
70
|
// Children
|
|
112
|
-
children,
|
|
113
|
-
|
|
114
|
-
|
|
71
|
+
children,
|
|
72
|
+
// Zag
|
|
73
|
+
...zagProps }) => {
|
|
74
|
+
const ctx = useContext(TabsContext);
|
|
75
|
+
return (_jsx("div", { ...ctx.api.getContentProps(zagProps), className: `${base} ${classes}`, "data-testid": "tabs-panel", children: children }));
|
|
115
76
|
};
|
|
77
|
+
// Export ---
|
|
116
78
|
export const Tabs = Object.assign(TabsRoot, {
|
|
79
|
+
/** A group of tab controls. */
|
|
117
80
|
List: TabsList,
|
|
81
|
+
/** An individual tab control. */
|
|
118
82
|
Control: TabsControl,
|
|
119
|
-
|
|
120
|
-
|
|
83
|
+
/** A group of tab panels. */
|
|
84
|
+
Content: TabsContent,
|
|
85
|
+
/** An individual tab panel. */
|
|
86
|
+
Panel: TabsPanel
|
|
121
87
|
});
|