Skip to content

Commit 50f040a

Browse files
authored
Merge pull request #757 from lumapps/chore/fix-storybook-injected-props
chore(storybook): fix dark theme switcher & chromatic date override
2 parents 2947dae + 0a22eb1 commit 50f040a

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"build:angularjs": "yarn workspace @lumx/angularjs build",
7474
"build:storybook": "yarn workspace @lumx/react build:storybook",
7575
"chromatic": "npx chromatic -b build:storybook",
76-
"clean": "rm -rf packages/*/dist && lerna clean --yes && lerna run --stream clean",
76+
"clean": "rm -rf packages/*/dist; lerna clean --yes && lerna run --stream clean",
7777
"clean:git-hooks": "yarn husky uninstall",
7878
"format": "yarn format:code && yarn format:style",
7979
"format:style": "prettier-stylelint --prettier-last --write packages/**/*.{css,scss}",

packages/lumx-react/src/stories/generated/List/Demos.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
export default { title: 'LumX components/list/List Demos' };
55

66
export { App as Big } from './big';
7+
export { App as Clickable } from './clickable';
78
export { App as Huge } from './huge';
89
export { App as Paddings } from './paddings';
910
export { App as Regular } from './regular';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../site-demo/content/product/components/list/react/clickable.tsx

packages/lumx-react/storybook/story-block/StoryBlock.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ReactElement, useState } from 'react';
1+
import React, { ElementType, useState } from 'react';
22
import classNames from 'classnames';
33
import isChromatic from 'chromatic/isChromatic';
44
import { Alignment, Switch, Theme } from '@lumx/react';
@@ -10,21 +10,23 @@ import './index.scss';
1010
import 'focus-visible';
1111

1212
interface StoryBlockProps {
13-
children(p: { theme: Theme, today?: Date }): ReactElement;
13+
Story: ElementType;
14+
context: any;
1415
}
1516

1617
const CLASSNAME = 'story-block';
1718

1819
export const StoryBlock: React.FC<StoryBlockProps> = (props) => {
19-
const { children } = props;
20+
const { Story, context } = props;
2021

2122
const [theme, setTheme] = useState<Theme>(Theme.light);
23+
context.args.theme = theme;
2224
const toggleTheme = () => setTheme(theme === Theme.light ? Theme.dark : Theme.light);
2325

24-
if (isChromatic()) {
25-
// Hard code today date for chromatic.
26-
return children({ theme, today: new Date('May 25 2021 01:00') });
27-
}
26+
// Hard code today date for chromatic.
27+
context.args.today = isChromatic() ? new Date('May 25 2021 01:00') : new Date();
28+
29+
if (isChromatic()) return <Story />;
2830

2931
return (
3032
<div className={classNames(CLASSNAME, `${CLASSNAME}--theme-${theme}`)}>
@@ -41,7 +43,7 @@ export const StoryBlock: React.FC<StoryBlockProps> = (props) => {
4143
<MaterialThemeSwitcher theme={theme} />
4244
</div>
4345

44-
{children({ theme, today: new Date() })}
46+
<Story />
4547
</div>
4648
);
4749
};

packages/lumx-react/storybook/story-block/decorator.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ import React from 'react';
22

33
import { StoryBlock } from './StoryBlock';
44

5-
export const withStoryBlockDecorator = (storyFn) => <StoryBlock>{storyFn}</StoryBlock>;
5+
export const withStoryBlockDecorator = (Story, context) => {
6+
return <StoryBlock Story={Story} context={context}/>;
7+
};

0 commit comments

Comments
 (0)