Svelte implementation of the Carbon Design System https://svelte.carbondesignsystem.com
Find a file
2021-01-27 14:52:56 -08:00
docs chore(deps-dev): replace node-sass with sass, upgrade autoprefixer, postcss (#497) 2021-01-27 14:52:56 -08:00
examples fix(examples): use external stylesheet for rollup examples 2020-09-27 10:57:08 -07:00
scripts chore(deps-dev): replace node-sass with sass, upgrade autoprefixer, postcss (#497) 2021-01-27 14:52:56 -08:00
src feat: make renderIcon/icon prop consistent (#496) 2021-01-27 14:16:07 -08:00
tests Alignment with Carbon version 10.27 (#495) 2021-01-27 13:29:20 -08:00
types feat: make renderIcon/icon prop consistent (#496) 2021-01-27 14:16:07 -08:00
.gitignore chore: remove storybook 2020-10-14 16:23:44 -07:00
.prettierignore chore: remove storybook 2020-10-14 16:23:44 -07:00
.travis.yml fix(types): remove "undefined" dispatched events 2020-11-19 09:09:57 -08:00
CHANGELOG.md v0.26.0 2020-12-11 05:09:55 -08:00
CODEOWNERS add plain header UI Shell example (#459) 2020-12-11 05:04:42 -08:00
COMPONENT_INDEX.md feat: make renderIcon/icon prop consistent (#496) 2021-01-27 14:16:07 -08:00
CONTRIBUTING.md Alignment with Carbon version 10.27 (#495) 2021-01-27 13:29:20 -08:00
LICENSE Initial commit 2019-12-15 13:16:40 -05:00
MAINTAINERS.md add plain header UI Shell example (#459) 2020-12-11 05:04:42 -08:00
package.json chore(deps-dev): replace node-sass with sass, upgrade autoprefixer, postcss (#497) 2021-01-27 14:52:56 -08:00
README.md Alignment with Carbon version 10.27 (#495) 2021-01-27 13:29:20 -08:00
rollup.config.js Alignment with Carbon version 10.27 (#495) 2021-01-27 13:29:20 -08:00
tsconfig.json build: use svelte compiler to generate typescript definitions 2020-08-10 18:27:26 -07:00
yarn.lock chore(deps-dev): replace node-sass with sass, upgrade autoprefixer, postcss (#497) 2021-01-27 14:52:56 -08:00

carbon-components-svelte

NPM GitHub npm downloads to date Build

Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.

Design systems facilitate design and development through reuse, consistency, and extensibility.

The Carbon Svelte portfolio also includes:

Documentation

Deploys by Vercel

The documentation website contains live demos and examples.

Other forms of documentation are auto-generated:

Getting started

Install carbon-components-svelte as a development dependency.

yarn add -D carbon-components-svelte
# OR
npm i -D carbon-components-svelte

Usage

The quickest way to get started is to customize a template from the examples folder.

Example set-ups demonstrate usage with popular application bundlers and frameworks. They include a mix of client-side rendering (CSR) and server-side rendering (SSR) approaches.

Scaffolding

Each example is published in a dedicated branch of the same name.

Use degit to scaffold a new project:

For example, to use the svite template, run the following commands:

npx degit ibm/carbon-components-svelte#svite svelte-app
cd svelte-app
yarn install

Importing components

Import components from carbon-components-svelte in the script tag of your Svelte file.

<!-- App.svelte -->
<script>
  import { Accordion, AccordionItem } from "carbon-components-svelte";
</script>

<Accordion>
  <AccordionItem title="Section 1" open> Content 1 </AccordionItem>
  <AccordionItem title="Section 2"> Content 2 </AccordionItem>
  <AccordionItem title="Section 3"> Content 3 </AccordionItem>
</Accordion>

Refer to COMPONENT_INDEX.md for component API documentation.

Precompiled CSS StyleSheets

carbon-components-svelte includes precompiled CSS StyleSheets for each Carbon theme:

  • white.css: Default Carbon theme (light)
  • g10.css: Gray 10 theme (light)
  • g90.css: Gray 90 theme (dark)
  • g100.css: Gray 100 theme (dark)
  • all.css: All themes (White, Gray 10, Gray 90, Gray 100) using CSS variables

Each StyleSheet is generated from the flagship carbon-components library..

Usage

svelte-preprocess

The easiest way to import a StyleSheet is with svelte-preprocess.

const svelteOptions = {
  preprocess: require("svelte-preprocess")(),
};
<!-- App.svelte -->
<style lang="scss" global>
  /** Gray 10 theme **/
  @import "carbon-components-svelte/css/g10";
</style>
JavaScript import

Importing a CSS file in a JavaScript file will require the appropriate file loader(s).

import "carbon-components-svelte/css/all.css";
import App from "./App.svelte";

const app = new App({ target: document.body });

export default app;

See webpack.config.js in examples/webpack.

Dynamic theming

Use carbon-components-svelte/css/all.css for dynamic, client-side styling.

Update the theme by setting the theme attribute on the html element. The default theme is "white".

<!DOCTYPE html>
<html lang="en" theme="g10">
  <body>
    ...
  </body>
</html>

Using JavaScript:

<script>
  /** @type {"white" | "g10" | "g90" | "g100"} */
  let theme = "white";

  $: document.documentElement.setAttribute("theme", theme);
</script>

<button on:click="{() => theme = 'g90'}">Update theme</button>

TypeScript support

TypeScript definitions are generated by sveld.

Contributing

Refer to the Contributing guidelines.

Changelog

License

Apache 2.0