@skeletonlabs/skeleton-react 1.0.0-next.1 → 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.
Files changed (61) hide show
  1. package/dist/components/Accordion/Accordion.d.ts +9 -8
  2. package/dist/components/Accordion/Accordion.js +47 -68
  3. package/dist/components/Accordion/types.d.ts +24 -25
  4. package/dist/components/AppBar/AppBar.d.ts +6 -8
  5. package/dist/components/AppBar/AppBar.js +28 -32
  6. package/dist/components/AppBar/types.d.ts +5 -5
  7. package/dist/components/Avatar/Avatar.d.ts +2 -2
  8. package/dist/components/Avatar/Avatar.js +21 -7
  9. package/dist/components/Avatar/types.d.ts +10 -5
  10. package/dist/components/FileUpload/FileUpload.d.ts +3 -0
  11. package/dist/components/FileUpload/FileUpload.js +41 -0
  12. package/dist/components/FileUpload/types.d.ts +73 -0
  13. package/dist/components/FileUpload/types.js +1 -0
  14. package/dist/components/Navigation/Navigation.d.ts +11 -0
  15. package/dist/components/Navigation/Navigation.js +103 -0
  16. package/dist/components/Navigation/types.d.ts +132 -0
  17. package/dist/components/Navigation/types.js +2 -0
  18. package/dist/components/Pagination/Pagination.d.ts +3 -0
  19. package/dist/components/Pagination/Pagination.js +38 -0
  20. package/dist/components/Pagination/types.d.ts +52 -0
  21. package/dist/components/Pagination/types.js +1 -0
  22. package/dist/components/Progress/Progress.d.ts +2 -2
  23. package/dist/components/Progress/Progress.js +22 -14
  24. package/dist/components/Progress/types.d.ts +20 -8
  25. package/dist/components/ProgressRing/ProgressRing.d.ts +3 -0
  26. package/dist/components/ProgressRing/ProgressRing.js +31 -0
  27. package/dist/components/ProgressRing/types.d.ts +51 -0
  28. package/dist/components/ProgressRing/types.js +1 -0
  29. package/dist/components/Rating/Rating.d.ts +3 -0
  30. package/dist/components/Rating/Rating.js +52 -0
  31. package/dist/components/Rating/types.d.ts +40 -0
  32. package/dist/components/Rating/types.js +1 -0
  33. package/dist/components/Segment/Segment.d.ts +6 -0
  34. package/dist/components/Segment/Segment.js +63 -0
  35. package/dist/components/Segment/types.d.ts +61 -0
  36. package/dist/components/Segment/types.js +2 -0
  37. package/dist/components/Slider/Slider.d.ts +3 -0
  38. package/dist/components/Slider/Slider.js +43 -0
  39. package/dist/components/Slider/types.d.ts +72 -0
  40. package/dist/components/Slider/types.js +1 -0
  41. package/dist/components/Switch/Switch.d.ts +2 -2
  42. package/dist/components/Switch/Switch.js +37 -27
  43. package/dist/components/Switch/types.d.ts +30 -25
  44. package/dist/components/Tabs/Tabs.d.ts +12 -7
  45. package/dist/components/Tabs/Tabs.js +65 -99
  46. package/dist/components/Tabs/types.d.ts +48 -81
  47. package/dist/components/TagsInput/TagsInput.d.ts +3 -0
  48. package/dist/components/TagsInput/TagsInput.js +42 -0
  49. package/dist/components/TagsInput/types.d.ts +44 -0
  50. package/dist/components/TagsInput/types.js +1 -0
  51. package/dist/index.d.ts +15 -7
  52. package/dist/index.js +14 -7
  53. package/dist/internal/nodes.d.ts +3 -0
  54. package/dist/internal/nodes.js +4 -0
  55. package/dist/internal/noop.d.ts +1 -0
  56. package/dist/internal/noop.js +2 -0
  57. package/package.json +46 -41
  58. package/dist/components/Test/Test.d.ts +0 -2
  59. package/dist/components/Test/Test.js +0 -10
  60. package/dist/utils/react-compose.d.ts +0 -4
  61. 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,2 @@
1
+ // Segment Control Types
2
+ export {};
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import type { SliderProps } from './types';
3
+ export declare const Slider: FC<SliderProps>;
@@ -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 {};
@@ -1,3 +1,3 @@
1
- import React from "react";
2
- import { SwitchProps } from "./types.js";
1
+ import React from 'react';
2
+ import { SwitchProps } from './types.js';
3
3
  export declare const Switch: React.FC<SwitchProps>;
@@ -1,41 +1,51 @@
1
- "use client";
1
+ 'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- export const Switch = ({ id = "", name = "", checked = false, disabled = false, compact = false,
4
- // Aria
5
- labelledby = undefined, describedby = undefined,
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 cursor-pointer transition duration-200", stateInactive = "preset-filled-surface-200-800", stateActive = "preset-filled-primary-500", stateDisabled = "opacity-50 cursor-not-allowed", width = "w-10", height = "h-6", padding = "p-0.5", rounded = "rounded-full", hover = "hover:brightness-90 dark:hover:brightness-110", classes = "",
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 = '',
8
14
  // 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 = "",
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 = '',
10
18
  // Icons
11
- iconInactiveBase = "pointer-events-none", iconActiveBase = "pointer-events-none",
19
+ iconInactiveBase = 'pointer-events-none', iconActiveBase = 'pointer-events-none',
12
20
  // Events
13
- onCheckedChange = () => { },
21
+ onCheckedChange = noop,
14
22
  // Children
15
- inactiveChild, activeChild, }) => {
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);
16
33
  // Set Compact Mode
17
34
  if (compact) {
18
- base = thumbBase;
35
+ controlBase = thumbBase;
19
36
  // Removes the height class
20
- height = "";
37
+ controlHeight = '';
21
38
  // Thumb inherits track styles
22
- thumbInactive = stateInactive;
23
- thumbActive = stateActive;
39
+ thumbInactive = controlInactive;
40
+ thumbActive = controlActive;
24
41
  // Remove X-axis translate
25
- thumbTranslateX = "";
42
+ thumbTranslateX = '';
26
43
  // Remove padding
27
- padding = "";
44
+ controlPadding = '';
28
45
  }
29
- function toggle() {
30
- if (disabled)
31
- return;
32
- checked = !checked;
33
- onCheckedChange(checked);
34
- }
35
- const rxTrackState = checked ? stateActive : stateInactive;
36
- const rxThumbState = checked
37
- ? `${thumbActive} ${thumbTranslateX}`
38
- : thumbInactive;
39
- const rxDisabled = disabled ? stateDisabled : "";
40
- 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: [_jsx("input", { type: "checkbox", id: id, name: name, checked: checked, onChange: () => { }, className: "hidden", 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] })] }));
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 })] }));
41
51
  };
@@ -1,7 +1,6 @@
1
- import { ReactNode } from "react";
2
- export interface SwitchProps {
3
- /** Set a unique ID for the switch input. */
4
- id: string;
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'> {
5
4
  /** Set a unique name for the switch input. */
6
5
  name: string;
7
6
  /** Set the checked state. */
@@ -10,30 +9,32 @@ 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 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;
37
38
  /** Set base classes for the thumb element. */
38
39
  thumbBase?: string;
39
40
  /** Set inactive classes for the thumb element. */
@@ -52,12 +53,16 @@ export interface SwitchProps {
52
53
  thumbDuration?: string;
53
54
  /** Provide arbitrary classes to the thumb element. */
54
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;
55
60
  /** Set base classes for the inactive icon child. */
56
61
  iconInactiveBase?: string;
57
62
  /** Set base classes for the active icon child. */
58
63
  iconActiveBase?: string;
59
64
  /** Triggers when the switch is toggled. */
60
- onCheckedChange?: (event: boolean) => void;
65
+ onCheckedChange?: (value: boolean) => void;
61
66
  /** The inactive state children. */
62
67
  inactiveChild?: ReactNode;
63
68
  /** The active state children. */
@@ -1,8 +1,13 @@
1
- import React from "react";
2
- import { TabsProps, TabsListProps, TabsControlProps, TabsControlItemProps, TabsPanelItemProps } from "./types.js";
3
- export declare const Tabs: React.FC<TabsProps> & {
4
- List: React.FC<TabsListProps>;
5
- Control: React.FC<TabsControlProps>;
6
- Panel: React.FC<TabsPanelItemProps>;
7
- Item: React.FC<TabsControlItemProps>;
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 { useEffect, useRef, useState } from "react";
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 = ({ id = "",
13
+ const TabsRoot = ({ fluid = false,
5
14
  // Root
6
- base = "w-full", spaceY = "space-y-4", classes = "",
15
+ base = 'w-full', classes = '',
16
+ // Events
17
+ onValueChange = noop,
7
18
  // Children
8
- children, }) => {
9
- return (_jsx("div", { id: id, className: `${base} ${spaceY} ${classes}`, "data-testid": "tabs", children: children }));
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 = "flex", justify = "justify-start", gap = "gap-2", border = "border-b border-surface-200-800", classes = "",
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
- return (_jsx("div", { className: `${base} ${gap} ${justify} ${border} ${classes}`, role: "tablist", children: children }));
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 = ({ id = "", name, group, title = "",
19
- // A11y
20
- label = "", controls = "",
38
+ const TabsControl = ({
21
39
  // Root
22
- base = "group", width = "", active = "text-surface-950-50 border-surface-950-50", inactive = "text-surface-600-400 border-transparent", flex = "flex justify-center items-center", background = "", border = "border-b", text = "type-scale-3", padding = "pb-2", rounded = "", gap = "gap-1", cursor = "cursor-pointer", classes = "",
23
- // Events
24
- onClick = () => { }, onKeydown = () => { }, onKeyup = () => { }, onChange = () => { },
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
- const [selected, setSelected] = useState(group === name);
28
- useEffect(() => {
29
- setSelected(group === name);
30
- }, [group, name]);
31
- const [rxActive, setRxActive] = useState(selected ? active : inactive);
32
- useEffect(() => {
33
- setRxActive(selected ? active : inactive);
34
- }, [selected, active, inactive]);
35
- function handleOnChange(event) {
36
- onChange(event.target.value);
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 TabsControlItem = ({
60
+ const TabsContent = ({
100
61
  // Root
101
- base = "w-full", flex = "flex justify-center items-center", gap = "gap-2", background = "group-hover:preset-tonal-primary", padding = "p-2 px-4", rounded = "rounded-container", classes = "",
62
+ base = '', classes = '',
102
63
  // Children
103
- children, }) => {
104
- return (_jsx("div", { className: `${base} ${flex} ${gap} ${background} ${padding} ${rounded} ${classes}`, children: children }));
64
+ children }) => {
65
+ return (_jsx("div", { className: `${base} ${classes}`, "data-testid": "tabs-content", children: children }));
105
66
  };
106
- const TabsPanelItem = ({ id = "", value, group,
107
- // A11y
108
- labelledBy,
67
+ const TabsPanel = ({
109
68
  // Root
110
- classes = "",
69
+ base = '', classes = '',
111
70
  // Children
112
- children, }) => {
113
- return (value === group &&
114
- children && (_jsx("div", { id: id, role: "tabpanel", tabIndex: 0, "aria-labelledby": labelledBy, className: classes, children: children })));
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
- Panel: TabsPanelItem,
120
- Item: TabsControlItem,
83
+ /** A group of tab panels. */
84
+ Content: TabsContent,
85
+ /** An individual tab panel. */
86
+ Panel: TabsPanel
121
87
  });