Skip to content

Commit e035262

Browse files
authored
feat: add react-components package skeleton and generator (#13024)
1 parent f38b1b8 commit e035262

103 files changed

Lines changed: 3666 additions & 109 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/unit-tests.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,29 @@ jobs:
6969

7070
- name: Test
7171
run: yarn test:webkit
72+
react:
73+
name: React
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v7
77+
78+
- name: Setup Node
79+
uses: actions/setup-node@v6
80+
with:
81+
node-version: '24'
82+
cache: 'yarn'
83+
84+
- name: Install Dependencies
85+
run: yarn --frozen-lockfile --no-progress --non-interactive
86+
87+
- name: Build React packages
88+
run: yarn release:react
89+
90+
- name: Lint TypeScript
91+
run: yarn lint:types:react
92+
93+
- name: Check generated package.json is committed
94+
run: git diff --exit-code packages/react-components*/package.json
95+
96+
- name: Check package integrity
97+
run: node react/scripts/check-package.js

‎.gitignore‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ tsconfig.build.tsbuildinfo
4444
# API docs generated files
4545
api-docs/dist
4646
api-docs/content/elements
47+
48+
# React components generated sources and build output
49+
packages/react-components*/src/generated
50+
packages/react-components*/css
51+
packages/react-components*/generated
52+
packages/react-components*/renderers
53+
packages/react-components*/utils
54+
packages/react-components*/*.d.ts
55+
packages/react-components*/*.d.ts.map
56+
packages/react-components*/*.js
57+
packages/react-components*/*.js.map

‎CONVENTIONS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ Methods that return a boolean should use an interrogative prefix (`_should...`,
114114

115115
When adding files under `packages/`, `dev/`, or `test/`, name files using dash-case (e.g. `form-layout.types.ts`). Build scripts under `scripts/` are the exception and use camelCase.
116116

117+
The React packages under `packages/react-components*/` are an exception. Component files use the PascalCase component name (`Button.ts`, `GridColumn.tsx`), because the file name is the published import specifier (`@vaadin/react-components/Button.js`). Hooks and utilities use camelCase (`useRenderer.ts`, `createComponent.ts`).
118+
117119
## JSDoc
118120

119121
Documentation / JSDoc should describe the public contract and behavior, not internal implementation details on how the behavior is achieved.

‎eslint.config.js‎

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import prettier from 'eslint-config-vaadin/prettier';
2+
import react from 'eslint-config-vaadin/react';
23
import testing from 'eslint-config-vaadin/testing';
34
import typescript from 'eslint-config-vaadin/typescript';
45
import html from 'eslint-plugin-html';
@@ -28,7 +29,31 @@ const PRO_LICENSE_HEADER = `
2829
*/
2930
`;
3031

31-
const PRO_COMPONENTS = ['charts', 'board', 'crud', 'dashboard', 'grid-pro', 'rich-text-editor', 'map'];
32+
// The React wrappers were started in 2022 in the vaadin/react-components repo.
33+
const REACT_LICENSE_HEADER = LICENSE_HEADER.replace('2000 - ', '2022 - ');
34+
const REACT_PRO_LICENSE_HEADER = PRO_LICENSE_HEADER.replace('2000 - ', '2022 - ');
35+
36+
const PRO_COMPONENTS = [
37+
'charts',
38+
'board',
39+
'crud',
40+
'dashboard',
41+
'grid-pro',
42+
'rich-text-editor',
43+
'map',
44+
'react-components-pro',
45+
];
46+
47+
const REACT_FILES = ['packages/react-components*/**/*.{ts,tsx}', 'react/dev/**/*.tsx'];
48+
49+
/** Turns off every rule of the React preset whose name starts with the given plugin prefix. */
50+
const reactRulesOff = (prefix) =>
51+
Object.fromEntries(
52+
react
53+
.flatMap((config) => Object.keys(config.rules ?? {}))
54+
.filter((rule) => rule.startsWith(prefix))
55+
.map((rule) => [rule, 'off']),
56+
);
3257

3358
export default [
3459
{
@@ -40,10 +65,33 @@ export default [
4065
'packages/**/dist/*.js',
4166
'packages/**/test/dom/__snapshots__/*.snap.js',
4267
'packages/**/test/*.generated.test.js',
68+
'packages/react-components*/*.{js,d.ts,map}',
69+
'packages/react-components*/{generated,renderers,utils,css}/**',
70+
'packages/react-components*/src/generated/**',
4371
],
4472
},
4573
...typescript,
4674
...testing,
75+
...react.map((config) => ({ ...config, files: REACT_FILES })),
76+
{
77+
files: REACT_FILES,
78+
settings: {
79+
react: { version: '19' },
80+
},
81+
rules: {
82+
'react/jsx-no-literals': 'off', // Wrappers and tests render plain text
83+
'react/destructuring-assignment': 'off', // Wrappers forward props objects as is
84+
'react/jsx-pascal-case': 'off', // Generated components use web component class names
85+
'react/function-component-definition': 'off', // Wrappers use forwardRef with arrow functions
86+
'react/display-name': 'off', // Wrappers set no display name
87+
'react/no-this-in-sfc': 'off', // False positives in renderer callbacks
88+
'@typescript-eslint/no-empty-object-type': 'off', // Props types extend web component types
89+
'@typescript-eslint/explicit-module-boundary-types': 'off', // Return types are inferred from createComponent
90+
'@typescript-eslint/no-unsafe-function-type': 'off', // Event handler maps use Function
91+
'@typescript-eslint/consistent-type-assertions': 'off', // Ref and element casts are needed
92+
...reactRulesOff('react-perf/'), // Renderer props take inline JSX, functions, arrays and objects
93+
},
94+
},
4795
...prettier,
4896
{
4997
plugins: {
@@ -141,17 +189,29 @@ export default [
141189
},
142190
},
143191
{
144-
files: ['packages/*/src/**/*.{ts,js}'],
192+
files: ['packages/*/src/**/*.{ts,tsx,js}'],
145193
rules: {
146194
'custom-rules/license-header': ['error', { licenseHeader: LICENSE_HEADER }],
147195
},
148196
},
149197
{
150-
files: [`packages/@(${PRO_COMPONENTS.join('|')})/src/**/*.{ts,js}`],
198+
files: [`packages/@(${PRO_COMPONENTS.join('|')})/src/**/*.{ts,tsx,js}`],
151199
rules: {
152200
'custom-rules/license-header': ['error', { licenseHeader: PRO_LICENSE_HEADER }],
153201
},
154202
},
203+
{
204+
files: ['packages/react-components/src/**/*.{ts,tsx}'],
205+
rules: {
206+
'custom-rules/license-header': ['error', { licenseHeader: REACT_LICENSE_HEADER }],
207+
},
208+
},
209+
{
210+
files: ['packages/react-components-pro/src/**/*.{ts,tsx}'],
211+
rules: {
212+
'custom-rules/license-header': ['error', { licenseHeader: REACT_PRO_LICENSE_HEADER }],
213+
},
214+
},
155215
{
156216
files: [
157217
'scripts/**/*.js',
@@ -160,6 +220,9 @@ export default [
160220
'wtr-utils.js',
161221
'custom-rules/**/*.js',
162222
'api-docs/.eleventy.js',
223+
'react/scripts/**/*.{js,ts}',
224+
'react/*.ts',
225+
'react/dev/*.ts',
163226
],
164227
languageOptions: {
165228
globals: {
@@ -204,4 +267,17 @@ export default [
204267
],
205268
},
206269
},
270+
{
271+
files: ['packages/react-components*/test/**'],
272+
rules: {
273+
...reactRulesOff('jsx-a11y/'), // Test fixtures are not real UI
274+
'react/button-has-type': 'off',
275+
},
276+
},
277+
{
278+
files: ['packages/react-components*/test/typings/**'],
279+
rules: {
280+
'@typescript-eslint/no-unused-vars': 'off',
281+
},
282+
},
207283
];

‎lerna.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3-
"packages": ["test/*", "packages/*", "api-docs", "dev"],
3+
"packages": ["test/*", "packages/*", "api-docs", "dev", "react"],
44
"npmClient": "yarn",
55
"version": "25.4.0-alpha2"
66
}

‎package.json‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"api-docs:build": "yarn release:cem && yarn workspace api-docs generate ../custom-elements.json && yarn workspace api-docs build",
88
"api-docs:start": "yarn release:cem && yarn workspace api-docs generate ../custom-elements.json && yarn workspace api-docs start",
9+
"clean:react": "yarn workspace @vaadin/react-components clean",
910
"debug": "yarn test --watch",
1011
"debug:it": "yarn test --watch --config web-test-runner-it.config.js",
1112
"dev:build": "yarn workspace dev build",
@@ -14,10 +15,12 @@
1415
"lint:css": "stylelint --ignore-path .gitignore \"packages/**/src/**/*.js\" \"packages/vaadin-lumo-styles/mixins/*.js\" \"packages/**/*.css\" \"dev/**/*.html\"",
1516
"lint:js": "eslint",
1617
"lint:types": "tsc",
18+
"lint:types:react": "yarn workspace react-components-tooling lint:types",
1719
"postinstall": "patch-package",
1820
"prepare": "husky",
1921
"release": "yarn release:themes && yarn release:cem && yarn release:web-types",
2022
"release:cem": "custom-elements-manifest analyze --config custom-elements-manifest.config.js && node ./scripts/split-cem.js",
23+
"release:react": "yarn release:cem && yarn release:web-types && yarn workspace @vaadin/react-components build",
2124
"release:themes": "yarn workspace @vaadin/aura build && yarn workspace @vaadin/vaadin-lumo-styles build",
2225
"release:web-types": "node scripts/buildWebtypes.js",
2326
"start": "web-dev-server --node-resolve --open /dev",
@@ -76,7 +79,7 @@
7679
"playwright": "~1.63.0"
7780
},
7881
"lint-staged": {
79-
"*.{js,ts}": [
82+
"*.{js,ts,tsx}": [
8083
"eslint --fix",
8184
"prettier --write"
8285
],
@@ -89,6 +92,7 @@
8992
"test/*",
9093
"packages/*",
9194
"api-docs",
92-
"dev"
95+
"dev",
96+
"react"
9397
]
9498
}

0 commit comments

Comments
 (0)