@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,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,98 +1,77 @@
1
- "use client";
1
+ 'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { createContext, useContext, useEffect, useState } from "react";
4
- import { motion, AnimatePresence } from "framer-motion";
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
- iconOpen: "-",
9
- iconClosed: "+",
10
- open: () => { },
11
- close: () => { },
12
- toggle: () => { },
13
- isOpen: () => false,
10
+ iconOpen: '-',
11
+ iconClosed: '+',
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
- base = "", padding = "", spaceY = "space-y-2", rounded = "rounded", width = "w-full", classes = "",
21
+ base = '', padding = '', spaceY = 'space-y-2', rounded = 'rounded', width = 'w-full', classes = '',
23
22
  // Icons
24
- iconOpen = "-", iconClosed = "+",
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
- children, }) => {
74
- const rootCtx = useContext(AccordionContext);
58
+ children }) => {
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
- base = "", padding = "py-2 px-4", rounded = "", classes = "",
66
+ base = '', padding = 'py-2 px-4', rounded = '', classes = '',
85
67
  // Children
86
- children, }) => {
87
- const rootCtx = useContext(AccordionContext);
68
+ children }) => {
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,
96
75
  Control: AccordionControl,
97
- Panel: AccordionPanel,
76
+ Panel: AccordionPanel
98
77
  });
@@ -1,33 +1,24 @@
1
- import React, { type ReactNode } from "react";
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
  }
@@ -1,5 +1,5 @@
1
- import React from "react";
2
- import { ToolbarCenterProps, AppBarHeadlineProps, ToolbarLeadProps, AppBarProps, ToolBarProps, ToolbarTrailProps } from "./types.js";
1
+ import React from 'react';
2
+ import { ToolbarCenterProps, AppBarHeadlineProps, ToolbarLeadProps, AppBarProps, ToolBarProps, ToolbarTrailProps } from './types.js';
3
3
  export declare const AppBar: React.FC<AppBarProps> & {
4
4
  Toolbar: React.FC<ToolBarProps>;
5
5
  ToolbarLead: React.FC<ToolbarLeadProps>;
@@ -1,53 +1,51 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- // React Compose ---
3
- import { reactCompose } from "../../utils/react-compose.js";
4
2
  // Components ---
5
3
  const AppBarRoot = ({
6
4
  // Root
7
- base = "w-full flex flex-col", background = "bg-surface-100-900", spaceY = "space-y-4", border = "", padding = "p-4", shadow = "", classes = "",
5
+ base = 'w-full flex flex-col', background = 'bg-surface-100-900', spaceY = 'space-y-4', border = '', padding = 'p-4', shadow = '', classes = '',
8
6
  // Children
9
- children, }) => {
7
+ children }) => {
10
8
  return (_jsx("div", { className: `${base} ${background} ${spaceY} ${border} ${padding} ${shadow} ${classes}`, role: "toolbar", "data-testid": "app-bar", children: children }));
11
9
  };
12
10
  const Toolbar = ({
13
11
  // Toolbar
14
- base = "flex justify-between", gridCols = "grid-cols-[auto_1fr_auto]", gap = "gap-4", classes = "",
12
+ base = 'flex justify-between', gridCols = 'grid-cols-[auto_1fr_auto]', gap = 'gap-4', classes = '',
15
13
  // Children
16
- children, }) => {
17
- return (_jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, children: children }));
14
+ children }) => {
15
+ return _jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, children: children });
18
16
  };
19
17
  const ToolbarLead = ({
20
18
  // Lead
21
- base = "flex", spaceX = "space-x-4 rtl:space-x-reverse", padding = "", classes = "",
19
+ base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
22
20
  // Children
23
- children, }) => {
24
- return (_jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children }));
21
+ children }) => {
22
+ return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
25
23
  };
26
24
  const ToolbarCenter = ({
27
25
  // Center
28
- base = "grow", align = "text-center", padding = "", classes = "",
26
+ base = 'grow', align = 'text-center', padding = '', classes = '',
29
27
  // Children
30
- children, }) => {
31
- return (_jsx("div", { className: `${base} ${align} ${padding} ${classes}`, children: children }));
28
+ children }) => {
29
+ return _jsx("div", { className: `${base} ${align} ${padding} ${classes}`, children: children });
32
30
  };
33
31
  const ToolbarTrail = ({
34
32
  // Trail
35
- base = "flex", spaceX = "space-x-4 rtl:space-x-reverse", padding = "", classes = "",
33
+ base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
36
34
  // Children
37
- children, }) => {
38
- return (_jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children }));
35
+ children }) => {
36
+ return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
39
37
  };
40
38
  const AppBarHeadline = ({
41
39
  // Headline
42
- base = "w-full", classes = "",
40
+ base = 'w-full', classes = '',
43
41
  // Children
44
- children, }) => {
42
+ children }) => {
45
43
  return _jsx("div", { className: `${base} ${classes}`, children: children });
46
44
  };
47
- export const AppBar = reactCompose(AppBarRoot, {
45
+ export const AppBar = Object.assign(AppBarRoot, {
48
46
  Toolbar: Toolbar,
49
47
  ToolbarLead: ToolbarLead,
50
48
  ToolbarCenter: ToolbarCenter,
51
49
  ToolbarTrail: ToolbarTrail,
52
- Headline: AppBarHeadline,
50
+ Headline: AppBarHeadline
53
51
  });
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  export interface AppBarProps extends React.PropsWithChildren {
3
3
  /** Set base styles. */
4
4
  base?: string;
@@ -1,3 +1,3 @@
1
- import React from "react";
2
- import { AvatarProps } from "./types.js";
1
+ import React from 'react';
2
+ import { AvatarProps } from './types.js';
3
3
  export declare const Avatar: React.FC<AvatarProps>;
@@ -1,11 +1,25 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- export const Avatar = ({ src = "", alt = "", filter = "",
1
+ 'use client';
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
- base = "overflow-hidden isolate", background = "bg-surface-400-600", size = "size-16", font = "", border = "", rounded = "rounded-full", shadow = "", classes = "",
8
+ base = 'overflow-hidden isolate', background = 'bg-surface-400-600', size = 'size-16', font = '', border = '', rounded = 'rounded-full', shadow = '', classes = '',
6
9
  // Image
7
- imageBase = "w-full object-cover", imageClasses = "",
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
- 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) }));
14
+ 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
  }
@@ -1,5 +1,5 @@
1
- import React from "react";
2
- import { NavContextState, NavRailProps, NavBarProps, NavTileProps } from "./types.js";
1
+ import React from 'react';
2
+ import { NavContextState, NavRailProps, NavBarProps, NavTileProps } from './types.js';
3
3
  export declare const NavContext: React.Context<NavContextState>;
4
4
  export declare const NavRail: React.FC<NavRailProps>;
5
5
  export declare const NavBar: React.FC<NavBarProps>;
@@ -1,81 +1,104 @@
1
- "use client";
1
+ 'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { createContext, useContext } from "react";
3
+ import { createContext, useContext } from 'react';
4
4
  // Contexts ---
5
5
  export const NavContext = createContext({
6
- parent: "",
6
+ parent: 'none',
7
+ value: '',
7
8
  expanded: false,
9
+ onSelectionHandler: () => { }
8
10
  });
9
11
  // Components ---
10
- export const NavRail = ({ expanded = false,
12
+ export const NavRail = ({ value = '', expanded = false,
11
13
  // Root
12
- base = "h-full flex flex-col", background = "preset-filled-surface-100-900", padding = "p-1", width = "w-24", widthExpanded = "w-64", height = "h-full", classes = "",
14
+ base = 'h-full flex flex-col', background = 'preset-filled-surface-100-900', padding = 'p-1', width = 'w-24', widthExpanded = 'w-64', height = 'h-full', classes = '',
13
15
  // Header
14
- headerBase = "flex", headerFlexDirection = "flex-col", headerJustify = "justify-center", headerItems = "items-center", headerGap = "gap-1", headerClasses = "",
16
+ headerBase = 'flex', headerFlexDirection = 'flex-col', headerJustify = 'justify-center', headerItems = 'items-center', headerGap = 'gap-1', headerClasses = '',
15
17
  // Tiles
16
- tilesBase = "flex-1 flex", tilesFlexDirection = "flex-col", tilesJustify = "justify-center", tilesItems = "items-center", tilesGap = "gap-1", tilesClasses = "",
18
+ tilesBase = 'flex-1 flex', tilesFlexDirection = 'flex-col', tilesJustify = 'justify-center', tilesItems = 'items-center', tilesGap = 'gap-1', tilesClasses = '',
17
19
  // Footer
18
- footerBase = "flex", footerFlexDirection = "flex-col", footerJustify = "justify-center", footerItems = "items-center", footerGap = "gap-1", footerClasses = "",
20
+ footerBase = 'flex', footerFlexDirection = 'flex-col', footerJustify = 'justify-center', footerItems = 'items-center', footerGap = 'gap-1', footerClasses = '',
21
+ // Events
22
+ onChange,
19
23
  // Snippets
20
- header, children, footer, }) => {
24
+ header, children, footer }) => {
25
+ function onSelectionHandler(id) {
26
+ value = id;
27
+ if (onChange)
28
+ onChange(id);
29
+ }
21
30
  // Set Context
22
31
  const ctx = {
23
- parent: "rail",
32
+ parent: 'rail',
33
+ value,
24
34
  expanded,
35
+ onSelectionHandler
25
36
  };
26
37
  // Reactive
27
- let rxWidth = expanded ? widthExpanded : width;
38
+ const rxWidth = expanded ? widthExpanded : width;
28
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] }) }));
29
40
  };
30
- export const NavBar = ({
41
+ export const NavBar = ({ value = '',
31
42
  // Root
32
- base = "h-full flex flex-col", background = "preset-filled-surface-100-900", width = "min-w-[320px] w-full", height = "h-20", padding = "p-1", classes = "",
43
+ base = 'h-full flex flex-col', background = 'preset-filled-surface-100-900', width = 'min-w-[320px] w-full', height = 'h-20', padding = 'p-1', classes = '',
33
44
  // Tiles
34
- tilesBase = "flex-1 flex", tilesFlexDirection = "", tilesJustify = "justify-center", tilesItems = "items-center", tilesGap = "gap-1", tilesClasses = "",
45
+ tilesBase = 'flex-1 flex', tilesFlexDirection = '', tilesJustify = 'justify-center', tilesItems = 'items-center', tilesGap = 'gap-1', tilesClasses = '',
46
+ // Events
47
+ onChange,
35
48
  // Snippets
36
- children, }) => {
49
+ children }) => {
50
+ function onSelectionHandler(id) {
51
+ value = id;
52
+ if (onChange)
53
+ onChange(id);
54
+ }
37
55
  // Set Context
38
56
  const ctx = {
39
- parent: "bar",
57
+ parent: 'bar',
58
+ value,
59
+ expanded: false,
60
+ onSelectionHandler
40
61
  };
41
62
  return (_jsx("aside", { className: `${base} ${background} ${width} ${height} ${padding} ${classes}`, "data-testid": "nav-bar", children: _jsx(NavContext.Provider, { value: ctx, children: children ? (_jsx("nav", { className: `${tilesBase} ${tilesFlexDirection} ${tilesJustify} ${tilesItems} ${tilesGap} ${tilesClasses}`, children: children })) : null }) }));
42
63
  };
43
64
  export const NavTile = ({ id, href, target, label, labelExpanded, title, selected = false,
44
65
  // Root
45
- base = "flex items-center", width = "w-full", aspect = "aspect-square", background = "", hover = "hover:preset-filled-surface-50-950", active = "preset-filled-primary-500", padding = "p-2", gap = "gap-1", rounded = "rounded-container", classes = "flex-col justify-center",
66
+ base = 'flex items-center', width = 'w-full', aspect = 'aspect-square', background = '', hover = 'hover:preset-filled-surface-50-950', active = 'preset-filled-primary-500', padding = 'p-2', gap = 'gap-1', rounded = 'rounded-container', classes = 'flex-col justify-center',
46
67
  // Expanded
47
- expandedPadding = "py-3 px-4", expandedGap = "gap-4", expandedClasses = "",
68
+ expandedPadding = 'py-3 px-4', expandedGap = 'gap-4', expandedClasses = '',
48
69
  // Label (base)
49
- labelBase = "type-scale-1", labelClasses = "",
70
+ labelBase = 'type-scale-1', labelClasses = '',
50
71
  // Label (expanded)
51
- labelExpandedBase = "", labelExpandedClasses = "",
72
+ labelExpandedBase = '', labelExpandedClasses = '',
52
73
  // Events
53
74
  onClick,
54
75
  // Snippets
55
- children, }) => {
76
+ children }) => {
56
77
  // Get Context
57
78
  const ctx = useContext(NavContext);
58
79
  // Local
59
- const TileElement = href ? "a" : "button";
60
- const type = href ? undefined : "button";
61
- const role = href ? undefined : "button";
80
+ const TileElement = href ? 'a' : 'button';
81
+ const type = href ? undefined : 'button';
82
+ const role = href ? undefined : 'button';
62
83
  // Reactive
63
- let rxSize = ctx.parent === "bar" ? `h-full` : `${aspect}`;
84
+ const rxSize = ctx.parent === 'bar' ? `h-full` : `${aspect}`;
64
85
  const classesCollapsed = `${rxSize} ${padding} ${gap} ${classes}`;
65
86
  const classesExtended = `${expandedPadding} ${expandedGap} ${expandedClasses}`;
66
- let rxMode = ctx.expanded ? classesExtended : classesCollapsed;
67
- let rxBackground = selected ? active : `${background} ${hover}`;
87
+ const rxMode = ctx.expanded ? classesExtended : classesCollapsed;
88
+ const rxBackground = selected || ctx.value === id ? active : `${background} ${hover}`;
68
89
  function onClickHandler() {
69
90
  if (onClick && !id)
70
- throw new Error("No ID was provided");
91
+ throw new Error('No ID was provided');
71
92
  if (onClick && id)
72
93
  onClick(id);
94
+ if (ctx.onSelectionHandler && id)
95
+ ctx.onSelectionHandler(id);
73
96
  }
74
- 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 }) : null, label && !ctx.expanded ? _jsx("div", { className: `${labelBase} ${labelClasses}`, children: label }) : null, labelExpanded && ctx.expanded ? _jsx("div", { className: `${labelExpandedBase} ${labelExpandedClasses}`, children: labelExpanded }) : null] }));
75
98
  };
76
99
  // Exports ---
77
100
  export const Nav = Object.assign(() => null, {
78
101
  Rail: NavRail,
79
102
  Bar: NavBar,
80
- Tile: NavTile,
103
+ Tile: NavTile
81
104
  });
@@ -1,9 +1,12 @@
1
- /// <reference types="react" />
2
1
  export interface NavContextState {
3
2
  parent: string;
3
+ value: string;
4
4
  expanded?: boolean;
5
+ onSelectionHandler: (id: string) => void;
5
6
  }
7
+ /** Props common between NavRail and NavBar */
6
8
  export interface NavCommonProps {
9
+ value?: string;
7
10
  /** Set base styles. */
8
11
  base?: string;
9
12
  /** Set background classes. */
@@ -30,6 +33,8 @@ export interface NavCommonProps {
30
33
  tilesGap?: string;
31
34
  /** Provide arbitrary CSS classes. */
32
35
  tilesClasses?: string;
36
+ /** Triggers when selection occurs. */
37
+ onChange?: (id: string) => void;
33
38
  }
34
39
  export interface NavBarProps extends NavCommonProps {
35
40
  /** The default children. */
@@ -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>;