chore(examples): add routify set-up

This commit is contained in:
Eric Liu 2020-09-07 14:51:19 -07:00
commit 1d479eb835
16 changed files with 2885 additions and 0 deletions

View file

@ -0,0 +1,6 @@
<script>
import { Router } from "@sveltech/routify";
import { routes } from "../.routify/routes";
</script>
<Router routes="{routes}" />

View file

@ -0,0 +1,65 @@
<script>
export let persist = false;
export let persistKey = "theme";
export let theme = "white";
export const themes = ["white", "g10", "g90", "g100"];
import { onMount, afterUpdate, setContext } from "svelte";
import { writable, derived } from "svelte/store";
const isValidTheme = (value) => themes.includes(value);
const isDark = (value) =>
isValidTheme(value) && (value === "g90" || value === "g100");
const carbon_theme = writable(theme);
const dark = writable(isDark(theme));
const light = derived(dark, (_) => !_);
const unsubscribe = carbon_theme.subscribe((value) => {
theme = value;
});
setContext("Theme", {
updateVar: (name, value) => {
document.documentElement.style.setProperty(name, value);
},
carbon_theme,
dark,
light,
});
onMount(() => {
try {
const persisted_theme = localStorage.getItem(persistKey);
if (isValidTheme(persisted_theme)) {
carbon_theme.set(persisted_theme);
}
} catch (error) {
console.error(error);
}
return () => {
unsubscribe();
};
});
afterUpdate(() => {
if (isValidTheme(theme)) {
document.documentElement.setAttribute("theme", theme);
if (persist) {
localStorage.setItem(persistKey, theme);
}
} else {
console.warn(
`"${theme}" is not a valid Carbon theme. Choose from available themes: ${JSON.stringify(
themes
)}`
);
}
});
$: dark.set(isDark(theme));
</script>
<slot />

View file

@ -0,0 +1,6 @@
import HMR from "@sveltech/routify/hmr";
import App from "./App.svelte";
const app = HMR(App, { target: document.body }, "routify-app");
export default app;

View file

@ -0,0 +1,14 @@
<script>
import { url } from "@sveltech/routify";
import { Row, Column, Link } from "carbon-components-svelte";
</script>
<Row>
<Column lg="{16}">
<h1>404</h1>
<div>
Page not found.
<Link inline href="{$url('..')}">Return home</Link>
</div>
</Column>
</Row>

View file

@ -0,0 +1,19 @@
<script>
import { metatags, page } from "@sveltech/routify";
import { Content, Grid } from "carbon-components-svelte";
import Navigation from "./_navigation.svelte";
import Theme from "../components/Theme.svelte";
</script>
<style lang="scss" global>
@import "carbon-components-svelte/css/all";
</style>
<Theme persist theme="g10">
<Navigation />
<Content style="background: none; padding: 1rem">
<Grid>
<slot />
</Grid>
</Content>
</Theme>

View file

@ -0,0 +1,35 @@
<script>
import {
SkipToContent,
Header,
HeaderUtilities,
HeaderGlobalAction,
} from "carbon-components-svelte";
import Notification20 from "carbon-icons-svelte/lib/Notification20";
import UserAvatar20 from "carbon-icons-svelte/lib/UserAvatar20";
import AppSwitcher20 from "carbon-icons-svelte/lib/AppSwitcher20";
import { getContext } from "svelte";
const ctx = getContext("Theme");
$: if (ctx) {
ctx.dark.subscribe((value) => {
console.log("dark mode?", value);
});
ctx.light.subscribe((value) => {
console.log("light mode?", value);
});
ctx.updateVar("--cds-productive-heading-06-font-size", "4rem");
}
</script>
<Header company="IBM" platformName="Carbon Components Svelte" href="/">
<div slot="skip-to-content">
<SkipToContent />
</div>
<HeaderUtilities>
<HeaderGlobalAction aria-label="Notifications" icon="{Notification20}" />
<HeaderGlobalAction aria-label="User Avatar" icon="{UserAvatar20}" />
<HeaderGlobalAction aria-label="App Switcher" icon="{AppSwitcher20}" />
</HeaderUtilities>
</Header>

View file

@ -0,0 +1,83 @@
<script>
import {
Breadcrumb,
BreadcrumbItem,
Grid,
Row,
Column,
Tabs,
TabContent,
Tab,
Select,
SelectItem,
} from "carbon-components-svelte";
import { getContext } from "svelte";
const { carbon_theme } = getContext("Theme");
</script>
<Row>
<Column lg="{16}">
<Breadcrumb noTrailingSlash aria-label="Page navigation">
<BreadcrumbItem href="/">Getting started</BreadcrumbItem>
</Breadcrumb>
<h1 style="margin-bottom: 1.5rem">Design &amp; build with Carbon</h1>
</Column>
</Row>
<Row>
<Column noGutter>
<Tabs aria-label="Tab navigation">
<Tab label="About" />
<Tab label="Design" />
<Tab label="Develop" />
<div slot="content" class="tabbed-content">
<Grid as fullWidth let:props>
<TabContent {...props}>
<Row>
<Column md="{4}" lg="{7}">
<Select
labelText="Carbon theme"
bind:selected="{$carbon_theme}"
style="margin-bottom: 1rem">
<SelectItem value="white" text="White" />
<SelectItem value="g10" text="Gray 10" />
<SelectItem value="g90" text="Gray 90" />
<SelectItem value="g100" text="Gray 100" />
</Select>
<p>
Carbon is IBMs open-source design system for digital products
and experiences. With the IBM Design Language as its
foundation, the system consists of working code, design tools
and resources, human interface guidelines, and a vibrant
community of contributors.
</p>
</Column>
</Row>
</TabContent>
<TabContent {...props}>
<Row>
<Column md="{4}" lg="{7}">
<p>
Rapidly build beautiful and accessible experiences. The Carbon
kit contains all resources you need to get started.
</p>
</Column>
</Row>
</TabContent>
<TabContent {...props}>
<Row>
<Column md="{4}" lg="{7}">
<p>
Carbon provides styles and components in Vanilla, React,
Angular, Vue and Svelte for anyone building on the web.
</p>
</Column>
</Row>
</TabContent>
</Grid>
</div>
</Tabs>
</Column>
</Row>