|
| 1 | +# React |
| 2 | + |
| 3 | +We offer a |
| 4 | +[dedicated npm package for React](https://www.npmjs.com/package/@six-group/ui-library-react) to |
| 5 | +simplify the use of our web components. Find detailed steps in this guide to learn how to use it. |
| 6 | + |
| 7 | +For more detailed usage examples, check the |
| 8 | +[React demo](https://six-group.github.io/six-webcomponents/demo/react) and its |
| 9 | +[source code](https://github.com/six-group/six-webcomponents/tree/main/examples/react). |
| 10 | + |
| 11 | +## Setup |
| 12 | + |
| 13 | +This installation guide assumes you are using [Vite](https://vitejs.dev/) as your build tool and |
| 14 | +[React Router](https://reactrouter.com/) as your dedicated React framework. |
| 15 | + |
| 16 | +1. Install both the web components and React library: |
| 17 | + |
| 18 | + ```bash |
| 19 | + npm install @six-group/ui-library |
| 20 | + npm install @six-group/ui-library-react |
| 21 | + ``` |
| 22 | + |
| 23 | +2. In your main.tsx file, import the styles: |
| 24 | + |
| 25 | + ```ts |
| 26 | + import '@six-group/ui-library/dist/ui-library/ui-library.css'; |
| 27 | + ``` |
| 28 | + |
| 29 | +## Using the Components |
| 30 | + |
| 31 | +The components can be used just like any other React component. |
| 32 | + |
| 33 | +1. Import the component with an import statement like this |
| 34 | + |
| 35 | + ```ts |
| 36 | + import { SixMenuItem } from '@six-group/ui-library-react'; |
| 37 | + ``` |
| 38 | + |
| 39 | +2. Use it in the template |
| 40 | + |
| 41 | + ```html |
| 42 | + <SixMenuItem value="logout">Logout</SixMenuItem> |
| 43 | + ``` |
| 44 | + |
| 45 | +## Router |
| 46 | + |
| 47 | +If you are using `react-router` and want to use `NavLink` attributes on the web components |
| 48 | + |
| 49 | +```ts |
| 50 | +import { NavLink } from 'react-router'; |
| 51 | +``` |
| 52 | + |
| 53 | +You can then use `router-link` on any component from the library like this: |
| 54 | + |
| 55 | +```ts |
| 56 | +const getLinkClassName = ({ isActive }: { isActive: boolean }) => |
| 57 | + `${styles[isActive ? 'active-link' : 'link']}`; |
| 58 | +``` |
| 59 | + |
| 60 | +```html |
| 61 | +<NavLink to={'/'} className={getLinkClassName}> |
| 62 | + <SixSidebarItemGroup name="Home" icon="home" /> |
| 63 | +</NavLink> |
| 64 | +``` |
| 65 | + |
| 66 | +## Forms |
| 67 | + |
| 68 | +If you want to use the web components in a form, you can check out the example in the React example |
| 69 | +app. We are not using any form library, but there are some good form libraries out there. Following |
| 70 | +a list of libraries, you can check out and which we recommend as a starting point: |
| 71 | + |
| 72 | +- [react-hook-form](https://react-hook-form.com/) |
| 73 | +- [tanstack-form](https://tanstack.com/form/latest/docs/overview) |
| 74 | + |
| 75 | +### Error Message Translations |
| 76 | + |
| 77 | +For proper translation, set the lang attribute on the `html` element. Languages available are `en`, |
| 78 | +`de`, `it`, and `fr`. |
0 commit comments