Skip to content

Commit

Permalink
Merge pull request #113 from oaknational/chore/PUPIL-439/storybook-theme
Browse files Browse the repository at this point in the history
chore(PUPIL-439): add some basic Oak branding to Storybook
  • Loading branch information
carlmw authored Feb 23, 2024
2 parents 0d35f2b + ec1c381 commit 5e693ae
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ const config = {
docs: {
autodocs: "tag",
},
staticDirs: ["./public"],
};
export default config;
4 changes: 4 additions & 0 deletions .storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<link
href="https://googleapis-fonts.thenational.academy/css2?family=Lexend:wght@300;400;600&display=swap"
rel="stylesheet"
/>
6 changes: 6 additions & 0 deletions .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { addons } from "@storybook/manager-api";
import { oakStorybookTheme } from "./oakStorybookTheme";

addons.setConfig({
theme: oakStorybookTheme,
});
43 changes: 43 additions & 0 deletions .storybook/oakStorybookTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { create } from "@storybook/theming/create";
import assert from "assert";

// @ts-expect-error: this is an svg
import brandImage from "../assets/logo.svg";
import { oakDefaultTheme } from "../src/styles/theme/default.theme";
import { OakUiRoleToken, oakColorTokens } from "../src/styles/theme/color";
import { oakBorderRadiusTokens } from "../src/styles/theme/borders";

export const oakStorybookTheme = create({
base: "light",
brandTitle: "Oak National Academy",
brandUrl: "https://www.thenational.academy",
brandImage,
fontBase: "Lexend, sans-serif",
colorPrimary: oakColorTokens.mint,
colorSecondary: oakColorTokens.oakGreen,

appBg: getUIColor("bg-decorative1-very-subdued"),
appBorderColor: getUIColor("border-neutral"),
appBorderRadius: oakBorderRadiusTokens["border-radius-m"],

textColor: getUIColor("text-primary"),
textInverseColor: getUIColor("text-inverted"),
textMutedColor: getUIColor("text-subdued"),

inputBorder: getUIColor("border-primary"),
inputTextColor: getUIColor("text-primary"),
inputBorderRadius: oakBorderRadiusTokens["border-radius-m"],

barTextColor: getUIColor("icon-inverted"),
barSelectedColor: getUIColor("icon-inverted"),
buttonBg: getUIColor("bg-btn-secondary"),
buttonBorder: getUIColor("border-primary"),
barHoverColor: getUIColor("text-primary"),
});

function getUIColor(uiColor: OakUiRoleToken) {
const colorName = oakDefaultTheme.uiColors[uiColor];
assert(colorName, `Color '${uiColor}' not found in theme`);

return oakColorTokens[colorName];
}
4 changes: 4 additions & 0 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<link
href="https://googleapis-fonts.thenational.academy/css2?family=Lexend:wght@300;400;600&display=swap"
rel="stylesheet"
/>
4 changes: 4 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Decorator, Preview } from "@storybook/react";

import { oakDefaultTheme } from "../src/styles/theme/default.theme";
import { OakGlobalStyle } from "../src/components/atoms/OakGlobalStyle/OakGlobalStyle";
import { oakStorybookTheme } from "./oakStorybookTheme";

const globalDecorator: Decorator = (Story, context) => {
return (
Expand All @@ -27,6 +28,9 @@ const preview: Preview = {
date: /Date$/i,
},
},
docs: {
theme: oakStorybookTheme,
},
},
decorators: [globalDecorator],
};
Expand Down
1 change: 1 addition & 0 deletions .storybook/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5e693ae

Please sign in to comment.