mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
docs: update guidance on examples, usage
This commit is contained in:
parent
344f636484
commit
18f0ea4b35
7 changed files with 151 additions and 15 deletions
106
README.md
106
README.md
|
@ -5,38 +5,114 @@
|
||||||
|
|
||||||
> Svelte implementation of the [Carbon Design System](https://github.com/carbon-design-system)
|
> Svelte implementation of the [Carbon Design System](https://github.com/carbon-design-system)
|
||||||
|
|
||||||
## Getting Started
|
## Getting started
|
||||||
|
|
||||||
`carbon-components-svelte` can be installed as a development dependency.
|
`carbon-components-svelte` can be installed as a development dependency.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn add -D carbon-components-svelte
|
yarn add -D carbon-components-svelte
|
||||||
|
# OR
|
||||||
|
npm -i -D carbon-components-svelte
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
The quickest way to start is to use a template from the [examples](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.
|
||||||
|
|
||||||
|
- **[rollup](examples/rollup/)**: SPA bundled using [Rollup](https://github.com/rollup/rollup)
|
||||||
|
- **[rollup-typescript](examples/rollup-typescript/)**: SPA bundled using Rollup with TypeScript support
|
||||||
|
- **[routify](examples/routify/)**: SPA + static export using [Routify](https://github.com/roxiness/routify)
|
||||||
|
- **[sapper](examples/sapper/)**: SSR + static export using [Sapper](https://github.com/sveltejs/sapper)
|
||||||
|
- **[svite](examples/svite/)**: SPA developed with Svite, bundled with [Rollup](https://github.com/rollup/rollup)
|
||||||
|
- **[webpack](examples/webpack/)**: SPA bundled with [webpack](https://github.com/webpack/webpack)
|
||||||
|
|
||||||
|
### Scaffolding
|
||||||
|
|
||||||
|
Each example is published in a dedicated branch of the same name.
|
||||||
|
|
||||||
|
Use [degit](https://github.com/Rich-Harris/degit) to scaffold a new project:
|
||||||
|
|
||||||
|
For example, to use the `svite` template, run the following commands:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
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.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
|
<!-- App.svelte -->
|
||||||
<script>
|
<script>
|
||||||
import { Button } from "carbon-components-svelte";
|
import { Accordion, AccordionItem } from "carbon-components-svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<Accordion>
|
||||||
<link
|
<AccordionItem title="Section 1" open> Content 1 </AccordionItem>
|
||||||
rel="stylesheet"
|
<AccordionItem title="Section 2"> Content 2 </AccordionItem>
|
||||||
href="https://unpkg.com/carbon-components/css/carbon-components.min.css"
|
<AccordionItem title="Section 3"> Content 3 </AccordionItem>
|
||||||
/>
|
</Accordion>
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<Button>Primary</Button>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Refer to [COMPONENT_INDEX.md](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](scripts/build-css.js) from the flagship [carbon-components](https://github.com/carbon-design-system/carbon/tree/master/packages/components) library.
|
||||||
|
|
||||||
|
The [examples](examples/) use `all.css` for dynamic theming through CSS variables.
|
||||||
|
|
||||||
|
#### Usage
|
||||||
|
|
||||||
|
##### `svelte-preprocess`
|
||||||
|
|
||||||
|
The easiest way to import a StyleSheet is with [svelte-preprocess](https://github.com/sveltejs/svelte-preprocess).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const svelteOptions = {
|
||||||
|
preprocess: require("svelte-preprocess")(),
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```html
|
||||||
|
<!-- 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).
|
||||||
|
|
||||||
|
```js
|
||||||
|
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](examples/webpack/webpack.config.js) in [examples/webpack](examples/webpack).
|
||||||
|
|
||||||
### TypeScript support
|
### TypeScript support
|
||||||
|
|
||||||
This library ships with TypeScript definitions ([types/index.d.ts](types/index.d.ts)).
|
The component library ships with TypeScript definitions ([types/index.d.ts](types/index.d.ts)).
|
||||||
|
|
||||||
## Components
|
|
||||||
|
|
||||||
Refer to [COMPONENT_INDEX.md](COMPONENT_INDEX.md) for component documentation.
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,16 @@
|
||||||
|
|
||||||
> Example Rollup/TypeScript set-up scaffolded from the official [Svelte template](https://github.com/sveltejs/template).
|
> Example Rollup/TypeScript set-up scaffolded from the official [Svelte template](https://github.com/sveltejs/template).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Scaffold a new project using [degit](https://github.com/Rich-Harris/degit):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npx degit ibm/carbon-components-svelte#rollup-typescript svelte-app
|
||||||
|
cd svelte-app
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
## Available scripts
|
## Available scripts
|
||||||
|
|
||||||
### `yarn dev`
|
### `yarn dev`
|
||||||
|
|
|
@ -2,6 +2,16 @@
|
||||||
|
|
||||||
> Example set-up using [Rollup](https://github.com/rollup/rollup).
|
> Example set-up using [Rollup](https://github.com/rollup/rollup).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Scaffold a new project using [degit](https://github.com/Rich-Harris/degit):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npx degit ibm/carbon-components-svelte#rollup svelte-app
|
||||||
|
cd svelte-app
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
## Available scripts
|
## Available scripts
|
||||||
|
|
||||||
### `yarn dev`
|
### `yarn dev`
|
||||||
|
|
|
@ -2,6 +2,16 @@
|
||||||
|
|
||||||
> Example set-up using [Routify](https://github.com/roxiness/routify).
|
> Example set-up using [Routify](https://github.com/roxiness/routify).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Scaffold a new project using [degit](https://github.com/Rich-Harris/degit):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npx degit ibm/carbon-components-svelte#routify svelte-app
|
||||||
|
cd svelte-app
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
## Available scripts
|
## Available scripts
|
||||||
|
|
||||||
### `yarn dev`
|
### `yarn dev`
|
||||||
|
|
|
@ -2,6 +2,16 @@
|
||||||
|
|
||||||
> Example set-up using [Sapper](https://github.com/sveltejs/sapper).
|
> Example set-up using [Sapper](https://github.com/sveltejs/sapper).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Scaffold a new project using [degit](https://github.com/Rich-Harris/degit):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npx degit ibm/carbon-components-svelte#sapper svelte-app
|
||||||
|
cd svelte-app
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
## Available scripts
|
## Available scripts
|
||||||
|
|
||||||
### `yarn dev`
|
### `yarn dev`
|
||||||
|
|
|
@ -2,6 +2,16 @@
|
||||||
|
|
||||||
> Example set-up using [svite](https://github.com/dominikg/svite).
|
> Example set-up using [svite](https://github.com/dominikg/svite).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Scaffold a new project using [degit](https://github.com/Rich-Harris/degit):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npx degit ibm/carbon-components-svelte#svite svelte-app
|
||||||
|
cd svelte-app
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
## Available scripts
|
## Available scripts
|
||||||
|
|
||||||
### `yarn dev`
|
### `yarn dev`
|
||||||
|
|
|
@ -2,6 +2,16 @@
|
||||||
|
|
||||||
> Example set-up using [webpack](https://github.com/webpack/webpack).
|
> Example set-up using [webpack](https://github.com/webpack/webpack).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Scaffold a new project using [degit](https://github.com/Rich-Harris/degit):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npx degit ibm/carbon-components-svelte#webpack svelte-app
|
||||||
|
cd svelte-app
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
## Available scripts
|
## Available scripts
|
||||||
|
|
||||||
### `yarn dev`
|
### `yarn dev`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue