@scania/tegel
v1.48.0
Published
Tegel Design System
Readme
@scania/tegel
Official website: https://tegel.scania.com/
Storybook: https://tds-storybook.tegel.scania.com/
The design system supports the design and development of digital solutions at Scania. The purpose is to secure a coherent, premium brand and user experience across all of Scania's digital touchpoints.
Status
This package is currently considered a beta. Version 1.0.0 and later are released, and we see no braking changes coming in near future.
Installation
React
with Typescript
- Run
npm install @scania/tegel - src folder create a file called
register-webcomponents.ts - Paste the following into that file:
import { defineCustomElements, JSX as LocalJSX } from '@scania/tegel/loader';
import { DetailedHTMLProps, HTMLAttributes } from 'react';
type StencilProps<T> = {
[P in keyof T]?: Omit<T[P], 'ref'> | HTMLAttributes<T>;
};
type ReactProps<T> = {
[P in keyof T]?: DetailedHTMLProps<HTMLAttributes<T[P]>, T[P]>;
};
type StencilToReact<T = LocalJSX.IntrinsicElements, U = HTMLElementTagNameMap> = StencilProps<T> &
ReactProps<U>;
declare global {
export namespace JSX {
interface IntrinsicElements extends StencilToReact {}
}
}
defineCustomElements(window);- In your index.tsx import
register-webcomponents.ts
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import './register-webcomponents';
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
reportWebVitals();- In your global css file (usually
App.css) import the tegel stylesheet.
@import url('@scania/tegel/dist/tegel/tegel.css');with Javascript
- Run
npm install @scania/tegel - In your index.jsx define the custom components:
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { defineCustomElements } from '@scania/tegel/loader';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
reportWebVitals();
defineCustomElements();- In your global css file (usually
App.css) import the tegel stylesheet.
@import url('@scania/tegel/dist/tegel/tegel.css');Angular
- Run
npm install @scania/tegel - In your
main.tsimport and call the functiondefineCustomElements():
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { defineCustomElements } from '@scania/tegel/loader';
import { AppModule } from './app/app.module';
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
defineCustomElements(window);- In your
app.module.tsimportCUSTOM_ELEMENTS_SCHEMA:
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
providers: [],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}- In your global css file (
styles.css) import the tegel stylesheet.
@import url('@scania/tegel/dist/tegel/tegel.css');HTML
- Run
npm initto generate a package.json - Run
npm install @scania/tegel - Import the package and its style in your
<head>:
<script type="module">
import { defineCustomElements } from './node_modules/@scania/tegel/loader/index.es2017.js';
defineCustomElements();
</script>
<link rel="stylesheet" href="./node_modules/@scania/tegel/dist/tegel/tegel.css" />See all available components in the Tegel Design System.
Development notes
When adding or editing Stencil components, do not use DOM property names for instance fields (e.g. private or @State()). Custom elements extend HTMLElement, so names like children, parentElement, scrollWidth, childNodes, firstChild, tagName, shadowRoot are read-only getters on the prototype. Assigning to them (e.g. this.children = ...) throws "Cannot set property X which has only a getter", especially when the component is used from React. Use alternative names (e.g. tabElements instead of children, parentDropdown instead of parentElement, scrollableWidth instead of scrollWidth).
Browser support
See the browser support section on the Tegel website.
Community
Get in touch with the team and the community:
License
All CSS, HTML and JS code are available under the MIT license. The Scania brand identity, logos and photographs found in this repository are copyrighted Scania CV AB and are not available on an open source basis or to be used as examples or in any other way, if not specifically ordered by Scania CV AB.
