Svelte implementation of the Carbon Design System https://svelte.carbondesignsystem.com
Find a file
2020-09-13 13:39:36 -07:00
.github feat: initial commit 2019-12-15 11:20:52 -08:00
.storybook chore: use precompiled g10 theme in storybook 2020-09-06 15:41:00 -07:00
docs chore(prettier): use svelteStrictMode 2020-09-04 16:35:49 -07:00
examples docs: update guidance on examples, usage 2020-09-13 13:39:36 -07:00
scripts fix(scripts): clean gh-pages for each example 2020-09-13 13:38:22 -07:00
src feat(ui-shell): add HeaderGlobalAction component 2020-09-05 15:28:10 -07:00
types chore(examples): update typescript example 2020-09-13 12:36:12 -07:00
.gitignore feat: build pre-compiled CSS from Carbon themes 2020-09-06 15:40:36 -07:00
.prettierrc chore(prettier): use svelteStrictMode 2020-09-04 16:35:49 -07:00
.travis.yml ci(travis): require node_js >=12 2020-09-04 17:46:02 -07:00
CHANGELOG.md v0.11.0 2020-09-05 15:34:49 -07:00
COMPONENT_INDEX.md v0.11.0 2020-09-05 15:34:49 -07:00
CONTRIBUTING.md ci(travis): require node_js >=12 2020-09-04 17:46:02 -07:00
LICENSE Initial commit 2019-12-15 13:16:40 -05:00
package.json build(scripts): publish examples using gh-pages 2020-09-13 12:43:23 -07:00
README.md docs: update guidance on examples, usage 2020-09-13 13:39:36 -07:00
rollup.config.js refactor(types): integrate generate docs in rollup.config.js 2020-08-11 08:38:07 -07:00
tsconfig.json build: use svelte compiler to generate typescript definitions 2020-08-10 18:27:26 -07:00
yarn.lock build(scripts): publish examples using gh-pages 2020-09-13 12:43:23 -07:00

carbon-components-svelte

NPM Build

Svelte implementation of the Carbon Design System

Getting started

carbon-components-svelte can be installed as a development dependency.

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

Usage

The quickest way to start is to use a template from the examples folder.

Example set-ups demonstrate usage with popular application bundlers and frameworks. They feature a mix of Singe-page Applications (SPA), Server-side rendering (SSR) and statically exported 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 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.

The examples use all.css for dynamic theming through CSS variables.

Usage

svelte-preprocess

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

const svelteOptions = {
  preprocess: require("svelte-preprocess")(),
};
<!-- App.svelte -->
<style 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.

TypeScript support

The component library ships with TypeScript definitions (types/index.d.ts).

Contributing

Refer to the Contributing guidelines.

Changelog

License

Apache 2.0