@niwa-labs/ui-kit 0.0.0-stage → 0.0.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 +21 -0
- package/README.md +29 -2
- package/package.json +31 -4
- package/src/agent/diff-view.tsx +62 -0
- package/src/agent/execution-track.tsx +201 -0
- package/src/agent/guard.ts +121 -0
- package/src/agent/guarded-action.tsx +272 -0
- package/src/agent/id-chip.tsx +102 -0
- package/src/agent/markdown.tsx +34 -0
- package/src/agent/payload.ts +42 -0
- package/src/agent/phase-plan.tsx +183 -0
- package/src/agent/plan-impact.ts +104 -0
- package/src/agent/state.tsx +75 -0
- package/src/agent/tool-call.tsx +106 -0
- package/src/agent/transcript.tsx +88 -0
- package/src/execution-track.css +327 -0
- package/src/index.ts +76 -0
- package/src/lib/cn.ts +19 -0
- package/src/page-layout.css +183 -0
- package/src/theme.css +136 -0
- package/src/ui/badge.tsx +32 -0
- package/src/ui/button.tsx +38 -0
- package/src/ui/collapsible.tsx +13 -0
- package/src/ui/data-value.tsx +211 -0
- package/src/ui/message.tsx +81 -0
- package/src/ui/page-layout.tsx +33 -0
- package/src/ui/schema-view.tsx +144 -0
- package/src/ui/spinner.tsx +16 -0
- package/src/ui/tabs.tsx +63 -0
- package/src/ui/tooltip.tsx +50 -0
- package/src/ui/trace.tsx +100 -0
- package/test/browser.test.ts +13 -0
- package/test/diff-view.test.tsx +50 -0
- package/test/guard.test.ts +113 -0
- package/test/guarded-action.test.tsx +229 -0
- package/test/helpers.test.ts +83 -0
- package/test/phase-plan.test.tsx +146 -0
- package/test/plan.test.ts +71 -0
- package/test/render.test.tsx +62 -0
- package/test/structured-values.test.tsx +31 -0
- package/test/tabs.test.tsx +90 -0
- package/tsconfig.json +16 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// The cockpit's shared components. Styles come from Tailwind classes over the tokens of
|
|
2
|
+
// `src/theme.css`, which the application imports into its stylesheet.
|
|
3
|
+
|
|
4
|
+
export { cn, cnWith } from "./lib/cn.ts";
|
|
5
|
+
|
|
6
|
+
export { Badge, badgeVariants, type BadgeProps } from "./ui/badge.tsx";
|
|
7
|
+
export { Button, buttonVariants, type ButtonProps } from "./ui/button.tsx";
|
|
8
|
+
export { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./ui/collapsible.tsx";
|
|
9
|
+
export {
|
|
10
|
+
MessageAvatar,
|
|
11
|
+
Message,
|
|
12
|
+
MessageBubble,
|
|
13
|
+
MessageContent,
|
|
14
|
+
MessageFooter,
|
|
15
|
+
MessageGroup,
|
|
16
|
+
MessageHeader,
|
|
17
|
+
} from "./ui/message.tsx";
|
|
18
|
+
export { Spinner } from "./ui/spinner.tsx";
|
|
19
|
+
export { Tabs, TabsContent, TabsList, TabsTrigger, tabsListVariants } from "./ui/tabs.tsx";
|
|
20
|
+
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip.tsx";
|
|
21
|
+
export {
|
|
22
|
+
Trace,
|
|
23
|
+
TraceCollapsible,
|
|
24
|
+
TraceCollapsibleContent,
|
|
25
|
+
TraceCollapsibleTrigger,
|
|
26
|
+
TraceDescription,
|
|
27
|
+
TraceIcon,
|
|
28
|
+
TraceLine,
|
|
29
|
+
TraceTitle,
|
|
30
|
+
type TraceStatus,
|
|
31
|
+
} from "./ui/trace.tsx";
|
|
32
|
+
|
|
33
|
+
export { isSettled, StateRing, WORK_STATE_LABEL, type StateRingProps, type WorkState } from "./agent/state.tsx";
|
|
34
|
+
export { IdChip, idPrefix, isPlainClick, shortId, type IdChipProps } from "./agent/id-chip.tsx";
|
|
35
|
+
export { formatAgo, formatDuration, formatPayload } from "./agent/payload.ts";
|
|
36
|
+
export { ToolCall, type ToolCallProps, type ToolCallState } from "./agent/tool-call.tsx";
|
|
37
|
+
export { Markdown, type MarkdownProps } from "./agent/markdown.tsx";
|
|
38
|
+
export { DiffView, type DiffLayout, type DiffViewProps } from "./agent/diff-view.tsx";
|
|
39
|
+
export { Transcript, type TranscriptProps } from "./agent/transcript.tsx";
|
|
40
|
+
export {
|
|
41
|
+
DEFAULT_GUARD_TIMING,
|
|
42
|
+
firesOnUnmount,
|
|
43
|
+
guardReducer,
|
|
44
|
+
holdProgress,
|
|
45
|
+
IDLE,
|
|
46
|
+
nextDeadline,
|
|
47
|
+
type GuardEvent,
|
|
48
|
+
type GuardState,
|
|
49
|
+
type GuardTiming,
|
|
50
|
+
} from "./agent/guard.ts";
|
|
51
|
+
export {
|
|
52
|
+
GuardButton,
|
|
53
|
+
GuardNotice,
|
|
54
|
+
useGuardedAction,
|
|
55
|
+
type GuardButtonProps,
|
|
56
|
+
type GuardedAction,
|
|
57
|
+
type GuardedActionOptions,
|
|
58
|
+
type GuardNoticeProps,
|
|
59
|
+
} from "./agent/guarded-action.tsx";
|
|
60
|
+
export {
|
|
61
|
+
describeRecompute,
|
|
62
|
+
describeStop,
|
|
63
|
+
recomputeImpact,
|
|
64
|
+
stopImpact,
|
|
65
|
+
targetTitle,
|
|
66
|
+
type PlanPhase,
|
|
67
|
+
type PlanStep,
|
|
68
|
+
type PlanTarget,
|
|
69
|
+
type RecomputeImpact,
|
|
70
|
+
type StopImpact,
|
|
71
|
+
} from "./agent/plan-impact.ts";
|
|
72
|
+
export { PhasePlan, type PhasePlanPhase, type PhasePlanProps, type PhasePlanStep } from "./agent/phase-plan.tsx";
|
|
73
|
+
export { ActivityLabel, MiniPhaseTrack, ExecutionTrack, PhaseSequence, type Activity, type ExecutionPhase, type ExecutionStep } from "./agent/execution-track.tsx";
|
|
74
|
+
export { PageHeading, PageSection } from "./ui/page-layout.tsx";
|
|
75
|
+
export { CopyValue, FileRef, DataValue, fieldLabel } from "./ui/data-value.tsx";
|
|
76
|
+
export { SchemaView } from "./ui/schema-view.tsx";
|
package/src/lib/cn.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { clsx, type ClassValue } from "clsx";
|
|
2
|
+
import { twMerge } from "tailwind-merge";
|
|
3
|
+
|
|
4
|
+
/** Joins class names and lets a later Tailwind utility win over an earlier one of the same kind. */
|
|
5
|
+
export function cn(...inputs: ClassValue[]): string {
|
|
6
|
+
return twMerge(clsx(inputs));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Merges `className` into `base` the way `cn` does, for a Base UI part that also takes a function
|
|
11
|
+
* of its state: the function is kept, and its result is merged when the part renders.
|
|
12
|
+
*/
|
|
13
|
+
export function cnWith<State>(
|
|
14
|
+
base: ClassValue,
|
|
15
|
+
className: string | ((state: State) => string | undefined) | undefined,
|
|
16
|
+
): string | ((state: State) => string) {
|
|
17
|
+
if (typeof className === "function") return (state) => cn(base, className(state));
|
|
18
|
+
return cn(base, className);
|
|
19
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
.desk-page {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 1.25rem;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
}
|
|
7
|
+
.desk-page h1 {
|
|
8
|
+
font-size: clamp(27px, 2.45vw, 36px);
|
|
9
|
+
line-height: 1.1;
|
|
10
|
+
font-weight: 720;
|
|
11
|
+
letter-spacing: -0.034em;
|
|
12
|
+
overflow-wrap: anywhere;
|
|
13
|
+
}
|
|
14
|
+
.desk-heading,
|
|
15
|
+
.desk-tools {
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
flex-wrap: wrap;
|
|
19
|
+
gap: 0.65rem;
|
|
20
|
+
}
|
|
21
|
+
.desk-heading {
|
|
22
|
+
justify-content: space-between;
|
|
23
|
+
gap: 1rem;
|
|
24
|
+
}
|
|
25
|
+
.desk-section {
|
|
26
|
+
min-width: 0;
|
|
27
|
+
border-top: 2px solid var(--border);
|
|
28
|
+
padding-top: 0.75rem;
|
|
29
|
+
margin-bottom: 0.65rem;
|
|
30
|
+
}
|
|
31
|
+
.desk-section h2 {
|
|
32
|
+
font-size: 20px;
|
|
33
|
+
font-weight: 680;
|
|
34
|
+
letter-spacing: -0.035em;
|
|
35
|
+
margin: 0 0 0.65rem;
|
|
36
|
+
}
|
|
37
|
+
.desk-section header h2 {
|
|
38
|
+
margin: 0 auto 0 0;
|
|
39
|
+
}
|
|
40
|
+
.nw-copy-wrap {
|
|
41
|
+
display: inline-flex;
|
|
42
|
+
flex-wrap: wrap;
|
|
43
|
+
max-width: 100%;
|
|
44
|
+
align-items: center;
|
|
45
|
+
gap: 0.45rem;
|
|
46
|
+
vertical-align: middle;
|
|
47
|
+
}
|
|
48
|
+
.nw-copy {
|
|
49
|
+
display: inline-flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
gap: 0.5em;
|
|
52
|
+
max-width: 100%;
|
|
53
|
+
min-width: 0;
|
|
54
|
+
color: var(--primary);
|
|
55
|
+
cursor: copy;
|
|
56
|
+
text-align: left;
|
|
57
|
+
overflow-wrap: anywhere;
|
|
58
|
+
}
|
|
59
|
+
.nw-copy svg {
|
|
60
|
+
flex: none;
|
|
61
|
+
opacity: 0.72;
|
|
62
|
+
}
|
|
63
|
+
.nw-copy:hover svg,
|
|
64
|
+
.nw-copy:focus-visible svg {
|
|
65
|
+
opacity: 1;
|
|
66
|
+
}
|
|
67
|
+
.nw-copy-wrap > [role="status"] {
|
|
68
|
+
color: var(--state-done);
|
|
69
|
+
}
|
|
70
|
+
.nw-file {
|
|
71
|
+
display: inline-flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
gap: 0.5rem;
|
|
74
|
+
}
|
|
75
|
+
.nw-file b {
|
|
76
|
+
display: block;
|
|
77
|
+
font-weight: 600;
|
|
78
|
+
}
|
|
79
|
+
.nw-file small {
|
|
80
|
+
display: block;
|
|
81
|
+
color: var(--muted-foreground);
|
|
82
|
+
line-height: 1.3;
|
|
83
|
+
}
|
|
84
|
+
.nw-fields {
|
|
85
|
+
display: grid;
|
|
86
|
+
min-width: 0;
|
|
87
|
+
margin: 0.3rem 0;
|
|
88
|
+
}
|
|
89
|
+
.nw-fields > div {
|
|
90
|
+
display: grid;
|
|
91
|
+
grid-template-columns: minmax(5rem, 27%) minmax(0, 1fr);
|
|
92
|
+
gap: 12px;
|
|
93
|
+
padding: 6px 0;
|
|
94
|
+
border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
|
|
95
|
+
}
|
|
96
|
+
.nw-fields dt,
|
|
97
|
+
.nw-quiet,
|
|
98
|
+
.nw-field-rule {
|
|
99
|
+
color: var(--muted-foreground);
|
|
100
|
+
}
|
|
101
|
+
.nw-fields dt {
|
|
102
|
+
font-size: 0.84em;
|
|
103
|
+
}
|
|
104
|
+
.nw-fields dd,
|
|
105
|
+
.nw-value-text,
|
|
106
|
+
.nw-url {
|
|
107
|
+
overflow-wrap: anywhere;
|
|
108
|
+
min-width: 0;
|
|
109
|
+
}
|
|
110
|
+
.nw-value-text {
|
|
111
|
+
white-space: pre-wrap;
|
|
112
|
+
}
|
|
113
|
+
.nw-value-list,
|
|
114
|
+
.nw-schema ul {
|
|
115
|
+
list-style: none;
|
|
116
|
+
padding-left: 0;
|
|
117
|
+
}
|
|
118
|
+
.nw-value-list > li {
|
|
119
|
+
border-left: 2px solid var(--border);
|
|
120
|
+
padding-left: 0.7rem;
|
|
121
|
+
margin: 0.25rem 0;
|
|
122
|
+
}
|
|
123
|
+
.nw-tag {
|
|
124
|
+
display: inline-flex;
|
|
125
|
+
padding: 1px 7px;
|
|
126
|
+
border-radius: 4px;
|
|
127
|
+
background: var(--muted);
|
|
128
|
+
color: var(--muted-foreground);
|
|
129
|
+
font: 500 11px/1.6 system-ui;
|
|
130
|
+
}
|
|
131
|
+
.nw-tag[data-tone="green"],
|
|
132
|
+
.nw-number {
|
|
133
|
+
color: var(--state-done);
|
|
134
|
+
}
|
|
135
|
+
.nw-tag[data-tone="blue"] {
|
|
136
|
+
color: var(--state-running);
|
|
137
|
+
background: color-mix(in srgb, var(--state-running) 10%, transparent);
|
|
138
|
+
}
|
|
139
|
+
.nw-schema {
|
|
140
|
+
min-width: 0;
|
|
141
|
+
}
|
|
142
|
+
.nw-schema > p {
|
|
143
|
+
color: var(--muted-foreground);
|
|
144
|
+
font-size: 13px;
|
|
145
|
+
margin: 3px 0 6px;
|
|
146
|
+
}
|
|
147
|
+
.nw-schema li {
|
|
148
|
+
padding: 9px 0 9px 12px;
|
|
149
|
+
border-left: 2px solid var(--border);
|
|
150
|
+
margin: 7px 0;
|
|
151
|
+
}
|
|
152
|
+
.nw-field-heading {
|
|
153
|
+
display: flex;
|
|
154
|
+
align-items: baseline;
|
|
155
|
+
gap: 8px;
|
|
156
|
+
flex-wrap: wrap;
|
|
157
|
+
}
|
|
158
|
+
.nw-field-heading strong {
|
|
159
|
+
font: 600 14px/1.4 system-ui;
|
|
160
|
+
}
|
|
161
|
+
.nw-field-heading small,
|
|
162
|
+
.nw-field-rule {
|
|
163
|
+
font-size: 12px;
|
|
164
|
+
}
|
|
165
|
+
.nw-field-rule {
|
|
166
|
+
display: inline-flex;
|
|
167
|
+
align-items: baseline;
|
|
168
|
+
gap: 5px;
|
|
169
|
+
margin: 2px 12px 2px 0;
|
|
170
|
+
}
|
|
171
|
+
.nw-field-rule b {
|
|
172
|
+
color: var(--foreground);
|
|
173
|
+
}
|
|
174
|
+
.nw-more,
|
|
175
|
+
.nw-fold > summary,
|
|
176
|
+
.nw-url {
|
|
177
|
+
color: var(--primary);
|
|
178
|
+
}
|
|
179
|
+
.nw-schema-child {
|
|
180
|
+
padding-left: 12px;
|
|
181
|
+
border-left: 1px solid var(--border);
|
|
182
|
+
margin-top: 5px;
|
|
183
|
+
}
|
package/src/theme.css
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
@import "./page-layout.css";
|
|
2
|
+
@import "./execution-track.css";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* The cockpit theme: design tokens as CSS variables, mapped into Tailwind.
|
|
6
|
+
*
|
|
7
|
+
* The application imports Tailwind first and this file after it. Modules built
|
|
8
|
+
* on the cockpit use the same token names (`bg-background`, `text-muted-foreground`,
|
|
9
|
+
* `border-border`, the `state-*` colours), so a module looks native without
|
|
10
|
+
* shipping colours of its own.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
@source "./";
|
|
14
|
+
@source "../node_modules/streamdown/dist/*.js";
|
|
15
|
+
|
|
16
|
+
@custom-variant dark (&:is(.dark *));
|
|
17
|
+
|
|
18
|
+
:root {
|
|
19
|
+
--radius: 0.625rem;
|
|
20
|
+
--background: oklch(1 0 0);
|
|
21
|
+
--foreground: oklch(0.145 0 0);
|
|
22
|
+
--card: oklch(1 0 0);
|
|
23
|
+
--card-foreground: oklch(0.145 0 0);
|
|
24
|
+
--popover: oklch(1 0 0);
|
|
25
|
+
--popover-foreground: oklch(0.145 0 0);
|
|
26
|
+
--primary: oklch(0.205 0 0);
|
|
27
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
28
|
+
--secondary: oklch(0.97 0 0);
|
|
29
|
+
--secondary-foreground: oklch(0.205 0 0);
|
|
30
|
+
--muted: oklch(0.97 0 0);
|
|
31
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
32
|
+
--accent: oklch(0.97 0 0);
|
|
33
|
+
--accent-foreground: oklch(0.205 0 0);
|
|
34
|
+
--destructive: oklch(0.577 0.245 27.325);
|
|
35
|
+
--border: oklch(0.922 0 0);
|
|
36
|
+
--input: oklch(0.922 0 0);
|
|
37
|
+
--ring: oklch(0.708 0 0);
|
|
38
|
+
|
|
39
|
+
/* States of runs, steps, sessions and requests. */
|
|
40
|
+
--state-running: oklch(0.62 0.17 250);
|
|
41
|
+
--state-waiting: oklch(0.75 0.16 75);
|
|
42
|
+
--state-done: oklch(0.63 0.15 150);
|
|
43
|
+
--state-failed: oklch(0.577 0.245 27.325);
|
|
44
|
+
--state-idle: oklch(0.708 0 0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.dark {
|
|
48
|
+
--background: oklch(0.145 0 0);
|
|
49
|
+
--foreground: oklch(0.985 0 0);
|
|
50
|
+
--card: oklch(0.205 0 0);
|
|
51
|
+
--card-foreground: oklch(0.985 0 0);
|
|
52
|
+
--popover: oklch(0.205 0 0);
|
|
53
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
54
|
+
--primary: oklch(0.922 0 0);
|
|
55
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
56
|
+
--secondary: oklch(0.269 0 0);
|
|
57
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
58
|
+
--muted: oklch(0.269 0 0);
|
|
59
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
60
|
+
--accent: oklch(0.269 0 0);
|
|
61
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
62
|
+
--destructive: oklch(0.704 0.191 22.216);
|
|
63
|
+
--border: oklch(1 0 0 / 10%);
|
|
64
|
+
--input: oklch(1 0 0 / 15%);
|
|
65
|
+
--ring: oklch(0.556 0 0);
|
|
66
|
+
|
|
67
|
+
--state-running: oklch(0.7 0.15 250);
|
|
68
|
+
--state-waiting: oklch(0.8 0.15 80);
|
|
69
|
+
--state-done: oklch(0.72 0.15 150);
|
|
70
|
+
--state-failed: oklch(0.704 0.191 22.216);
|
|
71
|
+
--state-idle: oklch(0.556 0 0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@theme inline {
|
|
75
|
+
--font-sans: ui-sans-serif, system-ui, sans-serif;
|
|
76
|
+
--font-mono: ui-monospace, "SF Mono", Menlo, monospace;
|
|
77
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
78
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
79
|
+
--radius-lg: var(--radius);
|
|
80
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
81
|
+
--color-background: var(--background);
|
|
82
|
+
--color-foreground: var(--foreground);
|
|
83
|
+
--color-card: var(--card);
|
|
84
|
+
--color-card-foreground: var(--card-foreground);
|
|
85
|
+
--color-popover: var(--popover);
|
|
86
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
87
|
+
--color-primary: var(--primary);
|
|
88
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
89
|
+
--color-secondary: var(--secondary);
|
|
90
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
91
|
+
--color-muted: var(--muted);
|
|
92
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
93
|
+
--color-accent: var(--accent);
|
|
94
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
95
|
+
--color-destructive: var(--destructive);
|
|
96
|
+
--color-border: var(--border);
|
|
97
|
+
--color-input: var(--input);
|
|
98
|
+
--color-ring: var(--ring);
|
|
99
|
+
--color-state-running: var(--state-running);
|
|
100
|
+
--color-state-waiting: var(--state-waiting);
|
|
101
|
+
--color-state-done: var(--state-done);
|
|
102
|
+
--color-state-failed: var(--state-failed);
|
|
103
|
+
--color-state-idle: var(--state-idle);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* A moving highlight over the text of a step that is running. */
|
|
107
|
+
@utility shimmer {
|
|
108
|
+
background: linear-gradient(90deg, currentColor 40%, var(--foreground) 50%, currentColor 60%) 0 0 / 200% 100%;
|
|
109
|
+
background-clip: text;
|
|
110
|
+
color: transparent;
|
|
111
|
+
animation: shimmer 2s linear infinite;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@utility shimmer-none {
|
|
115
|
+
animation: none;
|
|
116
|
+
background: none;
|
|
117
|
+
color: inherit;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@keyframes shimmer {
|
|
121
|
+
from {
|
|
122
|
+
background-position: 100% 0;
|
|
123
|
+
}
|
|
124
|
+
to {
|
|
125
|
+
background-position: -100% 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@layer base {
|
|
130
|
+
* {
|
|
131
|
+
@apply border-border outline-ring/50;
|
|
132
|
+
}
|
|
133
|
+
body {
|
|
134
|
+
@apply bg-background text-foreground;
|
|
135
|
+
}
|
|
136
|
+
}
|
package/src/ui/badge.tsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/cn.ts";
|
|
6
|
+
|
|
7
|
+
export const badgeVariants = cva(
|
|
8
|
+
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 [&>svg]:pointer-events-none [&>svg]:size-3!",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
|
13
|
+
secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
|
|
14
|
+
destructive: "bg-destructive/10 text-destructive dark:bg-destructive/20 [a]:hover:bg-destructive/20",
|
|
15
|
+
outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
|
|
16
|
+
ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: { variant: "default" },
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export type BadgeProps = useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>;
|
|
24
|
+
|
|
25
|
+
export function Badge({ className, variant = "default", render, ...props }: BadgeProps) {
|
|
26
|
+
return useRender({
|
|
27
|
+
defaultTagName: "span",
|
|
28
|
+
props: mergeProps<"span">({ className: cn(badgeVariants({ variant }), className) }, props),
|
|
29
|
+
render,
|
|
30
|
+
state: { slot: "badge", variant },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
|
|
4
|
+
import { cn } from "../lib/cn.ts";
|
|
5
|
+
|
|
6
|
+
export const buttonVariants = cva(
|
|
7
|
+
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
12
|
+
outline:
|
|
13
|
+
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
14
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
15
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted dark:hover:bg-muted/50",
|
|
16
|
+
destructive:
|
|
17
|
+
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30",
|
|
18
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
19
|
+
},
|
|
20
|
+
size: {
|
|
21
|
+
default: "h-8 gap-1.5 px-2.5",
|
|
22
|
+
xs: "h-6 gap-1 rounded-md px-2 text-xs [&_svg:not([class*='size-'])]:size-3",
|
|
23
|
+
sm: "h-7 gap-1 rounded-md px-2.5 text-[0.8rem] [&_svg:not([class*='size-'])]:size-3.5",
|
|
24
|
+
lg: "h-9 gap-1.5 px-2.5",
|
|
25
|
+
icon: "size-8",
|
|
26
|
+
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3.5",
|
|
27
|
+
"icon-sm": "size-7 rounded-md",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: { variant: "default", size: "default" },
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export type ButtonProps = ButtonPrimitive.Props & VariantProps<typeof buttonVariants>;
|
|
35
|
+
|
|
36
|
+
export function Button({ className, variant = "default", size = "default", ...props }: ButtonProps) {
|
|
37
|
+
return <ButtonPrimitive data-slot="button" className={cn(buttonVariants({ variant, size, className }))} {...props} />;
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible";
|
|
2
|
+
|
|
3
|
+
export function Collapsible(props: CollapsiblePrimitive.Root.Props) {
|
|
4
|
+
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function CollapsibleTrigger(props: CollapsiblePrimitive.Trigger.Props) {
|
|
8
|
+
return <CollapsiblePrimitive.Trigger data-slot="collapsible-trigger" {...props} />;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function CollapsibleContent(props: CollapsiblePrimitive.Panel.Props) {
|
|
12
|
+
return <CollapsiblePrimitive.Panel data-slot="collapsible-content" {...props} />;
|
|
13
|
+
}
|