@vjdesigns/vjdesigns-ui 3.8.0 → 3.8.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 +4 -0
- package/LICENSE +1 -1
- package/README.md +854 -854
- package/dist/ai/llms-full.txt +576 -576
- package/dist/ai/registry.json +6 -6
- package/dist/components/data-display/Poll/Poll.module.css.cjs.js +1 -1
- package/dist/components/data-display/Poll/Poll.module.css.mjs +1 -1
- 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.8.
|
|
1
|
+
# @vjdesigns/vjdesigns-ui 3.8.1: 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
|