@skybin-tech/nebula-ui 0.0.9 → 0.0.11

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 (2) hide show
  1. package/README.md +354 -1
  2. package/package.json +2 -3
package/README.md CHANGED
@@ -1 +1,354 @@
1
- # nebula-ui
1
+ # nebula-ui
2
+
3
+ A React component library built on [shadcn/ui](https://ui.shadcn.com/) patterns, providing form-integrated components with automatic Zod validation, accessible primitives, and utility hooks.
4
+
5
+ See [CHANGELOG.md](CHANGELOG.md) for release history.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @skybin-tech/nebula-ui
11
+ ```
12
+
13
+ ### Peer dependencies
14
+
15
+ ```bash
16
+ npm install react react-dom react-hook-form @hookform/resolvers zod \
17
+ @radix-ui/react-avatar @radix-ui/react-checkbox @radix-ui/react-dropdown-menu \
18
+ @radix-ui/react-label @radix-ui/react-radio-group @radix-ui/react-select \
19
+ @radix-ui/react-separator @radix-ui/react-slot @radix-ui/react-switch \
20
+ class-variance-authority clsx tailwind-merge lucide-react tailwindcss
21
+ ```
22
+
23
+ ### Styles
24
+
25
+ Import the stylesheet once in your app entry point:
26
+
27
+ ```ts
28
+ import "@skybin-tech/nebula-ui/styles.css";
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Form system
34
+
35
+ The form system is built around `react-hook-form` and `zod`. Wrap fields in `<Form>` and each field automatically registers its validation rules — no need to define a schema separately.
36
+
37
+ ### Form
38
+
39
+ The root form component. Provides context to all child fields and handles validation and submission.
40
+
41
+ ```tsx
42
+ import { Form, TextBox, Button } from "@skybin-tech/nebula-ui";
43
+
44
+ <Form
45
+ onSubmit={(data) => console.log(data)}
46
+ defaultValues={{ username: "", email: "" }}
47
+ >
48
+ <TextBox name="username" label="Username" required minLength={3} maxLength={50} />
49
+ <TextBox name="email" label="Email" type="email" required email />
50
+ <Button type="submit">Submit</Button>
51
+ </Form>
52
+ ```
53
+
54
+ You can also provide a base Zod schema that gets merged with field-level rules:
55
+
56
+ ```tsx
57
+ const baseSchema = z.object({ username: z.string(), email: z.string() });
58
+
59
+ <Form schema={baseSchema} onSubmit={handleSubmit}>
60
+ <TextBox name="username" required minLength={3} />
61
+ <TextBox name="email" required email />
62
+ </Form>
63
+ ```
64
+
65
+ **Props**
66
+
67
+ | Prop | Type | Default | Description |
68
+ |------|------|---------|-------------|
69
+ | `onSubmit` | `SubmitHandler` | — | Form submit handler |
70
+ | `onError` | `SubmitErrorHandler` | — | Validation error handler |
71
+ | `defaultValues` | `object` | — | Initial field values |
72
+ | `values` | `object` | — | Controlled field values |
73
+ | `schema` | `ZodType` | — | Base Zod schema (merged with field rules) |
74
+ | `config` | `FormConfig` | — | Form-wide configuration (size, layout, etc.) |
75
+ | `form` | `UseFormReturn` | — | External RHF form instance |
76
+ | `mode` | `string` | `"onBlur"` | When to trigger validation |
77
+ | `reValidateMode` | `string` | `"onChange"` | When to re-validate after first submission |
78
+
79
+ **FormConfig options**
80
+
81
+ | Key | Type | Default | Description |
82
+ |-----|------|---------|-------------|
83
+ | `size` | `"sm" \| "md" \| "lg"` | `"md"` | Default size for all fields |
84
+ | `layout` | `"vertical" \| "horizontal" \| "inline"` | `"vertical"` | Layout direction |
85
+ | `labelWidth` | `string \| number` | — | Label width for horizontal layout |
86
+ | `disabled` | `boolean` | `false` | Disable all fields |
87
+ | `colon` | `boolean` | `true` | Append `:` to labels |
88
+ | `showInlineErrors` | `boolean` | `true` | Show validation errors inline |
89
+ | `validateOnBlur` | `boolean` | `true` | Validate on blur |
90
+ | `validateOnChange` | `boolean` | `false` | Validate on change |
91
+
92
+ ---
93
+
94
+ ### TextBox
95
+
96
+ Single-line text input with full form integration.
97
+
98
+ ```tsx
99
+ <TextBox name="username" label="Username" required minLength={3} maxLength={50} />
100
+ <TextBox name="email" label="Email" type="email" required email />
101
+ <TextBox name="website" label="Website" url />
102
+ <TextBox name="amount" label="Amount" type="number" minValue={0} maxValue={100} />
103
+ <TextBox name="search" label="Search" prefix={<SearchIcon />} allowClear />
104
+ ```
105
+
106
+ **Validation props**
107
+
108
+ | Prop | Type | Description |
109
+ |------|------|-------------|
110
+ | `required` | `boolean \| string` | Mark as required; string sets the error message |
111
+ | `minLength` | `number \| { value, message }` | Minimum character count |
112
+ | `maxLength` | `number \| { value, message }` | Maximum character count |
113
+ | `minValue` | `number \| { value, message }` | Minimum numeric value |
114
+ | `maxValue` | `number \| { value, message }` | Maximum numeric value |
115
+ | `pattern` | `RegExp \| { value, message }` | Regex pattern |
116
+ | `email` | `boolean \| string` | Email format validation |
117
+ | `url` | `boolean \| string` | URL format validation |
118
+ | `validate` | `(value) => boolean \| string` | Custom validation function |
119
+
120
+ ---
121
+
122
+ ### TextArea
123
+
124
+ Multi-line text input with optional character count display.
125
+
126
+ ```tsx
127
+ <TextArea name="description" label="Description" required minLength={10} />
128
+ <TextArea name="bio" label="Bio" showCount maxCount={500} maxLength={500} />
129
+ ```
130
+
131
+ Supports the same validation props as `TextBox` (except `minValue`, `maxValue`, `email`, `url`, `pattern`).
132
+
133
+ ---
134
+
135
+ ### Select
136
+
137
+ Dropdown select with support for an `options` array or custom `children`.
138
+
139
+ ```tsx
140
+ <Select
141
+ name="country"
142
+ label="Country"
143
+ required
144
+ options={[
145
+ { label: "USA", value: "us" },
146
+ { label: "Canada", value: "ca" },
147
+ ]}
148
+ />
149
+
150
+ // Or with custom children
151
+ <Select name="role" label="Role" required>
152
+ <SelectItem value="admin">Admin</SelectItem>
153
+ <SelectItem value="user">User</SelectItem>
154
+ </Select>
155
+ ```
156
+
157
+ ---
158
+
159
+ ### Checkbox
160
+
161
+ Boolean checkbox field. When `required` is set, the checkbox must be checked to pass validation.
162
+
163
+ ```tsx
164
+ <Checkbox name="terms" label="I agree to the terms and conditions" required />
165
+ <Checkbox name="newsletter" label="Subscribe to newsletter" />
166
+ ```
167
+
168
+ ---
169
+
170
+ ### RadioGroup
171
+
172
+ A group of mutually exclusive radio buttons. Accepts an `options` array or custom `RadioItem` children.
173
+
174
+ ```tsx
175
+ <RadioGroup
176
+ name="gender"
177
+ label="Gender"
178
+ required
179
+ options={[
180
+ { label: "Male", value: "male" },
181
+ { label: "Female", value: "female" },
182
+ { label: "Other", value: "other" },
183
+ ]}
184
+ />
185
+
186
+ // Horizontal layout
187
+ <RadioGroup name="size" label="Size" direction="horizontal" options={[...]} />
188
+ ```
189
+
190
+ ---
191
+
192
+ ### Switch
193
+
194
+ Toggle switch backed by a boolean form field.
195
+
196
+ ```tsx
197
+ <Switch name="notifications" label="Enable notifications" />
198
+ <Switch name="terms" label="Accept terms" required="You must accept the terms" />
199
+ <Switch name="darkMode" label="Dark mode" checkedText="On" uncheckedText="Off" />
200
+ ```
201
+
202
+ ---
203
+
204
+ ## Display components
205
+
206
+ ### Button
207
+
208
+ A styled button with multiple variants, sizes, and a built-in loading state.
209
+
210
+ ```tsx
211
+ import { Button } from "@skybin-tech/nebula-ui";
212
+
213
+ <Button variant="primary" size="md">Save</Button>
214
+ <Button variant="outline" loading>Saving…</Button>
215
+ <Button variant="danger" fullWidth>Delete</Button>
216
+ ```
217
+
218
+ | Variant | Description |
219
+ |---------|-------------|
220
+ | `primary` | Filled primary colour (default) |
221
+ | `secondary` | Filled secondary colour |
222
+ | `outline` | Transparent with primary border |
223
+ | `ghost` | Transparent, no border |
224
+ | `danger` | Destructive / red |
225
+
226
+ Sizes: `sm`, `md` (default), `lg`.
227
+
228
+ ---
229
+
230
+ ### Card
231
+
232
+ Composable card layout components.
233
+
234
+ ```tsx
235
+ import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "@skybin-tech/nebula-ui";
236
+
237
+ <Card>
238
+ <CardHeader>
239
+ <CardTitle>Title</CardTitle>
240
+ <CardDescription>Subtitle</CardDescription>
241
+ </CardHeader>
242
+ <CardContent>Content goes here</CardContent>
243
+ <CardFooter>Footer</CardFooter>
244
+ </Card>
245
+ ```
246
+
247
+ ---
248
+
249
+ ### Badge
250
+
251
+ Small status or label indicator.
252
+
253
+ ```tsx
254
+ import { Badge } from "@skybin-tech/nebula-ui";
255
+
256
+ <Badge variant="default">New</Badge>
257
+ <Badge variant="secondary">Beta</Badge>
258
+ <Badge variant="destructive">Error</Badge>
259
+ <Badge variant="outline">Draft</Badge>
260
+ ```
261
+
262
+ ---
263
+
264
+ ### Avatar
265
+
266
+ User avatar with image and fallback initials.
267
+
268
+ ```tsx
269
+ import { Avatar, AvatarImage, AvatarFallback } from "@skybin-tech/nebula-ui";
270
+
271
+ <Avatar>
272
+ <AvatarImage src="/avatar.jpg" alt="John Doe" />
273
+ <AvatarFallback>JD</AvatarFallback>
274
+ </Avatar>
275
+ ```
276
+
277
+ ---
278
+
279
+ ### DropdownMenu
280
+
281
+ Accessible dropdown built on Radix UI.
282
+
283
+ ```tsx
284
+ import {
285
+ DropdownMenu,
286
+ DropdownMenuTrigger,
287
+ DropdownMenuContent,
288
+ DropdownMenuItem,
289
+ DropdownMenuSeparator,
290
+ } from "@skybin-tech/nebula-ui";
291
+
292
+ <DropdownMenu>
293
+ <DropdownMenuTrigger asChild>
294
+ <Button variant="outline">Options</Button>
295
+ </DropdownMenuTrigger>
296
+ <DropdownMenuContent>
297
+ <DropdownMenuItem>Edit</DropdownMenuItem>
298
+ <DropdownMenuItem>Duplicate</DropdownMenuItem>
299
+ <DropdownMenuSeparator />
300
+ <DropdownMenuItem>Delete</DropdownMenuItem>
301
+ </DropdownMenuContent>
302
+ </DropdownMenu>
303
+ ```
304
+
305
+ ---
306
+
307
+ ### Separator
308
+
309
+ A horizontal or vertical divider line.
310
+
311
+ ```tsx
312
+ import { Separator } from "@skybin-tech/nebula-ui";
313
+
314
+ <Separator />
315
+ <Separator orientation="vertical" />
316
+ ```
317
+
318
+ ---
319
+
320
+ ## Hooks
321
+
322
+ ### useDebounce
323
+
324
+ Debounces a value, returning the latest value only after the specified delay has elapsed with no further changes.
325
+
326
+ ```tsx
327
+ import { useDebounce } from "@skybin-tech/nebula-ui";
328
+
329
+ const debouncedSearch = useDebounce(searchTerm, 300);
330
+ ```
331
+
332
+ ### useToggle
333
+
334
+ Returns a boolean state and a stable toggle function.
335
+
336
+ ```tsx
337
+ import { useToggle } from "@skybin-tech/nebula-ui";
338
+
339
+ const [isOpen, toggleOpen] = useToggle(false);
340
+ ```
341
+
342
+ ---
343
+
344
+ ## Utilities
345
+
346
+ ### cn
347
+
348
+ Merges Tailwind CSS class names, handling conflicts via `tailwind-merge`.
349
+
350
+ ```tsx
351
+ import { cn } from "@skybin-tech/nebula-ui";
352
+
353
+ <div className={cn("p-4 text-sm", isActive && "bg-primary text-white")} />
354
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skybin-tech/nebula-ui",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "author": "Anwar <anwar@skybin.io>",
6
6
  "description": "Reusable React component library with form validation using shadcn/ui patterns, react-hook-form, and Zod",
@@ -68,8 +68,7 @@
68
68
  "default": "./dist/cjs/utils/cn.cjs"
69
69
  }
70
70
  },
71
- "./styles.css": "./dist/nebula-ui.css",
72
- "./package.json": "./package.json",
71
+ "./package.json": "./package.json",
73
72
  "./components/Card": {
74
73
  "import": {
75
74
  "types": "./dist/components/Card/index.d.ts",