Designsystemet

repository·main·Indexed 42 days ago

https://github.com/digdir/designsystemet

A suite of tools and components for creating consistent digital experiences for public services. It includes a CLI for managing design tokens, a CSS implementation using @layer for specificity management, React components with SSR support, and framework-independent web components via @digdir/designsystemet-web.

Tokens
167.7K
Snippets
428
Records
883
Agent score
49%

What's inside Designsystemet

  1. Overview of Designsystemet packages

    main

    Designsystemet is a suite of tools designed to create consistent and user-friendly digital experiences for public services. It provides several packages depending on your technical requirements:

    • @digdir/designsystemet: The Command Line Interface (CLI) for Designsystemet.
    • @digdir/designsystemet-react: React-specific implementation of Designsystemet components.
    • @digdir/designsystemet-web: Framework-agnostic implementations of web components and helpers.
    • @digdir/designsystemet-css: CSS implementation of components (used by the React package) and contains the default theme.
    • @digdir/designsystemet-types: TypeScript definitions and types for the system.

    Note: @digdir/designsystemet-theme is deprecated.

  2. Overview of @digdir/designsystemet-css

    main

    The @digdir/designsystemet-css package provides the CSS implementation of Designsystemet components.

    Key technical details:

    • It utilizes the CSS @layer directive with the layer name ds to manage specificity.
    • It exports a default theme located under /theme.
    • You can also use a CSS file generated via the @digdir/designsystemet tokens build command for custom theming.
    • Custom themes can be built using the official web tool at https://theme.designsystemet.no/en.
  3. Accessibility compliance in Designsystemet

    main

    Designsystemet provides foundational components designed to meet the WCAG requirements included in Norwegian legislation. The system aims to support accessibility through:

    • Accessible Components: Components are built with specific HTML and ARIA attributes, proper focus handling, and dynamic announcements for screen readers.
    • Guidance and Best Practices: Beyond technical implementation, the system provides recommendations to ensure digital solutions are user-friendly for people with permanent or temporary impairments.
    • Continuous Improvement: Accessibility is integrated into the development lifecycle. Issues or limitations affecting a component's accessibility are prioritized for fixes to benefit all users of the system.
  4. Use @digdir/designsystemet-react components

    main

    The @digdir/designsystemet-react package provides the React implementation of Designsystemet components.

    Key Features

    • Styling: Uses @digdir/designsystemet-css for all component styles.
    • Theming: Components use @digdir/designsystemet-css/theme or a CSS file generated via the @digdir/designsystemet tokens build command. You can also build custom themes at https://theme.designsystemet.no/en.
    • Refs: All components support ref for direct DOM access.
    • SSR Support: All components support Server-Side Rendering (SSR). To ensure compatibility, use the full component name (e.g., CardBlock) instead of dot-notation (e.g., Card.Block).
    • HTML Compatibility: Most components extend and behave like native HTML elements.
    • Composition: Most components support composition and the asChild prop, which allows you to override the underlying HTML element.
  5. Understand the color generation approach in Designsystemet

    main
    Designsystemet generates color scales by mimicking how light affects colors in the real world. Instead of relying solely on HSL or other color spaces that can lead to oversaturation or unbalanced hues, the system uses an RGB-based approach involving shading (adding black to make a color darker) and tinting (adding white to make a color lighter). This method ensures that the resulting scales are visually balanced, harmonious, and maintain the perceived character of the base color.
  6. WCAG contrast requirements and luminance

    main

    Designsystemet is built to meet WCAG AA requirements (and aims for AAA where appropriate).

    Contrast Ratios

    To meet AA standards, you must ensure the following contrast ratios between text and background:

    • Small text: Minimum 4.5:1.
    • Large text (≥ 18px): Minimum 3:1.
    • Interactive/Graphical elements: Minimum 3:1.

    Relative Luminance

    WCAG calculates contrast based on relative luminance, a normalized value between 0 (black) and 1 (white). This value is derived from the RGB components, where the green channel contributes most to perceived brightness. The contrast score ranges from 1:1 (no contrast) to 21:1 (maximum contrast).

  7. When to use the List component

    main

    Use the List component to improve content scannability and clarity in the following scenarios:

    • Summarising key points.
    • Showing multiple steps in a process.
    • Listing criteria, options, or prerequisites.

    Avoid using a List when:

    • The items are so long that readability suffers. In this case, consider breaking the content into several shorter lists.
    • Information needs to be structured for comparison. Use the Table component instead.
  8. When to use Radio buttons

    main

    Use radio buttons when a user must choose exactly one option from a set of several mutually exclusive options in a form.

    Do not use radio buttons if:

    • The user should be able to select multiple options (use checkbox instead).
    • There is only one choice to make (consider using switch or checkbox).
    • There are more than seven options in a group (consider using suggestion or select).