@carbonid1/design-system 5.15.1 → 5.16.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/README.md +1 -0
- package/dist/Select/Select.js +13 -2
- package/dist/Switch/Switch.d.ts +5 -0
- package/dist/Switch/Switch.js +10 -0
- package/dist/Switch/Switch.types.d.ts +7 -0
- package/dist/Switch/Switch.types.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
71
71
|
| `Kbd` | Keyboard key display (`⌘K`, `⇧B`) |
|
|
72
72
|
| `ProgressRing` | Circular progress indicator |
|
|
73
73
|
| `Slider` | Range slider |
|
|
74
|
+
| `Switch` | Boolean setting control with a compound `Root` / `Thumb` API |
|
|
74
75
|
| `ContextMenu` | Right-click / long-press menu (compound API) |
|
|
75
76
|
| `Select` | Custom dropdown — never use native `<select>` |
|
|
76
77
|
| `Tooltip` | Hover/focus tooltip (wraps a single child) |
|
package/dist/Select/Select.js
CHANGED
|
@@ -21,7 +21,9 @@ export const Select = ({ value, onChange, options, groups, placeholder, id, clas
|
|
|
21
21
|
return { items: flat, groupStartIndices: starts };
|
|
22
22
|
}, [options, groups]);
|
|
23
23
|
const selectedOption = items.find(o => o.value === value);
|
|
24
|
+
const selectedIndex = items.findIndex(o => o.value === value);
|
|
24
25
|
const displayText = selectedOption?.label ?? placeholder ?? value;
|
|
26
|
+
const initialHighlightedIndex = selectedIndex >= 0 ? selectedIndex : 0;
|
|
25
27
|
// Click outside to close
|
|
26
28
|
useEffect(() => {
|
|
27
29
|
const handleClickOutside = (e) => {
|
|
@@ -47,10 +49,13 @@ export const Select = ({ value, onChange, options, groups, placeholder, id, clas
|
|
|
47
49
|
if (e.key === 'ArrowDown' || e.key === 'ArrowUp' || e.key === 'Enter' || e.key === ' ') {
|
|
48
50
|
e.preventDefault();
|
|
49
51
|
changeOpen(true);
|
|
50
|
-
setHighlightedIndex(
|
|
52
|
+
setHighlightedIndex(initialHighlightedIndex);
|
|
51
53
|
}
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
56
|
+
if (items.length === 0) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
54
59
|
if (e.key === 'ArrowDown') {
|
|
55
60
|
e.preventDefault();
|
|
56
61
|
setHighlightedIndex(prev => (prev + 1) % items.length);
|
|
@@ -73,7 +78,13 @@ export const Select = ({ value, onChange, options, groups, placeholder, id, clas
|
|
|
73
78
|
const selected = itemValue === value ? 'font-medium' : '';
|
|
74
79
|
return `${base} ${highlight} ${selected}`;
|
|
75
80
|
};
|
|
76
|
-
return (_jsxs("div", { className: "relative", ref: containerRef, onKeyDown: handleKeyDown, children: [_jsxs("button", { type: "button", id: id, className: `flex items-center justify-between gap-2 ${className ?? ''}`, "aria-expanded": open, "aria-haspopup": "listbox", "aria-label": ariaLabel, onClick: () =>
|
|
81
|
+
return (_jsxs("div", { className: "relative", ref: containerRef, onKeyDown: handleKeyDown, children: [_jsxs("button", { type: "button", id: id, className: `flex items-center justify-between gap-2 ${className ?? ''}`, "aria-expanded": open, "aria-haspopup": "listbox", "aria-label": ariaLabel, onClick: () => {
|
|
82
|
+
const nextOpen = !open;
|
|
83
|
+
changeOpen(nextOpen);
|
|
84
|
+
if (nextOpen) {
|
|
85
|
+
setHighlightedIndex(initialHighlightedIndex);
|
|
86
|
+
}
|
|
87
|
+
}, children: [_jsx("span", { className: "truncate", children: displayText }), _jsx(ChevronDown, { className: `size-4 shrink-0 transition-transform ${open ? 'rotate-180' : ''}` })] }), open && (_jsx("ul", { role: "listbox", className: `border-border bg-background absolute z-50 mt-1 max-h-60 w-max min-w-full overflow-y-auto rounded-lg border shadow-lg ${menuClassName ?? ''}`, children: items.map((item, index) => {
|
|
77
88
|
const groupHeader = groupStartIndices.find(g => g.index === index);
|
|
78
89
|
return (_jsxs("li", { role: "presentation", children: [groupHeader && (_jsx("div", { className: "text-muted-foreground px-3 pt-2 pb-1 text-xs font-medium uppercase", children: groupHeader.label })), _jsx("div", { role: "option", "aria-selected": value === item.value, className: itemClassName(index, item.value), onClick: () => selectItem(item.value), onMouseEnter: () => setHighlightedIndex(index), children: renderOption
|
|
79
90
|
? renderOption(item, {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SwitchRootProps, SwitchThumbProps } from './Switch.types';
|
|
2
|
+
export declare const Switch: {
|
|
3
|
+
Root: ({ className, ...props }: SwitchRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
Thumb: ({ className, ...props }: SwitchThumbProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Switch as BaseSwitch } from '@base-ui/react/switch';
|
|
4
|
+
import { cn } from '../helpers/cn/cn';
|
|
5
|
+
const Root = ({ className, ...props }) => (_jsx(BaseSwitch.Root, { "data-slot": "switch", className: cn('border-input-border bg-input data-checked:border-primary data-checked:bg-primary inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border p-0.5 outline-hidden', 'transition-colors duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none', 'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-3', 'data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:opacity-50', className), ...props }));
|
|
6
|
+
const Thumb = ({ className, ...props }) => (_jsx(BaseSwitch.Thumb, { "data-slot": "switch-thumb", className: cn('bg-background pointer-events-none block size-4 translate-x-0 rounded-full shadow-sm', 'transition-transform duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none', 'data-checked:translate-x-4', className), ...props }));
|
|
7
|
+
export const Switch = {
|
|
8
|
+
Root,
|
|
9
|
+
Thumb,
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Switch as BaseSwitch } from '@base-ui/react/switch';
|
|
2
|
+
export type SwitchRootProps = Omit<BaseSwitch.Root.Props, 'className'> & {
|
|
3
|
+
className?: string;
|
|
4
|
+
};
|
|
5
|
+
export type SwitchThumbProps = Omit<BaseSwitch.Thumb.Props, 'className'> & {
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export { Text, textVariants } from './Text/Text';
|
|
|
11
11
|
export type { TextProps, TextPropsDefault } from './Text/Text.types';
|
|
12
12
|
export { ProgressRing } from './ProgressRing/ProgressRing';
|
|
13
13
|
export { Slider } from './Slider/Slider';
|
|
14
|
+
export { Switch } from './Switch/Switch';
|
|
15
|
+
export type { SwitchRootProps, SwitchThumbProps } from './Switch/Switch.types';
|
|
14
16
|
export { SegmentedControl } from './SegmentedControl/SegmentedControl';
|
|
15
17
|
export type { SegmentedControlItemProps, SegmentedControlRootProps, SegmentedControlSize, } from './SegmentedControl/SegmentedControl.types';
|
|
16
18
|
export { ScrollArea } from './ScrollArea/ScrollArea';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { Kbd, kbdVariants } from './Kbd/Kbd';
|
|
|
6
6
|
export { Text, textVariants } from './Text/Text';
|
|
7
7
|
export { ProgressRing } from './ProgressRing/ProgressRing';
|
|
8
8
|
export { Slider } from './Slider/Slider';
|
|
9
|
+
export { Switch } from './Switch/Switch';
|
|
9
10
|
export { SegmentedControl } from './SegmentedControl/SegmentedControl';
|
|
10
11
|
export { ScrollArea } from './ScrollArea/ScrollArea';
|
|
11
12
|
export { ContextMenu } from './ContextMenu/ContextMenu';
|