@lab206/ui 0.1.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 +114 -0
- package/README.md +6 -0
- package/dist/components/Accordion.d.ts +25 -0
- package/dist/components/Accordion.d.ts.map +1 -0
- package/dist/components/Accordion.js +123 -0
- package/dist/components/Accordion.js.map +1 -0
- package/dist/components/Alert.d.ts +17 -0
- package/dist/components/Alert.d.ts.map +1 -0
- package/dist/components/Alert.js +59 -0
- package/dist/components/Alert.js.map +1 -0
- package/dist/components/AspectRatio.d.ts +13 -0
- package/dist/components/AspectRatio.d.ts.map +1 -0
- package/dist/components/AspectRatio.js +38 -0
- package/dist/components/AspectRatio.js.map +1 -0
- package/dist/components/Avatar.d.ts +17 -0
- package/dist/components/Avatar.d.ts.map +1 -0
- package/dist/components/Avatar.js +57 -0
- package/dist/components/Avatar.js.map +1 -0
- package/dist/components/Badge.d.ts +12 -0
- package/dist/components/Badge.d.ts.map +1 -0
- package/dist/components/Badge.js +62 -0
- package/dist/components/Badge.js.map +1 -0
- package/dist/components/Breadcrumb.d.ts +16 -0
- package/dist/components/Breadcrumb.d.ts.map +1 -0
- package/dist/components/Breadcrumb.js +76 -0
- package/dist/components/Breadcrumb.js.map +1 -0
- package/dist/components/Button.d.ts +28 -0
- package/dist/components/Button.d.ts.map +1 -0
- package/dist/components/Button.js +110 -0
- package/dist/components/Button.js.map +1 -0
- package/dist/components/Card.d.ts +18 -0
- package/dist/components/Card.d.ts.map +1 -0
- package/dist/components/Card.js +57 -0
- package/dist/components/Card.js.map +1 -0
- package/dist/components/Checkbox.d.ts +23 -0
- package/dist/components/Checkbox.d.ts.map +1 -0
- package/dist/components/Checkbox.js +107 -0
- package/dist/components/Checkbox.js.map +1 -0
- package/dist/components/Chip.d.ts +18 -0
- package/dist/components/Chip.d.ts.map +1 -0
- package/dist/components/Chip.js +103 -0
- package/dist/components/Chip.js.map +1 -0
- package/dist/components/Code.d.ts +12 -0
- package/dist/components/Code.d.ts.map +1 -0
- package/dist/components/Code.js +57 -0
- package/dist/components/Code.js.map +1 -0
- package/dist/components/Collapse.d.ts +15 -0
- package/dist/components/Collapse.d.ts.map +1 -0
- package/dist/components/Collapse.js +49 -0
- package/dist/components/Collapse.js.map +1 -0
- package/dist/components/Combobox.d.ts +47 -0
- package/dist/components/Combobox.d.ts.map +1 -0
- package/dist/components/Combobox.js +325 -0
- package/dist/components/Combobox.js.map +1 -0
- package/dist/components/Command.d.ts +42 -0
- package/dist/components/Command.d.ts.map +1 -0
- package/dist/components/Command.js +263 -0
- package/dist/components/Command.js.map +1 -0
- package/dist/components/Container.d.ts +11 -0
- package/dist/components/Container.d.ts.map +1 -0
- package/dist/components/Container.js +38 -0
- package/dist/components/Container.js.map +1 -0
- package/dist/components/Dialog.d.ts +26 -0
- package/dist/components/Dialog.d.ts.map +1 -0
- package/dist/components/Dialog.js +159 -0
- package/dist/components/Dialog.js.map +1 -0
- package/dist/components/Divider.d.ts +10 -0
- package/dist/components/Divider.d.ts.map +1 -0
- package/dist/components/Divider.js +52 -0
- package/dist/components/Divider.js.map +1 -0
- package/dist/components/Drawer.d.ts +19 -0
- package/dist/components/Drawer.d.ts.map +1 -0
- package/dist/components/Drawer.js +131 -0
- package/dist/components/Drawer.js.map +1 -0
- package/dist/components/Empty.d.ts +17 -0
- package/dist/components/Empty.d.ts.map +1 -0
- package/dist/components/Empty.js +51 -0
- package/dist/components/Empty.js.map +1 -0
- package/dist/components/Field.d.ts +27 -0
- package/dist/components/Field.d.ts.map +1 -0
- package/dist/components/Field.js +153 -0
- package/dist/components/Field.js.map +1 -0
- package/dist/components/Grid.d.ts +13 -0
- package/dist/components/Grid.d.ts.map +1 -0
- package/dist/components/Grid.js +44 -0
- package/dist/components/Grid.js.map +1 -0
- package/dist/components/Input.d.ts +55 -0
- package/dist/components/Input.d.ts.map +1 -0
- package/dist/components/Input.js +113 -0
- package/dist/components/Input.js.map +1 -0
- package/dist/components/Kbd.d.ts +10 -0
- package/dist/components/Kbd.d.ts.map +1 -0
- package/dist/components/Kbd.js +41 -0
- package/dist/components/Kbd.js.map +1 -0
- package/dist/components/Label.d.ts +13 -0
- package/dist/components/Label.d.ts.map +1 -0
- package/dist/components/Label.js +34 -0
- package/dist/components/Label.js.map +1 -0
- package/dist/components/Link.d.ts +18 -0
- package/dist/components/Link.d.ts.map +1 -0
- package/dist/components/Link.js +41 -0
- package/dist/components/Link.js.map +1 -0
- package/dist/components/List.d.ts +22 -0
- package/dist/components/List.d.ts.map +1 -0
- package/dist/components/List.js +157 -0
- package/dist/components/List.js.map +1 -0
- package/dist/components/Menu.d.ts +28 -0
- package/dist/components/Menu.d.ts.map +1 -0
- package/dist/components/Menu.js +126 -0
- package/dist/components/Menu.js.map +1 -0
- package/dist/components/NumberInput.d.ts +27 -0
- package/dist/components/NumberInput.d.ts.map +1 -0
- package/dist/components/NumberInput.js +92 -0
- package/dist/components/NumberInput.js.map +1 -0
- package/dist/components/Pagination.d.ts +13 -0
- package/dist/components/Pagination.d.ts.map +1 -0
- package/dist/components/Pagination.js +104 -0
- package/dist/components/Pagination.js.map +1 -0
- package/dist/components/Popover.d.ts +26 -0
- package/dist/components/Popover.d.ts.map +1 -0
- package/dist/components/Popover.js +165 -0
- package/dist/components/Popover.js.map +1 -0
- package/dist/components/Progress.d.ts +15 -0
- package/dist/components/Progress.d.ts.map +1 -0
- package/dist/components/Progress.js +63 -0
- package/dist/components/Progress.js.map +1 -0
- package/dist/components/Radio.d.ts +25 -0
- package/dist/components/Radio.d.ts.map +1 -0
- package/dist/components/Radio.js +95 -0
- package/dist/components/Radio.js.map +1 -0
- package/dist/components/ScrollArea.d.ts +13 -0
- package/dist/components/ScrollArea.d.ts.map +1 -0
- package/dist/components/ScrollArea.js +33 -0
- package/dist/components/ScrollArea.js.map +1 -0
- package/dist/components/Select.d.ts +34 -0
- package/dist/components/Select.d.ts.map +1 -0
- package/dist/components/Select.js +108 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Skeleton.d.ts +18 -0
- package/dist/components/Skeleton.d.ts.map +1 -0
- package/dist/components/Skeleton.js +86 -0
- package/dist/components/Skeleton.js.map +1 -0
- package/dist/components/Slider.d.ts +26 -0
- package/dist/components/Slider.d.ts.map +1 -0
- package/dist/components/Slider.js +113 -0
- package/dist/components/Slider.js.map +1 -0
- package/dist/components/Spinner.d.ts +12 -0
- package/dist/components/Spinner.d.ts.map +1 -0
- package/dist/components/Spinner.js +44 -0
- package/dist/components/Spinner.js.map +1 -0
- package/dist/components/Stack.d.ts +21 -0
- package/dist/components/Stack.d.ts.map +1 -0
- package/dist/components/Stack.js +48 -0
- package/dist/components/Stack.js.map +1 -0
- package/dist/components/Stat.d.ts +23 -0
- package/dist/components/Stat.d.ts.map +1 -0
- package/dist/components/Stat.js +115 -0
- package/dist/components/Stat.js.map +1 -0
- package/dist/components/Steps.d.ts +20 -0
- package/dist/components/Steps.d.ts.map +1 -0
- package/dist/components/Steps.js +126 -0
- package/dist/components/Steps.js.map +1 -0
- package/dist/components/Switch.d.ts +23 -0
- package/dist/components/Switch.d.ts.map +1 -0
- package/dist/components/Switch.js +108 -0
- package/dist/components/Switch.js.map +1 -0
- package/dist/components/Table.d.ts +27 -0
- package/dist/components/Table.d.ts.map +1 -0
- package/dist/components/Table.js +112 -0
- package/dist/components/Table.js.map +1 -0
- package/dist/components/Tabs.d.ts +27 -0
- package/dist/components/Tabs.d.ts.map +1 -0
- package/dist/components/Tabs.js +171 -0
- package/dist/components/Tabs.js.map +1 -0
- package/dist/components/Text.d.ts +17 -0
- package/dist/components/Text.d.ts.map +1 -0
- package/dist/components/Text.js +48 -0
- package/dist/components/Text.js.map +1 -0
- package/dist/components/Textarea.d.ts +32 -0
- package/dist/components/Textarea.d.ts.map +1 -0
- package/dist/components/Textarea.js +91 -0
- package/dist/components/Textarea.js.map +1 -0
- package/dist/components/Timeline.d.ts +17 -0
- package/dist/components/Timeline.d.ts.map +1 -0
- package/dist/components/Timeline.js +95 -0
- package/dist/components/Timeline.js.map +1 -0
- package/dist/components/Toast.d.ts +36 -0
- package/dist/components/Toast.d.ts.map +1 -0
- package/dist/components/Toast.js +143 -0
- package/dist/components/Toast.js.map +1 -0
- package/dist/components/ToggleGroup.d.ts +25 -0
- package/dist/components/ToggleGroup.d.ts.map +1 -0
- package/dist/components/ToggleGroup.js +103 -0
- package/dist/components/ToggleGroup.js.map +1 -0
- package/dist/components/Tooltip.d.ts +19 -0
- package/dist/components/Tooltip.d.ts.map +1 -0
- package/dist/components/Tooltip.js +141 -0
- package/dist/components/Tooltip.js.map +1 -0
- package/dist/components/Transition.d.ts +22 -0
- package/dist/components/Transition.d.ts.map +1 -0
- package/dist/components/Transition.js +139 -0
- package/dist/components/Transition.js.map +1 -0
- package/dist/density.d.ts +21 -0
- package/dist/density.d.ts.map +1 -0
- package/dist/density.js +31 -0
- package/dist/density.js.map +1 -0
- package/dist/dev.d.ts +27 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/dev.js +77 -0
- package/dist/dev.js.map +1 -0
- package/dist/focusTrap.d.ts +6 -0
- package/dist/focusTrap.d.ts.map +1 -0
- package/dist/focusTrap.js +55 -0
- package/dist/focusTrap.js.map +1 -0
- package/dist/form.d.ts +125 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +192 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +134 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/motion.d.ts +29 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +43 -0
- package/dist/motion.js.map +1 -0
- package/dist/overlay.d.ts +63 -0
- package/dist/overlay.d.ts.map +1 -0
- package/dist/overlay.js +172 -0
- package/dist/overlay.js.map +1 -0
- package/dist/palette.d.ts +20 -0
- package/dist/palette.d.ts.map +1 -0
- package/dist/palette.js +52 -0
- package/dist/palette.js.map +1 -0
- package/dist/reactive.d.ts +25 -0
- package/dist/reactive.d.ts.map +1 -0
- package/dist/reactive.js +43 -0
- package/dist/reactive.js.map +1 -0
- package/dist/rovingFocus.d.ts +36 -0
- package/dist/rovingFocus.d.ts.map +1 -0
- package/dist/rovingFocus.js +127 -0
- package/dist/rovingFocus.js.map +1 -0
- package/dist/size-entries/form-kit.d.ts +12 -0
- package/dist/size-entries/form-kit.d.ts.map +1 -0
- package/dist/size-entries/form-kit.js +12 -0
- package/dist/size-entries/form-kit.js.map +1 -0
- package/dist/styles.d.ts +29 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +53 -0
- package/dist/styles.js.map +1 -0
- package/dist/theme.d.ts +22 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +32 -0
- package/dist/theme.js.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +24 -0
- package/dist/utils.js.map +1 -0
- package/package.json +71 -0
- package/src/components/Accordion.tsx +194 -0
- package/src/components/Alert.tsx +88 -0
- package/src/components/AspectRatio.tsx +64 -0
- package/src/components/Avatar.tsx +89 -0
- package/src/components/Badge.tsx +84 -0
- package/src/components/Breadcrumb.tsx +116 -0
- package/src/components/Button.tsx +148 -0
- package/src/components/Card.tsx +92 -0
- package/src/components/Checkbox.tsx +143 -0
- package/src/components/Chip.tsx +153 -0
- package/src/components/Code.tsx +71 -0
- package/src/components/Collapse.tsx +76 -0
- package/src/components/Combobox.tsx +438 -0
- package/src/components/Command.tsx +380 -0
- package/src/components/Container.tsx +58 -0
- package/src/components/Dialog.tsx +226 -0
- package/src/components/Divider.tsx +72 -0
- package/src/components/Drawer.tsx +191 -0
- package/src/components/Empty.tsx +86 -0
- package/src/components/Field.tsx +184 -0
- package/src/components/Grid.tsx +67 -0
- package/src/components/Input.tsx +169 -0
- package/src/components/Kbd.tsx +57 -0
- package/src/components/Label.tsx +54 -0
- package/src/components/Link.tsx +87 -0
- package/src/components/List.tsx +236 -0
- package/src/components/Menu.tsx +195 -0
- package/src/components/NumberInput.tsx +158 -0
- package/src/components/Pagination.tsx +153 -0
- package/src/components/Popover.tsx +219 -0
- package/src/components/Progress.tsx +108 -0
- package/src/components/Radio.tsx +161 -0
- package/src/components/ScrollArea.tsx +58 -0
- package/src/components/Select.tsx +128 -0
- package/src/components/Skeleton.tsx +117 -0
- package/src/components/Slider.tsx +175 -0
- package/src/components/Spinner.tsx +70 -0
- package/src/components/Stack.tsx +79 -0
- package/src/components/Stat.tsx +169 -0
- package/src/components/Steps.tsx +191 -0
- package/src/components/Switch.tsx +146 -0
- package/src/components/Table.tsx +168 -0
- package/src/components/Tabs.tsx +246 -0
- package/src/components/Text.tsx +69 -0
- package/src/components/Textarea.tsx +128 -0
- package/src/components/Timeline.tsx +150 -0
- package/src/components/Toast.tsx +221 -0
- package/src/components/ToggleGroup.tsx +161 -0
- package/src/components/Tooltip.tsx +187 -0
- package/src/components/Transition.tsx +155 -0
- package/src/density.ts +46 -0
- package/src/dev.ts +87 -0
- package/src/focusTrap.ts +61 -0
- package/src/form.ts +269 -0
- package/src/index.ts +243 -0
- package/src/motion.ts +62 -0
- package/src/overlay.ts +232 -0
- package/src/palette.ts +70 -0
- package/src/reactive.ts +54 -0
- package/src/rovingFocus.ts +171 -0
- package/src/size-entries/form-kit.ts +11 -0
- package/src/styles/base.css +70 -0
- package/src/styles/theme.css +14 -0
- package/src/styles/tokens.css +377 -0
- package/src/styles/utilities.css +216 -0
- package/src/styles.ts +52 -0
- package/src/theme.ts +48 -0
- package/src/utils.ts +25 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { For, component, type ComponentProps } from "@lab206/dom";
|
|
2
|
+
import { cx } from "../utils.js";
|
|
3
|
+
import { createStyleSheet } from "../styles.js";
|
|
4
|
+
|
|
5
|
+
export type StepItem = {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type StepsProps = {
|
|
12
|
+
steps: StepItem[] | (() => StepItem[]);
|
|
13
|
+
/** 0-based current step index */
|
|
14
|
+
current: number | (() => number);
|
|
15
|
+
class?: string | (() => string);
|
|
16
|
+
onStepClick?: (index: number) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ensure = createStyleSheet(
|
|
20
|
+
"steps",
|
|
21
|
+
`
|
|
22
|
+
.pu-steps {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
gap: 0;
|
|
26
|
+
width: 100%;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
list-style: none;
|
|
30
|
+
}
|
|
31
|
+
.pu-steps__item {
|
|
32
|
+
display: grid;
|
|
33
|
+
grid-template-columns: auto 1fr;
|
|
34
|
+
gap: 0 0.75rem;
|
|
35
|
+
position: relative;
|
|
36
|
+
}
|
|
37
|
+
.pu-steps__marker {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: column;
|
|
40
|
+
align-items: center;
|
|
41
|
+
width: 1.75rem;
|
|
42
|
+
}
|
|
43
|
+
.pu-steps__dot {
|
|
44
|
+
width: 1.75rem;
|
|
45
|
+
height: 1.75rem;
|
|
46
|
+
border-radius: 50%;
|
|
47
|
+
border: 2px solid var(--pu-color-border);
|
|
48
|
+
background: var(--pu-color-surface);
|
|
49
|
+
color: var(--pu-color-text-muted);
|
|
50
|
+
font-size: var(--pu-text-xs);
|
|
51
|
+
font-weight: var(--pu-font-bold);
|
|
52
|
+
display: grid;
|
|
53
|
+
place-items: center;
|
|
54
|
+
z-index: 1;
|
|
55
|
+
transition:
|
|
56
|
+
background var(--pu-duration) var(--pu-ease),
|
|
57
|
+
border-color var(--pu-duration) var(--pu-ease),
|
|
58
|
+
color var(--pu-duration) var(--pu-ease);
|
|
59
|
+
}
|
|
60
|
+
.pu-steps__item.is-done .pu-steps__dot,
|
|
61
|
+
.pu-steps__item.is-current .pu-steps__dot {
|
|
62
|
+
border-color: var(--pu-color-accent);
|
|
63
|
+
background: var(--pu-color-accent);
|
|
64
|
+
color: var(--pu-color-accent-fg);
|
|
65
|
+
}
|
|
66
|
+
.pu-steps__item.is-current .pu-steps__dot {
|
|
67
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--pu-color-accent) 22%, transparent);
|
|
68
|
+
}
|
|
69
|
+
.pu-steps__line {
|
|
70
|
+
flex: 1;
|
|
71
|
+
width: 2px;
|
|
72
|
+
min-height: 1.25rem;
|
|
73
|
+
background: var(--pu-color-border);
|
|
74
|
+
margin: 0.2rem 0;
|
|
75
|
+
}
|
|
76
|
+
.pu-steps__item.is-done .pu-steps__line {
|
|
77
|
+
background: var(--pu-color-accent);
|
|
78
|
+
}
|
|
79
|
+
.pu-steps__item:last-child .pu-steps__line { display: none; }
|
|
80
|
+
.pu-steps__body {
|
|
81
|
+
padding-bottom: 1.1rem;
|
|
82
|
+
min-width: 0;
|
|
83
|
+
}
|
|
84
|
+
.pu-steps__item:last-child .pu-steps__body { padding-bottom: 0; }
|
|
85
|
+
.pu-steps__label {
|
|
86
|
+
font-size: var(--pu-text-sm);
|
|
87
|
+
font-weight: var(--pu-font-semibold);
|
|
88
|
+
color: var(--pu-color-text);
|
|
89
|
+
margin: 0.2rem 0 0;
|
|
90
|
+
}
|
|
91
|
+
.pu-steps__item.is-todo .pu-steps__label {
|
|
92
|
+
color: var(--pu-color-text-muted);
|
|
93
|
+
}
|
|
94
|
+
.pu-steps__desc {
|
|
95
|
+
margin: 0.2rem 0 0;
|
|
96
|
+
font-size: var(--pu-text-xs);
|
|
97
|
+
color: var(--pu-color-text-muted);
|
|
98
|
+
line-height: 1.45;
|
|
99
|
+
}
|
|
100
|
+
.pu-steps__btn {
|
|
101
|
+
appearance: none;
|
|
102
|
+
border: 0;
|
|
103
|
+
background: transparent;
|
|
104
|
+
padding: 0;
|
|
105
|
+
font: inherit;
|
|
106
|
+
text-align: left;
|
|
107
|
+
cursor: pointer;
|
|
108
|
+
color: inherit;
|
|
109
|
+
border-radius: var(--pu-radius-sm);
|
|
110
|
+
}
|
|
111
|
+
.pu-steps__btn:focus-visible {
|
|
112
|
+
outline: none;
|
|
113
|
+
box-shadow:
|
|
114
|
+
0 0 0 2px var(--pu-color-surface),
|
|
115
|
+
0 0 0 4px color-mix(in srgb, var(--pu-color-focus) 55%, transparent);
|
|
116
|
+
}
|
|
117
|
+
.pu-steps__btn:disabled { cursor: default; }
|
|
118
|
+
`,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
/** Vertical step / wizard indicator. */
|
|
122
|
+
export const Steps = component((raw: StepsProps) => {
|
|
123
|
+
ensure();
|
|
124
|
+
const props = raw as ComponentProps<StepsProps>;
|
|
125
|
+
const getSteps = () =>
|
|
126
|
+
typeof props.steps === "function"
|
|
127
|
+
? (props.steps as () => StepItem[])()
|
|
128
|
+
: (props.steps ?? []);
|
|
129
|
+
const current = () =>
|
|
130
|
+
typeof props.current === "function"
|
|
131
|
+
? (props.current as () => number)()
|
|
132
|
+
: props.current;
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<ol
|
|
136
|
+
class={() =>
|
|
137
|
+
cx(
|
|
138
|
+
"pu-steps",
|
|
139
|
+
typeof props.class === "function" ? props.class() : props.class,
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
ref={(el) => ensure(el.ownerDocument)}
|
|
143
|
+
>
|
|
144
|
+
<For each={getSteps}>
|
|
145
|
+
{(step, index) => (
|
|
146
|
+
<li
|
|
147
|
+
class={() => {
|
|
148
|
+
const i = index();
|
|
149
|
+
const c = current();
|
|
150
|
+
return cx(
|
|
151
|
+
"pu-steps__item",
|
|
152
|
+
i < c && "is-done",
|
|
153
|
+
i === c && "is-current",
|
|
154
|
+
i > c && "is-todo",
|
|
155
|
+
);
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
<div class="pu-steps__marker" aria-hidden="true">
|
|
159
|
+
<div class="pu-steps__dot">
|
|
160
|
+
{() =>
|
|
161
|
+
index() < current() ? "✓" : String(index() + 1)
|
|
162
|
+
}
|
|
163
|
+
</div>
|
|
164
|
+
<div class="pu-steps__line" />
|
|
165
|
+
</div>
|
|
166
|
+
<div class="pu-steps__body">
|
|
167
|
+
<button
|
|
168
|
+
type="button"
|
|
169
|
+
class="pu-steps__btn"
|
|
170
|
+
disabled={() => !props.onStepClick}
|
|
171
|
+
onClick={() => props.onStepClick?.(index())}
|
|
172
|
+
>
|
|
173
|
+
<div class="pu-steps__label">{() => step().label}</div>
|
|
174
|
+
{() =>
|
|
175
|
+
step().description
|
|
176
|
+
? (() => {
|
|
177
|
+
const p = document.createElement("p");
|
|
178
|
+
p.className = "pu-steps__desc";
|
|
179
|
+
p.textContent = step().description!;
|
|
180
|
+
return p;
|
|
181
|
+
})()
|
|
182
|
+
: null
|
|
183
|
+
}
|
|
184
|
+
</button>
|
|
185
|
+
</div>
|
|
186
|
+
</li>
|
|
187
|
+
)}
|
|
188
|
+
</For>
|
|
189
|
+
</ol>
|
|
190
|
+
);
|
|
191
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { type Signal } from "@lab206/core";
|
|
2
|
+
import { component, mergeProps, type ComponentProps } from "@lab206/dom";
|
|
3
|
+
import { cx } from "../utils.js";
|
|
4
|
+
import { readBool, type MaybeReactive } from "../reactive.js";
|
|
5
|
+
import type { Bindable } from "../form.js";
|
|
6
|
+
|
|
7
|
+
export type SwitchProps = {
|
|
8
|
+
checked?: MaybeReactive<boolean>;
|
|
9
|
+
/** Two-way bind a boolean signal. */
|
|
10
|
+
bind?: Bindable<boolean> | Signal<boolean>;
|
|
11
|
+
disabled?: MaybeReactive<boolean>;
|
|
12
|
+
onChange?: (checked: boolean) => void;
|
|
13
|
+
label?: string;
|
|
14
|
+
class?: MaybeReactive<string>;
|
|
15
|
+
id?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const styles = `
|
|
19
|
+
.pu-switch {
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
gap: var(--pu-space-2);
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
user-select: none;
|
|
25
|
+
font-size: var(--pu-text-sm);
|
|
26
|
+
color: var(--pu-color-text);
|
|
27
|
+
}
|
|
28
|
+
.pu-switch[data-disabled="true"] {
|
|
29
|
+
opacity: 0.55;
|
|
30
|
+
cursor: not-allowed;
|
|
31
|
+
}
|
|
32
|
+
.pu-switch__track {
|
|
33
|
+
position: relative;
|
|
34
|
+
width: 2.5rem;
|
|
35
|
+
height: 1.4rem;
|
|
36
|
+
border-radius: var(--pu-radius-full);
|
|
37
|
+
background: var(--pu-color-surface-2);
|
|
38
|
+
border: 1.5px solid var(--pu-color-control-border, var(--pu-color-border-strong));
|
|
39
|
+
box-sizing: border-box;
|
|
40
|
+
transition:
|
|
41
|
+
background var(--pu-duration) var(--pu-ease-out),
|
|
42
|
+
border-color var(--pu-duration) var(--pu-ease-out);
|
|
43
|
+
flex-shrink: 0;
|
|
44
|
+
}
|
|
45
|
+
.pu-switch:hover:not([data-disabled="true"]) .pu-switch__track {
|
|
46
|
+
border-color: var(--pu-color-border-strong);
|
|
47
|
+
}
|
|
48
|
+
.pu-switch[data-checked="true"] .pu-switch__track {
|
|
49
|
+
background: var(--pu-color-accent);
|
|
50
|
+
border-color: var(--pu-color-accent);
|
|
51
|
+
}
|
|
52
|
+
.pu-switch__thumb {
|
|
53
|
+
position: absolute;
|
|
54
|
+
top: 1.5px;
|
|
55
|
+
left: 1.5px;
|
|
56
|
+
width: calc(1.4rem - 6px);
|
|
57
|
+
height: calc(1.4rem - 6px);
|
|
58
|
+
border-radius: 50%;
|
|
59
|
+
/* Always a clear knob — surface-elevated blends into the track in dark mode */
|
|
60
|
+
background: #fff;
|
|
61
|
+
border: 1px solid color-mix(in srgb, var(--pu-color-text) 14%, transparent);
|
|
62
|
+
box-shadow:
|
|
63
|
+
var(--pu-shadow-sm),
|
|
64
|
+
0 1px 2px color-mix(in srgb, #000 18%, transparent);
|
|
65
|
+
transition:
|
|
66
|
+
transform var(--pu-duration) var(--pu-ease-spring),
|
|
67
|
+
background var(--pu-duration) var(--pu-ease-out),
|
|
68
|
+
border-color var(--pu-duration) var(--pu-ease-out);
|
|
69
|
+
}
|
|
70
|
+
.pu-switch[data-checked="true"] .pu-switch__thumb {
|
|
71
|
+
background: var(--pu-color-accent-fg, #fff);
|
|
72
|
+
border-color: transparent;
|
|
73
|
+
transform: translateX(1.05rem);
|
|
74
|
+
}
|
|
75
|
+
@media (prefers-reduced-motion: reduce) {
|
|
76
|
+
.pu-switch__thumb,
|
|
77
|
+
.pu-switch__track { transition: none; }
|
|
78
|
+
}
|
|
79
|
+
.pu-switch__input {
|
|
80
|
+
position: absolute;
|
|
81
|
+
opacity: 0;
|
|
82
|
+
width: 0;
|
|
83
|
+
height: 0;
|
|
84
|
+
}
|
|
85
|
+
.pu-switch__input:focus-visible + .pu-switch__track {
|
|
86
|
+
outline: none;
|
|
87
|
+
box-shadow:
|
|
88
|
+
0 0 0 2px var(--pu-color-surface),
|
|
89
|
+
0 0 0 4px color-mix(in srgb, var(--pu-color-focus) 55%, transparent);
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
let injected = false;
|
|
94
|
+
function ensureStyles() {
|
|
95
|
+
if (injected || typeof document === "undefined") return;
|
|
96
|
+
injected = true;
|
|
97
|
+
const el = document.createElement("style");
|
|
98
|
+
el.setAttribute("data-pu-ui", "switch");
|
|
99
|
+
el.textContent = styles;
|
|
100
|
+
document.head.appendChild(el);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const Switch = component((raw: SwitchProps) => {
|
|
104
|
+
ensureStyles();
|
|
105
|
+
const props = mergeProps({}, raw) as ComponentProps<SwitchProps>;
|
|
106
|
+
const id = props.id ?? `pu-switch-${Math.random().toString(36).slice(2, 9)}`;
|
|
107
|
+
const bound = raw.bind;
|
|
108
|
+
|
|
109
|
+
const isChecked = () =>
|
|
110
|
+
bound
|
|
111
|
+
? readBool(bound as MaybeReactive<boolean>)
|
|
112
|
+
: readBool(props.checked as MaybeReactive<boolean>);
|
|
113
|
+
const isDisabled = () => readBool(props.disabled as MaybeReactive<boolean>);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<label
|
|
117
|
+
class={() =>
|
|
118
|
+
cx(
|
|
119
|
+
"pu-switch",
|
|
120
|
+
typeof props.class === "function" ? props.class() : props.class,
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
data-checked={() => (isChecked() ? "true" : "false")}
|
|
124
|
+
data-disabled={() => (isDisabled() ? "true" : "false")}
|
|
125
|
+
>
|
|
126
|
+
<input
|
|
127
|
+
id={id}
|
|
128
|
+
class="pu-switch__input"
|
|
129
|
+
type="checkbox"
|
|
130
|
+
role="switch"
|
|
131
|
+
checked={isChecked}
|
|
132
|
+
disabled={isDisabled}
|
|
133
|
+
onChange={(e: Event) => {
|
|
134
|
+
if (isDisabled()) return;
|
|
135
|
+
const next = (e.target as HTMLInputElement).checked;
|
|
136
|
+
if (bound) bound.set(next);
|
|
137
|
+
props.onChange?.(next);
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
<span class="pu-switch__track" aria-hidden="true">
|
|
141
|
+
<span class="pu-switch__thumb" />
|
|
142
|
+
</span>
|
|
143
|
+
{props.label ? <span>{props.label}</span> : null}
|
|
144
|
+
</label>
|
|
145
|
+
);
|
|
146
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { For, component, type ComponentProps } from "@lab206/dom";
|
|
2
|
+
import { cx } from "../utils.js";
|
|
3
|
+
import { createStyleSheet } from "../styles.js";
|
|
4
|
+
|
|
5
|
+
export type TableColumn<T = Record<string, unknown>> = {
|
|
6
|
+
key: string;
|
|
7
|
+
header: string;
|
|
8
|
+
/** Cell renderer; defaults to row[key] */
|
|
9
|
+
cell?: (row: T) => unknown;
|
|
10
|
+
align?: "left" | "center" | "right";
|
|
11
|
+
width?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type TableProps<T = Record<string, unknown>> = {
|
|
15
|
+
columns: TableColumn<T>[] | (() => TableColumn<T>[]);
|
|
16
|
+
rows: T[] | (() => T[]);
|
|
17
|
+
/** Row key field or function */
|
|
18
|
+
rowKey?: string | ((row: T) => string);
|
|
19
|
+
dense?: boolean;
|
|
20
|
+
class?: string | (() => string);
|
|
21
|
+
onRowClick?: (row: T) => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const ensure = createStyleSheet(
|
|
25
|
+
"table",
|
|
26
|
+
`
|
|
27
|
+
.pu-table-wrap {
|
|
28
|
+
width: 100%;
|
|
29
|
+
overflow: auto;
|
|
30
|
+
border: 1px solid var(--pu-color-border);
|
|
31
|
+
border-radius: var(--pu-radius-lg);
|
|
32
|
+
background: var(--pu-color-surface);
|
|
33
|
+
}
|
|
34
|
+
.pu-table {
|
|
35
|
+
width: 100%;
|
|
36
|
+
border-collapse: collapse;
|
|
37
|
+
font-size: var(--pu-text-sm);
|
|
38
|
+
}
|
|
39
|
+
.pu-table th,
|
|
40
|
+
.pu-table td {
|
|
41
|
+
padding: 0.7rem 0.9rem;
|
|
42
|
+
text-align: left;
|
|
43
|
+
border-bottom: 1px solid var(--pu-color-border);
|
|
44
|
+
vertical-align: middle;
|
|
45
|
+
}
|
|
46
|
+
.pu-table--dense th,
|
|
47
|
+
.pu-table--dense td {
|
|
48
|
+
padding: 0.45rem 0.7rem;
|
|
49
|
+
}
|
|
50
|
+
.pu-table th {
|
|
51
|
+
font-weight: var(--pu-font-semibold);
|
|
52
|
+
color: var(--pu-color-text-muted);
|
|
53
|
+
background: var(--pu-color-surface-2);
|
|
54
|
+
font-size: var(--pu-text-xs);
|
|
55
|
+
letter-spacing: 0.02em;
|
|
56
|
+
text-transform: uppercase;
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
}
|
|
59
|
+
.pu-table tbody tr:last-child td { border-bottom: 0; }
|
|
60
|
+
.pu-table tbody tr.is-clickable { cursor: pointer; }
|
|
61
|
+
.pu-table tbody tr.is-clickable:hover td {
|
|
62
|
+
background: color-mix(in srgb, var(--pu-color-accent) 6%, transparent);
|
|
63
|
+
}
|
|
64
|
+
.pu-table .align-center { text-align: center; }
|
|
65
|
+
.pu-table .align-right { text-align: right; }
|
|
66
|
+
.pu-table__empty {
|
|
67
|
+
padding: 1.5rem;
|
|
68
|
+
text-align: center;
|
|
69
|
+
color: var(--pu-color-text-muted);
|
|
70
|
+
font-size: var(--pu-text-sm);
|
|
71
|
+
}
|
|
72
|
+
`,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
function keyOf<T>(row: T, rowKey: TableProps<T>["rowKey"], index: number): string {
|
|
76
|
+
if (typeof rowKey === "function") return rowKey(row);
|
|
77
|
+
if (typeof rowKey === "string" && row && typeof row === "object") {
|
|
78
|
+
const v = (row as Record<string, unknown>)[rowKey];
|
|
79
|
+
if (v != null) return String(v);
|
|
80
|
+
}
|
|
81
|
+
return String(index);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Data table with optional dense mode + row click. */
|
|
85
|
+
export const Table = component((raw: TableProps) => {
|
|
86
|
+
ensure();
|
|
87
|
+
const props = raw as ComponentProps<TableProps>;
|
|
88
|
+
const getCols = () =>
|
|
89
|
+
typeof props.columns === "function"
|
|
90
|
+
? (props.columns as () => TableColumn[])()
|
|
91
|
+
: (props.columns ?? []);
|
|
92
|
+
const getRows = () =>
|
|
93
|
+
typeof props.rows === "function"
|
|
94
|
+
? (props.rows as () => Record<string, unknown>[])()
|
|
95
|
+
: (props.rows ?? []);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div
|
|
99
|
+
class={() =>
|
|
100
|
+
cx(
|
|
101
|
+
"pu-table-wrap",
|
|
102
|
+
typeof props.class === "function" ? props.class() : props.class,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
ref={(el) => ensure(el.ownerDocument)}
|
|
106
|
+
>
|
|
107
|
+
<table class={() => cx("pu-table", props.dense && "pu-table--dense")}>
|
|
108
|
+
<thead>
|
|
109
|
+
<tr>
|
|
110
|
+
<For each={getCols}>
|
|
111
|
+
{(col) => (
|
|
112
|
+
<th
|
|
113
|
+
class={() =>
|
|
114
|
+
col().align && col().align !== "left"
|
|
115
|
+
? `align-${col().align}`
|
|
116
|
+
: undefined
|
|
117
|
+
}
|
|
118
|
+
style={() =>
|
|
119
|
+
col().width ? { width: col().width } : undefined
|
|
120
|
+
}
|
|
121
|
+
>
|
|
122
|
+
{() => col().header}
|
|
123
|
+
</th>
|
|
124
|
+
)}
|
|
125
|
+
</For>
|
|
126
|
+
</tr>
|
|
127
|
+
</thead>
|
|
128
|
+
<tbody>
|
|
129
|
+
{() => {
|
|
130
|
+
const rows = getRows();
|
|
131
|
+
if (rows.length === 0) {
|
|
132
|
+
const tr = document.createElement("tr");
|
|
133
|
+
const td = document.createElement("td");
|
|
134
|
+
td.colSpan = Math.max(1, getCols().length);
|
|
135
|
+
td.className = "pu-table__empty";
|
|
136
|
+
td.textContent = "No rows";
|
|
137
|
+
tr.appendChild(td);
|
|
138
|
+
return tr;
|
|
139
|
+
}
|
|
140
|
+
const frag = document.createDocumentFragment();
|
|
141
|
+
rows.forEach((row, i) => {
|
|
142
|
+
const tr = document.createElement("tr");
|
|
143
|
+
if (props.onRowClick) {
|
|
144
|
+
tr.classList.add("is-clickable");
|
|
145
|
+
tr.onclick = () => props.onRowClick?.(row);
|
|
146
|
+
}
|
|
147
|
+
for (const col of getCols()) {
|
|
148
|
+
const td = document.createElement("td");
|
|
149
|
+
if (col.align && col.align !== "left") {
|
|
150
|
+
td.className = `align-${col.align}`;
|
|
151
|
+
}
|
|
152
|
+
const content = col.cell
|
|
153
|
+
? col.cell(row)
|
|
154
|
+
: (row as Record<string, unknown>)[col.key];
|
|
155
|
+
if (content instanceof Node) td.appendChild(content);
|
|
156
|
+
else td.textContent = content == null ? "" : String(content);
|
|
157
|
+
tr.appendChild(td);
|
|
158
|
+
}
|
|
159
|
+
tr.dataset.key = keyOf(row, props.rowKey, i);
|
|
160
|
+
frag.appendChild(tr);
|
|
161
|
+
});
|
|
162
|
+
return frag;
|
|
163
|
+
}}
|
|
164
|
+
</tbody>
|
|
165
|
+
</table>
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
});
|