2019-12-17 20:25:57 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { addDecorator, configure } from '@storybook/react';
|
2020-02-07 19:07:22 +00:00
|
|
|
import { withKnobs, boolean, optionsKnob } from '@storybook/addon-knobs';
|
2019-12-17 20:25:57 +00:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import * as styles from './styles.scss';
|
|
|
|
import messages from '../_locales/en/messages.json';
|
|
|
|
import { I18n } from '../sticker-creator/util/i18n';
|
2020-02-07 19:07:22 +00:00
|
|
|
import { ClassyProvider } from '../ts/components/PopperRootContext';
|
|
|
|
|
|
|
|
const optionsConfig = {
|
|
|
|
display: 'inline-radio',
|
|
|
|
};
|
|
|
|
|
2020-08-27 16:59:04 +00:00
|
|
|
const persistKnob = id => knob => {
|
|
|
|
const value = knob(localStorage.getItem(id));
|
|
|
|
localStorage.setItem(id, value);
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
2020-02-07 19:07:22 +00:00
|
|
|
const makeThemeKnob = pane =>
|
2020-08-27 16:59:04 +00:00
|
|
|
persistKnob(`${pane}-pane-theme`)(localValue =>
|
|
|
|
optionsKnob(
|
|
|
|
`${pane} Pane Theme`,
|
|
|
|
{ Light: '', Dark: classnames('dark-theme', styles.darkTheme) },
|
|
|
|
localValue || '',
|
|
|
|
optionsConfig,
|
|
|
|
`${pane} Pane`
|
|
|
|
)
|
2020-02-07 19:07:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const makeDeviceThemeKnob = pane =>
|
2020-08-27 16:59:04 +00:00
|
|
|
persistKnob(`${pane}-pane-device-theme`)(localValue =>
|
|
|
|
optionsKnob(
|
|
|
|
`${pane} Pane Device Theme`,
|
|
|
|
{ Android: '', iOS: 'ios-theme' },
|
|
|
|
localValue || '',
|
|
|
|
optionsConfig,
|
|
|
|
`${pane} Pane`
|
|
|
|
)
|
2020-02-07 19:07:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const makeModeKnob = pane =>
|
2020-08-27 16:59:04 +00:00
|
|
|
persistKnob(`${pane}-pane-mode`)(localValue =>
|
|
|
|
optionsKnob(
|
|
|
|
`${pane} Pane Mode`,
|
|
|
|
{ Mouse: 'mouse-mode', Keyboard: 'keyboard-mode' },
|
|
|
|
localValue || 'mouse-mode',
|
|
|
|
optionsConfig,
|
|
|
|
`${pane} Pane`
|
|
|
|
)
|
2020-02-07 19:07:22 +00:00
|
|
|
);
|
2019-12-17 20:25:57 +00:00
|
|
|
|
|
|
|
addDecorator(withKnobs);
|
|
|
|
|
|
|
|
addDecorator((storyFn /* , context */) => {
|
|
|
|
const contents = storyFn();
|
2020-02-07 19:07:22 +00:00
|
|
|
const firstPaneTheme = makeThemeKnob('First');
|
|
|
|
const firstPaneDeviceTheme = makeDeviceThemeKnob('First');
|
|
|
|
const firstPaneMode = makeModeKnob('First');
|
|
|
|
|
2020-08-27 16:59:04 +00:00
|
|
|
const secondPane = persistKnob('second-pane-active')(localValue =>
|
|
|
|
boolean('Second Pane Active', localValue !== 'false', 'Second Pane')
|
|
|
|
);
|
2020-02-07 19:07:22 +00:00
|
|
|
|
|
|
|
const secondPaneTheme = makeThemeKnob('Second');
|
|
|
|
const secondPaneDeviceTheme = makeDeviceThemeKnob('Second');
|
|
|
|
const secondPaneMode = makeModeKnob('Second');
|
2019-12-17 20:25:57 +00:00
|
|
|
|
2020-06-26 00:08:58 +00:00
|
|
|
// Adding it to the body as well so that we can cover modals and other
|
|
|
|
// components that are rendered outside of this decorator container
|
|
|
|
if (firstPaneTheme === '') {
|
|
|
|
document.body.classList.remove('dark-theme');
|
|
|
|
} else {
|
|
|
|
document.body.classList.add('dark-theme');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firstPaneDeviceTheme === '') {
|
|
|
|
document.body.classList.remove('ios-theme');
|
|
|
|
} else {
|
|
|
|
document.body.classList.add('ios-theme');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firstPaneMode === 'mouse-mode') {
|
|
|
|
document.body.classList.remove('keyboard-mode');
|
|
|
|
document.body.classList.add('mouse-mode');
|
|
|
|
} else {
|
|
|
|
document.body.classList.remove('mouse-mode');
|
|
|
|
document.body.classList.add('keyboard-mode');
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:25:57 +00:00
|
|
|
return (
|
|
|
|
<div className={styles.container}>
|
2020-02-07 19:07:22 +00:00
|
|
|
<ClassyProvider themes={['dark']}>
|
2020-02-06 19:28:01 +00:00
|
|
|
<div
|
2020-02-07 19:07:22 +00:00
|
|
|
className={classnames(
|
|
|
|
styles.panel,
|
|
|
|
firstPaneTheme,
|
|
|
|
firstPaneDeviceTheme,
|
|
|
|
firstPaneMode
|
|
|
|
)}
|
2020-02-06 19:28:01 +00:00
|
|
|
>
|
|
|
|
{contents}
|
|
|
|
</div>
|
2020-02-07 19:07:22 +00:00
|
|
|
</ClassyProvider>
|
|
|
|
{secondPane ? (
|
|
|
|
<div
|
|
|
|
className={classnames(
|
|
|
|
styles.panel,
|
|
|
|
secondPaneTheme,
|
|
|
|
secondPaneDeviceTheme,
|
|
|
|
secondPaneMode
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{contents}
|
|
|
|
</div>
|
|
|
|
) : null}
|
2019-12-17 20:25:57 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Hack to enable hooks in stories: https://github.com/storybookjs/storybook/issues/5721#issuecomment-473869398
|
|
|
|
addDecorator(Story => <Story />);
|
|
|
|
|
|
|
|
addDecorator(story => <I18n messages={messages}>{story()}</I18n>);
|
|
|
|
|
|
|
|
configure(() => {
|
2020-02-07 19:07:22 +00:00
|
|
|
// Load main app stories
|
|
|
|
const tsComponentsContext = require.context(
|
|
|
|
'../ts/components',
|
|
|
|
true,
|
|
|
|
/\.stories.tsx?$/
|
|
|
|
);
|
|
|
|
tsComponentsContext.keys().forEach(f => tsComponentsContext(f));
|
2020-08-28 02:11:24 +00:00
|
|
|
// Load sticker creator stories
|
|
|
|
const stickerCreatorContext = require.context(
|
|
|
|
'../sticker-creator',
|
|
|
|
true,
|
|
|
|
/\.stories\.tsx?$/
|
|
|
|
);
|
|
|
|
stickerCreatorContext.keys().forEach(f => stickerCreatorContext(f));
|
2019-12-17 20:25:57 +00:00
|
|
|
}, module);
|