• Stars
    star
    2,665
  • Rank 17,152 (Top 0.4 %)
  • Language Svelte
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Svelte implementation of the Carbon Design System

carbon-components-svelte

NPM GitHub npm downloads to date Chat with us on Discord

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

Other forms of documentation are auto-generated:

Installation

Install carbon-components-svelte as a development dependency.

# Yarn
yarn add -D carbon-components-svelte

# npm
npm i -D carbon-components-svelte

# pnpm
pnpm i -D carbon-components-svelte

Usage

Styling

Before importing components, you will need to first apply Carbon component styles. The Carbon Design System supports five themes (2 light, 3 dark).

  • white.css: Default Carbon theme (light)
  • g10.css: Gray 10 theme (light)
  • g80.css: Gray 80 theme (dark)
  • 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 compiled CSS is generated from the following .scss files:

CSS StyleSheet

// White theme
import "carbon-components-svelte/css/white.css";

// Gray 10 theme
import "carbon-components-svelte/css/g10.css";

// Gray 80 theme
import "carbon-components-svelte/css/g80.css";

// Gray 90 theme
import "carbon-components-svelte/css/g90.css";

// Gray 100 theme
import "carbon-components-svelte/css/g100.css";

// All themes
import "carbon-components-svelte/css/all.css";

CDN

An alternative to loading styles is to link an external StyleSheet from a Content Delivery Network (CDN) like unpkg.com.

This is best suited for rapid prototyping.

HTML
<!DOCTYPE html>
<html>
  <head>
    <link
      rel="stylesheet"
      href="https://unpkg.com/carbon-components-svelte/css/white.css"
    />
  </head>
</html>
svelte:head
<svelte:head>
  <link
    rel="stylesheet"
    href="https://unpkg.com/carbon-components-svelte/css/white.css"
  />
</svelte:head>

SCSS

The most performant method to load styles is to import SCSS directly from carbon-components. Although it requires more set up, you can reduce the size of the bundle CSS by importing individual component styles instead of a pre-compiled CSS StyleSheet.

Refer to the official Carbon guide on SASS for documentation.

Dynamic theming

Use the "all.css" StyleSheet for dynamic, client-side theming.

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

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>

Programmatically switch between each of the five Carbon themes by setting the "theme" attribute on the HTML element.

<script>
  let theme = "white"; // "white" | "g10" | "g80" | "g90" | "g100"

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

Importing components

Import components from carbon-components-svelte in the script tag of your Svelte file. Visit the documentation site for examples.

<!-- 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.

Preprocessors

carbon-preprocess-svelte is a collection of Svelte preprocessors for Carbon.

# Yarn
yarn add -D carbon-preprocess-svelte

# npm
npm i -D carbon-preprocess-svelte

# pnpm
pnpm i -D carbon-preprocess-svelte

optimizeImports

optimizeImports is a script preprocessor that rewrites base imports from Carbon components/icons/pictograms packages to their source Svelte code paths. This can greatly speed up compile times during development while preserving typeahead and autocompletion hinting offered by integrated development environments (IDE) like VSCode.

The preprocessor optimizes imports from the following packages:

Before & After

- import { Button } from "carbon-components-svelte";
- import { Add16 } from "carbon-icons-svelte";
- import { Airplane } from "carbon-pictograms-svelte";
+ import Button from "carbon-components-svelte/src/Button/Button.svelte";
+ import Add16 from "carbon-icons-svelte/lib/Add16.svelte";
+ import Airplane from "carbon-pictograms-svelte/lib/Airplane.svelte";

Usage

// svelte.config.js
import { optimizeImports } from "carbon-preprocess-svelte";

export default {
  preprocess: [optimizeImports()],
};

svelte-preprocess should be invoked before any preprocessor from carbon-preprocess-svelte.

// svelte.config.js
+ import sveltePreprocess from "svelte-preprocess";
import { optimizeImports } from "carbon-preprocess-svelte";

export default {
  preprocess: [
+   sveltePreprocess(),
    optimizeImports()
  ],
};

Examples

TypeScript support

TypeScript definitions are generated by sveld.

Contributing

Refer to the Contributing guidelines.

Changelog

License

Apache 2.0

More Repositories

1

carbon

A design system built by IBM
JavaScript
7,718
star
2

carbon-components-react

React components for the Carbon Design System
JavaScript
1,080
star
3

carbon-design-kit

A versioned, comprehensive kit of the Carbon Design System visual assets (components, icons, pictograms, text styles, color styles, grid templates).
1,072
star
4

carbon-charts

📊 📈⠀Robust dataviz framework implemented using D3 & typescript
HTML
904
star
5

carbon-components-vue

Vue implementation of the Carbon Design System
JavaScript
607
star
6

carbon-components-angular

An Angular implementation of the Carbon Design System for IBM.
TypeScript
510
star
7

carbon-web-components

Carbon Design System variant on top of Web Components
TypeScript
477
star
8

sveld

Generate TypeScript definitions for your Svelte components
Svelte
402
star
9

carbon-icons-svelte

Carbon Design System SVG icons as Svelte components
TypeScript
394
star
10

gatsby-theme-carbon

A Carbon inspired Gatsby theme
MDX
351
star
11

carbon-website

The website for the Carbon Design System.
MDX
261
star
12

carbon-for-ibm-dotcom

Carbon for IBM.com is based on the Carbon Design System for IBM
TypeScript
258
star
13

carbon-website-archive

The old website for the Carbon Design System. This repo is archived.
JavaScript
238
star
14

carbon-tutorial

An app for the Carbon Design System tutorial
JavaScript
157
star
15

carbon-pictograms-svelte

Carbon Design System SVG pictograms as Svelte components
TypeScript
119
star
16

carbon-addons-iot-react

A collection of React components shared between IBM Watson IoT products.
JavaScript
96
star
17

carbon-icons

SVG icon library for the Carbon Design System
HTML
85
star
18

ibm-products

A Carbon-powered React component library for IBM Products
JavaScript
81
star
19

design-language-website

IBM Design Language website
CSS
76
star
20

carbon-angular-starter

A simple starter app for bootstrapping applications with Carbon
TypeScript
76
star
21

ibm-security

A Carbon-powered React component library built by IBM Security
JavaScript
76
star
22

carbon-elements

Project moved to carbon-design-system/carbon
71
star
23

carbon-preprocess-svelte

Svelte preprocessors for the Carbon Design System
TypeScript
68
star
24

design-system-website

This repo has been archived, the new repo can can be found at
JavaScript
46
star
25

devtools

A simple set of tools for teams building live Carbon pages.
JavaScript
43
star
26

carbon-boilerplate

A simple boilerplate for rapid UI prototyping with Carbon components
JavaScript
42
star
27

carbon-for-ibm-dotcom-website

This is the Carbon for IBM.com website, which includes documentation and guidelines around design and development for IBM.com
MDX
39
star
28

carbon-for-ibm-dotcom-nextjs-template

This is a NextJS template utilizing Carbon for IBM.com React
JavaScript
33
star
29

carbon-tutorial-vue

JavaScript
31
star
30

carbon-react-native

The React Native implementation of the Carbon Design System
TypeScript
28
star
31

carbon-themes

A collection of themes for use with Carbon Components
28
star
32

carbon-addons-data-viz-react

DEPRECATED. Please use Carbon Charts instead
JavaScript
26
star
33

carbon-platform

The "next" version of the Carbon Design System website, as a platform.
JavaScript
22
star
34

carbon-tutorial-angular

An Angular app for the Carbon Design System tutorial
20
star
35

carbon-addons-ics

Carbon Add-on for IBM Collaboration Solutions
JavaScript
19
star
36

carbon-icons-angular

Carbon icons, in Angular!
JavaScript
19
star
37

gatsby-starter-carbon-theme

A Gatsby starter demonstrating the Gatsby Carbon theme
JavaScript
18
star
38

carbon-tutorial-svelte

An app for the Carbon Svelte tutorial
Svelte
18
star
39

tailwind-preset-carbon

JavaScript
17
star
40

icons-motion

A library of animated Carbon icons
JavaScript
17
star
41

carbon-addons-cloud

[DEPRECATED] Carbon Design System add-on for IBM Cloud
CSS
15
star
42

carbon-tutorial-nextjs

CSS
14
star
43

carbon-for-ibm-dotcom-nextjs-test

This is a sample NextJS application utilizing Carbon for IBM.com
JavaScript
14
star
44

carbon-sandbox

A theme playground for Carbon Components
CSS
13
star
45

carbon-addons-cloud-react

[DEPRECATED] React components for the Cloud Add-on
JavaScript
13
star
46

issue-tracking

For tracking issues that can't be put in the relevant open source repositories. Using to deprecate issue tracking in GHE.
11
star
47

carbon-design-system.framerfx

CSS
11
star
48

carbon-for-ibm-dotcom-web-components-template

This is an HTML Template utilizing Carbon for IBM.com Web Components. It contains a basic WebPack setup using Handlebars for page management, which includes the dds-dotcom-shell, along with other various patterns and components available in Carbon for IBM.com.
Handlebars
11
star
49

toolkit

[Experimental] A UI Toolkit for the Carbon Design System
JavaScript
10
star
50

stylelint-plugin-carbon-tokens

JavaScript
9
star
51

developer-essentials

For creation of Developer Essentials course for Carbon / Front-end Skills
9
star
52

uptime

Uptime monitoring for Carbon
Markdown
9
star
53

carbon-nextjs-template

Template for Next.js and Carbon
JavaScript
8
star
54

carbon-contribution

Documentation on how to contribute back to Carbon
7
star
55

carbon-spec

[WIP] Specification for the Carbon Design System
7
star
56

carbon-addons-beta-react

Beta React components. May be elevated into the main library.
JavaScript
7
star
57

carbonated

Internal services for building the Carbon Design System
JavaScript
6
star
58

carbon-addons-infrastructure

Carbon Add-on for IBM Cloud Infrastructure
JavaScript
6
star
59

carbon-utils-position

Position elements anywhere
TypeScript
6
star
60

carbon-addons-boilerplate-react

JavaScript
5
star
61

roadmap

Carbon Design System's roadmap.
5
star
62

sync

Internal tool for keeping project repositories in sync
JavaScript
5
star
63

carbon-addons-cloud-vanilla

JavaScript
4
star
64

carbon-addons-website

Carbon Design System add-on for design system website
CSS
4
star
65

carbon-for-ibm-dotcom-tutorial

JavaScript
4
star
66

carbon-badges

A site to apply for Carbon badges.
JavaScript
4
star
67

carbon-upgrade

[Experimental] A tool for upgrading Carbon versions (to v10): `npx carbon-upgrade`
4
star
68

carbon-for-ibm-dotcom-design-kit

A versioned, comprehensive kit of the Carbon for IBM.com visual assets.
4
star
69

carbon-addons-catalog-react

Bluemix Catalog components in React
JavaScript
3
star
70

carbon-labs

A collection of components and patterns implemented using Carbon Web Components for the IBM AI experience.
TypeScript
3
star
71

okrs

Objectives and key results for the Carbon team.
3
star
72

digital-design-ideation

3
star
73

carbon-shared-tests

Carbon Shared Tests are re-usable UI unit tests aligned to the Carbon Design System
TypeScript
3
star
74

carb

[Experimental] Tooling for managing design systems
Rust
2
star
75

ibm-cloud

Carbon for IBM Cloud
JavaScript
2
star
76

sandboxes

JavaScript
2
star
77

action-ibmcloud-cf

Common GitHub actions used in various repositories in carbon-design-system org, for deploying a IBM Cloud CF app.
JavaScript
2
star
78

rfcs

RFCs for changes to the Carbon Design System
2
star
79

carbon-sketch-assistant

Carbon Design System design validation directly in Sketch
TypeScript
2
star
80

incubator

[Experimental] Explore, build, and try-out new work with Carbon
JavaScript
2
star
81

remote-learning-enablement

https://remote-learning-enablement.vercel.app/remotelearning/
JavaScript
2
star
82

platform

[Internal] Tools and services for managing a design system
JavaScript
2
star
83

carbon-dco

Signed Developer Certificate of Origins for the Carbon Design System.
JavaScript
2
star
84

carbon-for-ibm-dotcom-web-components-test

Environment for testing Carbon for IBM.com web components as a mock application
Handlebars
2
star
85

repo-transfer-test

a repo to test the transferring from account to organization
JavaScript
1
star
86

Contentful-for-IBM.com

JavaScript
1
star
87

gatsby-theme-presentation

JavaScript
1
star
88

.github

1
star
89

pattern-contributions

This repository is a single place to triage, manage, and maintain pattern contributions to the Carbon Design System.
1
star
90

archived-v10-release-issues

The default for issues and epics is public. There may be rare occasions when an issue needs to remain confidential. If so, put that issue in this repo.
1
star
91

content-planning

This is a place to plan, organize, and communicate about Carbon content
1
star
92

ibm-cdai

IBM CDAI
1
star
93

carbon-job-stories

1
star
94

carbon-v11

1
star
95

carbon-style-stats

Dashboard for analyzing various Carbon stylesheet statistics
JavaScript
1
star
96

carbon-triage

Tools for helping with issue triage
JavaScript
1
star
97

carbon-tutorial-test1

Build an app with the Carbon Design System and Next.js
1
star
98

carbon-vega-theme

The official 4 Carbon themes offered for Vega users
SCSS
1
star