@skeletonlabs/skeleton-react 1.0.0-next.2 → 1.0.0-next.3
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/Accordion/Accordion.d.ts +2 -2
- package/dist/components/Accordion/Accordion.js +21 -21
- package/dist/components/Accordion/types.d.ts +1 -1
- package/dist/components/AppBar/AppBar.d.ts +2 -2
- package/dist/components/AppBar/AppBar.js +18 -20
- package/dist/components/AppBar/types.d.ts +1 -1
- package/dist/components/Avatar/Avatar.d.ts +2 -2
- package/dist/components/Avatar/Avatar.js +5 -5
- package/dist/components/Navigation/Navigation.d.ts +2 -2
- package/dist/components/Navigation/Navigation.js +53 -30
- package/dist/components/Navigation/types.d.ts +6 -0
- package/dist/components/Progress/Progress.d.ts +2 -2
- package/dist/components/Progress/Progress.js +6 -6
- package/dist/components/ProgressRing/ProgressRing.d.ts +2 -2
- package/dist/components/ProgressRing/ProgressRing.js +21 -20
- package/dist/components/ProgressRing/types.d.ts +1 -1
- package/dist/components/Rating/Rating.d.ts +2 -2
- package/dist/components/Rating/Rating.js +40 -37
- package/dist/components/Rating/types.d.ts +1 -1
- package/dist/components/Segment/Segment.d.ts +6 -0
- package/dist/components/Segment/Segment.js +60 -0
- package/dist/components/Segment/types.d.ts +56 -0
- package/dist/components/Segment/types.js +2 -0
- package/dist/components/Switch/Switch.d.ts +2 -2
- package/dist/components/Switch/Switch.js +14 -16
- package/dist/components/Switch/types.d.ts +2 -2
- package/dist/components/Tabs/Tabs.d.ts +4 -4
- package/dist/components/Tabs/Tabs.js +35 -28
- package/dist/components/Tabs/types.d.ts +19 -15
- package/dist/components/Test/Test.js +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.js +11 -10
- package/package.json +14 -18
- package/dist/utils/react-compose.d.ts +0 -4
- package/dist/utils/react-compose.js +0 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { AccordionContextState, AccordionControlProps, AccordionItemContextState, AccordionItemProps, AccordionPanelProps, AccordionProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AccordionContextState, AccordionControlProps, AccordionItemContextState, AccordionItemProps, AccordionPanelProps, AccordionProps } from './types.js';
|
|
3
3
|
export declare const AccordionContext: React.Context<AccordionContextState>;
|
|
4
4
|
export declare const AccordionItemContext: React.Context<AccordionItemContextState>;
|
|
5
5
|
export declare const Accordion: React.FC<AccordionProps> & {
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { motion, AnimatePresence } from 'framer-motion';
|
|
4
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
5
5
|
// Contexts ---
|
|
6
6
|
export const AccordionContext = createContext({
|
|
7
7
|
animDuration: 0.2,
|
|
8
|
-
iconOpen:
|
|
9
|
-
iconClosed:
|
|
8
|
+
iconOpen: '-',
|
|
9
|
+
iconClosed: '+',
|
|
10
10
|
open: () => { },
|
|
11
11
|
close: () => { },
|
|
12
12
|
toggle: () => { },
|
|
13
|
-
isOpen: () => false
|
|
13
|
+
isOpen: () => false
|
|
14
14
|
});
|
|
15
15
|
export const AccordionItemContext = createContext({
|
|
16
|
-
id:
|
|
17
|
-
onClick: () => { }
|
|
16
|
+
id: '',
|
|
17
|
+
onClick: () => { }
|
|
18
18
|
});
|
|
19
19
|
// Components ---
|
|
20
20
|
const AccordionRoot = ({ multiple = false, value: valueInit = [], animDuration = 0.2,
|
|
21
21
|
// Root
|
|
22
|
-
base =
|
|
22
|
+
base = '', padding = '', spaceY = 'space-y-2', rounded = 'rounded', width = 'w-full', classes = '',
|
|
23
23
|
// Icons
|
|
24
|
-
iconOpen =
|
|
24
|
+
iconOpen = '-', iconClosed = '+',
|
|
25
25
|
// Events
|
|
26
26
|
onValueChange = () => { },
|
|
27
27
|
// Children
|
|
28
|
-
children
|
|
28
|
+
children }) => {
|
|
29
29
|
// State
|
|
30
30
|
const [value, setValue] = useState(multiple ? valueInit : [valueInit[0]]);
|
|
31
31
|
// Functions
|
|
@@ -53,24 +53,24 @@ children, }) => {
|
|
|
53
53
|
open,
|
|
54
54
|
close,
|
|
55
55
|
toggle,
|
|
56
|
-
isOpen
|
|
56
|
+
isOpen
|
|
57
57
|
};
|
|
58
58
|
return (_jsx("div", { className: `${base} ${padding} ${spaceY} ${rounded} ${width} ${classes}`, "data-testid": "accordion", children: _jsx(AccordionContext.Provider, { value: ctx, children: children }) }));
|
|
59
59
|
};
|
|
60
|
-
const AccordionItem = ({ id, base =
|
|
60
|
+
const AccordionItem = ({ id, base = '', spaceY = '', classes = '',
|
|
61
61
|
// Events
|
|
62
62
|
onClick = () => { },
|
|
63
63
|
// Children
|
|
64
|
-
children
|
|
64
|
+
children }) => {
|
|
65
65
|
return (_jsx(AccordionItemContext.Provider, { value: { id, onClick }, children: _jsx("div", { className: `${base} ${spaceY} ${classes}`, "data-testid": "accordion-item", children: children }) }));
|
|
66
66
|
};
|
|
67
67
|
const AccordionControl = ({ disabled = false,
|
|
68
68
|
// Control
|
|
69
|
-
base =
|
|
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 = '',
|
|
70
70
|
// Icons
|
|
71
71
|
lead,
|
|
72
72
|
// Children
|
|
73
|
-
children
|
|
73
|
+
children }) => {
|
|
74
74
|
const rootCtx = useContext(AccordionContext);
|
|
75
75
|
const itemCtx = useContext(AccordionItemContext);
|
|
76
76
|
function clickHandler(event) {
|
|
@@ -81,18 +81,18 @@ children, }) => {
|
|
|
81
81
|
};
|
|
82
82
|
const AccordionPanel = ({
|
|
83
83
|
// Panel
|
|
84
|
-
base =
|
|
84
|
+
base = '', padding = 'py-2 px-4', rounded = '', classes = '',
|
|
85
85
|
// Children
|
|
86
|
-
children
|
|
86
|
+
children }) => {
|
|
87
87
|
const rootCtx = useContext(AccordionContext);
|
|
88
88
|
const itemCtx = useContext(AccordionItemContext);
|
|
89
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:
|
|
91
|
-
collapsed: { opacity: 0, height: 0 }
|
|
90
|
+
open: { opacity: 1, height: 'auto' },
|
|
91
|
+
collapsed: { opacity: 0, height: 0 }
|
|
92
92
|
}, transition: { duration: rootCtx.animDuration && 0.2 }, children: _jsx("div", { className: `${base} ${padding} ${rounded} ${classes}`, "data-testid": "accordion-panel-children", children: children }) })) }) }));
|
|
93
93
|
};
|
|
94
94
|
export const Accordion = Object.assign(AccordionRoot, {
|
|
95
95
|
Item: AccordionItem,
|
|
96
96
|
Control: AccordionControl,
|
|
97
|
-
Panel: AccordionPanel
|
|
97
|
+
Panel: AccordionPanel
|
|
98
98
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { ToolbarCenterProps, AppBarHeadlineProps, ToolbarLeadProps, AppBarProps, ToolBarProps, ToolbarTrailProps } from
|
|
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 =
|
|
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 =
|
|
12
|
+
base = 'flex justify-between', gridCols = 'grid-cols-[auto_1fr_auto]', gap = 'gap-4', classes = '',
|
|
15
13
|
// Children
|
|
16
|
-
children
|
|
17
|
-
return
|
|
14
|
+
children }) => {
|
|
15
|
+
return _jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, children: children });
|
|
18
16
|
};
|
|
19
17
|
const ToolbarLead = ({
|
|
20
18
|
// Lead
|
|
21
|
-
base =
|
|
19
|
+
base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
|
|
22
20
|
// Children
|
|
23
|
-
children
|
|
24
|
-
return
|
|
21
|
+
children }) => {
|
|
22
|
+
return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
|
|
25
23
|
};
|
|
26
24
|
const ToolbarCenter = ({
|
|
27
25
|
// Center
|
|
28
|
-
base =
|
|
26
|
+
base = 'grow', align = 'text-center', padding = '', classes = '',
|
|
29
27
|
// Children
|
|
30
|
-
children
|
|
31
|
-
return
|
|
28
|
+
children }) => {
|
|
29
|
+
return _jsx("div", { className: `${base} ${align} ${padding} ${classes}`, children: children });
|
|
32
30
|
};
|
|
33
31
|
const ToolbarTrail = ({
|
|
34
32
|
// Trail
|
|
35
|
-
base =
|
|
33
|
+
base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
|
|
36
34
|
// Children
|
|
37
|
-
children
|
|
38
|
-
return
|
|
35
|
+
children }) => {
|
|
36
|
+
return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
|
|
39
37
|
};
|
|
40
38
|
const AppBarHeadline = ({
|
|
41
39
|
// Headline
|
|
42
|
-
base =
|
|
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 =
|
|
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,3 +1,3 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { AvatarProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AvatarProps } from './types.js';
|
|
3
3
|
export declare const Avatar: React.FC<AvatarProps>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
export const Avatar = ({ src =
|
|
3
|
+
export const Avatar = ({ src = '', alt = '', filter = '',
|
|
4
4
|
// Root
|
|
5
|
-
base =
|
|
5
|
+
base = 'overflow-hidden isolate', background = 'bg-surface-400-600', size = 'size-16', font = '', border = '', rounded = 'rounded-full', shadow = '', classes = '',
|
|
6
6
|
// Image
|
|
7
|
-
imageBase =
|
|
7
|
+
imageBase = 'w-full object-cover', imageClasses = '',
|
|
8
8
|
// Children
|
|
9
|
-
children
|
|
9
|
+
children }) => {
|
|
10
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) }));
|
|
11
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { NavContextState, NavRailProps, NavBarProps, NavTileProps } from
|
|
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
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext } from
|
|
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 =
|
|
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 =
|
|
16
|
+
headerBase = 'flex', headerFlexDirection = 'flex-col', headerJustify = 'justify-center', headerItems = 'items-center', headerGap = 'gap-1', headerClasses = '',
|
|
15
17
|
// Tiles
|
|
16
|
-
tilesBase =
|
|
18
|
+
tilesBase = 'flex-1 flex', tilesFlexDirection = 'flex-col', tilesJustify = 'justify-center', tilesItems = 'items-center', tilesGap = 'gap-1', tilesClasses = '',
|
|
17
19
|
// Footer
|
|
18
|
-
footerBase =
|
|
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:
|
|
32
|
+
parent: 'rail',
|
|
33
|
+
value,
|
|
24
34
|
expanded,
|
|
35
|
+
onSelectionHandler
|
|
25
36
|
};
|
|
26
37
|
// Reactive
|
|
27
|
-
|
|
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 =
|
|
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 =
|
|
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:
|
|
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 =
|
|
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 =
|
|
68
|
+
expandedPadding = 'py-3 px-4', expandedGap = 'gap-4', expandedClasses = '',
|
|
48
69
|
// Label (base)
|
|
49
|
-
labelBase =
|
|
70
|
+
labelBase = 'type-scale-1', labelClasses = '',
|
|
50
71
|
// Label (expanded)
|
|
51
|
-
labelExpandedBase =
|
|
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 ?
|
|
60
|
-
const type = href ? undefined :
|
|
61
|
-
const role = href ? undefined :
|
|
80
|
+
const TileElement = href ? 'a' : 'button';
|
|
81
|
+
const type = href ? undefined : 'button';
|
|
82
|
+
const role = href ? undefined : 'button';
|
|
62
83
|
// Reactive
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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(
|
|
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 ?
|
|
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,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export interface NavContextState {
|
|
3
3
|
parent: string;
|
|
4
|
+
value: string;
|
|
4
5
|
expanded?: boolean;
|
|
6
|
+
onSelectionHandler: (id: string) => void;
|
|
5
7
|
}
|
|
8
|
+
/** Props common between NavRail and NavBar */
|
|
6
9
|
export interface NavCommonProps {
|
|
10
|
+
value?: string;
|
|
7
11
|
/** Set base styles. */
|
|
8
12
|
base?: string;
|
|
9
13
|
/** Set background classes. */
|
|
@@ -30,6 +34,8 @@ export interface NavCommonProps {
|
|
|
30
34
|
tilesGap?: string;
|
|
31
35
|
/** Provide arbitrary CSS classes. */
|
|
32
36
|
tilesClasses?: string;
|
|
37
|
+
/** Triggers when selection occurs. */
|
|
38
|
+
onChange?: (id: string) => void;
|
|
33
39
|
}
|
|
34
40
|
export interface NavBarProps extends NavCommonProps {
|
|
35
41
|
/** The default children. */
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type FC } from
|
|
2
|
-
import { ProgressProps } from
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
import { ProgressProps } from './types.js';
|
|
3
3
|
export declare const Progress: FC<ProgressProps>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from
|
|
3
|
-
export const Progress = ({ value, max = 100, labelledBy =
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
export const Progress = ({ value, max = 100, labelledBy = '',
|
|
4
4
|
// Root
|
|
5
|
-
base =
|
|
5
|
+
base = 'overflow-x-hidden', bg = 'bg-surface-200-800', width = 'w-full', height = 'h-2', rounded = 'rounded', classes = '',
|
|
6
6
|
// Meter
|
|
7
|
-
meterBase =
|
|
7
|
+
meterBase = 'h-full', meterBg = 'bg-surface-950-50', meterRounded = 'rounded', meterTransition = 'transition-[width]', meterAnimate = 'animate-indeterminate', meterClasses = '' }) => {
|
|
8
8
|
useEffect(() => {
|
|
9
9
|
if (max < 0) {
|
|
10
|
-
console.warn(
|
|
10
|
+
console.warn('The max prop should be greater than or equal to 0');
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
const indeterminate = value === undefined;
|
|
14
14
|
const fillPercentage = `${indeterminate ? 50 : ((value - 0) / (max - 0)) * 100}%`;
|
|
15
|
-
const rxIndeterminate = indeterminate ? meterAnimate :
|
|
15
|
+
const rxIndeterminate = indeterminate ? meterAnimate : '';
|
|
16
16
|
return (_jsx(_Fragment, { children: _jsx("div", { role: "progressbar", "aria-labelledby": labelledBy, "aria-valuenow": value, "aria-valuemin": 0, "aria-valuemax": max, className: `${base} ${bg} ${width} ${height} ${rounded} ${classes}`, children: _jsx("div", { className: `${meterBase} ${meterBg} ${meterRounded} ${meterTransition} ${rxIndeterminate} ${meterClasses}`, style: { width: fillPercentage } }) }) }));
|
|
17
17
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type FC } from
|
|
2
|
-
import { ProgressRingProps } from
|
|
1
|
+
import { type FC } from 'react';
|
|
2
|
+
import { ProgressRingProps } from './types.js';
|
|
3
3
|
export declare const ProgressRing: FC<ProgressRingProps>;
|
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
3
|
export const ProgressRing = ({ value, max = 100, strokeWidth = 50, // px
|
|
4
|
-
strokeLinecap =
|
|
4
|
+
strokeLinecap = 'round', labelledby = '',
|
|
5
5
|
// Base (figure)
|
|
6
|
-
base =
|
|
6
|
+
base = 'relative', size = 'size-32', classes = '',
|
|
7
7
|
// Slot
|
|
8
|
-
childrenBase =
|
|
8
|
+
childrenBase = 'absolute top-0 left-0 z-[1] flex justify-center items-center', childrenClasses = '',
|
|
9
9
|
// SVG
|
|
10
|
-
svgBase =
|
|
10
|
+
svgBase = 'absolute top-0 left-0 w-full h-full rounded-full', svgClasses = '',
|
|
11
11
|
// Track
|
|
12
|
-
trackBase =
|
|
12
|
+
trackBase = 'fill-none', trackStroke = 'stroke-surface-200-800', trackClasses = '',
|
|
13
13
|
// Meter
|
|
14
|
-
meterBase =
|
|
14
|
+
meterBase = 'fill-none', meterStroke = 'stroke-primary-500', meterTransition = 'transition-[stroke-dashoffset]', meterDuration = 'duration-100', meterClasses = '',
|
|
15
15
|
// Label
|
|
16
|
-
label, labelBase =
|
|
17
|
-
labelFontWeight =
|
|
16
|
+
label, labelBase = '', labelFill = 'fill-surface-950-50', labelFontSize = 96, // px
|
|
17
|
+
labelFontWeight = 'bold', labelClasses = '',
|
|
18
18
|
// Children
|
|
19
|
-
children
|
|
19
|
+
children }) => {
|
|
20
20
|
// Local
|
|
21
21
|
const baseSize = 512; // px
|
|
22
22
|
const radius = baseSize / 2 - strokeWidth / 2;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const [circumference, setCircumference] = useState(radius);
|
|
24
|
+
const [dashoffset, setDashoffset] = useState(0);
|
|
25
25
|
useEffect(() => {
|
|
26
|
+
// Since calcDashOffset is only used in this effect, it's implementation should be inside the effect to avoid a rerender loop
|
|
27
|
+
const calcDashOffset = () => {
|
|
28
|
+
const v = value !== undefined ? value : 25;
|
|
29
|
+
const percent = (100 * v) / max;
|
|
30
|
+
setCircumference(radius * 2 * Math.PI);
|
|
31
|
+
return circumference - (percent / 100) * circumference;
|
|
32
|
+
};
|
|
26
33
|
setDashoffset(calcDashOffset());
|
|
27
|
-
}, [
|
|
28
|
-
|
|
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] })] }));
|
|
34
|
+
}, [circumference, max, radius, setCircumference, value]);
|
|
35
|
+
return (_jsxs("figure", { className: `${base} ${size} ${classes}`, role: "meter", "aria-labelledby": labelledby, "aria-valuenow": value || 0, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuetext": `${value} / ${max}`, "data-testid": "progress-ring", children: [children ? _jsx("div", { className: `${childrenBase} ${size} ${childrenClasses}`, children: children }) : null, _jsxs("svg", { viewBox: `0 0 ${baseSize} ${baseSize}`, className: `${svgBase} ${svgClasses} ${value === undefined ? 'animate-spin' : ''}`, children: [_jsx("circle", { className: `${trackBase} ${trackStroke} ${trackClasses}`, strokeWidth: strokeWidth, r: radius, cx: "50%", cy: "50%" }), _jsx("circle", { className: `${meterBase} ${meterStroke} ${meterTransition} ${meterDuration} ${meterClasses}`, r: radius, cx: "50%", cy: "50%", strokeWidth: strokeWidth, strokeLinecap: strokeLinecap, strokeDasharray: `${circumference} ${circumference}`, strokeDashoffset: dashoffset, transform: `rotate(-90 ${baseSize / 2} ${baseSize / 2})` }), value !== undefined && !children ? (_jsx("text", { className: `${labelBase} ${labelFill} ${labelClasses}`, x: "50%", y: "50%", fontSize: labelFontSize, fontWeight: labelFontWeight, textAnchor: "middle", dominantBaseline: "central", children: label ?? `${value}%` })) : null] })] }));
|
|
35
36
|
};
|
|
@@ -7,7 +7,7 @@ export interface ProgressRingProps extends React.PropsWithChildren {
|
|
|
7
7
|
/** Set the stroke size (px) */
|
|
8
8
|
strokeWidth?: number;
|
|
9
9
|
/** Defines the shape of the meter */
|
|
10
|
-
strokeLinecap?:
|
|
10
|
+
strokeLinecap?: 'inherit' | 'butt' | 'round' | 'square';
|
|
11
11
|
/** Set the aria-labelledby value */
|
|
12
12
|
labelledby?: string;
|
|
13
13
|
/** Set the root base classes */
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { RatingProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RatingProps } from './types';
|
|
3
3
|
export declare const Rating: React.FC<RatingProps>;
|