@skeletonlabs/skeleton-react 1.0.0-next.1 → 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.
- package/dist/components/AppBar/AppBar.d.ts +5 -7
- package/dist/components/AppBar/AppBar.js +8 -11
- package/dist/components/AppBar/types.d.ts +4 -4
- package/dist/components/Navigation/Navigation.d.ts +11 -0
- package/dist/components/Navigation/Navigation.js +81 -0
- package/dist/components/Navigation/types.d.ts +125 -0
- package/dist/components/Navigation/types.js +2 -0
- package/dist/components/ProgressRing/ProgressRing.d.ts +3 -0
- package/dist/components/ProgressRing/ProgressRing.js +35 -0
- package/dist/components/ProgressRing/types.d.ts +55 -0
- package/dist/components/ProgressRing/types.js +1 -0
- package/dist/components/Rating/Rating.d.ts +3 -0
- package/dist/components/Rating/Rating.js +79 -0
- package/dist/components/Rating/types.d.ts +59 -0
- package/dist/components/Rating/types.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
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<
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,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,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 {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +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
|
|
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";
|
|
6
8
|
export { Switch } from "./components/Switch/Switch.js";
|
|
7
9
|
export { Tabs } from "./components/Tabs/Tabs.js";
|
|
10
|
+
export { Rating } from "./components/Rating/Rating.js";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +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
|
|
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";
|
|
7
9
|
export { Switch } from "./components/Switch/Switch.js";
|
|
8
10
|
export { Tabs } from "./components/Tabs/Tabs.js";
|
|
11
|
+
export { Rating } from "./components/Rating/Rating.js";
|