@kamaldgrt/ui 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kamal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,106 @@
1
- # Temporary Holding Version
1
+ # @kamaldgrt/ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared React UI primitives styled with Tailwind CSS theme tokens:
4
+
5
+ - **`Modal`**: centered dialog. Backdrop click and Escape close it, and the first field gets focus on open.
6
+ - **`ConfirmModal`**: message plus Cancel and Confirm, with an optional `danger` style and an optional secondary action.
7
+ - **`PromptModal`**: one or more labeled text inputs plus Cancel and OK. It replaces `window.prompt`.
8
+ - **`Drawer`**: right-side slide-over panel with an enter and exit transition and an optional header icon.
9
+
10
+ All components are client components (`"use client"` is included in the build).
11
+
12
+ ## Requirements
13
+
14
+ - React 19
15
+ - `lucide-react` (peer dependency, used by `Drawer`)
16
+ - Tailwind CSS v4 in the consuming app
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm i @kamaldgrt/ui
22
+ ```
23
+
24
+ ## Setup in the consuming app
25
+
26
+ The components carry Tailwind class names, so the app's Tailwind build has to scan the package. Add this to the app's main stylesheet. The path is relative to that file:
27
+
28
+ ```css
29
+ @import "tailwindcss";
30
+ @source "../../node_modules/@kamaldgrt/ui/dist";
31
+ ```
32
+
33
+ Without the `@source` line, Tailwind never sees the package's classes and the components render unstyled.
34
+
35
+ ### Theme tokens
36
+
37
+ The components use semantic color tokens, so each app keeps its own look. The app must define these under `@theme` as `--color-*` variables:
38
+
39
+ | Token | Used for |
40
+ |---|---|
41
+ | `surface`, `surface-elevated`, `surface-hover` | backgrounds, dialog card, hover state |
42
+ | `foreground`, `muted` | text |
43
+ | `border`, `border-subtle` | borders |
44
+ | `cta`, `cta-foreground`, `cta-hover` | primary button |
45
+ | `danger-bg`, `danger-text` | destructive button |
46
+ | `warning-bg`, `warning-text` | drawer icon chip |
47
+
48
+ ```css
49
+ @theme {
50
+ --color-surface: #ffffff;
51
+ --color-foreground: #111827;
52
+ /* ...and so on for every token above */
53
+ }
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ```tsx
59
+ import { ConfirmModal, Drawer, Modal, PromptModal } from "@kamaldgrt/ui";
60
+
61
+ <ConfirmModal
62
+ isOpen={open}
63
+ onClose={() => setOpen(false)}
64
+ onConfirm={remove}
65
+ title="Delete item"
66
+ message="This cannot be undone."
67
+ confirmLabel="Delete"
68
+ danger
69
+ />
70
+
71
+ <Drawer isOpen={open} onClose={() => setOpen(false)} title="New item" icon={Plus}>
72
+ <ItemForm />
73
+ </Drawer>
74
+
75
+ <PromptModal
76
+ isOpen={open}
77
+ onClose={() => setOpen(false)}
78
+ onSubmit={({ name }) => rename(name)}
79
+ title="Rename"
80
+ fields={[{ name: "name", label: "Name", defaultValue: current }]}
81
+ />
82
+ ```
83
+
84
+ Behavior worth knowing:
85
+
86
+ - A `Drawer` stays mounted for 200 ms after `isOpen` turns false so the slide-out can play. Its children remount on every open, so forms start fresh.
87
+ - Pressing Escape inside a `Drawer` that contains an open dialog closes only the dialog.
88
+ - `Modal` takes an optional `className` that replaces the default card styling.
89
+ - There is no focus trap. One dialog at a time is the supported case.
90
+
91
+ ## Development
92
+
93
+ ```bash
94
+ npm install
95
+ npm test # vitest (jsdom, testing-library)
96
+ npm run typecheck # tsc --noEmit
97
+ npm run build # tsup -> dist/ (ESM + .d.ts)
98
+ ```
99
+
100
+ ## API changes
101
+
102
+ Everything is imported from the package root. Treat exported names, props and the list of theme tokens as a public API:
103
+
104
+ - Additive changes (new optional props, new components, new tokens with a fallback) bump the minor version.
105
+ - Breaking changes (removed or renamed props, new required tokens) bump the major version.
106
+ - Tag each release (`vX.Y.Z`) to match the published version.
@@ -0,0 +1,50 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { LucideIcon } from 'lucide-react';
4
+
5
+ declare function ConfirmModal({ isOpen, onClose, onConfirm, title, message, confirmLabel, danger, secondaryLabel, onSecondary, }: {
6
+ isOpen: boolean;
7
+ onClose: () => void;
8
+ onConfirm: () => void;
9
+ title: string;
10
+ message: string;
11
+ confirmLabel?: string;
12
+ danger?: boolean;
13
+ secondaryLabel?: string;
14
+ onSecondary?: () => void;
15
+ }): react.JSX.Element;
16
+
17
+ declare function Drawer({ isOpen, onClose, title, icon: Icon, children, }: {
18
+ isOpen: boolean;
19
+ onClose: () => void;
20
+ title: string;
21
+ icon?: LucideIcon;
22
+ children: ReactNode;
23
+ }): react.JSX.Element | null;
24
+
25
+ declare function Modal({ isOpen, onClose, title, children, className, }: {
26
+ isOpen: boolean;
27
+ onClose: () => void;
28
+ title: string;
29
+ children: ReactNode;
30
+ className?: string;
31
+ }): react.JSX.Element | null;
32
+
33
+ type PromptField = {
34
+ name: string;
35
+ label: string;
36
+ placeholder?: string;
37
+ defaultValue?: string;
38
+ optional?: boolean;
39
+ };
40
+ declare function PromptModal({ isOpen, onClose, onSubmit, title, fields, submitLabel, }: {
41
+ isOpen: boolean;
42
+ onClose: () => void;
43
+ onSubmit: (values: Record<string, string>) => void;
44
+ title: string;
45
+ fields: PromptField[];
46
+ submitLabel?: string;
47
+ }): react.JSX.Element;
48
+
49
+ export { ConfirmModal, Drawer, Modal, PromptModal };
50
+ export type { PromptField };
package/dist/index.js ADDED
@@ -0,0 +1,293 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+
22
+ // src/Modal.tsx
23
+ import { useEffect, useRef } from "react";
24
+ import { jsx, jsxs } from "react/jsx-runtime";
25
+ function Modal({
26
+ isOpen,
27
+ onClose,
28
+ title,
29
+ children,
30
+ className
31
+ }) {
32
+ const cardRef = useRef(null);
33
+ useEffect(() => {
34
+ var _a, _b;
35
+ if (!isOpen) return;
36
+ (_b = (_a = cardRef.current) == null ? void 0 : _a.querySelector("input, button, textarea, select")) == null ? void 0 : _b.focus();
37
+ }, [isOpen]);
38
+ useEffect(() => {
39
+ if (!isOpen) return;
40
+ function handleKeyDown(e) {
41
+ if (e.key === "Escape") onClose();
42
+ }
43
+ document.addEventListener("keydown", handleKeyDown);
44
+ return () => document.removeEventListener("keydown", handleKeyDown);
45
+ }, [isOpen, onClose]);
46
+ if (!isOpen) return null;
47
+ return /* @__PURE__ */ jsx(
48
+ "div",
49
+ {
50
+ className: "fixed inset-0 z-50 flex items-center justify-center bg-black/40",
51
+ onClick: onClose,
52
+ children: /* @__PURE__ */ jsxs(
53
+ "div",
54
+ {
55
+ ref: cardRef,
56
+ role: "dialog",
57
+ "aria-modal": "true",
58
+ "aria-label": title,
59
+ onClick: (e) => e.stopPropagation(),
60
+ className: className != null ? className : "w-80 rounded-lg border-2 border-border bg-surface-elevated p-4",
61
+ children: [
62
+ /* @__PURE__ */ jsx("p", { className: "mb-3 text-sm font-semibold text-foreground", children: title }),
63
+ children
64
+ ]
65
+ }
66
+ )
67
+ }
68
+ );
69
+ }
70
+
71
+ // src/ConfirmModal.tsx
72
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
73
+ function ConfirmModal({
74
+ isOpen,
75
+ onClose,
76
+ onConfirm,
77
+ title,
78
+ message,
79
+ confirmLabel = "Confirm",
80
+ danger = false,
81
+ // Optional third button, rendered between Cancel and Confirm — for
82
+ // dialogs offering a safe alternative to a destructive Confirm (e.g.
83
+ // "Mark Inactive" next to "Delete Permanently"). Never itself styled
84
+ // `danger`; that's reserved for the main destructive action.
85
+ secondaryLabel,
86
+ onSecondary
87
+ }) {
88
+ return /* @__PURE__ */ jsxs2(Modal, { isOpen, onClose, title, children: [
89
+ /* @__PURE__ */ jsx2("p", { className: "mb-4 text-sm text-foreground", children: message }),
90
+ /* @__PURE__ */ jsxs2("div", { className: "flex justify-end gap-2", children: [
91
+ /* @__PURE__ */ jsx2(
92
+ "button",
93
+ {
94
+ type: "button",
95
+ onClick: onClose,
96
+ className: "rounded-md px-3 py-1.5 text-sm text-muted hover:bg-surface-hover",
97
+ children: "Cancel"
98
+ }
99
+ ),
100
+ secondaryLabel && onSecondary && /* @__PURE__ */ jsx2(
101
+ "button",
102
+ {
103
+ type: "button",
104
+ onClick: onSecondary,
105
+ className: "rounded-md border border-border px-3 py-1.5 text-sm font-medium text-foreground hover:bg-surface-hover",
106
+ children: secondaryLabel
107
+ }
108
+ ),
109
+ /* @__PURE__ */ jsx2(
110
+ "button",
111
+ {
112
+ type: "button",
113
+ onClick: onConfirm,
114
+ className: danger ? "rounded-md bg-danger-bg px-3 py-1.5 text-sm font-medium text-danger-text hover:opacity-90" : "rounded-md bg-cta px-3 py-1.5 text-sm font-medium text-cta-foreground hover:bg-cta-hover hover:font-semibold",
115
+ children: confirmLabel
116
+ }
117
+ )
118
+ ] })
119
+ ] });
120
+ }
121
+
122
+ // src/Drawer.tsx
123
+ import { X } from "lucide-react";
124
+ import { useEffect as useEffect2, useRef as useRef2, useState } from "react";
125
+
126
+ // src/constants.ts
127
+ var DRAWER_TRANSITION_DURATION_MS = 200;
128
+
129
+ // src/Drawer.tsx
130
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
131
+ function Drawer({
132
+ isOpen,
133
+ onClose,
134
+ title,
135
+ icon: Icon,
136
+ children
137
+ }) {
138
+ const [mounted, setMounted] = useState(isOpen);
139
+ const [visible, setVisible] = useState(false);
140
+ const contentRef = useRef2(null);
141
+ useEffect2(() => {
142
+ if (isOpen) {
143
+ setMounted(true);
144
+ const raf = requestAnimationFrame(() => setVisible(true));
145
+ return () => cancelAnimationFrame(raf);
146
+ }
147
+ setVisible(false);
148
+ const timer = setTimeout(() => setMounted(false), DRAWER_TRANSITION_DURATION_MS);
149
+ return () => clearTimeout(timer);
150
+ }, [isOpen]);
151
+ useEffect2(() => {
152
+ var _a, _b;
153
+ if (!isOpen) return;
154
+ (_b = (_a = contentRef.current) == null ? void 0 : _a.querySelector("input, button, textarea, select")) == null ? void 0 : _b.focus();
155
+ }, [isOpen]);
156
+ useEffect2(() => {
157
+ if (!isOpen) return;
158
+ function handleKeyDown(e) {
159
+ var _a;
160
+ if (e.key !== "Escape") return;
161
+ if ((_a = contentRef.current) == null ? void 0 : _a.querySelector('[role="dialog"]')) return;
162
+ onClose();
163
+ }
164
+ document.addEventListener("keydown", handleKeyDown);
165
+ return () => document.removeEventListener("keydown", handleKeyDown);
166
+ }, [isOpen, onClose]);
167
+ if (!mounted) return null;
168
+ return /* @__PURE__ */ jsx3(
169
+ "div",
170
+ {
171
+ className: `fixed inset-0 z-50 bg-black/40 transition-opacity duration-200 ${visible ? "opacity-100" : "opacity-0"}`,
172
+ onClick: onClose,
173
+ children: /* @__PURE__ */ jsxs3(
174
+ "div",
175
+ {
176
+ role: "dialog",
177
+ "aria-modal": "true",
178
+ "aria-label": title,
179
+ onClick: (e) => e.stopPropagation(),
180
+ className: `fixed inset-y-0 right-0 flex w-full flex-col border-l border-border-subtle bg-surface-elevated shadow-lg transition-transform duration-200 sm:max-w-md ${visible ? "translate-x-0" : "translate-x-full"}`,
181
+ children: [
182
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between border-b border-border-subtle px-4 py-3", children: [
183
+ /* @__PURE__ */ jsxs3("p", { className: "flex min-w-0 items-center gap-2.5 text-sm font-semibold text-foreground", children: [
184
+ Icon && /* @__PURE__ */ jsx3("span", { className: "flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-warning-bg text-warning-text", children: /* @__PURE__ */ jsx3(Icon, { "aria-hidden": true, className: "h-4 w-4" }) }),
185
+ /* @__PURE__ */ jsx3("span", { className: "break-words", children: title })
186
+ ] }),
187
+ /* @__PURE__ */ jsx3(
188
+ "button",
189
+ {
190
+ type: "button",
191
+ onClick: onClose,
192
+ "aria-label": "Close",
193
+ className: "rounded p-1 text-muted hover:bg-surface-hover hover:text-foreground",
194
+ children: /* @__PURE__ */ jsx3(X, { "aria-hidden": true, className: "h-4 w-4" })
195
+ }
196
+ )
197
+ ] }),
198
+ /* @__PURE__ */ jsx3("div", { ref: contentRef, className: "flex-1 overflow-y-auto p-4", children })
199
+ ]
200
+ }
201
+ )
202
+ }
203
+ );
204
+ }
205
+
206
+ // src/PromptModal.tsx
207
+ import { useEffect as useEffect3, useState as useState2 } from "react";
208
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
209
+ function PromptModal({
210
+ isOpen,
211
+ onClose,
212
+ onSubmit,
213
+ title,
214
+ fields,
215
+ submitLabel = "OK"
216
+ }) {
217
+ const [values, setValues] = useState2({});
218
+ useEffect3(() => {
219
+ if (isOpen) {
220
+ setValues(
221
+ Object.fromEntries(fields.map((f) => {
222
+ var _a;
223
+ return [f.name, (_a = f.defaultValue) != null ? _a : ""];
224
+ }))
225
+ );
226
+ }
227
+ }, [isOpen]);
228
+ const canSubmit = fields.every(
229
+ (f) => {
230
+ var _a;
231
+ return f.optional || ((_a = values[f.name]) != null ? _a : "").trim();
232
+ }
233
+ );
234
+ function handleSubmit() {
235
+ if (!canSubmit) return;
236
+ onSubmit(
237
+ Object.fromEntries(fields.map((f) => [f.name, values[f.name].trim()]))
238
+ );
239
+ }
240
+ return /* @__PURE__ */ jsx4(Modal, { isOpen, onClose, title, children: /* @__PURE__ */ jsxs4(
241
+ "form",
242
+ {
243
+ onSubmit: (e) => {
244
+ e.preventDefault();
245
+ handleSubmit();
246
+ },
247
+ children: [
248
+ /* @__PURE__ */ jsx4("div", { className: "mb-4 space-y-3", children: fields.map((f) => {
249
+ var _a;
250
+ return /* @__PURE__ */ jsxs4("label", { className: "block", children: [
251
+ /* @__PURE__ */ jsx4("span", { className: "mb-1 block text-xs font-medium text-muted", children: f.label }),
252
+ /* @__PURE__ */ jsx4(
253
+ "input",
254
+ {
255
+ type: "text",
256
+ value: (_a = values[f.name]) != null ? _a : "",
257
+ onChange: (e) => setValues((prev) => __spreadProps(__spreadValues({}, prev), { [f.name]: e.target.value })),
258
+ placeholder: f.placeholder,
259
+ className: "w-full rounded-md border border-border bg-surface px-2 py-1.5 text-sm text-foreground"
260
+ }
261
+ )
262
+ ] }, f.name);
263
+ }) }),
264
+ /* @__PURE__ */ jsxs4("div", { className: "flex justify-end gap-2", children: [
265
+ /* @__PURE__ */ jsx4(
266
+ "button",
267
+ {
268
+ type: "button",
269
+ onClick: onClose,
270
+ className: "rounded-md px-3 py-1.5 text-sm text-muted hover:bg-surface-hover",
271
+ children: "Cancel"
272
+ }
273
+ ),
274
+ /* @__PURE__ */ jsx4(
275
+ "button",
276
+ {
277
+ type: "submit",
278
+ disabled: !canSubmit,
279
+ className: "rounded-md bg-cta px-3 py-1.5 text-sm font-medium text-cta-foreground hover:bg-cta-hover hover:font-semibold disabled:opacity-50",
280
+ children: submitLabel
281
+ }
282
+ )
283
+ ] })
284
+ ]
285
+ }
286
+ ) });
287
+ }
288
+ export {
289
+ ConfirmModal,
290
+ Drawer,
291
+ Modal,
292
+ PromptModal
293
+ };
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@kamaldgrt/ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Shared React UI primitives (modals, drawer) styled with Tailwind theme tokens.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "sideEffects": false,
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/KamalDGRT/nico-ui.git"
21
+ },
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "test": "vitest run",
25
+ "typecheck": "tsc --noEmit",
26
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
27
+ },
28
+ "peerDependencies": {
29
+ "lucide-react": "^1.37.0",
30
+ "react": "^19.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@testing-library/jest-dom": "^7.0.1",
34
+ "@testing-library/react": "^16.3.3",
35
+ "@testing-library/user-event": "^14.6.8",
36
+ "@types/react": "^19.3.0",
37
+ "@types/react-dom": "^19.3.0",
38
+ "jsdom": "^29.1.1",
39
+ "lucide-react": "^1.61.0",
40
+ "react": "^19.2.8",
41
+ "react-dom": "^19.2.8",
42
+ "tsup": "^9.0.0",
43
+ "typescript": "^5.9.3",
44
+ "vitest": "^4.1.12"
45
+ }
46
+ }