sterling-svelte  2.0.0
A modern, accessible, lightweight UI component library for Svelte.

Installation

  1. In your Svelte application, use your favorite package manager to install sterling-svelte.
  2. npm install @geoffcox/sterling-svelte
    yarn add @geoffcox/sterling-svelte
  3. Add sterling-svelte components. You can import each component from their .svelte file or multiple from the library.
  4. <script>
      import Button from '@geoffcox/sterling-svelte/Button.svelte';
      import { Checkbox } from '@geoffcox/sterling-svelte';
    </script>
    
    <div>
      <Button>Hello sterling-svelte</Button>
      <Checkbox>Ready</Checkbox>
    </div>

Apply the Sterling theme (optional & recommended)

If you don't have your own theme for sterling-svelte, it is recommended to use the Sterling theme.

  1. Add the sterling-svelte-themes package
  2. npm install @geoffcox/sterling-svelte-themes
    yarn add @geoffcox/sterling-svelte-themes
  3. In the root of your applications (+layout.svelte), import the Sterling theme.
  4. import '@geoffcox/sterling-svelte-themes/sterling.css';
  5. Set either light-mode or dark-mode on the root of your application.
  6. <html class="light-mode"></html>

Support light and dark modes (optional)

  1. Import the applyLightDarkMode action in the script section.
  2. import { applyLightDarkMode } from '@geoffcox/sterling-svelte';
    
    // TODO: Provide UI to toggle this between auto, light, or dark.
    let mode = $state('auto');
      
  3. Use applyLightDark mode on the top-level div of your application.
  4. Recommended: Specify atDocumentRoot: true to apply the class at the root of the HTML document. This ensure styles are applied to floating UI appending to the body element's children.

    <div use:applyLightDarkMode={{atDocumentRoot: true, mode}}>
      ...
    </div>

How to use the Sterling theme in Svelte REPL

If you are working in the svelte.dev REPL or another project where you cannot import CSS from Svelte components, you can use this alternative:
<svelte:head>
  <link href="https://unpkg.com/@geoffcox/sterling-svelte-themes/css/sterling.css" rel="stylesheet">
</svelte:head>