@vjdesigns/vjdesigns-ui 3.8.4 → 3.9.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.
- package/CHANGELOG.md +239 -234
- package/README.md +872 -858
- package/dist/ai/llms-full.txt +669 -592
- package/dist/ai/llms.txt +2 -1
- package/dist/ai/registry.json +243 -36
- package/dist/components/primitives/Icon/AccessibilityIcon.cjs.js +1 -0
- package/dist/components/primitives/Icon/AccessibilityIcon.d.ts +130 -0
- package/dist/components/primitives/Icon/AccessibilityIcon.mjs +27 -0
- package/dist/components/primitives/Icon/Icon.module.css.cjs.js +1 -1
- package/dist/components/primitives/Icon/Icon.module.css.mjs +4 -3
- package/dist/components/primitives/Icon/accessibilityIconPaths.cjs.js +1 -0
- package/dist/components/primitives/Icon/accessibilityIconPaths.d.ts +103 -0
- package/dist/components/primitives/Icon/accessibilityIconPaths.mjs +224 -0
- package/dist/components/primitives/Icon/index.d.ts +2 -0
- package/dist/i18n/en.cjs.js +1 -1
- package/dist/i18n/en.mjs +22 -0
- package/dist/i18n/types.d.ts +43 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.mjs +111 -109
- package/dist/locales/ar.cjs.js +1 -1
- package/dist/locales/ar.mjs +22 -0
- package/dist/locales/bn.cjs.js +1 -1
- package/dist/locales/bn.mjs +22 -0
- package/dist/locales/cs.cjs.js +1 -1
- package/dist/locales/cs.mjs +22 -0
- package/dist/locales/da.cjs.js +1 -1
- package/dist/locales/da.mjs +22 -0
- package/dist/locales/de.cjs.js +1 -1
- package/dist/locales/de.mjs +22 -0
- package/dist/locales/el.cjs.js +1 -1
- package/dist/locales/el.mjs +22 -0
- package/dist/locales/es.cjs.js +1 -1
- package/dist/locales/es.mjs +22 -0
- package/dist/locales/fa.cjs.js +1 -1
- package/dist/locales/fa.mjs +22 -0
- package/dist/locales/fi.cjs.js +1 -1
- package/dist/locales/fi.mjs +22 -0
- package/dist/locales/fr.cjs.js +1 -1
- package/dist/locales/fr.mjs +22 -0
- package/dist/locales/he.cjs.js +1 -1
- package/dist/locales/he.mjs +22 -0
- package/dist/locales/hi.cjs.js +1 -1
- package/dist/locales/hi.mjs +22 -0
- package/dist/locales/hu.cjs.js +1 -1
- package/dist/locales/hu.mjs +22 -0
- package/dist/locales/id.cjs.js +1 -1
- package/dist/locales/id.mjs +22 -0
- package/dist/locales/it.cjs.js +1 -1
- package/dist/locales/it.mjs +22 -0
- package/dist/locales/ja.cjs.js +1 -1
- package/dist/locales/ja.mjs +22 -0
- package/dist/locales/ko.cjs.js +1 -1
- package/dist/locales/ko.mjs +22 -0
- package/dist/locales/nb.cjs.js +1 -1
- package/dist/locales/nb.mjs +22 -0
- package/dist/locales/nl.cjs.js +1 -1
- package/dist/locales/nl.mjs +22 -0
- package/dist/locales/pl.cjs.js +1 -1
- package/dist/locales/pl.mjs +22 -0
- package/dist/locales/pt-BR.cjs.js +1 -1
- package/dist/locales/pt-BR.mjs +22 -0
- package/dist/locales/ro.cjs.js +1 -1
- package/dist/locales/ro.mjs +22 -0
- package/dist/locales/ru.cjs.js +1 -1
- package/dist/locales/ru.mjs +22 -0
- package/dist/locales/sv.cjs.js +1 -1
- package/dist/locales/sv.mjs +22 -0
- package/dist/locales/th.cjs.js +1 -1
- package/dist/locales/th.mjs +22 -0
- package/dist/locales/tr.cjs.js +1 -1
- package/dist/locales/tr.mjs +22 -0
- package/dist/locales/uk.cjs.js +1 -1
- package/dist/locales/uk.mjs +22 -0
- package/dist/locales/ur.cjs.js +1 -1
- package/dist/locales/ur.mjs +22 -0
- package/dist/locales/vi.cjs.js +1 -1
- package/dist/locales/vi.mjs +22 -0
- package/dist/locales/zh-Hans.cjs.js +1 -1
- package/dist/locales/zh-Hans.mjs +22 -0
- package/dist/locales/zh-Hant.cjs.js +1 -1
- package/dist/locales/zh-Hant.mjs +22 -0
- package/dist/vjdesigns-ui.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,858 +1,872 @@
|
|
|
1
|
-
# vjdesigns-ui
|
|
2
|
-
|
|
3
|
-
**Accessible components, with the proof.** A React 19 component library from VJ Designs: more than 80 components built to WCAG 2.2 AA and audited on every release with axe-core in light and dark mode, with keyboard support, focus management and screen reader names already done. Each component's docs page lists its keys, roles and audit results. Your content, labels and flows are still yours to check; [vjdesigns-ui.org/accessibility](https://vjdesigns-ui.org/accessibility) lists exactly what that covers.
|
|
4
|
-
|
|
5
|
-
It also has light and dark modes, five brand palettes,
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
🌐 **Website and Pro:** [vjdesigns-ui.org](https://vjdesigns-ui.org)
|
|
10
|
-
📚 **Live docs and Storybook:** [component.vjdesigns.org](https://component.vjdesigns.org)
|
|
11
|
-
📦 **npm:** [@vjdesigns/vjdesigns-ui](https://www.npmjs.com/package/@vjdesigns/vjdesigns-ui)
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
Install the package along with React and React DOM. The library requires **React 19**, which the components need in order to render:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install @vjdesigns/vjdesigns-ui react react-dom
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
If your project already uses React, you only need the first package:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm install @vjdesigns/vjdesigns-ui
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Browser support
|
|
30
|
-
|
|
31
|
-
The components support the current and previous major versions of evergreen browsers, with these minimums:
|
|
32
|
-
|
|
33
|
-
| Browser | Minimum version |
|
|
34
|
-
| --- | --- |
|
|
35
|
-
| Chrome, Edge, and other Chromium browsers | 111 |
|
|
36
|
-
| Firefox | 121 |
|
|
37
|
-
| Safari (macOS and iOS) | 16.2 |
|
|
38
|
-
|
|
39
|
-
These are set by the CSS the components rely on: `color-mix()`, container queries, `:has()` (which draws some keyboard focus rings), and the `inert` attribute. Internet Explorer and legacy (non-Chromium) Edge aren't supported.
|
|
40
|
-
|
|
41
|
-
A few newer features are used only where available, with a fallback elsewhere: `field-sizing` for auto-growing `Textarea` (measured in JavaScript otherwise), the `scrollend` event in `Carousel`, and `hidden="until-found"` for find-in-page in `Accordion` and `Collapsible`.
|
|
42
|
-
|
|
43
|
-
### Import the styles
|
|
44
|
-
|
|
45
|
-
The component styles and shared design tokens ship as a separate stylesheet. Import it **once** at your app's entry point, or the components will render unstyled.
|
|
46
|
-
|
|
47
|
-
**React:** in `main.tsx` (or `App.tsx`)
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Angular:** add it to the `styles` array in `angular.json`
|
|
54
|
-
|
|
55
|
-
```json
|
|
56
|
-
"styles": [
|
|
57
|
-
"node_modules/@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css",
|
|
58
|
-
"src/styles.css"
|
|
59
|
-
]
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
**Vue:** in `main.ts`
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## Usage
|
|
71
|
-
|
|
72
|
-
The components are built with React. You can use them directly in a React project. In Angular or Vue, you mount them inside a small wrapper component, as shown below.
|
|
73
|
-
|
|
74
|
-
### React
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
import { useState } from "react";
|
|
78
|
-
import { Button, CheckBox } from "@vjdesigns/vjdesigns-ui";
|
|
79
|
-
|
|
80
|
-
export function SignupForm() {
|
|
81
|
-
const [accepted, setAccepted] = useState(false);
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<form>
|
|
85
|
-
<CheckBox
|
|
86
|
-
label="Accept terms"
|
|
87
|
-
checked={accepted}
|
|
88
|
-
onCheckedChange={setAccepted}
|
|
89
|
-
/>
|
|
90
|
-
<Button
|
|
91
|
-
variant="solid"
|
|
92
|
-
tone="primary"
|
|
93
|
-
size="md"
|
|
94
|
-
disabled={!accepted}
|
|
95
|
-
onClick={() => console.log("Submitted")}
|
|
96
|
-
>
|
|
97
|
-
Submit
|
|
98
|
-
</Button>
|
|
99
|
-
</form>
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Next.js (App Router) and React Server Components
|
|
105
|
-
|
|
106
|
-
The library works in Server Components. Interactive components (anything with state, effects, or context: `Button`, `DataGrid`, `Modal`, ...) are marked `"use client"`, so you can render them from a Server Component like any client component. Utilities (`cx`, `sortRows`, `createBrandPalette`, `getLocaleDirection`, ...) and the locale catalogs have no directive, so you can call or read them on the server too. Every component also renders on the server for the first paint.
|
|
107
|
-
|
|
108
|
-
Put the providers in a small client file of your own, and render it from the root layout:
|
|
109
|
-
|
|
110
|
-
```tsx
|
|
111
|
-
// app/providers.tsx
|
|
112
|
-
"use client";
|
|
113
|
-
import { LocaleProvider, ToastProvider } from "@vjdesigns/vjdesigns-ui";
|
|
114
|
-
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
115
|
-
import type { ReactNode } from "react";
|
|
116
|
-
|
|
117
|
-
export function Providers({ children }: { children: ReactNode }) {
|
|
118
|
-
return (
|
|
119
|
-
<LocaleProvider locale="es" messages={es}>
|
|
120
|
-
<ToastProvider>{children}</ToastProvider>
|
|
121
|
-
</LocaleProvider>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
```tsx
|
|
127
|
-
// app/layout.tsx (a Server Component)
|
|
128
|
-
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
129
|
-
import { getLocaleDirection } from "@vjdesigns/vjdesigns-ui";
|
|
130
|
-
import { Providers } from "./providers";
|
|
131
|
-
|
|
132
|
-
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
133
|
-
return (
|
|
134
|
-
<html lang="es" dir={getLocaleDirection("es")}>
|
|
135
|
-
<body>
|
|
136
|
-
<Providers>{children}</Providers>
|
|
137
|
-
</body>
|
|
138
|
-
</html>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
Two rules of Server Components to keep in mind:
|
|
144
|
-
|
|
145
|
-
- **Functions can't be passed from a Server Component to a client one.** That includes event handlers (`onClick`), DataGrid columns with `cell` or `value` functions, and the locale catalogs themselves (their plural messages are functions, which is why `LocaleProvider` goes in the client providers file above). Render those components from your own `"use client"` file.
|
|
146
|
-
- **Compound parts can't be reached with a dot from a Server Component** (`Tabs.List`, `Menu.Item`): Next.js reports "You cannot dot into a client module". Use them inside a `"use client"` file, or use the named exports where they exist (`CardHeader`, `CardBody`, `NavbarBrand`, ...).
|
|
147
|
-
|
|
148
|
-
### Angular
|
|
149
|
-
|
|
150
|
-
Make a standalone wrapper that renders the React component into its host element. The wrapper uses `createElement`, so you don't need to change your JSX or TSX settings.
|
|
151
|
-
|
|
152
|
-
```ts
|
|
153
|
-
// vj-button.component.ts
|
|
154
|
-
import {
|
|
155
|
-
AfterViewInit,
|
|
156
|
-
Component,
|
|
157
|
-
ElementRef,
|
|
158
|
-
EventEmitter,
|
|
159
|
-
Input,
|
|
160
|
-
OnChanges,
|
|
161
|
-
OnDestroy,
|
|
162
|
-
Output,
|
|
163
|
-
ViewChild,
|
|
164
|
-
} from "@angular/core";
|
|
165
|
-
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
166
|
-
import { createRoot, Root } from "react-dom/client";
|
|
167
|
-
import {
|
|
168
|
-
Button,
|
|
169
|
-
type ButtonProps,
|
|
170
|
-
type ButtonVariant,
|
|
171
|
-
type Size,
|
|
172
|
-
type Tone,
|
|
173
|
-
} from "@vjdesigns/vjdesigns-ui";
|
|
174
|
-
|
|
175
|
-
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
176
|
-
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
177
|
-
|
|
178
|
-
@Component({
|
|
179
|
-
selector: "vj-button",
|
|
180
|
-
standalone: true,
|
|
181
|
-
template: `<span #host></span>`,
|
|
182
|
-
})
|
|
183
|
-
export class VjButtonComponent implements AfterViewInit, OnChanges, OnDestroy {
|
|
184
|
-
@ViewChild("host", { static: true }) host!: ElementRef<HTMLElement>;
|
|
185
|
-
|
|
186
|
-
@Input() label = "";
|
|
187
|
-
@Input() variant: ButtonVariant = "solid";
|
|
188
|
-
@Input() tone: Tone = "primary";
|
|
189
|
-
@Input() size: Size = "md";
|
|
190
|
-
@Input() disabled = false;
|
|
191
|
-
@Output() clicked = new EventEmitter<MouseEvent>();
|
|
192
|
-
|
|
193
|
-
private root?: Root;
|
|
194
|
-
|
|
195
|
-
ngAfterViewInit() {
|
|
196
|
-
this.root = createRoot(this.host.nativeElement);
|
|
197
|
-
this.render();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
ngOnChanges() {
|
|
201
|
-
this.render();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
ngOnDestroy() {
|
|
205
|
-
this.root?.unmount();
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private render() {
|
|
209
|
-
this.root?.render(
|
|
210
|
-
createElement(
|
|
211
|
-
ReactButton,
|
|
212
|
-
{
|
|
213
|
-
variant: this.variant,
|
|
214
|
-
tone: this.tone,
|
|
215
|
-
size: this.size,
|
|
216
|
-
disabled: this.disabled,
|
|
217
|
-
onClick: (event: ReactMouseEvent) => this.clicked.emit(event.nativeEvent),
|
|
218
|
-
},
|
|
219
|
-
this.label // the button's text is passed as children
|
|
220
|
-
)
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
Import the wrapper wherever you need it:
|
|
227
|
-
|
|
228
|
-
```ts
|
|
229
|
-
// app.component.ts
|
|
230
|
-
import { Component } from "@angular/core";
|
|
231
|
-
import { VjButtonComponent } from "./vj-button.component";
|
|
232
|
-
|
|
233
|
-
@Component({
|
|
234
|
-
selector: "app-root",
|
|
235
|
-
standalone: true,
|
|
236
|
-
imports: [VjButtonComponent],
|
|
237
|
-
template: `<vj-button label="Submit" tone="primary" (clicked)="onSubmit()" />`,
|
|
238
|
-
})
|
|
239
|
-
export class AppComponent {
|
|
240
|
-
onSubmit() {
|
|
241
|
-
console.log("Submitted");
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Vue 3
|
|
247
|
-
|
|
248
|
-
Make a wrapper component that mounts the React component when it loads and re-renders it whenever its props change.
|
|
249
|
-
|
|
250
|
-
```vue
|
|
251
|
-
<!-- VjButton.vue -->
|
|
252
|
-
<script setup lang="ts">
|
|
253
|
-
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
254
|
-
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
255
|
-
import { createRoot, type Root } from "react-dom/client";
|
|
256
|
-
import {
|
|
257
|
-
Button,
|
|
258
|
-
type ButtonProps,
|
|
259
|
-
type ButtonVariant,
|
|
260
|
-
type Size,
|
|
261
|
-
type Tone,
|
|
262
|
-
} from "@vjdesigns/vjdesigns-ui";
|
|
263
|
-
|
|
264
|
-
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
265
|
-
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
266
|
-
|
|
267
|
-
const props = withDefaults(
|
|
268
|
-
defineProps<{
|
|
269
|
-
label: string;
|
|
270
|
-
variant?: ButtonVariant;
|
|
271
|
-
tone?: Tone;
|
|
272
|
-
size?: Size;
|
|
273
|
-
disabled?: boolean;
|
|
274
|
-
}>(),
|
|
275
|
-
{ variant: "solid", tone: "primary", size: "md", disabled: false }
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
const emit = defineEmits<{ click: [event: MouseEvent] }>();
|
|
279
|
-
|
|
280
|
-
const host = ref<HTMLElement | null>(null);
|
|
281
|
-
let root: Root | undefined;
|
|
282
|
-
|
|
283
|
-
function render() {
|
|
284
|
-
root?.render(
|
|
285
|
-
createElement(
|
|
286
|
-
ReactButton,
|
|
287
|
-
{
|
|
288
|
-
variant: props.variant,
|
|
289
|
-
tone: props.tone,
|
|
290
|
-
size: props.size,
|
|
291
|
-
disabled: props.disabled,
|
|
292
|
-
onClick: (event: ReactMouseEvent) => emit("click", event.nativeEvent),
|
|
293
|
-
},
|
|
294
|
-
props.label // the button's text is passed as children
|
|
295
|
-
)
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
onMounted(() => {
|
|
300
|
-
root = createRoot(host.value!);
|
|
301
|
-
render();
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
watch(() => ({ ...props }), render);
|
|
305
|
-
|
|
306
|
-
onBeforeUnmount(() => root?.unmount());
|
|
307
|
-
</script>
|
|
308
|
-
|
|
309
|
-
<template>
|
|
310
|
-
<span ref="host" />
|
|
311
|
-
</template>
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
Use it like any other Vue component:
|
|
315
|
-
|
|
316
|
-
```vue
|
|
317
|
-
<script setup lang="ts">
|
|
318
|
-
import VjButton from "./VjButton.vue";
|
|
319
|
-
|
|
320
|
-
const onSubmit = () => console.log("Submitted");
|
|
321
|
-
</script>
|
|
322
|
-
|
|
323
|
-
<template>
|
|
324
|
-
<VjButton label="Submit" tone="primary" @click="onSubmit" />
|
|
325
|
-
</template>
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
> **Tip:** Wrap `CheckBox` and any other component the same way. Pass its props into `createElement`, and send its callbacks back out as Angular outputs or Vue emits. For `CheckBox`, that means sending `onCheckedChange` back out.
|
|
329
|
-
|
|
330
|
-
---
|
|
331
|
-
|
|
332
|
-
## Theming
|
|
333
|
-
|
|
334
|
-
Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:
|
|
335
|
-
|
|
336
|
-
```tsx
|
|
337
|
-
import { Theme, Button } from "@vjdesigns/vjdesigns-ui";
|
|
338
|
-
|
|
339
|
-
<Theme mode="dark" brand="purple" fill>
|
|
340
|
-
<Button>Dark, purple button</Button>
|
|
341
|
-
</Theme>
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
| Prop | Type | Default | Description |
|
|
345
|
-
| --- | --- | --- | --- |
|
|
346
|
-
| `mode` | `"light" \| "dark"` | inherited | Color mode for everything inside. |
|
|
347
|
-
| `brand` | `"black" \| "blue" \| "gold" \| "green" \| "purple"`, a hex color, or `{ light, dark }` | inherited | Brand palette for buttons, links, focus rings and indicators. |
|
|
348
|
-
| `accent` | `"brand" | "lime"`, a hex color, or `{ light, dark }` | inherited (the brand's own) | The bright highlight on badges, switches, progress bars, sliders, steppers, and active navigation. |
|
|
349
|
-
| `fill` | `boolean` | `false` | Paints the theme's background and text color on the wrapper. |
|
|
350
|
-
|
|
351
|
-
Outside React (or to theme the whole page), set the attributes on `<html>` instead:
|
|
352
|
-
|
|
353
|
-
```html
|
|
354
|
-
<html data-theme="dark" data-brand="purple" data-accent="lime">
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
### Accent color
|
|
358
|
-
|
|
359
|
-
The accent is the energetic highlight: badges, switches, progress bars, sliders, steppers, and the active link in the Navbar. By default it follows the brand, as a bright shade of the brand's own color, so it always fits:
|
|
360
|
-
|
|
361
|
-
| Brand | Default accent |
|
|
362
|
-
| --- | --- |
|
|
363
|
-
| `blue` (default) | sky blue `#76c7ff` |
|
|
364
|
-
| `purple` | lavender `#c0b0ff` |
|
|
365
|
-
| `gold` | amber `#f5ad5f` |
|
|
366
|
-
| `green` | mint `#72d4ad` |
|
|
367
|
-
| `black` | lime `#c8f031` (black has no hue to build on) |
|
|
368
|
-
| a custom hex | generated from that color |
|
|
369
|
-
|
|
370
|
-
To choose a different one:
|
|
371
|
-
|
|
372
|
-
```tsx
|
|
373
|
-
<Theme accent="lime">…</Theme> // the original bright yellow-green ("volt", its former name, still works)
|
|
374
|
-
<Theme accent="#ff6b00">…</Theme> // any color
|
|
375
|
-
<Theme accent="brand">…</Theme> // back to the brand's own, inside an area with another accent
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
Accents always carry dark text. A color too dark for that is lightened (same hue) just enough to meet WCAG AA, with a warning in development. An accent you set also holds inside nested brands. In CSS, `accentCss("name", "#ff6b00")` generates a `[data-accent="name"]` rule, like `brandCss` below.
|
|
379
|
-
|
|
380
|
-
### Custom brand colors
|
|
381
|
-
|
|
382
|
-
Pass any hex color as `brand` and a full palette is generated for both modes:
|
|
383
|
-
|
|
384
|
-
```tsx
|
|
385
|
-
<Theme brand="#e11d48">…</Theme>
|
|
386
|
-
<Theme brand={{ light: "#4338ca", dark: "#f472b6" }}>…</Theme>
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
Every generated palette meets WCAG 2.2 AA. A single color is used exactly as given in the mode where it has enough contrast (dark colors in light mode, light colors in dark mode), and the other mode gets a matching shade of the same hue. If a color doesn't have enough contrast (for example, a mid-tone that fails in both modes), its lightness is shifted just enough to pass, and a warning is logged in development.
|
|
390
|
-
|
|
391
|
-
To define a brand in CSS instead (for the whole page, applied before any JavaScript runs), generate a stylesheet rule with `brandCss`:
|
|
392
|
-
|
|
393
|
-
```ts
|
|
394
|
-
import { brandCss } from "@vjdesigns/vjdesigns-ui";
|
|
395
|
-
|
|
396
|
-
brandCss("acme", "#e11d48"); // '[data-brand="acme"] { --brand-light-primary: … }'
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
Add the rule to your stylesheet and use `<html data-brand="acme">`. `createBrandPalette(color)` returns the generated colors as an object, if you need them directly.
|
|
400
|
-
|
|
401
|
-
### Tailwind CSS
|
|
402
|
-
|
|
403
|
-
A Tailwind CSS v4 preset turns the design tokens into utilities, so your own layouts match the components. Import it after Tailwind in your CSS, and keep importing the library's stylesheet as usual:
|
|
404
|
-
|
|
405
|
-
```css
|
|
406
|
-
@import "tailwindcss";
|
|
407
|
-
@import "@vjdesigns/vjdesigns-ui/tailwind.css";
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
```tsx
|
|
411
|
-
<section className="bg-surface text-text rounded-xl shadow-md p-6">
|
|
412
|
-
<h2 className="font-display text-2xl tracking-tight">Season stats</h2>
|
|
413
|
-
<p className="text-text-muted">Updated after every game.</p>
|
|
414
|
-
<span className="bg-accent text-on-accent rounded-control px-3">New</span>
|
|
415
|
-
</section>
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
Every utility points at a token (`bg-primary` is `var(--color-primary)`), so Tailwind classes follow `Theme`, `data-theme`, `data-brand`, and `data-accent` exactly like the components, with no `dark:` variants needed.
|
|
419
|
-
|
|
420
|
-
| Group | Utilities |
|
|
421
|
-
| --- | --- |
|
|
422
|
-
| Colors | `bg-`, `text-`, `border-`, `ring-`, … with `bg`, `surface` (`-raised`, `-sunken`, `-hover`, `-active`), `overlay`, `text` (`-muted`, `-disabled`, `-inverse`), `border` (`-strong`, `-input`), `focus-ring`, `link-visited`; and for `primary`, `accent`, `success`, `warning`, `danger`, `info`, `neutral`: the solid color, `-hover`, `-active`, `on-…` (text on the solid), `-subtle`, `-subtle-hover`, `-subtle-text`, `-border`. Opacity modifiers work (`bg-primary/50`). |
|
|
423
|
-
| Charts | `bg-chart-1` to `bg-chart-8`, for fills only, in that order. Slots 3 to 5 are under 3:1 on white, so pair them with a legend, labels, or a data table. |
|
|
424
|
-
| Type | `font-display` (headings, buttons, labels, numbers), `font-body`, `font-mono`; `text-xs` to `text-6xl` (plus `text-md`); `font-regular` to `font-black`; `leading-tight`, `-snug`, `-normal`, `-relaxed`; `tracking-tight`, `-normal`, `-wide`, `-caps` |
|
|
425
|
-
| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |
|
|
426
|
-
| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |
|
|
427
|
-
| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |
|
|
428
|
-
| Sizes | `h-control-sm`, `-md`, `-lg` (and `w-`, `min-h-`, …), `size-target` (the 24px minimum pointer target), `max-w-xs` to `max-w-2xl` and `@xs:` to `@2xl:` container queries |
|
|
429
|
-
| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |
|
|
430
|
-
| Dark mode | `dark:` follows `data-theme="dark"`, not the OS setting. |
|
|
431
|
-
|
|
432
|
-
Tailwind's numeric spacing (`p-4` = 1rem) already matches the 4px token scale, and the breakpoints (`sm:` to `2xl:`) are the same as Tailwind's.
|
|
433
|
-
|
|
434
|
-
Some Tailwind names change meaning with the preset: `rounded-*`, `shadow-*`, `blur-sm`/`-lg`, `ease-in`/`-out`, `font-mono`, `font-medium` to `font-black`, `leading-*`, and the `text-*` sizes take the library's values (for example, `rounded-md` is 12px and `font-black` is 800). So do the containers: `max-w-md` and `@md:` are 48rem, not Tailwind's 28rem. The library's stylesheet already gives some of these names its own values once it's loaded, even without the preset; the preset keeps the utilities and the container queries consistent.
|
|
435
|
-
|
|
436
|
-
For text contrast, use the pairs the components use: `text-text` or `text-text-muted` on `bg-bg`, `bg-surface`, and the other surfaces; `text-on-primary` on `bg-primary` (likewise `on-accent`, `on-success`, …); `text-primary-subtle-text` on `bg-primary-subtle` (likewise for each tone). These pairs meet WCAG 2.2 AA in both themes and every brand. Don't use accent or chart colors for text.
|
|
437
|
-
|
|
438
|
-
The preset doesn't change the components, and Tailwind's preflight (its CSS reset) doesn't override them, whichever stylesheet loads first.
|
|
439
|
-
|
|
440
|
-
---
|
|
441
|
-
|
|
442
|
-
## Languages
|
|
443
|
-
|
|
444
|
-
Components have built-in text: button names like "Close" and "Next page", screen-reader announcements like "3 results available", validation messages, and date formats. Wrap your app in `LocaleProvider` to show all of it in another language:
|
|
445
|
-
|
|
446
|
-
```tsx
|
|
447
|
-
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
|
|
448
|
-
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
449
|
-
|
|
450
|
-
<LocaleProvider locale="es" messages={es}>
|
|
451
|
-
<App />
|
|
452
|
-
</LocaleProvider>
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
`LocaleProvider` sets:
|
|
456
|
-
|
|
457
|
-
- **Built-in text** for every component, from `messages`.
|
|
458
|
-
- **Dates and numbers** in the locale's format (`23/10/2026`, `1.234,5`), and plurals that follow the language's rules.
|
|
459
|
-
- **Writing direction**: Arabic, Hebrew, Persian, and Urdu get `dir="rtl"`, and layouts and arrow keys mirror.
|
|
460
|
-
- **`lang`** on its wrapper, so screen readers pronounce the text correctly. Popups (menus, dialogs, tooltips) keep the language of the area that opened them.
|
|
461
|
-
|
|
462
|
-
Each locale is a separate import, so your app only downloads the languages it uses. Without a `LocaleProvider`, components use English text and the browser's date and number format.
|
|
463
|
-
|
|
464
|
-
This library only translates its own built-in text. Text your app passes in, like `<Button>Save</Button>`, is your app's content: translate it with your app's i18n library (react-i18next, FormatJS, and so on).
|
|
465
|
-
|
|
466
|
-
### What gets translated
|
|
467
|
-
|
|
468
|
-
The language is never picked automatically from where the user lives or their browser settings. Your app chooses it by rendering a `LocaleProvider`. For example, with `<LocaleProvider locale="de" messages={de}>`:
|
|
469
|
-
|
|
470
|
-
| | Translated? |
|
|
471
|
-
| --- | --- |
|
|
472
|
-
| Text your app passes in, like `<Button>Save</Button>` | No: your app translates it |
|
|
473
|
-
| Built-in names, like "Close", "Next page", "Clear search" | Yes: "Schließen", "Nächste Seite", "Suche löschen" |
|
|
474
|
-
| Screen-reader announcements, like "3 results available" | Yes: "3 Ergebnisse verfügbar" |
|
|
475
|
-
| Validation messages, empty states, file-upload prompts | Yes |
|
|
476
|
-
| Dates and numbers | Yes: "23.10.2026", "4,5" |
|
|
477
|
-
|
|
478
|
-
To follow the user's browser language, pass it yourself: `locale={navigator.language}` together with the matching `messages` (see [Switching language at runtime](#switching-language-at-runtime)).
|
|
479
|
-
|
|
480
|
-
### Bundled languages
|
|
481
|
-
|
|
482
|
-
`ar` Arabic · `bn` Bengali · `cs` Czech · `da` Danish · `de` German · `el` Greek · `es` Spanish · `fa` Persian · `fi` Finnish · `fr` French · `he` Hebrew · `hi` Hindi · `hu` Hungarian · `id` Indonesian · `it` Italian · `ja` Japanese · `ko` Korean · `nb` Norwegian Bokmål · `nl` Dutch · `pl` Polish · `pt-BR` Portuguese (Brazil) · `ro` Romanian · `ru` Russian · `sv` Swedish · `th` Thai · `tr` Turkish · `uk` Ukrainian · `ur` Urdu · `vi` Vietnamese · `zh-Hans` Chinese (Simplified) · `zh-Hant` Chinese (Traditional), plus English (the default).
|
|
483
|
-
|
|
484
|
-
The translations are machine-generated and haven't been reviewed by native speakers yet. If you find a wrong or awkward phrase, override it (below) and report it so the bundled locale can be fixed. (Working on the library itself? See [Translating built-in text](#translating-built-in-text).)
|
|
485
|
-
|
|
486
|
-
### Changing a few strings
|
|
487
|
-
|
|
488
|
-
Pass only the strings you want to change. Everything else falls back to the outer provider's language (English at the top):
|
|
489
|
-
|
|
490
|
-
```tsx
|
|
491
|
-
<LocaleProvider locale="en-GB" messages={{ pagination: { next: "Onwards" } }}>
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
Providers nest, so an inner provider can switch the language for one part of the page. Per-component props such as `clearLabel` or `labels` still win over the provider.
|
|
495
|
-
|
|
496
|
-
### Other languages
|
|
497
|
-
|
|
498
|
-
For a language that isn't bundled, write a complete messages object. TypeScript flags any missing string. Use English as the template:
|
|
499
|
-
|
|
500
|
-
```ts
|
|
501
|
-
import { en, plural, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
502
|
-
|
|
503
|
-
const p = plural("sw");
|
|
504
|
-
export const sw: Messages = {
|
|
505
|
-
...en,
|
|
506
|
-
pagination: { ...en.pagination, next: "Ukurasa unaofuata", previous: "Ukurasa uliopita" },
|
|
507
|
-
searchInput: {
|
|
508
|
-
...en.searchInput,
|
|
509
|
-
results: (count) => p(count, { "=0": "Hakuna matokeo", one: "Tokeo #", other: "Matokeo #" }),
|
|
510
|
-
},
|
|
511
|
-
// ...
|
|
512
|
-
};
|
|
513
|
-
```
|
|
514
|
-
|
|
515
|
-
`plural(locale)` picks the right plural form for any language (`#` is the formatted number).
|
|
516
|
-
|
|
517
|
-
### Switching language at runtime
|
|
518
|
-
|
|
519
|
-
List the languages your app offers as loaders, so each one is downloaded only when picked:
|
|
520
|
-
|
|
521
|
-
```tsx
|
|
522
|
-
import { LocaleProvider, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
523
|
-
|
|
524
|
-
const loaders: Record<string, () => Promise<{ default: Messages }>> = {
|
|
525
|
-
es: () => import("@vjdesigns/vjdesigns-ui/locales/es"),
|
|
526
|
-
fr: () => import("@vjdesigns/vjdesigns-ui/locales/fr"),
|
|
527
|
-
ar: () => import("@vjdesigns/vjdesigns-ui/locales/ar"),
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
function App({ lang }: { lang: string }) {
|
|
531
|
-
const [messages, setMessages] = useState<Messages>();
|
|
532
|
-
useEffect(() => {
|
|
533
|
-
const load = loaders[lang];
|
|
534
|
-
if (load) load().then((mod) => setMessages(mod.default));
|
|
535
|
-
else setMessages(undefined); // English
|
|
536
|
-
}, [lang]);
|
|
537
|
-
// Until a language loads, the previous one (or English) shows.
|
|
538
|
-
return <LocaleProvider locale={lang} messages={messages}>…</LocaleProvider>;
|
|
539
|
-
}
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
For server rendering, also set `<html lang="…" dir="…">` on the page. `getLocaleDirection(locale)` returns `"ltr"` or `"rtl"`.
|
|
543
|
-
|
|
544
|
-
---
|
|
545
|
-
|
|
546
|
-
## Form validation
|
|
547
|
-
|
|
548
|
-
> **Front-end validation is not security.** It helps people fill in a form correctly, but anyone can turn off JavaScript or send requests straight to your server. Always validate again on the server. The format checks below (`isEmail`, `isIP`, …) are plain functions you can reuse there.
|
|
549
|
-
|
|
550
|
-
`useFormValidation` checks a form when it's submitted, using the browser's own rules on each input (`required`, `type="email"`, `minLength`, `pattern`, `min` / `max`) plus any rules you add. Messages follow the current language.
|
|
551
|
-
|
|
552
|
-
```tsx
|
|
553
|
-
import {
|
|
554
|
-
useFormValidation, rules, ErrorSummary, Field, Input, PasswordInput, Button,
|
|
555
|
-
} from "@vjdesigns/vjdesigns-ui";
|
|
556
|
-
|
|
557
|
-
function SignUp() {
|
|
558
|
-
const form = useFormValidation({
|
|
559
|
-
rules: {
|
|
560
|
-
confirm: rules.matches("password", "The passwords don't match."),
|
|
561
|
-
serverIp: rules.ip(), // IPv4 or IPv6
|
|
562
|
-
},
|
|
563
|
-
// Runs only when everything is valid. Return the server's errors to show them on their fields.
|
|
564
|
-
onValid: async (values) => {
|
|
565
|
-
const response = await api.signUp(values);
|
|
566
|
-
return response.errors; // e.g. { username: "That username is taken." }
|
|
567
|
-
},
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
return (
|
|
571
|
-
<form {...form.formProps}>
|
|
572
|
-
<ErrorSummary ref={form.summaryRef} errors={form.errorList} />
|
|
573
|
-
<Field label="Email" required error={form.errors.email}>
|
|
574
|
-
<Input name="email" type="email" />
|
|
575
|
-
</Field>
|
|
576
|
-
<Field label="Password" required error={form.errors.password}>
|
|
577
|
-
<PasswordInput name="password" minLength={12} />
|
|
578
|
-
</Field>
|
|
579
|
-
<Field label="Confirm password" required error={form.errors.confirm}>
|
|
580
|
-
<PasswordInput name="confirm" />
|
|
581
|
-
</Field>
|
|
582
|
-
<Field label="Server IP" error={form.errors.serverIp}>
|
|
583
|
-
<Input name="serverIp" />
|
|
584
|
-
</Field>
|
|
585
|
-
<Button type="submit" loading={form.isSubmitting}>Create account</Button>
|
|
586
|
-
</form>
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
How it behaves:
|
|
592
|
-
|
|
593
|
-
- **On submit**, every field is checked. If anything is wrong, the `ErrorSummary` at the top lists the problems and takes focus, so screen readers announce it. Each item links to its field. Without a summary, focus goes to the first invalid field.
|
|
594
|
-
- **Errors are keyed by the field's `name`.** Pass `form.errors.<name>` to each `Field`'s `error`.
|
|
595
|
-
- **After a failed submit**, an error disappears as soon as the field is fixed (while typing), and a field is fully re-checked when you leave it. It doesn't nag while you're still typing.
|
|
596
|
-
- **Server errors** (returned from `onValid`, or set with `form.setErrors({...})`) show on their fields and stay until that field is edited.
|
|
597
|
-
- **Emails** must have a real domain (`name@example.com`). The browser's own check also accepts `name@localhost`.
|
|
598
|
-
|
|
599
|
-
### Rules and format checks
|
|
600
|
-
|
|
601
|
-
| Rule | Checks |
|
|
602
|
-
| --- | --- |
|
|
603
|
-
| `rules.required()` | Not empty (for controls without a native `required`) |
|
|
604
|
-
| `rules.email()` | An email address in the usual format, with a top-level domain |
|
|
605
|
-
| `rules.ip()` / `rules.ip({ version: 4 })` / `rules.ip({ version: 6 })` | An IPv4 or IPv6 address |
|
|
606
|
-
| `rules.minLength(n)` / `rules.maxLength(n)` | Length in characters |
|
|
607
|
-
| `rules.pattern(/regex/, "message")` | The whole value matches |
|
|
608
|
-
| `rules.matches("otherField")` | Equals another field (confirm password) |
|
|
609
|
-
| your own `(value, { values }) => message` | Anything else |
|
|
610
|
-
|
|
611
|
-
Each rule takes an optional custom message. The checks behind them are exported for use anywhere, including your server:
|
|
612
|
-
|
|
613
|
-
- `isEmail(value)`
|
|
614
|
-
- `isIPv4(value)`: four numbers 0–255, no leading zeros
|
|
615
|
-
- `isIPv6(value)`: including `::` shorthand and IPv4 tails like `::ffff:192.168.0.1`
|
|
616
|
-
- `isIP(value, version?)`
|
|
617
|
-
|
|
618
|
-
---
|
|
619
|
-
|
|
620
|
-
## Hooks
|
|
621
|
-
|
|
622
|
-
Tested hooks for everyday UI work, exported from the package root (`import { useDisclosure } from "@vjdesigns/vjdesigns-ui"`). All are safe in server rendering and tree-shakable: each costs only itself, mostly well under 1 KB. Live demos are in Storybook under Hooks.
|
|
623
|
-
|
|
624
|
-
| Hook | What it does |
|
|
625
|
-
| --- | --- |
|
|
626
|
-
| `useDisclosure(initial?)` | Open/closed state with stable `open`, `close`, `toggle` handlers (for Modal, Drawer, Popover) |
|
|
627
|
-
| `useToggle(values?)` | Cycles through values: a boolean, or a list like `["list", "grid"]` |
|
|
628
|
-
| `usePrevious(value)` | The value from before its last change |
|
|
629
|
-
| `useDebouncedValue(value, ms)` | The value, updated after it stops changing (search as you type) |
|
|
630
|
-
| `useDebouncedCallback(fn, ms)` | A function that runs once after calls stop, with `cancel` and `flush` |
|
|
631
|
-
| `useThrottledCallback(fn, ms)` | A function that runs at most once per interval (scroll, resize) |
|
|
632
|
-
| `useInterval(fn, ms \| null)` / `useTimeout(fn, ms \| null)` | Timers that always call the latest function; `null` pauses |
|
|
633
|
-
| `useLocalStorage(key, default)` / `useSessionStorage` | State saved in storage, synced across components and tabs, and never throws when storage is blocked |
|
|
634
|
-
| `useClipboard()` | `copy(text)` with a `copied` flag, and a fallback when the Clipboard API is blocked |
|
|
635
|
-
| `useHotkeys([[keys, fn]])` | Page shortcuts. `mod` is ⌘ or Ctrl. Plain keys don't fire while typing. `getHotkeyHandler` does the same for one element |
|
|
636
|
-
| `useEventListener(type, fn, target?)` | An event listener that always calls the latest handler |
|
|
637
|
-
| `useClickOutside(fn)` | Calls `fn` on a press or focus move outside the element |
|
|
638
|
-
| `useIntersection(options)` | Whether an element is in view (lazy loading, entrance effects) |
|
|
639
|
-
| `useElementSize()` | An element's size as it resizes |
|
|
640
|
-
| `useVirtualizer(options)` | Renders only the visible items of a long list (what `VirtualList` uses), with variable heights and `scrollToIndex` |
|
|
641
|
-
| `useMediaQuery(query)` / `useResponsiveValue(value)` | A synced media query, or a responsive value resolved for the viewport |
|
|
642
|
-
| `useHydrated()` | False during server rendering, true after (avoids hydration mismatches) |
|
|
643
|
-
| `useReducedMotion()` / `useColorScheme()` | The user's motion and color-scheme preferences |
|
|
644
|
-
| `useOnline()` / `useDocumentVisibility()` / `useViewportSize()` | Connection, tab visibility, and viewport size |
|
|
645
|
-
| `useControllableState`, `useFormValidation`, `useFocusTrap`, `useScrollLock`, … | The building blocks the components use, for your own components |
|
|
646
|
-
|
|
647
|
-
---
|
|
648
|
-
|
|
649
|
-
## AI assistants
|
|
650
|
-
|
|
651
|
-
The package ships documentation written for AI coding assistants, generated from the source on every build, so it always matches the version you have installed:
|
|
652
|
-
|
|
653
|
-
| File | What it is |
|
|
654
|
-
| --- | --- |
|
|
655
|
-
| `@vjdesigns/vjdesigns-ui/llms.txt` | A short index in the [llms.txt](https://llmstxt.org) format: setup essentials and one line per component |
|
|
656
|
-
| `@vjdesigns/vjdesigns-ui/llms-full.txt` | The full reference in one file: guides, and every component's props (type, default, description), subcomponents, and examples |
|
|
657
|
-
| `@vjdesigns/vjdesigns-ui/registry.json` | The same, as structured JSON |
|
|
658
|
-
|
|
659
|
-
The files are in `node_modules/@vjdesigns/vjdesigns-ui/dist/ai/`. Point your assistant's rules or context at `llms-full.txt`.
|
|
660
|
-
|
|
661
|
-
### MCP server
|
|
662
|
-
|
|
663
|
-
For assistants that support the [Model Context Protocol](https://modelcontextprotocol.io), the package includes a small MCP server with four tools:
|
|
664
|
-
|
|
665
|
-
- `list_components`
|
|
666
|
-
- `get_component`, for exact props
|
|
667
|
-
- `search_docs`
|
|
668
|
-
- `get_guide`
|
|
669
|
-
|
|
670
|
-
It reads the docs of your installed version and needs no network access.
|
|
671
|
-
|
|
672
|
-
Claude Code:
|
|
673
|
-
|
|
674
|
-
```bash
|
|
675
|
-
claude mcp add vjdesigns-ui -- npx -p @vjdesigns/vjdesigns-ui vjdesigns-ui-mcp
|
|
676
|
-
```
|
|
677
|
-
|
|
678
|
-
Cursor (`.cursor/mcp.json`), Claude Desktop, and other clients (VS Code's `.vscode/mcp.json` uses `"servers"` instead of `"mcpServers"`):
|
|
679
|
-
|
|
680
|
-
```json
|
|
681
|
-
{
|
|
682
|
-
"mcpServers": {
|
|
683
|
-
"vjdesigns-ui": {
|
|
684
|
-
"command": "npx",
|
|
685
|
-
"args": ["-p", "@vjdesigns/vjdesigns-ui", "vjdesigns-ui-mcp"]
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
---
|
|
692
|
-
|
|
693
|
-
## Components
|
|
694
|
-
|
|
695
|
-
Every component below is exported from the package root. Full prop docs and live examples are in [Storybook](https://component.vjdesigns.org).
|
|
696
|
-
|
|
697
|
-
| Category | Components |
|
|
698
|
-
| --- | --- |
|
|
699
|
-
| **Primitives** | Button, CopyButton, IconButton, ButtonGroup, Icon, Kbd, Typography |
|
|
700
|
-
| **Layout** | Box, Container, Divider, Flex, Grid, ResizablePanels, ScrollArea, Stack |
|
|
701
|
-
| **Forms** | CheckBox, CheckBoxGroup, ColorPicker, Combobox, DatePicker, DateRangePicker, DateTimePicker, Field, FileUpload, Input, NumberInput, PasswordInput, PinInput, Radio, Rating, SearchInput, SegmentedControl, Select, Slider, Switch, TagInput, Textarea, TimePicker, ToggleGroup |
|
|
702
|
-
| **Navigation** | Breadcrumbs, ContextMenu, Link, Menu, MobileNav, Navbar, Pagination, Sidebar, SkipLink, Stepper, Tabs, Toolbar |
|
|
703
|
-
| **Overlays** | CommandPalette, Drawer, HoverCard, Modal, Popover, Tooltip |
|
|
704
|
-
| **Feedback** | Alert, Banner, ErrorSummary, Progress, Skeleton, Spinner, Toast |
|
|
705
|
-
| **Data display** | Accordion, Avatar, Badge, Card, Carousel, Chat, Chip, CodeBlock, Collapsible, Countdown, DataGrid, EmptyState, Image, List, Stat, Table, Timeline, TreeView, VirtualList |
|
|
706
|
-
| **Utilities** | Portal, Theme, VisuallyHidden |
|
|
707
|
-
|
|
708
|
-
### Button
|
|
709
|
-
|
|
710
|
-
```tsx
|
|
711
|
-
<Button variant="solid" tone="primary">Save</Button>
|
|
712
|
-
<Button variant="outline" tone="danger" startIcon={<TrashIcon />}>Delete</Button>
|
|
713
|
-
<Button href="/pricing" variant="link">See pricing</Button>
|
|
714
|
-
<Button loading loadingText="Saving…">Save</Button>
|
|
715
|
-
```
|
|
716
|
-
|
|
717
|
-
| Prop | Type | Default | Description |
|
|
718
|
-
| --- | --- | --- | --- |
|
|
719
|
-
| `children` | `ReactNode` | — | The visible label. |
|
|
720
|
-
| `variant` | `"solid" \| "soft" \| "outline" \| "ghost" \| "link" \| "inverse"` | `"solid"` | Visual style. |
|
|
721
|
-
| `tone` | `"neutral" \| "primary" \| "accent" \| "success" \| "warning" \| "danger" \| "info"` | `"primary"` | Semantic color. |
|
|
722
|
-
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding and type size. |
|
|
723
|
-
| `radius` | `"none" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "2xl" \| "pill"` | `"pill"` | Corner rounding. |
|
|
724
|
-
| `startIcon` / `endIcon` | `ReactNode` | — | Decorative icon before or after the label. Hidden from screen readers. |
|
|
725
|
-
| `loading` | `boolean` | `false` | Shows a spinner, sets `aria-busy` and ignores clicks. |
|
|
726
|
-
| `loadingText` | `ReactNode` | — | Label shown next to the spinner while loading. |
|
|
727
|
-
| `fullWidth` | `boolean` | `false` | Stretches the button to fill its container. |
|
|
728
|
-
| `compact` | `boolean` | `false` | Tighter side padding for short labels like "OK". |
|
|
729
|
-
| `disabled` | `boolean` | `false` | Disables the button. |
|
|
730
|
-
| `href` | `string` | — | Renders the button as an `<a>` link with the same styling. |
|
|
731
|
-
| `as` | `ElementType` | — | Renders as your own component, such as a React Router or Next.js `Link`. |
|
|
732
|
-
|
|
733
|
-
Also accepts all standard `<button>` attributes (or `<a>` attributes when `href` is set), such as `onClick` and `type`.
|
|
734
|
-
|
|
735
|
-
For icon-only buttons, use `IconButton`. `aria-label` is required:
|
|
736
|
-
|
|
737
|
-
```tsx
|
|
738
|
-
<IconButton aria-label="Close" variant="ghost"><CloseIcon /></IconButton>
|
|
739
|
-
```
|
|
740
|
-
|
|
741
|
-
To group related buttons, use `ButtonGroup`. It passes `variant`, `tone`, `size`, `radius` and `disabled` down to every button inside.
|
|
742
|
-
|
|
743
|
-
### CheckBox
|
|
744
|
-
|
|
745
|
-
```tsx
|
|
746
|
-
<CheckBox label="Email me updates" description="About once a month." />
|
|
747
|
-
<CheckBox label="Remember me" labelPosition="start" defaultChecked />
|
|
748
|
-
```
|
|
749
|
-
|
|
750
|
-
| Prop | Type | Default | Description |
|
|
751
|
-
| --- | --- | --- | --- |
|
|
752
|
-
| `label` | `ReactNode` | — | Visible label. Clicking it toggles the box. Without it, pass `aria-label`. |
|
|
753
|
-
| `description` | `ReactNode` | — | Supporting text below the label, linked with `aria-describedby`. |
|
|
754
|
-
| `checked` | `boolean` | — | Checked state (controlled). |
|
|
755
|
-
| `defaultChecked` | `boolean` | — | Initial checked state (uncontrolled). |
|
|
756
|
-
| `onCheckedChange` | `(checked: boolean) => void` | — | Called with the new state when the user toggles the box. |
|
|
757
|
-
| `indeterminate` | `boolean` | `false` | Shows a "mixed" dash, for a "select all" box whose options are partly checked. |
|
|
758
|
-
| `labelPosition` | `"start" \| "end"` | `"end"` | Puts the label before (`start`) or after (`end`) the box. |
|
|
759
|
-
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Box and text size. |
|
|
760
|
-
| `tone` | `Tone` | `"primary"` | Fill color when checked. |
|
|
761
|
-
| `invalid` | `boolean` | `false` | Danger styling plus `aria-invalid`. |
|
|
762
|
-
| `readOnly` | `boolean` | `false` | Keeps the box focusable but prevents toggling. |
|
|
763
|
-
|
|
764
|
-
Also accepts native `<input type="checkbox">` attributes, such as `name`, `required` and `disabled`.
|
|
765
|
-
|
|
766
|
-
To manage several options as one `string[]` value, use `CheckBoxGroup`:
|
|
767
|
-
|
|
768
|
-
```tsx
|
|
769
|
-
<CheckBoxGroup label="Toppings" defaultValue={["cheese"]} onValueChange={setToppings}>
|
|
770
|
-
<CheckBox value="cheese" label="Cheese" />
|
|
771
|
-
<CheckBox value="peppers" label="Peppers" />
|
|
772
|
-
</CheckBoxGroup>
|
|
773
|
-
```
|
|
774
|
-
|
|
775
|
-
For a "select all" box, pass its label as `selectAll`. The group adds the parent box, keeps its checked and mixed states in sync, and links the options to it, so screen readers announce them as belonging to it. Disabled options keep their state.
|
|
776
|
-
|
|
777
|
-
```tsx
|
|
778
|
-
<CheckBoxGroup label="Pizza order" selectAll="All toppings" name="toppings">
|
|
779
|
-
<CheckBox value="cheese" label="Cheese" />
|
|
780
|
-
<CheckBox value="peppers" label="Peppers" />
|
|
781
|
-
</CheckBoxGroup>
|
|
782
|
-
```
|
|
783
|
-
|
|
784
|
-
### Chat: rendering replies safely
|
|
785
|
-
|
|
786
|
-
By default `Chat` shows each message as plain text, which is always safe. If you pass `renderContent` to render Markdown, treat every message as untrusted, including the model's replies, since a prompt injection can make a model write anything:
|
|
787
|
-
|
|
788
|
-
- Render to React elements, never an HTML string: don't use `dangerouslySetInnerHTML` or your Markdown renderer's raw-HTML option. If you must render HTML, sanitize it first (for example with DOMPurify).
|
|
789
|
-
- Allow only `http:`, `https:`, and `mailto:` link URLs, and give external links `rel="noopener noreferrer"`.
|
|
790
|
-
- Don't load remote images from replies automatically: an image URL can send conversation data to another server.
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
|
824
|
-
|
|
|
825
|
-
|
|
|
826
|
-
|
|
|
827
|
-
|
|
|
828
|
-
|
|
|
829
|
-
|
|
|
830
|
-
|
|
|
831
|
-
| Figma kit
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1
|
+
# vjdesigns-ui
|
|
2
|
+
|
|
3
|
+
**Accessible components, with the proof.** A React 19 component library from VJ Designs: more than 80 components built to WCAG 2.2 AA and audited on every release with axe-core in light and dark mode, with keyboard support, focus management and screen reader names already done. Each component's docs page lists its keys, roles and audit results. Your content, labels and flows are still yours to check; [vjdesigns-ui.org/accessibility](https://vjdesigns-ui.org/accessibility) lists exactly what that covers.
|
|
4
|
+
|
|
5
|
+
It also has light and dark modes, five brand palettes, 32 languages, right-to-left support, and no runtime dependencies. Need data grids, charts, planners, or ready-made pages? See [Pro](#pro).
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
🌐 **Website and Pro:** [vjdesigns-ui.org](https://vjdesigns-ui.org)
|
|
10
|
+
📚 **Live docs and Storybook:** [component.vjdesigns.org](https://component.vjdesigns.org)
|
|
11
|
+
📦 **npm:** [@vjdesigns/vjdesigns-ui](https://www.npmjs.com/package/@vjdesigns/vjdesigns-ui)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Install the package along with React and React DOM. The library requires **React 19**, which the components need in order to render:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @vjdesigns/vjdesigns-ui react react-dom
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
If your project already uses React, you only need the first package:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @vjdesigns/vjdesigns-ui
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Browser support
|
|
30
|
+
|
|
31
|
+
The components support the current and previous major versions of evergreen browsers, with these minimums:
|
|
32
|
+
|
|
33
|
+
| Browser | Minimum version |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| Chrome, Edge, and other Chromium browsers | 111 |
|
|
36
|
+
| Firefox | 121 |
|
|
37
|
+
| Safari (macOS and iOS) | 16.2 |
|
|
38
|
+
|
|
39
|
+
These are set by the CSS the components rely on: `color-mix()`, container queries, `:has()` (which draws some keyboard focus rings), and the `inert` attribute. Internet Explorer and legacy (non-Chromium) Edge aren't supported.
|
|
40
|
+
|
|
41
|
+
A few newer features are used only where available, with a fallback elsewhere: `field-sizing` for auto-growing `Textarea` (measured in JavaScript otherwise), the `scrollend` event in `Carousel`, and `hidden="until-found"` for find-in-page in `Accordion` and `Collapsible`.
|
|
42
|
+
|
|
43
|
+
### Import the styles
|
|
44
|
+
|
|
45
|
+
The component styles and shared design tokens ship as a separate stylesheet. Import it **once** at your app's entry point, or the components will render unstyled.
|
|
46
|
+
|
|
47
|
+
**React:** in `main.tsx` (or `App.tsx`)
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Angular:** add it to the `styles` array in `angular.json`
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
"styles": [
|
|
57
|
+
"node_modules/@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css",
|
|
58
|
+
"src/styles.css"
|
|
59
|
+
]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Vue:** in `main.ts`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
The components are built with React. You can use them directly in a React project. In Angular or Vue, you mount them inside a small wrapper component, as shown below.
|
|
73
|
+
|
|
74
|
+
### React
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { useState } from "react";
|
|
78
|
+
import { Button, CheckBox } from "@vjdesigns/vjdesigns-ui";
|
|
79
|
+
|
|
80
|
+
export function SignupForm() {
|
|
81
|
+
const [accepted, setAccepted] = useState(false);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<form>
|
|
85
|
+
<CheckBox
|
|
86
|
+
label="Accept terms"
|
|
87
|
+
checked={accepted}
|
|
88
|
+
onCheckedChange={setAccepted}
|
|
89
|
+
/>
|
|
90
|
+
<Button
|
|
91
|
+
variant="solid"
|
|
92
|
+
tone="primary"
|
|
93
|
+
size="md"
|
|
94
|
+
disabled={!accepted}
|
|
95
|
+
onClick={() => console.log("Submitted")}
|
|
96
|
+
>
|
|
97
|
+
Submit
|
|
98
|
+
</Button>
|
|
99
|
+
</form>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Next.js (App Router) and React Server Components
|
|
105
|
+
|
|
106
|
+
The library works in Server Components. Interactive components (anything with state, effects, or context: `Button`, `DataGrid`, `Modal`, ...) are marked `"use client"`, so you can render them from a Server Component like any client component. Utilities (`cx`, `sortRows`, `createBrandPalette`, `getLocaleDirection`, ...) and the locale catalogs have no directive, so you can call or read them on the server too. Every component also renders on the server for the first paint.
|
|
107
|
+
|
|
108
|
+
Put the providers in a small client file of your own, and render it from the root layout:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
// app/providers.tsx
|
|
112
|
+
"use client";
|
|
113
|
+
import { LocaleProvider, ToastProvider } from "@vjdesigns/vjdesigns-ui";
|
|
114
|
+
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
115
|
+
import type { ReactNode } from "react";
|
|
116
|
+
|
|
117
|
+
export function Providers({ children }: { children: ReactNode }) {
|
|
118
|
+
return (
|
|
119
|
+
<LocaleProvider locale="es" messages={es}>
|
|
120
|
+
<ToastProvider>{children}</ToastProvider>
|
|
121
|
+
</LocaleProvider>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
// app/layout.tsx (a Server Component)
|
|
128
|
+
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
129
|
+
import { getLocaleDirection } from "@vjdesigns/vjdesigns-ui";
|
|
130
|
+
import { Providers } from "./providers";
|
|
131
|
+
|
|
132
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
133
|
+
return (
|
|
134
|
+
<html lang="es" dir={getLocaleDirection("es")}>
|
|
135
|
+
<body>
|
|
136
|
+
<Providers>{children}</Providers>
|
|
137
|
+
</body>
|
|
138
|
+
</html>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Two rules of Server Components to keep in mind:
|
|
144
|
+
|
|
145
|
+
- **Functions can't be passed from a Server Component to a client one.** That includes event handlers (`onClick`), DataGrid columns with `cell` or `value` functions, and the locale catalogs themselves (their plural messages are functions, which is why `LocaleProvider` goes in the client providers file above). Render those components from your own `"use client"` file.
|
|
146
|
+
- **Compound parts can't be reached with a dot from a Server Component** (`Tabs.List`, `Menu.Item`): Next.js reports "You cannot dot into a client module". Use them inside a `"use client"` file, or use the named exports where they exist (`CardHeader`, `CardBody`, `NavbarBrand`, ...).
|
|
147
|
+
|
|
148
|
+
### Angular
|
|
149
|
+
|
|
150
|
+
Make a standalone wrapper that renders the React component into its host element. The wrapper uses `createElement`, so you don't need to change your JSX or TSX settings.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
// vj-button.component.ts
|
|
154
|
+
import {
|
|
155
|
+
AfterViewInit,
|
|
156
|
+
Component,
|
|
157
|
+
ElementRef,
|
|
158
|
+
EventEmitter,
|
|
159
|
+
Input,
|
|
160
|
+
OnChanges,
|
|
161
|
+
OnDestroy,
|
|
162
|
+
Output,
|
|
163
|
+
ViewChild,
|
|
164
|
+
} from "@angular/core";
|
|
165
|
+
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
166
|
+
import { createRoot, Root } from "react-dom/client";
|
|
167
|
+
import {
|
|
168
|
+
Button,
|
|
169
|
+
type ButtonProps,
|
|
170
|
+
type ButtonVariant,
|
|
171
|
+
type Size,
|
|
172
|
+
type Tone,
|
|
173
|
+
} from "@vjdesigns/vjdesigns-ui";
|
|
174
|
+
|
|
175
|
+
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
176
|
+
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
177
|
+
|
|
178
|
+
@Component({
|
|
179
|
+
selector: "vj-button",
|
|
180
|
+
standalone: true,
|
|
181
|
+
template: `<span #host></span>`,
|
|
182
|
+
})
|
|
183
|
+
export class VjButtonComponent implements AfterViewInit, OnChanges, OnDestroy {
|
|
184
|
+
@ViewChild("host", { static: true }) host!: ElementRef<HTMLElement>;
|
|
185
|
+
|
|
186
|
+
@Input() label = "";
|
|
187
|
+
@Input() variant: ButtonVariant = "solid";
|
|
188
|
+
@Input() tone: Tone = "primary";
|
|
189
|
+
@Input() size: Size = "md";
|
|
190
|
+
@Input() disabled = false;
|
|
191
|
+
@Output() clicked = new EventEmitter<MouseEvent>();
|
|
192
|
+
|
|
193
|
+
private root?: Root;
|
|
194
|
+
|
|
195
|
+
ngAfterViewInit() {
|
|
196
|
+
this.root = createRoot(this.host.nativeElement);
|
|
197
|
+
this.render();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
ngOnChanges() {
|
|
201
|
+
this.render();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
ngOnDestroy() {
|
|
205
|
+
this.root?.unmount();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private render() {
|
|
209
|
+
this.root?.render(
|
|
210
|
+
createElement(
|
|
211
|
+
ReactButton,
|
|
212
|
+
{
|
|
213
|
+
variant: this.variant,
|
|
214
|
+
tone: this.tone,
|
|
215
|
+
size: this.size,
|
|
216
|
+
disabled: this.disabled,
|
|
217
|
+
onClick: (event: ReactMouseEvent) => this.clicked.emit(event.nativeEvent),
|
|
218
|
+
},
|
|
219
|
+
this.label // the button's text is passed as children
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Import the wrapper wherever you need it:
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
// app.component.ts
|
|
230
|
+
import { Component } from "@angular/core";
|
|
231
|
+
import { VjButtonComponent } from "./vj-button.component";
|
|
232
|
+
|
|
233
|
+
@Component({
|
|
234
|
+
selector: "app-root",
|
|
235
|
+
standalone: true,
|
|
236
|
+
imports: [VjButtonComponent],
|
|
237
|
+
template: `<vj-button label="Submit" tone="primary" (clicked)="onSubmit()" />`,
|
|
238
|
+
})
|
|
239
|
+
export class AppComponent {
|
|
240
|
+
onSubmit() {
|
|
241
|
+
console.log("Submitted");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Vue 3
|
|
247
|
+
|
|
248
|
+
Make a wrapper component that mounts the React component when it loads and re-renders it whenever its props change.
|
|
249
|
+
|
|
250
|
+
```vue
|
|
251
|
+
<!-- VjButton.vue -->
|
|
252
|
+
<script setup lang="ts">
|
|
253
|
+
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
254
|
+
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
255
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
256
|
+
import {
|
|
257
|
+
Button,
|
|
258
|
+
type ButtonProps,
|
|
259
|
+
type ButtonVariant,
|
|
260
|
+
type Size,
|
|
261
|
+
type Tone,
|
|
262
|
+
} from "@vjdesigns/vjdesigns-ui";
|
|
263
|
+
|
|
264
|
+
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
265
|
+
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
266
|
+
|
|
267
|
+
const props = withDefaults(
|
|
268
|
+
defineProps<{
|
|
269
|
+
label: string;
|
|
270
|
+
variant?: ButtonVariant;
|
|
271
|
+
tone?: Tone;
|
|
272
|
+
size?: Size;
|
|
273
|
+
disabled?: boolean;
|
|
274
|
+
}>(),
|
|
275
|
+
{ variant: "solid", tone: "primary", size: "md", disabled: false }
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const emit = defineEmits<{ click: [event: MouseEvent] }>();
|
|
279
|
+
|
|
280
|
+
const host = ref<HTMLElement | null>(null);
|
|
281
|
+
let root: Root | undefined;
|
|
282
|
+
|
|
283
|
+
function render() {
|
|
284
|
+
root?.render(
|
|
285
|
+
createElement(
|
|
286
|
+
ReactButton,
|
|
287
|
+
{
|
|
288
|
+
variant: props.variant,
|
|
289
|
+
tone: props.tone,
|
|
290
|
+
size: props.size,
|
|
291
|
+
disabled: props.disabled,
|
|
292
|
+
onClick: (event: ReactMouseEvent) => emit("click", event.nativeEvent),
|
|
293
|
+
},
|
|
294
|
+
props.label // the button's text is passed as children
|
|
295
|
+
)
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
onMounted(() => {
|
|
300
|
+
root = createRoot(host.value!);
|
|
301
|
+
render();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
watch(() => ({ ...props }), render);
|
|
305
|
+
|
|
306
|
+
onBeforeUnmount(() => root?.unmount());
|
|
307
|
+
</script>
|
|
308
|
+
|
|
309
|
+
<template>
|
|
310
|
+
<span ref="host" />
|
|
311
|
+
</template>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Use it like any other Vue component:
|
|
315
|
+
|
|
316
|
+
```vue
|
|
317
|
+
<script setup lang="ts">
|
|
318
|
+
import VjButton from "./VjButton.vue";
|
|
319
|
+
|
|
320
|
+
const onSubmit = () => console.log("Submitted");
|
|
321
|
+
</script>
|
|
322
|
+
|
|
323
|
+
<template>
|
|
324
|
+
<VjButton label="Submit" tone="primary" @click="onSubmit" />
|
|
325
|
+
</template>
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
> **Tip:** Wrap `CheckBox` and any other component the same way. Pass its props into `createElement`, and send its callbacks back out as Angular outputs or Vue emits. For `CheckBox`, that means sending `onCheckedChange` back out.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Theming
|
|
333
|
+
|
|
334
|
+
Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:
|
|
335
|
+
|
|
336
|
+
```tsx
|
|
337
|
+
import { Theme, Button } from "@vjdesigns/vjdesigns-ui";
|
|
338
|
+
|
|
339
|
+
<Theme mode="dark" brand="purple" fill>
|
|
340
|
+
<Button>Dark, purple button</Button>
|
|
341
|
+
</Theme>
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
| Prop | Type | Default | Description |
|
|
345
|
+
| --- | --- | --- | --- |
|
|
346
|
+
| `mode` | `"light" \| "dark"` | inherited | Color mode for everything inside. |
|
|
347
|
+
| `brand` | `"black" \| "blue" \| "gold" \| "green" \| "purple"`, a hex color, or `{ light, dark }` | inherited | Brand palette for buttons, links, focus rings and indicators. |
|
|
348
|
+
| `accent` | `"brand" | "lime"`, a hex color, or `{ light, dark }` | inherited (the brand's own) | The bright highlight on badges, switches, progress bars, sliders, steppers, and active navigation. |
|
|
349
|
+
| `fill` | `boolean` | `false` | Paints the theme's background and text color on the wrapper. |
|
|
350
|
+
|
|
351
|
+
Outside React (or to theme the whole page), set the attributes on `<html>` instead:
|
|
352
|
+
|
|
353
|
+
```html
|
|
354
|
+
<html data-theme="dark" data-brand="purple" data-accent="lime">
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Accent color
|
|
358
|
+
|
|
359
|
+
The accent is the energetic highlight: badges, switches, progress bars, sliders, steppers, and the active link in the Navbar. By default it follows the brand, as a bright shade of the brand's own color, so it always fits:
|
|
360
|
+
|
|
361
|
+
| Brand | Default accent |
|
|
362
|
+
| --- | --- |
|
|
363
|
+
| `blue` (default) | sky blue `#76c7ff` |
|
|
364
|
+
| `purple` | lavender `#c0b0ff` |
|
|
365
|
+
| `gold` | amber `#f5ad5f` |
|
|
366
|
+
| `green` | mint `#72d4ad` |
|
|
367
|
+
| `black` | lime `#c8f031` (black has no hue to build on) |
|
|
368
|
+
| a custom hex | generated from that color |
|
|
369
|
+
|
|
370
|
+
To choose a different one:
|
|
371
|
+
|
|
372
|
+
```tsx
|
|
373
|
+
<Theme accent="lime">…</Theme> // the original bright yellow-green ("volt", its former name, still works)
|
|
374
|
+
<Theme accent="#ff6b00">…</Theme> // any color
|
|
375
|
+
<Theme accent="brand">…</Theme> // back to the brand's own, inside an area with another accent
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Accents always carry dark text. A color too dark for that is lightened (same hue) just enough to meet WCAG AA, with a warning in development. An accent you set also holds inside nested brands. In CSS, `accentCss("name", "#ff6b00")` generates a `[data-accent="name"]` rule, like `brandCss` below.
|
|
379
|
+
|
|
380
|
+
### Custom brand colors
|
|
381
|
+
|
|
382
|
+
Pass any hex color as `brand` and a full palette is generated for both modes:
|
|
383
|
+
|
|
384
|
+
```tsx
|
|
385
|
+
<Theme brand="#e11d48">…</Theme>
|
|
386
|
+
<Theme brand={{ light: "#4338ca", dark: "#f472b6" }}>…</Theme>
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
Every generated palette meets WCAG 2.2 AA. A single color is used exactly as given in the mode where it has enough contrast (dark colors in light mode, light colors in dark mode), and the other mode gets a matching shade of the same hue. If a color doesn't have enough contrast (for example, a mid-tone that fails in both modes), its lightness is shifted just enough to pass, and a warning is logged in development.
|
|
390
|
+
|
|
391
|
+
To define a brand in CSS instead (for the whole page, applied before any JavaScript runs), generate a stylesheet rule with `brandCss`:
|
|
392
|
+
|
|
393
|
+
```ts
|
|
394
|
+
import { brandCss } from "@vjdesigns/vjdesigns-ui";
|
|
395
|
+
|
|
396
|
+
brandCss("acme", "#e11d48"); // '[data-brand="acme"] { --brand-light-primary: … }'
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Add the rule to your stylesheet and use `<html data-brand="acme">`. `createBrandPalette(color)` returns the generated colors as an object, if you need them directly.
|
|
400
|
+
|
|
401
|
+
### Tailwind CSS
|
|
402
|
+
|
|
403
|
+
A Tailwind CSS v4 preset turns the design tokens into utilities, so your own layouts match the components. Import it after Tailwind in your CSS, and keep importing the library's stylesheet as usual:
|
|
404
|
+
|
|
405
|
+
```css
|
|
406
|
+
@import "tailwindcss";
|
|
407
|
+
@import "@vjdesigns/vjdesigns-ui/tailwind.css";
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
```tsx
|
|
411
|
+
<section className="bg-surface text-text rounded-xl shadow-md p-6">
|
|
412
|
+
<h2 className="font-display text-2xl tracking-tight">Season stats</h2>
|
|
413
|
+
<p className="text-text-muted">Updated after every game.</p>
|
|
414
|
+
<span className="bg-accent text-on-accent rounded-control px-3">New</span>
|
|
415
|
+
</section>
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Every utility points at a token (`bg-primary` is `var(--color-primary)`), so Tailwind classes follow `Theme`, `data-theme`, `data-brand`, and `data-accent` exactly like the components, with no `dark:` variants needed.
|
|
419
|
+
|
|
420
|
+
| Group | Utilities |
|
|
421
|
+
| --- | --- |
|
|
422
|
+
| Colors | `bg-`, `text-`, `border-`, `ring-`, … with `bg`, `surface` (`-raised`, `-sunken`, `-hover`, `-active`), `overlay`, `text` (`-muted`, `-disabled`, `-inverse`), `border` (`-strong`, `-input`), `focus-ring`, `link-visited`; and for `primary`, `accent`, `success`, `warning`, `danger`, `info`, `neutral`: the solid color, `-hover`, `-active`, `on-…` (text on the solid), `-subtle`, `-subtle-hover`, `-subtle-text`, `-border`. Opacity modifiers work (`bg-primary/50`). |
|
|
423
|
+
| Charts | `bg-chart-1` to `bg-chart-8`, for fills only, in that order. Slots 3 to 5 are under 3:1 on white, so pair them with a legend, labels, or a data table. |
|
|
424
|
+
| Type | `font-display` (headings, buttons, labels, numbers), `font-body`, `font-mono`; `text-xs` to `text-6xl` (plus `text-md`); `font-regular` to `font-black`; `leading-tight`, `-snug`, `-normal`, `-relaxed`; `tracking-tight`, `-normal`, `-wide`, `-caps` |
|
|
425
|
+
| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |
|
|
426
|
+
| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |
|
|
427
|
+
| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |
|
|
428
|
+
| Sizes | `h-control-sm`, `-md`, `-lg` (and `w-`, `min-h-`, …), `size-target` (the 24px minimum pointer target), `max-w-xs` to `max-w-2xl` and `@xs:` to `@2xl:` container queries |
|
|
429
|
+
| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |
|
|
430
|
+
| Dark mode | `dark:` follows `data-theme="dark"`, not the OS setting. |
|
|
431
|
+
|
|
432
|
+
Tailwind's numeric spacing (`p-4` = 1rem) already matches the 4px token scale, and the breakpoints (`sm:` to `2xl:`) are the same as Tailwind's.
|
|
433
|
+
|
|
434
|
+
Some Tailwind names change meaning with the preset: `rounded-*`, `shadow-*`, `blur-sm`/`-lg`, `ease-in`/`-out`, `font-mono`, `font-medium` to `font-black`, `leading-*`, and the `text-*` sizes take the library's values (for example, `rounded-md` is 12px and `font-black` is 800). So do the containers: `max-w-md` and `@md:` are 48rem, not Tailwind's 28rem. The library's stylesheet already gives some of these names its own values once it's loaded, even without the preset; the preset keeps the utilities and the container queries consistent.
|
|
435
|
+
|
|
436
|
+
For text contrast, use the pairs the components use: `text-text` or `text-text-muted` on `bg-bg`, `bg-surface`, and the other surfaces; `text-on-primary` on `bg-primary` (likewise `on-accent`, `on-success`, …); `text-primary-subtle-text` on `bg-primary-subtle` (likewise for each tone). These pairs meet WCAG 2.2 AA in both themes and every brand. Don't use accent or chart colors for text.
|
|
437
|
+
|
|
438
|
+
The preset doesn't change the components, and Tailwind's preflight (its CSS reset) doesn't override them, whichever stylesheet loads first.
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
## Languages
|
|
443
|
+
|
|
444
|
+
Components have built-in text: button names like "Close" and "Next page", screen-reader announcements like "3 results available", validation messages, and date formats. Wrap your app in `LocaleProvider` to show all of it in another language:
|
|
445
|
+
|
|
446
|
+
```tsx
|
|
447
|
+
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
|
|
448
|
+
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
449
|
+
|
|
450
|
+
<LocaleProvider locale="es" messages={es}>
|
|
451
|
+
<App />
|
|
452
|
+
</LocaleProvider>
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
`LocaleProvider` sets:
|
|
456
|
+
|
|
457
|
+
- **Built-in text** for every component, from `messages`.
|
|
458
|
+
- **Dates and numbers** in the locale's format (`23/10/2026`, `1.234,5`), and plurals that follow the language's rules.
|
|
459
|
+
- **Writing direction**: Arabic, Hebrew, Persian, and Urdu get `dir="rtl"`, and layouts and arrow keys mirror.
|
|
460
|
+
- **`lang`** on its wrapper, so screen readers pronounce the text correctly. Popups (menus, dialogs, tooltips) keep the language of the area that opened them.
|
|
461
|
+
|
|
462
|
+
Each locale is a separate import, so your app only downloads the languages it uses. Without a `LocaleProvider`, components use English text and the browser's date and number format.
|
|
463
|
+
|
|
464
|
+
This library only translates its own built-in text. Text your app passes in, like `<Button>Save</Button>`, is your app's content: translate it with your app's i18n library (react-i18next, FormatJS, and so on).
|
|
465
|
+
|
|
466
|
+
### What gets translated
|
|
467
|
+
|
|
468
|
+
The language is never picked automatically from where the user lives or their browser settings. Your app chooses it by rendering a `LocaleProvider`. For example, with `<LocaleProvider locale="de" messages={de}>`:
|
|
469
|
+
|
|
470
|
+
| | Translated? |
|
|
471
|
+
| --- | --- |
|
|
472
|
+
| Text your app passes in, like `<Button>Save</Button>` | No: your app translates it |
|
|
473
|
+
| Built-in names, like "Close", "Next page", "Clear search" | Yes: "Schließen", "Nächste Seite", "Suche löschen" |
|
|
474
|
+
| Screen-reader announcements, like "3 results available" | Yes: "3 Ergebnisse verfügbar" |
|
|
475
|
+
| Validation messages, empty states, file-upload prompts | Yes |
|
|
476
|
+
| Dates and numbers | Yes: "23.10.2026", "4,5" |
|
|
477
|
+
|
|
478
|
+
To follow the user's browser language, pass it yourself: `locale={navigator.language}` together with the matching `messages` (see [Switching language at runtime](#switching-language-at-runtime)).
|
|
479
|
+
|
|
480
|
+
### Bundled languages
|
|
481
|
+
|
|
482
|
+
`ar` Arabic · `bn` Bengali · `cs` Czech · `da` Danish · `de` German · `el` Greek · `es` Spanish · `fa` Persian · `fi` Finnish · `fr` French · `he` Hebrew · `hi` Hindi · `hu` Hungarian · `id` Indonesian · `it` Italian · `ja` Japanese · `ko` Korean · `nb` Norwegian Bokmål · `nl` Dutch · `pl` Polish · `pt-BR` Portuguese (Brazil) · `ro` Romanian · `ru` Russian · `sv` Swedish · `th` Thai · `tr` Turkish · `uk` Ukrainian · `ur` Urdu · `vi` Vietnamese · `zh-Hans` Chinese (Simplified) · `zh-Hant` Chinese (Traditional), plus English (the default).
|
|
483
|
+
|
|
484
|
+
The translations are machine-generated and haven't been reviewed by native speakers yet. If you find a wrong or awkward phrase, override it (below) and report it so the bundled locale can be fixed. (Working on the library itself? See [Translating built-in text](#translating-built-in-text).)
|
|
485
|
+
|
|
486
|
+
### Changing a few strings
|
|
487
|
+
|
|
488
|
+
Pass only the strings you want to change. Everything else falls back to the outer provider's language (English at the top):
|
|
489
|
+
|
|
490
|
+
```tsx
|
|
491
|
+
<LocaleProvider locale="en-GB" messages={{ pagination: { next: "Onwards" } }}>
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
Providers nest, so an inner provider can switch the language for one part of the page. Per-component props such as `clearLabel` or `labels` still win over the provider.
|
|
495
|
+
|
|
496
|
+
### Other languages
|
|
497
|
+
|
|
498
|
+
For a language that isn't bundled, write a complete messages object. TypeScript flags any missing string. Use English as the template:
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
import { en, plural, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
502
|
+
|
|
503
|
+
const p = plural("sw");
|
|
504
|
+
export const sw: Messages = {
|
|
505
|
+
...en,
|
|
506
|
+
pagination: { ...en.pagination, next: "Ukurasa unaofuata", previous: "Ukurasa uliopita" },
|
|
507
|
+
searchInput: {
|
|
508
|
+
...en.searchInput,
|
|
509
|
+
results: (count) => p(count, { "=0": "Hakuna matokeo", one: "Tokeo #", other: "Matokeo #" }),
|
|
510
|
+
},
|
|
511
|
+
// ...
|
|
512
|
+
};
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
`plural(locale)` picks the right plural form for any language (`#` is the formatted number).
|
|
516
|
+
|
|
517
|
+
### Switching language at runtime
|
|
518
|
+
|
|
519
|
+
List the languages your app offers as loaders, so each one is downloaded only when picked:
|
|
520
|
+
|
|
521
|
+
```tsx
|
|
522
|
+
import { LocaleProvider, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
523
|
+
|
|
524
|
+
const loaders: Record<string, () => Promise<{ default: Messages }>> = {
|
|
525
|
+
es: () => import("@vjdesigns/vjdesigns-ui/locales/es"),
|
|
526
|
+
fr: () => import("@vjdesigns/vjdesigns-ui/locales/fr"),
|
|
527
|
+
ar: () => import("@vjdesigns/vjdesigns-ui/locales/ar"),
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
function App({ lang }: { lang: string }) {
|
|
531
|
+
const [messages, setMessages] = useState<Messages>();
|
|
532
|
+
useEffect(() => {
|
|
533
|
+
const load = loaders[lang];
|
|
534
|
+
if (load) load().then((mod) => setMessages(mod.default));
|
|
535
|
+
else setMessages(undefined); // English
|
|
536
|
+
}, [lang]);
|
|
537
|
+
// Until a language loads, the previous one (or English) shows.
|
|
538
|
+
return <LocaleProvider locale={lang} messages={messages}>…</LocaleProvider>;
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
For server rendering, also set `<html lang="…" dir="…">` on the page. `getLocaleDirection(locale)` returns `"ltr"` or `"rtl"`.
|
|
543
|
+
|
|
544
|
+
---
|
|
545
|
+
|
|
546
|
+
## Form validation
|
|
547
|
+
|
|
548
|
+
> **Front-end validation is not security.** It helps people fill in a form correctly, but anyone can turn off JavaScript or send requests straight to your server. Always validate again on the server. The format checks below (`isEmail`, `isIP`, …) are plain functions you can reuse there.
|
|
549
|
+
|
|
550
|
+
`useFormValidation` checks a form when it's submitted, using the browser's own rules on each input (`required`, `type="email"`, `minLength`, `pattern`, `min` / `max`) plus any rules you add. Messages follow the current language.
|
|
551
|
+
|
|
552
|
+
```tsx
|
|
553
|
+
import {
|
|
554
|
+
useFormValidation, rules, ErrorSummary, Field, Input, PasswordInput, Button,
|
|
555
|
+
} from "@vjdesigns/vjdesigns-ui";
|
|
556
|
+
|
|
557
|
+
function SignUp() {
|
|
558
|
+
const form = useFormValidation({
|
|
559
|
+
rules: {
|
|
560
|
+
confirm: rules.matches("password", "The passwords don't match."),
|
|
561
|
+
serverIp: rules.ip(), // IPv4 or IPv6
|
|
562
|
+
},
|
|
563
|
+
// Runs only when everything is valid. Return the server's errors to show them on their fields.
|
|
564
|
+
onValid: async (values) => {
|
|
565
|
+
const response = await api.signUp(values);
|
|
566
|
+
return response.errors; // e.g. { username: "That username is taken." }
|
|
567
|
+
},
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
return (
|
|
571
|
+
<form {...form.formProps}>
|
|
572
|
+
<ErrorSummary ref={form.summaryRef} errors={form.errorList} />
|
|
573
|
+
<Field label="Email" required error={form.errors.email}>
|
|
574
|
+
<Input name="email" type="email" />
|
|
575
|
+
</Field>
|
|
576
|
+
<Field label="Password" required error={form.errors.password}>
|
|
577
|
+
<PasswordInput name="password" minLength={12} />
|
|
578
|
+
</Field>
|
|
579
|
+
<Field label="Confirm password" required error={form.errors.confirm}>
|
|
580
|
+
<PasswordInput name="confirm" />
|
|
581
|
+
</Field>
|
|
582
|
+
<Field label="Server IP" error={form.errors.serverIp}>
|
|
583
|
+
<Input name="serverIp" />
|
|
584
|
+
</Field>
|
|
585
|
+
<Button type="submit" loading={form.isSubmitting}>Create account</Button>
|
|
586
|
+
</form>
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
How it behaves:
|
|
592
|
+
|
|
593
|
+
- **On submit**, every field is checked. If anything is wrong, the `ErrorSummary` at the top lists the problems and takes focus, so screen readers announce it. Each item links to its field. Without a summary, focus goes to the first invalid field.
|
|
594
|
+
- **Errors are keyed by the field's `name`.** Pass `form.errors.<name>` to each `Field`'s `error`.
|
|
595
|
+
- **After a failed submit**, an error disappears as soon as the field is fixed (while typing), and a field is fully re-checked when you leave it. It doesn't nag while you're still typing.
|
|
596
|
+
- **Server errors** (returned from `onValid`, or set with `form.setErrors({...})`) show on their fields and stay until that field is edited.
|
|
597
|
+
- **Emails** must have a real domain (`name@example.com`). The browser's own check also accepts `name@localhost`.
|
|
598
|
+
|
|
599
|
+
### Rules and format checks
|
|
600
|
+
|
|
601
|
+
| Rule | Checks |
|
|
602
|
+
| --- | --- |
|
|
603
|
+
| `rules.required()` | Not empty (for controls without a native `required`) |
|
|
604
|
+
| `rules.email()` | An email address in the usual format, with a top-level domain |
|
|
605
|
+
| `rules.ip()` / `rules.ip({ version: 4 })` / `rules.ip({ version: 6 })` | An IPv4 or IPv6 address |
|
|
606
|
+
| `rules.minLength(n)` / `rules.maxLength(n)` | Length in characters |
|
|
607
|
+
| `rules.pattern(/regex/, "message")` | The whole value matches |
|
|
608
|
+
| `rules.matches("otherField")` | Equals another field (confirm password) |
|
|
609
|
+
| your own `(value, { values }) => message` | Anything else |
|
|
610
|
+
|
|
611
|
+
Each rule takes an optional custom message. The checks behind them are exported for use anywhere, including your server:
|
|
612
|
+
|
|
613
|
+
- `isEmail(value)`
|
|
614
|
+
- `isIPv4(value)`: four numbers 0–255, no leading zeros
|
|
615
|
+
- `isIPv6(value)`: including `::` shorthand and IPv4 tails like `::ffff:192.168.0.1`
|
|
616
|
+
- `isIP(value, version?)`
|
|
617
|
+
|
|
618
|
+
---
|
|
619
|
+
|
|
620
|
+
## Hooks
|
|
621
|
+
|
|
622
|
+
Tested hooks for everyday UI work, exported from the package root (`import { useDisclosure } from "@vjdesigns/vjdesigns-ui"`). All are safe in server rendering and tree-shakable: each costs only itself, mostly well under 1 KB. Live demos are in Storybook under Hooks.
|
|
623
|
+
|
|
624
|
+
| Hook | What it does |
|
|
625
|
+
| --- | --- |
|
|
626
|
+
| `useDisclosure(initial?)` | Open/closed state with stable `open`, `close`, `toggle` handlers (for Modal, Drawer, Popover) |
|
|
627
|
+
| `useToggle(values?)` | Cycles through values: a boolean, or a list like `["list", "grid"]` |
|
|
628
|
+
| `usePrevious(value)` | The value from before its last change |
|
|
629
|
+
| `useDebouncedValue(value, ms)` | The value, updated after it stops changing (search as you type) |
|
|
630
|
+
| `useDebouncedCallback(fn, ms)` | A function that runs once after calls stop, with `cancel` and `flush` |
|
|
631
|
+
| `useThrottledCallback(fn, ms)` | A function that runs at most once per interval (scroll, resize) |
|
|
632
|
+
| `useInterval(fn, ms \| null)` / `useTimeout(fn, ms \| null)` | Timers that always call the latest function; `null` pauses |
|
|
633
|
+
| `useLocalStorage(key, default)` / `useSessionStorage` | State saved in storage, synced across components and tabs, and never throws when storage is blocked |
|
|
634
|
+
| `useClipboard()` | `copy(text)` with a `copied` flag, and a fallback when the Clipboard API is blocked |
|
|
635
|
+
| `useHotkeys([[keys, fn]])` | Page shortcuts. `mod` is ⌘ or Ctrl. Plain keys don't fire while typing. `getHotkeyHandler` does the same for one element |
|
|
636
|
+
| `useEventListener(type, fn, target?)` | An event listener that always calls the latest handler |
|
|
637
|
+
| `useClickOutside(fn)` | Calls `fn` on a press or focus move outside the element |
|
|
638
|
+
| `useIntersection(options)` | Whether an element is in view (lazy loading, entrance effects) |
|
|
639
|
+
| `useElementSize()` | An element's size as it resizes |
|
|
640
|
+
| `useVirtualizer(options)` | Renders only the visible items of a long list (what `VirtualList` uses), with variable heights and `scrollToIndex` |
|
|
641
|
+
| `useMediaQuery(query)` / `useResponsiveValue(value)` | A synced media query, or a responsive value resolved for the viewport |
|
|
642
|
+
| `useHydrated()` | False during server rendering, true after (avoids hydration mismatches) |
|
|
643
|
+
| `useReducedMotion()` / `useColorScheme()` | The user's motion and color-scheme preferences |
|
|
644
|
+
| `useOnline()` / `useDocumentVisibility()` / `useViewportSize()` | Connection, tab visibility, and viewport size |
|
|
645
|
+
| `useControllableState`, `useFormValidation`, `useFocusTrap`, `useScrollLock`, … | The building blocks the components use, for your own components |
|
|
646
|
+
|
|
647
|
+
---
|
|
648
|
+
|
|
649
|
+
## AI assistants
|
|
650
|
+
|
|
651
|
+
The package ships documentation written for AI coding assistants, generated from the source on every build, so it always matches the version you have installed:
|
|
652
|
+
|
|
653
|
+
| File | What it is |
|
|
654
|
+
| --- | --- |
|
|
655
|
+
| `@vjdesigns/vjdesigns-ui/llms.txt` | A short index in the [llms.txt](https://llmstxt.org) format: setup essentials and one line per component |
|
|
656
|
+
| `@vjdesigns/vjdesigns-ui/llms-full.txt` | The full reference in one file: guides, and every component's props (type, default, description), subcomponents, and examples |
|
|
657
|
+
| `@vjdesigns/vjdesigns-ui/registry.json` | The same, as structured JSON |
|
|
658
|
+
|
|
659
|
+
The files are in `node_modules/@vjdesigns/vjdesigns-ui/dist/ai/`. Point your assistant's rules or context at `llms-full.txt`.
|
|
660
|
+
|
|
661
|
+
### MCP server
|
|
662
|
+
|
|
663
|
+
For assistants that support the [Model Context Protocol](https://modelcontextprotocol.io), the package includes a small MCP server with four tools:
|
|
664
|
+
|
|
665
|
+
- `list_components`
|
|
666
|
+
- `get_component`, for exact props
|
|
667
|
+
- `search_docs`
|
|
668
|
+
- `get_guide`
|
|
669
|
+
|
|
670
|
+
It reads the docs of your installed version and needs no network access.
|
|
671
|
+
|
|
672
|
+
Claude Code:
|
|
673
|
+
|
|
674
|
+
```bash
|
|
675
|
+
claude mcp add vjdesigns-ui -- npx -p @vjdesigns/vjdesigns-ui vjdesigns-ui-mcp
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
Cursor (`.cursor/mcp.json`), Claude Desktop, and other clients (VS Code's `.vscode/mcp.json` uses `"servers"` instead of `"mcpServers"`):
|
|
679
|
+
|
|
680
|
+
```json
|
|
681
|
+
{
|
|
682
|
+
"mcpServers": {
|
|
683
|
+
"vjdesigns-ui": {
|
|
684
|
+
"command": "npx",
|
|
685
|
+
"args": ["-p", "@vjdesigns/vjdesigns-ui", "vjdesigns-ui-mcp"]
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
---
|
|
692
|
+
|
|
693
|
+
## Components
|
|
694
|
+
|
|
695
|
+
Every component below is exported from the package root. Full prop docs and live examples are in [Storybook](https://component.vjdesigns.org).
|
|
696
|
+
|
|
697
|
+
| Category | Components |
|
|
698
|
+
| --- | --- |
|
|
699
|
+
| **Primitives** | AccessibilityIcon, Button, CopyButton, IconButton, ButtonGroup, Icon, Kbd, Typography |
|
|
700
|
+
| **Layout** | Box, Container, Divider, Flex, Grid, ResizablePanels, ScrollArea, Stack |
|
|
701
|
+
| **Forms** | CheckBox, CheckBoxGroup, ColorPicker, Combobox, DatePicker, DateRangePicker, DateTimePicker, Field, FileUpload, Input, NumberInput, PasswordInput, PinInput, Radio, Rating, SearchInput, SegmentedControl, Select, Slider, Switch, TagInput, Textarea, TimePicker, ToggleGroup |
|
|
702
|
+
| **Navigation** | Breadcrumbs, ContextMenu, Link, Menu, MobileNav, Navbar, Pagination, Sidebar, SkipLink, Stepper, Tabs, Toolbar |
|
|
703
|
+
| **Overlays** | CommandPalette, Drawer, HoverCard, Modal, Popover, Tooltip |
|
|
704
|
+
| **Feedback** | Alert, Banner, ErrorSummary, Progress, Skeleton, Spinner, Toast |
|
|
705
|
+
| **Data display** | Accordion, Avatar, Badge, Card, Carousel, Chat, Chip, CodeBlock, Collapsible, Countdown, DataGrid, EmptyState, Image, List, Stat, Table, Timeline, TreeView, VirtualList |
|
|
706
|
+
| **Utilities** | Portal, Theme, VisuallyHidden |
|
|
707
|
+
|
|
708
|
+
### Button
|
|
709
|
+
|
|
710
|
+
```tsx
|
|
711
|
+
<Button variant="solid" tone="primary">Save</Button>
|
|
712
|
+
<Button variant="outline" tone="danger" startIcon={<TrashIcon />}>Delete</Button>
|
|
713
|
+
<Button href="/pricing" variant="link">See pricing</Button>
|
|
714
|
+
<Button loading loadingText="Saving…">Save</Button>
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
| Prop | Type | Default | Description |
|
|
718
|
+
| --- | --- | --- | --- |
|
|
719
|
+
| `children` | `ReactNode` | — | The visible label. |
|
|
720
|
+
| `variant` | `"solid" \| "soft" \| "outline" \| "ghost" \| "link" \| "inverse"` | `"solid"` | Visual style. |
|
|
721
|
+
| `tone` | `"neutral" \| "primary" \| "accent" \| "success" \| "warning" \| "danger" \| "info"` | `"primary"` | Semantic color. |
|
|
722
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding and type size. |
|
|
723
|
+
| `radius` | `"none" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "2xl" \| "pill"` | `"pill"` | Corner rounding. |
|
|
724
|
+
| `startIcon` / `endIcon` | `ReactNode` | — | Decorative icon before or after the label. Hidden from screen readers. |
|
|
725
|
+
| `loading` | `boolean` | `false` | Shows a spinner, sets `aria-busy` and ignores clicks. |
|
|
726
|
+
| `loadingText` | `ReactNode` | — | Label shown next to the spinner while loading. |
|
|
727
|
+
| `fullWidth` | `boolean` | `false` | Stretches the button to fill its container. |
|
|
728
|
+
| `compact` | `boolean` | `false` | Tighter side padding for short labels like "OK". |
|
|
729
|
+
| `disabled` | `boolean` | `false` | Disables the button. |
|
|
730
|
+
| `href` | `string` | — | Renders the button as an `<a>` link with the same styling. |
|
|
731
|
+
| `as` | `ElementType` | — | Renders as your own component, such as a React Router or Next.js `Link`. |
|
|
732
|
+
|
|
733
|
+
Also accepts all standard `<button>` attributes (or `<a>` attributes when `href` is set), such as `onClick` and `type`.
|
|
734
|
+
|
|
735
|
+
For icon-only buttons, use `IconButton`. `aria-label` is required:
|
|
736
|
+
|
|
737
|
+
```tsx
|
|
738
|
+
<IconButton aria-label="Close" variant="ghost"><CloseIcon /></IconButton>
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
To group related buttons, use `ButtonGroup`. It passes `variant`, `tone`, `size`, `radius` and `disabled` down to every button inside.
|
|
742
|
+
|
|
743
|
+
### CheckBox
|
|
744
|
+
|
|
745
|
+
```tsx
|
|
746
|
+
<CheckBox label="Email me updates" description="About once a month." />
|
|
747
|
+
<CheckBox label="Remember me" labelPosition="start" defaultChecked />
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
| Prop | Type | Default | Description |
|
|
751
|
+
| --- | --- | --- | --- |
|
|
752
|
+
| `label` | `ReactNode` | — | Visible label. Clicking it toggles the box. Without it, pass `aria-label`. |
|
|
753
|
+
| `description` | `ReactNode` | — | Supporting text below the label, linked with `aria-describedby`. |
|
|
754
|
+
| `checked` | `boolean` | — | Checked state (controlled). |
|
|
755
|
+
| `defaultChecked` | `boolean` | — | Initial checked state (uncontrolled). |
|
|
756
|
+
| `onCheckedChange` | `(checked: boolean) => void` | — | Called with the new state when the user toggles the box. |
|
|
757
|
+
| `indeterminate` | `boolean` | `false` | Shows a "mixed" dash, for a "select all" box whose options are partly checked. |
|
|
758
|
+
| `labelPosition` | `"start" \| "end"` | `"end"` | Puts the label before (`start`) or after (`end`) the box. |
|
|
759
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Box and text size. |
|
|
760
|
+
| `tone` | `Tone` | `"primary"` | Fill color when checked. |
|
|
761
|
+
| `invalid` | `boolean` | `false` | Danger styling plus `aria-invalid`. |
|
|
762
|
+
| `readOnly` | `boolean` | `false` | Keeps the box focusable but prevents toggling. |
|
|
763
|
+
|
|
764
|
+
Also accepts native `<input type="checkbox">` attributes, such as `name`, `required` and `disabled`.
|
|
765
|
+
|
|
766
|
+
To manage several options as one `string[]` value, use `CheckBoxGroup`:
|
|
767
|
+
|
|
768
|
+
```tsx
|
|
769
|
+
<CheckBoxGroup label="Toppings" defaultValue={["cheese"]} onValueChange={setToppings}>
|
|
770
|
+
<CheckBox value="cheese" label="Cheese" />
|
|
771
|
+
<CheckBox value="peppers" label="Peppers" />
|
|
772
|
+
</CheckBoxGroup>
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
For a "select all" box, pass its label as `selectAll`. The group adds the parent box, keeps its checked and mixed states in sync, and links the options to it, so screen readers announce them as belonging to it. Disabled options keep their state.
|
|
776
|
+
|
|
777
|
+
```tsx
|
|
778
|
+
<CheckBoxGroup label="Pizza order" selectAll="All toppings" name="toppings">
|
|
779
|
+
<CheckBox value="cheese" label="Cheese" />
|
|
780
|
+
<CheckBox value="peppers" label="Peppers" />
|
|
781
|
+
</CheckBoxGroup>
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
### Chat: rendering replies safely
|
|
785
|
+
|
|
786
|
+
By default `Chat` shows each message as plain text, which is always safe. If you pass `renderContent` to render Markdown, treat every message as untrusted, including the model's replies, since a prompt injection can make a model write anything:
|
|
787
|
+
|
|
788
|
+
- Render to React elements, never an HTML string: don't use `dangerouslySetInnerHTML` or your Markdown renderer's raw-HTML option. If you must render HTML, sanitize it first (for example with DOMPurify).
|
|
789
|
+
- Allow only `http:`, `https:`, and `mailto:` link URLs, and give external links `rel="noopener noreferrer"`.
|
|
790
|
+
- Don't load remote images from replies automatically: an image URL can send conversation data to another server.
|
|
791
|
+
|
|
792
|
+
### Accessibility icons
|
|
793
|
+
|
|
794
|
+
20 icons for accessibility features and services: wheelchair access, step-free routes, elevators, braille, audio description, screen readers, hearing loops, sign language, transcripts, easy read, display settings (text size, contrast, color filters, reduced motion), and keyboard, voice, and switch input.
|
|
795
|
+
|
|
796
|
+
```tsx
|
|
797
|
+
import { AccessibilityIcon, HearingLoopIcon, WheelchairIcon } from "@vjdesigns/vjdesigns-ui";
|
|
798
|
+
|
|
799
|
+
<WheelchairIcon /> {/* decorative, next to text that says the same */}
|
|
800
|
+
<HearingLoopIcon labeled /> {/* named "Hearing loop", in the current language */}
|
|
801
|
+
<AccessibilityIcon name="braille" label="Braille menu on request" />
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
They take the same props as `Icon`, plus `labeled`, which gives the icon a built-in accessible name in every bundled language. They're also tested on every release against rules the main set doesn't have to meet: readable at 16px, not mistakable for any other icon at that size, drawn inside a safe area, and painted only with `currentColor`, so dark mode and Windows High Contrast recolor all of them. The Storybook **Checks** story shows each icon's results. The wheelchair, ramp, and blind icons mirror in right-to-left layouts. Use them at 16px or larger.
|
|
805
|
+
|
|
806
|
+
---
|
|
807
|
+
|
|
808
|
+
## Pro
|
|
809
|
+
|
|
810
|
+
**Everything above is free. [`@vjdesigns-pro/ui`](https://vjdesigns-ui.org) adds the large, hard-to-build parts most apps eventually need:** an advanced data grid, charts, scheduling and planning views, and ready-made pages. They use the same tokens, themes, languages, and accessibility standard as the free package, so they look and behave like the rest of your app from the first render.
|
|
811
|
+
|
|
812
|
+
### Why teams choose Pro
|
|
813
|
+
|
|
814
|
+
- **Skip the hardest weeks of the build.** Data grids with pinned columns and inline editing, drag-and-drop planners, and a full dashboard frame are the components that take longest to get right. Pro gives you finished, tested versions to connect to your data.
|
|
815
|
+
- **Accessible where it's hardest.** Most libraries stop at buttons and forms. In Pro, every chart can be explored by keyboard, reads its values aloud, can switch to a data table, and can draw its series with patterns (hatches, dashes, and shapes) for color-blind viewers. Every drag-and-drop interaction (Kanban cards, calendar events, Gantt bars) also works from the keyboard. Every story is tested against WCAG 2.2 AA in light and dark mode.
|
|
816
|
+
- **One design system, not a patchwork.** There's no third-party chart, calendar, or spreadsheet library with its own look to fight. Pro follows your brand, accent color, theme, language, and reading direction automatically.
|
|
817
|
+
- **Nothing extra to install or audit.** Pro has no runtime dependencies. Excel export writes real `.xlsx` files without a spreadsheet library, and charts draw without a charting library.
|
|
818
|
+
- **Design and code stay in sync.** The Figma kit is generated from the same tokens as the components, so a designer's file and the shipped app can't drift apart.
|
|
819
|
+
- **A license that fits how you ship.** Licensed per developer. The apps you build can go to any number of end users, who need no license of their own, and versions released while your license is active keep working in the apps you've shipped.
|
|
820
|
+
|
|
821
|
+
### What's included
|
|
822
|
+
|
|
823
|
+
| Area | What you get |
|
|
824
|
+
| --- | --- |
|
|
825
|
+
| **Data** | `DataGridPro`: resizable, pinned, reorderable, and hideable columns; column menus; filters with chips; row grouping with subtotals; tree data; master-detail rows; inline editing with validation; copy and paste of cell ranges; loading while scrolling. **CSV export** that's safe to open in a spreadsheet, and **Excel export** to real `.xlsx` files with typed cells. |
|
|
826
|
+
| **Charts** | Bar (grouped and stacked), Line, Area, Pie, Donut, Scatter, Heatmap, Gauge, and Sparkline, with zoom and color-blind-friendly patterns (hatched fills, dashed lines, shaped points) that viewers can switch on. |
|
|
827
|
+
| **Planning** | `Scheduler` (month, week, day, and agenda views; repeating events), `Kanban` (work-in-progress limits), and `Gantt` (dependencies and milestones; day, week, and month scales). |
|
|
828
|
+
| **App templates** | A dashboard frame with 3 layouts and 7 grid templates; sign-in, sign-up, password reset, and verification code forms with passkey support; an onboarding wizard and guided product tours; team and billing pages; error pages (404, 500, 403, maintenance, offline); and a complete AI chat app. |
|
|
829
|
+
| **Marketing** | Hero, feature grid, pricing table (monthly or yearly, with prices formatted for each locale), testimonials, FAQ, call to action, and footer. |
|
|
830
|
+
| **Sports** | Standings, a game schedule with calendar export, game cards, box scores, rosters, player profiles, tryout registration, and a ticket picker. |
|
|
831
|
+
| **Design** | A Figma kit with variables for every brand, theme, and accent, shadow styles, and W3C design token files. |
|
|
832
|
+
|
|
833
|
+
### Free or Pro?
|
|
834
|
+
|
|
835
|
+
| | Free | Pro |
|
|
836
|
+
| --- | :-: | :-: |
|
|
837
|
+
| 80+ components, hooks, theming, 32 languages, form validation | ✓ | ✓ |
|
|
838
|
+
| `DataGrid`: sorting, filtering, selection, pagination, server-side data | ✓ | ✓ |
|
|
839
|
+
| Advanced grid: pinning, resizing, grouping, tree data, editing, copy and paste | | ✓ |
|
|
840
|
+
| CSV and Excel export | | ✓ |
|
|
841
|
+
| Charts | | ✓ |
|
|
842
|
+
| Scheduler, Kanban, and Gantt | | ✓ |
|
|
843
|
+
| Dashboard, account, onboarding, product tour, billing, error, and chat templates | | ✓ |
|
|
844
|
+
| Marketing and sports components | | ✓ |
|
|
845
|
+
| Figma kit | | ✓ |
|
|
846
|
+
|
|
847
|
+
Pro builds on the free package rather than replacing it, so you can start free and add Pro later without rewriting anything. `DataGridPro` takes every `DataGrid` prop, so upgrading a grid is a one-word change.
|
|
848
|
+
|
|
849
|
+
### Get Pro
|
|
850
|
+
|
|
851
|
+
See plans and buy a license at **[vjdesigns-ui.org](https://vjdesigns-ui.org)**. After purchase you'll get a license key and install instructions. Pro installs next to this package with a few lines in your project's `.npmrc`.
|
|
852
|
+
|
|
853
|
+
---
|
|
854
|
+
|
|
855
|
+
## Support
|
|
856
|
+
|
|
857
|
+
Found a bug or need a feature? [Open an issue](https://github.com/vjdesigns/vjdesigns-ui-issues/issues). Release notes for every version are in [CHANGELOG.md](CHANGELOG.md).
|
|
858
|
+
|
|
859
|
+
---
|
|
860
|
+
|
|
861
|
+
## Access to the production Storybook
|
|
862
|
+
|
|
863
|
+
1. Go to [component.vjdesigns.org](https://component.vjdesigns.org/).
|
|
864
|
+
2. Enter your email in the Cloudflare prompt to receive a 6-digit access code.
|
|
865
|
+
|
|
866
|
+
<img width="1917" height="927" alt="Cloudflare access prompt for component.vjdesigns.org" src="https://github.com/user-attachments/assets/bfe58737-52d2-4bf3-b7f7-72ba5ee54969" />
|
|
867
|
+
|
|
868
|
+
---
|
|
869
|
+
|
|
870
|
+
## License
|
|
871
|
+
|
|
872
|
+
[ISC](LICENSE) © 2026 Vertical Jump Designs LLC. Pro (`@vjdesigns-pro/ui`) has its own commercial license; see [vjdesigns-ui.org](https://vjdesigns-ui.org).
|