Skip to content

Commit

Permalink
chore(docs): avoid stale persisted values
Browse files Browse the repository at this point in the history
Use a skeleton state to mask the initial render of applying persisted theme and icon size values.
  • Loading branch information
metonym committed Dec 30, 2023
1 parent 7dc900b commit 0e1f763
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
62 changes: 36 additions & 26 deletions docs/src/components/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Theme,
Select,
SelectItem,
SelectSkeleton,
LocalStorage,
} from "carbon-components-svelte";
import fuzzy from "fuzzy";
Expand All @@ -34,9 +35,7 @@
let theme = "white";
let iconSize = 16;
$: if (typeof document !== "undefined") {
document.documentElement.setAttribute("theme", theme);
}
$: mounted = typeof document !== "undefined";
let moduleName = null;
Expand Down Expand Up @@ -69,31 +68,35 @@
<Row>
<Column>
<div class="options">
<Theme
bind:theme
persist
render="select"
select={{
id: "select-theme",
size: "xl",
labelText: "Carbon theme",
themes: ["white", "g10", "g80", "g90", "g100"],
}}
/>
<LocalStorage key="icon-size" bind:value={iconSize} />
<Select
id="select-icon-size"
labelText="Icon size"
size="xl"
bind:selected={iconSize}
>
<SelectItem value={16} />
<SelectItem value={20} />
<SelectItem value={24} />
<SelectItem value={32} />
</Select>
{#if mounted}
<Theme
bind:theme
persist
render="select"
select={{
id: "select-theme",
labelText: "Carbon theme",
themes: ["white", "g10", "g80", "g90", "g100"],
}}
/>
<LocalStorage key="icon-size" bind:value={iconSize} />
<Select
id="select-icon-size"
labelText="Icon size"
bind:selected={iconSize}
>
<SelectItem value={16} />
<SelectItem value={20} />
<SelectItem value={24} />
<SelectItem value={32} />
</Select>
{:else}
<SelectSkeleton class="select-skeleton" />
<SelectSkeleton class="select-skeleton" />
{/if}
<Search
id="search"
size="lg"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
Expand Down Expand Up @@ -232,6 +235,13 @@
overflow-y: scroll;
}
:global(.select-skeleton) {
position: relative;
height: 64px;
top: 2px;
min-width: 6.42rem;
}
:global(#select-theme),
:global(#select-icon-size) {
min-width: 4rem;
Expand Down
1 change: 0 additions & 1 deletion docs/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Home from "../components/index.svelte";
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
Expand Down

0 comments on commit 0e1f763

Please sign in to comment.