@skeletonlabs/skeleton-react 1.0.0-next.1 → 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 +6 -8
- package/dist/components/AppBar/AppBar.js +26 -31
- package/dist/components/AppBar/types.d.ts +5 -5
- package/dist/components/Avatar/Avatar.d.ts +2 -2
- package/dist/components/Avatar/Avatar.js +5 -5
- package/dist/components/Navigation/Navigation.d.ts +11 -0
- package/dist/components/Navigation/Navigation.js +104 -0
- package/dist/components/Navigation/types.d.ts +131 -0
- package/dist/components/Navigation/types.js +2 -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 +3 -0
- package/dist/components/ProgressRing/ProgressRing.js +36 -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 +82 -0
- package/dist/components/Rating/types.d.ts +59 -0
- package/dist/components/Rating/types.js +1 -0
- 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 -7
- package/dist/index.js +11 -7
- 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,11 +1,9 @@
|
|
|
1
|
-
import React from
|
|
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
|
-
};
|
|
1
|
+
import React from 'react';
|
|
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,56 +1,51 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
// React Compose ---
|
|
4
|
-
import { reactCompose } from "../../utils/react-compose.js";
|
|
5
2
|
// Components ---
|
|
6
3
|
const AppBarRoot = ({
|
|
7
4
|
// Root
|
|
8
|
-
base =
|
|
5
|
+
base = 'w-full flex flex-col', background = 'bg-surface-100-900', spaceY = 'space-y-4', border = '', padding = 'p-4', shadow = '', classes = '',
|
|
9
6
|
// Children
|
|
10
|
-
children
|
|
7
|
+
children }) => {
|
|
11
8
|
return (_jsx("div", { className: `${base} ${background} ${spaceY} ${border} ${padding} ${shadow} ${classes}`, role: "toolbar", "data-testid": "app-bar", children: children }));
|
|
12
9
|
};
|
|
13
|
-
const
|
|
10
|
+
const Toolbar = ({
|
|
14
11
|
// Toolbar
|
|
15
|
-
base =
|
|
12
|
+
base = 'flex justify-between', gridCols = 'grid-cols-[auto_1fr_auto]', gap = 'gap-4', classes = '',
|
|
16
13
|
// Children
|
|
17
|
-
children
|
|
18
|
-
return
|
|
14
|
+
children }) => {
|
|
15
|
+
return _jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, children: children });
|
|
19
16
|
};
|
|
20
|
-
const
|
|
17
|
+
const ToolbarLead = ({
|
|
21
18
|
// Lead
|
|
22
|
-
base =
|
|
19
|
+
base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
|
|
23
20
|
// Children
|
|
24
|
-
children
|
|
25
|
-
return
|
|
21
|
+
children }) => {
|
|
22
|
+
return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
|
|
26
23
|
};
|
|
27
|
-
const
|
|
24
|
+
const ToolbarCenter = ({
|
|
28
25
|
// Center
|
|
29
|
-
base =
|
|
26
|
+
base = 'grow', align = 'text-center', padding = '', classes = '',
|
|
30
27
|
// Children
|
|
31
|
-
children
|
|
32
|
-
return
|
|
28
|
+
children }) => {
|
|
29
|
+
return _jsx("div", { className: `${base} ${align} ${padding} ${classes}`, children: children });
|
|
33
30
|
};
|
|
34
|
-
const
|
|
31
|
+
const ToolbarTrail = ({
|
|
35
32
|
// Trail
|
|
36
|
-
base =
|
|
33
|
+
base = 'flex', spaceX = 'space-x-4 rtl:space-x-reverse', padding = '', classes = '',
|
|
37
34
|
// Children
|
|
38
|
-
children
|
|
39
|
-
return
|
|
35
|
+
children }) => {
|
|
36
|
+
return _jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children });
|
|
40
37
|
};
|
|
41
38
|
const AppBarHeadline = ({
|
|
42
39
|
// Headline
|
|
43
|
-
base =
|
|
40
|
+
base = 'w-full', classes = '',
|
|
44
41
|
// Children
|
|
45
|
-
children
|
|
42
|
+
children }) => {
|
|
46
43
|
return _jsx("div", { className: `${base} ${classes}`, children: children });
|
|
47
44
|
};
|
|
48
|
-
export const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Toolbar: ToolBar,
|
|
55
|
-
Headline: AppBarHeadline,
|
|
45
|
+
export const AppBar = Object.assign(AppBarRoot, {
|
|
46
|
+
Toolbar: Toolbar,
|
|
47
|
+
ToolbarLead: ToolbarLead,
|
|
48
|
+
ToolbarCenter: ToolbarCenter,
|
|
49
|
+
ToolbarTrail: ToolbarTrail,
|
|
50
|
+
Headline: AppBarHeadline
|
|
56
51
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export interface AppBarProps extends React.PropsWithChildren {
|
|
3
3
|
/** Set base styles. */
|
|
4
4
|
base?: string;
|
|
@@ -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. */
|
|
@@ -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
|
};
|
|
@@ -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,104 @@
|
|
|
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: 'none',
|
|
7
|
+
value: '',
|
|
8
|
+
expanded: false,
|
|
9
|
+
onSelectionHandler: () => { }
|
|
10
|
+
});
|
|
11
|
+
// Components ---
|
|
12
|
+
export const NavRail = ({ value = '', expanded = false,
|
|
13
|
+
// Root
|
|
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 = '',
|
|
15
|
+
// Header
|
|
16
|
+
headerBase = 'flex', headerFlexDirection = 'flex-col', headerJustify = 'justify-center', headerItems = 'items-center', headerGap = 'gap-1', headerClasses = '',
|
|
17
|
+
// Tiles
|
|
18
|
+
tilesBase = 'flex-1 flex', tilesFlexDirection = 'flex-col', tilesJustify = 'justify-center', tilesItems = 'items-center', tilesGap = 'gap-1', tilesClasses = '',
|
|
19
|
+
// Footer
|
|
20
|
+
footerBase = 'flex', footerFlexDirection = 'flex-col', footerJustify = 'justify-center', footerItems = 'items-center', footerGap = 'gap-1', footerClasses = '',
|
|
21
|
+
// Events
|
|
22
|
+
onChange,
|
|
23
|
+
// Snippets
|
|
24
|
+
header, children, footer }) => {
|
|
25
|
+
function onSelectionHandler(id) {
|
|
26
|
+
value = id;
|
|
27
|
+
if (onChange)
|
|
28
|
+
onChange(id);
|
|
29
|
+
}
|
|
30
|
+
// Set Context
|
|
31
|
+
const ctx = {
|
|
32
|
+
parent: 'rail',
|
|
33
|
+
value,
|
|
34
|
+
expanded,
|
|
35
|
+
onSelectionHandler
|
|
36
|
+
};
|
|
37
|
+
// Reactive
|
|
38
|
+
const rxWidth = expanded ? widthExpanded : width;
|
|
39
|
+
return (_jsx("aside", { className: `${base} ${background} ${height} ${padding} ${rxWidth} ${classes}`, "data-testid": "nav-rail", children: _jsxs(NavContext.Provider, { value: ctx, children: [header ? (_jsx("header", { className: `${headerBase} ${headerFlexDirection} ${headerJustify} ${headerItems} ${headerGap} ${headerClasses}`, children: header })) : null, children ? (_jsx("nav", { className: `${tilesBase} ${tilesFlexDirection} ${tilesJustify} ${tilesItems} ${tilesGap} ${tilesClasses}`, children: children })) : null, footer ? (_jsx("footer", { className: `${footerBase} ${footerFlexDirection} ${footerJustify} ${footerItems} ${footerGap} ${footerClasses}`, children: footer })) : null] }) }));
|
|
40
|
+
};
|
|
41
|
+
export const NavBar = ({ value = '',
|
|
42
|
+
// Root
|
|
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 = '',
|
|
44
|
+
// Tiles
|
|
45
|
+
tilesBase = 'flex-1 flex', tilesFlexDirection = '', tilesJustify = 'justify-center', tilesItems = 'items-center', tilesGap = 'gap-1', tilesClasses = '',
|
|
46
|
+
// Events
|
|
47
|
+
onChange,
|
|
48
|
+
// Snippets
|
|
49
|
+
children }) => {
|
|
50
|
+
function onSelectionHandler(id) {
|
|
51
|
+
value = id;
|
|
52
|
+
if (onChange)
|
|
53
|
+
onChange(id);
|
|
54
|
+
}
|
|
55
|
+
// Set Context
|
|
56
|
+
const ctx = {
|
|
57
|
+
parent: 'bar',
|
|
58
|
+
value,
|
|
59
|
+
expanded: false,
|
|
60
|
+
onSelectionHandler
|
|
61
|
+
};
|
|
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 }) }));
|
|
63
|
+
};
|
|
64
|
+
export const NavTile = ({ id, href, target, label, labelExpanded, title, selected = false,
|
|
65
|
+
// Root
|
|
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',
|
|
67
|
+
// Expanded
|
|
68
|
+
expandedPadding = 'py-3 px-4', expandedGap = 'gap-4', expandedClasses = '',
|
|
69
|
+
// Label (base)
|
|
70
|
+
labelBase = 'type-scale-1', labelClasses = '',
|
|
71
|
+
// Label (expanded)
|
|
72
|
+
labelExpandedBase = '', labelExpandedClasses = '',
|
|
73
|
+
// Events
|
|
74
|
+
onClick,
|
|
75
|
+
// Snippets
|
|
76
|
+
children }) => {
|
|
77
|
+
// Get Context
|
|
78
|
+
const ctx = useContext(NavContext);
|
|
79
|
+
// Local
|
|
80
|
+
const TileElement = href ? 'a' : 'button';
|
|
81
|
+
const type = href ? undefined : 'button';
|
|
82
|
+
const role = href ? undefined : 'button';
|
|
83
|
+
// Reactive
|
|
84
|
+
const rxSize = ctx.parent === 'bar' ? `h-full` : `${aspect}`;
|
|
85
|
+
const classesCollapsed = `${rxSize} ${padding} ${gap} ${classes}`;
|
|
86
|
+
const classesExtended = `${expandedPadding} ${expandedGap} ${expandedClasses}`;
|
|
87
|
+
const rxMode = ctx.expanded ? classesExtended : classesCollapsed;
|
|
88
|
+
const rxBackground = selected || ctx.value === id ? active : `${background} ${hover}`;
|
|
89
|
+
function onClickHandler() {
|
|
90
|
+
if (onClick && !id)
|
|
91
|
+
throw new Error('No ID was provided');
|
|
92
|
+
if (onClick && id)
|
|
93
|
+
onClick(id);
|
|
94
|
+
if (ctx.onSelectionHandler && id)
|
|
95
|
+
ctx.onSelectionHandler(id);
|
|
96
|
+
}
|
|
97
|
+
return (_jsxs(TileElement, { className: `${base} ${width} ${rounded} ${rxBackground} ${rxMode}`, href: href, target: target, type: type, title: title, role: role, onClick: onClickHandler, "data-parent": ctx.parent, "data-expanded": ctx.expanded, "data-testid": "nav-tile", children: [children ? _jsx("div", { children: children }) : null, label && !ctx.expanded ? _jsx("div", { className: `${labelBase} ${labelClasses}`, children: label }) : null, labelExpanded && ctx.expanded ? _jsx("div", { className: `${labelExpandedBase} ${labelExpandedClasses}`, children: labelExpanded }) : null] }));
|
|
98
|
+
};
|
|
99
|
+
// Exports ---
|
|
100
|
+
export const Nav = Object.assign(() => null, {
|
|
101
|
+
Rail: NavRail,
|
|
102
|
+
Bar: NavBar,
|
|
103
|
+
Tile: NavTile
|
|
104
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface NavContextState {
|
|
3
|
+
parent: string;
|
|
4
|
+
value: string;
|
|
5
|
+
expanded?: boolean;
|
|
6
|
+
onSelectionHandler: (id: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/** Props common between NavRail and NavBar */
|
|
9
|
+
export interface NavCommonProps {
|
|
10
|
+
value?: string;
|
|
11
|
+
/** Set base styles. */
|
|
12
|
+
base?: string;
|
|
13
|
+
/** Set background classes. */
|
|
14
|
+
background?: string;
|
|
15
|
+
/** Set padding classes. */
|
|
16
|
+
padding?: string;
|
|
17
|
+
/** Set width classes. */
|
|
18
|
+
width?: string;
|
|
19
|
+
/** Set width classes for expanded mode. */
|
|
20
|
+
widthExpanded?: string;
|
|
21
|
+
/** Set width classes. */
|
|
22
|
+
height?: string;
|
|
23
|
+
/** Provide arbitrary CSS classes. */
|
|
24
|
+
classes?: string;
|
|
25
|
+
/** Set base classes. */
|
|
26
|
+
tilesBase?: string;
|
|
27
|
+
/** Set flex direction classes. */
|
|
28
|
+
tilesFlexDirection?: string;
|
|
29
|
+
/** Set flex justify classes. */
|
|
30
|
+
tilesJustify?: string;
|
|
31
|
+
/** Set flex align classes. */
|
|
32
|
+
tilesItems?: string;
|
|
33
|
+
/** Set gap classes. */
|
|
34
|
+
tilesGap?: string;
|
|
35
|
+
/** Provide arbitrary CSS classes. */
|
|
36
|
+
tilesClasses?: string;
|
|
37
|
+
/** Triggers when selection occurs. */
|
|
38
|
+
onChange?: (id: string) => void;
|
|
39
|
+
}
|
|
40
|
+
export interface NavBarProps extends NavCommonProps {
|
|
41
|
+
/** The default children. */
|
|
42
|
+
children?: React.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
export interface NavRailProps extends NavCommonProps {
|
|
45
|
+
/** Enabled expanded mode. */
|
|
46
|
+
expanded?: boolean;
|
|
47
|
+
/** Set base classes. */
|
|
48
|
+
headerBase?: string;
|
|
49
|
+
/** Set flex direction classes. */
|
|
50
|
+
headerFlexDirection?: string;
|
|
51
|
+
/** Set flex justify classes. */
|
|
52
|
+
headerJustify?: string;
|
|
53
|
+
/** Set flex align classes. */
|
|
54
|
+
headerItems?: string;
|
|
55
|
+
/** Set gap classes. */
|
|
56
|
+
headerGap?: string;
|
|
57
|
+
/** Provide arbitrary CSS classes. */
|
|
58
|
+
headerClasses?: string;
|
|
59
|
+
/** Set base classes. */
|
|
60
|
+
footerBase?: string;
|
|
61
|
+
/** Set flex direction classes. */
|
|
62
|
+
footerFlexDirection?: string;
|
|
63
|
+
/** Set flex justify classes. */
|
|
64
|
+
footerJustify?: string;
|
|
65
|
+
/** Set flex align classes. */
|
|
66
|
+
footerItems?: string;
|
|
67
|
+
/** Set gap classes. */
|
|
68
|
+
footerGap?: string;
|
|
69
|
+
/** Provide arbitrary CSS classes. */
|
|
70
|
+
footerClasses?: string;
|
|
71
|
+
/** The header child node. */
|
|
72
|
+
header?: React.ReactNode;
|
|
73
|
+
/** The tiles child node. */
|
|
74
|
+
children?: React.ReactNode;
|
|
75
|
+
/** The footer child node. */
|
|
76
|
+
footer?: React.ReactNode;
|
|
77
|
+
}
|
|
78
|
+
export interface NavTileProps {
|
|
79
|
+
/** Provide a unique ID. */
|
|
80
|
+
id?: string;
|
|
81
|
+
/** Provide an href link; turns Tiles into an anchor */
|
|
82
|
+
href?: string;
|
|
83
|
+
/** Set the href target attribute. */
|
|
84
|
+
target?: string;
|
|
85
|
+
/** Provide the label text. */
|
|
86
|
+
label?: string;
|
|
87
|
+
/** Provide a longer label in expanded mode. */
|
|
88
|
+
labelExpanded?: string;
|
|
89
|
+
/** Provile a title attribute. */
|
|
90
|
+
title?: string;
|
|
91
|
+
/** Enable the active selected state. */
|
|
92
|
+
selected?: boolean;
|
|
93
|
+
/** Set base styles. */
|
|
94
|
+
base?: string;
|
|
95
|
+
/** Set width classes. */
|
|
96
|
+
width?: string;
|
|
97
|
+
/** Set aspect ratio classes. */
|
|
98
|
+
aspect?: string;
|
|
99
|
+
/** Set background classes. */
|
|
100
|
+
background?: string;
|
|
101
|
+
/** Set hover classes. */
|
|
102
|
+
hover?: string;
|
|
103
|
+
/** Set active classes. */
|
|
104
|
+
active?: string;
|
|
105
|
+
/** Set padding classes. */
|
|
106
|
+
padding?: string;
|
|
107
|
+
/** Set gap classes. */
|
|
108
|
+
gap?: string;
|
|
109
|
+
/** Set rounded classes. */
|
|
110
|
+
rounded?: string;
|
|
111
|
+
/** Provide arbitrary CSS classes. */
|
|
112
|
+
classes?: string;
|
|
113
|
+
/** Set padding classes for expanded mode. */
|
|
114
|
+
expandedPadding?: string;
|
|
115
|
+
/** Set gap classes for expanded mode. */
|
|
116
|
+
expandedGap?: string;
|
|
117
|
+
/** Provide arbitrary CSS classes for expanded mode. */
|
|
118
|
+
expandedClasses?: string;
|
|
119
|
+
/** Set base classes. */
|
|
120
|
+
labelBase?: string;
|
|
121
|
+
/** Provide arbitrary CSS classes. */
|
|
122
|
+
labelClasses?: string;
|
|
123
|
+
/** Set base classes. */
|
|
124
|
+
labelExpandedBase?: string;
|
|
125
|
+
/** Provide arbitrary CSS classes. */
|
|
126
|
+
labelExpandedClasses?: string;
|
|
127
|
+
/** Triggers when the tile is clicked. */
|
|
128
|
+
onClick?: (id: string) => void;
|
|
129
|
+
/** The default children. */
|
|
130
|
+
children?: React.ReactNode;
|
|
131
|
+
}
|
|
@@ -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
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
const [circumference, setCircumference] = useState(radius);
|
|
24
|
+
const [dashoffset, setDashoffset] = useState(0);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
// Since calcDashOffset is only used in this effect, it's implementation should be inside the effect to avoid a rerender loop
|
|
27
|
+
const calcDashOffset = () => {
|
|
28
|
+
const v = value !== undefined ? value : 25;
|
|
29
|
+
const percent = (100 * v) / max;
|
|
30
|
+
setCircumference(radius * 2 * Math.PI);
|
|
31
|
+
return circumference - (percent / 100) * circumference;
|
|
32
|
+
};
|
|
33
|
+
setDashoffset(calcDashOffset());
|
|
34
|
+
}, [circumference, max, radius, setCircumference, value]);
|
|
35
|
+
return (_jsxs("figure", { className: `${base} ${size} ${classes}`, role: "meter", "aria-labelledby": labelledby, "aria-valuenow": value || 0, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuetext": `${value} / ${max}`, "data-testid": "progress-ring", children: [children ? _jsx("div", { className: `${childrenBase} ${size} ${childrenClasses}`, children: children }) : null, _jsxs("svg", { viewBox: `0 0 ${baseSize} ${baseSize}`, className: `${svgBase} ${svgClasses} ${value === undefined ? 'animate-spin' : ''}`, children: [_jsx("circle", { className: `${trackBase} ${trackStroke} ${trackClasses}`, strokeWidth: strokeWidth, r: radius, cx: "50%", cy: "50%" }), _jsx("circle", { className: `${meterBase} ${meterStroke} ${meterTransition} ${meterDuration} ${meterClasses}`, r: radius, cx: "50%", cy: "50%", strokeWidth: strokeWidth, strokeLinecap: strokeLinecap, strokeDasharray: `${circumference} ${circumference}`, strokeDashoffset: dashoffset, transform: `rotate(-90 ${baseSize / 2} ${baseSize / 2})` }), value !== undefined && !children ? (_jsx("text", { className: `${labelBase} ${labelFill} ${labelClasses}`, x: "50%", y: "50%", fontSize: labelFontSize, fontWeight: labelFontWeight, textAnchor: "middle", dominantBaseline: "central", children: label ?? `${value}%` })) : null] })] }));
|
|
36
|
+
};
|