mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
docs: build carbon themes using sass
This commit is contained in:
parent
9aa01ce5fb
commit
e2c8ea6d76
10 changed files with 808 additions and 28 deletions
1
docs/.gitignore
vendored
1
docs/.gitignore
vendored
|
@ -5,3 +5,4 @@
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
/cypress/screenshots/
|
/cypress/screenshots/
|
||||||
/__sapper__/
|
/__sapper__/
|
||||||
|
static/style.css
|
|
@ -29,6 +29,14 @@ yarn link "carbon-components-svelte"
|
||||||
yarn install
|
yarn install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Before starting development, you will need to build the Carbon-themed CSS StyleSheet once.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
node scripts/carbon-theme
|
||||||
|
```
|
||||||
|
|
||||||
|
A file containing the four Carbon themes will be outputted to `static/style.css`. Do not check this file into source control.
|
||||||
|
|
||||||
## Available Scripts
|
## Available Scripts
|
||||||
|
|
||||||
### `yarn dev`
|
### `yarn dev`
|
||||||
|
|
|
@ -13,9 +13,13 @@
|
||||||
"sirv": "^1.0.1"
|
"sirv": "^1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"autoprefixer": "^9.8.5",
|
||||||
|
"carbon-components": "^10.16.0",
|
||||||
"carbon-components-svelte": "../",
|
"carbon-components-svelte": "../",
|
||||||
"cypress": "^4.10.0",
|
"cypress": "^4.10.0",
|
||||||
|
"node-sass": "^4.14.1",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
|
"postcss": "^7.0.32",
|
||||||
"sapper": "^0.27.16",
|
"sapper": "^0.27.16",
|
||||||
"shx": "^0.3.2",
|
"shx": "^0.3.2",
|
||||||
"svelte": "^3.24.0",
|
"svelte": "^3.24.0",
|
||||||
|
|
55
docs/scripts/carbon-theme.js
Normal file
55
docs/scripts/carbon-theme.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
const fs = require("fs");
|
||||||
|
const sass = require("node-sass");
|
||||||
|
const autoprefixer = require("autoprefixer");
|
||||||
|
const postcss = require("postcss");
|
||||||
|
const { promisify } = require("util");
|
||||||
|
|
||||||
|
const writeFile = promisify(fs.writeFile);
|
||||||
|
const outFile = "./static/style.css";
|
||||||
|
|
||||||
|
async function generateCss() {
|
||||||
|
sass.render(
|
||||||
|
{
|
||||||
|
outFile,
|
||||||
|
omitSourceMapUrl: true,
|
||||||
|
data: `
|
||||||
|
$feature-flags: (
|
||||||
|
enable-css-custom-properties: true,
|
||||||
|
grid-columns-16: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
@import "node_modules/carbon-components/scss/globals/scss/_css--helpers.scss";
|
||||||
|
@import "node_modules/carbon-components/scss/globals/scss/vendor/@carbon/elements/scss/themes/_mixins.scss";
|
||||||
|
|
||||||
|
:root[carbon-theme="white"] { @include carbon--theme($carbon--theme--white, true); }
|
||||||
|
:root { @include carbon--theme($carbon--theme--g10, true); }
|
||||||
|
:root[carbon-theme="g90"] { @include carbon--theme($carbon--theme--g90, true); }
|
||||||
|
:root[carbon-theme="g100"] { @include carbon--theme($carbon--theme--g100, true); }
|
||||||
|
|
||||||
|
$css--font-face: true;
|
||||||
|
$css--helpers: true;
|
||||||
|
$css--body: true;
|
||||||
|
$css--use-layer: true;
|
||||||
|
$css--reset: true;
|
||||||
|
$css--default-type: true;
|
||||||
|
$css--plex: true;
|
||||||
|
|
||||||
|
@import "node_modules/carbon-components/scss/globals/scss/_css--reset.scss";
|
||||||
|
@import "node_modules/carbon-components/scss/globals/scss/_css--font-face.scss";
|
||||||
|
@import "node_modules/carbon-components/scss/globals/scss/_css--helpers.scss";
|
||||||
|
@import "node_modules/carbon-components/scss/globals/scss/_css--body.scss";
|
||||||
|
@import "node_modules/carbon-components/scss/globals/grid/_grid.scss";
|
||||||
|
@import "node_modules/carbon-components/scss/globals/scss/styles.scss";`,
|
||||||
|
},
|
||||||
|
async (error, result) => {
|
||||||
|
if (!error) {
|
||||||
|
const prefixed = await postcss([autoprefixer]).process(result.css, {
|
||||||
|
from: undefined,
|
||||||
|
});
|
||||||
|
await writeFile(outFile, prefixed.css);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
generateCss();
|
|
@ -7,8 +7,9 @@
|
||||||
HeaderNav,
|
HeaderNav,
|
||||||
HeaderNavItem,
|
HeaderNavItem,
|
||||||
HeaderUtilities,
|
HeaderUtilities,
|
||||||
HeaderActionLink
|
HeaderActionLink,
|
||||||
} from "carbon-components-svelte";
|
} from "carbon-components-svelte";
|
||||||
|
import Theme from "./Theme.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Header
|
<Header
|
||||||
|
|
29
docs/src/components/Theme.svelte
Normal file
29
docs/src/components/Theme.svelte
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<script>
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import { Select, SelectItem } from "carbon-components-svelte";
|
||||||
|
|
||||||
|
let theme = undefined;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
theme = localStorage.getItem("theme") || "g10";
|
||||||
|
});
|
||||||
|
|
||||||
|
$: if (theme) {
|
||||||
|
localStorage.setItem("theme", theme);
|
||||||
|
document.documentElement.setAttribute("carbon-theme", theme);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:global(.bx--select-input) {
|
||||||
|
width: auto;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<Select inline labelText="Theme" bind:selected={theme}>
|
||||||
|
<SelectItem value="white" text="White" />
|
||||||
|
<SelectItem value="g10" text="Gray 10" />
|
||||||
|
<SelectItem value="g90" text="Gray 90" />
|
||||||
|
<SelectItem value="g100" text="Gray 100" />
|
||||||
|
</Select>
|
|
@ -29,6 +29,10 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
:global(#sapper) {
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
:global(.bx--content) {
|
:global(.bx--content) {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import components from "./components/_components";
|
import Theme from "../components/Theme.svelte";
|
||||||
import { Link } from "carbon-components-svelte";
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1>Welcome</h1>
|
<h1>Welcome</h1>
|
||||||
|
|
||||||
{#each components as component}
|
<Theme />
|
||||||
<Link href="examples/{component.title}">{component.title}</Link>
|
|
||||||
{/each}
|
|
||||||
|
|
|
@ -9,10 +9,7 @@
|
||||||
|
|
||||||
<link rel="manifest" href="manifest.json" crossorigin="use-credentials" />
|
<link rel="manifest" href="manifest.json" crossorigin="use-credentials" />
|
||||||
<link rel="icon" type="image/png" href="favicon.png" />
|
<link rel="icon" type="image/png" href="favicon.png" />
|
||||||
<link
|
<link rel="stylesheet" href="style.css" />
|
||||||
rel="stylesheet"
|
|
||||||
href="https://unpkg.com/carbon-components/css/carbon-components.min.css"
|
|
||||||
/>
|
|
||||||
<title>Carbon Components Svelte</title>
|
<title>Carbon Components Svelte</title>
|
||||||
|
|
||||||
%sapper.styles% %sapper.head%
|
%sapper.styles% %sapper.head%
|
||||||
|
|
720
docs/yarn.lock
720
docs/yarn.lock
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue