@eutobias/serenojs 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +682 -2
  3. package/admin-dist/assets/index-B3EgqtT6.js +9 -0
  4. package/admin-dist/assets/index-D2m0Eb4k.css +2 -0
  5. package/admin-dist/index.html +17 -0
  6. package/dist/auth/auth.server.d.ts +31 -0
  7. package/dist/auth/auth.server.js +141 -0
  8. package/dist/auth/config.d.ts +32 -0
  9. package/dist/auth/config.js +25 -0
  10. package/dist/auth/cookies.server.d.ts +7 -0
  11. package/dist/auth/cookies.server.js +65 -0
  12. package/dist/auth/http.server.d.ts +8 -0
  13. package/dist/auth/http.server.js +30 -0
  14. package/dist/auth/password.server.d.ts +2 -0
  15. package/dist/auth/password.server.js +21 -0
  16. package/dist/auth/session.server.d.ts +2 -0
  17. package/dist/auth/session.server.js +14 -0
  18. package/dist/auth/users.server.d.ts +16 -0
  19. package/dist/auth/users.server.js +123 -0
  20. package/dist/config.d.ts +91 -0
  21. package/dist/config.js +39 -0
  22. package/dist/core/backup.server.d.ts +52 -0
  23. package/dist/core/backup.server.js +349 -0
  24. package/dist/core/db.server.d.ts +24 -0
  25. package/dist/core/db.server.js +526 -0
  26. package/dist/core/media.d.ts +22 -0
  27. package/dist/core/media.js +76 -0
  28. package/dist/core/media.server.d.ts +18 -0
  29. package/dist/core/media.server.js +102 -0
  30. package/dist/core/schema.d.ts +26 -0
  31. package/dist/core/schema.js +99 -0
  32. package/dist/core/types.d.ts +143 -0
  33. package/dist/core/types.js +1 -0
  34. package/dist/core/validation.d.ts +16 -0
  35. package/dist/core/validation.js +192 -0
  36. package/dist/locale.d.ts +2 -0
  37. package/dist/locale.js +14 -0
  38. package/dist/runtime.d.ts +8 -0
  39. package/dist/runtime.js +37 -0
  40. package/dist/server/app.d.ts +20 -0
  41. package/dist/server/app.js +661 -0
  42. package/dist/ui/admin/admin-shell.d.ts +16 -0
  43. package/dist/ui/admin/admin-shell.js +38 -0
  44. package/dist/ui/admin/backup-manager.d.ts +5 -0
  45. package/dist/ui/admin/backup-manager.js +165 -0
  46. package/dist/ui/admin/collection-icon.d.ts +22 -0
  47. package/dist/ui/admin/collection-icon.js +34 -0
  48. package/dist/ui/admin/collection-manager.d.ts +7 -0
  49. package/dist/ui/admin/collection-manager.js +212 -0
  50. package/dist/ui/admin/display.d.ts +7 -0
  51. package/dist/ui/admin/display.js +65 -0
  52. package/dist/ui/admin/field-control.d.ts +14 -0
  53. package/dist/ui/admin/field-control.js +58 -0
  54. package/dist/ui/admin/i18n.d.ts +27 -0
  55. package/dist/ui/admin/i18n.js +324 -0
  56. package/dist/ui/admin/item-form.d.ts +20 -0
  57. package/dist/ui/admin/item-form.js +60 -0
  58. package/dist/ui/admin/list-control.d.ts +13 -0
  59. package/dist/ui/admin/list-control.js +31 -0
  60. package/dist/ui/admin/locales.d.ts +4 -0
  61. package/dist/ui/admin/locales.js +8 -0
  62. package/dist/ui/admin/login-form.d.ts +3 -0
  63. package/dist/ui/admin/login-form.js +52 -0
  64. package/dist/ui/admin/media-control.d.ts +14 -0
  65. package/dist/ui/admin/media-control.js +74 -0
  66. package/dist/ui/admin/media-list-control.d.ts +14 -0
  67. package/dist/ui/admin/media-list-control.js +91 -0
  68. package/dist/ui/admin/pagination.d.ts +11 -0
  69. package/dist/ui/admin/pagination.js +14 -0
  70. package/dist/ui/admin/relation-control.d.ts +14 -0
  71. package/dist/ui/admin/relation-control.js +33 -0
  72. package/dist/ui/admin/router.d.ts +17 -0
  73. package/dist/ui/admin/router.js +58 -0
  74. package/dist/ui/admin/runtime.d.ts +28 -0
  75. package/dist/ui/admin/runtime.js +29 -0
  76. package/dist/ui/admin/sidebar.d.ts +13 -0
  77. package/dist/ui/admin/sidebar.js +29 -0
  78. package/dist/ui/admin/standalone-manager.d.ts +11 -0
  79. package/dist/ui/admin/standalone-manager.js +51 -0
  80. package/dist/ui/admin/table.d.ts +21 -0
  81. package/dist/ui/admin/table.js +23 -0
  82. package/dist/ui/admin/toast.d.ts +16 -0
  83. package/dist/ui/admin/toast.js +59 -0
  84. package/dist/ui/admin/users-manager.d.ts +6 -0
  85. package/dist/ui/admin/users-manager.js +157 -0
  86. package/dist/ui/badge.d.ts +9 -0
  87. package/dist/ui/badge.js +14 -0
  88. package/dist/ui/box.d.ts +17 -0
  89. package/dist/ui/box.js +14 -0
  90. package/dist/ui/button.d.ts +25 -0
  91. package/dist/ui/button.js +28 -0
  92. package/dist/ui/card.d.ts +45 -0
  93. package/dist/ui/card.js +49 -0
  94. package/dist/ui/container.d.ts +13 -0
  95. package/dist/ui/container.js +13 -0
  96. package/dist/ui/drawer.d.ts +15 -0
  97. package/dist/ui/drawer.js +31 -0
  98. package/dist/ui/field-wrapper.d.ts +15 -0
  99. package/dist/ui/field-wrapper.js +11 -0
  100. package/dist/ui/index.d.ts +8 -0
  101. package/dist/ui/index.js +8 -0
  102. package/dist/ui/text.d.ts +19 -0
  103. package/dist/ui/text.js +40 -0
  104. package/package.json +81 -3
  105. package/src/admin/app.tsx +371 -0
  106. package/src/admin/index.html +16 -0
  107. package/src/admin/main.tsx +42 -0
  108. package/src/admin/styles.css +9 -0
  109. package/src/auth/auth.server.ts +203 -0
  110. package/src/auth/config.ts +46 -0
  111. package/src/auth/cookies.server.ts +84 -0
  112. package/src/auth/http.server.ts +32 -0
  113. package/src/auth/password.server.ts +25 -0
  114. package/src/auth/session.server.ts +16 -0
  115. package/src/auth/users.server.ts +159 -0
  116. package/src/config.ts +120 -0
  117. package/src/core/backup.server.ts +446 -0
  118. package/src/core/db.server.ts +685 -0
  119. package/src/core/media.server.ts +136 -0
  120. package/src/core/media.ts +91 -0
  121. package/src/core/schema.ts +126 -0
  122. package/src/core/types.ts +194 -0
  123. package/src/core/validation.ts +215 -0
  124. package/src/global.d.ts +1 -0
  125. package/src/locale.ts +16 -0
  126. package/src/runtime.ts +54 -0
  127. package/src/server/app.ts +737 -0
  128. package/src/ui/admin/admin-shell.tsx +106 -0
  129. package/src/ui/admin/backup-manager.tsx +327 -0
  130. package/src/ui/admin/collection-icon.tsx +69 -0
  131. package/src/ui/admin/collection-manager.tsx +408 -0
  132. package/src/ui/admin/display.tsx +138 -0
  133. package/src/ui/admin/field-control.tsx +214 -0
  134. package/src/ui/admin/i18n.tsx +401 -0
  135. package/src/ui/admin/item-form.tsx +200 -0
  136. package/src/ui/admin/list-control.tsx +121 -0
  137. package/src/ui/admin/locales.ts +12 -0
  138. package/src/ui/admin/login-form.tsx +98 -0
  139. package/src/ui/admin/media-control.tsx +161 -0
  140. package/src/ui/admin/media-list-control.tsx +242 -0
  141. package/src/ui/admin/pagination.tsx +58 -0
  142. package/src/ui/admin/relation-control.tsx +142 -0
  143. package/src/ui/admin/router.tsx +105 -0
  144. package/src/ui/admin/runtime.tsx +58 -0
  145. package/src/ui/admin/sidebar.tsx +178 -0
  146. package/src/ui/admin/standalone-manager.tsx +103 -0
  147. package/src/ui/admin/table.tsx +129 -0
  148. package/src/ui/admin/toast.tsx +126 -0
  149. package/src/ui/admin/users-manager.tsx +344 -0
  150. package/src/ui/badge.tsx +27 -0
  151. package/src/ui/box.tsx +33 -0
  152. package/src/ui/button.tsx +77 -0
  153. package/src/ui/card.tsx +92 -0
  154. package/src/ui/container.tsx +28 -0
  155. package/src/ui/drawer.tsx +104 -0
  156. package/src/ui/field-wrapper.tsx +54 -0
  157. package/src/ui/index.ts +8 -0
  158. package/src/ui/text.tsx +93 -0
@@ -0,0 +1,344 @@
1
+ "use client";
2
+
3
+ import { useCallback, useState } from "react";
4
+
5
+ import type { UserSummary } from "../../auth/config.js";
6
+ import { Badge } from "../badge.js";
7
+ import { Box } from "../box.js";
8
+ import { Button, IconButton } from "../button.js";
9
+ import { Drawer } from "../drawer.js";
10
+ import { FieldWrapper, inputClass } from "../field-wrapper.js";
11
+ import { Text } from "../text.js";
12
+ import { FiEdit2, FiTrash2 } from "react-icons/fi";
13
+
14
+ import { DataTable, type Column } from "./table.js";
15
+ import { useToast } from "./toast.js";
16
+ import { useI18n } from "./i18n.js";
17
+ import { useCmsUrls } from "./runtime.js";
18
+
19
+ export type UsersManagerProps = {
20
+ initial: UserSummary[];
21
+ currentUserId: number;
22
+ };
23
+
24
+ type DrawerState =
25
+ | { kind: "closed" }
26
+ | { kind: "form"; user: UserSummary | null }
27
+ | { kind: "delete"; user: UserSummary };
28
+
29
+ /** Deterministic (UTC) date format to avoid hydration mismatches. */
30
+ function formatDateTime(value: string, locale: "en" | "pt"): string {
31
+ const match = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})/.exec(value);
32
+ if (!match) return value || "—";
33
+ const date = locale === "en" ? `${match[2]}/${match[3]}/${match[1]}` : `${match[3]}/${match[2]}/${match[1]}`;
34
+ return `${date} ${match[4]}:${match[5]}`;
35
+ }
36
+
37
+ export const UsersManager = ({ initial, currentUserId }: UsersManagerProps) => {
38
+ const toast = useToast();
39
+ const { auth } = useCmsUrls();
40
+ const { t, locale } = useI18n();
41
+ const [users, setUsers] = useState<UserSummary[]>(initial);
42
+ const [drawer, setDrawer] = useState<DrawerState>({ kind: "closed" });
43
+ const [email, setEmail] = useState("");
44
+ const [password, setPassword] = useState("");
45
+ const [submitting, setSubmitting] = useState(false);
46
+ const [errors, setErrors] = useState<Record<string, string>>({});
47
+ const [formError, setFormError] = useState<string | null>(null);
48
+
49
+ const reload = useCallback(async () => {
50
+ const response = await fetch(auth("users"));
51
+ if (!response.ok) return;
52
+ const json = (await response.json()) as { users?: UserSummary[] };
53
+ if (json.users) setUsers(json.users);
54
+ }, []);
55
+
56
+ const closeDrawer = () => {
57
+ setDrawer({ kind: "closed" });
58
+ setErrors({});
59
+ setFormError(null);
60
+ };
61
+
62
+ const openCreate = () => {
63
+ setEmail("");
64
+ setPassword("");
65
+ setErrors({});
66
+ setFormError(null);
67
+ setDrawer({ kind: "form", user: null });
68
+ };
69
+
70
+ const openEdit = (user: UserSummary) => {
71
+ setEmail(user.email);
72
+ setPassword("");
73
+ setErrors({});
74
+ setFormError(null);
75
+ setDrawer({ kind: "form", user });
76
+ };
77
+
78
+ const submit = async (event: React.FormEvent) => {
79
+ event.preventDefault();
80
+ if (drawer.kind !== "form") return;
81
+ const editing = drawer.user;
82
+ setSubmitting(true);
83
+ setErrors({});
84
+ setFormError(null);
85
+ try {
86
+ const response = await fetch(
87
+ editing ? auth(`users/${editing.id}`) : auth("users"),
88
+ {
89
+ method: editing ? "PATCH" : "POST",
90
+ headers: { "Content-Type": "application/json" },
91
+ body: JSON.stringify({ email, password }),
92
+ },
93
+ );
94
+ const json = (await response.json()) as {
95
+ message?: string;
96
+ errors?: Record<string, string>;
97
+ };
98
+ if (!response.ok) {
99
+ setErrors(json.errors ?? {});
100
+ setFormError(json.message ?? t("users.saveError"));
101
+ return;
102
+ }
103
+ closeDrawer();
104
+ toast.success(editing ? t("users.updated") : t("users.created"));
105
+ await reload();
106
+ } catch {
107
+ setFormError(t("users.networkSave"));
108
+ } finally {
109
+ setSubmitting(false);
110
+ }
111
+ };
112
+
113
+ const confirmDelete = async () => {
114
+ if (drawer.kind !== "delete") return;
115
+ setSubmitting(true);
116
+ try {
117
+ const response = await fetch(auth(`users/${drawer.user.id}`), {
118
+ method: "DELETE",
119
+ });
120
+ const json = (await response.json().catch(() => null)) as
121
+ | { message?: string }
122
+ | null;
123
+ if (!response.ok) {
124
+ toast.error(json?.message ?? t("users.removeError"));
125
+ return;
126
+ }
127
+ closeDrawer();
128
+ toast.success(t("users.removed"));
129
+ await reload();
130
+ } catch {
131
+ toast.error(t("users.networkRemove"));
132
+ } finally {
133
+ setSubmitting(false);
134
+ }
135
+ };
136
+
137
+ const columns: Column<UserSummary>[] = [
138
+ {
139
+ key: "id",
140
+ header: "ID",
141
+ width: "70px",
142
+ render: (user) => (
143
+ <Text as="span" size="caption" className="text-gray-400">
144
+ #{user.id}
145
+ </Text>
146
+ ),
147
+ },
148
+ {
149
+ key: "email",
150
+ header: t("common.email"),
151
+ render: (user) => (
152
+ <Box className="items-center gap-2">
153
+ <Text as="span" size="caption" className="font-medium text-gray-900">
154
+ {user.email}
155
+ </Text>
156
+ {user.id === currentUserId ? <Badge tone="purple">{t("users.you")}</Badge> : null}
157
+ </Box>
158
+ ),
159
+ },
160
+ {
161
+ key: "createdAt",
162
+ header: t("common.createdAt"),
163
+ width: "150px",
164
+ render: (user) => (
165
+ <Text as="span" size="caption" className="whitespace-nowrap text-gray-500">
166
+ {formatDateTime(user.createdAt, locale)}
167
+ </Text>
168
+ ),
169
+ },
170
+ {
171
+ key: "updatedAt",
172
+ header: t("common.updatedAt"),
173
+ width: "150px",
174
+ render: (user) => (
175
+ <Text as="span" size="caption" className="whitespace-nowrap text-gray-500">
176
+ {formatDateTime(user.updatedAt, locale)}
177
+ </Text>
178
+ ),
179
+ },
180
+ {
181
+ key: "__actions",
182
+ header: "",
183
+ width: "110px",
184
+ align: "right",
185
+ render: (user) => (
186
+ <Box className="items-center justify-end gap-1">
187
+ <IconButton
188
+ type="button"
189
+ label={t("common.edit")}
190
+ onClick={() => openEdit(user)}
191
+ >
192
+ <FiEdit2 aria-hidden />
193
+ </IconButton>
194
+ {user.id === currentUserId ? null : (
195
+ <IconButton
196
+ type="button"
197
+ label={t("common.remove")}
198
+ className="text-red-600 hover:bg-red-50 hover:text-red-700"
199
+ onClick={() => setDrawer({ kind: "delete", user })}
200
+ >
201
+ <FiTrash2 aria-hidden />
202
+ </IconButton>
203
+ )}
204
+ </Box>
205
+ ),
206
+ },
207
+ ];
208
+
209
+ return (
210
+ <Box className="flex-col gap-6 p-4 sm:p-6 lg:p-8">
211
+ <Box className="flex-col items-start justify-between gap-3 sm:flex-row sm:gap-4">
212
+ <Box className="flex-col gap-1">
213
+ <Box className="items-center gap-3">
214
+ <Text size="title" className="font-semibold text-gray-900">
215
+ {t("users.title")}
216
+ </Text>
217
+ <Badge tone="gray">{users.length}</Badge>
218
+ </Box>
219
+ <Text size="caption" className="text-gray-500">
220
+ {t("users.subtitle")}
221
+ </Text>
222
+ </Box>
223
+ <Button type="button" variant="primary" onClick={openCreate}>
224
+ {t("users.new")}
225
+ </Button>
226
+ </Box>
227
+
228
+ <DataTable
229
+ columns={columns}
230
+ rows={users}
231
+ rowKey={(user) => user.id}
232
+ empty={t("users.empty")}
233
+ />
234
+
235
+ <Drawer
236
+ open={drawer.kind !== "closed"}
237
+ onClose={closeDrawer}
238
+ title={
239
+ drawer.kind === "form"
240
+ ? drawer.user
241
+ ? t("users.editTitle", { id: drawer.user.id })
242
+ : t("users.createTitle")
243
+ : t("users.removeTitle")
244
+ }
245
+ description={
246
+ drawer.kind === "delete"
247
+ ? t("common.deleteWarning")
248
+ : undefined
249
+ }
250
+ >
251
+ {drawer.kind === "form" ? (
252
+ <Box
253
+ as="form"
254
+ className="flex-col gap-5"
255
+ onSubmit={(event) => void submit(event)}
256
+ >
257
+ {formError ? (
258
+ <Box className="rounded-md border border-red-200 bg-red-50 px-3 py-2">
259
+ <Text size="caption" className="text-red-700">
260
+ {formError}
261
+ </Text>
262
+ </Box>
263
+ ) : null}
264
+
265
+ <FieldWrapper label={t("common.email")} htmlFor="user-email" required error={errors.email}>
266
+ <input
267
+ id="user-email"
268
+ type="email"
269
+ autoComplete="off"
270
+ required
271
+ value={email}
272
+ disabled={submitting}
273
+ onChange={(event) => setEmail(event.target.value)}
274
+ className={`${inputClass} border-gray-300`}
275
+ />
276
+ </FieldWrapper>
277
+
278
+ <FieldWrapper
279
+ label={drawer.user ? t("users.newPassword") : t("common.password")}
280
+ htmlFor="user-password"
281
+ required={!drawer.user}
282
+ help={
283
+ drawer.user
284
+ ? t("users.passwordHintKeep")
285
+ : t("users.passwordHintMin")
286
+ }
287
+ error={errors.password}
288
+ >
289
+ <input
290
+ id="user-password"
291
+ type="password"
292
+ autoComplete="new-password"
293
+ value={password}
294
+ disabled={submitting}
295
+ onChange={(event) => setPassword(event.target.value)}
296
+ className={`${inputClass} border-gray-300`}
297
+ />
298
+ </FieldWrapper>
299
+
300
+ <Box className="items-center justify-end gap-2 border-t border-gray-200 pt-4">
301
+ <Button
302
+ type="button"
303
+ variant="secondary"
304
+ onClick={closeDrawer}
305
+ disabled={submitting}
306
+ >
307
+ {t("common.cancel")}
308
+ </Button>
309
+ <Button type="submit" variant="primary" disabled={submitting}>
310
+ {submitting ? t("common.saving") : drawer.user ? t("common.saveChanges") : t("users.create")}
311
+ </Button>
312
+ </Box>
313
+ </Box>
314
+ ) : null}
315
+
316
+ {drawer.kind === "delete" ? (
317
+ <Box className="flex-col gap-6">
318
+ <Text className="text-gray-700">
319
+ {t("users.removeConfirm", { email: drawer.user.email })}
320
+ </Text>
321
+ <Box className="items-center justify-end gap-2 border-t border-gray-200 pt-4">
322
+ <Button
323
+ type="button"
324
+ variant="secondary"
325
+ onClick={closeDrawer}
326
+ disabled={submitting}
327
+ >
328
+ {t("common.cancel")}
329
+ </Button>
330
+ <Button
331
+ type="button"
332
+ variant="danger"
333
+ onClick={() => void confirmDelete()}
334
+ disabled={submitting}
335
+ >
336
+ {submitting ? t("common.removing") : t("common.remove")}
337
+ </Button>
338
+ </Box>
339
+ </Box>
340
+ ) : null}
341
+ </Drawer>
342
+ </Box>
343
+ );
344
+ };
@@ -0,0 +1,27 @@
1
+ import { Box, type BoxProps } from "./box.js";
2
+
3
+ export type BadgeTone = "gray" | "green" | "amber" | "blue" | "red" | "purple";
4
+
5
+ export type BadgeProps = BoxProps<"span"> & {
6
+ tone?: BadgeTone;
7
+ };
8
+
9
+ const tones: Record<BadgeTone, string> = {
10
+ gray: "bg-gray-100 text-gray-700",
11
+ green: "bg-emerald-100 text-emerald-700",
12
+ amber: "bg-amber-100 text-amber-700",
13
+ blue: "bg-blue-100 text-blue-700",
14
+ red: "bg-red-100 text-red-700",
15
+ purple: "bg-purple-100 text-purple-700",
16
+ };
17
+
18
+ /**
19
+ * Small pill label built on `Box`.
20
+ */
21
+ export const Badge = ({ tone = "gray", className = "", ...props }: BadgeProps) => (
22
+ <Box
23
+ as="span"
24
+ className={`w-fit items-center rounded-full px-2 py-0.5 text-xs font-medium ${tones[tone]} ${className}`}
25
+ {...props}
26
+ />
27
+ );
package/src/ui/box.tsx ADDED
@@ -0,0 +1,33 @@
1
+ import { type ElementType, type ComponentPropsWithoutRef, type ReactElement } from "react";
2
+
3
+ export type CustomComponentTag<T extends ElementType = "div"> = {
4
+ as?: T;
5
+ } & ComponentPropsWithoutRef<T>;
6
+
7
+ export type BoxProps<T extends ElementType = "div"> = {
8
+ className?: string;
9
+ } & CustomComponentTag<T>;
10
+
11
+ /**
12
+ * Polymorphic layout component that renders as a flex container.
13
+ *
14
+ * @example
15
+ * <Box as="section" className="gap-4">
16
+ * <span>Item 1</span>
17
+ * <span>Item 2</span>
18
+ * </Box>
19
+ */
20
+ export const Box = <T extends ElementType = "div">({
21
+ as,
22
+ className = "",
23
+ children,
24
+ ...props
25
+ }: BoxProps<T>): ReactElement => {
26
+ const Tag = as ?? "div";
27
+
28
+ return (
29
+ <Tag className={`flex ${className}`} {...props}>
30
+ {children}
31
+ </Tag>
32
+ );
33
+ };
@@ -0,0 +1,77 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ import { Box, type BoxProps } from "./box.js";
4
+
5
+ export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger";
6
+ export type ButtonSize = "sm" | "md" | "icon";
7
+
8
+ export type ButtonProps = BoxProps<"button"> & {
9
+ variant?: ButtonVariant;
10
+ size?: ButtonSize;
11
+ };
12
+
13
+ const variants: Record<ButtonVariant, string> = {
14
+ primary:
15
+ "border-gray-900 bg-gray-900 text-white hover:bg-gray-800 hover:border-gray-800",
16
+ secondary:
17
+ "border-gray-300 bg-white text-gray-900 hover:bg-gray-50 hover:border-gray-400",
18
+ ghost:
19
+ "border-transparent bg-transparent text-gray-700 hover:bg-gray-100 hover:text-gray-900",
20
+ danger:
21
+ "border-red-600 bg-red-600 text-white hover:bg-red-500 hover:border-red-500",
22
+ };
23
+
24
+ const sizes: Record<ButtonSize, string> = {
25
+ sm: "gap-1.5 px-2.5 py-1.5 text-xs",
26
+ md: "gap-2 px-3.5 py-2 text-sm",
27
+ icon: "h-8 w-8 p-0 text-base",
28
+ };
29
+
30
+ /**
31
+ * Button built on top of `Box`.
32
+ *
33
+ * @example
34
+ * <Button variant="primary" onClick={save}>Salvar</Button>
35
+ * <Button variant="ghost" size="sm">Cancelar</Button>
36
+ */
37
+ export const Button = ({
38
+ variant = "primary",
39
+ size = "md",
40
+ className = "",
41
+ ...props
42
+ }: ButtonProps) => {
43
+ return (
44
+ <Box
45
+ as="button"
46
+ type="button"
47
+ className={`cursor-pointer select-none items-center justify-center rounded-md border font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${variants[variant]} ${sizes[size]} ${className}`}
48
+ {...props}
49
+ />
50
+ );
51
+ };
52
+
53
+ export type IconButtonProps = ButtonProps & {
54
+ label: string;
55
+ children: ReactNode;
56
+ };
57
+
58
+ /**
59
+ * Square icon-only button. The label is exposed to assistive tech via
60
+ * `aria-label` and shown as a native tooltip via `title`.
61
+ */
62
+ export const IconButton = ({
63
+ label,
64
+ children,
65
+ variant = "ghost",
66
+ ...props
67
+ }: IconButtonProps) => (
68
+ <Button
69
+ aria-label={label}
70
+ title={label}
71
+ variant={variant}
72
+ size="icon"
73
+ {...props}
74
+ >
75
+ {children}
76
+ </Button>
77
+ );
@@ -0,0 +1,92 @@
1
+ import { type ElementType } from "react";
2
+ import { Box, type BoxProps } from "./box.js";
3
+
4
+ export type CardProps<T extends ElementType = "div"> = BoxProps<T>;
5
+
6
+ /**
7
+ * Container component that groups card header, body, and footer.
8
+ *
9
+ * @example
10
+ * <Card className="shadow-md">
11
+ * <CardHeader>Title</CardHeader>
12
+ * <CardBody>Content</CardBody>
13
+ * <CardFooter>Actions</CardFooter>
14
+ * </Card>
15
+ */
16
+ export const Card = ({ className = "", children, ...props }: CardProps) => {
17
+ return (
18
+ <Box
19
+ className={`flex-col overflow-hidden rounded-lg border border-gray-200 bg-white ${className}`}
20
+ {...props}
21
+ >
22
+ {children}
23
+ </Box>
24
+ );
25
+ };
26
+
27
+ export type CardHeaderProps<T extends ElementType = "div"> = BoxProps<T>;
28
+
29
+ /**
30
+ * Header section of a Card, typically holding titles or actions.
31
+ *
32
+ * @example
33
+ * <CardHeader className="border-b">
34
+ * <Text size="title">Title</Text>
35
+ * </CardHeader>
36
+ */
37
+ export const CardHeader = ({
38
+ className = "",
39
+ children,
40
+ ...props
41
+ }: CardHeaderProps) => {
42
+ return (
43
+ <Box className={`items-center gap-4 px-6 py-4 ${className}`} {...props}>
44
+ {children}
45
+ </Box>
46
+ );
47
+ };
48
+
49
+ export type CardBodyProps<T extends ElementType = "div"> = BoxProps<T>;
50
+
51
+ /**
52
+ * Main content section of a Card.
53
+ *
54
+ * @example
55
+ * <CardBody className="gap-2">
56
+ * <Text>Content</Text>
57
+ * </CardBody>
58
+ */
59
+ export const CardBody = ({
60
+ className = "",
61
+ children,
62
+ ...props
63
+ }: CardBodyProps) => {
64
+ return (
65
+ <Box className={`flex-1 flex-col px-6 py-4 ${className}`} {...props}>
66
+ {children}
67
+ </Box>
68
+ );
69
+ };
70
+
71
+ export type CardFooterProps<T extends ElementType = "div"> = BoxProps<T>;
72
+
73
+ /**
74
+ * Footer section of a Card, typically holding actions.
75
+ *
76
+ * @example
77
+ * <CardFooter className="justify-end gap-2">
78
+ * <button>Cancel</button>
79
+ * <button>Save</button>
80
+ * </CardFooter>
81
+ */
82
+ export const CardFooter = ({
83
+ className = "",
84
+ children,
85
+ ...props
86
+ }: CardFooterProps) => {
87
+ return (
88
+ <Box className={`items-center gap-2 px-6 py-4 ${className}`} {...props}>
89
+ {children}
90
+ </Box>
91
+ );
92
+ };
@@ -0,0 +1,28 @@
1
+ import { Box, type CustomComponentTag } from "./box.js";
2
+ import { type ElementType } from "react";
3
+
4
+ export type ContainerProps<T extends ElementType = "div"> = {
5
+ className?: string;
6
+ } & CustomComponentTag<T>;
7
+
8
+ /**
9
+ * @example
10
+ * <Container as="main" className="gap-4">
11
+ * <span>Item 1</span>
12
+ * <span>Item 2</span>
13
+ * </Container>
14
+ */
15
+ export const Container = <T extends ElementType = "div">({
16
+ as,
17
+ className = "",
18
+ children,
19
+ ...props
20
+ }: ContainerProps<T>) => {
21
+ const Tag = as ?? "div";
22
+
23
+ return (
24
+ <Box as={Tag} className={`flex-col w-full min-h-screen ${className}`} {...props}>
25
+ {children}
26
+ </Box>
27
+ );
28
+ };