@skeletonlabs/skeleton-react 1.0.0-next.2 → 1.0.0-next.4

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