Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/_github_pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ jobs:
strategy:
matrix:
include:
- package: workflows-lib
artifact: storybook
- package: workflows-lib-shared
artifact: storybook-shared
- package: workflows-ui
artifact: storybook-ui
- package: workflows-apollo
artifact: storybook-apollo
steps:
- name: Checkout Source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -82,7 +82,7 @@ jobs:
path: frontend/${{ matrix.package }}/storybook-static

publish_pages:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: github.event_name == 'push' && github.ref == 'refs/heads/production'
needs:
- lint_docs
- build_docs
Expand Down
3 changes: 1 addition & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "5.7.0",
"react-is": "18.3.1",
"storybook": "10.6.7"
"react-is": "18.3.1"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
Expand Down
782 changes: 418 additions & 364 deletions frontend/pnpm-lock.yaml

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions frontend/workflows-apollo/.storybook/ThemeSwapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useColorScheme } from "@mui/material/styles";
import * as React from "react";
import { useEffect } from "react";
import type { StoryContext } from "@storybook/react-vite";

export const TextLight = "Mode: Light";
export const TextDark = "Mode: Dark";
export const TextSystem = "Mode: System";

type ThemeMode = typeof TextLight | typeof TextDark | typeof TextSystem;

interface Globals {
themeMode?: ThemeMode;
}
interface ThemeSwapperProps {
context: StoryContext & {
globals: Globals;
};
children: React.ReactNode;
}

const ThemeSwapper = ({ context, children }: ThemeSwapperProps) => {
const { mode, systemMode, setMode } = useColorScheme();

const selectedThemeMode = context.globals.themeMode ?? TextSystem;

useEffect(() => {
const targetMode =
selectedThemeMode === TextLight
? "light"
: selectedThemeMode === TextDark
? "dark"
: "system";

if (mode !== targetMode) {
setMode(targetMode);
}
}, [selectedThemeMode, mode, systemMode, setMode]);

const resolvedMode = mode === "system" ? systemMode : mode;

return (
<div
style={{
backgroundColor: resolvedMode === "light" ? "#ffffff" : "#161820",
}}
>
{children}
</div>
);
};

export { ThemeSwapper };
8 changes: 8 additions & 0 deletions frontend/workflows-apollo/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
stories: ["../**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: ["@storybook/addon-docs", "storybook-addon-apollo-client"],
framework: "@storybook/react-vite",
};
export default config;
87 changes: 87 additions & 0 deletions frontend/workflows-apollo/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from "react";
import { CssBaseline } from "@mui/material";
import "./storybook.css"; /* Storybook CSS override */
import { ThemeProvider } from "@mui/material";
import { DiamondDSTheme } from "@diamondlightsource/sci-react-ui";
import { ThemeSwapper, TextLight, TextDark } from "./ThemeSwapper";
import { Decorator, definePreview } from "@storybook/react-vite";
import { ApolloClient, InMemoryCache } from "@apollo/client";
import apolloClient from "storybook-addon-apollo-client";
import { MockLink } from "@apollo/client/testing";
import addonDocs from "@storybook/addon-docs";

const TextThemeDiamondDS = "Theme: DiamondDS";

export const decorators: Decorator[] = [];

export default definePreview({
decorators: [
(StoriesWithPadding: React.FC) => {
return (
<div style={{ padding: "2em" }}>
<StoriesWithPadding />
</div>
);
},
(Story, context) => {
const disableThemeSwapper =
context.parameters.disableThemeSwapper === true;
return (
<ThemeProvider theme={DiamondDSTheme}>
<CssBaseline />

{disableThemeSwapper ? (
<Story />
) : (
<ThemeSwapper context={context}>
<Story />
</ThemeSwapper>
)}
</ThemeProvider>
);
},
],
globalTypes: {
themeMode: {
description: "Global theme mode for components",
toolbar: {
title: "Theme Mode",
icon: "mirror",
items: [TextLight, TextDark],
dynamicTitle: true,
},
},
},
initialGlobals: {
theme: TextThemeDiamondDS,
},
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
backgrounds: { disable: true },
layout: "fullscreen",
},
argTypes: {
linkComponent: {
control: false,
},
},
addons: [
addonDocs(),
apolloClient({
createClient: ({
mocks = [],
}: {
mocks?: ReadonlyArray<MockLink.MockedResponse>;
}) =>
new ApolloClient({
cache: new InMemoryCache(),
link: new MockLink(mocks),
}),
}),
],
});
Loading