@vjdesigns/vjdesigns-ui 3.8.4 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +239 -234
- package/README.md +872 -858
- package/dist/ai/llms-full.txt +668 -591
- package/dist/ai/llms.txt +1 -0
- package/dist/ai/registry.json +242 -35
- 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 +1 -1
package/dist/ai/llms-full.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @vjdesigns/vjdesigns-ui 3.
|
|
1
|
+
# @vjdesigns/vjdesigns-ui 3.9.0: full reference
|
|
2
2
|
|
|
3
3
|
> Accessible React 19 component library: WCAG 2.2 AA verified (axe on every story, a contrast check on every color pair), 31 languages with right-to-left support, themeable with any brand color (auto-adjusted to stay accessible), tree-shakable, no runtime dependencies besides React.
|
|
4
4
|
|
|
@@ -12,597 +12,597 @@
|
|
|
12
12
|
|
|
13
13
|
# Guide: Installation
|
|
14
14
|
|
|
15
|
-
Install the package along with React and React DOM. The library requires **React 19**, which the components need in order to render:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @vjdesigns/vjdesigns-ui react react-dom
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
If your project already uses React, you only need the first package:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @vjdesigns/vjdesigns-ui
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Browser support
|
|
28
|
-
|
|
29
|
-
The components support the current and previous major versions of evergreen browsers, with these minimums:
|
|
30
|
-
|
|
31
|
-
| Browser | Minimum version |
|
|
32
|
-
| --- | --- |
|
|
33
|
-
| Chrome, Edge, and other Chromium browsers | 111 |
|
|
34
|
-
| Firefox | 121 |
|
|
35
|
-
| Safari (macOS and iOS) | 16.2 |
|
|
36
|
-
|
|
37
|
-
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.
|
|
38
|
-
|
|
39
|
-
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`.
|
|
40
|
-
|
|
41
|
-
### Import the styles
|
|
42
|
-
|
|
43
|
-
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.
|
|
44
|
-
|
|
45
|
-
**React:** in `main.tsx` (or `App.tsx`)
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
**Angular:** add it to the `styles` array in `angular.json`
|
|
52
|
-
|
|
53
|
-
```json
|
|
54
|
-
"styles": [
|
|
55
|
-
"node_modules/@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css",
|
|
56
|
-
"src/styles.css"
|
|
57
|
-
]
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
**Vue:** in `main.ts`
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
15
|
+
Install the package along with React and React DOM. The library requires **React 19**, which the components need in order to render:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @vjdesigns/vjdesigns-ui react react-dom
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
If your project already uses React, you only need the first package:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @vjdesigns/vjdesigns-ui
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Browser support
|
|
28
|
+
|
|
29
|
+
The components support the current and previous major versions of evergreen browsers, with these minimums:
|
|
30
|
+
|
|
31
|
+
| Browser | Minimum version |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Chrome, Edge, and other Chromium browsers | 111 |
|
|
34
|
+
| Firefox | 121 |
|
|
35
|
+
| Safari (macOS and iOS) | 16.2 |
|
|
36
|
+
|
|
37
|
+
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.
|
|
38
|
+
|
|
39
|
+
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`.
|
|
40
|
+
|
|
41
|
+
### Import the styles
|
|
42
|
+
|
|
43
|
+
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.
|
|
44
|
+
|
|
45
|
+
**React:** in `main.tsx` (or `App.tsx`)
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Angular:** add it to the `styles` array in `angular.json`
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
"styles": [
|
|
55
|
+
"node_modules/@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css",
|
|
56
|
+
"src/styles.css"
|
|
57
|
+
]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Vue:** in `main.ts`
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
# Guide: Usage
|
|
67
67
|
|
|
68
|
-
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.
|
|
69
|
-
|
|
70
|
-
### React
|
|
71
|
-
|
|
72
|
-
```tsx
|
|
73
|
-
import { useState } from "react";
|
|
74
|
-
import { Button, CheckBox } from "@vjdesigns/vjdesigns-ui";
|
|
75
|
-
|
|
76
|
-
export function SignupForm() {
|
|
77
|
-
const [accepted, setAccepted] = useState(false);
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<form>
|
|
81
|
-
<CheckBox
|
|
82
|
-
label="Accept terms"
|
|
83
|
-
checked={accepted}
|
|
84
|
-
onCheckedChange={setAccepted}
|
|
85
|
-
/>
|
|
86
|
-
<Button
|
|
87
|
-
variant="solid"
|
|
88
|
-
tone="primary"
|
|
89
|
-
size="md"
|
|
90
|
-
disabled={!accepted}
|
|
91
|
-
onClick={() => console.log("Submitted")}
|
|
92
|
-
>
|
|
93
|
-
Submit
|
|
94
|
-
</Button>
|
|
95
|
-
</form>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Next.js (App Router) and React Server Components
|
|
101
|
-
|
|
102
|
-
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.
|
|
103
|
-
|
|
104
|
-
Put the providers in a small client file of your own, and render it from the root layout:
|
|
105
|
-
|
|
106
|
-
```tsx
|
|
107
|
-
// app/providers.tsx
|
|
108
|
-
"use client";
|
|
109
|
-
import { LocaleProvider, ToastProvider } from "@vjdesigns/vjdesigns-ui";
|
|
110
|
-
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
111
|
-
import type { ReactNode } from "react";
|
|
112
|
-
|
|
113
|
-
export function Providers({ children }: { children: ReactNode }) {
|
|
114
|
-
return (
|
|
115
|
-
<LocaleProvider locale="es" messages={es}>
|
|
116
|
-
<ToastProvider>{children}</ToastProvider>
|
|
117
|
-
</LocaleProvider>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
```tsx
|
|
123
|
-
// app/layout.tsx (a Server Component)
|
|
124
|
-
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
125
|
-
import { getLocaleDirection } from "@vjdesigns/vjdesigns-ui";
|
|
126
|
-
import { Providers } from "./providers";
|
|
127
|
-
|
|
128
|
-
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
129
|
-
return (
|
|
130
|
-
<html lang="es" dir={getLocaleDirection("es")}>
|
|
131
|
-
<body>
|
|
132
|
-
<Providers>{children}</Providers>
|
|
133
|
-
</body>
|
|
134
|
-
</html>
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
Two rules of Server Components to keep in mind:
|
|
140
|
-
|
|
141
|
-
- **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.
|
|
142
|
-
- **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`, ...).
|
|
143
|
-
|
|
144
|
-
### Angular
|
|
145
|
-
|
|
146
|
-
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.
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
// vj-button.component.ts
|
|
150
|
-
import {
|
|
151
|
-
AfterViewInit,
|
|
152
|
-
Component,
|
|
153
|
-
ElementRef,
|
|
154
|
-
EventEmitter,
|
|
155
|
-
Input,
|
|
156
|
-
OnChanges,
|
|
157
|
-
OnDestroy,
|
|
158
|
-
Output,
|
|
159
|
-
ViewChild,
|
|
160
|
-
} from "@angular/core";
|
|
161
|
-
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
162
|
-
import { createRoot, Root } from "react-dom/client";
|
|
163
|
-
import {
|
|
164
|
-
Button,
|
|
165
|
-
type ButtonProps,
|
|
166
|
-
type ButtonVariant,
|
|
167
|
-
type Size,
|
|
168
|
-
type Tone,
|
|
169
|
-
} from "@vjdesigns/vjdesigns-ui";
|
|
170
|
-
|
|
171
|
-
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
172
|
-
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
173
|
-
|
|
174
|
-
@Component({
|
|
175
|
-
selector: "vj-button",
|
|
176
|
-
standalone: true,
|
|
177
|
-
template: `<span #host></span>`,
|
|
178
|
-
})
|
|
179
|
-
export class VjButtonComponent implements AfterViewInit, OnChanges, OnDestroy {
|
|
180
|
-
@ViewChild("host", { static: true }) host!: ElementRef<HTMLElement>;
|
|
181
|
-
|
|
182
|
-
@Input() label = "";
|
|
183
|
-
@Input() variant: ButtonVariant = "solid";
|
|
184
|
-
@Input() tone: Tone = "primary";
|
|
185
|
-
@Input() size: Size = "md";
|
|
186
|
-
@Input() disabled = false;
|
|
187
|
-
@Output() clicked = new EventEmitter<MouseEvent>();
|
|
188
|
-
|
|
189
|
-
private root?: Root;
|
|
190
|
-
|
|
191
|
-
ngAfterViewInit() {
|
|
192
|
-
this.root = createRoot(this.host.nativeElement);
|
|
193
|
-
this.render();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
ngOnChanges() {
|
|
197
|
-
this.render();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
ngOnDestroy() {
|
|
201
|
-
this.root?.unmount();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
private render() {
|
|
205
|
-
this.root?.render(
|
|
206
|
-
createElement(
|
|
207
|
-
ReactButton,
|
|
208
|
-
{
|
|
209
|
-
variant: this.variant,
|
|
210
|
-
tone: this.tone,
|
|
211
|
-
size: this.size,
|
|
212
|
-
disabled: this.disabled,
|
|
213
|
-
onClick: (event: ReactMouseEvent) => this.clicked.emit(event.nativeEvent),
|
|
214
|
-
},
|
|
215
|
-
this.label // the button's text is passed as children
|
|
216
|
-
)
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Import the wrapper wherever you need it:
|
|
223
|
-
|
|
224
|
-
```ts
|
|
225
|
-
// app.component.ts
|
|
226
|
-
import { Component } from "@angular/core";
|
|
227
|
-
import { VjButtonComponent } from "./vj-button.component";
|
|
228
|
-
|
|
229
|
-
@Component({
|
|
230
|
-
selector: "app-root",
|
|
231
|
-
standalone: true,
|
|
232
|
-
imports: [VjButtonComponent],
|
|
233
|
-
template: `<vj-button label="Submit" tone="primary" (clicked)="onSubmit()" />`,
|
|
234
|
-
})
|
|
235
|
-
export class AppComponent {
|
|
236
|
-
onSubmit() {
|
|
237
|
-
console.log("Submitted");
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Vue 3
|
|
243
|
-
|
|
244
|
-
Make a wrapper component that mounts the React component when it loads and re-renders it whenever its props change.
|
|
245
|
-
|
|
246
|
-
```vue
|
|
247
|
-
<!-- VjButton.vue -->
|
|
248
|
-
<script setup lang="ts">
|
|
249
|
-
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
250
|
-
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
251
|
-
import { createRoot, type Root } from "react-dom/client";
|
|
252
|
-
import {
|
|
253
|
-
Button,
|
|
254
|
-
type ButtonProps,
|
|
255
|
-
type ButtonVariant,
|
|
256
|
-
type Size,
|
|
257
|
-
type Tone,
|
|
258
|
-
} from "@vjdesigns/vjdesigns-ui";
|
|
259
|
-
|
|
260
|
-
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
261
|
-
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
262
|
-
|
|
263
|
-
const props = withDefaults(
|
|
264
|
-
defineProps<{
|
|
265
|
-
label: string;
|
|
266
|
-
variant?: ButtonVariant;
|
|
267
|
-
tone?: Tone;
|
|
268
|
-
size?: Size;
|
|
269
|
-
disabled?: boolean;
|
|
270
|
-
}>(),
|
|
271
|
-
{ variant: "solid", tone: "primary", size: "md", disabled: false }
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
const emit = defineEmits<{ click: [event: MouseEvent] }>();
|
|
275
|
-
|
|
276
|
-
const host = ref<HTMLElement | null>(null);
|
|
277
|
-
let root: Root | undefined;
|
|
278
|
-
|
|
279
|
-
function render() {
|
|
280
|
-
root?.render(
|
|
281
|
-
createElement(
|
|
282
|
-
ReactButton,
|
|
283
|
-
{
|
|
284
|
-
variant: props.variant,
|
|
285
|
-
tone: props.tone,
|
|
286
|
-
size: props.size,
|
|
287
|
-
disabled: props.disabled,
|
|
288
|
-
onClick: (event: ReactMouseEvent) => emit("click", event.nativeEvent),
|
|
289
|
-
},
|
|
290
|
-
props.label // the button's text is passed as children
|
|
291
|
-
)
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
onMounted(() => {
|
|
296
|
-
root = createRoot(host.value!);
|
|
297
|
-
render();
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
watch(() => ({ ...props }), render);
|
|
301
|
-
|
|
302
|
-
onBeforeUnmount(() => root?.unmount());
|
|
303
|
-
</script>
|
|
304
|
-
|
|
305
|
-
<template>
|
|
306
|
-
<span ref="host" />
|
|
307
|
-
</template>
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
Use it like any other Vue component:
|
|
311
|
-
|
|
312
|
-
```vue
|
|
313
|
-
<script setup lang="ts">
|
|
314
|
-
import VjButton from "./VjButton.vue";
|
|
315
|
-
|
|
316
|
-
const onSubmit = () => console.log("Submitted");
|
|
317
|
-
</script>
|
|
318
|
-
|
|
319
|
-
<template>
|
|
320
|
-
<VjButton label="Submit" tone="primary" @click="onSubmit" />
|
|
321
|
-
</template>
|
|
322
|
-
```
|
|
323
|
-
|
|
68
|
+
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.
|
|
69
|
+
|
|
70
|
+
### React
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { useState } from "react";
|
|
74
|
+
import { Button, CheckBox } from "@vjdesigns/vjdesigns-ui";
|
|
75
|
+
|
|
76
|
+
export function SignupForm() {
|
|
77
|
+
const [accepted, setAccepted] = useState(false);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<form>
|
|
81
|
+
<CheckBox
|
|
82
|
+
label="Accept terms"
|
|
83
|
+
checked={accepted}
|
|
84
|
+
onCheckedChange={setAccepted}
|
|
85
|
+
/>
|
|
86
|
+
<Button
|
|
87
|
+
variant="solid"
|
|
88
|
+
tone="primary"
|
|
89
|
+
size="md"
|
|
90
|
+
disabled={!accepted}
|
|
91
|
+
onClick={() => console.log("Submitted")}
|
|
92
|
+
>
|
|
93
|
+
Submit
|
|
94
|
+
</Button>
|
|
95
|
+
</form>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Next.js (App Router) and React Server Components
|
|
101
|
+
|
|
102
|
+
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.
|
|
103
|
+
|
|
104
|
+
Put the providers in a small client file of your own, and render it from the root layout:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
// app/providers.tsx
|
|
108
|
+
"use client";
|
|
109
|
+
import { LocaleProvider, ToastProvider } from "@vjdesigns/vjdesigns-ui";
|
|
110
|
+
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
111
|
+
import type { ReactNode } from "react";
|
|
112
|
+
|
|
113
|
+
export function Providers({ children }: { children: ReactNode }) {
|
|
114
|
+
return (
|
|
115
|
+
<LocaleProvider locale="es" messages={es}>
|
|
116
|
+
<ToastProvider>{children}</ToastProvider>
|
|
117
|
+
</LocaleProvider>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
// app/layout.tsx (a Server Component)
|
|
124
|
+
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
|
|
125
|
+
import { getLocaleDirection } from "@vjdesigns/vjdesigns-ui";
|
|
126
|
+
import { Providers } from "./providers";
|
|
127
|
+
|
|
128
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
129
|
+
return (
|
|
130
|
+
<html lang="es" dir={getLocaleDirection("es")}>
|
|
131
|
+
<body>
|
|
132
|
+
<Providers>{children}</Providers>
|
|
133
|
+
</body>
|
|
134
|
+
</html>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Two rules of Server Components to keep in mind:
|
|
140
|
+
|
|
141
|
+
- **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.
|
|
142
|
+
- **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`, ...).
|
|
143
|
+
|
|
144
|
+
### Angular
|
|
145
|
+
|
|
146
|
+
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.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
// vj-button.component.ts
|
|
150
|
+
import {
|
|
151
|
+
AfterViewInit,
|
|
152
|
+
Component,
|
|
153
|
+
ElementRef,
|
|
154
|
+
EventEmitter,
|
|
155
|
+
Input,
|
|
156
|
+
OnChanges,
|
|
157
|
+
OnDestroy,
|
|
158
|
+
Output,
|
|
159
|
+
ViewChild,
|
|
160
|
+
} from "@angular/core";
|
|
161
|
+
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
162
|
+
import { createRoot, Root } from "react-dom/client";
|
|
163
|
+
import {
|
|
164
|
+
Button,
|
|
165
|
+
type ButtonProps,
|
|
166
|
+
type ButtonVariant,
|
|
167
|
+
type Size,
|
|
168
|
+
type Tone,
|
|
169
|
+
} from "@vjdesigns/vjdesigns-ui";
|
|
170
|
+
|
|
171
|
+
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
172
|
+
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
173
|
+
|
|
174
|
+
@Component({
|
|
175
|
+
selector: "vj-button",
|
|
176
|
+
standalone: true,
|
|
177
|
+
template: `<span #host></span>`,
|
|
178
|
+
})
|
|
179
|
+
export class VjButtonComponent implements AfterViewInit, OnChanges, OnDestroy {
|
|
180
|
+
@ViewChild("host", { static: true }) host!: ElementRef<HTMLElement>;
|
|
181
|
+
|
|
182
|
+
@Input() label = "";
|
|
183
|
+
@Input() variant: ButtonVariant = "solid";
|
|
184
|
+
@Input() tone: Tone = "primary";
|
|
185
|
+
@Input() size: Size = "md";
|
|
186
|
+
@Input() disabled = false;
|
|
187
|
+
@Output() clicked = new EventEmitter<MouseEvent>();
|
|
188
|
+
|
|
189
|
+
private root?: Root;
|
|
190
|
+
|
|
191
|
+
ngAfterViewInit() {
|
|
192
|
+
this.root = createRoot(this.host.nativeElement);
|
|
193
|
+
this.render();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
ngOnChanges() {
|
|
197
|
+
this.render();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
ngOnDestroy() {
|
|
201
|
+
this.root?.unmount();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private render() {
|
|
205
|
+
this.root?.render(
|
|
206
|
+
createElement(
|
|
207
|
+
ReactButton,
|
|
208
|
+
{
|
|
209
|
+
variant: this.variant,
|
|
210
|
+
tone: this.tone,
|
|
211
|
+
size: this.size,
|
|
212
|
+
disabled: this.disabled,
|
|
213
|
+
onClick: (event: ReactMouseEvent) => this.clicked.emit(event.nativeEvent),
|
|
214
|
+
},
|
|
215
|
+
this.label // the button's text is passed as children
|
|
216
|
+
)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Import the wrapper wherever you need it:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
// app.component.ts
|
|
226
|
+
import { Component } from "@angular/core";
|
|
227
|
+
import { VjButtonComponent } from "./vj-button.component";
|
|
228
|
+
|
|
229
|
+
@Component({
|
|
230
|
+
selector: "app-root",
|
|
231
|
+
standalone: true,
|
|
232
|
+
imports: [VjButtonComponent],
|
|
233
|
+
template: `<vj-button label="Submit" tone="primary" (clicked)="onSubmit()" />`,
|
|
234
|
+
})
|
|
235
|
+
export class AppComponent {
|
|
236
|
+
onSubmit() {
|
|
237
|
+
console.log("Submitted");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Vue 3
|
|
243
|
+
|
|
244
|
+
Make a wrapper component that mounts the React component when it loads and re-renders it whenever its props change.
|
|
245
|
+
|
|
246
|
+
```vue
|
|
247
|
+
<!-- VjButton.vue -->
|
|
248
|
+
<script setup lang="ts">
|
|
249
|
+
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
250
|
+
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
|
|
251
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
252
|
+
import {
|
|
253
|
+
Button,
|
|
254
|
+
type ButtonProps,
|
|
255
|
+
type ButtonVariant,
|
|
256
|
+
type Size,
|
|
257
|
+
type Tone,
|
|
258
|
+
} from "@vjdesigns/vjdesigns-ui";
|
|
259
|
+
|
|
260
|
+
// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
|
|
261
|
+
const ReactButton = Button as (props: ButtonProps) => ReactElement;
|
|
262
|
+
|
|
263
|
+
const props = withDefaults(
|
|
264
|
+
defineProps<{
|
|
265
|
+
label: string;
|
|
266
|
+
variant?: ButtonVariant;
|
|
267
|
+
tone?: Tone;
|
|
268
|
+
size?: Size;
|
|
269
|
+
disabled?: boolean;
|
|
270
|
+
}>(),
|
|
271
|
+
{ variant: "solid", tone: "primary", size: "md", disabled: false }
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
const emit = defineEmits<{ click: [event: MouseEvent] }>();
|
|
275
|
+
|
|
276
|
+
const host = ref<HTMLElement | null>(null);
|
|
277
|
+
let root: Root | undefined;
|
|
278
|
+
|
|
279
|
+
function render() {
|
|
280
|
+
root?.render(
|
|
281
|
+
createElement(
|
|
282
|
+
ReactButton,
|
|
283
|
+
{
|
|
284
|
+
variant: props.variant,
|
|
285
|
+
tone: props.tone,
|
|
286
|
+
size: props.size,
|
|
287
|
+
disabled: props.disabled,
|
|
288
|
+
onClick: (event: ReactMouseEvent) => emit("click", event.nativeEvent),
|
|
289
|
+
},
|
|
290
|
+
props.label // the button's text is passed as children
|
|
291
|
+
)
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
onMounted(() => {
|
|
296
|
+
root = createRoot(host.value!);
|
|
297
|
+
render();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
watch(() => ({ ...props }), render);
|
|
301
|
+
|
|
302
|
+
onBeforeUnmount(() => root?.unmount());
|
|
303
|
+
</script>
|
|
304
|
+
|
|
305
|
+
<template>
|
|
306
|
+
<span ref="host" />
|
|
307
|
+
</template>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Use it like any other Vue component:
|
|
311
|
+
|
|
312
|
+
```vue
|
|
313
|
+
<script setup lang="ts">
|
|
314
|
+
import VjButton from "./VjButton.vue";
|
|
315
|
+
|
|
316
|
+
const onSubmit = () => console.log("Submitted");
|
|
317
|
+
</script>
|
|
318
|
+
|
|
319
|
+
<template>
|
|
320
|
+
<VjButton label="Submit" tone="primary" @click="onSubmit" />
|
|
321
|
+
</template>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
324
|
> **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.
|
|
325
325
|
|
|
326
326
|
# Guide: Theming
|
|
327
327
|
|
|
328
|
-
Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:
|
|
329
|
-
|
|
330
|
-
```tsx
|
|
331
|
-
import { Theme, Button } from "@vjdesigns/vjdesigns-ui";
|
|
332
|
-
|
|
333
|
-
<Theme mode="dark" brand="purple" fill>
|
|
334
|
-
<Button>Dark, purple button</Button>
|
|
335
|
-
</Theme>
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
| Prop | Type | Default | Description |
|
|
339
|
-
| --- | --- | --- | --- |
|
|
340
|
-
| `mode` | `"light" \| "dark"` | inherited | Color mode for everything inside. |
|
|
341
|
-
| `brand` | `"black" \| "blue" \| "gold" \| "green" \| "purple"`, a hex color, or `{ light, dark }` | inherited | Brand palette for buttons, links, focus rings and indicators. |
|
|
342
|
-
| `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. |
|
|
343
|
-
| `fill` | `boolean` | `false` | Paints the theme's background and text color on the wrapper. |
|
|
344
|
-
|
|
345
|
-
Outside React (or to theme the whole page), set the attributes on `<html>` instead:
|
|
346
|
-
|
|
347
|
-
```html
|
|
348
|
-
<html data-theme="dark" data-brand="purple" data-accent="lime">
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
### Accent color
|
|
352
|
-
|
|
353
|
-
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:
|
|
354
|
-
|
|
355
|
-
| Brand | Default accent |
|
|
356
|
-
| --- | --- |
|
|
357
|
-
| `blue` (default) | sky blue `#76c7ff` |
|
|
358
|
-
| `purple` | lavender `#c0b0ff` |
|
|
359
|
-
| `gold` | amber `#f5ad5f` |
|
|
360
|
-
| `green` | mint `#72d4ad` |
|
|
361
|
-
| `black` | lime `#c8f031` (black has no hue to build on) |
|
|
362
|
-
| a custom hex | generated from that color |
|
|
363
|
-
|
|
364
|
-
To choose a different one:
|
|
365
|
-
|
|
366
|
-
```tsx
|
|
367
|
-
<Theme accent="lime">…</Theme> // the original bright yellow-green ("volt", its former name, still works)
|
|
368
|
-
<Theme accent="#ff6b00">…</Theme> // any color
|
|
369
|
-
<Theme accent="brand">…</Theme> // back to the brand's own, inside an area with another accent
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
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.
|
|
373
|
-
|
|
374
|
-
### Custom brand colors
|
|
375
|
-
|
|
376
|
-
Pass any hex color as `brand` and a full palette is generated for both modes:
|
|
377
|
-
|
|
378
|
-
```tsx
|
|
379
|
-
<Theme brand="#e11d48">…</Theme>
|
|
380
|
-
<Theme brand={{ light: "#4338ca", dark: "#f472b6" }}>…</Theme>
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
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.
|
|
384
|
-
|
|
385
|
-
To define a brand in CSS instead (for the whole page, applied before any JavaScript runs), generate a stylesheet rule with `brandCss`:
|
|
386
|
-
|
|
387
|
-
```ts
|
|
388
|
-
import { brandCss } from "@vjdesigns/vjdesigns-ui";
|
|
389
|
-
|
|
390
|
-
brandCss("acme", "#e11d48"); // '[data-brand="acme"] { --brand-light-primary: … }'
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
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.
|
|
394
|
-
|
|
395
|
-
### Tailwind CSS
|
|
396
|
-
|
|
397
|
-
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:
|
|
398
|
-
|
|
399
|
-
```css
|
|
400
|
-
@import "tailwindcss";
|
|
401
|
-
@import "@vjdesigns/vjdesigns-ui/tailwind.css";
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
```tsx
|
|
405
|
-
<section className="bg-surface text-text rounded-xl shadow-md p-6">
|
|
406
|
-
<h2 className="font-display text-2xl tracking-tight">Season stats</h2>
|
|
407
|
-
<p className="text-text-muted">Updated after every game.</p>
|
|
408
|
-
<span className="bg-accent text-on-accent rounded-control px-3">New</span>
|
|
409
|
-
</section>
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
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.
|
|
413
|
-
|
|
414
|
-
| Group | Utilities |
|
|
415
|
-
| --- | --- |
|
|
416
|
-
| 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`). |
|
|
417
|
-
| 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. |
|
|
418
|
-
| 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` |
|
|
419
|
-
| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |
|
|
420
|
-
| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |
|
|
421
|
-
| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |
|
|
422
|
-
| 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 |
|
|
423
|
-
| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |
|
|
424
|
-
| Dark mode | `dark:` follows `data-theme="dark"`, not the OS setting. |
|
|
425
|
-
|
|
426
|
-
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.
|
|
427
|
-
|
|
428
|
-
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.
|
|
429
|
-
|
|
430
|
-
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.
|
|
431
|
-
|
|
328
|
+
Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
import { Theme, Button } from "@vjdesigns/vjdesigns-ui";
|
|
332
|
+
|
|
333
|
+
<Theme mode="dark" brand="purple" fill>
|
|
334
|
+
<Button>Dark, purple button</Button>
|
|
335
|
+
</Theme>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
| Prop | Type | Default | Description |
|
|
339
|
+
| --- | --- | --- | --- |
|
|
340
|
+
| `mode` | `"light" \| "dark"` | inherited | Color mode for everything inside. |
|
|
341
|
+
| `brand` | `"black" \| "blue" \| "gold" \| "green" \| "purple"`, a hex color, or `{ light, dark }` | inherited | Brand palette for buttons, links, focus rings and indicators. |
|
|
342
|
+
| `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. |
|
|
343
|
+
| `fill` | `boolean` | `false` | Paints the theme's background and text color on the wrapper. |
|
|
344
|
+
|
|
345
|
+
Outside React (or to theme the whole page), set the attributes on `<html>` instead:
|
|
346
|
+
|
|
347
|
+
```html
|
|
348
|
+
<html data-theme="dark" data-brand="purple" data-accent="lime">
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Accent color
|
|
352
|
+
|
|
353
|
+
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:
|
|
354
|
+
|
|
355
|
+
| Brand | Default accent |
|
|
356
|
+
| --- | --- |
|
|
357
|
+
| `blue` (default) | sky blue `#76c7ff` |
|
|
358
|
+
| `purple` | lavender `#c0b0ff` |
|
|
359
|
+
| `gold` | amber `#f5ad5f` |
|
|
360
|
+
| `green` | mint `#72d4ad` |
|
|
361
|
+
| `black` | lime `#c8f031` (black has no hue to build on) |
|
|
362
|
+
| a custom hex | generated from that color |
|
|
363
|
+
|
|
364
|
+
To choose a different one:
|
|
365
|
+
|
|
366
|
+
```tsx
|
|
367
|
+
<Theme accent="lime">…</Theme> // the original bright yellow-green ("volt", its former name, still works)
|
|
368
|
+
<Theme accent="#ff6b00">…</Theme> // any color
|
|
369
|
+
<Theme accent="brand">…</Theme> // back to the brand's own, inside an area with another accent
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
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.
|
|
373
|
+
|
|
374
|
+
### Custom brand colors
|
|
375
|
+
|
|
376
|
+
Pass any hex color as `brand` and a full palette is generated for both modes:
|
|
377
|
+
|
|
378
|
+
```tsx
|
|
379
|
+
<Theme brand="#e11d48">…</Theme>
|
|
380
|
+
<Theme brand={{ light: "#4338ca", dark: "#f472b6" }}>…</Theme>
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
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.
|
|
384
|
+
|
|
385
|
+
To define a brand in CSS instead (for the whole page, applied before any JavaScript runs), generate a stylesheet rule with `brandCss`:
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
import { brandCss } from "@vjdesigns/vjdesigns-ui";
|
|
389
|
+
|
|
390
|
+
brandCss("acme", "#e11d48"); // '[data-brand="acme"] { --brand-light-primary: … }'
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
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.
|
|
394
|
+
|
|
395
|
+
### Tailwind CSS
|
|
396
|
+
|
|
397
|
+
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:
|
|
398
|
+
|
|
399
|
+
```css
|
|
400
|
+
@import "tailwindcss";
|
|
401
|
+
@import "@vjdesigns/vjdesigns-ui/tailwind.css";
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
```tsx
|
|
405
|
+
<section className="bg-surface text-text rounded-xl shadow-md p-6">
|
|
406
|
+
<h2 className="font-display text-2xl tracking-tight">Season stats</h2>
|
|
407
|
+
<p className="text-text-muted">Updated after every game.</p>
|
|
408
|
+
<span className="bg-accent text-on-accent rounded-control px-3">New</span>
|
|
409
|
+
</section>
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
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.
|
|
413
|
+
|
|
414
|
+
| Group | Utilities |
|
|
415
|
+
| --- | --- |
|
|
416
|
+
| 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`). |
|
|
417
|
+
| 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. |
|
|
418
|
+
| 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` |
|
|
419
|
+
| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |
|
|
420
|
+
| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |
|
|
421
|
+
| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |
|
|
422
|
+
| 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 |
|
|
423
|
+
| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |
|
|
424
|
+
| Dark mode | `dark:` follows `data-theme="dark"`, not the OS setting. |
|
|
425
|
+
|
|
426
|
+
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.
|
|
427
|
+
|
|
428
|
+
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.
|
|
429
|
+
|
|
430
|
+
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.
|
|
431
|
+
|
|
432
432
|
The preset doesn't change the components, and Tailwind's preflight (its CSS reset) doesn't override them, whichever stylesheet loads first.
|
|
433
433
|
|
|
434
434
|
# Guide: Languages
|
|
435
435
|
|
|
436
|
-
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:
|
|
437
|
-
|
|
438
|
-
```tsx
|
|
439
|
-
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
|
|
440
|
-
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
441
|
-
|
|
442
|
-
<LocaleProvider locale="es" messages={es}>
|
|
443
|
-
<App />
|
|
444
|
-
</LocaleProvider>
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
`LocaleProvider` sets:
|
|
448
|
-
|
|
449
|
-
- **Built-in text** for every component, from `messages`.
|
|
450
|
-
- **Dates and numbers** in the locale's format (`23/10/2026`, `1.234,5`), and plurals that follow the language's rules.
|
|
451
|
-
- **Writing direction**: Arabic, Hebrew, Persian, and Urdu get `dir="rtl"`, and layouts and arrow keys mirror.
|
|
452
|
-
- **`lang`** on its wrapper, so screen readers pronounce the text correctly. Popups (menus, dialogs, tooltips) keep the language of the area that opened them.
|
|
453
|
-
|
|
454
|
-
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.
|
|
455
|
-
|
|
456
|
-
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).
|
|
457
|
-
|
|
458
|
-
### What gets translated
|
|
459
|
-
|
|
460
|
-
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}>`:
|
|
461
|
-
|
|
462
|
-
| | Translated? |
|
|
463
|
-
| --- | --- |
|
|
464
|
-
| Text your app passes in, like `<Button>Save</Button>` | No: your app translates it |
|
|
465
|
-
| Built-in names, like "Close", "Next page", "Clear search" | Yes: "Schließen", "Nächste Seite", "Suche löschen" |
|
|
466
|
-
| Screen-reader announcements, like "3 results available" | Yes: "3 Ergebnisse verfügbar" |
|
|
467
|
-
| Validation messages, empty states, file-upload prompts | Yes |
|
|
468
|
-
| Dates and numbers | Yes: "23.10.2026", "4,5" |
|
|
469
|
-
|
|
470
|
-
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)).
|
|
471
|
-
|
|
472
|
-
### Bundled languages
|
|
473
|
-
|
|
474
|
-
`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).
|
|
475
|
-
|
|
476
|
-
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).)
|
|
477
|
-
|
|
478
|
-
### Changing a few strings
|
|
479
|
-
|
|
480
|
-
Pass only the strings you want to change. Everything else falls back to the outer provider's language (English at the top):
|
|
481
|
-
|
|
482
|
-
```tsx
|
|
483
|
-
<LocaleProvider locale="en-GB" messages={{ pagination: { next: "Onwards" } }}>
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
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.
|
|
487
|
-
|
|
488
|
-
### Other languages
|
|
489
|
-
|
|
490
|
-
For a language that isn't bundled, write a complete messages object. TypeScript flags any missing string. Use English as the template:
|
|
491
|
-
|
|
492
|
-
```ts
|
|
493
|
-
import { en, plural, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
494
|
-
|
|
495
|
-
const p = plural("sw");
|
|
496
|
-
export const sw: Messages = {
|
|
497
|
-
...en,
|
|
498
|
-
pagination: { ...en.pagination, next: "Ukurasa unaofuata", previous: "Ukurasa uliopita" },
|
|
499
|
-
searchInput: {
|
|
500
|
-
...en.searchInput,
|
|
501
|
-
results: (count) => p(count, { "=0": "Hakuna matokeo", one: "Tokeo #", other: "Matokeo #" }),
|
|
502
|
-
},
|
|
503
|
-
// ...
|
|
504
|
-
};
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
`plural(locale)` picks the right plural form for any language (`#` is the formatted number).
|
|
508
|
-
|
|
509
|
-
### Switching language at runtime
|
|
510
|
-
|
|
511
|
-
List the languages your app offers as loaders, so each one is downloaded only when picked:
|
|
512
|
-
|
|
513
|
-
```tsx
|
|
514
|
-
import { LocaleProvider, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
515
|
-
|
|
516
|
-
const loaders: Record<string, () => Promise<{ default: Messages }>> = {
|
|
517
|
-
es: () => import("@vjdesigns/vjdesigns-ui/locales/es"),
|
|
518
|
-
fr: () => import("@vjdesigns/vjdesigns-ui/locales/fr"),
|
|
519
|
-
ar: () => import("@vjdesigns/vjdesigns-ui/locales/ar"),
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
function App({ lang }: { lang: string }) {
|
|
523
|
-
const [messages, setMessages] = useState<Messages>();
|
|
524
|
-
useEffect(() => {
|
|
525
|
-
const load = loaders[lang];
|
|
526
|
-
if (load) load().then((mod) => setMessages(mod.default));
|
|
527
|
-
else setMessages(undefined); // English
|
|
528
|
-
}, [lang]);
|
|
529
|
-
// Until a language loads, the previous one (or English) shows.
|
|
530
|
-
return <LocaleProvider locale={lang} messages={messages}>…</LocaleProvider>;
|
|
531
|
-
}
|
|
532
|
-
```
|
|
533
|
-
|
|
436
|
+
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:
|
|
437
|
+
|
|
438
|
+
```tsx
|
|
439
|
+
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
|
|
440
|
+
import es from "@vjdesigns/vjdesigns-ui/locales/es";
|
|
441
|
+
|
|
442
|
+
<LocaleProvider locale="es" messages={es}>
|
|
443
|
+
<App />
|
|
444
|
+
</LocaleProvider>
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
`LocaleProvider` sets:
|
|
448
|
+
|
|
449
|
+
- **Built-in text** for every component, from `messages`.
|
|
450
|
+
- **Dates and numbers** in the locale's format (`23/10/2026`, `1.234,5`), and plurals that follow the language's rules.
|
|
451
|
+
- **Writing direction**: Arabic, Hebrew, Persian, and Urdu get `dir="rtl"`, and layouts and arrow keys mirror.
|
|
452
|
+
- **`lang`** on its wrapper, so screen readers pronounce the text correctly. Popups (menus, dialogs, tooltips) keep the language of the area that opened them.
|
|
453
|
+
|
|
454
|
+
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.
|
|
455
|
+
|
|
456
|
+
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).
|
|
457
|
+
|
|
458
|
+
### What gets translated
|
|
459
|
+
|
|
460
|
+
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}>`:
|
|
461
|
+
|
|
462
|
+
| | Translated? |
|
|
463
|
+
| --- | --- |
|
|
464
|
+
| Text your app passes in, like `<Button>Save</Button>` | No: your app translates it |
|
|
465
|
+
| Built-in names, like "Close", "Next page", "Clear search" | Yes: "Schließen", "Nächste Seite", "Suche löschen" |
|
|
466
|
+
| Screen-reader announcements, like "3 results available" | Yes: "3 Ergebnisse verfügbar" |
|
|
467
|
+
| Validation messages, empty states, file-upload prompts | Yes |
|
|
468
|
+
| Dates and numbers | Yes: "23.10.2026", "4,5" |
|
|
469
|
+
|
|
470
|
+
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)).
|
|
471
|
+
|
|
472
|
+
### Bundled languages
|
|
473
|
+
|
|
474
|
+
`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).
|
|
475
|
+
|
|
476
|
+
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).)
|
|
477
|
+
|
|
478
|
+
### Changing a few strings
|
|
479
|
+
|
|
480
|
+
Pass only the strings you want to change. Everything else falls back to the outer provider's language (English at the top):
|
|
481
|
+
|
|
482
|
+
```tsx
|
|
483
|
+
<LocaleProvider locale="en-GB" messages={{ pagination: { next: "Onwards" } }}>
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
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.
|
|
487
|
+
|
|
488
|
+
### Other languages
|
|
489
|
+
|
|
490
|
+
For a language that isn't bundled, write a complete messages object. TypeScript flags any missing string. Use English as the template:
|
|
491
|
+
|
|
492
|
+
```ts
|
|
493
|
+
import { en, plural, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
494
|
+
|
|
495
|
+
const p = plural("sw");
|
|
496
|
+
export const sw: Messages = {
|
|
497
|
+
...en,
|
|
498
|
+
pagination: { ...en.pagination, next: "Ukurasa unaofuata", previous: "Ukurasa uliopita" },
|
|
499
|
+
searchInput: {
|
|
500
|
+
...en.searchInput,
|
|
501
|
+
results: (count) => p(count, { "=0": "Hakuna matokeo", one: "Tokeo #", other: "Matokeo #" }),
|
|
502
|
+
},
|
|
503
|
+
// ...
|
|
504
|
+
};
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
`plural(locale)` picks the right plural form for any language (`#` is the formatted number).
|
|
508
|
+
|
|
509
|
+
### Switching language at runtime
|
|
510
|
+
|
|
511
|
+
List the languages your app offers as loaders, so each one is downloaded only when picked:
|
|
512
|
+
|
|
513
|
+
```tsx
|
|
514
|
+
import { LocaleProvider, type Messages } from "@vjdesigns/vjdesigns-ui";
|
|
515
|
+
|
|
516
|
+
const loaders: Record<string, () => Promise<{ default: Messages }>> = {
|
|
517
|
+
es: () => import("@vjdesigns/vjdesigns-ui/locales/es"),
|
|
518
|
+
fr: () => import("@vjdesigns/vjdesigns-ui/locales/fr"),
|
|
519
|
+
ar: () => import("@vjdesigns/vjdesigns-ui/locales/ar"),
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
function App({ lang }: { lang: string }) {
|
|
523
|
+
const [messages, setMessages] = useState<Messages>();
|
|
524
|
+
useEffect(() => {
|
|
525
|
+
const load = loaders[lang];
|
|
526
|
+
if (load) load().then((mod) => setMessages(mod.default));
|
|
527
|
+
else setMessages(undefined); // English
|
|
528
|
+
}, [lang]);
|
|
529
|
+
// Until a language loads, the previous one (or English) shows.
|
|
530
|
+
return <LocaleProvider locale={lang} messages={messages}>…</LocaleProvider>;
|
|
531
|
+
}
|
|
532
|
+
```
|
|
533
|
+
|
|
534
534
|
For server rendering, also set `<html lang="…" dir="…">` on the page. `getLocaleDirection(locale)` returns `"ltr"` or `"rtl"`.
|
|
535
535
|
|
|
536
536
|
# Guide: Form validation
|
|
537
537
|
|
|
538
|
-
> **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.
|
|
539
|
-
|
|
540
|
-
`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.
|
|
541
|
-
|
|
542
|
-
```tsx
|
|
543
|
-
import {
|
|
544
|
-
useFormValidation, rules, ErrorSummary, Field, Input, PasswordInput, Button,
|
|
545
|
-
} from "@vjdesigns/vjdesigns-ui";
|
|
546
|
-
|
|
547
|
-
function SignUp() {
|
|
548
|
-
const form = useFormValidation({
|
|
549
|
-
rules: {
|
|
550
|
-
confirm: rules.matches("password", "The passwords don't match."),
|
|
551
|
-
serverIp: rules.ip(), // IPv4 or IPv6
|
|
552
|
-
},
|
|
553
|
-
// Runs only when everything is valid. Return the server's errors to show them on their fields.
|
|
554
|
-
onValid: async (values) => {
|
|
555
|
-
const response = await api.signUp(values);
|
|
556
|
-
return response.errors; // e.g. { username: "That username is taken." }
|
|
557
|
-
},
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
return (
|
|
561
|
-
<form {...form.formProps}>
|
|
562
|
-
<ErrorSummary ref={form.summaryRef} errors={form.errorList} />
|
|
563
|
-
<Field label="Email" required error={form.errors.email}>
|
|
564
|
-
<Input name="email" type="email" />
|
|
565
|
-
</Field>
|
|
566
|
-
<Field label="Password" required error={form.errors.password}>
|
|
567
|
-
<PasswordInput name="password" minLength={12} />
|
|
568
|
-
</Field>
|
|
569
|
-
<Field label="Confirm password" required error={form.errors.confirm}>
|
|
570
|
-
<PasswordInput name="confirm" />
|
|
571
|
-
</Field>
|
|
572
|
-
<Field label="Server IP" error={form.errors.serverIp}>
|
|
573
|
-
<Input name="serverIp" />
|
|
574
|
-
</Field>
|
|
575
|
-
<Button type="submit" loading={form.isSubmitting}>Create account</Button>
|
|
576
|
-
</form>
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
```
|
|
580
|
-
|
|
581
|
-
How it behaves:
|
|
582
|
-
|
|
583
|
-
- **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.
|
|
584
|
-
- **Errors are keyed by the field's `name`.** Pass `form.errors.<name>` to each `Field`'s `error`.
|
|
585
|
-
- **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.
|
|
586
|
-
- **Server errors** (returned from `onValid`, or set with `form.setErrors({...})`) show on their fields and stay until that field is edited.
|
|
587
|
-
- **Emails** must have a real domain (`name@example.com`). The browser's own check also accepts `name@localhost`.
|
|
588
|
-
|
|
589
|
-
### Rules and format checks
|
|
590
|
-
|
|
591
|
-
| Rule | Checks |
|
|
592
|
-
| --- | --- |
|
|
593
|
-
| `rules.required()` | Not empty (for controls without a native `required`) |
|
|
594
|
-
| `rules.email()` | An email address in the usual format, with a top-level domain |
|
|
595
|
-
| `rules.ip()` / `rules.ip({ version: 4 })` / `rules.ip({ version: 6 })` | An IPv4 or IPv6 address |
|
|
596
|
-
| `rules.minLength(n)` / `rules.maxLength(n)` | Length in characters |
|
|
597
|
-
| `rules.pattern(/regex/, "message")` | The whole value matches |
|
|
598
|
-
| `rules.matches("otherField")` | Equals another field (confirm password) |
|
|
599
|
-
| your own `(value, { values }) => message` | Anything else |
|
|
600
|
-
|
|
601
|
-
Each rule takes an optional custom message. The checks behind them are exported for use anywhere, including your server:
|
|
602
|
-
|
|
603
|
-
- `isEmail(value)`
|
|
604
|
-
- `isIPv4(value)`: four numbers 0–255, no leading zeros
|
|
605
|
-
- `isIPv6(value)`: including `::` shorthand and IPv4 tails like `::ffff:192.168.0.1`
|
|
538
|
+
> **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.
|
|
539
|
+
|
|
540
|
+
`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.
|
|
541
|
+
|
|
542
|
+
```tsx
|
|
543
|
+
import {
|
|
544
|
+
useFormValidation, rules, ErrorSummary, Field, Input, PasswordInput, Button,
|
|
545
|
+
} from "@vjdesigns/vjdesigns-ui";
|
|
546
|
+
|
|
547
|
+
function SignUp() {
|
|
548
|
+
const form = useFormValidation({
|
|
549
|
+
rules: {
|
|
550
|
+
confirm: rules.matches("password", "The passwords don't match."),
|
|
551
|
+
serverIp: rules.ip(), // IPv4 or IPv6
|
|
552
|
+
},
|
|
553
|
+
// Runs only when everything is valid. Return the server's errors to show them on their fields.
|
|
554
|
+
onValid: async (values) => {
|
|
555
|
+
const response = await api.signUp(values);
|
|
556
|
+
return response.errors; // e.g. { username: "That username is taken." }
|
|
557
|
+
},
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
return (
|
|
561
|
+
<form {...form.formProps}>
|
|
562
|
+
<ErrorSummary ref={form.summaryRef} errors={form.errorList} />
|
|
563
|
+
<Field label="Email" required error={form.errors.email}>
|
|
564
|
+
<Input name="email" type="email" />
|
|
565
|
+
</Field>
|
|
566
|
+
<Field label="Password" required error={form.errors.password}>
|
|
567
|
+
<PasswordInput name="password" minLength={12} />
|
|
568
|
+
</Field>
|
|
569
|
+
<Field label="Confirm password" required error={form.errors.confirm}>
|
|
570
|
+
<PasswordInput name="confirm" />
|
|
571
|
+
</Field>
|
|
572
|
+
<Field label="Server IP" error={form.errors.serverIp}>
|
|
573
|
+
<Input name="serverIp" />
|
|
574
|
+
</Field>
|
|
575
|
+
<Button type="submit" loading={form.isSubmitting}>Create account</Button>
|
|
576
|
+
</form>
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
How it behaves:
|
|
582
|
+
|
|
583
|
+
- **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.
|
|
584
|
+
- **Errors are keyed by the field's `name`.** Pass `form.errors.<name>` to each `Field`'s `error`.
|
|
585
|
+
- **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.
|
|
586
|
+
- **Server errors** (returned from `onValid`, or set with `form.setErrors({...})`) show on their fields and stay until that field is edited.
|
|
587
|
+
- **Emails** must have a real domain (`name@example.com`). The browser's own check also accepts `name@localhost`.
|
|
588
|
+
|
|
589
|
+
### Rules and format checks
|
|
590
|
+
|
|
591
|
+
| Rule | Checks |
|
|
592
|
+
| --- | --- |
|
|
593
|
+
| `rules.required()` | Not empty (for controls without a native `required`) |
|
|
594
|
+
| `rules.email()` | An email address in the usual format, with a top-level domain |
|
|
595
|
+
| `rules.ip()` / `rules.ip({ version: 4 })` / `rules.ip({ version: 6 })` | An IPv4 or IPv6 address |
|
|
596
|
+
| `rules.minLength(n)` / `rules.maxLength(n)` | Length in characters |
|
|
597
|
+
| `rules.pattern(/regex/, "message")` | The whole value matches |
|
|
598
|
+
| `rules.matches("otherField")` | Equals another field (confirm password) |
|
|
599
|
+
| your own `(value, { values }) => message` | Anything else |
|
|
600
|
+
|
|
601
|
+
Each rule takes an optional custom message. The checks behind them are exported for use anywhere, including your server:
|
|
602
|
+
|
|
603
|
+
- `isEmail(value)`
|
|
604
|
+
- `isIPv4(value)`: four numbers 0–255, no leading zeros
|
|
605
|
+
- `isIPv6(value)`: including `::` shorthand and IPv4 tails like `::ffff:192.168.0.1`
|
|
606
606
|
- `isIP(value, version?)`
|
|
607
607
|
|
|
608
608
|
# Components
|
|
@@ -2823,7 +2823,7 @@ Accessibility:
|
|
|
2823
2823
|
|
|
2824
2824
|
import { Calendar } from "@vjdesigns/vjdesigns-ui";
|
|
2825
2825
|
|
|
2826
|
-
Category: forms · Storybook: Forms/
|
|
2826
|
+
Category: forms · Storybook: Forms/Calendar
|
|
2827
2827
|
|
|
2828
2828
|
A month grid for picking a date or a date range, following the WAI-ARIA
|
|
2829
2829
|
date picker grid pattern: arrow keys move by day and week, Home/End to the
|
|
@@ -2864,21 +2864,17 @@ time zones. Use `parseISODate` / `toISODate` to convert to and from `Date`.
|
|
|
2864
2864
|
### Examples (Storybook stories)
|
|
2865
2865
|
|
|
2866
2866
|
- Playground
|
|
2867
|
-
-
|
|
2868
|
-
-
|
|
2869
|
-
- Typed input + validation
|
|
2867
|
+
- Single
|
|
2868
|
+
- Range
|
|
2870
2869
|
- Min / Max
|
|
2871
|
-
- Disabled
|
|
2872
|
-
-
|
|
2873
|
-
- Clearable
|
|
2874
|
-
- Sizes
|
|
2875
|
-
- States
|
|
2870
|
+
- Disabled dates (weekends)
|
|
2871
|
+
- Two Months
|
|
2876
2872
|
- Locales
|
|
2877
|
-
-
|
|
2878
|
-
-
|
|
2879
|
-
-
|
|
2880
|
-
-
|
|
2881
|
-
-
|
|
2873
|
+
- Sizes
|
|
2874
|
+
- Outside Days Hidden
|
|
2875
|
+
- Controlled
|
|
2876
|
+
- Composition: tournament dates
|
|
2877
|
+
- Selected date outside min: A selected date that has become unavailable (here, `min` is after it) keeps on-primary text on the primary fill; the line-through marks it unavailable. (axe skips contrast on `aria-disabled` cells, so check this one by eye in both themes.)
|
|
2882
2878
|
|
|
2883
2879
|
## CheckBox
|
|
2884
2880
|
|
|
@@ -3252,7 +3248,7 @@ Escape closes only the calendar, also inside a `Modal` or `Drawer`.
|
|
|
3252
3248
|
|
|
3253
3249
|
import { DateRangePicker } from "@vjdesigns/vjdesigns-ui";
|
|
3254
3250
|
|
|
3255
|
-
Category: forms · Storybook: Forms/
|
|
3251
|
+
Category: forms · Storybook: Forms/DateRangePicker
|
|
3256
3252
|
|
|
3257
3253
|
A date range field: two text fields (start and end) typed in the locale's
|
|
3258
3254
|
short format, plus a calendar button that opens a range `Calendar` (two
|
|
@@ -3313,6 +3309,19 @@ invalid state reach both fields. Errors are announced politely.
|
|
|
3313
3309
|
- `style`: `CSSProperties`. Style for the outer root.
|
|
3314
3310
|
- `id`: `string`. id of the start field (the Field label points here).
|
|
3315
3311
|
|
|
3312
|
+
### Examples (Storybook stories)
|
|
3313
|
+
|
|
3314
|
+
- Playground
|
|
3315
|
+
- Basic: Pick a start and an end in the calendar: the range commits and the popup closes.
|
|
3316
|
+
- Escape after one pick: Escape after picking only a start keeps the old range.
|
|
3317
|
+
- With Field: Inside a Field: the group and both inputs take the Field's label, hint, and required state.
|
|
3318
|
+
- Typed Input: Typed dates are parsed on blur; an end before the start is rejected with a message.
|
|
3319
|
+
- Min, max, and unavailable days
|
|
3320
|
+
- States
|
|
3321
|
+
- Sizes
|
|
3322
|
+
- Narrow: Narrow containers stack the two fields (reflow at 320px).
|
|
3323
|
+
- In AForm: Hidden inputs (`startName`, `endName`) submit ISO dates with the form.
|
|
3324
|
+
|
|
3316
3325
|
## DateTimePicker
|
|
3317
3326
|
|
|
3318
3327
|
import { DateTimePicker } from "@vjdesigns/vjdesigns-ui";
|
|
@@ -7344,6 +7353,49 @@ without a provider, using the defaults.
|
|
|
7344
7353
|
- Near Viewport Edge: Triggers pinned to the canvas edges. A `top` tooltip on the top edge flips to the bottom; tooltips near the sides are clamped into the viewport while the arrow keeps pointing at the trigger.
|
|
7345
7354
|
- Logical Placements: `start` and `end` are logical sides: `end` sits on the right in a left-to-right layout and on the left in a right-to-left one (Sidebar's rail tooltips use it).
|
|
7346
7355
|
|
|
7356
|
+
## AccessibilityIcon
|
|
7357
|
+
|
|
7358
|
+
import { AccessibilityIcon } from "@vjdesigns/vjdesigns-ui";
|
|
7359
|
+
|
|
7360
|
+
Category: primitives · Storybook: Primitives/AccessibilityIcon
|
|
7361
|
+
|
|
7362
|
+
Icons for accessibility features and services: wheelchair access, audio
|
|
7363
|
+
description and transcripts, hearing loops, sign language, display
|
|
7364
|
+
settings, and alternative input. (Captions are `Icon name="captions"`.) Same props as `Icon`, plus `labeled`, which turns on a
|
|
7365
|
+
built-in accessible name in every bundled language. Decorative by default.
|
|
7366
|
+
|
|
7367
|
+
Drawn to stricter rules than the main set, all checked on every release:
|
|
7368
|
+
readable at 16px, never mistakable for another icon at that size, inside a
|
|
7369
|
+
safe area, and painted only with `currentColor` so tones, dark mode, and
|
|
7370
|
+
Windows High Contrast recolor them. Icons that show movement (wheelchair,
|
|
7371
|
+
ramp, blind) mirror in right-to-left layouts. Use them at 16px (`sm`) or
|
|
7372
|
+
larger.
|
|
7373
|
+
|
|
7374
|
+
### Props
|
|
7375
|
+
|
|
7376
|
+
- `size`: `IconSize`. Size: `xs` 12px, `sm` 16px, `md` 20px, `lg` 24px, `xl` 32px, `2xl` 48px, or a number of pixels.
|
|
7377
|
+
- `tone`: `IconTone`. Color. Defaults to `inherit` (`currentColor`).
|
|
7378
|
+
- `strokeWidth`: `number`. Stroke width on the 24x24 grid. Applies to stroke-based icons.
|
|
7379
|
+
- `label`: `string`. Accessible name. When set, the icon is meaningful (`role="img"` plus `aria-label`). When omitted, the icon is decorative and hidden from assistive technology (`aria-hidden="true"`, `focusable="false"`).
|
|
7380
|
+
- `spin`: `boolean`. Rotates the icon continuously (for `loader`). Stops under reduced motion.
|
|
7381
|
+
- `labeled`: `boolean`. Give the icon its built-in accessible name, translated by `LocaleProvider` (for example "Wheelchair accessible"), so screen readers announce it as an image. `label` wins when both are set. Leave both off when nearby text already says the same thing: the icon is then decorative.
|
|
7382
|
+
- `name`: `AccessibilityIconName` (required). Accessibility icon to render.
|
|
7383
|
+
- Plus every native `<svg>` attribute (className, style, id, aria-*, data-*, event handlers), spread onto the root.
|
|
7384
|
+
|
|
7385
|
+
### Examples (Storybook stories)
|
|
7386
|
+
|
|
7387
|
+
- Playground
|
|
7388
|
+
- Gallery
|
|
7389
|
+
- Decorative vs Labeled
|
|
7390
|
+
- Sizes
|
|
7391
|
+
- All at 16px
|
|
7392
|
+
- Tones
|
|
7393
|
+
- Right to left
|
|
7394
|
+
- Translated
|
|
7395
|
+
- Example: venue access information
|
|
7396
|
+
- Example: video with access features
|
|
7397
|
+
- Checks
|
|
7398
|
+
|
|
7347
7399
|
## Button
|
|
7348
7400
|
|
|
7349
7401
|
import { Button } from "@vjdesigns/vjdesigns-ui";
|
|
@@ -7805,6 +7857,31 @@ Hides content visually while keeping it available to screen readers.
|
|
|
7805
7857
|
|
|
7806
7858
|
Decorative or labelled SVG icons, all with the same props as `Icon`: CheckIcon, CloseIcon, PlusIcon, MinusIcon, ChevronUpIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ArrowUpIcon, ArrowDownIcon, ArrowLeftIcon, ArrowRightIcon, ChevronsLeftIcon, ChevronsRightIcon, SearchIcon, MenuIcon, MoreHorizontalIcon, MoreVerticalIcon, InfoIcon, WarningIcon, ErrorIcon, SuccessIcon, HelpIcon, NoteIcon, OfflineIcon, EyeIcon, EyeOffIcon, CalendarIcon, ClockIcon, UploadIcon, DownloadIcon, TrashIcon, EditIcon, CopyIcon, ExternalLinkIcon, LinkIcon, HomeIcon, UserIcon, UsersIcon, SettingsIcon, BellIcon, StarIcon, StarFilledIcon, HeartIcon, HeartFilledIcon, FilterIcon, SortIcon, RefreshIcon, PauseIcon, PlayIcon, EyeDropperIcon, GripIcon, SunIcon, MoonIcon, LockIcon, MailIcon, FileIcon, FolderIcon, FolderOpenIcon, ImageIcon, LoaderIcon, FaceVerySadIcon, FaceSadIcon, FaceNeutralIcon, FaceHappyIcon, FaceVeryHappyIcon, ThumbsUpIcon, ThumbsDownIcon, VerifiedIcon, VolumeIcon, VolumeOffIcon, FullscreenIcon, FullscreenExitIcon, CaptionsIcon, PipIcon.
|
|
7807
7859
|
|
|
7860
|
+
## Accessibility icons
|
|
7861
|
+
|
|
7862
|
+
Icons for accessibility features and services. Each takes the same props as `AccessibilityIcon` without `name`, so `labeled` gives it a built-in, translated accessible name:
|
|
7863
|
+
|
|
7864
|
+
- `UniversalAccessIcon`: A person with open arms inside a circle, a widely used mark for accessibility in general: an accessibility menu, settings page, or statement. Built-in name: "Accessibility".
|
|
7865
|
+
- `WheelchairIcon`: A person in a wheelchair, leaning forward: a place, entrance, seat, or route that wheelchair users can use. Mirrors in right-to-left layouts. Built-in name: "Wheelchair accessible".
|
|
7866
|
+
- `RampIcon`: A ramp with an arrow: step-free access, an entrance or route without stairs. Mirrors in right-to-left layouts. Built-in name: "Step-free access".
|
|
7867
|
+
- `ElevatorIcon`: Lift doors with up and down arrows: an elevator or lift. Built-in name: "Elevator".
|
|
7868
|
+
- `BlindIcon`: A person walking with a long cane: services for blind and low-vision people, such as guided tours or tactile maps. Mirrors in right-to-left layouts. Built-in name: "Blind or low vision".
|
|
7869
|
+
- `BrailleIcon`: A braille cell with raised and flat dots: braille documents, labels, or signage. Built-in name: "Braille".
|
|
7870
|
+
- `AudioDescriptionIcon`: "AD" with a sound wave, the international mark for audio description: a narrated track describing what's on screen. Built-in name: "Audio description".
|
|
7871
|
+
- `ScreenReaderIcon`: A screen with text and sound waves: screen reader support, or content tested with screen readers. Built-in name: "Screen reader".
|
|
7872
|
+
- `HearingLoopIcon`: An ear with a "T": a hearing loop (induction loop) that hearing aids set to T can pick up. Built-in name: "Hearing loop".
|
|
7873
|
+
- `DeafIcon`: An ear with a line through it: services for Deaf and hard-of-hearing people. Built-in name: "Deaf or hard of hearing".
|
|
7874
|
+
- `SignLanguageIcon`: A signing hand with motion marks: sign language interpretation. Not tied to one sign language; say which (ASL, BSL, LSF, ...) in nearby text or `label`. Built-in name: "Sign language".
|
|
7875
|
+
- `TranscriptIcon`: A speech bubble with lines of text: a written transcript of audio or video. Built-in name: "Transcript".
|
|
7876
|
+
- `EasyReadIcon`: An open book: an easy-read version, written in plain language for people with learning or cognitive disabilities. Built-in name: "Easy read".
|
|
7877
|
+
- `TextSizeIcon`: A small and a large letter A: a text size setting. Built-in name: "Text size".
|
|
7878
|
+
- `HighContrastIcon`: A half-filled circle: a high-contrast setting or theme. Built-in name: "High contrast".
|
|
7879
|
+
- `ColorFiltersIcon`: Three overlapping circles: color filters or color-blindness settings. Built-in name: "Color filters".
|
|
7880
|
+
- `ReducedMotionIcon`: A wave settling into a flat line: a setting that reduces or turns off animation. Built-in name: "Reduced motion".
|
|
7881
|
+
- `KeyboardIcon`: A keyboard: full keyboard support, or keyboard shortcuts help. Built-in name: "Keyboard accessible".
|
|
7882
|
+
- `VoiceControlIcon`: A microphone: voice control or speech input. Built-in name: "Voice control".
|
|
7883
|
+
- `SwitchAccessIcon`: A large push button: switch access, for people who use one or two switches instead of a keyboard or pointer. Built-in name: "Switch access".
|
|
7884
|
+
|
|
7808
7885
|
# Hooks
|
|
7809
7886
|
|
|
7810
7887
|
## useResolvedElement
|