Gathering detailed insights and metrics for carbon-components-svelte
Gathering detailed insights and metrics for carbon-components-svelte
Gathering detailed insights and metrics for carbon-components-svelte
Gathering detailed insights and metrics for carbon-components-svelte
carbon-icons-svelte
Carbon Design System SVG icons as Svelte components
@softmotions/carbon-components-svelte
Svelte implementation of the Carbon Design System
carbon-pictograms-svelte
Carbon Design System SVG pictograms as Svelte components
carbon-preprocess-svelte
Svelte preprocessors for the Carbon Design System
Svelte implementation of the Carbon Design System
npm install carbon-components-svelte
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,708 Stars
2,025 Commits
262 Forks
42 Watching
16 Branches
126 Contributors
Updated on 25 Nov 2024
Minified
Minified + Gzipped
Svelte (91.3%)
JavaScript (5.23%)
SCSS (3.07%)
TypeScript (0.34%)
HTML (0.06%)
Cumulative downloads
Total Downloads
Last day
25%
5,092
Compared to previous day
Last week
25.9%
26,408
Compared to previous week
Last month
-0.4%
98,771
Compared to previous month
Last year
-27.1%
1,742,417
Compared to previous year
2
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:
Other forms of documentation are auto-generated:
1# npm 2npm i carbon-components-svelte 3 4# pnpm 5pnpm i carbon-components-svelte 6 7# Yarn 8yarn add carbon-components-svelte 9 10# Bun 11bun add carbon-components-svelte
Before importing components, you will need to first apply Carbon component styles. The Carbon Design System supports five themes (2 light, 3 dark).
Each StyleSheet is generated from the flagship carbon-components library.
The compiled CSS is generated from the following .scss
files:
1// White theme 2import "carbon-components-svelte/css/white.css"; 3 4// Gray 10 theme 5import "carbon-components-svelte/css/g10.css"; 6 7// Gray 80 theme 8import "carbon-components-svelte/css/g80.css"; 9 10// Gray 90 theme 11import "carbon-components-svelte/css/g90.css"; 12 13// Gray 100 theme 14import "carbon-components-svelte/css/g100.css"; 15 16// All themes 17import "carbon-components-svelte/css/all.css";
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.
Use the "all.css" StyleSheet for dynamic, client-side theming.
1import "carbon-components-svelte/css/all.css";
Update the theme by setting the theme
attribute on the html
element. The default theme
is "white"
.
1<!doctype html> 2<html lang="en" theme="g10"> 3 <body> 4 ... 5 </body> 6</html>
Programmatically switch between each of the five Carbon themes by setting the "theme" attribute on the HTML element.
1<script> 2 let theme = "white"; // "white" | "g10" | "g80" | "g90" | "g100" 3 4 $: document.documentElement.setAttribute("theme", theme); 5</script>
Import components from carbon-components-svelte
in the script
tag of your Svelte file. Visit the documentation site for examples.
1<!-- App.svelte --> 2<script> 3 import { Accordion, AccordionItem } from "carbon-components-svelte"; 4</script> 5 6<Accordion> 7 <AccordionItem title="Section 1" open> Content 1 </AccordionItem> 8 <AccordionItem title="Section 2"> Content 2 </AccordionItem> 9 <AccordionItem title="Section 3"> Content 3 </AccordionItem> 10</Accordion>
Refer to COMPONENT_INDEX.md for component API documentation.
carbon-preprocess-svelte is a collection of Svelte preprocessors for Carbon.
[!NOTE] Using
carbon-preprocess-svelte
is optional and not a prerequisite for this library. It should be installed as a development dependency.
1# npm 2npm i -D carbon-preprocess-svelte 3 4# pnpm 5pnpm i -D carbon-preprocess-svelte 6 7# Yarn 8yarn add -D carbon-preprocess-svelte 9 10# Bun 11bun add -D carbon-preprocess-svelte
optimizeImports
optimizeImports
is a Svelte preprocessor that rewrites barrel imports from Carbon components/icons/pictograms packages to their source Svelte code paths. This can significantly speed up development and production build compile times while preserving typeahead and autocompletion offered by integrated development environments (IDE) like VS Code.
The preprocessor optimizes imports from the following packages:
Before & After
1- import { Button } from "carbon-components-svelte"; 2+ import Button from "carbon-components-svelte/src/Button/Button.svelte"; 3 4- import { Add } from "carbon-icons-svelte"; 5+ import Add from "carbon-icons-svelte/lib/Add.svelte"; 6 7- import { Airplane } from "carbon-pictograms-svelte"; 8+ import Airplane from "carbon-pictograms-svelte/lib/Airplane.svelte";
See examples for full configurations.
1// svelte.config.js 2import { optimizeImports } from "carbon-preprocess-svelte"; 3 4export default { 5 preprocess: [optimizeImports()], 6};
Any other preprocessors that transpile code in the script
block should be invoked before optimizeImports
.
For example, vitePreprocess
should precede optimizeImports
.
1// svelte.config.js 2+ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; 3import { optimizeImports } from "carbon-preprocess-svelte"; 4 5export default { 6 preprocess: [ 7+ vitePreprocess(), 8 optimizeImports() 9 ], 10};
optimizeCss
optimizeCss
is a Vite plugin that removes unused Carbon styles at build time. The plugin is compatible with Rollup (Vite extends the Rollup plugin API).
carbon-components-svelte@0.85.0
or greater is required.
1$ vite build 2 3Optimized index-CU4gbKFa.css 4- Before: 606.26 kB 5+ After: 53.22 kB (-91.22%) 6 7dist/index.html 0.34 kB │ gzip: 0.24 kB 8dist/assets/index-CU4gbKFa.css 53.22 kB │ gzip: 6.91 kB 9dist/assets/index-Ceijs3eO.js 53.65 kB │ gzip: 15.88 kB
[!NOTE] This is a plugin and not a Svelte preprocessor. It should be added to the list of
vite.plugins
. For Vite set-ups, this plugin is only run when building the app. For Rollup and Webpack, you should conditionally apply the plugin to only execute when building for production.
See examples for full configurations.
1// vite.config.js 2import { sveltekit } from "@sveltejs/kit/vite"; 3import { optimizeCss } from "carbon-preprocess-svelte"; 4import { defineConfig } from "vite"; 5 6export default defineConfig({ 7 plugins: [sveltekit(), optimizeCss()], 8});
TypeScript definitions are generated by sveld.
Refer to the Contributing guidelines.
This package uses IBM Telemetry to collect de-identified and anonymized metrics data in CI environments. By installing this package as a dependency you are agreeing to telemetry collection. To opt out, see Opting out of IBM Telemetry data collection. For more information on the data being collected, please see the IBM Telemetry documentation.
No vulnerabilities found.
No security vulnerabilities found.