@mrcaktuz/sds-react 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +421 -2
- package/dist/grid.cjs +15699 -0
- package/dist/grid.d.cts +43 -0
- package/dist/grid.d.ts +43 -0
- package/dist/grid.js +15653 -0
- package/dist/index.cjs +259 -0
- package/dist/index.d.cts +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +232 -0
- package/package.json +48 -3
package/README.md
CHANGED
|
@@ -1,3 +1,422 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mrcaktuz/sds-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Synerglass Design System — React components, styled on import.
|
|
4
|
+
Usable in a React project (Vite, Next.js) and in a **Vaadin Flow** application through React adapters (see [Usage in Vaadin](#usage-in-vaadin)).
|
|
5
|
+
|
|
6
|
+
> **Vaadin version for this release: `25.3.6`**
|
|
7
|
+
> Built and tested with `@vaadin/react-components` `25.3.6` (peer dependency `~25.3.6`: patches `25.3.x` accepted).
|
|
8
|
+
> In a Vaadin application, set `<vaadin.version>25.3.6</vaadin.version>` in the `pom.xml` (see [Versions](#versions)).
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i @mrcaktuz/sds-react
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Peer dependencies, provided by the host project:
|
|
17
|
+
|
|
18
|
+
| Package | Version | Needed for |
|
|
19
|
+
| -------------------------- | --------- | ------------------------------------------------------------------------------ |
|
|
20
|
+
| `react`, `react-dom` | `^19` | Every component |
|
|
21
|
+
| `@vaadin/react-components` | `~25.3.6` | The `/grid` entry only. In a Vaadin app, the version comes from the `pom.xml` |
|
|
22
|
+
|
|
23
|
+
npm (v7+) and pnpm install peer dependencies automatically; Yarn needs them added by hand.
|
|
24
|
+
|
|
25
|
+
## Entries
|
|
26
|
+
|
|
27
|
+
| Import | Components | Server-side rendering |
|
|
28
|
+
| --------------------------- | ----------------------------------------- | --------------------- |
|
|
29
|
+
| `@mrcaktuz/sds-react` | `SDSButton`, `SDSInput`, `SDSPagination` | Safe |
|
|
30
|
+
| `@mrcaktuz/sds-react/grid` | `SDSGrid` and its columns (Vaadin based) | **Browser only** |
|
|
31
|
+
|
|
32
|
+
The Vaadin-based components register custom elements as soon as they are imported, which crashes in Node.js.
|
|
33
|
+
That is why they live in a separate entry: importing the main entry never loads Vaadin.
|
|
34
|
+
|
|
35
|
+
## Styles
|
|
36
|
+
|
|
37
|
+
- **Importing a component is enough**: its CSS (`@mrcaktuz/sds-styles`) is imported by the component itself and loaded by the host bundler (Vite in Vaadin). No stylesheet to import by hand.
|
|
38
|
+
- The CSS is global (no Shadow DOM): it applies to the components rendered by a Vaadin `ReactAdapterElement`.
|
|
39
|
+
- Colors come from the SDS tokens (`--sds-c-*`), in light and dark.
|
|
40
|
+
|
|
41
|
+
### Light / dark theme
|
|
42
|
+
|
|
43
|
+
| `<html>` tag | Theme |
|
|
44
|
+
| ------------------------------------------- | -------------------------- |
|
|
45
|
+
| no attribute | OS preference |
|
|
46
|
+
| `theme="dark"` or `data-theme="dark"` | dark, whatever the OS |
|
|
47
|
+
| `theme="light"` or `data-theme="light"` | light, whatever the OS |
|
|
48
|
+
| `theme="dark compact"` (several values) | dark |
|
|
49
|
+
|
|
50
|
+
`theme` is the attribute of the Vaadin Lumo theme: **when the Vaadin application switches to dark, the DS components follow**.
|
|
51
|
+
|
|
52
|
+
```java
|
|
53
|
+
// Force dark
|
|
54
|
+
UI.getCurrent().getElement().executeJs("document.documentElement.setAttribute('theme', 'dark')");
|
|
55
|
+
// Back to the OS preference
|
|
56
|
+
UI.getCurrent().getElement().executeJs("document.documentElement.removeAttribute('theme')");
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The components only follow the theme: the application still manages its own background and texts.
|
|
60
|
+
|
|
61
|
+
## Components
|
|
62
|
+
|
|
63
|
+
### SDSButton
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { SDSButton } from '@mrcaktuz/sds-react';
|
|
67
|
+
|
|
68
|
+
<SDSButton onClick={save}>Save</SDSButton>
|
|
69
|
+
<SDSButton variant="outline" color="brand">Cancel</SDSButton>
|
|
70
|
+
<SDSButton variant="ghost" color="danger" icon={<TrashIcon />} iconOnly aria-label="Delete" />
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Prop | Type | Default | Description |
|
|
74
|
+
| -------------- | ----------------------------------------------------------- | ----------- | ------------------------------------------- |
|
|
75
|
+
| `variant` | `"primary"` \| `"outline"` \| `"ghost"` | `"primary"` | Visual variant |
|
|
76
|
+
| `color` | `"brand"` \| `"gray"` \| `"success"` \| `"warning"` \| `"danger"` | `"brand"` | Required with a non-default `variant` |
|
|
77
|
+
| `small` | `boolean` | `false` | Smaller padding |
|
|
78
|
+
| `icon` | `ReactNode` | — | SVG icon |
|
|
79
|
+
| `iconPosition` | `"left"` \| `"right"` | `"left"` | |
|
|
80
|
+
| `iconOnly` | `boolean` | `false` | Hides the text: set `aria-label` |
|
|
81
|
+
| other props | `<button>` attributes | — | `onClick`, `disabled`, `type`… |
|
|
82
|
+
|
|
83
|
+
Combinations outside of the design system are rejected at compile time.
|
|
84
|
+
|
|
85
|
+
### SDSInput
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { SDSInput } from '@mrcaktuz/sds-react';
|
|
89
|
+
|
|
90
|
+
<SDSInput
|
|
91
|
+
label="E-mail"
|
|
92
|
+
type="email"
|
|
93
|
+
value="jean.dupont@synerglass.com"
|
|
94
|
+
onBlur={(value) => validate(value)}
|
|
95
|
+
/>
|
|
96
|
+
<SDSInput label="E-mail" status="error" message="Invalid address" />
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
| Prop | Type | Default | Description |
|
|
100
|
+
| ------------- | ------------------------------------------------------------------------------------------ | ----------- | --------------------------------------------------------- |
|
|
101
|
+
| `id` | `string` | generated | HTML id of the `<input>`, also links the label |
|
|
102
|
+
| `type` | `"text"` \| `"email"` \| `"password"` \| `"number"` \| `"tel"` \| `"url"` \| `"search"` \| `"date"` | `"text"` | |
|
|
103
|
+
| `label` | `string` | — | Not displayed when missing |
|
|
104
|
+
| `placeholder` | `string` | — | |
|
|
105
|
+
| `value` | `string` | `""` | Fills the field; every new value replaces its content |
|
|
106
|
+
| `status` | `"default"` \| `"error"` \| `"success"` | `"default"` | Border, icon and message colors |
|
|
107
|
+
| `message` | `string` | — | Shown only with the `error` and `success` statuses |
|
|
108
|
+
| `onChange` | `(value: string, event) => void` | — | On each keystroke |
|
|
109
|
+
| `onBlur` | `(value: string, event) => void` | — | When the field loses focus |
|
|
110
|
+
|
|
111
|
+
- The callbacks receive the value first: no need to read `event.target.value`.
|
|
112
|
+
- **No validation inside the component**: the host sets `status` and `message`.
|
|
113
|
+
- Prefer `onBlur` to `onChange` to limit server round trips.
|
|
114
|
+
|
|
115
|
+
### SDSPagination
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import { SDSPagination } from '@mrcaktuz/sds-react';
|
|
119
|
+
|
|
120
|
+
<SDSPagination page={page} pageSize={15} totalItems={total} onPageChange={setPage} />
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Prop | Type | Default | Description |
|
|
124
|
+
| ------------------ | ------------------------------------------ | ------------------- | ------------------------------- |
|
|
125
|
+
| `page` | `number` | — | Current page, starting at 1 |
|
|
126
|
+
| `pageSize` | `number` | — | |
|
|
127
|
+
| `totalItems` | `number` | — | |
|
|
128
|
+
| `onPageChange` | `(page: number) => void` | — | |
|
|
129
|
+
| `onPageSizeChange` | `(pageSize: number) => void` | — | |
|
|
130
|
+
| `showRowsPerPage` | `boolean` | `true` | "Rows per page" selector |
|
|
131
|
+
| `pageSizeOptions` | `number[]` | `[15, 30, 50]` | |
|
|
132
|
+
| `resultsSummary` | `(from, to, total) => string` | `"1–15 sur 100"` | |
|
|
133
|
+
|
|
134
|
+
### SDSGrid (`/grid` entry)
|
|
135
|
+
|
|
136
|
+
The official Vaadin Grid, themed with the SDS tokens. Same API as the Vaadin `Grid` and columns.
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { SDSGrid, SDSGridColumn, SDSGridSortColumn } from '@mrcaktuz/sds-react/grid';
|
|
140
|
+
|
|
141
|
+
<SDSGrid items={users} stripes>
|
|
142
|
+
<SDSGridSortColumn path="name" header="Name" />
|
|
143
|
+
<SDSGridColumn path="email" header="E-mail" />
|
|
144
|
+
</SDSGrid>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
| Prop | Type | Default | Description |
|
|
148
|
+
| --------------- | --------- | ------- | --------------------------------- |
|
|
149
|
+
| `stripes` | `boolean` | `false` | Background on every other row |
|
|
150
|
+
| `columnBorders` | `boolean` | `false` | Vertical borders between columns |
|
|
151
|
+
| `noBorder` | `boolean` | `false` | No outer border nor radius |
|
|
152
|
+
| other props | Vaadin `GridProps` | — | `items`, `dataProvider`, `allRowsVisible`… |
|
|
153
|
+
|
|
154
|
+
Columns: `SDSGridColumn`, `SDSGridSortColumn`, `SDSGridFilterColumn`, `SDSGridSelectionColumn` (the Vaadin columns).
|
|
155
|
+
The SDS theme is scoped to the `sds-grid` class: native Vaadin grids on the same screen keep their own style.
|
|
156
|
+
|
|
157
|
+
## Usage in Vaadin
|
|
158
|
+
|
|
159
|
+
Vaadin Flow (24.4+) integrates React components with a `ReactAdapterElement` (TypeScript, in `src/main/frontend/`) and a `ReactAdapterComponent` (Java).
|
|
160
|
+
The DS publishes the React components; **the adapters and Java classes are written in the Vaadin project**.
|
|
161
|
+
|
|
162
|
+
### Versions
|
|
163
|
+
|
|
164
|
+
**The DS decides the Vaadin version**: each release of this package states the Vaadin version it requires (`@vaadin/react-components` peer dependency).
|
|
165
|
+
In a Vaadin application, the `pom.xml` sets the version of every `@vaadin/*` package: if it differs, the application version wins and the grid theme may break silently.
|
|
166
|
+
|
|
167
|
+
On each DS release, update both in **the same pull request**:
|
|
168
|
+
|
|
169
|
+
```xml
|
|
170
|
+
<vaadin.version>25.3.6</vaadin.version> <!-- must match the DS release notes -->
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
```java
|
|
174
|
+
public final class SdsVersion {
|
|
175
|
+
public static final String PACKAGE = "@mrcaktuz/sds-react";
|
|
176
|
+
public static final String VERSION = "0.1.0"; // the only line to change on each DS release
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Rules
|
|
181
|
+
|
|
182
|
+
- **Import everything from this package**, never `@vaadin/*` directly, and the grid from the `/grid` entry.
|
|
183
|
+
- **State and event names must be identical in TypeScript and Java**: a typo fails silently. The tables below are the contract.
|
|
184
|
+
- **Data goes through JSON**: `setState` values must be serializable (records, simple beans). One page at a time, not thousands of rows. No Java component inside a grid cell.
|
|
185
|
+
- **Free Vaadin components only** (no Grid Pro, Charts…).
|
|
186
|
+
- Custom element tags use the `synerds-` prefix: `sds-*` tags are already used by the DS.
|
|
187
|
+
|
|
188
|
+
How the React props map to Vaadin:
|
|
189
|
+
|
|
190
|
+
| React prop | Vaadin side |
|
|
191
|
+
| ---------------------------------------------- | ------------------------------------------------------------------- |
|
|
192
|
+
| Data (`label`, `value`, `status`, `items`…) | Synchronized state: `setState(...)` / `getState(...)` |
|
|
193
|
+
| Input (`onChange` of `SDSInput`) | `value` state updated → `addStateChangeListener("value", ...)` |
|
|
194
|
+
| Actions (`onBlur`, `onClick`) | Custom event → `getElement().addEventListener(...)` |
|
|
195
|
+
|
|
196
|
+
### SDSInput
|
|
197
|
+
|
|
198
|
+
| Tag | States | Events |
|
|
199
|
+
| --------------- | ----------------------------------------------------------------------- | ----------------------------------- |
|
|
200
|
+
| `synerds-input` | `inputId`, `value`, `label`, `placeholder`, `type`, `status`, `message` | `synerds-blur` (detail: the value) |
|
|
201
|
+
|
|
202
|
+
`src/main/frontend/synerds-input.tsx`:
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
import type { ReactElement } from 'react';
|
|
206
|
+
import { ReactAdapterElement, type RenderHooks } from 'Frontend/generated/flow/ReactAdapter';
|
|
207
|
+
import { SDSInput, type SDSInputStatus, type SDSInputType } from '@mrcaktuz/sds-react';
|
|
208
|
+
|
|
209
|
+
class SynerDsInputElement extends ReactAdapterElement {
|
|
210
|
+
protected override render(hooks: RenderHooks): ReactElement | null {
|
|
211
|
+
const [inputId] = hooks.useState<string>('inputId');
|
|
212
|
+
const [value, setValue] = hooks.useState<string>('value');
|
|
213
|
+
const [label] = hooks.useState<string>('label');
|
|
214
|
+
const [placeholder] = hooks.useState<string>('placeholder');
|
|
215
|
+
const [type] = hooks.useState<SDSInputType>('type');
|
|
216
|
+
const [status] = hooks.useState<SDSInputStatus>('status');
|
|
217
|
+
const [message] = hooks.useState<string>('message');
|
|
218
|
+
const dispatchBlur = hooks.useCustomEvent<string>('synerds-blur');
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<SDSInput
|
|
222
|
+
id={inputId}
|
|
223
|
+
label={label}
|
|
224
|
+
placeholder={placeholder}
|
|
225
|
+
type={type}
|
|
226
|
+
status={status}
|
|
227
|
+
message={message}
|
|
228
|
+
value={value}
|
|
229
|
+
onChange={(v) => setValue(v)}
|
|
230
|
+
onBlur={(v) => dispatchBlur(v)}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
customElements.define('synerds-input', SynerDsInputElement);
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
`SynerDsInput.java`:
|
|
240
|
+
|
|
241
|
+
```java
|
|
242
|
+
@Tag("synerds-input")
|
|
243
|
+
@NpmPackage(value = SdsVersion.PACKAGE, version = SdsVersion.VERSION)
|
|
244
|
+
@JsModule("./synerds-input.tsx")
|
|
245
|
+
public class SynerDsInput extends ReactAdapterComponent {
|
|
246
|
+
|
|
247
|
+
public SynerDsInput(String label) {
|
|
248
|
+
setLabel(label);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public void setInputId(String id) { setState("inputId", id); } // id of the <input> (not setId of the component)
|
|
252
|
+
public void setLabel(String label) { setState("label", label); }
|
|
253
|
+
public void setPlaceholder(String placeholder) { setState("placeholder", placeholder); }
|
|
254
|
+
public void setType(String type) { setState("type", type); } // "text", "email", "password"...
|
|
255
|
+
|
|
256
|
+
public String getValue() { return getState("value", String.class); }
|
|
257
|
+
public void setValue(String value) { setState("value", value); }
|
|
258
|
+
|
|
259
|
+
public void setError(String message) { setState("status", "error"); setState("message", message); }
|
|
260
|
+
public void setSuccess(String message) { setState("status", "success"); setState("message", message); }
|
|
261
|
+
public void clearStatus() { setState("status", "default"); setState("message", null); }
|
|
262
|
+
|
|
263
|
+
/** On each keystroke (the value is synchronized automatically) */
|
|
264
|
+
public void addValueChangeListener(Consumer<String> listener) {
|
|
265
|
+
addStateChangeListener("value", String.class, listener);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** When the field loses focus */
|
|
269
|
+
public void addBlurListener(Consumer<String> listener) {
|
|
270
|
+
getElement().addEventListener("synerds-blur", e -> listener.accept(e.getEventData().getString("event.detail")))
|
|
271
|
+
.addEventData("event.detail");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### SDSButton
|
|
277
|
+
|
|
278
|
+
| Tag | States | Events |
|
|
279
|
+
| ---------------- | --------------------------------------- | --------------- |
|
|
280
|
+
| `synerds-button` | `text`, `variant`, `color`, `disabled` | `synerds-click` |
|
|
281
|
+
|
|
282
|
+
`src/main/frontend/synerds-button.tsx`:
|
|
283
|
+
|
|
284
|
+
```tsx
|
|
285
|
+
import type { ReactElement } from 'react';
|
|
286
|
+
import { ReactAdapterElement, type RenderHooks } from 'Frontend/generated/flow/ReactAdapter';
|
|
287
|
+
import { SDSButton, type SDSButtonProps } from '@mrcaktuz/sds-react';
|
|
288
|
+
|
|
289
|
+
class SynerDsButtonElement extends ReactAdapterElement {
|
|
290
|
+
protected override render(hooks: RenderHooks): ReactElement | null {
|
|
291
|
+
const [text] = hooks.useState<string>('text');
|
|
292
|
+
const [variant] = hooks.useState<string>('variant');
|
|
293
|
+
const [color] = hooks.useState<string>('color');
|
|
294
|
+
const [disabled] = hooks.useState<boolean>('disabled');
|
|
295
|
+
const dispatchClick = hooks.useCustomEvent<void>('synerds-click');
|
|
296
|
+
|
|
297
|
+
// variant/color come from Java as strings: the allowed pairs are listed in the SDSButton table
|
|
298
|
+
const appearance = { variant: variant ?? 'primary', color: color ?? 'brand' } as SDSButtonProps;
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<SDSButton {...appearance} disabled={disabled} onClick={() => dispatchClick()}>
|
|
302
|
+
{text}
|
|
303
|
+
</SDSButton>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
customElements.define('synerds-button', SynerDsButtonElement);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
`SynerDsButton.java`:
|
|
312
|
+
|
|
313
|
+
```java
|
|
314
|
+
@Tag("synerds-button")
|
|
315
|
+
@NpmPackage(value = SdsVersion.PACKAGE, version = SdsVersion.VERSION)
|
|
316
|
+
@JsModule("./synerds-button.tsx")
|
|
317
|
+
public class SynerDsButton extends ReactAdapterComponent {
|
|
318
|
+
|
|
319
|
+
public SynerDsButton(String text) {
|
|
320
|
+
setText(text);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
public void setText(String text) { setState("text", text); }
|
|
324
|
+
/** variant: "primary", "outline", "ghost"; color: "brand", "gray", "success", "warning", "danger" */
|
|
325
|
+
public void setAppearance(String variant, String color) {
|
|
326
|
+
setState("variant", variant);
|
|
327
|
+
setState("color", color);
|
|
328
|
+
}
|
|
329
|
+
public void setDisabled(boolean disabled) { setState("disabled", disabled); }
|
|
330
|
+
|
|
331
|
+
public void addClickListener(Runnable listener) {
|
|
332
|
+
getElement().addEventListener("synerds-click", e -> listener.run());
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### SDSGrid
|
|
338
|
+
|
|
339
|
+
| Tag | States | Events |
|
|
340
|
+
| -------------- | ---------------------------------------------------- | ------ |
|
|
341
|
+
| `synerds-grid` | `columns` (`{ path, header }[]`), `items` (objects) | — |
|
|
342
|
+
|
|
343
|
+
`src/main/frontend/synerds-grid.tsx`:
|
|
344
|
+
|
|
345
|
+
```tsx
|
|
346
|
+
import type { ReactElement } from 'react';
|
|
347
|
+
import { ReactAdapterElement, type RenderHooks } from 'Frontend/generated/flow/ReactAdapter';
|
|
348
|
+
import { SDSGrid, SDSGridColumn } from '@mrcaktuz/sds-react/grid';
|
|
349
|
+
|
|
350
|
+
type Column = { path: string; header: string };
|
|
351
|
+
|
|
352
|
+
class SynerDsGridElement extends ReactAdapterElement {
|
|
353
|
+
protected override render(hooks: RenderHooks): ReactElement | null {
|
|
354
|
+
const [columns] = hooks.useState<Column[]>('columns');
|
|
355
|
+
const [items] = hooks.useState<object[]>('items');
|
|
356
|
+
|
|
357
|
+
return (
|
|
358
|
+
<SDSGrid items={items ?? []} allRowsVisible>
|
|
359
|
+
{(columns ?? []).map((c) => (
|
|
360
|
+
<SDSGridColumn key={c.path} path={c.path} header={c.header} />
|
|
361
|
+
))}
|
|
362
|
+
</SDSGrid>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
customElements.define('synerds-grid', SynerDsGridElement);
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
`SynerDsGrid.java`:
|
|
371
|
+
|
|
372
|
+
```java
|
|
373
|
+
@Tag("synerds-grid")
|
|
374
|
+
@NpmPackage(value = SdsVersion.PACKAGE, version = SdsVersion.VERSION)
|
|
375
|
+
@JsModule("./synerds-grid.tsx")
|
|
376
|
+
public class SynerDsGrid<T> extends ReactAdapterComponent {
|
|
377
|
+
public record Column(String path, String header) {}
|
|
378
|
+
|
|
379
|
+
public void setColumns(List<Column> columns) { setState("columns", columns); }
|
|
380
|
+
public void setItems(List<T> items) { setState("items", items); }
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### In a view
|
|
385
|
+
|
|
386
|
+
```java
|
|
387
|
+
SynerDsInput email = new SynerDsInput("E-mail");
|
|
388
|
+
email.setType("email");
|
|
389
|
+
email.addBlurListener(value -> {
|
|
390
|
+
if (value.contains("@")) email.setSuccess("Valid address");
|
|
391
|
+
else email.setError("Invalid address");
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
SynerDsButton save = new SynerDsButton("Save");
|
|
395
|
+
save.addClickListener(() -> Notification.show("Saved"));
|
|
396
|
+
|
|
397
|
+
SynerDsGrid<Person> grid = new SynerDsGrid<>();
|
|
398
|
+
grid.setColumns(List.of(new SynerDsGrid.Column("name", "Name"), new SynerDsGrid.Column("email", "E-mail")));
|
|
399
|
+
grid.setItems(personService.findPage(0, 15));
|
|
400
|
+
|
|
401
|
+
add(email, save, grid);
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Checks after an upgrade
|
|
405
|
+
|
|
406
|
+
- Only one version of `@vaadin/grid` in the `node_modules` of the Vaadin project, and only one loaded in the page.
|
|
407
|
+
- A native Java `Grid` on the same screen keeps its original style.
|
|
408
|
+
- The dark theme works with the Vaadin theme actually used by the application.
|
|
409
|
+
|
|
410
|
+
## Usage in Next.js
|
|
411
|
+
|
|
412
|
+
The main entry is safe with server-side rendering. The `/grid` components must be loaded in the browser only:
|
|
413
|
+
|
|
414
|
+
```tsx
|
|
415
|
+
'use client';
|
|
416
|
+
import dynamic from 'next/dynamic';
|
|
417
|
+
|
|
418
|
+
const UsersTable = dynamic(() => import('./UsersTable'), {
|
|
419
|
+
ssr: false,
|
|
420
|
+
loading: () => <div style={{ minHeight: 480 }} aria-busy="true" />, // reserve space to avoid layout shift
|
|
421
|
+
});
|
|
422
|
+
```
|