@momoi-labs/kiso-react 0.15.0 → 0.16.1
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/alert-dialog.d.ts +1 -1
- package/dist/alert-dialog.js +7 -2
- package/dist/app-shell.d.ts +12 -0
- package/dist/app-shell.js +48 -5
- package/dist/bottom-nav.d.ts +8 -0
- package/dist/bottom-nav.js +18 -0
- package/dist/chart.js +1 -1
- package/dist/chip-input.js +7 -1
- package/dist/code-editor.d.ts +12 -0
- package/dist/code-editor.js +40 -0
- package/dist/command-palette.js +16 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lifecycle.d.ts +3 -1
- package/dist/lifecycle.js +24 -3
- package/dist/pane-grid.js +10 -4
- package/dist/styles.css +13 -1
- package/dist/tabs.d.ts +10 -1
- package/dist/tabs.js +66 -3
- package/package.json +2 -2
package/dist/alert-dialog.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Button } from "./button.js";
|
|
|
4
4
|
declare function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Root>): React.JSX.Element;
|
|
5
5
|
declare function AlertDialogTrigger({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>): React.JSX.Element;
|
|
6
6
|
declare function AlertDialogPortal({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>): React.JSX.Element;
|
|
7
|
-
declare function AlertDialogOverlay({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>): React.JSX.Element;
|
|
7
|
+
declare function AlertDialogOverlay({ className, onMouseDown, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>): React.JSX.Element;
|
|
8
8
|
declare function AlertDialogContent({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Content>): React.JSX.Element;
|
|
9
9
|
declare function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
10
10
|
declare function AlertDialogFooter({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
package/dist/alert-dialog.js
CHANGED
|
@@ -13,8 +13,13 @@ function AlertDialogTrigger({ ...props }) {
|
|
|
13
13
|
function AlertDialogPortal({ ...props }) {
|
|
14
14
|
return (_jsx(AlertDialogPrimitive.Portal, { "data-slot": "alert-dialog-portal", ...props }));
|
|
15
15
|
}
|
|
16
|
-
function AlertDialogOverlay({ className, ...props }) {
|
|
17
|
-
return (_jsx(AlertDialogPrimitive.Overlay, { "data-slot": "alert-dialog-overlay",
|
|
16
|
+
function AlertDialogOverlay({ className, onMouseDown, ...props }) {
|
|
17
|
+
return (_jsx(AlertDialogPrimitive.Overlay, { "data-slot": "alert-dialog-overlay",
|
|
18
|
+
// The dialog stays open on a backdrop tap, so focus must stay in it.
|
|
19
|
+
onMouseDown: (event) => {
|
|
20
|
+
onMouseDown?.(event);
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
}, className: cn("kiso-react-overlay", className), ...props }));
|
|
18
23
|
}
|
|
19
24
|
function AlertDialogContent({ className, ...props }) {
|
|
20
25
|
return (_jsxs(AlertDialogPortal, { children: [_jsx(AlertDialogOverlay, {}), _jsx(AlertDialogPrimitive.Content, { "aria-modal": "true", "data-slot": "alert-dialog-content", className: cn("kiso-react-dialog marked", className), ...props })] }));
|
package/dist/app-shell.d.ts
CHANGED
|
@@ -42,9 +42,19 @@ type ApplicationShellSidebarProps = ApplicationShellSharedProps & {
|
|
|
42
42
|
collapsed?: boolean;
|
|
43
43
|
defaultCollapsed?: boolean;
|
|
44
44
|
onCollapsedChange?: (collapsed: boolean) => void;
|
|
45
|
+
/** Below 1024px the sidebar opens as a drawer. Control it to close the
|
|
46
|
+
* drawer from a destination it cannot see, such as a menu in a portal. */
|
|
47
|
+
drawerOpen?: boolean;
|
|
48
|
+
onDrawerOpenChange?: (open: boolean) => void;
|
|
49
|
+
/** Below 700px, "bottom" moves the destinations to a BottomNav. */
|
|
50
|
+
phoneNavigation?: "drawer" | "bottom";
|
|
51
|
+
bottomNav?: never;
|
|
45
52
|
};
|
|
46
53
|
type ApplicationShellTopbarProps = ApplicationShellSharedProps & {
|
|
47
54
|
layout: "topbar";
|
|
55
|
+
/** A BottomNav for phones, below 700px. */
|
|
56
|
+
bottomNav?: React.ReactNode;
|
|
57
|
+
phoneNavigation?: never;
|
|
48
58
|
navigation?: never;
|
|
49
59
|
navigationLabel?: never;
|
|
50
60
|
footer?: never;
|
|
@@ -53,6 +63,8 @@ type ApplicationShellTopbarProps = ApplicationShellSharedProps & {
|
|
|
53
63
|
collapsed?: never;
|
|
54
64
|
defaultCollapsed?: never;
|
|
55
65
|
onCollapsedChange?: never;
|
|
66
|
+
drawerOpen?: never;
|
|
67
|
+
onDrawerOpenChange?: never;
|
|
56
68
|
};
|
|
57
69
|
type ApplicationShellProps = ApplicationShellSidebarProps | ApplicationShellTopbarProps;
|
|
58
70
|
declare function ApplicationShell(props: ApplicationShellProps): React.JSX.Element;
|
package/dist/app-shell.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { clsx as cn } from "clsx";
|
|
6
|
-
import { PanelLeftClose, PanelLeftOpen, PanelRight } from "lucide-react";
|
|
6
|
+
import { Ellipsis, Menu, PanelLeftClose, PanelLeftOpen, PanelRight } from "lucide-react";
|
|
7
|
+
import { Drawer, DrawerBody, DrawerContent, DrawerHeader, DrawerTitle } from "./drawer.js";
|
|
8
|
+
import { VisuallyHidden } from "radix-ui";
|
|
9
|
+
import { BottomNav, BottomNavBadge, BottomNavLink } from "./bottom-nav.js";
|
|
7
10
|
import { Button } from "./button.js";
|
|
8
11
|
import { Header } from "./header.js";
|
|
9
12
|
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
@@ -33,13 +36,23 @@ function ApplicationShellNavigation({ navigation, navigationLabel, collapsible =
|
|
|
33
36
|
}
|
|
34
37
|
function ApplicationShell(props) {
|
|
35
38
|
if (props.layout === "topbar") {
|
|
36
|
-
const { brand, primaryAction, header, headerVariant, panel, children, layout: _layout, ...shellProps } = props;
|
|
37
|
-
return (_jsxs(AppShell, { ...shellProps, "data-layout": "topbar", children: [_jsxs(AppShellMain, { children: [_jsxs(Header, { variant: headerVariant, children: [brand, primaryAction, header] }), children] }), panel] }));
|
|
39
|
+
const { brand, primaryAction, header, headerVariant, panel, bottomNav, children, layout: _layout, ...shellProps } = props;
|
|
40
|
+
return (_jsxs(AppShell, { ...shellProps, "data-layout": "topbar", children: [_jsxs(AppShellMain, { children: [_jsxs(Header, { variant: headerVariant, children: [brand, primaryAction, header] }), children] }), panel, bottomNav] }));
|
|
38
41
|
}
|
|
39
42
|
return _jsx(ApplicationShellSidebar, { ...props });
|
|
40
43
|
}
|
|
41
|
-
function ApplicationShellSidebar({ brand, primaryAction, navigation, navigationLabel = "Primary", footer, header, headerVariant, panel, children, layout: _layout, collapsible = false, togglePlacement = "sidebar", collapsed, defaultCollapsed = false, onCollapsedChange, ...shellProps }) {
|
|
44
|
+
function ApplicationShellSidebar({ brand, primaryAction, navigation, navigationLabel = "Primary", footer, header, headerVariant, panel, children, layout: _layout, collapsible = false, togglePlacement = "sidebar", collapsed, defaultCollapsed = false, onCollapsedChange, drawerOpen: controlledDrawer, onDrawerOpenChange, phoneNavigation = "drawer", ...shellProps }) {
|
|
42
45
|
const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed);
|
|
46
|
+
// Below 1024px the sidebar is not in the page; the same brand, action,
|
|
47
|
+
// navigation and footer open in a drawer from the header instead.
|
|
48
|
+
const [innerDrawer, setInnerDrawer] = React.useState(false);
|
|
49
|
+
const drawerOpen = controlledDrawer ?? innerDrawer;
|
|
50
|
+
const setDrawerOpen = (open) => {
|
|
51
|
+
if (controlledDrawer === undefined)
|
|
52
|
+
setInnerDrawer(open);
|
|
53
|
+
onDrawerOpenChange?.(open);
|
|
54
|
+
};
|
|
55
|
+
const menuRef = React.useRef(null);
|
|
43
56
|
const isCollapsed = collapsible && (collapsed ?? internalCollapsed);
|
|
44
57
|
const sidebarId = React.useId();
|
|
45
58
|
const sidebarRef = React.useRef(null);
|
|
@@ -58,6 +71,36 @@ function ApplicationShellSidebar({ brand, primaryAction, navigation, navigationL
|
|
|
58
71
|
onCollapsedChange?.(next);
|
|
59
72
|
}
|
|
60
73
|
const toggle = collapsible ? (_jsx(Button, { ref: toggleRef, variant: "ghost", size: "sm", className: "sidebar-toggle btn-icon", "aria-controls": sidebarId, "aria-expanded": !isCollapsed, "aria-label": isCollapsed ? "Expand sidebar" : "Collapse sidebar", title: isCollapsed ? "Expand sidebar" : "Collapse sidebar", onClick: toggleSidebar, children: isCollapsed ? _jsx(PanelLeftOpen, { className: "icon", "aria-hidden": "true" }) : _jsx(PanelLeftClose, { className: "icon", "aria-hidden": "true" }) })) : null;
|
|
61
|
-
|
|
74
|
+
const menu = (_jsx(Button, { ref: menuRef, variant: "ghost", size: "sm", className: "app-shell-menu btn-icon", "aria-expanded": drawerOpen, "aria-label": "Open navigation", title: "Navigation", onClick: () => setDrawerOpen(true), children: _jsx(Menu, { className: "icon", "aria-hidden": "true" }) }));
|
|
75
|
+
return (_jsxs(AppShell, { ...shellProps, "data-phone-drawer": "true", "data-phone-navigation": phoneNavigation, children: [_jsxs(Sidebar, { ref: sidebarRef, id: sidebarId, collapsed: isCollapsed, children: [_jsx(SidebarHeader, { className: collapsible && togglePlacement === "sidebar" ? "sidebar-header-collapsible" : undefined, children: collapsible ? _jsxs(_Fragment, { children: [_jsxs("div", { className: "sidebar-expanded-content", children: [brand, primaryAction] }), togglePlacement === "sidebar" && toggle] }) : _jsxs(_Fragment, { children: [brand, primaryAction] }) }), _jsx(SidebarBody, { children: _jsx(ApplicationShellNavigation, { navigation: navigation, navigationLabel: navigationLabel, collapsible: collapsible }) }), footer && _jsx(SidebarFooter, { className: collapsible ? "sidebar-expanded-content" : undefined, children: footer })] }), _jsxs(AppShellMain, { children: [_jsxs(Header, { variant: headerVariant, "data-phone-only": header || (collapsible && togglePlacement === "header") ? undefined : "true", children: [menu, phoneNavigation === "bottom" && _jsx("div", { className: "app-shell-phone-brand", children: brand }), phoneNavigation === "bottom" && primaryAction && _jsx("div", { className: "app-shell-phone-action", children: primaryAction }), togglePlacement === "header" && toggle, header] }), children] }), panel, _jsx(Drawer, { open: drawerOpen, onOpenChange: setDrawerOpen, children: _jsxs(DrawerContent, { placement: "side", className: "app-shell-drawer", onCloseAutoFocus: (event) => {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
menuRef.current?.focus();
|
|
78
|
+
}, children: [_jsxs(DrawerHeader, { children: [_jsx(VisuallyHidden.Root, { asChild: true, children: _jsx(DrawerTitle, { children: "Navigation" }) }), brand] }), _jsxs(DrawerBody, { onClick: (event) => {
|
|
79
|
+
// A destination, or anything the product marks as one, leaves
|
|
80
|
+
// the drawer: the page it opens is the point.
|
|
81
|
+
if (event.target.closest("a[href], [data-slot='navigation-link'], [data-shell-navigate]"))
|
|
82
|
+
setDrawerOpen(false);
|
|
83
|
+
}, children: [primaryAction, _jsx(ApplicationShellNavigation, { navigation: navigation, navigationLabel: navigationLabel, collapsible: false }), footer && _jsx("div", { className: "app-shell-drawer-footer", children: footer })] })] }) }), phoneNavigation === "bottom" && _jsx(ApplicationShellBottomNav, { navigation: navigation, navigationLabel: navigationLabel, footer: footer })] }));
|
|
84
|
+
}
|
|
85
|
+
/* The bar holds five destinations at most. With more, the first four stay in
|
|
86
|
+
the bar and the rest, with the footer, open from More in a bottom sheet. */
|
|
87
|
+
function ApplicationShellBottomNav({ navigation, navigationLabel, footer }) {
|
|
88
|
+
const [moreOpen, setMoreOpen] = React.useState(false);
|
|
89
|
+
const destinations = navigation.flatMap(group => group.destinations);
|
|
90
|
+
const overflow = destinations.length > 5;
|
|
91
|
+
const inBar = overflow ? destinations.slice(0, 4) : destinations;
|
|
92
|
+
const rest = navigation
|
|
93
|
+
.map(group => ({ ...group, destinations: group.destinations.filter(destination => !inBar.includes(destination)) }))
|
|
94
|
+
.filter(group => group.destinations.length > 0);
|
|
95
|
+
const link = (destination, index) => (_jsxs(BottomNavLink, { href: destination.href, active: destination.active, onClick: (event) => {
|
|
96
|
+
if (!destination.onClick)
|
|
97
|
+
return;
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
destination.onClick();
|
|
100
|
+
}, children: [destination.leading && _jsx("span", { className: "bottom-nav-icon", "aria-hidden": "true", children: destination.leading }), _jsx("span", { children: destination.label }), (typeof destination.trailing === "string" || typeof destination.trailing === "number") && _jsx(BottomNavBadge, { children: destination.trailing })] }, `${destination.href}-${index}`));
|
|
101
|
+
return _jsxs(_Fragment, { children: [_jsxs(BottomNav, { "aria-label": navigationLabel, children: [inBar.map(link), overflow && _jsx(BottomNavLink, { asChild: true, active: rest.some(group => group.destinations.some(destination => destination.active)), children: _jsxs("button", { type: "button", "aria-haspopup": "dialog", "aria-expanded": moreOpen, onClick: () => setMoreOpen(true), children: [_jsx("span", { className: "bottom-nav-icon", "aria-hidden": "true", children: _jsx(Ellipsis, { className: "icon" }) }), _jsx("span", { children: "More" })] }) })] }), overflow && _jsx(Drawer, { open: moreOpen, onOpenChange: setMoreOpen, children: _jsxs(DrawerContent, { placement: "bottom", className: "app-shell-drawer app-shell-more", children: [_jsx(DrawerHeader, { children: _jsx(DrawerTitle, { children: "More" }) }), _jsxs(DrawerBody, { onClick: (event) => {
|
|
102
|
+
if (event.target.closest("a[href], [data-slot='navigation-link'], [data-shell-navigate]"))
|
|
103
|
+
setMoreOpen(false);
|
|
104
|
+
}, children: [_jsx(ApplicationShellNavigation, { navigation: rest, navigationLabel: `${navigationLabel}, more` }), footer && _jsx("div", { className: "app-shell-drawer-footer", children: footer })] })] }) })] });
|
|
62
105
|
}
|
|
63
106
|
export { AppShell, AppShellMain, AppShellPanel, AppShellPanelToggle, ApplicationShell };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare function BottomNav({ className, children, ...props }: React.ComponentProps<"nav">): React.JSX.Element;
|
|
3
|
+
declare function BottomNavLink({ className, active, asChild, ...props }: React.ComponentProps<"a"> & {
|
|
4
|
+
active?: boolean;
|
|
5
|
+
asChild?: boolean;
|
|
6
|
+
}): React.JSX.Element;
|
|
7
|
+
declare function BottomNavBadge({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
|
|
8
|
+
export { BottomNav, BottomNavLink, BottomNavBadge };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { clsx as cn } from "clsx";
|
|
3
|
+
import { Slot } from "radix-ui";
|
|
4
|
+
// A phone's main navigation, fixed to the bottom edge below 700px and not
|
|
5
|
+
// rendered above it. The product keeps the same destinations in its header or
|
|
6
|
+
// sidebar for wider screens, decides which one is current, and passes
|
|
7
|
+
// `asChild` to keep a router's own link component.
|
|
8
|
+
function BottomNav({ className, children, ...props }) {
|
|
9
|
+
return (_jsx("nav", { "data-slot": "bottom-nav", className: cn("bottom-nav", className), ...props, children: _jsx("ul", { className: "bottom-nav-list", children: children }) }));
|
|
10
|
+
}
|
|
11
|
+
function BottomNavLink({ className, active = false, asChild = false, ...props }) {
|
|
12
|
+
const Comp = asChild ? Slot.Root : "a";
|
|
13
|
+
return (_jsx("li", { "data-slot": "bottom-nav-item", children: _jsx(Comp, { "data-slot": "bottom-nav-link", "aria-current": active ? "page" : undefined, className: cn("bottom-nav-link", className), ...props }) }));
|
|
14
|
+
}
|
|
15
|
+
function BottomNavBadge({ className, ...props }) {
|
|
16
|
+
return _jsx("span", { "data-slot": "bottom-nav-badge", className: cn("bottom-nav-badge", className), ...props });
|
|
17
|
+
}
|
|
18
|
+
export { BottomNav, BottomNavLink, BottomNavBadge };
|
package/dist/chart.js
CHANGED
|
@@ -47,7 +47,7 @@ export function Chart({ data, series, label, variant = "line", layout = "standar
|
|
|
47
47
|
else
|
|
48
48
|
splitMin -= Math.max(1, Math.abs(splitMin) * 0.1);
|
|
49
49
|
}
|
|
50
|
-
const renderPlot = (indices, lane) => _jsx("div", { className: "chart-plot", style: { height }, children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(ComposedChart, { data: plot, syncId: syncId ?? (layout === "split" ? id : undefined), syncMethod: "value", accessibilityLayer: true, "aria-label": lane ? `${label}: ${lane.label}` : label, "aria-describedby": `${id}-help`, margin: { top: 8, right:
|
|
50
|
+
const renderPlot = (indices, lane) => _jsx("div", { className: "chart-plot", style: { height }, children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(ComposedChart, { data: plot, syncId: syncId ?? (layout === "split" ? id : undefined), syncMethod: "value", accessibilityLayer: true, "aria-label": lane ? `${label}: ${lane.label}` : label, "aria-describedby": `${id}-help`, margin: { top: 8, right: 20, bottom: 0, left: 0 }, children: [_jsx("defs", { children: indices.map(index => _jsx(ChartPattern, { id: `${id}-halftone-${index}`, color: chartColor(chartSlot(series[index], index)) }, series[index].key)) }), _jsx(CartesianGrid, { vertical: false, stroke: "var(--color-border)", strokeWidth: 0.5 }), _jsx(XAxis, { dataKey: "timestamp", type: "number", domain: ["dataMin", "dataMax"], scale: "time", axisLine: false, tickLine: false, tickFormatter: formatTime, minTickGap: 48, tick: { fill: "var(--color-muted-foreground)" } }), _jsx(YAxis, { domain: layout === "split" ? [splitMin, splitMax]
|
|
51
51
|
: [min ?? (variant === "stacked-area" ? 0 : "auto"), max ?? "auto"], tickCount: 3, axisLine: false, tickLine: false, tickFormatter: formatValue, tick: { fill: "var(--color-muted-foreground)" }, width: 56 }), _jsx(Tooltip, { filterNull: false, isAnimationActive: false, cursor: { stroke: "var(--color-border-strong)", strokeDasharray: "3 3" }, content: ({ active, label: timestamp }) => _jsx(ChartReadout, { active: active, timestamp: Number(timestamp), data: data, series: series, formatTime: formatTime, displayValue: displayValue, sidebar: legend === "sidebar", onInspect: legend === "sidebar" && (!lane || indices[0] === 0) ? setActiveTimestamp : undefined }) }), indices.map(index => {
|
|
52
52
|
const item = series[index];
|
|
53
53
|
const slot = chartSlot(item, index);
|
package/dist/chip-input.js
CHANGED
|
@@ -114,6 +114,11 @@ function ChipInputList({ className, "aria-label": ariaLabel = "Suggestions", ...
|
|
|
114
114
|
setOpen(true);
|
|
115
115
|
return () => setOpen(false);
|
|
116
116
|
}, [setOpen]);
|
|
117
|
+
// Near the bottom of a phone screen the list would open out of sight.
|
|
118
|
+
React.useEffect(() => {
|
|
119
|
+
if (open)
|
|
120
|
+
listRef.current?.scrollIntoView?.({ block: "nearest" });
|
|
121
|
+
}, [open, listRef]);
|
|
117
122
|
return (_jsx("div", { id: listId, ref: listRef, role: "listbox", hidden: !open, "aria-label": ariaLabel, "data-slot": "chip-input-list", className: cn("menu chip-input-list", className), ...props }));
|
|
118
123
|
}
|
|
119
124
|
function ChipInputOption({ className, disabled = false, onSelect, onClick, ...props }) {
|
|
@@ -168,7 +173,8 @@ function EditableSegment({ slot, className, value, placeholder, display, onCommi
|
|
|
168
173
|
}
|
|
169
174
|
if (draft !== null) {
|
|
170
175
|
return (_jsxs(_Fragment, { children: [_jsx("input", { ref: editorRef, "data-slot": `${slot}-input`, className: cn(className, "is-editing"), "aria-label": editLabel, value: draft, autoFocus: true, size: 1, style: {
|
|
171
|
-
|
|
176
|
+
// The segment's own padding comes on top of the text.
|
|
177
|
+
width: `calc(${Math.min(Math.max(draft.length + 1, 6), maxWidth)}ch + 2 * var(--spacing-sm))`,
|
|
172
178
|
}, onChange: (event) => setDraft(event.target.value), onBlur: () => commit(draft), onCompositionStart: () => { composing.current = true; }, onCompositionEnd: () => { composing.current = false; }, onKeyDown: (event) => {
|
|
173
179
|
event.stopPropagation();
|
|
174
180
|
if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from "react";
|
|
2
|
+
/** Paints a value. Return HTML as `{ __html }`, as from Prism; nothing leaves the text plain. */
|
|
3
|
+
export type CodeEditorHighlight = (code: string) => ReactNode | {
|
|
4
|
+
__html: string;
|
|
5
|
+
};
|
|
6
|
+
export type CodeEditorProps = Omit<ComponentProps<"textarea">, "children" | "value" | "defaultValue" | "wrap"> & {
|
|
7
|
+
value?: string;
|
|
8
|
+
defaultValue?: string;
|
|
9
|
+
highlight?: CodeEditorHighlight;
|
|
10
|
+
lineNumbers?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function CodeEditor({ className, value, defaultValue, highlight, lineNumbers, rows, disabled, onChange, onScroll, ref, ...props }: CodeEditorProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { clsx as cn } from "clsx";
|
|
5
|
+
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
6
|
+
function isHTML(painted) {
|
|
7
|
+
return typeof painted === "object" && painted !== null && "__html" in painted;
|
|
8
|
+
}
|
|
9
|
+
export function CodeEditor({ className, value, defaultValue = "", highlight, lineNumbers = true, rows = 5, disabled, onChange, onScroll, ref, ...props }) {
|
|
10
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
11
|
+
const code = value ?? uncontrolled;
|
|
12
|
+
const input = useRef(null);
|
|
13
|
+
const gutter = useRef(null);
|
|
14
|
+
const layer = useRef(null);
|
|
15
|
+
// A disabled value is plain text in the disabled color, like any field.
|
|
16
|
+
const painted = disabled ? undefined : highlight?.(code);
|
|
17
|
+
const highlighted = painted != null && painted !== false && painted !== "";
|
|
18
|
+
const lines = code.split("\n").length;
|
|
19
|
+
// Layers move with the textarea instead of scrolling, so they never clamp
|
|
20
|
+
// at a different extent than the textarea does.
|
|
21
|
+
function sync() {
|
|
22
|
+
const { scrollTop = 0, scrollLeft = 0 } = input.current ?? {};
|
|
23
|
+
if (gutter.current)
|
|
24
|
+
gutter.current.style.transform = `translateY(${-scrollTop}px)`;
|
|
25
|
+
if (layer.current)
|
|
26
|
+
layer.current.style.transform = `translate(${-scrollLeft}px, ${-scrollTop}px)`;
|
|
27
|
+
}
|
|
28
|
+
// A layer that mounts while the textarea is scrolled starts in step.
|
|
29
|
+
useIsomorphicLayoutEffect(sync);
|
|
30
|
+
return (_jsxs("div", { className: cn("field-control code-editor", className), "data-slot": "code-editor", "data-highlighted": highlighted, "data-line-numbers": lineNumbers, children: [lineNumbers && _jsx("div", { className: "code-editor-gutter", "aria-hidden": "true", style: { "--code-editor-digits": String(lines).length }, children: _jsx("div", { ref: gutter, children: Array.from({ length: lines }, (_, index) => _jsx("span", { children: index + 1 }, index)) }) }), _jsxs("div", { className: "code-editor-code", children: [highlighted && _jsx("div", { className: "code-editor-highlight", "aria-hidden": "true", children: isHTML(painted)
|
|
31
|
+
? _jsx("div", { ref: layer, dangerouslySetInnerHTML: painted })
|
|
32
|
+
: _jsx("div", { ref: layer, children: painted }) }), _jsx("textarea", { autoCapitalize: "off", autoComplete: "off", autoCorrect: "off", spellCheck: false, ...props, ref: (node) => {
|
|
33
|
+
input.current = node;
|
|
34
|
+
if (typeof ref === "function")
|
|
35
|
+
return ref(node);
|
|
36
|
+
if (ref)
|
|
37
|
+
ref.current = node;
|
|
38
|
+
}, className: "code-editor-input", rows: rows, wrap: "off", disabled: disabled, value: code, onChange: (event) => { if (value === undefined)
|
|
39
|
+
setUncontrolled(event.target.value); onChange?.(event); }, onScroll: (event) => { sync(); onScroll?.(event); } })] })] }));
|
|
40
|
+
}
|
package/dist/command-palette.js
CHANGED
|
@@ -24,7 +24,22 @@ function CommandPalette({ className, label = "Command palette", children, ...pro
|
|
|
24
24
|
const composing = React.useRef(false);
|
|
25
25
|
const listId = React.useId();
|
|
26
26
|
const listRef = React.useRef(null);
|
|
27
|
-
|
|
27
|
+
// A palette opened by a shortcut or a controlled button has no Radix
|
|
28
|
+
// trigger, so remember where focus was and return it there. The input
|
|
29
|
+
// takes focus as it mounts, so read it while rendering the open state.
|
|
30
|
+
const returnFocus = React.useRef(null);
|
|
31
|
+
const wasOpen = React.useRef(false);
|
|
32
|
+
if (props.open && !wasOpen.current && typeof document !== "undefined") {
|
|
33
|
+
returnFocus.current = document.activeElement;
|
|
34
|
+
}
|
|
35
|
+
wasOpen.current = Boolean(props.open);
|
|
36
|
+
return (_jsx(DialogPrimitive.Root, { "data-slot": "command-palette", ...props, children: _jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsxs(DialogPrimitive.Content, { "aria-modal": "true", onCloseAutoFocus: (event) => {
|
|
37
|
+
const target = returnFocus.current;
|
|
38
|
+
if (target?.isConnected && target !== document.body) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
target.focus();
|
|
41
|
+
}
|
|
42
|
+
}, onEscapeKeyDown: (event) => {
|
|
28
43
|
if (composing.current || event.isComposing || event.keyCode === 229)
|
|
29
44
|
event.preventDefault();
|
|
30
45
|
}, "data-slot": "command-palette-content", className: cn("palette kiso-react-palette", className), children: [_jsx(VisuallyHidden.Root, { asChild: true, children: _jsx(DialogPrimitive.Title, { children: label }) }), _jsx(CommandPaletteContext.Provider, { value: { composing, activeId, setActiveId, listId, listRef }, children: children })] })] }) }));
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ export * from "./alert.js";
|
|
|
2
2
|
export * from "./alert-dialog.js";
|
|
3
3
|
export * from "./app-shell.js";
|
|
4
4
|
export * from "./badge.js";
|
|
5
|
+
export * from "./bottom-nav.js";
|
|
5
6
|
export * from "./brand-mark.js";
|
|
6
7
|
export * from "./breadcrumb.js";
|
|
7
8
|
export * from "./button.js";
|
|
8
9
|
export * from "./card.js";
|
|
9
10
|
export * from "./checkbox.js";
|
|
10
11
|
export * from "./chip-input.js";
|
|
12
|
+
export * from "./code-editor.js";
|
|
11
13
|
export * from "./filter-input.js";
|
|
12
14
|
export * from "./filter-expression.js";
|
|
13
15
|
export * from "./command-palette.js";
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,14 @@ export * from "./alert.js";
|
|
|
3
3
|
export * from "./alert-dialog.js";
|
|
4
4
|
export * from "./app-shell.js";
|
|
5
5
|
export * from "./badge.js";
|
|
6
|
+
export * from "./bottom-nav.js";
|
|
6
7
|
export * from "./brand-mark.js";
|
|
7
8
|
export * from "./breadcrumb.js";
|
|
8
9
|
export * from "./button.js";
|
|
9
10
|
export * from "./card.js";
|
|
10
11
|
export * from "./checkbox.js";
|
|
11
12
|
export * from "./chip-input.js";
|
|
13
|
+
export * from "./code-editor.js";
|
|
12
14
|
export * from "./filter-input.js";
|
|
13
15
|
export * from "./filter-expression.js";
|
|
14
16
|
export * from "./command-palette.js";
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -3,5 +3,7 @@ export type LifecycleProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
|
3
3
|
status: React.ReactNode;
|
|
4
4
|
actions?: React.ReactNode;
|
|
5
5
|
destructive?: React.ReactNode;
|
|
6
|
+
/** The title of the sheet that holds the actions on a phone. */
|
|
7
|
+
actionsLabel?: string;
|
|
6
8
|
};
|
|
7
|
-
export declare function Lifecycle({ status, actions, destructive, className, ...props }: LifecycleProps): React.JSX.Element;
|
|
9
|
+
export declare function Lifecycle({ status, actions, destructive, actionsLabel, className, ...props }: LifecycleProps): React.JSX.Element;
|
package/dist/lifecycle.js
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
2
3
|
import { clsx as cn } from "clsx";
|
|
4
|
+
import { Ellipsis } from "lucide-react";
|
|
5
|
+
import { Button } from "./button.js";
|
|
6
|
+
import { Drawer, DrawerBody, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from "./drawer.js";
|
|
3
7
|
/* The header row of a detail screen: what the thing is, what you can do to
|
|
4
8
|
it, and the one action you do not want to hit by accident. Status is read,
|
|
5
9
|
the verbs are pressed, and the destructive action sits outside both with a
|
|
6
10
|
wider gap. A screen with no verbs passes none, and the middle group is
|
|
7
|
-
dropped rather than rendered as an empty bordered box.
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
dropped rather than rendered as an empty bordered box.
|
|
12
|
+
|
|
13
|
+
On a phone the verbs and the destructive action do not fit beside the
|
|
14
|
+
status, so they move to a sheet behind one button. Picking one closes the
|
|
15
|
+
sheet, unless it opened a dialog of its own, which then sits over it. */
|
|
16
|
+
export function Lifecycle({ status, actions, destructive, actionsLabel = "Actions", className, ...props }) {
|
|
17
|
+
const [open, setOpen] = React.useState(false);
|
|
18
|
+
const sheet = React.useRef(null);
|
|
19
|
+
return _jsxs("div", { ...props, "data-slot": "lifecycle", className: cn("lifecycle", className), children: [_jsx("div", { className: "cluster cluster-status", role: "group", "aria-label": "Status", children: status }), actions ? _jsx("div", { className: "cluster cluster-verbs", role: "group", "aria-label": "Actions", children: actions }) : null, destructive, actions || destructive ? (_jsxs(Drawer, { open: open, onOpenChange: setOpen, children: [_jsx(DrawerTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "sm", className: "lifecycle-more btn-icon", "aria-label": `More ${actionsLabel.toLowerCase()}`, title: actionsLabel, children: _jsx(Ellipsis, { className: "icon", "aria-hidden": "true" }) }) }), _jsxs(DrawerContent, { ref: sheet, placement: "bottom", children: [_jsx(DrawerHeader, { children: _jsx(DrawerTitle, { children: actionsLabel }) }), _jsx(DrawerBody, { children: _jsxs("div", { className: "lifecycle-sheet", onClick: (event) => {
|
|
20
|
+
if (!event.target.closest("button:not(:disabled), a[href]"))
|
|
21
|
+
return;
|
|
22
|
+
// An action that owns its confirmation renders it inside the
|
|
23
|
+
// sheet; closing the sheet would unmount both. Its dialog
|
|
24
|
+
// opens over the sheet instead.
|
|
25
|
+
requestAnimationFrame(() => {
|
|
26
|
+
const dialogs = document.querySelectorAll("[role='dialog'][data-state='open'], [role='alertdialog'][data-state='open']");
|
|
27
|
+
if (![...dialogs].some((dialog) => dialog !== sheet.current))
|
|
28
|
+
setOpen(false);
|
|
29
|
+
});
|
|
30
|
+
}, children: [actions, destructive] }) })] })] })) : null] });
|
|
10
31
|
}
|
package/dist/pane-grid.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { clsx as cn } from "clsx";
|
|
5
|
+
import { GripVertical } from "lucide-react";
|
|
5
6
|
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
6
7
|
const COLUMNS = 12;
|
|
7
8
|
/* A drag ends on release, on cancellation, or when capture is lost. */
|
|
@@ -362,7 +363,11 @@ export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutCha
|
|
|
362
363
|
return;
|
|
363
364
|
event.preventDefault();
|
|
364
365
|
const handle = event.currentTarget;
|
|
365
|
-
|
|
366
|
+
// A pointer the browser has already handed to scrolling cannot be captured.
|
|
367
|
+
try {
|
|
368
|
+
handle.setPointerCapture(event.pointerId);
|
|
369
|
+
}
|
|
370
|
+
catch { /* the gesture stays a scroll */ }
|
|
366
371
|
const start = { x: event.clientX, y: event.clientY };
|
|
367
372
|
let active = false;
|
|
368
373
|
let target = null;
|
|
@@ -380,14 +385,15 @@ export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutCha
|
|
|
380
385
|
target.invalid = exceeds(id, target);
|
|
381
386
|
paint(target);
|
|
382
387
|
};
|
|
383
|
-
const stop = () => {
|
|
388
|
+
const stop = (ended) => {
|
|
384
389
|
handle.removeEventListener("pointermove", move);
|
|
385
390
|
for (const type of RELEASE)
|
|
386
391
|
handle.removeEventListener(type, stop);
|
|
387
392
|
pane.classList.remove("dragging");
|
|
388
393
|
delete bodyRef.current?.dataset.dragging;
|
|
389
394
|
paint(null);
|
|
390
|
-
|
|
395
|
+
// A cancelled gesture, such as a touch that became a scroll, moves nothing.
|
|
396
|
+
if (ended.type === "pointercancel" || !active || !target || target.invalid)
|
|
391
397
|
return;
|
|
392
398
|
const rows = plan(id, target);
|
|
393
399
|
if (rows)
|
|
@@ -472,7 +478,7 @@ export function GridPane({ id, title, min: _min, size: _size, newRow: _newRow, a
|
|
|
472
478
|
else
|
|
473
479
|
return;
|
|
474
480
|
event.preventDefault();
|
|
475
|
-
}, children: [_jsx("h3", { "data-slot": "grid-pane-title", className: "grid-pane-title t-h3", children: title }), placement.debug && _jsxs("span", { className: "grid-pane-meta", children: ["size=", placement.size, " \u00B7 min=", placement.min, " \u00B7 max=", placement.max] }), actions != null && _jsx("div", { "data-slot": "grid-pane-actions", className: "grid-pane-actions", children: actions })] }), _jsx("div", { "data-slot": "grid-pane-body", className: "grid-pane-body", children: children }), !placement.compact && (_jsx("div", { "data-slot": "grid-pane-resizer", className: "grid-pane-resizer", role: "separator", tabIndex: 0, "aria-orientation": "vertical", "aria-label": `Resize ${title}`, "aria-valuenow": placement.size, "aria-valuemin": placement.min, "aria-valuemax": placement.max, "aria-disabled": placement.min === placement.max || undefined, onPointerDown: (event) => api.startResize(id, event), onKeyDown: (event) => {
|
|
481
|
+
}, children: [_jsx(GripVertical, { className: "icon grid-pane-grip", "aria-hidden": "true" }), _jsx("h3", { "data-slot": "grid-pane-title", className: "grid-pane-title t-h3", children: title }), placement.debug && _jsxs("span", { className: "grid-pane-meta", children: ["size=", placement.size, " \u00B7 min=", placement.min, " \u00B7 max=", placement.max] }), actions != null && _jsx("div", { "data-slot": "grid-pane-actions", className: "grid-pane-actions", children: actions })] }), _jsx("div", { "data-slot": "grid-pane-body", className: "grid-pane-body", children: children }), !placement.compact && (_jsx("div", { "data-slot": "grid-pane-resizer", className: "grid-pane-resizer", role: "separator", tabIndex: 0, "aria-orientation": "vertical", "aria-label": `Resize ${title}`, "aria-valuenow": placement.size, "aria-valuemin": placement.min, "aria-valuemax": placement.max, "aria-disabled": placement.min === placement.max || undefined, onPointerDown: (event) => api.startResize(id, event), onKeyDown: (event) => {
|
|
476
482
|
if (event.key === "ArrowRight")
|
|
477
483
|
api.resize(id, placement.size + 1);
|
|
478
484
|
else if (event.key === "ArrowLeft")
|
package/dist/styles.css
CHANGED
|
@@ -210,6 +210,7 @@
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
@media (pointer: coarse) {
|
|
213
|
+
.accent-pill { height: auto; min-height: var(--size-touch-min); }
|
|
213
214
|
/* Reserve the extended target in layout so adjacent controls cannot overlap. */
|
|
214
215
|
.kiso-checkbox { margin: calc((var(--size-touch-min) - var(--size-icon-md)) / 2); }
|
|
215
216
|
.kiso-react-switch {
|
|
@@ -285,6 +286,7 @@
|
|
|
285
286
|
[data-slot="select-trigger"]:disabled { cursor: not-allowed; }
|
|
286
287
|
[data-slot="select-item"] { justify-content: space-between; }
|
|
287
288
|
[data-slot="select-content"] {
|
|
289
|
+
min-width: var(--radix-select-trigger-width);
|
|
288
290
|
max-height: var(--radix-select-content-available-height);
|
|
289
291
|
overflow: hidden;
|
|
290
292
|
}
|
|
@@ -331,7 +333,7 @@
|
|
|
331
333
|
max-height: min(32rem, var(--radix-popover-content-available-height));
|
|
332
334
|
overflow-y: auto; overscroll-behavior: contain; padding: 0;
|
|
333
335
|
}
|
|
334
|
-
.detail-select-option { display: grid; grid-template-columns: minmax(
|
|
336
|
+
.detail-select-option { display: grid; grid-template-columns: minmax(min-content, 8rem) minmax(0, 1fr); gap: var(--spacing-lg); padding: var(--spacing-md); border-bottom: 1px solid var(--color-border); }
|
|
335
337
|
.detail-select-option:last-child { border-bottom: 0; }
|
|
336
338
|
.detail-select-option:not([data-disabled]) { cursor: pointer; }
|
|
337
339
|
@media (hover: hover) {
|
|
@@ -431,13 +433,23 @@
|
|
|
431
433
|
inset-inline: 0;
|
|
432
434
|
inset-block-end: 0;
|
|
433
435
|
max-height: 85dvh;
|
|
436
|
+
padding-block-end: env(safe-area-inset-bottom);
|
|
434
437
|
border-start-start-radius: var(--radius-surface);
|
|
435
438
|
border-start-end-radius: var(--radius-surface);
|
|
436
439
|
}
|
|
440
|
+
/* The shell's navigation opens from the edge its sidebar sat on, and leaves
|
|
441
|
+
a strip of the page showing so it reads as over the page, not a new one. */
|
|
442
|
+
.kiso-react-drawer.app-shell-drawer[data-placement="side"] {
|
|
443
|
+
inset-inline-start: 0;
|
|
444
|
+
inset-inline-end: auto;
|
|
445
|
+
width: min(20rem, calc(100vw - var(--spacing-3xl)));
|
|
446
|
+
border-radius: 0 var(--radius-surface) var(--radius-surface) 0;
|
|
447
|
+
}
|
|
437
448
|
/* Header and footer stay put; the body takes the leftover height. */
|
|
438
449
|
.kiso-react-drawer [data-slot="dialog-body"] {
|
|
439
450
|
flex: 1 1 auto;
|
|
440
451
|
overflow-y: auto;
|
|
452
|
+
align-content: start;
|
|
441
453
|
}
|
|
442
454
|
|
|
443
455
|
@media (forced-colors: active) {
|
package/dist/tabs.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Tabs as TabsPrimitive } from "radix-ui";
|
|
3
|
-
|
|
3
|
+
type TabsProps = React.ComponentProps<typeof TabsPrimitive.Root> & {
|
|
4
|
+
/**
|
|
5
|
+
* Below 1024px, show each panel under a header of its own, one open at a
|
|
6
|
+
* time, instead of a strip of triggers that cannot fit a phone. The panels
|
|
7
|
+
* are the same elements in both layouts, so crossing the breakpoint (a
|
|
8
|
+
* phone turned sideways) keeps what they hold: an edited form, a terminal.
|
|
9
|
+
*/
|
|
10
|
+
sections?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function Tabs({ sections, ...props }: TabsProps): React.JSX.Element;
|
|
4
13
|
declare function TabsList({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.List>): React.JSX.Element;
|
|
5
14
|
declare function TabsTrigger({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Trigger>): React.JSX.Element;
|
|
6
15
|
declare function TabsContent({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Content>): React.JSX.Element;
|
package/dist/tabs.js
CHANGED
|
@@ -1,10 +1,73 @@
|
|
|
1
1
|
// Adapted from shadcn/ui new-york-v4. See ../SHADCN-LICENSE.
|
|
2
2
|
"use client";
|
|
3
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
import * as React from "react";
|
|
4
5
|
import { clsx as cn } from "clsx";
|
|
6
|
+
import { ChevronDown } from "lucide-react";
|
|
5
7
|
import { Tabs as TabsPrimitive } from "radix-ui";
|
|
6
|
-
function Tabs({ ...props }) {
|
|
7
|
-
|
|
8
|
+
function Tabs({ sections = false, ...props }) {
|
|
9
|
+
if (!sections)
|
|
10
|
+
return _jsx(TabsPrimitive.Root, { "data-slot": "tabs", ...props });
|
|
11
|
+
return _jsx(SectionedTabs, { ...props });
|
|
12
|
+
}
|
|
13
|
+
/** Children with fragments opened, so a conditional group still counts.
|
|
14
|
+
* Keys carry the fragment's, so two groups never share one. */
|
|
15
|
+
function flatten(children, prefix = "") {
|
|
16
|
+
return React.Children.toArray(children).flatMap((child) => {
|
|
17
|
+
if (!React.isValidElement(child))
|
|
18
|
+
return [child];
|
|
19
|
+
if (child.type === React.Fragment)
|
|
20
|
+
return flatten(child.props.children, `${prefix}${child.key}/`);
|
|
21
|
+
return [prefix ? React.cloneElement(child, { key: `${prefix}${child.key}` }) : child];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function SectionedTabs({ value: controlled, defaultValue, onValueChange, className, children, ...props }) {
|
|
25
|
+
const [inner, setInner] = React.useState(defaultValue);
|
|
26
|
+
const value = controlled ?? inner;
|
|
27
|
+
// Closing the open section is a phone's own state: the selected tab stays,
|
|
28
|
+
// so a wider screen never shows a card with no panel. It belongs to the
|
|
29
|
+
// value it closed, so any other way to a panel (a tab, a link in a panel
|
|
30
|
+
// that sets the value) opens it.
|
|
31
|
+
const [collapsedFor, setCollapsedFor] = React.useState();
|
|
32
|
+
const [shown, setShown] = React.useState(value);
|
|
33
|
+
if (shown !== value) {
|
|
34
|
+
setShown(value);
|
|
35
|
+
setCollapsedFor(undefined);
|
|
36
|
+
}
|
|
37
|
+
const collapsed = value !== undefined && collapsedFor === value;
|
|
38
|
+
const select = (next) => {
|
|
39
|
+
if (controlled === undefined)
|
|
40
|
+
setInner(next);
|
|
41
|
+
onValueChange?.(next);
|
|
42
|
+
};
|
|
43
|
+
const items = flatten(children);
|
|
44
|
+
const triggers = [];
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
if (!React.isValidElement(item) || item.type !== TabsList)
|
|
47
|
+
continue;
|
|
48
|
+
for (const trigger of flatten(item.props.children)) {
|
|
49
|
+
if (!React.isValidElement(trigger) || trigger.type !== TabsTrigger)
|
|
50
|
+
continue;
|
|
51
|
+
triggers.push({ value: trigger.props.value, label: trigger.props.children, disabled: trigger.props.disabled });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const laid = [];
|
|
55
|
+
for (const item of items) {
|
|
56
|
+
if (React.isValidElement(item) && item.type === TabsContent) {
|
|
57
|
+
const trigger = triggers.find((one) => one.value === item.props.value);
|
|
58
|
+
if (trigger) {
|
|
59
|
+
const open = trigger.value === value && !collapsed;
|
|
60
|
+
laid.push(_jsxs("button", { type: "button", "data-slot": "tabs-section", className: "tabs-section", "data-state": open ? "open" : "closed", "aria-expanded": open, disabled: trigger.disabled, onClick: () => {
|
|
61
|
+
if (trigger.value !== value)
|
|
62
|
+
select(trigger.value);
|
|
63
|
+
else
|
|
64
|
+
setCollapsedFor(collapsed ? undefined : value);
|
|
65
|
+
}, children: [_jsx("span", { className: "tabs-section-label", children: trigger.label }), _jsx(ChevronDown, { className: "icon tabs-section-chevron", "aria-hidden": "true" })] }, `section-${trigger.value}`));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
laid.push(item);
|
|
69
|
+
}
|
|
70
|
+
return (_jsx(TabsPrimitive.Root, { "data-slot": "tabs", "data-sections": "true", "data-collapsed": collapsed ? "true" : undefined, className: className, value: value, onValueChange: select, ...props, children: laid }));
|
|
8
71
|
}
|
|
9
72
|
function TabsList({ className, ...props }) {
|
|
10
73
|
return (_jsx(TabsPrimitive.List, { "data-slot": "tabs-list", className: cn("tabs", className), ...props }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momoi-labs/kiso-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Kiso React components built with shadcn/ui and Radix",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepack": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@momoi-labs/kiso": "^0.
|
|
35
|
+
"@momoi-labs/kiso": "^0.20.3",
|
|
36
36
|
"class-variance-authority": "0.7.1",
|
|
37
37
|
"clsx": "2.1.1",
|
|
38
38
|
"radix-ui": "1.6.7",
|