@open-elements/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 +201 -0
- package/README.md +37 -0
- package/dist/brand.css +48 -0
- package/dist/components/alert-dialog.d.ts +19 -0
- package/dist/components/alert-dialog.d.ts.map +1 -0
- package/dist/components/alert-dialog.js +66 -0
- package/dist/components/alert-dialog.js.map +1 -0
- package/dist/components/badge.d.ts +10 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +37 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/button.d.ts +11 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +48 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/calendar.d.ts +9 -0
- package/dist/components/calendar.d.ts.map +1 -0
- package/dist/components/calendar.js +58 -0
- package/dist/components/calendar.js.map +1 -0
- package/dist/components/card.d.ts +10 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +43 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/combobox.d.ts +25 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +85 -0
- package/dist/components/combobox.js.map +1 -0
- package/dist/components/dialog.d.ts +18 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +59 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/health-status.d.ts +12 -0
- package/dist/components/health-status.d.ts.map +1 -0
- package/dist/components/health-status.js +8 -0
- package/dist/components/health-status.js.map +1 -0
- package/dist/components/input-group.d.ts +17 -0
- package/dist/components/input-group.d.ts.map +1 -0
- package/dist/components/input-group.js +82 -0
- package/dist/components/input-group.js.map +1 -0
- package/dist/components/input.d.ts +4 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +19 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/label.d.ts +5 -0
- package/dist/components/label.d.ts.map +1 -0
- package/dist/components/label.js +21 -0
- package/dist/components/label.js.map +1 -0
- package/dist/components/language-switch.d.ts +2 -0
- package/dist/components/language-switch.d.ts.map +1 -0
- package/dist/components/language-switch.js +13 -0
- package/dist/components/language-switch.js.map +1 -0
- package/dist/components/popover.d.ts +11 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +45 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/select.d.ts +16 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +60 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/separator.d.ts +5 -0
- package/dist/components/separator.d.ts.map +1 -0
- package/dist/components/separator.js +21 -0
- package/dist/components/separator.js.map +1 -0
- package/dist/components/sheet.d.ts +15 -0
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +62 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/sidebar.d.ts +53 -0
- package/dist/components/sidebar.d.ts.map +1 -0
- package/dist/components/sidebar.js +44 -0
- package/dist/components/sidebar.js.map +1 -0
- package/dist/components/skeleton.d.ts +3 -0
- package/dist/components/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton.js +19 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/table.d.ts +11 -0
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +48 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tag-chips.d.ts +8 -0
- package/dist/components/tag-chips.d.ts.map +1 -0
- package/dist/components/tag-chips.js +22 -0
- package/dist/components/tag-chips.js.map +1 -0
- package/dist/components/tag-form.d.ts +29 -0
- package/dist/components/tag-form.d.ts.map +1 -0
- package/dist/components/tag-form.js +84 -0
- package/dist/components/tag-form.js.map +1 -0
- package/dist/components/tag-multi-select.d.ts +4 -0
- package/dist/components/tag-multi-select.d.ts.map +1 -0
- package/dist/components/tag-multi-select.js +30 -0
- package/dist/components/tag-multi-select.js.map +1 -0
- package/dist/components/textarea.d.ts +4 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +19 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/tooltip.d.ts +8 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +26 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/i18n/de.d.ts +7 -0
- package/dist/i18n/de.d.ts.map +1 -0
- package/dist/i18n/de.js +7 -0
- package/dist/i18n/de.js.map +1 -0
- package/dist/i18n/en.d.ts +7 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +7 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/language-context.d.ts +14 -0
- package/dist/i18n/language-context.d.ts.map +1 -0
- package/dist/i18n/language-context.js +77 -0
- package/dist/i18n/language-context.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +77 -0
- package/src/components/__tests__/button.test.tsx +41 -0
- package/src/components/__tests__/input.test.tsx +28 -0
- package/src/components/__tests__/tag-multi-select.test.tsx +131 -0
- package/src/components/__tests__/textarea.test.tsx +22 -0
- package/src/components/alert-dialog.tsx +179 -0
- package/src/components/badge.tsx +46 -0
- package/src/components/button.tsx +62 -0
- package/src/components/calendar.tsx +180 -0
- package/src/components/card.tsx +75 -0
- package/src/components/combobox.tsx +277 -0
- package/src/components/dialog.tsx +144 -0
- package/src/components/health-status.tsx +37 -0
- package/src/components/input-group.tsx +158 -0
- package/src/components/input.tsx +21 -0
- package/src/components/label.tsx +21 -0
- package/src/components/language-switch.tsx +36 -0
- package/src/components/popover.tsx +74 -0
- package/src/components/select.tsx +175 -0
- package/src/components/separator.tsx +28 -0
- package/src/components/sheet.tsx +134 -0
- package/src/components/sidebar.tsx +290 -0
- package/src/components/skeleton.tsx +13 -0
- package/src/components/table.tsx +92 -0
- package/src/components/tag-chips.tsx +47 -0
- package/src/components/tag-form.tsx +200 -0
- package/src/components/tag-multi-select.tsx +84 -0
- package/src/components/textarea.tsx +18 -0
- package/src/components/tooltip.tsx +32 -0
- package/src/i18n/de.ts +6 -0
- package/src/i18n/en.ts +6 -0
- package/src/i18n/language-context.tsx +104 -0
- package/src/index.ts +156 -0
- package/src/lib/__tests__/utils.test.ts +29 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/brand.css +48 -0
- package/src/test/setup.ts +1 -0
- package/src/types/index.ts +29 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { ChevronDown, CircleUser, LayoutDashboard, LogOut, Menu } from "lucide-react";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import { Button } from "./button";
|
|
8
|
+
import { Tooltip, TooltipTrigger, TooltipContent } from "./tooltip";
|
|
9
|
+
import { Sheet, SheetContent, SheetTrigger, SheetTitle } from "./sheet";
|
|
10
|
+
import { LanguageSwitch } from "./language-switch";
|
|
11
|
+
|
|
12
|
+
// --- NavItem ---
|
|
13
|
+
|
|
14
|
+
interface NavItemProps {
|
|
15
|
+
readonly href: string;
|
|
16
|
+
readonly icon: React.ReactNode;
|
|
17
|
+
readonly label: string;
|
|
18
|
+
readonly active?: boolean;
|
|
19
|
+
readonly indented?: boolean;
|
|
20
|
+
readonly onClick?: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function NavItem({ href, icon, label, active, indented, onClick }: NavItemProps) {
|
|
24
|
+
return (
|
|
25
|
+
<a
|
|
26
|
+
href={href}
|
|
27
|
+
onClick={onClick}
|
|
28
|
+
className={cn(
|
|
29
|
+
"flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors",
|
|
30
|
+
indented && "pl-10",
|
|
31
|
+
active
|
|
32
|
+
? "bg-oe-green/20 text-oe-green"
|
|
33
|
+
: "text-oe-white/70 hover:bg-oe-white/10 hover:text-oe-white",
|
|
34
|
+
)}
|
|
35
|
+
>
|
|
36
|
+
{icon}
|
|
37
|
+
{label}
|
|
38
|
+
</a>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// --- CollapsibleGroup ---
|
|
43
|
+
|
|
44
|
+
interface CollapsibleGroupProps {
|
|
45
|
+
readonly icon: React.ReactNode;
|
|
46
|
+
readonly label: string;
|
|
47
|
+
readonly defaultOpen?: boolean;
|
|
48
|
+
readonly active?: boolean;
|
|
49
|
+
readonly children: React.ReactNode;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function CollapsibleGroup({
|
|
53
|
+
icon,
|
|
54
|
+
label,
|
|
55
|
+
defaultOpen = false,
|
|
56
|
+
active,
|
|
57
|
+
children,
|
|
58
|
+
}: CollapsibleGroupProps) {
|
|
59
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
onClick={() => setOpen((prev) => !prev)}
|
|
66
|
+
className={cn(
|
|
67
|
+
"flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors w-full text-left",
|
|
68
|
+
active ? "text-oe-white" : "text-oe-white/70 hover:bg-oe-white/10 hover:text-oe-white",
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
{icon}
|
|
72
|
+
{label}
|
|
73
|
+
<ChevronDown
|
|
74
|
+
className={cn("ml-auto h-4 w-4 transition-transform", open ? "rotate-0" : "-rotate-90")}
|
|
75
|
+
/>
|
|
76
|
+
</button>
|
|
77
|
+
{open && <div className="flex flex-col gap-1">{children}</div>}
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- UserSection ---
|
|
83
|
+
|
|
84
|
+
interface UserSectionTranslations {
|
|
85
|
+
readonly uploadAvatar: string;
|
|
86
|
+
readonly logout: string;
|
|
87
|
+
readonly noRoles: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface UserSectionProps {
|
|
91
|
+
readonly userName: string;
|
|
92
|
+
readonly avatarUrl?: string;
|
|
93
|
+
readonly roles?: readonly string[];
|
|
94
|
+
readonly onAvatarClick?: () => void;
|
|
95
|
+
readonly onLogout: () => void;
|
|
96
|
+
readonly translations: UserSectionTranslations;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function UserSection({
|
|
100
|
+
userName,
|
|
101
|
+
avatarUrl,
|
|
102
|
+
roles,
|
|
103
|
+
onAvatarClick,
|
|
104
|
+
onLogout,
|
|
105
|
+
translations: t,
|
|
106
|
+
}: UserSectionProps) {
|
|
107
|
+
return (
|
|
108
|
+
<div className="border-t border-oe-white/10 px-6 py-4">
|
|
109
|
+
<div className="flex items-center gap-3">
|
|
110
|
+
<Tooltip>
|
|
111
|
+
<TooltipTrigger asChild>
|
|
112
|
+
<button type="button" onClick={onAvatarClick} className="shrink-0">
|
|
113
|
+
{avatarUrl ? (
|
|
114
|
+
<img src={avatarUrl} alt={userName} className="h-8 w-8 rounded-full object-cover" />
|
|
115
|
+
) : (
|
|
116
|
+
<CircleUser className="h-8 w-8 text-oe-gray-light" />
|
|
117
|
+
)}
|
|
118
|
+
</button>
|
|
119
|
+
</TooltipTrigger>
|
|
120
|
+
<TooltipContent>{t.uploadAvatar}</TooltipContent>
|
|
121
|
+
</Tooltip>
|
|
122
|
+
<div className="flex-1 min-w-0">
|
|
123
|
+
<Tooltip>
|
|
124
|
+
<TooltipTrigger asChild>
|
|
125
|
+
<p className="text-sm font-medium text-oe-white truncate cursor-default">
|
|
126
|
+
{userName}
|
|
127
|
+
</p>
|
|
128
|
+
</TooltipTrigger>
|
|
129
|
+
<TooltipContent>
|
|
130
|
+
{roles && roles.length > 0 ? roles.join(", ") : t.noRoles}
|
|
131
|
+
</TooltipContent>
|
|
132
|
+
</Tooltip>
|
|
133
|
+
</div>
|
|
134
|
+
<Tooltip>
|
|
135
|
+
<TooltipTrigger asChild>
|
|
136
|
+
<Button
|
|
137
|
+
variant="ghost"
|
|
138
|
+
size="icon"
|
|
139
|
+
className="text-oe-white/70 hover:bg-oe-white/10 hover:text-oe-white"
|
|
140
|
+
onClick={onLogout}
|
|
141
|
+
>
|
|
142
|
+
<LogOut className="h-4 w-4" />
|
|
143
|
+
</Button>
|
|
144
|
+
</TooltipTrigger>
|
|
145
|
+
<TooltipContent>{t.logout}</TooltipContent>
|
|
146
|
+
</Tooltip>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// --- SidebarHeader ---
|
|
153
|
+
|
|
154
|
+
interface SidebarHeaderProps {
|
|
155
|
+
readonly appTitle: string;
|
|
156
|
+
readonly logoIcon?: React.ReactNode;
|
|
157
|
+
readonly homeHref?: string;
|
|
158
|
+
readonly developedByText?: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function SidebarHeader({
|
|
162
|
+
appTitle,
|
|
163
|
+
logoIcon,
|
|
164
|
+
homeHref = "/",
|
|
165
|
+
developedByText = "Developed by",
|
|
166
|
+
}: SidebarHeaderProps) {
|
|
167
|
+
return (
|
|
168
|
+
<div className="border-b border-oe-white/10 px-6 py-4">
|
|
169
|
+
<a href={homeHref} className="flex items-center gap-3">
|
|
170
|
+
{logoIcon ?? <LayoutDashboard className="h-6 w-6 text-oe-green" />}
|
|
171
|
+
<span className="font-heading text-lg font-bold text-oe-white">{appTitle}</span>
|
|
172
|
+
</a>
|
|
173
|
+
<a
|
|
174
|
+
href="https://open-elements.com"
|
|
175
|
+
target="_blank"
|
|
176
|
+
rel="noopener noreferrer"
|
|
177
|
+
className="mt-2 flex items-center gap-2 opacity-70 hover:opacity-100 transition-opacity"
|
|
178
|
+
>
|
|
179
|
+
<span className="text-xs text-oe-gray-light">{developedByText}</span>
|
|
180
|
+
<img src="/oe-logo-landscape-dark.svg" alt="Open Elements" className="h-4" />
|
|
181
|
+
</a>
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// --- Sidebar ---
|
|
187
|
+
|
|
188
|
+
interface SidebarProps {
|
|
189
|
+
readonly appTitle: string;
|
|
190
|
+
readonly header?: React.ReactNode;
|
|
191
|
+
readonly user?: UserSectionProps;
|
|
192
|
+
readonly children: React.ReactNode;
|
|
193
|
+
readonly bottomChildren?: React.ReactNode;
|
|
194
|
+
readonly menuLabel?: string;
|
|
195
|
+
readonly homeHref?: string;
|
|
196
|
+
readonly developedByText?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function Sidebar({
|
|
200
|
+
appTitle,
|
|
201
|
+
header,
|
|
202
|
+
user,
|
|
203
|
+
children,
|
|
204
|
+
bottomChildren,
|
|
205
|
+
menuLabel = "Menu",
|
|
206
|
+
homeHref,
|
|
207
|
+
developedByText,
|
|
208
|
+
}: SidebarProps) {
|
|
209
|
+
const [open, setOpen] = useState(false);
|
|
210
|
+
|
|
211
|
+
const headerContent = header ?? (
|
|
212
|
+
<SidebarHeader appTitle={appTitle} homeHref={homeHref} developedByText={developedByText} />
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const bottomSection = (
|
|
216
|
+
<div>
|
|
217
|
+
<div className="border-t border-oe-white/10 px-6 py-4">
|
|
218
|
+
<LanguageSwitch />
|
|
219
|
+
</div>
|
|
220
|
+
{user && <UserSection {...user} />}
|
|
221
|
+
</div>
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<>
|
|
226
|
+
{/* Desktop sidebar */}
|
|
227
|
+
<aside className="hidden md:flex md:w-64 md:flex-col md:fixed md:inset-y-0 bg-oe-dark">
|
|
228
|
+
{headerContent}
|
|
229
|
+
<div className="flex flex-1 flex-col">
|
|
230
|
+
<nav className="flex flex-col gap-1 px-3 py-4">{children}</nav>
|
|
231
|
+
{bottomChildren && (
|
|
232
|
+
<div className="mt-auto flex flex-col gap-1 px-3 pb-2">{bottomChildren}</div>
|
|
233
|
+
)}
|
|
234
|
+
</div>
|
|
235
|
+
{bottomSection}
|
|
236
|
+
</aside>
|
|
237
|
+
|
|
238
|
+
{/* Mobile header + hamburger */}
|
|
239
|
+
<header className="flex md:hidden h-14 items-center border-b border-oe-gray-light bg-oe-dark px-4">
|
|
240
|
+
<Sheet open={open} onOpenChange={setOpen}>
|
|
241
|
+
<Tooltip>
|
|
242
|
+
<TooltipTrigger asChild>
|
|
243
|
+
<SheetTrigger asChild>
|
|
244
|
+
<Button variant="ghost" size="icon" className="text-oe-white hover:bg-oe-white/10">
|
|
245
|
+
<Menu className="h-6 w-6" />
|
|
246
|
+
<span className="sr-only">{menuLabel}</span>
|
|
247
|
+
</Button>
|
|
248
|
+
</SheetTrigger>
|
|
249
|
+
</TooltipTrigger>
|
|
250
|
+
<TooltipContent>{menuLabel}</TooltipContent>
|
|
251
|
+
</Tooltip>
|
|
252
|
+
<SheetContent side="left" className="w-64 bg-oe-dark p-0 border-none flex flex-col">
|
|
253
|
+
<SheetTitle className="sr-only">Navigation</SheetTitle>
|
|
254
|
+
{headerContent}
|
|
255
|
+
<div className="flex flex-1 flex-col">
|
|
256
|
+
<nav className="flex flex-col gap-1 px-3 py-4">
|
|
257
|
+
{React.Children.map(children, (child) => {
|
|
258
|
+
if (React.isValidElement<NavItemProps>(child) && child.type === NavItem) {
|
|
259
|
+
return React.cloneElement(child, {
|
|
260
|
+
onClick: () => {
|
|
261
|
+
child.props.onClick?.();
|
|
262
|
+
setOpen(false);
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return child;
|
|
267
|
+
})}
|
|
268
|
+
</nav>
|
|
269
|
+
{bottomChildren && (
|
|
270
|
+
<div className="mt-auto flex flex-col gap-1 px-3 pb-2">{bottomChildren}</div>
|
|
271
|
+
)}
|
|
272
|
+
</div>
|
|
273
|
+
{bottomSection}
|
|
274
|
+
</SheetContent>
|
|
275
|
+
</Sheet>
|
|
276
|
+
<span className="ml-3 font-heading text-lg font-bold text-oe-white">{appTitle}</span>
|
|
277
|
+
</header>
|
|
278
|
+
</>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export { Sidebar, SidebarHeader, NavItem, CollapsibleGroup, UserSection };
|
|
283
|
+
export type {
|
|
284
|
+
SidebarProps,
|
|
285
|
+
SidebarHeaderProps,
|
|
286
|
+
NavItemProps,
|
|
287
|
+
CollapsibleGroupProps,
|
|
288
|
+
UserSectionProps,
|
|
289
|
+
UserSectionTranslations,
|
|
290
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cn } from "../lib/utils";
|
|
2
|
+
|
|
3
|
+
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
|
4
|
+
return (
|
|
5
|
+
<div
|
|
6
|
+
data-slot="skeleton"
|
|
7
|
+
className={cn("animate-pulse rounded-md bg-accent", className)}
|
|
8
|
+
{...props}
|
|
9
|
+
/>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { Skeleton };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/utils";
|
|
6
|
+
|
|
7
|
+
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
|
8
|
+
return (
|
|
9
|
+
<div data-slot="table-container" className="relative w-full overflow-x-auto">
|
|
10
|
+
<table
|
|
11
|
+
data-slot="table"
|
|
12
|
+
className={cn("w-full caption-bottom text-sm", className)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
|
20
|
+
return <thead data-slot="table-header" className={cn("[&_tr]:border-b", className)} {...props} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
|
24
|
+
return (
|
|
25
|
+
<tbody
|
|
26
|
+
data-slot="table-body"
|
|
27
|
+
className={cn("[&_tr:last-child]:border-0", className)}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
|
34
|
+
return (
|
|
35
|
+
<tfoot
|
|
36
|
+
data-slot="table-footer"
|
|
37
|
+
className={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className)}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
|
44
|
+
return (
|
|
45
|
+
<tr
|
|
46
|
+
data-slot="table-row"
|
|
47
|
+
className={cn(
|
|
48
|
+
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
|
49
|
+
className,
|
|
50
|
+
)}
|
|
51
|
+
{...props}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
|
57
|
+
return (
|
|
58
|
+
<th
|
|
59
|
+
data-slot="table-head"
|
|
60
|
+
className={cn(
|
|
61
|
+
"h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
{...props}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
|
70
|
+
return (
|
|
71
|
+
<td
|
|
72
|
+
data-slot="table-cell"
|
|
73
|
+
className={cn(
|
|
74
|
+
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
|
75
|
+
className,
|
|
76
|
+
)}
|
|
77
|
+
{...props}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function TableCaption({ className, ...props }: React.ComponentProps<"caption">) {
|
|
83
|
+
return (
|
|
84
|
+
<caption
|
|
85
|
+
data-slot="table-caption"
|
|
86
|
+
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
|
87
|
+
{...props}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { TagDto } from "../types";
|
|
4
|
+
|
|
5
|
+
function getContrastColor(hex: string): string {
|
|
6
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
7
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
8
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
9
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
10
|
+
return luminance > 0.5 ? "#1A1A1A" : "#FFFFFF";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isValidHex(color: string): boolean {
|
|
14
|
+
return /^#[0-9A-Fa-f]{6}$/.test(color);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface TagChipsProps {
|
|
18
|
+
readonly tags: readonly TagDto[];
|
|
19
|
+
readonly label?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function TagChips({ tags, label }: TagChipsProps) {
|
|
23
|
+
if (tags.length === 0) return null;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className="mt-4">
|
|
27
|
+
{label && <h3 className="mb-2 text-sm font-medium text-oe-gray">{label}</h3>}
|
|
28
|
+
<div className="flex flex-wrap gap-2">
|
|
29
|
+
{tags.map((tag) => {
|
|
30
|
+
const bgColor = isValidHex(tag.color) ? tag.color : "#6B7280";
|
|
31
|
+
const textColor = isValidHex(tag.color) ? getContrastColor(tag.color) : "#FFFFFF";
|
|
32
|
+
return (
|
|
33
|
+
<span
|
|
34
|
+
key={tag.id}
|
|
35
|
+
className="inline-flex items-center rounded-full px-3 py-1 text-xs font-medium"
|
|
36
|
+
style={{ backgroundColor: bgColor, color: textColor }}
|
|
37
|
+
>
|
|
38
|
+
{tag.name}
|
|
39
|
+
</span>
|
|
40
|
+
);
|
|
41
|
+
})}
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type { TagChipsProps };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Check } from "lucide-react";
|
|
5
|
+
import { cn } from "../lib/utils";
|
|
6
|
+
import { Button } from "./button";
|
|
7
|
+
import { Input } from "./input";
|
|
8
|
+
import { Textarea } from "./textarea";
|
|
9
|
+
import { Label } from "./label";
|
|
10
|
+
import { Card, CardContent, CardHeader, CardTitle } from "./card";
|
|
11
|
+
import type { TagDto } from "../types";
|
|
12
|
+
|
|
13
|
+
const PALETTE_COLORS = [
|
|
14
|
+
"#EF4444",
|
|
15
|
+
"#F97316",
|
|
16
|
+
"#F59E0B",
|
|
17
|
+
"#EAB308",
|
|
18
|
+
"#84CC16",
|
|
19
|
+
"#22C55E",
|
|
20
|
+
"#14B8A6",
|
|
21
|
+
"#06B6D4",
|
|
22
|
+
"#3B82F6",
|
|
23
|
+
"#6366F1",
|
|
24
|
+
"#A855F7",
|
|
25
|
+
"#EC4899",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const HEX_REGEX = /^#[0-9A-Fa-f]{6}$/;
|
|
29
|
+
|
|
30
|
+
function getContrastColor(hex: string): string {
|
|
31
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
32
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
33
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
34
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
35
|
+
return luminance > 0.5 ? "#1A1A1A" : "#FFFFFF";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface TagFormTranslations {
|
|
39
|
+
readonly title: string;
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly nameRequired: string;
|
|
42
|
+
readonly namePlaceholder: string;
|
|
43
|
+
readonly nameConflict: string;
|
|
44
|
+
readonly description: string;
|
|
45
|
+
readonly descriptionPlaceholder: string;
|
|
46
|
+
readonly color: string;
|
|
47
|
+
readonly colorRequired: string;
|
|
48
|
+
readonly colorInvalid: string;
|
|
49
|
+
readonly colorPlaceholder: string;
|
|
50
|
+
readonly save: string;
|
|
51
|
+
readonly cancel: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface TagFormProps {
|
|
55
|
+
readonly tag?: TagDto;
|
|
56
|
+
readonly onSave: (data: {
|
|
57
|
+
name: string;
|
|
58
|
+
description: string | null;
|
|
59
|
+
color: string;
|
|
60
|
+
}) => Promise<void>;
|
|
61
|
+
readonly onCancel: () => void;
|
|
62
|
+
readonly translations: TagFormTranslations;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function TagForm({ tag, onSave, onCancel, translations: t }: TagFormProps) {
|
|
66
|
+
const [name, setName] = useState(tag?.name ?? "");
|
|
67
|
+
const [description, setDescription] = useState(tag?.description ?? "");
|
|
68
|
+
const [color, setColor] = useState(tag?.color ?? "");
|
|
69
|
+
const [submitting, setSubmitting] = useState(false);
|
|
70
|
+
const [errors, setErrors] = useState<{ name?: string; color?: string }>({});
|
|
71
|
+
|
|
72
|
+
function validate(): boolean {
|
|
73
|
+
const newErrors: { name?: string; color?: string } = {};
|
|
74
|
+
if (!name.trim()) {
|
|
75
|
+
newErrors.name = t.nameRequired;
|
|
76
|
+
}
|
|
77
|
+
if (!color.trim()) {
|
|
78
|
+
newErrors.color = t.colorRequired;
|
|
79
|
+
} else if (!HEX_REGEX.test(color)) {
|
|
80
|
+
newErrors.color = t.colorInvalid;
|
|
81
|
+
}
|
|
82
|
+
setErrors(newErrors);
|
|
83
|
+
return Object.keys(newErrors).length === 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
if (!validate()) return;
|
|
89
|
+
setSubmitting(true);
|
|
90
|
+
try {
|
|
91
|
+
await onSave({ name: name.trim(), description: description.trim() || null, color });
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (err instanceof Error && err.message === "CONFLICT") {
|
|
94
|
+
setErrors({ name: t.nameConflict });
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
setSubmitting(false);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<div className="mx-auto max-w-2xl">
|
|
103
|
+
<h1 className="mb-6 font-heading text-2xl font-bold text-oe-dark">{t.title}</h1>
|
|
104
|
+
<Card>
|
|
105
|
+
<CardHeader>
|
|
106
|
+
<CardTitle>{t.title}</CardTitle>
|
|
107
|
+
</CardHeader>
|
|
108
|
+
<CardContent>
|
|
109
|
+
<form onSubmit={handleSubmit} className="space-y-6">
|
|
110
|
+
<div className="space-y-2">
|
|
111
|
+
<Label htmlFor="name">{t.name} *</Label>
|
|
112
|
+
<Input
|
|
113
|
+
id="name"
|
|
114
|
+
value={name}
|
|
115
|
+
onChange={(e) => {
|
|
116
|
+
setName(e.target.value);
|
|
117
|
+
setErrors((prev) => ({ ...prev, name: undefined }));
|
|
118
|
+
}}
|
|
119
|
+
placeholder={t.namePlaceholder}
|
|
120
|
+
/>
|
|
121
|
+
{errors.name && <p className="text-sm text-oe-red">{errors.name}</p>}
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<div className="space-y-2">
|
|
125
|
+
<Label htmlFor="description">{t.description}</Label>
|
|
126
|
+
<Textarea
|
|
127
|
+
id="description"
|
|
128
|
+
value={description}
|
|
129
|
+
onChange={(e) => setDescription(e.target.value)}
|
|
130
|
+
placeholder={t.descriptionPlaceholder}
|
|
131
|
+
rows={3}
|
|
132
|
+
/>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div className="space-y-2">
|
|
136
|
+
<Label>{t.color} *</Label>
|
|
137
|
+
<div className="flex flex-wrap gap-2 mb-3">
|
|
138
|
+
{PALETTE_COLORS.map((c) => (
|
|
139
|
+
<button
|
|
140
|
+
key={c}
|
|
141
|
+
type="button"
|
|
142
|
+
className={cn(
|
|
143
|
+
"h-8 w-8 rounded-full border-2 flex items-center justify-center transition-all",
|
|
144
|
+
color.toUpperCase() === c.toUpperCase()
|
|
145
|
+
? "border-oe-dark scale-110"
|
|
146
|
+
: "border-transparent hover:border-oe-gray-light",
|
|
147
|
+
)}
|
|
148
|
+
style={{ backgroundColor: c }}
|
|
149
|
+
onClick={() => {
|
|
150
|
+
setColor(c);
|
|
151
|
+
setErrors((prev) => ({ ...prev, color: undefined }));
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
{color.toUpperCase() === c.toUpperCase() && (
|
|
155
|
+
<Check className="h-4 w-4" style={{ color: getContrastColor(c) }} />
|
|
156
|
+
)}
|
|
157
|
+
</button>
|
|
158
|
+
))}
|
|
159
|
+
</div>
|
|
160
|
+
<div className="flex items-center gap-3">
|
|
161
|
+
<Input
|
|
162
|
+
id="color"
|
|
163
|
+
value={color}
|
|
164
|
+
onChange={(e) => {
|
|
165
|
+
setColor(e.target.value);
|
|
166
|
+
setErrors((prev) => ({ ...prev, color: undefined }));
|
|
167
|
+
}}
|
|
168
|
+
placeholder={t.colorPlaceholder}
|
|
169
|
+
className="max-w-40"
|
|
170
|
+
/>
|
|
171
|
+
{HEX_REGEX.test(color) && (
|
|
172
|
+
<span
|
|
173
|
+
className="inline-block h-8 w-8 rounded-full border border-oe-gray-light"
|
|
174
|
+
style={{ backgroundColor: color }}
|
|
175
|
+
/>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
{errors.color && <p className="text-sm text-oe-red">{errors.color}</p>}
|
|
179
|
+
</div>
|
|
180
|
+
|
|
181
|
+
<div className="flex gap-3 pt-2">
|
|
182
|
+
<Button
|
|
183
|
+
type="submit"
|
|
184
|
+
disabled={submitting}
|
|
185
|
+
className="bg-oe-green hover:bg-oe-green/90 text-white"
|
|
186
|
+
>
|
|
187
|
+
{t.save}
|
|
188
|
+
</Button>
|
|
189
|
+
<Button type="button" variant="outline" onClick={onCancel}>
|
|
190
|
+
{t.cancel}
|
|
191
|
+
</Button>
|
|
192
|
+
</div>
|
|
193
|
+
</form>
|
|
194
|
+
</CardContent>
|
|
195
|
+
</Card>
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type { TagFormProps, TagFormTranslations };
|