Skip to content

Commit

Permalink
fix preview and remove unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Jul 30, 2024
1 parent e2aa5d3 commit 151ed0c
Show file tree
Hide file tree
Showing 29 changed files with 37 additions and 838 deletions.
37 changes: 37 additions & 0 deletions webapp/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Preview } from '@storybook/angular';
import { withThemeByClassName } from '@storybook/addon-themes';
import { DocsContainer } from '@storybook/blocks';
import { createElement } from 'react';
import { themes } from '@storybook/core/theming';

const preview: Preview = {
parameters: {
Expand All @@ -10,6 +13,40 @@ const preview: Preview = {
},
},
backgrounds: { disable: true },
docs: {
// Fix for the DocsContainer theme
container: (props: any) => {
// Function to get the computed CSS variable value
const getCSSVariableValue = (variableName: string) => {
const el = document.createElement('div');
el.style.display = 'none';
el.style.setProperty('--dummy', 'initial');
document.body.appendChild(el);
const computedStyle = getComputedStyle(el);
const value = computedStyle.getPropertyValue(variableName);
document.body.removeChild(el);
return value.trim();
};

// Function to get the HSL value of the --background variable
const getBackgroundHSL = (theme: 'light' | 'dark') => {
document.documentElement.className = theme;
return getCSSVariableValue('--background');
};

// Fixing the theme for the DocsContainer
const el = document.querySelector("html");
const currentTheme = props?.context.store.globals.globals.theme;
el!.dataset['theme'] = currentTheme;
const theme = props?.context.store.globals.globals.theme === 'dark' ? themes.dark: themes.light;
const backgroundHSL = getBackgroundHSL(currentTheme);
props.theme = {
...theme,
appContentBg: `hsl(${backgroundHSL})`,
};
return createElement(DocsContainer, props);
},
},
},
decorators: [
withThemeByClassName({
Expand Down
5 changes: 0 additions & 5 deletions webapp/src/stories/.eslintrc.json

This file was deleted.

Loading

0 comments on commit 151ed0c

Please sign in to comment.