@skeletonlabs/skeleton-react 1.0.0-next.3 → 1.0.0-next.5

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 (34) hide show
  1. package/dist/components/Accordion/Accordion.d.ts +9 -8
  2. package/dist/components/Accordion/Accordion.js +38 -59
  3. package/dist/components/Accordion/types.d.ts +23 -24
  4. package/dist/components/AppBar/AppBar.js +5 -5
  5. package/dist/components/Avatar/Avatar.js +17 -3
  6. package/dist/components/Avatar/types.d.ts +10 -5
  7. package/dist/components/Navigation/Navigation.js +2 -2
  8. package/dist/components/Navigation/types.d.ts +0 -1
  9. package/dist/components/Progress/Progress.d.ts +2 -2
  10. package/dist/components/Progress/Progress.js +21 -14
  11. package/dist/components/Progress/types.d.ts +20 -8
  12. package/dist/components/ProgressRing/ProgressRing.d.ts +2 -2
  13. package/dist/components/ProgressRing/ProgressRing.js +18 -24
  14. package/dist/components/ProgressRing/types.d.ts +8 -12
  15. package/dist/components/Rating/Rating.d.ts +3 -3
  16. package/dist/components/Rating/Rating.js +50 -79
  17. package/dist/components/Rating/types.d.ts +35 -54
  18. package/dist/components/Segment/Segment.d.ts +4 -4
  19. package/dist/components/Segment/Segment.js +41 -39
  20. package/dist/components/Segment/types.d.ts +28 -25
  21. package/dist/components/Switch/Switch.js +31 -22
  22. package/dist/components/Switch/types.d.ts +27 -24
  23. package/dist/components/Tabs/Tabs.d.ts +12 -7
  24. package/dist/components/Tabs/Tabs.js +61 -102
  25. package/dist/components/Tabs/types.d.ts +48 -85
  26. package/dist/index.d.ts +0 -1
  27. package/dist/index.js +0 -1
  28. package/dist/internal/nodes.d.ts +3 -0
  29. package/dist/internal/nodes.js +4 -0
  30. package/dist/internal/noop.d.ts +1 -0
  31. package/dist/internal/noop.js +2 -0
  32. package/package.json +24 -19
  33. package/dist/components/Test/Test.d.ts +0 -2
  34. package/dist/components/Test/Test.js +0 -10
@@ -1,9 +1,10 @@
1
- import React from 'react';
2
- import { AccordionContextState, AccordionControlProps, AccordionItemContextState, AccordionItemProps, AccordionPanelProps, AccordionProps } from './types.js';
3
- export declare const AccordionContext: React.Context<AccordionContextState>;
4
- export declare const AccordionItemContext: React.Context<AccordionItemContextState>;
5
- export declare const Accordion: React.FC<AccordionProps> & {
6
- Item: React.FC<AccordionItemProps>;
7
- Control: React.FC<AccordionControlProps>;
8
- Panel: React.FC<AccordionPanelProps>;
1
+ import type { FC } from 'react';
2
+ import * as accordion from '@zag-js/accordion';
3
+ import type { AccordionContextState, AccordionControlProps, AccordionItemProps, AccordionPanelProps, AccordionProps } from './types.js';
4
+ export declare const AccordionContext: import("react").Context<AccordionContextState>;
5
+ export declare const AccordionItemContext: import("react").Context<accordion.ItemProps>;
6
+ export declare const Accordion: FC<AccordionProps> & {
7
+ Item: FC<AccordionItemProps>;
8
+ Control: FC<AccordionControlProps>;
9
+ Panel: FC<AccordionPanelProps>;
9
10
  };
@@ -1,95 +1,74 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { motion, AnimatePresence } from 'framer-motion';
4
- import { createContext, useContext, useEffect, useState } from 'react';
3
+ import { createContext, useContext, useId } from 'react';
4
+ import * as accordion from '@zag-js/accordion';
5
+ import { useMachine, normalizeProps } from '@zag-js/react';
6
+ import { noop } from '../../internal/noop.js';
5
7
  // Contexts ---
6
8
  export const AccordionContext = createContext({
7
9
  animDuration: 0.2,
8
10
  iconOpen: '-',
9
11
  iconClosed: '+',
10
- open: () => { },
11
- close: () => { },
12
- toggle: () => { },
13
- isOpen: () => false
12
+ api: {}
14
13
  });
15
14
  export const AccordionItemContext = createContext({
16
- id: '',
17
- onClick: () => { }
15
+ value: '',
16
+ disabled: false
18
17
  });
19
18
  // Components ---
20
- const AccordionRoot = ({ multiple = false, value: valueInit = [], animDuration = 0.2,
19
+ const AccordionRoot = ({ animDuration = 0.2,
21
20
  // Root
22
21
  base = '', padding = '', spaceY = 'space-y-2', rounded = 'rounded', width = 'w-full', classes = '',
23
22
  // Icons
24
23
  iconOpen = '-', iconClosed = '+',
25
24
  // Events
26
- onValueChange = () => { },
25
+ onValueChange = noop,
27
26
  // Children
28
- children }) => {
29
- // State
30
- const [value, setValue] = useState(multiple ? valueInit : [valueInit[0]]);
31
- // Functions
32
- function open(id) {
33
- setValue((opened) => (multiple ? [...opened, id] : [id]));
34
- }
35
- function close(id) {
36
- setValue((opened) => opened.filter((_id) => _id !== id));
37
- }
38
- function toggle(id) {
39
- isOpen(id) ? close(id) : open(id);
40
- }
41
- function isOpen(id) {
42
- return value.includes(id);
43
- }
44
- // Effect
45
- useEffect(() => {
46
- onValueChange(value);
47
- }, [onValueChange, value]);
48
- // Context
49
- const ctx = {
50
- animDuration,
51
- iconOpen,
52
- iconClosed,
53
- open,
54
- close,
55
- toggle,
56
- isOpen
57
- };
58
- return (_jsx("div", { className: `${base} ${padding} ${spaceY} ${rounded} ${width} ${classes}`, "data-testid": "accordion", children: _jsx(AccordionContext.Provider, { value: ctx, children: children }) }));
27
+ children,
28
+ // Zag
29
+ ...zagProps }) => {
30
+ // Zag
31
+ const [state, send] = useMachine(accordion.machine({
32
+ id: useId(),
33
+ onValueChange: (details) => {
34
+ onValueChange(details.value);
35
+ }
36
+ }), { context: zagProps });
37
+ const api = accordion.connect(state, send, normalizeProps);
38
+ return (_jsx("div", { className: `${base} ${padding} ${spaceY} ${rounded} ${width} ${classes}`, ...api.getRootProps(), "data-testid": "accordion", children: _jsx(AccordionContext.Provider, { value: { animDuration, iconOpen, iconClosed, api }, children: children }) }));
59
39
  };
60
- const AccordionItem = ({ id, base = '', spaceY = '', classes = '',
61
- // Events
62
- onClick = () => { },
40
+ const AccordionItem = ({ base = '', spaceY = '', classes = '',
63
41
  // Children
64
- children }) => {
65
- return (_jsx(AccordionItemContext.Provider, { value: { id, onClick }, children: _jsx("div", { className: `${base} ${spaceY} ${classes}`, "data-testid": "accordion-item", children: children }) }));
42
+ children, ...zagProps }) => {
43
+ const ctx = useContext(AccordionContext);
44
+ return (_jsx(AccordionItemContext.Provider, { value: zagProps, children: _jsx("div", { className: `${base} ${spaceY} ${classes}`, ...ctx?.api.getItemProps(zagProps), "data-testid": "accordion-item", children: children }) }));
66
45
  };
67
- const AccordionControl = ({ disabled = false,
46
+ const AccordionControl = ({ headingElement = 'h3',
68
47
  // Control
69
- base = 'flex text-start items-center space-x-4 w-full', hover = 'hover:preset-tonal-primary', padding = 'py-2 px-4', rounded = 'rounded', classes = '', iconsBase = '',
48
+ base = 'flex text-start items-center space-x-4 w-full', hover = 'hover:preset-tonal-primary', padding = 'py-2 px-4', rounded = 'rounded', classes = '',
49
+ // Lead
50
+ leadBase = '', leadClasses = '',
51
+ // Content
52
+ contentBase = 'flex-1', contentClasses = '',
53
+ // Indicator
54
+ indicatorBase = '', indicatorClasses = '',
70
55
  // Icons
71
56
  lead,
72
57
  // Children
73
58
  children }) => {
74
- const rootCtx = useContext(AccordionContext);
59
+ const ctx = useContext(AccordionContext);
75
60
  const itemCtx = useContext(AccordionItemContext);
76
- function clickHandler(event) {
77
- rootCtx.toggle(itemCtx.id);
78
- itemCtx.onClick(event);
79
- }
80
- return (_jsxs("button", { type: "button", className: `${base} ${hover} ${padding} ${rounded} ${classes}`, "aria-expanded": rootCtx.isOpen(itemCtx.id), "aria-controls": `accordion-panel-${itemCtx.id}`, onClick: clickHandler, disabled: disabled, "data-testid": "accordion-control", children: [lead && _jsx("div", { children: lead }), _jsx("div", { className: "flex-1", children: children }), _jsx("div", { className: `${iconsBase}`, children: rootCtx.isOpen(itemCtx.id) ? rootCtx.iconOpen : rootCtx.iconClosed })] }));
61
+ const HeadingElement = headingElement;
62
+ return (_jsx(HeadingElement, { children: _jsxs("button", { className: `${base} ${hover} ${padding} ${rounded} ${classes}`, ...ctx.api.getItemTriggerProps(itemCtx), "data-testid": "accordion-control", children: [lead && (_jsx("div", { className: `${leadBase} ${leadClasses}`, "data-testid": "accordion-lead", children: lead })), _jsx("div", { className: `${contentBase} ${contentClasses}`, "data-testid": "accordion-content", children: children }), _jsx("div", { className: `${indicatorBase} ${indicatorClasses}`, "data-testid": "accordion-indicator", children: ctx.api.value.includes(itemCtx.value) ? ctx.iconOpen : ctx.iconClosed })] }) }));
81
63
  };
82
64
  const AccordionPanel = ({
83
65
  // Panel
84
66
  base = '', padding = 'py-2 px-4', rounded = '', classes = '',
85
67
  // Children
86
68
  children }) => {
87
- const rootCtx = useContext(AccordionContext);
69
+ const ctx = useContext(AccordionContext);
88
70
  const itemCtx = useContext(AccordionItemContext);
89
- return (_jsx("div", { role: "region", "aria-hidden": rootCtx.isOpen(itemCtx.id), "aria-labelledby": itemCtx.id, "data-testid": "accordion-panel", children: _jsx(AnimatePresence, { initial: false, children: rootCtx.isOpen(itemCtx.id) && (_jsx(motion.div, { className: "overflow-hidden", initial: "collapsed", animate: "open", exit: "collapsed", variants: {
90
- open: { opacity: 1, height: 'auto' },
91
- collapsed: { opacity: 0, height: 0 }
92
- }, transition: { duration: rootCtx.animDuration && 0.2 }, children: _jsx("div", { className: `${base} ${padding} ${rounded} ${classes}`, "data-testid": "accordion-panel-children", children: children }) })) }) }));
71
+ return (ctx.api.value.includes(itemCtx.value) && (_jsx("div", { ...ctx.api.getItemContentProps(itemCtx), className: `${base} ${padding} ${rounded} ${classes}`, "data-testid": "accordion-panel", children: children })));
93
72
  };
94
73
  export const Accordion = Object.assign(AccordionRoot, {
95
74
  Item: AccordionItem,
@@ -1,33 +1,24 @@
1
1
  import React, { type ReactNode } from 'react';
2
+ import * as accordion from '@zag-js/accordion';
2
3
  export interface AccordionContextState {
3
- animDuration?: number;
4
- iconOpen?: ReactNode;
5
- iconClosed?: ReactNode;
6
- open: (id: string) => void;
7
- close: (id: string) => void;
8
- toggle: (id: string) => void;
9
- isOpen: (id: string) => boolean;
4
+ animDuration: number;
5
+ iconOpen: ReactNode;
6
+ iconClosed: ReactNode;
7
+ api: ReturnType<typeof accordion.connect>;
10
8
  }
11
9
  export interface AccordionItemContextState {
12
10
  id: string;
13
11
  onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
14
12
  }
15
- export interface AccordionProps extends React.PropsWithChildren {
16
- /**
17
- * Enables opening multiple items at once.
18
- * @default false
19
- */
20
- multiple?: boolean;
21
- /** Takes an array list of open items. */
22
- value?: string[];
23
- /** The slide animation duration in milliseconds. */
13
+ export interface AccordionProps extends React.PropsWithChildren, Omit<accordion.Context, 'id' | 'orientation' | 'onValueChange'> {
14
+ /** The slide animation duration as a float value (ex: 0.2). */
24
15
  animDuration?: number;
25
16
  /** Set the open state icon. */
26
17
  iconOpen?: ReactNode;
27
18
  /** Set the closed state icon. */
28
19
  iconClosed?: ReactNode;
29
20
  /** Set the opened state. */
30
- onValueChange?: (opened: string[]) => void;
21
+ onValueChange?: (value: string[]) => void;
31
22
  /** Sets base styles. */
32
23
  base?: string;
33
24
  /** Set padding styles. */
@@ -41,19 +32,17 @@ export interface AccordionProps extends React.PropsWithChildren {
41
32
  /** Provide arbitrary CSS classes. */
42
33
  classes?: string;
43
34
  }
44
- export interface AccordionItemProps extends React.PropsWithChildren {
45
- /** The unique ID. */
46
- id: string;
35
+ export interface AccordionItemProps extends React.PropsWithChildren, accordion.ItemProps {
47
36
  /** Sets base styles. */
48
37
  base?: string;
49
38
  /** Set vertical spacing styles. */
50
39
  spaceY?: string;
51
40
  /** Provide arbitrary CSS classes. */
52
41
  classes?: string;
53
- /** Triggers on item click. */
54
- onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
55
42
  }
56
43
  export interface AccordionControlProps extends React.PropsWithChildren {
44
+ /** The heading element. */
45
+ headingElement?: keyof JSX.IntrinsicElements;
57
46
  /** Set a disabled state for the item. */
58
47
  disabled?: boolean;
59
48
  /** Sets control's base styles. */
@@ -66,8 +55,18 @@ export interface AccordionControlProps extends React.PropsWithChildren {
66
55
  rounded?: string;
67
56
  /** Provide arbitrary CSS classes to the control. */
68
57
  classes?: string;
69
- /** Set the base styles for the state icons. */
70
- iconsBase?: string;
58
+ /** Sets the lead's base styles */
59
+ leadBase?: string;
60
+ /** Provide arbitrary CSS classes to the lead. */
61
+ leadClasses?: string;
62
+ /** Sets the lead's base styles */
63
+ contentBase?: string;
64
+ /** Provide arbitrary CSS classes to the content. */
65
+ contentClasses?: string;
66
+ /** Sets the lead's base styles */
67
+ indicatorBase?: string;
68
+ /** Provide arbitrary CSS classes to the indicator. */
69
+ indicatorClasses?: string;
71
70
  /** The lead child slot for the control. */
72
71
  lead?: ReactNode;
73
72
  }
@@ -12,35 +12,35 @@ const Toolbar = ({
12
12
  base = 'flex justify-between', gridCols = 'grid-cols-[auto_1fr_auto]', gap = 'gap-4', classes = '',
13
13
  // Children
14
14
  children }) => {
15
- return _jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, children: children });
15
+ return (_jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, "data-testid": "app-bar-toolbar", children: children }));
16
16
  };
17
17
  const ToolbarLead = ({
18
18
  // Lead
19
19
  base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
20
20
  // Children
21
21
  children }) => {
22
- return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
22
+ return (_jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, "data-testid": "app-bar-toolbar-lead", children: children }));
23
23
  };
24
24
  const ToolbarCenter = ({
25
25
  // Center
26
26
  base = 'grow', align = 'text-center', padding = '', classes = '',
27
27
  // Children
28
28
  children }) => {
29
- return _jsx("div", { className: `${base} ${align} ${padding} ${classes}`, children: children });
29
+ return (_jsx("div", { className: `${base} ${align} ${padding} ${classes}`, "data-testid": "app-bar-toolbar-center", children: children }));
30
30
  };
31
31
  const ToolbarTrail = ({
32
32
  // Trail
33
33
  base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
34
34
  // Children
35
35
  children }) => {
36
- return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
36
+ return (_jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, "data-testid": "app-bar-toolbar-trail", children: children }));
37
37
  };
38
38
  const AppBarHeadline = ({
39
39
  // Headline
40
40
  base = 'w-full', classes = '',
41
41
  // Children
42
42
  children }) => {
43
- return _jsx("div", { className: `${base} ${classes}`, children: children });
43
+ return (_jsx("div", { className: `${base} ${classes}`, "data-testid": "app-bar-headline", children: children }));
44
44
  };
45
45
  export const AppBar = Object.assign(AppBarRoot, {
46
46
  Toolbar: Toolbar,
@@ -1,11 +1,25 @@
1
1
  'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- export const Avatar = ({ src = '', alt = '', filter = '',
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import * as avatar from '@zag-js/avatar';
5
+ import { useMachine, normalizeProps } from '@zag-js/react';
6
+ export const Avatar = ({ src, srcSet, name, filter,
4
7
  // Root
5
8
  base = 'overflow-hidden isolate', background = 'bg-surface-400-600', size = 'size-16', font = '', border = '', rounded = 'rounded-full', shadow = '', classes = '',
6
9
  // Image
7
10
  imageBase = 'w-full object-cover', imageClasses = '',
11
+ // Fallback
12
+ fallbackBase = 'w-full h-full flex justify-center items-center', fallbackClasses = '',
8
13
  // Children
9
14
  children }) => {
10
- return (_jsx("figure", { className: `${base} ${background} ${size} ${font} ${border} ${rounded} ${shadow} ${classes}`, "data-testid": "avatar", children: src ? (_jsx("img", { className: `${imageBase} ${imageClasses}`, src: src, alt: alt, style: { filter: filter ? `url(${filter})` : undefined } })) : (children) }));
15
+ // Zag
16
+ const [state, send] = useMachine(avatar.machine({ id: useId() }));
17
+ const api = avatar.connect(state, send, normalizeProps);
18
+ function getInitials(name) {
19
+ return name
20
+ .split(' ')
21
+ .map((word) => word[0])
22
+ .join('');
23
+ }
24
+ return (_jsxs("figure", { ...api.getRootProps(), className: `${base} ${background} ${size} ${font} ${border} ${rounded} ${shadow} ${classes}`, "data-testid": "avatar", children: [(src || srcSet) && (_jsx("img", { ...api.getImageProps(), src: src, srcSet: srcSet, alt: name, className: `${imageBase} ${imageClasses}`, style: { filter: filter ? `url(${filter})` : undefined }, "data-testid": "avatar-image" })), _jsx("span", { ...api.getFallbackProps(), className: `${fallbackBase} ${fallbackClasses}`, "data-testid": "avatar-fallback", children: children ? children : getInitials(name) })] }));
11
25
  };
@@ -1,10 +1,11 @@
1
- /// <reference types="react" />
2
1
  export interface AvatarProps extends React.PropsWithChildren {
3
- /** Set avatar image source URL. */
2
+ /** The source of the avatar image. */
4
3
  src?: string;
5
- /** Set avatar image Alt text. */
6
- alt?: string;
7
- /** Set avatar image filter name. such as "#Apollo". */
4
+ /** The source set of the avatar image. */
5
+ srcSet?: string;
6
+ /** Provide a name or username for the avatar. */
7
+ name: string;
8
+ /** Set avatar image filter name, such as: "#Apollo". */
8
9
  filter?: string;
9
10
  /** Set base styles. */
10
11
  base?: string;
@@ -26,4 +27,8 @@ export interface AvatarProps extends React.PropsWithChildren {
26
27
  imageBase?: string;
27
28
  /** Provide avatar image arbitrary CSS classes. */
28
29
  imageClasses?: string;
30
+ /** Set base classes for the fallback element. */
31
+ fallbackBase?: string;
32
+ /** Provide arbitrary CSS classes to fallback element. */
33
+ fallbackClasses?: string;
29
34
  }
@@ -36,7 +36,7 @@ header, children, footer }) => {
36
36
  };
37
37
  // Reactive
38
38
  const rxWidth = expanded ? widthExpanded : width;
39
- return (_jsx("aside", { className: `${base} ${background} ${height} ${padding} ${rxWidth} ${classes}`, "data-testid": "nav-rail", children: _jsxs(NavContext.Provider, { value: ctx, children: [header ? (_jsx("header", { className: `${headerBase} ${headerFlexDirection} ${headerJustify} ${headerItems} ${headerGap} ${headerClasses}`, children: header })) : null, children ? (_jsx("nav", { className: `${tilesBase} ${tilesFlexDirection} ${tilesJustify} ${tilesItems} ${tilesGap} ${tilesClasses}`, children: children })) : null, footer ? (_jsx("footer", { className: `${footerBase} ${footerFlexDirection} ${footerJustify} ${footerItems} ${footerGap} ${footerClasses}`, children: footer })) : null] }) }));
39
+ return (_jsx("aside", { className: `${base} ${background} ${height} ${padding} ${rxWidth} ${classes}`, "data-testid": "nav-rail", children: _jsxs(NavContext.Provider, { value: ctx, children: [header ? (_jsx("header", { className: `${headerBase} ${headerFlexDirection} ${headerJustify} ${headerItems} ${headerGap} ${headerClasses}`, "data-testid": "nav-rail-header", children: header })) : null, children ? (_jsx("nav", { className: `${tilesBase} ${tilesFlexDirection} ${tilesJustify} ${tilesItems} ${tilesGap} ${tilesClasses}`, "data-testid": "nav-rail-tiles", children: children })) : null, footer ? (_jsx("footer", { className: `${footerBase} ${footerFlexDirection} ${footerJustify} ${footerItems} ${footerGap} ${footerClasses}`, "data-testid": "nav-rail-footer", children: footer })) : null] }) }));
40
40
  };
41
41
  export const NavBar = ({ value = '',
42
42
  // Root
@@ -94,7 +94,7 @@ children }) => {
94
94
  if (ctx.onSelectionHandler && id)
95
95
  ctx.onSelectionHandler(id);
96
96
  }
97
- return (_jsxs(TileElement, { className: `${base} ${width} ${rounded} ${rxBackground} ${rxMode}`, href: href, target: target, type: type, title: title, role: role, onClick: onClickHandler, "data-parent": ctx.parent, "data-expanded": ctx.expanded, "data-testid": "nav-tile", children: [children ? _jsx("div", { children: children }) : null, label && !ctx.expanded ? _jsx("div", { className: `${labelBase} ${labelClasses}`, children: label }) : null, labelExpanded && ctx.expanded ? _jsx("div", { className: `${labelExpandedBase} ${labelExpandedClasses}`, children: labelExpanded }) : null] }));
97
+ return (_jsxs(TileElement, { className: `${base} ${width} ${rounded} ${rxBackground} ${rxMode}`, href: href, target: target, type: type, title: title, role: role, onClick: onClickHandler, "data-parent": ctx.parent, "data-expanded": ctx.expanded, "data-testid": "nav-tile", children: [children && _jsx("div", { children: children }), label && !ctx.expanded && (_jsx("div", { className: `${labelBase} ${labelClasses}`, "data-testid": "nav-tile-label", children: label })), labelExpanded && ctx.expanded && (_jsx("div", { className: `${labelExpandedBase} ${labelExpandedClasses}`, "data-testid": "nav-tile-label-expanded", children: labelExpanded }))] }));
98
98
  };
99
99
  // Exports ---
100
100
  export const Nav = Object.assign(() => null, {
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export interface NavContextState {
3
2
  parent: string;
4
3
  value: string;
@@ -1,3 +1,3 @@
1
- import { type FC } from 'react';
2
- import { ProgressProps } from './types.js';
1
+ import type { FC } from 'react';
2
+ import type { ProgressProps } from './types.js';
3
3
  export declare const Progress: FC<ProgressProps>;
@@ -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,36 +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)
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
6
7
  base = 'relative', size = 'size-32', classes = '',
7
8
  // Slot
8
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
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
+ labelBase = '', labelFill = 'fill-surface-950-50', labelFontSize = 24, // px
17
18
  labelFontWeight = 'bold', labelClasses = '',
18
19
  // Children
19
- children }) => {
20
- // Local
21
- const baseSize = 512; // px
22
- const radius = baseSize / 2 - strokeWidth / 2;
23
- const [circumference, setCircumference] = useState(radius);
24
- const [dashoffset, setDashoffset] = useState(0);
25
- useEffect(() => {
26
- // Since calcDashOffset is only used in this effect, it's implementation should be inside the effect to avoid a rerender loop
27
- const calcDashOffset = () => {
28
- const v = value !== undefined ? value : 25;
29
- const percent = (100 * v) / max;
30
- setCircumference(radius * 2 * Math.PI);
31
- return circumference - (percent / 100) * circumference;
32
- };
33
- setDashoffset(calcDashOffset());
34
- }, [circumference, max, radius, setCircumference, value]);
35
- 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}%` }))] })] }));
36
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
8
  strokeLinecap?: 'inherit' | 'butt' | 'round' | 'square';
11
- /** Set the aria-labelledby value */
12
- labelledby?: string;
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>;