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

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.
@@ -1,11 +1,9 @@
1
1
  import React from "react";
2
- import { AppBarCenterProps, AppBarHeadlineProps, AppBarLeadProps, AppBarProps, AppBarToolBarProps, AppBarTrailProps } from "./types.js";
3
- export declare const ToolBar: React.FC<AppBarToolBarProps> & {
4
- Lead: React.FC<AppBarLeadProps>;
5
- Center: React.FC<AppBarCenterProps>;
6
- Trail: React.FC<AppBarTrailProps>;
7
- };
2
+ import { ToolbarCenterProps, AppBarHeadlineProps, ToolbarLeadProps, AppBarProps, ToolBarProps, ToolbarTrailProps } from "./types.js";
8
3
  export declare const AppBar: React.FC<AppBarProps> & {
9
- Toolbar: React.FC<AppBarToolBarProps>;
4
+ Toolbar: React.FC<ToolBarProps>;
5
+ ToolbarLead: React.FC<ToolbarLeadProps>;
6
+ ToolbarCenter: React.FC<ToolbarCenterProps>;
7
+ ToolbarTrail: React.FC<ToolbarTrailProps>;
10
8
  Headline: React.FC<AppBarHeadlineProps>;
11
9
  };
@@ -1,4 +1,3 @@
1
- "use client";
2
1
  import { jsx as _jsx } from "react/jsx-runtime";
3
2
  // React Compose ---
4
3
  import { reactCompose } from "../../utils/react-compose.js";
@@ -10,28 +9,28 @@ base = "w-full flex flex-col", background = "bg-surface-100-900", spaceY = "spac
10
9
  children, }) => {
11
10
  return (_jsx("div", { className: `${base} ${background} ${spaceY} ${border} ${padding} ${shadow} ${classes}`, role: "toolbar", "data-testid": "app-bar", children: children }));
12
11
  };
13
- const AppBarToolBarRoot = ({
12
+ const Toolbar = ({
14
13
  // Toolbar
15
14
  base = "flex justify-between", gridCols = "grid-cols-[auto_1fr_auto]", gap = "gap-4", classes = "",
16
15
  // Children
17
16
  children, }) => {
18
17
  return (_jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, children: children }));
19
18
  };
20
- const AppBarLead = ({
19
+ const ToolbarLead = ({
21
20
  // Lead
22
21
  base = "flex", spaceX = "space-x-4 rtl:space-x-reverse", padding = "", classes = "",
23
22
  // Children
24
23
  children, }) => {
25
24
  return (_jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children }));
26
25
  };
27
- const AppBarCenter = ({
26
+ const ToolbarCenter = ({
28
27
  // Center
29
28
  base = "grow", align = "text-center", padding = "", classes = "",
30
29
  // Children
31
30
  children, }) => {
32
31
  return (_jsx("div", { className: `${base} ${align} ${padding} ${classes}`, children: children }));
33
32
  };
34
- const AppBarTrail = ({
33
+ const ToolbarTrail = ({
35
34
  // Trail
36
35
  base = "flex", spaceX = "space-x-4 rtl:space-x-reverse", padding = "", classes = "",
37
36
  // Children
@@ -45,12 +44,10 @@ base = "w-full", classes = "",
45
44
  children, }) => {
46
45
  return _jsx("div", { className: `${base} ${classes}`, children: children });
47
46
  };
48
- export const ToolBar = reactCompose(AppBarToolBarRoot, {
49
- Lead: AppBarLead,
50
- Center: AppBarCenter,
51
- Trail: AppBarTrail,
52
- });
53
47
  export const AppBar = reactCompose(AppBarRoot, {
54
- Toolbar: ToolBar,
48
+ Toolbar: Toolbar,
49
+ ToolbarLead: ToolbarLead,
50
+ ToolbarCenter: ToolbarCenter,
51
+ ToolbarTrail: ToolbarTrail,
55
52
  Headline: AppBarHeadline,
56
53
  });
@@ -15,7 +15,7 @@ export interface AppBarProps extends React.PropsWithChildren {
15
15
  /** Provide arbitrary CSS classes. */
16
16
  classes?: string;
17
17
  }
18
- export interface AppBarToolBarProps extends React.PropsWithChildren {
18
+ export interface ToolBarProps extends React.PropsWithChildren {
19
19
  /** Sets the toolbar component's base styles. */
20
20
  base?: string;
21
21
  /** Sets the toolbar component's grid columns styles. */
@@ -25,7 +25,7 @@ export interface AppBarToolBarProps extends React.PropsWithChildren {
25
25
  /** Provide arbitrary CSS classes to the toolbar component. */
26
26
  classes?: string;
27
27
  }
28
- export interface AppBarLeadProps extends React.PropsWithChildren {
28
+ export interface ToolbarLeadProps extends React.PropsWithChildren {
29
29
  /** Sets the lead component's base styles. */
30
30
  base?: string;
31
31
  /** Sets the lead component's horizontal spacing styles. */
@@ -35,7 +35,7 @@ export interface AppBarLeadProps extends React.PropsWithChildren {
35
35
  /** Provide arbitrary CSS classes to the lead component. */
36
36
  classes?: string;
37
37
  }
38
- export interface AppBarCenterProps extends React.PropsWithChildren {
38
+ export interface ToolbarCenterProps extends React.PropsWithChildren {
39
39
  /** Sets the center component's base styles. */
40
40
  base?: string;
41
41
  /** Sets the center component's alignment styles. */
@@ -45,7 +45,7 @@ export interface AppBarCenterProps extends React.PropsWithChildren {
45
45
  /** Provide arbitrary CSS classes to the center component. */
46
46
  classes?: string;
47
47
  }
48
- export interface AppBarTrailProps extends React.PropsWithChildren {
48
+ export interface ToolbarTrailProps extends React.PropsWithChildren {
49
49
  /** Sets the trail component's base styles. */
50
50
  base?: string;
51
51
  /** Sets the trail component's horizontal spacing styles. */
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { NavContextState, NavRailProps, NavBarProps, NavTileProps } from "./types.js";
3
+ export declare const NavContext: React.Context<NavContextState>;
4
+ export declare const NavRail: React.FC<NavRailProps>;
5
+ export declare const NavBar: React.FC<NavBarProps>;
6
+ export declare const NavTile: React.FC<NavTileProps>;
7
+ export declare const Nav: (() => null) & {
8
+ Rail: React.FC<NavRailProps>;
9
+ Bar: React.FC<NavBarProps>;
10
+ Tile: React.FC<NavTileProps>;
11
+ };
@@ -0,0 +1,81 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { createContext, useContext } from "react";
4
+ // Contexts ---
5
+ export const NavContext = createContext({
6
+ parent: "",
7
+ expanded: false,
8
+ });
9
+ // Components ---
10
+ export const NavRail = ({ expanded = false,
11
+ // 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 = "",
13
+ // Header
14
+ headerBase = "flex", headerFlexDirection = "flex-col", headerJustify = "justify-center", headerItems = "items-center", headerGap = "gap-1", headerClasses = "",
15
+ // Tiles
16
+ tilesBase = "flex-1 flex", tilesFlexDirection = "flex-col", tilesJustify = "justify-center", tilesItems = "items-center", tilesGap = "gap-1", tilesClasses = "",
17
+ // Footer
18
+ footerBase = "flex", footerFlexDirection = "flex-col", footerJustify = "justify-center", footerItems = "items-center", footerGap = "gap-1", footerClasses = "",
19
+ // Snippets
20
+ header, children, footer, }) => {
21
+ // Set Context
22
+ const ctx = {
23
+ parent: "rail",
24
+ expanded,
25
+ };
26
+ // Reactive
27
+ let rxWidth = expanded ? widthExpanded : width;
28
+ 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
+ };
30
+ export const NavBar = ({
31
+ // 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 = "",
33
+ // Tiles
34
+ tilesBase = "flex-1 flex", tilesFlexDirection = "", tilesJustify = "justify-center", tilesItems = "items-center", tilesGap = "gap-1", tilesClasses = "",
35
+ // Snippets
36
+ children, }) => {
37
+ // Set Context
38
+ const ctx = {
39
+ parent: "bar",
40
+ };
41
+ 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
+ };
43
+ export const NavTile = ({ id, href, target, label, labelExpanded, title, selected = false,
44
+ // 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",
46
+ // Expanded
47
+ expandedPadding = "py-3 px-4", expandedGap = "gap-4", expandedClasses = "",
48
+ // Label (base)
49
+ labelBase = "type-scale-1", labelClasses = "",
50
+ // Label (expanded)
51
+ labelExpandedBase = "", labelExpandedClasses = "",
52
+ // Events
53
+ onClick,
54
+ // Snippets
55
+ children, }) => {
56
+ // Get Context
57
+ const ctx = useContext(NavContext);
58
+ // Local
59
+ const TileElement = href ? "a" : "button";
60
+ const type = href ? undefined : "button";
61
+ const role = href ? undefined : "button";
62
+ // Reactive
63
+ let rxSize = ctx.parent === "bar" ? `h-full` : `${aspect}`;
64
+ const classesCollapsed = `${rxSize} ${padding} ${gap} ${classes}`;
65
+ const classesExtended = `${expandedPadding} ${expandedGap} ${expandedClasses}`;
66
+ let rxMode = ctx.expanded ? classesExtended : classesCollapsed;
67
+ let rxBackground = selected ? active : `${background} ${hover}`;
68
+ function onClickHandler() {
69
+ if (onClick && !id)
70
+ throw new Error("No ID was provided");
71
+ if (onClick && id)
72
+ onClick(id);
73
+ }
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] }));
75
+ };
76
+ // Exports ---
77
+ export const Nav = Object.assign(() => null, {
78
+ Rail: NavRail,
79
+ Bar: NavBar,
80
+ Tile: NavTile,
81
+ });
@@ -0,0 +1,125 @@
1
+ /// <reference types="react" />
2
+ export interface NavContextState {
3
+ parent: string;
4
+ expanded?: boolean;
5
+ }
6
+ export interface NavCommonProps {
7
+ /** Set base styles. */
8
+ base?: string;
9
+ /** Set background classes. */
10
+ background?: string;
11
+ /** Set padding classes. */
12
+ padding?: string;
13
+ /** Set width classes. */
14
+ width?: string;
15
+ /** Set width classes for expanded mode. */
16
+ widthExpanded?: string;
17
+ /** Set width classes. */
18
+ height?: string;
19
+ /** Provide arbitrary CSS classes. */
20
+ classes?: string;
21
+ /** Set base classes. */
22
+ tilesBase?: string;
23
+ /** Set flex direction classes. */
24
+ tilesFlexDirection?: string;
25
+ /** Set flex justify classes. */
26
+ tilesJustify?: string;
27
+ /** Set flex align classes. */
28
+ tilesItems?: string;
29
+ /** Set gap classes. */
30
+ tilesGap?: string;
31
+ /** Provide arbitrary CSS classes. */
32
+ tilesClasses?: string;
33
+ }
34
+ export interface NavBarProps extends NavCommonProps {
35
+ /** The default children. */
36
+ children?: React.ReactNode;
37
+ }
38
+ export interface NavRailProps extends NavCommonProps {
39
+ /** Enabled expanded mode. */
40
+ expanded?: boolean;
41
+ /** Set base classes. */
42
+ headerBase?: string;
43
+ /** Set flex direction classes. */
44
+ headerFlexDirection?: string;
45
+ /** Set flex justify classes. */
46
+ headerJustify?: string;
47
+ /** Set flex align classes. */
48
+ headerItems?: string;
49
+ /** Set gap classes. */
50
+ headerGap?: string;
51
+ /** Provide arbitrary CSS classes. */
52
+ headerClasses?: string;
53
+ /** Set base classes. */
54
+ footerBase?: string;
55
+ /** Set flex direction classes. */
56
+ footerFlexDirection?: string;
57
+ /** Set flex justify classes. */
58
+ footerJustify?: string;
59
+ /** Set flex align classes. */
60
+ footerItems?: string;
61
+ /** Set gap classes. */
62
+ footerGap?: string;
63
+ /** Provide arbitrary CSS classes. */
64
+ footerClasses?: string;
65
+ /** The header child node. */
66
+ header?: React.ReactNode;
67
+ /** The tiles child node. */
68
+ children?: React.ReactNode;
69
+ /** The footer child node. */
70
+ footer?: React.ReactNode;
71
+ }
72
+ export interface NavTileProps {
73
+ /** Provide a unique ID. */
74
+ id?: string;
75
+ /** Provide an href link; turns Tiles into an anchor */
76
+ href?: string;
77
+ /** Set the href target attribute. */
78
+ target?: string;
79
+ /** Provide the label text. */
80
+ label?: string;
81
+ /** Provide a longer label in expanded mode. */
82
+ labelExpanded?: string;
83
+ /** Provile a title attribute. */
84
+ title?: string;
85
+ /** Enable the active selected state. */
86
+ selected?: boolean;
87
+ /** Set base styles. */
88
+ base?: string;
89
+ /** Set width classes. */
90
+ width?: string;
91
+ /** Set aspect ratio classes. */
92
+ aspect?: string;
93
+ /** Set background classes. */
94
+ background?: string;
95
+ /** Set hover classes. */
96
+ hover?: string;
97
+ /** Set active classes. */
98
+ active?: string;
99
+ /** Set padding classes. */
100
+ padding?: string;
101
+ /** Set gap classes. */
102
+ gap?: string;
103
+ /** Set rounded classes. */
104
+ rounded?: string;
105
+ /** Provide arbitrary CSS classes. */
106
+ classes?: string;
107
+ /** Set padding classes for expanded mode. */
108
+ expandedPadding?: string;
109
+ /** Set gap classes for expanded mode. */
110
+ expandedGap?: string;
111
+ /** Provide arbitrary CSS classes for expanded mode. */
112
+ expandedClasses?: string;
113
+ /** Set base classes. */
114
+ labelBase?: string;
115
+ /** Provide arbitrary CSS classes. */
116
+ labelClasses?: string;
117
+ /** Set base classes. */
118
+ labelExpandedBase?: string;
119
+ /** Provide arbitrary CSS classes. */
120
+ labelExpandedClasses?: string;
121
+ /** Triggers when the tile is clicked. */
122
+ onClick?: (id: string) => void;
123
+ /** The default children. */
124
+ children?: React.ReactNode;
125
+ }
@@ -0,0 +1,2 @@
1
+ // Context ---
2
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type FC } from "react";
2
+ import { ProgressRingProps } from "./types.js";
3
+ export declare const ProgressRing: FC<ProgressRingProps>;
@@ -0,0 +1,35 @@
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 = "",
7
+ // Slot
8
+ childrenBase = "absolute top-0 left-0 z-[1] flex justify-center items-center", childrenClasses = "",
9
+ // SVG
10
+ svgBase = "absolute top-0 left-0 w-full h-full rounded-full", svgClasses = "",
11
+ // Track
12
+ trackBase = "fill-none", trackStroke = "stroke-surface-200-800", trackClasses = "",
13
+ // Meter
14
+ meterBase = "fill-none", meterStroke = "stroke-primary-500", meterTransition = "transition-[stroke-dashoffset]", meterDuration = "duration-100", meterClasses = "",
15
+ // Label
16
+ label, labelBase = "", labelFill = "fill-surface-950-50", labelFontSize = 96, // px
17
+ labelFontWeight = "bold", labelClasses = "",
18
+ // 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] })] }));
35
+ };
@@ -0,0 +1,55 @@
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;
9
+ /** Defines the shape of the meter */
10
+ strokeLinecap?: "inherit" | "butt" | "round" | "square";
11
+ /** Set the aria-labelledby value */
12
+ labelledby?: string;
13
+ /** Set the root base classes */
14
+ base?: string;
15
+ /** Set the root size classes */
16
+ size?: string;
17
+ /** Provide arbitrary classes to the root element */
18
+ classes?: string;
19
+ /** Set the nested children base classes */
20
+ childrenBase?: string;
21
+ /** Provide arbitrary classes to the nested children. */
22
+ childrenClasses?: string;
23
+ /** Set the SVG element base classes */
24
+ svgBase?: string;
25
+ /** Provide arbitrary classes to the SVG element */
26
+ svgClasses?: string;
27
+ /** Set the track base classes */
28
+ trackBase?: string;
29
+ /** Set the track stroke color classes */
30
+ trackStroke?: string;
31
+ /** Provide arbitrary classes to the track element */
32
+ trackClasses?: string;
33
+ /** Set the meter base classes */
34
+ meterBase?: string;
35
+ /** Set the meter stroke color classes */
36
+ meterStroke?: string;
37
+ /** Set the meter transition classes */
38
+ meterTransition?: string;
39
+ /** Set the meter transition duration classes */
40
+ meterDuration?: string;
41
+ /** Provide arbitrary classes to the meter element */
42
+ meterClasses?: string;
43
+ /** Set the text for the scalable label */
44
+ label?: string;
45
+ /** Set the label classes */
46
+ labelBase?: string;
47
+ /** Set the label fill color classes */
48
+ labelFill?: string;
49
+ /** Set the label font size */
50
+ labelFontSize?: number;
51
+ /** Set the label font weight */
52
+ labelFontWeight?: string;
53
+ /** Provide arbitrary classes to the label element */
54
+ labelClasses?: string;
55
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { RatingProps } from "./types";
3
+ export declare const Rating: React.FC<RatingProps>;
@@ -0,0 +1,79 @@
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,
5
+ // 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 = () => { },
15
+ // 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))) }));
79
+ };
@@ -0,0 +1,59 @@
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. */
12
+ 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. */
20
+ 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. */
56
+ iconEmpty?: ReactNode;
57
+ /** The full icon children. */
58
+ iconFull?: ReactNode;
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { SwitchProps } from "./types.js";
3
+ export declare const Switch: React.FC<SwitchProps>;
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ export const Switch = ({ id = "", name = "", checked = false, disabled = false, compact = false,
4
+ // Aria
5
+ labelledby = undefined, describedby = undefined,
6
+ // Root (Track)
7
+ base = "flex cursor-pointer transition duration-200", stateInactive = "preset-filled-surface-200-800", stateActive = "preset-filled-primary-500", stateDisabled = "opacity-50 cursor-not-allowed", width = "w-10", height = "h-6", padding = "p-0.5", rounded = "rounded-full", hover = "hover:brightness-90 dark:hover:brightness-110", classes = "",
8
+ // Thumb
9
+ thumbBase = "right-0 aspect-square h-full flex justify-center items-center text-right", thumbInactive = "preset-filled-surface-50-950", thumbActive = "bg-surface-50 text-surface-contrast-50", thumbRounded = "rounded-full", thumbTranslateX = "translate-x-4", thumbTransition = "transition", thumbEase = "ease-in-out", thumbDuration = "duration-200", thumbClasses = "",
10
+ // Icons
11
+ iconInactiveBase = "pointer-events-none", iconActiveBase = "pointer-events-none",
12
+ // Events
13
+ onCheckedChange = () => { },
14
+ // Children
15
+ inactiveChild, activeChild, }) => {
16
+ // Set Compact Mode
17
+ if (compact) {
18
+ base = thumbBase;
19
+ // Removes the height class
20
+ height = "";
21
+ // Thumb inherits track styles
22
+ thumbInactive = stateInactive;
23
+ thumbActive = stateActive;
24
+ // Remove X-axis translate
25
+ thumbTranslateX = "";
26
+ // Remove padding
27
+ padding = "";
28
+ }
29
+ function toggle() {
30
+ if (disabled)
31
+ return;
32
+ checked = !checked;
33
+ onCheckedChange(checked);
34
+ }
35
+ const rxTrackState = checked ? stateActive : stateInactive;
36
+ const rxThumbState = checked
37
+ ? `${thumbActive} ${thumbTranslateX}`
38
+ : thumbInactive;
39
+ const rxDisabled = disabled ? stateDisabled : "";
40
+ return (_jsxs("button", { type: "button", className: `${base} ${rxTrackState} ${width} ${height} ${padding} ${rounded} ${hover} ${rxDisabled} ${classes}`, role: "switch", "aria-checked": checked, "aria-labelledby": labelledby, "aria-describedby": describedby, onClick: toggle, "data-testid": "switch", children: [_jsx("input", { type: "checkbox", id: id, name: name, checked: checked, onChange: () => { }, className: "hidden", disabled: disabled }), _jsxs("div", { className: `${thumbBase} ${rxThumbState} ${thumbRounded} ${thumbTransition} ${thumbEase} ${thumbDuration} ${thumbClasses}`, children: [!checked && inactiveChild ? (_jsx("span", { className: iconInactiveBase, children: inactiveChild })) : null, checked && activeChild ? (_jsx("span", { className: iconActiveBase, children: activeChild })) : null] })] }));
41
+ };
@@ -0,0 +1,65 @@
1
+ import { ReactNode } from "react";
2
+ export interface SwitchProps {
3
+ /** Set a unique ID for the switch input. */
4
+ id: string;
5
+ /** Set a unique name for the switch input. */
6
+ name: string;
7
+ /** Set the checked state. */
8
+ checked?: boolean;
9
+ /** Set the disabled state. */
10
+ disabled?: boolean;
11
+ /** Set the compact display mode. */
12
+ compact?: boolean;
13
+ /** Identifies the element that labels the switch. */
14
+ labelledby?: string | undefined;
15
+ /** Identifies the element that describes the switch. */
16
+ describedby?: string | undefined;
17
+ /** Set base classes for the root element. */
18
+ base?: string;
19
+ /** Set inactive state classes for the root element. */
20
+ stateInactive?: string;
21
+ /** Set active state classes for the root element. */
22
+ stateActive?: string;
23
+ /** Set disabled state classes for the root element. */
24
+ stateDisabled?: string;
25
+ /** Set width classes for the root element. */
26
+ width?: string;
27
+ /** Set height classes for the root element. */
28
+ height?: string;
29
+ /** Set padding classes for the root element. */
30
+ padding?: string;
31
+ /** Set rounded classes for the root element. */
32
+ rounded?: string;
33
+ /** Set hover classes for the root element. */
34
+ hover?: string;
35
+ /** Provide arbitrary classes to the root element. */
36
+ classes?: string;
37
+ /** Set base classes for the thumb element. */
38
+ thumbBase?: string;
39
+ /** Set inactive classes for the thumb element. */
40
+ thumbInactive?: string;
41
+ /** Set active classes for the thumb element. */
42
+ thumbActive?: string;
43
+ /** Set rounded classes for the thumb element. */
44
+ thumbRounded?: string;
45
+ /** Set animation X-axis translate classes for the thumb element. */
46
+ thumbTranslateX?: string;
47
+ /** Set animation transition classes for the thumb element. */
48
+ thumbTransition?: string;
49
+ /** Set animation easing classes for the thumb element. */
50
+ thumbEase?: string;
51
+ /** Set animation duration classes for the thumb element. */
52
+ thumbDuration?: string;
53
+ /** Provide arbitrary classes to the thumb element. */
54
+ thumbClasses?: string;
55
+ /** Set base classes for the inactive icon child. */
56
+ iconInactiveBase?: string;
57
+ /** Set base classes for the active icon child. */
58
+ iconActiveBase?: string;
59
+ /** Triggers when the switch is toggled. */
60
+ onCheckedChange?: (event: boolean) => void;
61
+ /** The inactive state children. */
62
+ inactiveChild?: ReactNode;
63
+ /** The active state children. */
64
+ activeChild?: ReactNode;
65
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -10,7 +10,7 @@ children, }) => {
10
10
  };
11
11
  const TabsList = ({
12
12
  // Root
13
- base = "flex", justify = "justify-start", gap = "gap-2", border = "border-b-[1px] border-surface-200-800", classes = "",
13
+ base = "flex", justify = "justify-start", gap = "gap-2", border = "border-b border-surface-200-800", classes = "",
14
14
  // Children
15
15
  children, }) => {
16
16
  return (_jsx("div", { className: `${base} ${gap} ${justify} ${border} ${classes}`, role: "tablist", children: children }));
@@ -19,7 +19,7 @@ const TabsControl = ({ id = "", name, group, title = "",
19
19
  // A11y
20
20
  label = "", controls = "",
21
21
  // Root
22
- base = "group", width = "", active = "text-surface-950-50 border-surface-950-50", inactive = "text-surface-600-400 border-transparent", flex = "flex justify-center items-center", background = "", border = "border-b-[1px]", text = "type-scale-3", padding = "pb-2", rounded = "", gap = "gap-1", cursor = "cursor-pointer", classes = "",
22
+ base = "group", width = "", active = "text-surface-950-50 border-surface-950-50", inactive = "text-surface-600-400 border-transparent", flex = "flex justify-center items-center", background = "", border = "border-b", text = "type-scale-3", padding = "pb-2", rounded = "", gap = "gap-1", cursor = "cursor-pointer", classes = "",
23
23
  // Events
24
24
  onClick = () => { }, onKeydown = () => { }, onKeyup = () => { }, onChange = () => { },
25
25
  // Children
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  export { default as TestReact } from "./components/Test/Test.js";
2
2
  export { Accordion } from "./components/Accordion/Accordion.js";
3
3
  export { Avatar } from "./components/Avatar/Avatar.js";
4
- export { AppBar, ToolBar } from "./components/AppBar/AppBar.js";
4
+ export { AppBar } from "./components/AppBar/AppBar.js";
5
+ export { Nav } from "./components/Navigation/Navigation.js";
5
6
  export { Progress } from "./components/Progress/Progress.js";
7
+ export { ProgressRing } from "./components/ProgressRing/ProgressRing.js";
8
+ export { Switch } from "./components/Switch/Switch.js";
6
9
  export { Tabs } from "./components/Tabs/Tabs.js";
10
+ export { Rating } from "./components/Rating/Rating.js";
package/dist/index.js CHANGED
@@ -2,6 +2,10 @@ export { default as TestReact } from "./components/Test/Test.js";
2
2
  // Components
3
3
  export { Accordion } from "./components/Accordion/Accordion.js";
4
4
  export { Avatar } from "./components/Avatar/Avatar.js";
5
- export { AppBar, ToolBar } from "./components/AppBar/AppBar.js";
5
+ export { AppBar } from "./components/AppBar/AppBar.js";
6
+ export { Nav } from "./components/Navigation/Navigation.js";
6
7
  export { Progress } from "./components/Progress/Progress.js";
8
+ export { ProgressRing } from "./components/ProgressRing/ProgressRing.js";
9
+ export { Switch } from "./components/Switch/Switch.js";
7
10
  export { Tabs } from "./components/Tabs/Tabs.js";
11
+ export { Rating } from "./components/Rating/Rating.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skeletonlabs/skeleton-react",
3
- "version": "1.0.0-next.0",
3
+ "version": "1.0.0-next.2",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -39,6 +39,7 @@
39
39
  "eslint-plugin-react-hooks": "^4.6.0",
40
40
  "eslint-plugin-react-refresh": "^0.4.6",
41
41
  "jsdom": "^24.0.0",
42
+ "lucide-react": "^0.341.0",
42
43
  "postcss": "^8.4.38",
43
44
  "react-router-dom": "^6.22.3",
44
45
  "tailwindcss": "^3.4.3",
@@ -47,7 +48,7 @@
47
48
  "vite": "^5.2.8",
48
49
  "vite-plugin-remix-router": "^2.0.0",
49
50
  "vitest": "^1.4.0",
50
- "@skeletonlabs/skeleton": "3.0.0-next.0",
51
+ "@skeletonlabs/skeleton": "3.0.0-next.1",
51
52
  "vite-plugin-tw-plugin-watcher": "0.0.0"
52
53
  },
53
54
  "peerDependencies": {