Skip to content

Commit

Permalink
feat: extend dark mode to entire Storybook UI
Browse files Browse the repository at this point in the history
  • Loading branch information
acd02 committed Oct 25, 2024
1 parent 81827f2 commit 87a5d5a
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 137 deletions.
58 changes: 58 additions & 0 deletions .storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<style>
body {
color: var(--colors-on-background) !important;
}

/* === LEFT SIDEBAR === */
#storybook-explorer-tree .sidebar-item {
color: var(--colors-on-background) !important;
}

#storybook-explorer-tree .sidebar-item[data-selected='true'] {
background: var(--colors-support) !important;
color: var(--colors-on-support) !important;
}

nav.sidebar-container {
background: var(--colors-background) !important;
}

nav.sidebar-container input {
color: var(--colors-on-background) !important;
}

nav.sidebar-container [role='combobox'] svg {
stroke: var(--colors-on-background) !important;
}

nav.sidebar-container ol[role='listbox'] mark {
color: var(--colors-main) !important;
}

nav.sidebar-container .sidebar-subheading {
color: var(--colors-on-background) !important;
}


/* === TOP STICKY BAR === */
.sb-bar {
background: var(--colors-background) !important;
color: var(--colors-on-background) !important;
}

.sb-bar button {
background-color: var(--colors-surface-inverse) !important;
color: var(--colors-on-surface-inverse) !important;
}


/* === THEME PICKER WIDGET (INSIDE TOP STICKY BAR) === */
[data-testid='tooltip'] {
background-color: var(--colors-surface-inverse) !important;
color: var(--colors-on-surface-inverse) !important;
}

[data-testid='tooltip'] span {
color: var(--colors-on-surface-inverse) !important;
}
</style>
4 changes: 1 addition & 3 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { addons } from '@storybook/manager-api'

import { defaultTheme } from '@spark-ui/theme-utils'

import { getTheme } from './theme/getTheme.js'

addons.setConfig({
theme: getTheme({ base: 'light' }),
sidebar: {
showRoots: true,
collapsedRoots: ['using-spark', 'hooks', 'contributing', 'experimental', 'utils'],
Expand Down
42 changes: 37 additions & 5 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,26 @@
}

.sbdocs-wrapper {
background: rgb(var(--colors-background)) !important;
color: rgb(var(--colors-on-background)) !important;
padding: 30px 20px !important;
}

.sbdocs-wrapper :where(p:not(.sb-anchor, .sb-unstyled, .sb-unstyled p)) {
color: rgb(var(--colors-on-background)) !important;
}

.sbdocs-wrapper :where(li:not(.sb-anchor, .sb-unstyled, .sb-unstyled li)) {
color: rgb(var(--colors-on-background)) !important;
}

.sbdocs-wrapper #spark-doc-container > h2,
.sbdocs-wrapper #spark-doc-container > h3,
.sbdocs-wrapper #spark-doc-container > h4,
.sbdocs-wrapper #spark-doc-container > h5 {
color: rgb(var(--colors-support)) !important;
}

.sbdocs-content {
display: grid !important;
grid-template-columns: 100% 0;
Expand All @@ -30,10 +47,6 @@
}
}

#spark-doc-container {
width: 100%;
}

.docblock-source {
border: 1px solid #ebebed7f !important;
box-shadow: none !important;
Expand All @@ -46,8 +59,12 @@
grid-template-columns: 100%;
}

#spark-doc-container {
width: 100%;
}

#spark-doc-container > h1 {
color: #EC5A13 !important;
color: #ec5a13 !important;
font-weight: 700 !important;
}

Expand All @@ -69,6 +86,21 @@
background-color: rgb(var(--colors-alert));
color: rgb(var(--colors-on-alert));
}

/* === ArgTypes TABLE === */
table.docblock-argstable thead th {
color: rgb(var(--colors-on-background)) !important;
}

table.docblock-argstable tbody td {
background-color: rgb(var(--colors-background)) !important;
color: rgb(var(--colors-on-background)) !important;
border-inline-start-color: rgb(var(--colors-neutral-container)) !important;
border-inline-end-color: rgb(var(--colors-neutral-container)) !important;
border-block-start-color: rgb(var(--colors-neutral-container)) !important;
border-block-end-color: rgb(var(--colors-neutral-container)) !important;
border-top-color: rgb(var(--colors-neutral-container)) !important;
}
</style>

<link href="/normalize.css" rel="stylesheet" />
12 changes: 12 additions & 0 deletions .storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ShareExpand } from '@spark-ui/icons/dist/icons/ShareExpand'

import '../src/tailwind.css'
import './sb-theming.css'

import {setSparkThemeCSSVariables} from './utils'
import { ToC } from '@docs/helpers/ToC'

const ExampleContainer = ({ children, ...props }) => {
Expand Down Expand Up @@ -91,6 +93,16 @@ export const decorators = [
if (!htmlElement) return
htmlElement.setAttribute("data-theme", globals.theme)


const parentDocument = parent.document;
const parentHTML = parentDocument.documentElement;
if (!parentHTML) return

const themeKey = globals.theme
parentHTML.setAttribute("data-theme", themeKey)

setSparkThemeCSSVariables(parentHTML, themeKey)

return storyFn()
},
(storyFn, { id, viewMode }) => {
Expand Down
80 changes: 0 additions & 80 deletions .storybook/sb-theming.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,3 @@
li:not(.sb-anchor, .sb-unstyled, .sb-unstyled li) kbd {
color: rgb(var(--colors-on-background));
}

[data-theme='light'] {
--colors-basic: 9 65 113;
--colors-on-basic: 255 255 255;
--colors-basic-hovered: 12 82 145;
--colors-basic-container: 230 242 253;
--colors-on-basic-container: 21 34 51;
--colors-basic-container-hovered: 244 249 254;
--colors-accent: 133 38 217;
--colors-on-accent: 255 255 255;
--colors-accent-hovered: 159 71 235;
--colors-accent-container: 233 214 250;
--colors-on-accent-container: 54 37 85;
--colors-accent-container-hovered: 245 237 253;
--colors-accent-variant: 80 23 130;
--colors-on-accent-variant: 255 255 255;
--colors-accent-variant-hovered: 107 31 173;
--colors-main: 236 90 19;
--colors-on-main: 255 255 255;
--colors-main-hovered: 240 123 66;
--colors-main-container: 255 233 222;
--colors-on-main-container: 137 56 15;
--colors-main-container-hovered: 255 242 235;
--colors-main-variant: 184 74 20;
--colors-on-main-variant: 255 255 255;
--colors-main-variant-hovered: 236 90 19;
--colors-support: 9 65 113;
--colors-on-support: 255 255 255;
--colors-support-hovered: 12 82 145;
--colors-support-container: 230 242 253;
--colors-on-support-container: 21 34 51;
--colors-support-container-hovered: 244 249 254;
--colors-support-variant: 12 82 145;
--colors-on-support-variant: 255 255 255;
--colors-support-variant-hovered: 15 105 185;
--colors-success: 62 122 64;
--colors-on-success: 255 255 255;
--colors-success-hovered: 78 152 80;
--colors-success-container: 220 234 220;
--colors-on-success-container: 47 91 48;
--colors-success-container-hovered: 237 245 238;
--colors-alert: 255 170 0;
--colors-on-alert: 32 39 48;
--colors-alert-hovered: 255 187 51;
--colors-alert-container: 255 238 204;
--colors-on-alert-container: 153 102 0;
--colors-alert-container-hovered: 255 246 229;
--colors-error: 217 52 38;
--colors-on-error: 255 255 255;
--colors-error-hovered: 224 93 82;
--colors-error-container: 247 215 212;
--colors-on-error-container: 130 32 23;
--colors-error-container-hovered: 251 236 235;
--colors-info: 19 136 236;
--colors-on-info: 255 255 255;
--colors-info-hovered: 105 178 243;
--colors-info-container: 194 224 250;
--colors-on-info-container: 12 82 145;
--colors-info-container-hovered: 230 242 253;
--colors-neutral: 79 96 118;
--colors-on-neutral: 255 255 255;
--colors-neutral-hovered: 108 129 157;
--colors-neutral-container: 240 242 245;
--colors-on-neutral-container: 58 71 87;
--colors-neutral-container-hovered: 246 248 249;
--colors-background: 255 255 255;
--colors-on-background: 21 34 51;
--colors-background-variant: 244 249 254;
--colors-on-background-variant: 21 34 51;
--colors-surface: 255 255 255;
--colors-on-surface: 21 34 51;
--colors-surface-hovered: 246 248 249;
--colors-surface-inverse: 43 52 65;
--colors-on-surface-inverse: 255 255 255;
--colors-surface-inverse-hovered: 58 71 87;
--colors-outline: 172 184 199;
--colors-outline-high: 32 39 48;
--colors-overlay: 32 39 48;
--colors-on-overlay: 255 255 255;
}
12 changes: 6 additions & 6 deletions .storybook/spark-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 10 additions & 41 deletions .storybook/theme/getTheme.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
import { create } from '@storybook/theming/create'
import logoUrl from '../spark-logo.svg'
import { create } from "@storybook/theming/create";
import logoUrl from "../spark-logo.svg";

// https://github.com/storybookjs/storybook/blob/next/code/lib/theming/src/types.ts
export const getTheme = ({ base, sparkTheme }) =>
create({
export const getTheme = ({ base }) => {
return create({
base,
// Brand
colorPrimary: sparkTheme.colors.main,
colorSecondary: sparkTheme.colors.support,

// UI
appBg: sparkTheme.colors.backgroundVariant,
appContentBg: sparkTheme.colors.background,
// appPreviewBg: TODO
appBorderColor: sparkTheme.colors.basicContainer,
appBorderRadius: sparkTheme.borderRadius.lg,

// Typography
fontBase: '"Nunito", sans-serif',
fontCode: 'monospace',

// Text colors
textColor: sparkTheme.colors.onBackground,
textInverseColor: sparkTheme.colors.background,
// textMutedColor: TODO
fontCode: "monospace",

// Toolbar default and active colors
barTextColor: sparkTheme.colors.onBackground,
barHoverColor: sparkTheme.colors.basicContainerHovered,
barSelectedColor: sparkTheme.colors.basicContainer,
barBg: sparkTheme.colors.backgroundVariant,

// Form colors
buttonBg: sparkTheme.colors.primary,
buttonBorder: 'transparent',
inputBg: 'transparent',
inputBorder: sparkTheme.colors.basic,
inputTextColor: sparkTheme.colors.basic,
inputBorderRadius: sparkTheme.borderRadius.sm,

brandTitle: 'Spark design system',
brandUrl: 'https://zeroheight.com/1186e1705/p/0879a9-colors/b/27d7a3',
brandTitle: "Spark design system",
brandUrl: "https://zeroheight.com/1186e1705/p/0879a9-colors/b/27d7a3",
brandImage: logoUrl,
brandTarget: '_self',

// gridCellSize?: TODO
})
brandTarget: "_self",
});
};
Loading

0 comments on commit 87a5d5a

Please sign in to comment.