@scania/tegel 0.0.1-beta.5 → 0.0.1-beta.6

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/package.json +2 -2
  2. package/readme.md +135 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scania/tegel",
3
- "version": "0.0.1-beta.5",
3
+ "version": "0.0.1-beta.6",
4
4
  "description": "Tegel - Scania's Digital Design System",
5
5
  "keywords": [
6
6
  "tegel",
@@ -18,7 +18,7 @@
18
18
  "es2017": "dist/esm/index.mjs",
19
19
  "types": "dist/types/index.d.ts",
20
20
  "collection": "dist/collection/collection-manifest.json",
21
- "collection:main": "./dist/index.cjs.js",
21
+ "collection:main": "dist/collection/index.js",
22
22
  "unpkg": "dist/components/components.esm.js",
23
23
  "repository": {
24
24
  "type": "git",
package/readme.md CHANGED
@@ -15,6 +15,141 @@ Check out [Tegel Design System](https://tegel.scania.com/) for implementation an
15
15
 
16
16
  - Installation: [https://tegel.scania.com/development/getting-started-development/installation](https://tegel.scania.com/development/getting-started-development/installation)
17
17
 
18
+ ## React
19
+
20
+ ### Typescript
21
+
22
+ 1. Run `npm install @scania/tegel`
23
+ 2. src folder create a file called `register-webcomponents.ts`
24
+ 3. Paste the following into that file:
25
+ ```ts
26
+ import { defineCustomElements, JSX as LocalJSX } from '@scania/tegel/loader';
27
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
28
+
29
+ type StencilProps<T> = {
30
+ [P in keyof T]?: Omit<T[P], 'ref'> | HTMLAttributes<T>;
31
+ };
32
+
33
+ type ReactProps<T> = {
34
+ [P in keyof T]?: DetailedHTMLProps<HTMLAttributes<T[P]>, T[P]>;
35
+ };
36
+
37
+ type StencilToReact<T = LocalJSX.IntrinsicElements, U = HTMLElementTagNameMap> = StencilProps<T> &
38
+ ReactProps<U>;
39
+
40
+ declare global {
41
+ export namespace JSX {
42
+ interface IntrinsicElements extends StencilToReact { }
43
+ }
44
+ }
45
+
46
+ defineCustomElements(window)
47
+ ```
48
+ 4. In your index.tsx import `register-webcomponents.ts`
49
+ ```tsx
50
+ import React from 'react';
51
+ import ReactDOM from 'react-dom/client';
52
+ import './index.css';
53
+ import App from './App';
54
+ import reportWebVitals from './reportWebVitals';
55
+ import './register-webcomponents';
56
+
57
+ const root = ReactDOM.createRoot(
58
+ document.getElementById('root') as HTMLElement
59
+ );
60
+ root.render(
61
+ <React.StrictMode>
62
+ <App />
63
+ </React.StrictMode>
64
+ );
65
+
66
+ reportWebVitals();
67
+ ```
68
+ 5. In your global css file (usually `App.css`) import the tegel stylesheet.
69
+ ```css
70
+ @import url('@scania/tegel/dist/tegel/tegel.css');
71
+ ```
72
+
73
+ ### Javascript
74
+ 1. Run `npm install @scania/tegel`
75
+ 2. In your index.jsx define the custom components:
76
+ ```jsx
77
+ import React from 'react';
78
+ import ReactDOM from 'react-dom/client';
79
+ import './index.css';
80
+ import App from './App';
81
+ import reportWebVitals from './reportWebVitals';
82
+ import {defineCustomElements} from '@scania/tegel/loader'
83
+
84
+ const root = ReactDOM.createRoot(document.getElementById('root'));
85
+ root.render(
86
+ <React.StrictMode>
87
+ <App />
88
+ </React.StrictMode>
89
+ );
90
+
91
+ reportWebVitals();
92
+ defineCustomElements()
93
+ ```
94
+ 3. In your global css file (usually `App.css`) import the tegel stylesheet.
95
+ ```css
96
+ @import url('@scania/tegel/dist/tegel/tegel.css');
97
+ ```
98
+
99
+ ## Angular
100
+
101
+ 1. Run `npm install @scania/tegel`
102
+ 2. In your `main.ts` import and call the function `defineCustomElements()`:
103
+
104
+ ```ts
105
+ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
106
+ import { defineCustomElements } from '@scania/tegel/loader'
107
+ import { AppModule } from './app/app.module';
108
+
109
+
110
+ platformBrowserDynamic().bootstrapModule(AppModule)
111
+ .catch(err => console.error(err));
112
+
113
+ defineCustomElements(window);
114
+ ```
115
+ 3. In your `app.module.ts` import `CUSTOM_ELEMENTS_SCHEMA`:
116
+ ```ts
117
+ import { BrowserModule } from '@angular/platform-browser';
118
+ import { AppComponent } from './app.component';
119
+
120
+ @NgModule({
121
+ declarations: [
122
+ AppComponent
123
+ ],
124
+ imports: [
125
+ BrowserModule
126
+ ],
127
+ providers: [],
128
+ bootstrap: [AppComponent],
129
+ schemas: [CUSTOM_ELEMENTS_SCHEMA]
130
+ })
131
+ export class AppModule { }
132
+ ```
133
+ 4. In your global css file (`styles.css`) import the tegel stylesheet.
134
+ ```css
135
+ @import url('@scania/tegel/dist/tegel/tegel.css');
136
+ ```
137
+
138
+ ## HTML
139
+
140
+ 1. Run `npm init` to generate a package.json
141
+ 2. Run `npm install @scania/tegel`
142
+ 3. Import the package and its style in your `<head>`:
143
+ ```html
144
+ <script type="module">
145
+ import { defineCustomElements } from "./node_modules/@scania/tegel/loader/index.es2017.js";
146
+ defineCustomElements();
147
+ </script>
148
+ <link rel="stylesheet" href="./node_modules/@scania/tegel/dist/tegel/tegel.css">
149
+ ```
150
+
151
+
152
+
18
153
 
19
154
  See all available components in the [Tegel Design System](https://tegel.scania.com/components/overview).
20
155