@beeq/react 1.8.0-beta.9 → 1.8.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/.babelrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@nx/react/babel",
5
+ {
6
+ "runtime": "automatic",
7
+ "useBuiltIns": "usage"
8
+ }
9
+ ]
10
+ ],
11
+ "plugins": []
12
+ }
package/README.md CHANGED
@@ -2,35 +2,90 @@
2
2
 
3
3
  A lightweight utility that wraps BEEQ custom elements ("web components") so they can be used like native React components.
4
4
 
5
+ ## Why is this necessary?
6
+
7
+ React and custom elements don't play nicely together. The problem is best described by [Custom Elements Everywhere](https://custom-elements-everywhere.com/#react):
8
+
9
+ > **Handling data**
10
+ >
11
+ > React passes all data to Custom Elements in the form of HTML attributes. For primitive data this is fine, but the system breaks down when passing rich data, like objects or arrays. In these instances you end up with stringified values like some-attr="[object Object]" which can't actually be used.
12
+ >
13
+ > **Handling events**
14
+ >
15
+ > Because React implements its own synthetic event system, it cannot listen for DOM events coming from Custom Elements without the use of a workaround. Developers will need to reference their Custom Elements using a ref and manually attach event listeners with addEventListener. This makes working with Custom Elements cumbersome.
16
+
17
+ This utility solves these problems by exposing a native React component that maps properties and events to the underlying custom element. ✨
18
+
5
19
  ## Package installation
6
20
 
21
+ > [!TIP]
22
+ > Please always refer to the [official BEEQ documentation](https://www.beeq.design/3d466e231/p/359a26-for-developers/b/28e01f) for more information about the installation.
23
+
7
24
  - install the package
8
25
 
9
26
  ```
10
- npm install @beeq/react
27
+ npm install @beeq/{core,react}
11
28
  ```
12
29
 
13
- - update the package
30
+ > [!NOTE]
31
+ > Make sure that you have installed the `@beeq/core` package.
32
+
33
+ ### Add BEEQ styles and assets
14
34
 
35
+ Import BEEQ styles into your application's main style file:
36
+
37
+ ```css
38
+ @import "@beeq/core/dist/beeq/beeq.css";
15
39
  ```
16
- npm install @beeq/react@latest
40
+
41
+ > [!TIP]
42
+ > BEEQ uses SVG icons and these assets are shipped in a separate folder. You can use the `setBasePath` method to set the path to the icons. Make sure that your project bundle the icons in a way that they are accessible from the browser.
43
+
44
+ You can move the icons from the node_modules folder to your assets folder and set the path like this:
45
+
46
+ ```js
47
+ // vite.config.js
48
+ import { defineConfig } from 'vite';
49
+ import { viteStaticCopy } from 'vite-plugin-static-copy';
50
+ import react from '@vitejs/plugin-react';
51
+
52
+ export default defineConfig({
53
+ plugins: [
54
+ react(),
55
+ viteStaticCopy({
56
+ targets: [
57
+ {
58
+ src: './node_modules/@beeq/core/dist/beeq/svg/*',
59
+ dest: 'icons/svg',
60
+ },
61
+ // add more targets if needed
62
+ ],
63
+ }),
64
+ ],
65
+ // other configurations
66
+ });
17
67
  ```
18
68
 
19
- if `@beeq/core` package is installed you should update both
69
+ ```js
70
+ // main.ts
71
+ import { setBasePath } from "@beeq/core/dist/components";
20
72
 
21
- ```
22
- npm install @beeq/{core,react}
73
+ setBasePath('icons/svg');
23
74
  ```
24
75
 
25
- ### Add BEEQ styles and assets
76
+ > Please, notice the path 👆
26
77
 
27
- Make sure that BEEQ main style is imported into your application's main style file:
78
+ But you can also use a different icons library or a CDN:
28
79
 
29
- ```css
30
- @import "@beeq/core/dist/beeq/beeq";
80
+ ```js
81
+ import { setBasePath } from "@beeq/core/dist/components";
82
+
83
+ // Using heroicons library
84
+ setBasePath('https://cdn.jsdelivr.net/npm/heroicons@2.1.5/24/outline');
31
85
  ```
32
86
 
33
- > ❗️The icons SVG are shipped in a separate folder. Depending on your React stack, your project will need to include `node_modules/@beeq/core/dist/beeq/svg` in the build in such a way that it respond to: `http://<domain>/svg`
87
+ > [!CAUTION]
88
+ > When using a different icons library, make sure you use the correct icon names provided by the library or the CDN.
34
89
 
35
90
  ## Usage
36
91
 
@@ -52,17 +107,3 @@ function App() {
52
107
 
53
108
  export default App;
54
109
  ```
55
-
56
- ## Why is this necessary?
57
-
58
- React and custom elements don't play nicely together. The problem is best described by [Custom Elements Everywhere](https://custom-elements-everywhere.com/#react):
59
-
60
- > **Handling data**
61
- >
62
- > React passes all data to Custom Elements in the form of HTML attributes. For primitive data this is fine, but the system breaks down when passing rich data, like objects or arrays. In these instances you end up with stringified values like some-attr="[object Object]" which can't actually be used.
63
- >
64
- > **Handling events**
65
- >
66
- > Because React implements its own synthetic event system, it cannot listen for DOM events coming from Custom Elements without the use of a workaround. Developers will need to reference their Custom Elements using a ref and manually attach event listeners with addEventListener. This makes working with Custom Elements cumbersome.
67
-
68
- This utility solves these problems by exposing a native React component that maps properties and events to the underlying custom element. ✨
@@ -0,0 +1,41 @@
1
+ const nxESLint = require('@nx/eslint-plugin');
2
+ const jsoncParser = require('jsonc-eslint-parser');
3
+ const tsESLint = require('typescript-eslint');
4
+
5
+ /** @type { import("eslint").Linter.Config[] } */
6
+ module.exports = [
7
+ ...tsESLint.configs.recommended,
8
+ {
9
+ languageOptions: {
10
+ parserOptions: {
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ rules: {
15
+ '@typescript-eslint/no-explicit-any': 'off',
16
+ },
17
+ },
18
+ {
19
+ files: ['**/package.json', '**/project.json'],
20
+ languageOptions: {
21
+ parser: jsoncParser,
22
+ },
23
+ plugins: {
24
+ '@nx': nxESLint,
25
+ },
26
+ rules: {
27
+ '@nx/dependency-checks': [
28
+ 'error',
29
+ {
30
+ ignoredDependencies: ['@beeq/core', '@stencil/react-output-target', 'react', 'react-dom'],
31
+ },
32
+ ],
33
+ },
34
+ },
35
+ {
36
+ files: ['**/*.js'],
37
+ rules: {
38
+ '@typescript-eslint/no-require-imports': 'off',
39
+ },
40
+ },
41
+ ];
package/jest.config.ts ADDED
@@ -0,0 +1,14 @@
1
+ export default {
2
+ displayName: 'beeq-react',
3
+ preset: '../../jest.preset.js',
4
+ globals: {
5
+ 'ts-jest': {
6
+ tsconfig: '<rootDir>/tsconfig.spec.json',
7
+ },
8
+ },
9
+ transform: {
10
+ '^.+\\.[tj]sx?$': 'ts-jest',
11
+ },
12
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
13
+ coverageDirectory: '../../coverage/packages/beeq-react',
14
+ };
package/package.json CHANGED
@@ -1,23 +1,22 @@
1
1
  {
2
- "name": "@beeq/react",
3
- "version": "1.8.0-beta.9",
4
- "license": "Apache-2.0",
5
- "description": "React specific wrapper for BEEQ Design System components",
6
- "main": "./src/index.js",
7
- "module": "./src/index.js",
8
- "types": "./src/index.d.ts",
9
- "dependencies": {
10
- "@beeq/core": "^1.8.0-beta.9",
11
- "@stencil/react-output-target": "^0.7.1"
12
- },
13
- "peerDependencies": {
14
- "react": ">=18.0.0",
15
- "react-dom": ">=18.0.0",
16
- "tslib": "^2.6.3"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "https://github.com/Endava/BEEQ"
21
- },
22
- "type": "module"
23
- }
2
+ "name": "@beeq/react",
3
+ "version": "1.8.0",
4
+ "license": "Apache-2.0",
5
+ "description": "React specific wrapper for BEEQ Design System components",
6
+ "main": "./src/index.js",
7
+ "module": "./src/index.js",
8
+ "types": "./src/index.d.ts",
9
+ "dependencies": {
10
+ "@beeq/core": "^1.8.0",
11
+ "@stencil/react-output-target": "^0.7.1"
12
+ },
13
+ "peerDependencies": {
14
+ "react": ">=18.0.0",
15
+ "react-dom": ">=18.0.0",
16
+ "tslib": "^2.6.3"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/Endava/BEEQ"
21
+ }
22
+ }
package/project.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "beeq-react",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "packages/beeq-react/src",
5
+ "projectType": "library",
6
+ "tags": ["wrapper", "react", "publishable"],
7
+ "implicitDependencies": ["beeq"],
8
+ "targets": {
9
+ "build": {
10
+ "executor": "@nx/js:tsc",
11
+ "options": {
12
+ "clean": true,
13
+ "main": "packages/beeq-react/src/index.ts",
14
+ "assets": ["packages/beeq-react/README.md"],
15
+ "outputPath": "dist/beeq-react",
16
+ "project": "packages/beeq-react/package.json",
17
+ "tsConfig": "packages/beeq-react/tsconfig.lib.json"
18
+ },
19
+ "dependsOn": [{ "dependencies": true, "target": "build" }]
20
+ },
21
+ "lint": {
22
+ "executor": "@nx/eslint:lint",
23
+ "options": {
24
+ "lintFilePatterns": ["{projectRoot}/**/*.ts", "{projectRoot}/package.json", "{projectRoot}/project.json"]
25
+ }
26
+ }
27
+ }
28
+ }