@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
|
@@ -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,82 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
// Components ---
|
|
5
|
+
export const Rating = ({ value = 0, max = 5, interactive = false, step = 1,
|
|
6
|
+
// Root
|
|
7
|
+
base = 'flex', width = 'w-full', justify = 'justify-center', spaceX = 'space-x-2', classes = '',
|
|
8
|
+
// Item ---
|
|
9
|
+
buttonBase = 'w-full h-full', buttonPosition = 'relative', buttonAspect = 'aspect-square', buttonClasses = '',
|
|
10
|
+
// Icon Empty
|
|
11
|
+
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 = '',
|
|
12
|
+
// Icon Full
|
|
13
|
+
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 = '',
|
|
14
|
+
// Events
|
|
15
|
+
onMouseDown = () => { }, onKeyDown = () => { }, onValueChange = () => { },
|
|
16
|
+
// Children
|
|
17
|
+
iconEmpty, iconFull }) => {
|
|
18
|
+
const figureRef = useRef(null);
|
|
19
|
+
const valueRef = useRef(value);
|
|
20
|
+
const [focusedButtonIndex, setFocusedButtonIndex] = useState(0);
|
|
21
|
+
const [rxEmptyInteractive, setRxEmptyInteractive] = useState('');
|
|
22
|
+
const [rxFullInteractive, setRxFullInteractive] = useState('');
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const index = Math.max(0, Math.ceil(value - 1));
|
|
25
|
+
setFocusedButtonIndex(index);
|
|
26
|
+
}, [value]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setRxEmptyInteractive(interactive ? emptyInteractive : emptyStatic);
|
|
29
|
+
setRxFullInteractive(interactive ? fullInteractive : fullStatic);
|
|
30
|
+
}, [interactive, emptyInteractive, emptyStatic, fullInteractive, fullStatic]);
|
|
31
|
+
const onRatingMouseDown = useCallback((event, order) => {
|
|
32
|
+
if (!figureRef.current)
|
|
33
|
+
return;
|
|
34
|
+
const ratingRect = event.currentTarget.getBoundingClientRect();
|
|
35
|
+
const fractionWidth = ratingRect.width / step;
|
|
36
|
+
const left = event.clientX - ratingRect.left;
|
|
37
|
+
let selectedFraction = Math.floor(left / fractionWidth) + 1;
|
|
38
|
+
if (getComputedStyle(figureRef.current).direction === 'rtl') {
|
|
39
|
+
selectedFraction = step - selectedFraction + 1;
|
|
40
|
+
}
|
|
41
|
+
valueRef.current = order + selectedFraction / step;
|
|
42
|
+
onValueChange(valueRef.current);
|
|
43
|
+
onMouseDown(event, valueRef.current);
|
|
44
|
+
}, [step, onMouseDown, onValueChange]);
|
|
45
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/radio/examples/radio-rating/#kbd_label
|
|
46
|
+
const onRatingKeyDown = useCallback((event) => {
|
|
47
|
+
// If functions are not used outside of an effect/callback, they need to be defined in the effect/callback
|
|
48
|
+
function increaseValue() {
|
|
49
|
+
valueRef.current = Math.min(max, valueRef.current + 1 / step);
|
|
50
|
+
onValueChange(valueRef.current);
|
|
51
|
+
refreshFocus();
|
|
52
|
+
}
|
|
53
|
+
function decreaseValue() {
|
|
54
|
+
valueRef.current = Math.max(0, valueRef.current - 1 / step);
|
|
55
|
+
onValueChange(valueRef.current);
|
|
56
|
+
refreshFocus();
|
|
57
|
+
}
|
|
58
|
+
function refreshFocus() {
|
|
59
|
+
if (!figureRef.current)
|
|
60
|
+
return;
|
|
61
|
+
const buttons = figureRef.current.querySelectorAll('button');
|
|
62
|
+
buttons[Math.max(0, Math.ceil(valueRef.current - 1))].focus();
|
|
63
|
+
}
|
|
64
|
+
if (!figureRef.current)
|
|
65
|
+
return;
|
|
66
|
+
const rtl = getComputedStyle(figureRef.current).direction === 'rtl';
|
|
67
|
+
if (['ArrowLeft', 'ArrowUp'].includes(event.key)) {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
rtl ? increaseValue() : decreaseValue();
|
|
70
|
+
}
|
|
71
|
+
if (['ArrowRight', 'ArrowDown'].includes(event.key)) {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
rtl ? decreaseValue() : increaseValue();
|
|
74
|
+
}
|
|
75
|
+
onKeyDown(event);
|
|
76
|
+
}, [onKeyDown, max, onValueChange, step]);
|
|
77
|
+
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: {
|
|
78
|
+
'--clipValue': `${(value - order) * 100}%`
|
|
79
|
+
}, "data-testid": "rating-iconempty", children: iconEmpty }), _jsx("span", { className: `${fullBase} ${fullClip} ${rxFullInteractive} ${fullClasses}`, style: {
|
|
80
|
+
'--clipValue': `${100 - (value - order) * 100}%`
|
|
81
|
+
}, "data-testid": "rating-iconfull", children: iconFull })] }, order))) }));
|
|
82
|
+
};
|
|
@@ -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,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SegmentContextState, SegmentProps, SegmentItemsProps } from './types.js';
|
|
3
|
+
export declare const SegmentContext: React.Context<SegmentContextState>;
|
|
4
|
+
export declare const Segment: React.FC<SegmentProps> & {
|
|
5
|
+
Item: React.FC<SegmentItemsProps>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
4
|
+
// Contexts ---
|
|
5
|
+
export const SegmentContext = createContext({
|
|
6
|
+
value: '',
|
|
7
|
+
name: '',
|
|
8
|
+
onSelectionHandler: () => { }
|
|
9
|
+
});
|
|
10
|
+
// Components ---
|
|
11
|
+
const SegmentRoot = ({ value = '', name = '',
|
|
12
|
+
// Root
|
|
13
|
+
base = 'inline-flex items-stretch overflow-hidden', background = 'preset-outlined-surface-200-800', border = 'p-2', flexDirection = 'flex-row', // vertical: flex-col
|
|
14
|
+
gap = 'gap-2', padding = '', rounded = 'rounded-container', width = '', classes = '',
|
|
15
|
+
// Events
|
|
16
|
+
onChange,
|
|
17
|
+
// Children
|
|
18
|
+
children }) => {
|
|
19
|
+
function onSelectionHandler(newValue) {
|
|
20
|
+
value = newValue;
|
|
21
|
+
if (onChange)
|
|
22
|
+
onChange(newValue);
|
|
23
|
+
}
|
|
24
|
+
// Set Context
|
|
25
|
+
const ctx = {
|
|
26
|
+
value,
|
|
27
|
+
name,
|
|
28
|
+
onSelectionHandler
|
|
29
|
+
};
|
|
30
|
+
return (_jsx("div", { role: "radiogroup", className: `${base} ${flexDirection} ${background} ${border} ${padding} ${gap} ${rounded} ${width} ${classes}`, "data-testid": "segment", children: _jsx(SegmentContext.Provider, { value: ctx, children: children }) }));
|
|
31
|
+
};
|
|
32
|
+
const SegmentItem = ({ id, value, title, disabled = false,
|
|
33
|
+
// Root
|
|
34
|
+
base = 'btn', active = 'preset-filled', hover = 'hover:preset-tonal', classes = '',
|
|
35
|
+
// Label
|
|
36
|
+
labelBase = 'pointer-events-none', labelClasses = '',
|
|
37
|
+
// Events
|
|
38
|
+
onClick,
|
|
39
|
+
// Children
|
|
40
|
+
children }) => {
|
|
41
|
+
// Get Context
|
|
42
|
+
const ctx = useContext(SegmentContext);
|
|
43
|
+
// Reactive
|
|
44
|
+
const [selected, setSelected] = useState(value === ctx.value);
|
|
45
|
+
const [rxActive, setRxActive] = useState(selected ? active : hover);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
setSelected(value === ctx.value);
|
|
48
|
+
}, [value, ctx.value]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
setRxActive(selected ? active : hover);
|
|
51
|
+
}, [selected, active, hover]);
|
|
52
|
+
function onClickHandler() {
|
|
53
|
+
ctx.onSelectionHandler(value);
|
|
54
|
+
onClick?.(value);
|
|
55
|
+
}
|
|
56
|
+
return (_jsxs("button", { role: "radio", "aria-checked": selected, onClick: onClickHandler, type: "button", className: `${base} ${rxActive} ${classes}`, title: title, disabled: disabled, "data-testid": "segment-item", children: [selected ? _jsx("input", { type: "hidden", name: ctx.name, id: id, value: value }) : null, _jsx("label", { className: `${labelBase} ${labelClasses}`, children: children })] }));
|
|
57
|
+
};
|
|
58
|
+
export const Segment = Object.assign(SegmentRoot, {
|
|
59
|
+
Item: SegmentItem
|
|
60
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface SegmentContextState {
|
|
3
|
+
value: string;
|
|
4
|
+
name: string;
|
|
5
|
+
onSelectionHandler: (value: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface SegmentProps extends React.PropsWithChildren {
|
|
8
|
+
/** Set the group value, which determines selection state. */
|
|
9
|
+
value?: string;
|
|
10
|
+
/** Provide the shared input name. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Sets base classes. */
|
|
13
|
+
base?: string;
|
|
14
|
+
/** Set background classes. */
|
|
15
|
+
background?: string;
|
|
16
|
+
/** Set border classes. */
|
|
17
|
+
border?: string;
|
|
18
|
+
/** Set flex direction classes. */
|
|
19
|
+
flexDirection?: string;
|
|
20
|
+
/** Set gap classes. */
|
|
21
|
+
gap?: string;
|
|
22
|
+
/** Set padding classes. */
|
|
23
|
+
padding?: string;
|
|
24
|
+
/** Set rounded classes. */
|
|
25
|
+
rounded?: string;
|
|
26
|
+
/** Set width classes. */
|
|
27
|
+
width?: string;
|
|
28
|
+
/** Provide arbitrary CSS classes. */
|
|
29
|
+
classes?: string;
|
|
30
|
+
/** Triggers when the value state is changed. */
|
|
31
|
+
onChange?: (value: string) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface SegmentItemsProps extends React.PropsWithChildren {
|
|
34
|
+
/** Provide a unique ID. */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Provide the unique segment value. */
|
|
37
|
+
value: string;
|
|
38
|
+
/** Provide a hover title attribute. */
|
|
39
|
+
title?: string;
|
|
40
|
+
/** Set the disabled state. */
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
/** Sets base classes. */
|
|
43
|
+
base?: string;
|
|
44
|
+
/** Sets active state classes. */
|
|
45
|
+
active?: string;
|
|
46
|
+
/** Sets hover state classes. */
|
|
47
|
+
hover?: string;
|
|
48
|
+
/** Provide arbitrary CSS classes. */
|
|
49
|
+
classes?: string;
|
|
50
|
+
/** Sets base classes for the label element. */
|
|
51
|
+
labelBase?: string;
|
|
52
|
+
/** Provide arbitrary CSS classes for the label element. */
|
|
53
|
+
labelClasses?: string;
|
|
54
|
+
/** Triggers on items click event. */
|
|
55
|
+
onClick?: (group: string) => void;
|
|
56
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { SwitchProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SwitchProps } from './types.js';
|
|
3
3
|
export declare const Switch: React.FC<SwitchProps>;
|
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
export const Switch = ({ id =
|
|
3
|
+
export const Switch = ({ id = '', name = '', checked = false, disabled = false, compact = false,
|
|
4
4
|
// Aria
|
|
5
5
|
labelledby = undefined, describedby = undefined,
|
|
6
6
|
// Root (Track)
|
|
7
|
-
base =
|
|
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
8
|
// Thumb
|
|
9
|
-
thumbBase =
|
|
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
10
|
// Icons
|
|
11
|
-
iconInactiveBase =
|
|
11
|
+
iconInactiveBase = 'pointer-events-none', iconActiveBase = 'pointer-events-none',
|
|
12
12
|
// Events
|
|
13
|
-
|
|
13
|
+
onChange = () => { },
|
|
14
14
|
// Children
|
|
15
|
-
inactiveChild, activeChild
|
|
15
|
+
inactiveChild, activeChild }) => {
|
|
16
16
|
// Set Compact Mode
|
|
17
17
|
if (compact) {
|
|
18
18
|
base = thumbBase;
|
|
19
19
|
// Removes the height class
|
|
20
|
-
height =
|
|
20
|
+
height = '';
|
|
21
21
|
// Thumb inherits track styles
|
|
22
22
|
thumbInactive = stateInactive;
|
|
23
23
|
thumbActive = stateActive;
|
|
24
24
|
// Remove X-axis translate
|
|
25
|
-
thumbTranslateX =
|
|
25
|
+
thumbTranslateX = '';
|
|
26
26
|
// Remove padding
|
|
27
|
-
padding =
|
|
27
|
+
padding = '';
|
|
28
28
|
}
|
|
29
29
|
function toggle() {
|
|
30
30
|
if (disabled)
|
|
31
31
|
return;
|
|
32
32
|
checked = !checked;
|
|
33
|
-
|
|
33
|
+
onChange(checked);
|
|
34
34
|
}
|
|
35
35
|
const rxTrackState = checked ? stateActive : stateInactive;
|
|
36
|
-
const rxThumbState = checked
|
|
37
|
-
|
|
38
|
-
|
|
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] })] }));
|
|
36
|
+
const rxThumbState = checked ? `${thumbActive} ${thumbTranslateX}` : thumbInactive;
|
|
37
|
+
const rxDisabled = disabled ? stateDisabled : '';
|
|
38
|
+
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: [checked ?? _jsx("input", { type: "hidden", id: id, name: name, value: "on", 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
39
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode } from
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
export interface SwitchProps {
|
|
3
3
|
/** Set a unique ID for the switch input. */
|
|
4
4
|
id: string;
|
|
@@ -57,7 +57,7 @@ export interface SwitchProps {
|
|
|
57
57
|
/** Set base classes for the active icon child. */
|
|
58
58
|
iconActiveBase?: string;
|
|
59
59
|
/** Triggers when the switch is toggled. */
|
|
60
|
-
|
|
60
|
+
onChange?: (event: boolean) => void;
|
|
61
61
|
/** The inactive state children. */
|
|
62
62
|
inactiveChild?: ReactNode;
|
|
63
63
|
/** The active state children. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { TabsProps, TabsListProps, TabsControlProps,
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TabsProps, TabsListProps, TabsControlProps, TabPanelsProps, TabsPanelProps } from './types.js';
|
|
3
3
|
export declare const Tabs: React.FC<TabsProps> & {
|
|
4
4
|
List: React.FC<TabsListProps>;
|
|
5
5
|
Control: React.FC<TabsControlProps>;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Panels: React.FC<TabPanelsProps>;
|
|
7
|
+
Panel: React.FC<TabsPanelProps>;
|
|
8
8
|
};
|
|
@@ -1,29 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from
|
|
3
|
-
|
|
4
|
-
const TabsRoot = ({ id =
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
/** The root Tab component. */
|
|
5
|
+
const TabsRoot = ({ id = '',
|
|
5
6
|
// Root
|
|
6
|
-
base =
|
|
7
|
+
base = 'w-full', spaceY = 'space-y-4', classes = '',
|
|
7
8
|
// Children
|
|
8
|
-
children
|
|
9
|
+
children }) => {
|
|
9
10
|
return (_jsx("div", { id: id, className: `${base} ${spaceY} ${classes}`, "data-testid": "tabs", children: children }));
|
|
10
11
|
};
|
|
12
|
+
/** The list of `<Tab.Control>` components. */
|
|
11
13
|
const TabsList = ({
|
|
12
14
|
// Root
|
|
13
|
-
base =
|
|
15
|
+
base = 'flex', justify = 'justify-start', gap = 'gap-2', border = 'border-b border-surface-200-800', classes = '',
|
|
14
16
|
// Children
|
|
15
|
-
children
|
|
17
|
+
children }) => {
|
|
16
18
|
return (_jsx("div", { className: `${base} ${gap} ${justify} ${border} ${classes}`, role: "tablist", children: children }));
|
|
17
19
|
};
|
|
18
|
-
|
|
20
|
+
/** The individual Tab control component. */
|
|
21
|
+
const TabsControl = ({ id = '', name, group, title = '',
|
|
19
22
|
// A11y
|
|
20
|
-
label =
|
|
23
|
+
label = '', controls = '',
|
|
21
24
|
// Root
|
|
22
|
-
base =
|
|
25
|
+
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 = '',
|
|
26
|
+
// Content
|
|
27
|
+
contentBase = 'w-full', contentFlex = 'flex justify-center items-center', contentGap = 'gap-2', contentBg = 'group-hover:preset-tonal-primary', contentPadding = 'p-2 px-4', contentRounded = 'rounded-container', contentClasses = '',
|
|
23
28
|
// Events
|
|
24
29
|
onClick = () => { }, onKeydown = () => { }, onKeyup = () => { }, onChange = () => { },
|
|
25
30
|
// Children
|
|
26
|
-
children
|
|
31
|
+
children }) => {
|
|
27
32
|
const [selected, setSelected] = useState(group === name);
|
|
28
33
|
useEffect(() => {
|
|
29
34
|
setSelected(group === name);
|
|
@@ -40,7 +45,7 @@ children, }) => {
|
|
|
40
45
|
// Fire Event Handler
|
|
41
46
|
onKeydown(event);
|
|
42
47
|
// If select key events
|
|
43
|
-
if (![
|
|
48
|
+
if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(event.code))
|
|
44
49
|
return;
|
|
45
50
|
const elemInput = elemInputRef.current;
|
|
46
51
|
if (!elemInput)
|
|
@@ -55,7 +60,7 @@ children, }) => {
|
|
|
55
60
|
if (!tabList)
|
|
56
61
|
return;
|
|
57
62
|
// Get RTL mode
|
|
58
|
-
const isRTL = getComputedStyle(tabList).direction ===
|
|
63
|
+
const isRTL = getComputedStyle(tabList).direction === 'rtl';
|
|
59
64
|
// Get list of tab elements
|
|
60
65
|
const tabs = Array.from(tabList.querySelectorAll('[role="tab"]'));
|
|
61
66
|
// Get a reference to the current tab
|
|
@@ -63,24 +68,24 @@ children, }) => {
|
|
|
63
68
|
// Determine the index of the next tab
|
|
64
69
|
let nextIndex = -1;
|
|
65
70
|
switch (event.code) {
|
|
66
|
-
case
|
|
71
|
+
case 'ArrowRight':
|
|
67
72
|
if (isRTL) {
|
|
68
73
|
nextIndex = currIndex - 1 < 0 ? tabs.length - 1 : currIndex - 1;
|
|
69
74
|
break;
|
|
70
75
|
}
|
|
71
76
|
nextIndex = currIndex + 1 >= tabs.length ? 0 : currIndex + 1;
|
|
72
77
|
break;
|
|
73
|
-
case
|
|
78
|
+
case 'ArrowLeft':
|
|
74
79
|
if (isRTL) {
|
|
75
80
|
nextIndex = currIndex + 1 >= tabs.length ? 0 : currIndex + 1;
|
|
76
81
|
break;
|
|
77
82
|
}
|
|
78
83
|
nextIndex = currIndex - 1 < 0 ? tabs.length - 1 : currIndex - 1;
|
|
79
84
|
break;
|
|
80
|
-
case
|
|
85
|
+
case 'Home':
|
|
81
86
|
nextIndex = 0;
|
|
82
87
|
break;
|
|
83
|
-
case
|
|
88
|
+
case 'End':
|
|
84
89
|
nextIndex = tabs.length - 1;
|
|
85
90
|
break;
|
|
86
91
|
}
|
|
@@ -88,34 +93,36 @@ children, }) => {
|
|
|
88
93
|
return;
|
|
89
94
|
// Set Active Tab
|
|
90
95
|
const nextTab = tabs[nextIndex];
|
|
91
|
-
const nextTabInput = nextTab?.querySelector(
|
|
96
|
+
const nextTabInput = nextTab?.querySelector('input');
|
|
92
97
|
if (nextTabInput) {
|
|
93
98
|
nextTabInput.click();
|
|
94
99
|
nextTab.focus();
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
|
-
return (_jsx("label", { id: id, className: `${base} ${width} ${rxActive} ${flex} ${background} ${border} ${text} ${padding} ${rounded} ${gap} ${cursor} ${classes}`, "aria-label": label, title: title, children: _jsxs("div", { className: "size-full", role: "tab", "aria-controls": controls, "aria-selected": selected, "data-testid": "tabs-control", tabIndex: selected ? 0 : -1, onKeyDown: onKeyDownHandler, onKeyUp: onKeyup, children: [_jsx("div", { className: "h-0 w-0 flex-none overflow-hidden", children: _jsx("input", { ref: elemInputRef, type: "radio", name: name, value: name, checked: selected, onChange: handleOnChange, onClick: onClick, tabIndex: -1 }) }), children] }) }));
|
|
102
|
+
return (_jsx("label", { id: id, className: `${base} ${width} ${rxActive} ${flex} ${background} ${border} ${text} ${padding} ${rounded} ${gap} ${cursor} ${classes}`, "aria-label": label, title: title, children: _jsxs("div", { className: "size-full", role: "tab", "aria-controls": controls, "aria-selected": selected, "data-testid": "tabs-control", tabIndex: selected ? 0 : -1, onKeyDown: onKeyDownHandler, onKeyUp: onKeyup, children: [_jsx("div", { className: "h-0 w-0 flex-none overflow-hidden", children: _jsx("input", { ref: elemInputRef, type: "radio", name: name, value: name, checked: selected, onChange: handleOnChange, onClick: onClick, tabIndex: -1 }) }), children && (_jsx("div", { className: `${contentBase} ${contentFlex} ${contentGap} ${contentBg} ${contentPadding} ${contentRounded} ${contentClasses}`, children: children }))] }) }));
|
|
98
103
|
};
|
|
99
|
-
|
|
104
|
+
/** The list of `<Tab.Panel>` components. */
|
|
105
|
+
const TabPanels = ({
|
|
100
106
|
// Root
|
|
101
|
-
base =
|
|
107
|
+
base = '', classes = '',
|
|
102
108
|
// Children
|
|
103
|
-
children
|
|
104
|
-
return
|
|
109
|
+
children }) => {
|
|
110
|
+
return _jsx("div", { className: `${base} ${classes}`, children: children });
|
|
105
111
|
};
|
|
106
|
-
|
|
112
|
+
/** The individual Panel component. */
|
|
113
|
+
const TabsPanel = ({ id = '', value, group,
|
|
107
114
|
// A11y
|
|
108
115
|
labelledBy,
|
|
109
116
|
// Root
|
|
110
|
-
classes =
|
|
117
|
+
classes = '',
|
|
111
118
|
// Children
|
|
112
|
-
children
|
|
119
|
+
children }) => {
|
|
113
120
|
return (value === group &&
|
|
114
121
|
children && (_jsx("div", { id: id, role: "tabpanel", tabIndex: 0, "aria-labelledby": labelledBy, className: classes, children: children })));
|
|
115
122
|
};
|
|
116
123
|
export const Tabs = Object.assign(TabsRoot, {
|
|
117
124
|
List: TabsList,
|
|
118
125
|
Control: TabsControl,
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
Panels: TabPanels,
|
|
127
|
+
Panel: TabsPanel
|
|
121
128
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export interface TabsProps extends React.PropsWithChildren {
|
|
3
3
|
/** Provide a unique ID. */
|
|
4
4
|
id?: string;
|
|
@@ -60,6 +60,20 @@ export interface TabsControlProps extends React.PropsWithChildren {
|
|
|
60
60
|
cursor?: string;
|
|
61
61
|
/** Provide arbitrary CSS classes. */
|
|
62
62
|
classes?: string;
|
|
63
|
+
/** Sets tab content base styles. */
|
|
64
|
+
contentBase?: string;
|
|
65
|
+
/** Sets tab content flex styles. */
|
|
66
|
+
contentFlex?: string;
|
|
67
|
+
/** Sets the tab content gap styles. */
|
|
68
|
+
contentGap?: string;
|
|
69
|
+
/** Sets the tab content background styles. */
|
|
70
|
+
contentBg?: string;
|
|
71
|
+
/** Sets the tab content padding styles. */
|
|
72
|
+
contentPadding?: string;
|
|
73
|
+
/** Sets the tab content rounded styles. */
|
|
74
|
+
contentRounded?: string;
|
|
75
|
+
/** Provide arbitrary CSS classes for the tab content. */
|
|
76
|
+
contentClasses?: string;
|
|
63
77
|
/** Triggers on Tab Control click. */
|
|
64
78
|
onClick?: (event: React.MouseEvent<HTMLInputElement>) => void;
|
|
65
79
|
/** Triggers on Tab Control key down. */
|
|
@@ -69,23 +83,13 @@ export interface TabsControlProps extends React.PropsWithChildren {
|
|
|
69
83
|
/** Triggers on Tab Control group change. */
|
|
70
84
|
onChange?: (group: string) => void;
|
|
71
85
|
}
|
|
72
|
-
export interface
|
|
73
|
-
/** Sets base styles. */
|
|
86
|
+
export interface TabPanelsProps extends React.PropsWithChildren {
|
|
87
|
+
/** Sets wrapping panel base styles. */
|
|
74
88
|
base?: string;
|
|
75
|
-
/**
|
|
76
|
-
flex?: string;
|
|
77
|
-
/** Sets gap styles. */
|
|
78
|
-
gap?: string;
|
|
79
|
-
/** Sets background styles. */
|
|
80
|
-
background?: string;
|
|
81
|
-
/** Sets padding styles. */
|
|
82
|
-
padding?: string;
|
|
83
|
-
/** Sets rounded styles. */
|
|
84
|
-
rounded?: string;
|
|
85
|
-
/** Provide arbitrary CSS classes. */
|
|
89
|
+
/** Provide arbitrary CSS classes to the wrapping panel element. */
|
|
86
90
|
classes?: string;
|
|
87
91
|
}
|
|
88
|
-
export interface
|
|
92
|
+
export interface TabsPanelProps extends React.PropsWithChildren {
|
|
89
93
|
/** Provide a unique ID. */
|
|
90
94
|
id?: string;
|
|
91
95
|
/** Provide the tab panel value. */
|