@synergy-design-system/react 1.16.0 → 1.17.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.
Files changed (2) hide show
  1. package/README.md +112 -11
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -19,14 +19,17 @@ npm install --save @synergy-design-system/react @synergy-design-system/tokens
19
19
 
20
20
  # Only if not already installed
21
21
  npm install --save react react-dom
22
+
23
+ # Optional: if icons shall be used, install the assets package
24
+ npm install --save @synergy-design-system/assets
22
25
  ```
23
26
 
24
- > ⚠️ Note we do **not** ship react in this package.
27
+ > ⚠️ Note we do **not** ship React in this package.
25
28
  > You will have to install React by yourself first!
26
29
 
27
- ### 2. Add the wanted theme to your application
30
+ ### 2. Add the desired theme to your application
28
31
 
29
- The components will not display correctly without the needed theme. Please include either light or dark theme in your application, for example in a newly installed vite React application:
32
+ The components will not display correctly without the needed theme. Please include either light or dark theme in your application, for example in a newly installed React application:
30
33
 
31
34
  ```tsx
32
35
  // main.tsx
@@ -46,23 +49,65 @@ createRoot(document.getElementById("root")!).render(
46
49
 
47
50
  ### 3. Importing and rendering components
48
51
 
49
- You may now use the components by importing them from the `@synergy-design-system/react` package and rendering them in a react component.
52
+ You may now use the components by importing them from the `@synergy-design-system/react` package and rendering them in a React component.
50
53
 
51
54
  ```tsx
52
55
  import { SynButton } from "@synergy-design-system/react";
53
56
 
54
- export const MyButton = () => (
55
- <SynButton type="button" variant="filled">
56
- SynButton Example
57
- </SynButton>
58
- );
57
+ export const MyButton = () => <SynButton type="submit">Submit me</SynButton>;
58
+ ```
59
+
60
+ ### 4. Usage of the components
61
+
62
+ All information about which components exist as well as the available properties, events and usage of a component, can be found at `components` in our [documentation](https://synergy-design-system.github.io/?path=/docs/components).
63
+ The documentation is written for no specific web framework but only vanilla html and javascript.
64
+
65
+ An example demo repository with the usage of the React wrapper components can be found [here](https://github.com/synergy-design-system/synergy-design-system/tree/main/packages/_private/react-demo).
66
+
67
+ The naming of the components for React changes from kebab-case to PascalCase.
68
+ `syn-button` becomes `SynButton`:
69
+
70
+ ```html
71
+ <!-- Webcomponents example -->
72
+ <syn-button> My Button </syn-button>
73
+ ```
74
+
75
+ ```tsx
76
+ // React wrapper example
77
+ <SynButton> My Button </SynButton>
78
+ ```
79
+
80
+ ### 5. Usage of attributes
81
+
82
+ The attribute namings of the components are the same as in the documentation.
83
+
84
+ ```html
85
+ <!-- Webcomponents example -->
86
+ <syn-input
87
+ label="Nickname"
88
+ help-text="What would you like people to call you?"
89
+ required
90
+ ></syn-input>
59
91
  ```
60
92
 
61
- ## 4. Using component events
93
+ ```tsx
94
+ // React wrapper example
95
+ <SynInput
96
+ label="Nickname"
97
+ help-text="What would you like people to call you?"
98
+ required
99
+ />
100
+ ```
101
+
102
+ ### 6. Usage of events
103
+
104
+ Custom events are named in the documentation as following: `syn-change`, `syn-clear`, ...
62
105
 
63
106
  This library makes use of [@lit/react](https://lit.dev/docs/frameworks/react/) to wrap the existing Synergy Web Components.
64
107
  All events will be automatically set up to work without the need to attach event listeners manually.
65
- Just use them with the default react `onEVENT` prefix, where `EVENT` is the camelCased name of the event.
108
+ Just use them with the default React `onEVENT` prefix, where `EVENT` is the camelCased name of the event:
109
+
110
+ `syn-change`-> `onSynChange`, `syn-clear`-> `onSynClear`, ...
66
111
 
67
112
  ```tsx
68
113
  import { SynButton } from "@synergy-design-system/react";
@@ -78,6 +123,62 @@ export const MyButton = () => (
78
123
  );
79
124
  ```
80
125
 
126
+ If typescript is used, you can get the correct types for components and events from the `@synergy-design-system/components` package.
127
+
128
+ The components from the React wrapper and the types of the components package are called the same. Therefore there must be a renaming of e.g. the types.
129
+
130
+ An example for how these types can be used in case of event, is shown below:
131
+
132
+ ```tsx
133
+ import { SynInput } from "@synergy-design-system/react";
134
+ import type {
135
+ SynInput as SynInputType,
136
+ SynChangeEvent,
137
+ } from "@synergy-design-system/components";
138
+
139
+ export const MyComponent = () => (
140
+ <SynInput
141
+ label="Surname"
142
+ onSynChange={(e: SynChangeEvent) => {
143
+ const input = e.target as SynInputType;
144
+ // Now we get access to all properties, methods etc. of the syn-input
145
+ const surname = input.value;
146
+ doSomething(surname);
147
+ }}
148
+ />
149
+ );
150
+ ```
151
+
152
+ ### 7. Usage of methods
153
+
154
+ Components can have methods (like `focus`, `click`, `stepUp`, etc. ), which can trigger an action, if they are called.
155
+
156
+ An example for calling such a method in a React component is shown here:
157
+
158
+ ```tsx
159
+ import { SynButton, SynInput } from "@synergy-design-system/react";
160
+ import type { SynInput as SynInputType } from "@synergy-design-system/components";
161
+ import { type FC, useRef } from "react";
162
+
163
+ export const Home: FC = () => {
164
+ const count = useRef<SynInputType>(null);
165
+
166
+ return (
167
+ <>
168
+ <SynInput ref={count} label="My count" type="number" value="5" />
169
+ <SynButton
170
+ onClick={() => {
171
+ // Increment the count via calling the method
172
+ count.current?.stepUp();
173
+ }}
174
+ >
175
+ Increment
176
+ </SynButton>
177
+ </>
178
+ );
179
+ };
180
+ ```
181
+
81
182
  ---
82
183
 
83
184
  ## Development
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "dependencies": {
7
7
  "@lit/react": "^1.0.3",
8
- "@synergy-design-system/components": "^1.16.0"
8
+ "@synergy-design-system/components": "^1.17.0"
9
9
  },
10
10
  "description": "React wrappers for the Synergy Design System",
11
11
  "exports": {
@@ -40,7 +40,7 @@
40
40
  "directory": "packages/react"
41
41
  },
42
42
  "type": "module",
43
- "version": "1.16.0",
43
+ "version": "1.17.0",
44
44
  "devDependencies": {
45
45
  "@types/react": "^18.2.55",
46
46
  "react": "^18.2.0"