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

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Skeleton Labs, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Skeleton-React
2
+
3
+ Provides all React features for [Skeleton](https://skeleton.dev/).
4
+
5
+ ## Project
6
+
7
+ This project has been created using a [Vite/React](https://vitejs.dev/).
8
+
9
+ ## Exports
10
+
11
+ Library exports are contained within `/src/lib/index.ts`
12
+
13
+ ## Routing
14
+
15
+ Routing is provided by [vite-remix-router](https://vite-remix-router.vercel.app/) and Remix's [React Router](https://reactrouter.com/en/main).
16
+
17
+ ## Dev
18
+
19
+ To run locally, follow the following instructions:
20
+
21
+ ```
22
+ pnpm i
23
+ pnpm dev
24
+ ```
25
+
26
+ Then point your browser at http://localhost:5173/
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { AccordionContextState, AccordionControlProps, AccordionItemContextState, AccordionItemProps, AccordionPanelProps, AccordionProps } from "./types.js";
3
+ export declare const AccordionContext: React.Context<AccordionContextState>;
4
+ export declare const AccordionItemContext: React.Context<AccordionItemContextState>;
5
+ export declare const Accordion: React.FC<AccordionProps> & {
6
+ Item: React.FC<AccordionItemProps>;
7
+ Control: React.FC<AccordionControlProps>;
8
+ Panel: React.FC<AccordionPanelProps>;
9
+ };
@@ -0,0 +1,98 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { createContext, useContext, useEffect, useState } from "react";
4
+ import { motion, AnimatePresence } from "framer-motion";
5
+ // Contexts ---
6
+ export const AccordionContext = createContext({
7
+ animDuration: 0.2,
8
+ iconOpen: "-",
9
+ iconClosed: "+",
10
+ open: () => { },
11
+ close: () => { },
12
+ toggle: () => { },
13
+ isOpen: () => false,
14
+ });
15
+ export const AccordionItemContext = createContext({
16
+ id: "",
17
+ onClick: () => { },
18
+ });
19
+ // Components ---
20
+ const AccordionRoot = ({ multiple = false, value: valueInit = [], animDuration = 0.2,
21
+ // Root
22
+ base = "", padding = "", spaceY = "space-y-2", rounded = "rounded", width = "w-full", classes = "",
23
+ // Icons
24
+ iconOpen = "-", iconClosed = "+",
25
+ // Events
26
+ onValueChange = () => { },
27
+ // Children
28
+ children, }) => {
29
+ // State
30
+ const [value, setValue] = useState(multiple ? valueInit : [valueInit[0]]);
31
+ // Functions
32
+ function open(id) {
33
+ setValue((opened) => (multiple ? [...opened, id] : [id]));
34
+ }
35
+ function close(id) {
36
+ setValue((opened) => opened.filter((_id) => _id !== id));
37
+ }
38
+ function toggle(id) {
39
+ isOpen(id) ? close(id) : open(id);
40
+ }
41
+ function isOpen(id) {
42
+ return value.includes(id);
43
+ }
44
+ // Effect
45
+ useEffect(() => {
46
+ onValueChange(value);
47
+ }, [onValueChange, value]);
48
+ // Context
49
+ const ctx = {
50
+ animDuration,
51
+ iconOpen,
52
+ iconClosed,
53
+ open,
54
+ close,
55
+ toggle,
56
+ isOpen,
57
+ };
58
+ return (_jsx("div", { className: `${base} ${padding} ${spaceY} ${rounded} ${width} ${classes}`, "data-testid": "accordion", children: _jsx(AccordionContext.Provider, { value: ctx, children: children }) }));
59
+ };
60
+ const AccordionItem = ({ id, base = "", spaceY = "", classes = "",
61
+ // Events
62
+ onClick = () => { },
63
+ // Children
64
+ children, }) => {
65
+ return (_jsx(AccordionItemContext.Provider, { value: { id, onClick }, children: _jsx("div", { className: `${base} ${spaceY} ${classes}`, "data-testid": "accordion-item", children: children }) }));
66
+ };
67
+ const AccordionControl = ({ disabled = false,
68
+ // Control
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
+ // Icons
71
+ lead,
72
+ // Children
73
+ children, }) => {
74
+ const rootCtx = useContext(AccordionContext);
75
+ const itemCtx = useContext(AccordionItemContext);
76
+ function clickHandler(event) {
77
+ rootCtx.toggle(itemCtx.id);
78
+ itemCtx.onClick(event);
79
+ }
80
+ return (_jsxs("button", { type: "button", className: `${base} ${hover} ${padding} ${rounded} ${classes}`, "aria-expanded": rootCtx.isOpen(itemCtx.id), "aria-controls": `accordion-panel-${itemCtx.id}`, onClick: clickHandler, disabled: disabled, "data-testid": "accordion-control", children: [lead && _jsx("div", { children: lead }), _jsx("div", { className: "flex-1", children: children }), _jsx("div", { className: `${iconsBase}`, children: rootCtx.isOpen(itemCtx.id) ? rootCtx.iconOpen : rootCtx.iconClosed })] }));
81
+ };
82
+ const AccordionPanel = ({
83
+ // Panel
84
+ base = "", padding = "py-2 px-4", rounded = "", classes = "",
85
+ // Children
86
+ children, }) => {
87
+ const rootCtx = useContext(AccordionContext);
88
+ const itemCtx = useContext(AccordionItemContext);
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: "auto" },
91
+ collapsed: { opacity: 0, height: 0 },
92
+ }, transition: { duration: rootCtx.animDuration && 0.2 }, children: _jsx("div", { className: `${base} ${padding} ${rounded} ${classes}`, "data-testid": "accordion-panel-children", children: children }) })) }) }));
93
+ };
94
+ export const Accordion = Object.assign(AccordionRoot, {
95
+ Item: AccordionItem,
96
+ Control: AccordionControl,
97
+ Panel: AccordionPanel,
98
+ });
@@ -0,0 +1,83 @@
1
+ import React, { type ReactNode } from "react";
2
+ export interface AccordionContextState {
3
+ animDuration?: number;
4
+ iconOpen?: ReactNode;
5
+ iconClosed?: ReactNode;
6
+ open: (id: string) => void;
7
+ close: (id: string) => void;
8
+ toggle: (id: string) => void;
9
+ isOpen: (id: string) => boolean;
10
+ }
11
+ export interface AccordionItemContextState {
12
+ id: string;
13
+ onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
14
+ }
15
+ export interface AccordionProps extends React.PropsWithChildren {
16
+ /**
17
+ * Enables opening multiple items at once.
18
+ * @default false
19
+ */
20
+ multiple?: boolean;
21
+ /** Takes an array list of open items. */
22
+ value?: string[];
23
+ /** The slide animation duration in milliseconds. */
24
+ animDuration?: number;
25
+ /** Set the open state icon. */
26
+ iconOpen?: ReactNode;
27
+ /** Set the closed state icon. */
28
+ iconClosed?: ReactNode;
29
+ /** Set the opened state. */
30
+ onValueChange?: (opened: string[]) => void;
31
+ /** Sets base styles. */
32
+ base?: string;
33
+ /** Set padding styles. */
34
+ padding?: string;
35
+ /** Set vertical spacing styles. */
36
+ spaceY?: string;
37
+ /** Set border radius styles. */
38
+ rounded?: string;
39
+ /** Set the width styles. */
40
+ width?: string;
41
+ /** Provide arbitrary CSS classes. */
42
+ classes?: string;
43
+ }
44
+ export interface AccordionItemProps extends React.PropsWithChildren {
45
+ /** The unique ID. */
46
+ id: string;
47
+ /** Sets base styles. */
48
+ base?: string;
49
+ /** Set vertical spacing styles. */
50
+ spaceY?: string;
51
+ /** Provide arbitrary CSS classes. */
52
+ classes?: string;
53
+ /** Triggers on item click. */
54
+ onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
55
+ }
56
+ export interface AccordionControlProps extends React.PropsWithChildren {
57
+ /** Set a disabled state for the item. */
58
+ disabled?: boolean;
59
+ /** Sets control's base styles. */
60
+ base?: string;
61
+ /** Sets control's the hover styles. */
62
+ hover?: string;
63
+ /** Sets control's the padding styles. */
64
+ padding?: string;
65
+ /** Sets control's the border radius styles. */
66
+ rounded?: string;
67
+ /** Provide arbitrary CSS classes to the control. */
68
+ classes?: string;
69
+ /** Set the base styles for the state icons. */
70
+ iconsBase?: string;
71
+ /** The lead child slot for the control. */
72
+ lead?: ReactNode;
73
+ }
74
+ export interface AccordionPanelProps extends React.PropsWithChildren {
75
+ /** Set the panel's base styles. */
76
+ base?: string;
77
+ /** Set the panel's padding styles. */
78
+ padding?: string;
79
+ /** Set the panel's border-radius styles. */
80
+ rounded?: string;
81
+ /** Provide arbitrary CSS classes to the panel. */
82
+ classes?: string;
83
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { AppBarCenterProps, AppBarHeadlineProps, AppBarLeadProps, AppBarProps, AppBarToolBarProps, AppBarTrailProps } from "./types.js";
3
+ export declare const ToolBar: React.FC<AppBarToolBarProps> & {
4
+ Lead: React.FC<AppBarLeadProps>;
5
+ Center: React.FC<AppBarCenterProps>;
6
+ Trail: React.FC<AppBarTrailProps>;
7
+ };
8
+ export declare const AppBar: React.FC<AppBarProps> & {
9
+ Toolbar: React.FC<AppBarToolBarProps>;
10
+ Headline: React.FC<AppBarHeadlineProps>;
11
+ };
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ // React Compose ---
4
+ import { reactCompose } from "../../utils/react-compose.js";
5
+ // Components ---
6
+ const AppBarRoot = ({
7
+ // Root
8
+ base = "w-full flex flex-col", background = "bg-surface-100-900", spaceY = "space-y-4", border = "", padding = "p-4", shadow = "", classes = "",
9
+ // Children
10
+ children, }) => {
11
+ return (_jsx("div", { className: `${base} ${background} ${spaceY} ${border} ${padding} ${shadow} ${classes}`, role: "toolbar", "data-testid": "app-bar", children: children }));
12
+ };
13
+ const AppBarToolBarRoot = ({
14
+ // Toolbar
15
+ base = "flex justify-between", gridCols = "grid-cols-[auto_1fr_auto]", gap = "gap-4", classes = "",
16
+ // Children
17
+ children, }) => {
18
+ return (_jsx("div", { className: `${base} ${gridCols} ${gap} ${classes}`, children: children }));
19
+ };
20
+ const AppBarLead = ({
21
+ // Lead
22
+ base = "flex", spaceX = "space-x-4 rtl:space-x-reverse", padding = "", classes = "",
23
+ // Children
24
+ children, }) => {
25
+ return (_jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children }));
26
+ };
27
+ const AppBarCenter = ({
28
+ // Center
29
+ base = "grow", align = "text-center", padding = "", classes = "",
30
+ // Children
31
+ children, }) => {
32
+ return (_jsx("div", { className: `${base} ${align} ${padding} ${classes}`, children: children }));
33
+ };
34
+ const AppBarTrail = ({
35
+ // Trail
36
+ base = "flex", spaceX = "space-x-4 rtl:space-x-reverse", padding = "", classes = "",
37
+ // Children
38
+ children, }) => {
39
+ return (_jsx("div", { className: `${base} ${spaceX} ${padding} ${classes}`, children: children }));
40
+ };
41
+ const AppBarHeadline = ({
42
+ // Headline
43
+ base = "w-full", classes = "",
44
+ // Children
45
+ children, }) => {
46
+ return _jsx("div", { className: `${base} ${classes}`, children: children });
47
+ };
48
+ export const ToolBar = reactCompose(AppBarToolBarRoot, {
49
+ Lead: AppBarLead,
50
+ Center: AppBarCenter,
51
+ Trail: AppBarTrail,
52
+ });
53
+ export const AppBar = reactCompose(AppBarRoot, {
54
+ Toolbar: ToolBar,
55
+ Headline: AppBarHeadline,
56
+ });
@@ -0,0 +1,63 @@
1
+ import React from "react";
2
+ export interface AppBarProps extends React.PropsWithChildren {
3
+ /** Set base styles. */
4
+ base?: string;
5
+ /** Set background styles. */
6
+ background?: string;
7
+ /** Set vertical spacing styles. */
8
+ spaceY?: string;
9
+ /** Set border styles. */
10
+ border?: string;
11
+ /** Set padding styles. */
12
+ padding?: string;
13
+ /** Set shadow styles. */
14
+ shadow?: string;
15
+ /** Provide arbitrary CSS classes. */
16
+ classes?: string;
17
+ }
18
+ export interface AppBarToolBarProps extends React.PropsWithChildren {
19
+ /** Sets the toolbar component's base styles. */
20
+ base?: string;
21
+ /** Sets the toolbar component's grid columns styles. */
22
+ gridCols?: string;
23
+ /** Sets the toolbar component's gap styles. */
24
+ gap?: string;
25
+ /** Provide arbitrary CSS classes to the toolbar component. */
26
+ classes?: string;
27
+ }
28
+ export interface AppBarLeadProps extends React.PropsWithChildren {
29
+ /** Sets the lead component's base styles. */
30
+ base?: string;
31
+ /** Sets the lead component's horizontal spacing styles. */
32
+ spaceX?: string;
33
+ /** Sets the lead component's padding styles. */
34
+ padding?: string;
35
+ /** Provide arbitrary CSS classes to the lead component. */
36
+ classes?: string;
37
+ }
38
+ export interface AppBarCenterProps extends React.PropsWithChildren {
39
+ /** Sets the center component's base styles. */
40
+ base?: string;
41
+ /** Sets the center component's alignment styles. */
42
+ align?: string;
43
+ /** Sets the center component's padding styles. */
44
+ padding?: string;
45
+ /** Provide arbitrary CSS classes to the center component. */
46
+ classes?: string;
47
+ }
48
+ export interface AppBarTrailProps extends React.PropsWithChildren {
49
+ /** Sets the trail component's base styles. */
50
+ base?: string;
51
+ /** Sets the trail component's horizontal spacing styles. */
52
+ spaceX?: string;
53
+ /** Sets the trail component's padding styles. */
54
+ padding?: string;
55
+ /** Provide arbitrary CSS classes to the trail component. */
56
+ classes?: string;
57
+ }
58
+ export interface AppBarHeadlineProps extends React.PropsWithChildren {
59
+ /** Sets the headline component's base styles. */
60
+ base?: string;
61
+ /** Provide arbitrary CSS classes to the headline component. */
62
+ classes?: string;
63
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { AvatarProps } from "./types.js";
3
+ export declare const Avatar: React.FC<AvatarProps>;
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export const Avatar = ({ src = "", alt = "", filter = "",
4
+ // Root
5
+ base = "overflow-hidden isolate", background = "bg-surface-400-600", size = "size-16", font = "", border = "", rounded = "rounded-full", shadow = "", classes = "",
6
+ // Image
7
+ imageBase = "w-full object-cover", imageClasses = "",
8
+ // Children
9
+ children, }) => {
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
+ };
@@ -0,0 +1,29 @@
1
+ /// <reference types="react" />
2
+ export interface AvatarProps extends React.PropsWithChildren {
3
+ /** Set avatar image source URL. */
4
+ src?: string;
5
+ /** Set avatar image Alt text. */
6
+ alt?: string;
7
+ /** Set avatar image filter name. such as "#Apollo". */
8
+ filter?: string;
9
+ /** Set base styles. */
10
+ base?: string;
11
+ /** Set background styles. */
12
+ background?: string;
13
+ /** Set size styles. */
14
+ size?: string;
15
+ /** Set font styles. */
16
+ font?: string;
17
+ /** Set border styles. */
18
+ border?: string;
19
+ /** Set border radius styles. */
20
+ rounded?: string;
21
+ /** Set shadow styles. */
22
+ shadow?: string;
23
+ /** Provide arbitrary CSS classes. */
24
+ classes?: string;
25
+ /** Set avatar image base styles. */
26
+ imageBase?: string;
27
+ /** Provide avatar image arbitrary CSS classes. */
28
+ imageClasses?: string;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type FC } from "react";
2
+ import { ProgressProps } from "./types.js";
3
+ export declare const Progress: FC<ProgressProps>;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect } from "react";
3
+ export const Progress = ({ value, max = 100, labelledBy = "",
4
+ // Root
5
+ base = "overflow-x-hidden", bg = "bg-surface-200-800", width = "w-full", height = "h-2", rounded = "rounded", classes = "",
6
+ // Meter
7
+ meterBase = "h-full", meterBg = "bg-surface-950-50", meterRounded = "rounded", meterTransition = "transition-[width]", meterAnimate = "animate-indeterminate", meterClasses = "", }) => {
8
+ useEffect(() => {
9
+ if (max < 0) {
10
+ console.warn("The max prop should be greater than or equal to 0");
11
+ }
12
+ });
13
+ const indeterminate = value === undefined;
14
+ const fillPercentage = `${indeterminate ? 50 : ((value - 0) / (max - 0)) * 100}%`;
15
+ const rxIndeterminate = indeterminate ? meterAnimate : "";
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
+ };
@@ -0,0 +1,32 @@
1
+ export interface ProgressProps {
2
+ /** Set the value */
3
+ value?: number;
4
+ /** Set the maximum value */
5
+ max?: number;
6
+ /** Set the aria-labelledby */
7
+ labelledBy?: string;
8
+ /** Set root base classes */
9
+ base?: string;
10
+ /** Set root background classes */
11
+ bg?: string;
12
+ /** Set root width classes */
13
+ width?: string;
14
+ /** Set root height classes */
15
+ height?: string;
16
+ /** Set root rounded classes */
17
+ rounded?: string;
18
+ /** Set root arbitrary classes */
19
+ classes?: string;
20
+ /** Set meter base classes. */
21
+ meterBase?: string;
22
+ /** Set meter bg classes */
23
+ meterBg?: string;
24
+ /** Set meter rounded classes. */
25
+ meterRounded?: string;
26
+ /** Set meter transition classes. */
27
+ meterTransition?: string;
28
+ /** Set meter animation classes for indeterminate mode. */
29
+ meterAnimate?: string;
30
+ /** Set meter arbitrary classes. */
31
+ meterClasses?: string;
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { TabsProps, TabsListProps, TabsControlProps, TabsControlItemProps, TabsPanelItemProps } from "./types.js";
3
+ export declare const Tabs: React.FC<TabsProps> & {
4
+ List: React.FC<TabsListProps>;
5
+ Control: React.FC<TabsControlProps>;
6
+ Panel: React.FC<TabsPanelItemProps>;
7
+ Item: React.FC<TabsControlItemProps>;
8
+ };
@@ -0,0 +1,121 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ // Components ---
4
+ const TabsRoot = ({ id = "",
5
+ // Root
6
+ base = "w-full", spaceY = "space-y-4", classes = "",
7
+ // Children
8
+ children, }) => {
9
+ return (_jsx("div", { id: id, className: `${base} ${spaceY} ${classes}`, "data-testid": "tabs", children: children }));
10
+ };
11
+ const TabsList = ({
12
+ // Root
13
+ base = "flex", justify = "justify-start", gap = "gap-2", border = "border-b-[1px] border-surface-200-800", classes = "",
14
+ // Children
15
+ children, }) => {
16
+ return (_jsx("div", { className: `${base} ${gap} ${justify} ${border} ${classes}`, role: "tablist", children: children }));
17
+ };
18
+ const TabsControl = ({ id = "", name, group, title = "",
19
+ // A11y
20
+ label = "", controls = "",
21
+ // Root
22
+ base = "group", width = "", active = "text-surface-950-50 border-surface-950-50", inactive = "text-surface-600-400 border-transparent", flex = "flex justify-center items-center", background = "", border = "border-b-[1px]", text = "type-scale-3", padding = "pb-2", rounded = "", gap = "gap-1", cursor = "cursor-pointer", classes = "",
23
+ // Events
24
+ onClick = () => { }, onKeydown = () => { }, onKeyup = () => { }, onChange = () => { },
25
+ // Children
26
+ children, }) => {
27
+ const [selected, setSelected] = useState(group === name);
28
+ useEffect(() => {
29
+ setSelected(group === name);
30
+ }, [group, name]);
31
+ const [rxActive, setRxActive] = useState(selected ? active : inactive);
32
+ useEffect(() => {
33
+ setRxActive(selected ? active : inactive);
34
+ }, [selected, active, inactive]);
35
+ function handleOnChange(event) {
36
+ onChange(event.target.value);
37
+ }
38
+ const elemInputRef = useRef(null);
39
+ function onKeyDownHandler(event) {
40
+ // Fire Event Handler
41
+ onKeydown(event);
42
+ // If select key events
43
+ if (!["ArrowRight", "ArrowLeft", "Home", "End"].includes(event.code))
44
+ return;
45
+ const elemInput = elemInputRef.current;
46
+ if (!elemInput)
47
+ return;
48
+ // Prevent default behavior
49
+ event.preventDefault();
50
+ // Find the closest tab/tablelist
51
+ const currTab = elemInput.closest('[role="tab"]');
52
+ if (!currTab)
53
+ return;
54
+ const tabList = elemInput.closest('[role="tablist"]');
55
+ if (!tabList)
56
+ return;
57
+ // Get RTL mode
58
+ const isRTL = getComputedStyle(tabList).direction === "rtl";
59
+ // Get list of tab elements
60
+ const tabs = Array.from(tabList.querySelectorAll('[role="tab"]'));
61
+ // Get a reference to the current tab
62
+ const currIndex = tabs.indexOf(currTab);
63
+ // Determine the index of the next tab
64
+ let nextIndex = -1;
65
+ switch (event.code) {
66
+ case "ArrowRight":
67
+ if (isRTL) {
68
+ nextIndex = currIndex - 1 < 0 ? tabs.length - 1 : currIndex - 1;
69
+ break;
70
+ }
71
+ nextIndex = currIndex + 1 >= tabs.length ? 0 : currIndex + 1;
72
+ break;
73
+ case "ArrowLeft":
74
+ if (isRTL) {
75
+ nextIndex = currIndex + 1 >= tabs.length ? 0 : currIndex + 1;
76
+ break;
77
+ }
78
+ nextIndex = currIndex - 1 < 0 ? tabs.length - 1 : currIndex - 1;
79
+ break;
80
+ case "Home":
81
+ nextIndex = 0;
82
+ break;
83
+ case "End":
84
+ nextIndex = tabs.length - 1;
85
+ break;
86
+ }
87
+ if (nextIndex < 0)
88
+ return;
89
+ // Set Active Tab
90
+ const nextTab = tabs[nextIndex];
91
+ const nextTabInput = nextTab?.querySelector("input");
92
+ if (nextTabInput) {
93
+ nextTabInput.click();
94
+ nextTab.focus();
95
+ }
96
+ }
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] }) }));
98
+ };
99
+ const TabsControlItem = ({
100
+ // Root
101
+ base = "w-full", flex = "flex justify-center items-center", gap = "gap-2", background = "group-hover:preset-tonal-primary", padding = "p-2 px-4", rounded = "rounded-container", classes = "",
102
+ // Children
103
+ children, }) => {
104
+ return (_jsx("div", { className: `${base} ${flex} ${gap} ${background} ${padding} ${rounded} ${classes}`, children: children }));
105
+ };
106
+ const TabsPanelItem = ({ id = "", value, group,
107
+ // A11y
108
+ labelledBy,
109
+ // Root
110
+ classes = "",
111
+ // Children
112
+ children, }) => {
113
+ return (value === group &&
114
+ children && (_jsx("div", { id: id, role: "tabpanel", tabIndex: 0, "aria-labelledby": labelledBy, className: classes, children: children })));
115
+ };
116
+ export const Tabs = Object.assign(TabsRoot, {
117
+ List: TabsList,
118
+ Control: TabsControl,
119
+ Panel: TabsPanelItem,
120
+ Item: TabsControlItem,
121
+ });
@@ -0,0 +1,99 @@
1
+ import React from "react";
2
+ export interface TabsProps extends React.PropsWithChildren {
3
+ /** Provide a unique ID. */
4
+ id?: string;
5
+ /** Sets base styles. */
6
+ base?: string;
7
+ /** Set vertical spacing between list and panels. */
8
+ spaceY?: string;
9
+ /** Provide arbitrary CSS classes. */
10
+ classes?: string;
11
+ }
12
+ export interface TabsListProps extends React.PropsWithChildren {
13
+ /** Sets the base styles. */
14
+ base?: string;
15
+ /** Sets the justification styles. */
16
+ justify?: string;
17
+ /** Sets the gap spacing. */
18
+ gap?: string;
19
+ /** Sets the border styles. */
20
+ border?: string;
21
+ /** Provide arbitrary CSS classes. */
22
+ classes?: string;
23
+ }
24
+ export interface TabsControlProps extends React.PropsWithChildren {
25
+ /** Provide a unique ID. */
26
+ id?: string;
27
+ /** Provide the tab control name. */
28
+ name: string;
29
+ /** Provide the tab control radio group. */
30
+ group: string;
31
+ /** Provide a hoverable title attribute. */
32
+ title?: string;
33
+ /** Sets the A11y label. */
34
+ label?: string;
35
+ /** Sets ARIA controls value to define which panel this tab controls. */
36
+ controls?: string;
37
+ /** Sets base styles. */
38
+ base?: string;
39
+ /** Sets width styles. */
40
+ width?: string;
41
+ /** Sets the active control styles. */
42
+ active?: string;
43
+ /** Sets the inactive control styles. */
44
+ inactive?: string;
45
+ /** Sets flex styles. */
46
+ flex?: string;
47
+ /** Sets background styles. */
48
+ background?: string;
49
+ /** Sets border styles. */
50
+ border?: string;
51
+ /** Sets text size styles. */
52
+ text?: string;
53
+ /** Sets padding styles. */
54
+ padding?: string;
55
+ /** Sets rounded styles. */
56
+ rounded?: string;
57
+ /** Sets vertical gap styles. */
58
+ gap?: string;
59
+ /** Sets cursor styles. */
60
+ cursor?: string;
61
+ /** Provide arbitrary CSS classes. */
62
+ classes?: string;
63
+ /** Triggers on Tab Control click. */
64
+ onClick?: (event: React.MouseEvent<HTMLInputElement>) => void;
65
+ /** Triggers on Tab Control key down. */
66
+ onKeydown?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
67
+ /** Triggers on Tab Control key up. */
68
+ onKeyup?: (event: React.KeyboardEvent<HTMLDivElement>) => void;
69
+ /** Triggers on Tab Control group change. */
70
+ onChange?: (group: string) => void;
71
+ }
72
+ export interface TabsControlItemProps extends React.PropsWithChildren {
73
+ /** Sets base styles. */
74
+ base?: string;
75
+ /** Sets flex styles. */
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. */
86
+ classes?: string;
87
+ }
88
+ export interface TabsPanelItemProps extends React.PropsWithChildren {
89
+ /** Provide a unique ID. */
90
+ id?: string;
91
+ /** Provide the tab panel value. */
92
+ value: string;
93
+ /** Provide the tab control radio group. */
94
+ group: string;
95
+ /** Sets the A11y labelledby. */
96
+ labelledBy?: string;
97
+ /** Provide arbitrary CSS classes. */
98
+ classes?: string;
99
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare function Test(): import("react/jsx-runtime").JSX.Element;
2
+ export default Test;
@@ -0,0 +1,10 @@
1
+ import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ function Test() {
4
+ const [count, setCount] = useState(0);
5
+ function countUp() {
6
+ setCount((count) => count + 1);
7
+ }
8
+ return (_jsx(_Fragment, { children: _jsxs("button", { className: "btn preset-filled", onClick: countUp, children: ["Count is ", count] }) }));
9
+ }
10
+ export default Test;
@@ -0,0 +1,6 @@
1
+ export { default as TestReact } from "./components/Test/Test.js";
2
+ export { Accordion } from "./components/Accordion/Accordion.js";
3
+ export { Avatar } from "./components/Avatar/Avatar.js";
4
+ export { AppBar, ToolBar } from "./components/AppBar/AppBar.js";
5
+ export { Progress } from "./components/Progress/Progress.js";
6
+ export { Tabs } from "./components/Tabs/Tabs.js";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { default as TestReact } from "./components/Test/Test.js";
2
+ // Components
3
+ export { Accordion } from "./components/Accordion/Accordion.js";
4
+ export { Avatar } from "./components/Avatar/Avatar.js";
5
+ export { AppBar, ToolBar } from "./components/AppBar/AppBar.js";
6
+ export { Progress } from "./components/Progress/Progress.js";
7
+ export { Tabs } from "./components/Tabs/Tabs.js";
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare function reactCompose<T extends React.FC<any>, U extends Record<string, unknown>>(root: T, components: {
3
+ [k in keyof U]: React.FC<U[k]>;
4
+ }): T & { [k in keyof U]: import("react").FC<U[k]>; };
@@ -0,0 +1,3 @@
1
+ export function reactCompose(root, components) {
2
+ return Object.assign(root, components);
3
+ }
package/package.json CHANGED
@@ -1,16 +1,74 @@
1
1
  {
2
2
  "name": "@skeletonlabs/skeleton-react",
3
- "version": "0.0.0",
4
- "private": false,
5
- "description": "",
6
- "main": "index.js",
7
- "keywords": [],
8
- "author": "",
9
- "license": "MIT",
10
- "publishConfig": {
11
- "access": "public"
3
+ "version": "1.0.0-next.0",
4
+ "type": "module",
5
+ "types": "./dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "./dist/**/*.js",
14
+ "./dist/**/*.map",
15
+ "./dist/**/*.d.ts",
16
+ "./dist/**/*.cjs",
17
+ "./dist/**/*.d.cts",
18
+ "!./dist/**/*.test.*",
19
+ "!./dist/**/schema.json",
20
+ "!./dist/schemas.js",
21
+ "!./dist/schemas.d.ts"
22
+ ],
23
+ "dependencies": {
24
+ "react": "^18.2.0",
25
+ "react-dom": "^18.2.0"
26
+ },
27
+ "devDependencies": {
28
+ "@tailwindcss/forms": "^0.5.7",
29
+ "@testing-library/jest-dom": "^6.4.2",
30
+ "@testing-library/react": "^14.2.2",
31
+ "@testing-library/user-event": "^14.5.2",
32
+ "@types/react": "^18.2.74",
33
+ "@types/react-dom": "^18.2.24",
34
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
35
+ "@typescript-eslint/parser": "^6.21.0",
36
+ "@vitejs/plugin-react": "^4.2.1",
37
+ "autoprefixer": "^10.4.19",
38
+ "eslint": "^8.57.0",
39
+ "eslint-plugin-react-hooks": "^4.6.0",
40
+ "eslint-plugin-react-refresh": "^0.4.6",
41
+ "jsdom": "^24.0.0",
42
+ "postcss": "^8.4.38",
43
+ "react-router-dom": "^6.22.3",
44
+ "tailwindcss": "^3.4.3",
45
+ "typescript": "^5.4.4",
46
+ "typescript-json-schema": "^0.63.0",
47
+ "vite": "^5.2.8",
48
+ "vite-plugin-remix-router": "^2.0.0",
49
+ "vitest": "^1.4.0",
50
+ "@skeletonlabs/skeleton": "3.0.0-next.0",
51
+ "vite-plugin-tw-plugin-watcher": "0.0.0"
52
+ },
53
+ "peerDependencies": {
54
+ "framer-motion": "^11.0.24"
12
55
  },
13
56
  "scripts": {
14
- "test": "echo \"Error: no test specified\" && exit 1"
57
+ "dev": "vite",
58
+ "build": "vite build",
59
+ "package": "tsc --project tsconfig.package.json",
60
+ "package:watch": "tsc --project tsconfig.package.json --watch --preserveWatchOutput",
61
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
62
+ "preview": "vite preview",
63
+ "test": "vitest run",
64
+ "test:watch": "vitest",
65
+ "schema": "node ./scripts/generator.js"
66
+ },
67
+ "typesVersions": {
68
+ ">4.0": {
69
+ "index.d.ts": [
70
+ "./dist/index.d.ts"
71
+ ]
72
+ }
15
73
  }
16
74
  }