@lansforsakringar/core-components
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

LFDS Core Components

LFDS is Länsförsäkringar's design system core components distributed as composable Web Components.

Using Components

Script/Link Tag

You can import the design system using a script tag. Many CDN's distribute packages published to npm, for example jsDelivr. You should define the exact version you want to use to avoid breaking changes.

<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/@lansforsakringar/core-components@VERSION"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lansforsakringar/core-components@VERSION/index.css">

Bundling

Install

The design system is published on NPM and can be installed as a package.

npm install @lansforsakringar/core-components

When using a bundler like Vite or Webpack, you have two options for importing and registering the components.

Lazy Loading

By importing the bare module, components will load lazily as they are rendered on the page, making sure that no unused code is loaded.

import '@lansforsakringar/core-components'

Manually Registering Components

If you have more specific needs, e.g. your own lazy loading behavior, you can import the individual components and register them as custom elements.

import {
  LfdsButton,
  defineCustomElement,
} from '@lansforsakringar/core-components/lfds-button.js'

defineCustomElement(LfdsButton)

Styles

You'll also need to import the global styles in your application. If you are using build tools like Vite or Webpack, you can import the CSS file directly in your JavaScript.

import "@lansforsakringar/core-components/index.css"

Or in your CSS if you are using a CSS preprocessor like PostCSS.

@import "@lansforsakringar/core-components";

Assets

The design system make use of static assets e.g. images, fonts etc. These files are included in the distributed packages and need to be served by the consuming application.

The design systems needs to be configured so that it knowns where you are serving the assets from. This is done by wrapping your application (or parts of) with the <lfds-config> element, setting the assetPath attribute to the public path where assets are served.

<!doctype html>
<html>
  <head>
    <script type="module" src="/my-app.js"></script>
  </head>
  <body>
    <lfds-config assetPath="/lfds-assets">
      <!-- Your application goes here -->
    </lfds-config>
  </body>
</html>

Vite

For convenience, the design system provides a Vite plugin that can be used to serve these assets.

// vite.config.js
import { lfdsVite } from '@lansforsakringar/core-components/plugin'

export default {
  plugins: [lfdsVite({ assetDir: 'lfds-assets' })],
}

On build, the assets will be copied over to the provided assetDir relative to the Vite out directory.

CDN

Just like with the script tag, assets can be served from a CDN. All assets are configured to be served from the /assets path relative to the package.

<lfds-config
  assetPath="https://cdn.jsdelivr.net/npm/@lansforsakringar/core-components@VERSION/assets">
  <!-- Your application goes here -->
</lfds-config>

Copy

If you are not using Vite or want to serve the assets in a different way, you can copy the assets from the package to your public folder.

cp -r node_modules/@lansforsakringar/core-components/dist/core-components/assets public/lfds-assets

Readme

Keywords

none

Package Sidebar

Install

npm i @lansforsakringar/core-components

Weekly Downloads

12

Version

0.0.2

License

UNLICENSED

Unpacked Size

4.49 MB

Total Files

2588

Last publish

Collaborators

  • antontrollback
  • tornqvist
  • frdh