### Install Dependencies Source: https://github.com/digdir/designsystemet/blob/main/CONTRIBUTING.md Run this command to install all necessary project dependencies. ```bash pnpm i ``` -------------------------------- ### Complete Design System Configuration Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/cli-config.mdx This JSON configuration defines a custom theme named 'my-theme' with specific color palettes, typography settings, and overrides for colors, severity, and link visited states. Ensure the $schema path is correct for your project setup. ```json { "$schema": "node_modules/@digdir/designsystemet/dist/config.schema.json", "outDir": "./design-tokens", "themes": { "my-theme": { "colors": { "main": { "primary": "#0062BA", "accent": "#1E98F5" }, "neutral": "#1E2B3C", "support": { "extra1": "#F45F63", "extra2": "#E5AA20" } }, "borderRadius": 4, "typography": { "fontFamily": "Inter" }, "overrides": { "colors": { "primary": { "background-default": { "light": "#ff0000", "dark": "#000fff" }, "text-default": { "light": "#00ff00", "dark": "#00ffff" } } }, "severity": { "success": "#28a745", "warning": "#ffc107", "danger": "#dc3545", "info": "#17a2b8" }, "linkVisited": { "light": "#ff1234", "dark": "#1234ff" } } } } } ``` -------------------------------- ### Install Web Packages Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/setup.mdx Install the core CSS and Web Components packages for HTML projects. ```sh npm i @digdir/designsystemet-css @digdir/designsystemet-web ``` -------------------------------- ### Install React Packages Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/setup.mdx Install the core CSS and React component packages for React projects. ```sh npm i @digdir/designsystemet-css @digdir/designsystemet-react ``` -------------------------------- ### List Writing Rule 1 Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/list/en/overview.mdx Shows how to format list items when each item continues the introduction: lowercase start, no colon after intro, no full stop at item end. ```javascript ``` -------------------------------- ### CLI Example for Creating Tokens Source: https://github.com/digdir/designsystemet/blob/main/packages/cli/README.md A command-line example demonstrating how to create design tokens with specific color and border-radius options, and assigning them to a theme. This is equivalent to a minimal config file. ```bash npx @digdir/designsystemet tokens create \ --main-colors "primary:#0062BA" "accent:#1E98F5" \ --neutral-color "#1E2B3C" \ --support-colors "extra1:#F45F63" "extra2:#E5AA20" \ --border-radius 4 \ --theme "theme" ``` -------------------------------- ### Select with Options Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/select/en/overview.mdx A basic example of the Select component displaying a list of options. ```javascript import { PreviewEn } from "@/app/content/components/select/en/overview.mdx"; ``` -------------------------------- ### Skeleton Usage Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/skeleton/en/overview.mdx Provides a practical example of how to implement the Skeleton component in a layout. This snippet shows the component in a column layout. ```javascript ``` -------------------------------- ### Ordered List Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/list/en/overview.mdx Demonstrates the basic usage of an ordered list. ```javascript ``` -------------------------------- ### Install Designsystemet React and CSS Packages Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/react.mdx Install the necessary React components and CSS packages using npm. This is the first step to using the Designsystemet in your React project. ```sh npm i @digdir/designsystemet-react @digdir/designsystemet-css ``` -------------------------------- ### Install Designsystemet V1 Release Candidate Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/blog/en/v1rc1.mdx Use these commands to install the latest release candidate packages for React, theme, and CSS. ```shell npm i @digdir/designsystemet-react@next npm i @digdir/designsystemet-theme@next npm i @digdir/designsystemet-css@next ``` -------------------------------- ### Web component button example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/blog/en/web-components-and-designsystemet-without-react.mdx Demonstrates a custom web component element for a button. ```html Click me ``` -------------------------------- ### Install Designsystemet CSS Package Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/other-frameworks.mdx Install the CSS package using npm. This is the first step to using Designsystemet styles without React. ```sh npm i @digdir/designsystemet-css ``` -------------------------------- ### List Writing Rule 2 Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/list/en/overview.mdx Shows how to format list items when each item is a complete sentence: capital letter start, full stop at item end. ```javascript ``` -------------------------------- ### Unordered List Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/list/en/overview.mdx Demonstrates the basic usage of an unordered list. ```javascript ``` -------------------------------- ### Define a theme configuration Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/cli-config.mdx Example of a full theme configuration including colors and border radius. The $schema property is recommended for validation. ```json { "$schema": "node_modules/@digdir/designsystemet/dist/config.schema.json", "themes": { "my-theme": { "colors": { "main": { "primary": "#0062BA" }, "neutral": "#1E2B3C", "support": { "extra1": "#F45F63" } }, "borderRadius": 4 } } } ``` -------------------------------- ### Start Local Development Servers Source: https://github.com/digdir/designsystemet/blob/main/CONTRIBUTING.md Choose and run the script for the specific application you want to work on locally: Storybook, Storefront (www), or Themebuilder. ```bash pnpm storybook | www | themebuilder ``` -------------------------------- ### HTML Button Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/other-frameworks.mdx A basic example of a Designsystemet button using pure HTML. Apply the `ds-button` class and specify variants using `data-variant` attributes. ```html ``` -------------------------------- ### Conventional Commit Example: Docs Source: https://github.com/digdir/designsystemet/blob/main/CONTRIBUTING.md Example of a commit message for adding documentation to the Table component, including a scope. ```git docs(Table): added paragraph about table header and using interderminate checkboxes ``` -------------------------------- ### Ordered List Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/list/en/code.mdx Renders a standard ordered list using the 'ds-list' class. ```html
  1. Item
  2. Item
  3. Item
``` -------------------------------- ### Install Designsystemet Types Package Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/setup.mdx Install the type package for Designsystemet to enable type safety. This command should be run in your project's terminal. ```sh npm i -D @digdir/designsystemet-types ``` -------------------------------- ### Basic Textfield Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/textfield/en/overview.mdx Demonstrates a basic textfield with a label, help text, and validation message. Use when a complete form field is needed. ```javascript import { Textfield } from "@digdir/designsystemet-react"; function MyForm() { return ( ); } ``` -------------------------------- ### Unordered List Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/list/en/code.mdx Renders a standard unordered list using the 'ds-list' class. ```html
  • Item
  • Item
  • Item
``` -------------------------------- ### Do: Single Icon in Button Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/button/en/overview.mdx Example showing the correct usage of a single icon within a button. ```html ``` -------------------------------- ### Combine data-color and data-color-scheme Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/colors.mdx Examples showing how `data-color` and `data-color-scheme` can be used together. Note that `data-color` needs to be reapplied if the color scheme changes. ```html
``` -------------------------------- ### Link Card Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/card/en/overview.mdx Demonstrates using a Card component as a navigation element to link to another page. Ensure correct usage for navigation. ```javascript import { Card } from "@/components/card"; export default function Page() { return ( Go to Destination Click here to navigate to the destination page. ); } ``` -------------------------------- ### HTML Component Usage Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/setup.mdx Example of using a button and a form field with Designsystemet classes and structure in HTML. ```html ``` -------------------------------- ### Do: Use descriptive link text Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/link/en/overview.mdx Example of a good link text that is self-explanatory and makes sense when read aloud. ```jsx import { Link } from "@digdir/designsystemet-react"; Log in to the service ``` -------------------------------- ### Card with Sections Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/card/en/code.mdx Demonstrates how to use ds-card__block to divide a card into sections. Content must be placed within ds-card__block elements. ```html

Title

Content

Image description
``` -------------------------------- ### Interactive Popover Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/popover/en/overview.mdx Demonstrates a popover with interactive elements like buttons. Use this when the popover content needs user interaction. ```React import { Preview } from "@storybook/react"; import { PreviewEn } from "./PreviewEn"; const meta = { title: "Components/Popover/PreviewEn", component: PreviewEn, parameters: { layout: "centered", }, tags: ["autodocs"], }; export default meta; type Story = StoryObj; export const InteractiveEn: Story = { args: {}, }; ``` -------------------------------- ### Tag with Icon Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/tag/en/overview.mdx Demonstrates how to use an icon within a Tag component for additional visual information. Ensure proper padding and margin for spacing. ```javascript import { Tag, BodyLong } from '@digdir/design-system-react'
}>Completed }>Ongoing }>Cancelled
``` -------------------------------- ### React Component Usage Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/setup.mdx Example of using a Button and a Field component from the Designsystemet React library. ```js ; ``` -------------------------------- ### Sortable Table Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/table/en/overview.mdx Shows a table where columns can be sorted, indicated to the user that the data is sortable. This enhances data exploration. ```javascript import { Table } from "@digdir/designsystemet-react"; function SortableTable() { return ( Navn Alder By Ola Nordmann 30 Oslo Kari Hansen 25 Bergen ); } ``` -------------------------------- ### Design Systemet Config JSON with Theme Source: https://github.com/digdir/designsystemet/blob/main/packages/cli/README.md An example of a `designsystemet.config.json` file defining a theme with custom colors and border-radius. This configuration is equivalent to specific CLI options for creating tokens. ```json { "$schema": "./node_modules/@digdir/designsystemet/dist/config.schema.json", "outDir": "../path/to/design-tokens", "themes": { "theme": { "colors": { "main": { "primary": "#0062BA", "accent": "#1E98F5" }, "neutral": "#1E2B3C", "support": { "extra1": "#F45F63", "extra2": "#E5AA20" } }, "borderRadius": 4 } } } ``` -------------------------------- ### Component Color Inheritance Examples Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/colors.mdx Demonstrates how `Chip` and `Button` components inherit the 'neutral' color, while `Alert` does not due to its explicit color system. ```html
This Chip has neutral color.
I don't have neutral color.
``` -------------------------------- ### Horizontal Card Layout Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/card/en/code.mdx Demonstrates how to arrange Card.Block elements horizontally using flexbox or grid. This is useful for side-by-side content. ```html
Content 1
Content 2
``` -------------------------------- ### Skeleton Text Variant Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/skeleton/en/overview.mdx Illustrates the specific usage of the text variant of the Skeleton component. This is useful for mimicking text-based content during loading. ```javascript ``` -------------------------------- ### HTML Details Component Usage Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/details/en/code.mdx Demonstrates how to use the native HTML details element with Designsystemet CSS classes for styling. Includes examples with and without a card frame. ```html
Details heading text
Details content
Details heading text
Details content
``` -------------------------------- ### React Details Component Usage Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/details/en/code.mdx Shows how to implement the Details component using the Designsystemet React library. Provides examples for both standalone usage and within a Card component. ```tsx /* Without frame */ import { Details } from '@digdir/designsystemet-react';
Details heading text Details content
/* With frame */ import { Details, Card } from '@digdir/designsystemet-react';
Details heading text Details content
``` -------------------------------- ### Checkbox Group Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/checkbox/en/overview.mdx Checkboxes are typically used in groups allowing multiple selections. This example shows a basic group setup. ```javascript
``` -------------------------------- ### Build Project Source: https://github.com/digdir/designsystemet/blob/main/CONTRIBUTING.md Execute this command to build the project. ```bash pnpm build ``` -------------------------------- ### Conventional Commit Example: Fix Source: https://github.com/digdir/designsystemet/blob/main/CONTRIBUTING.md Example of a commit message fixing a bug in the Button component, including a scope. ```git fix(Button): correct padding when only icon ``` -------------------------------- ### Multiple Themes Configuration Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/start-here/own-theme.mdx This JSON configuration demonstrates how to define multiple themes, each with its own set of colors and design properties. Remember to run the create tokens command after updating this file. ```json { "outDir": "./design-tokens", "clean": true, "themes": { "theme-one": { "colors": { "main": { "primary": "#0062BA" }, "neutral": "#1E2B3C", "support": { "extra1": "#F45F63" } }, "borderRadius": 4 }, "theme-two": { "colors": { "main": { "primary": "#0062BA" }, "neutral": "#1E2B3C", "support": { "extra1": "#F45F63" } }, "borderRadius": 4 } } } ``` -------------------------------- ### Create Tokens and Build CSS using Config Source: https://github.com/digdir/designsystemet/blob/main/packages/cli/README.md Commands to generate new design tokens and CSS files using a configuration file. These commands should be run after setting up the `designsystemet.config.json`. ```bash npx @digdir/designsystemet tokens create ``` ```bash npx @digdir/designsystemet tokens build ``` -------------------------------- ### Avatar Stack React Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/avatar-stack/en/code.mdx Example of creating an avatar stack using the Design System's React components. Customize avatar size and overlap via props. ```tsx import { EXPERIMENTAL_AvatarStack as AvatarStack, Avatar } from '@digdir/designsystemet-react'; ON ``` -------------------------------- ### Import Default Theme CSS Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/setup.mdx Import the default Designsystemet theme CSS using JavaScript. ```js import '@digdir/designsystemet-css'; import '@digdir/designsystemet-css/theme'; ``` -------------------------------- ### Migrate from Beta Version Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/blog/en/v1rc1.mdx Run this npx command to migrate from the beta version of Designsystemet to v1. It automatically runs on all `.css` files but can be scoped using the `--glob` parameter. Always double-check your code after the script runs. ```shell npx @digdir/designsystemet migrate beta-to-v1 ``` -------------------------------- ### Link Card Example (HTML) Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/card/en/code.mdx Shows how to make an entire card function as a link by using an anchor tag as the outermost element. This ensures screen readers treat the entire card as a single link. ```html

Card Title

This is the card content.

``` -------------------------------- ### Field Component in React Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/field/en/code.mdx Provides an example of using the Field component from the @digdir/designsystemet-react library. ```tsx import { Field, Label, Input, ValidationMessage } from '@digdir/designsystemet-react'; Description Error message ``` -------------------------------- ### Basic Design Tokens Configuration Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/start-here/own-theme.mdx This JSON configuration file defines the output directory, whether to clean previous builds, and the structure for themes, including colors and border-radius. ```json { "outDir": "./design-tokens", "clean": true, "themes": { "theme": { "colors": { "main": { "primary": "#0062BA" }, "neutral": "#1E2B3C", "support": { "extra1": "#F45F63" } }, "borderRadius": 4 } } } ``` -------------------------------- ### Import the package Source: https://github.com/digdir/designsystemet/blob/main/packages/web/README.md Register all web components and observers globally by importing the package once. ```ts import '@digdir/designsystemet-web'; ``` -------------------------------- ### Radio Button Group Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/radio/en/overview.mdx Demonstrates how to group radio buttons with a legend and description for clarity. ```javascript import { Radio } from "@digdir/designsystemet-react"; function RadioGroupExample() { return ( Alternativ 1 Alternativ 2 Alternativ 3 ); } ``` -------------------------------- ### Do: Explain external links with text Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/link/en/overview.mdx Demonstrates using text to clarify that a link leads to an external site or opens in a new tab. ```jsx import { Link } from "@digdir/designsystemet-react"; Visit our external website (opens in new tab) ``` -------------------------------- ### React Textfield Component Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/textfield/en/code.mdx Basic usage of the Textfield component in React. Ensure you have installed the '@digdir/designsystemet-react' package. ```tsx import { Textfield } from '@digdir/designsystemet-react'; ``` -------------------------------- ### Don't: Multiple Icons in Button Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/button/en/overview.mdx Example demonstrating the incorrect usage of multiple icons in a single button. ```html ``` -------------------------------- ### Create Design Tokens Source: https://github.com/digdir/designsystemet/blob/main/packages/cli/README.md Use this command to create design tokens for themes, including custom colors and typography. It's recommended to use the theme builder for generating options. Run with `--clean` to remove deprecated or unneeded files. ```bash npx @digdir/designsystemet tokens create ``` ```bash npx @digdir/designsystemet tokens create --clean ``` -------------------------------- ### Chip as Button Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/chip/en/code.mdx Use this structure for a chip that acts as a button, for example, to clear filters. No special attributes are required. ```html ``` -------------------------------- ### Import Custom Theme CSS Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/fundamentals/en/code/setup.mdx Import your custom theme CSS after the main Designsystemet CSS. Replace '.css' with your actual theme file name. ```css @import '@digdir/designsystemet-css/index.css'; @import 'design-tokens-build/.css'; ``` -------------------------------- ### Basic Link in React Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/link/en/code.mdx Demonstrates how to import and use the Link component from the `@digdir/designsystemet-react` library to create a navigable link. ```tsx import { Link } from '@digdir/designsystemet-react'; Go to the design system; ``` -------------------------------- ### Chip Component in React Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/chip/en/code.mdx Examples of using the Chip component from '@digdir/designsystemet-react' in various forms: radio, checkbox, removable, and button. ```tsx import { Chip } from '@digdir/designsystemet-react'; // as radio Radio; // as checkbox Checkbox; // as removable Removable; // as button Button; ``` -------------------------------- ### React Breadcrumbs Component Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/breadcrumbs/en/code.mdx Example of using the React Breadcrumbs component with a label, a back link, and a list of navigation items. ```tsx Level 3 Level 1 Level 2 ``` -------------------------------- ### Breadcrumb with Long Navigation Items Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/breadcrumbs/en/overview.mdx Example demonstrating how long navigation item texts are handled within the breadcrumb component. ```javascript import { Breadcrumbs } from "@digdir/designsystemet-react"; Forsiden Arbeidsflate Innboks Meldinger Detaljer om melding Tilbake ``` -------------------------------- ### Card with Linked Elements Example (HTML) Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/card/en/code.mdx Illustrates how to make a card clickable while retaining distinct interactive elements like links and buttons. Uses data-clickdelegatefor to manage click delegation. ```html
Myrkheim Museum
``` -------------------------------- ### Required Textfield Example Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/textfield/en/overview.mdx Shows how to mark a textfield as required, which is legally mandated for mandatory fields. Ensure clear visual indication. ```javascript import { Textfield } from "@digdir/designsystemet-react"; function MyForm() { return ( ); } ``` -------------------------------- ### Disabled Select Source: https://github.com/digdir/designsystemet/blob/main/apps/www/app/content/components/select/en/overview.mdx An example of a disabled Select component. It is generally advised to avoid disabled states due to potential user confusion. ```javascript import { DisabledEn } from "@/app/content/components/select/en/overview.mdx"; ```