owncast/web/.storybook/preview.js

107 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-05-07 08:27:29 +02:00
import '../styles/variables.css';
import '../styles/global.less';
2022-04-19 23:33:43 +02:00
import '../styles/theme.less';
refactor(stories): co-locate stories with components (#2078) * refactor: move ActionButton component * refactor: move BanUserButton component * refactor: move ChatActionMessage component * refactor: move ChatContainer component * refactor: move AuthModal component * refactor: move BrowserNotifyModal component * refactor: move ChatUserMessage component * refactor: move ChatJoinMessage component * refactor: move ChatTextField component * refactor: move ChatUserBadge component * refactor: move FollowerCollection and SingleFollower components * fix: bad import path * refactor: move FollowModal component * refactor: move Modal component * refactor: move ContentHeader component * refactor: move ChatSystemMessage component * refactor: move Header component * refactor: move Footer component * refactor: move StatusBar component * refactor: move OfflineBanner component * refactor: move OwncastPlayer component * refactor: move IndieAuthModal component * refactor: move SocialLinks component * refactor: move VideoPoster component * refactor: move FollowModal component * refactor: move FediAuthModal.tsx component * refactor: move UserDropdown component * refactor: move ChatSocialMessage component * refactor: move Logo component * refactor: move NotifyReminderPopup component * refactor: move NameChangeModal component * refactor: move FatalErrorStateModal component * refactor: move ChatModeratorNotification component * refactor: move ChatModerationActionMenu and ChatModerationDetailsModal components * refactor: move CustomPageContent component * refactor: move storybook Introduction file * refactor: update storybook story import path * refactor: move storybook preview styles * refactor: move storybook doc pages * refactor: move Color and ImageAsset components * fix: bad import path * fix: bad import path in story file
2022-09-03 20:38:52 +02:00
import './preview.scss';
2022-05-07 10:13:26 +02:00
import { themes } from '@storybook/theming';
2022-05-17 23:23:52 +02:00
import { DocsContainer } from './storybook-theme';
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
import _ from 'lodash';
/**
* Takes an entry of a viewport (from Object.entries()) and converts it
* into two entries, one for landscape and one for portrait.
*
* @template {string} Key
*
* @param {[Key, import('@storybook/addon-viewport/dist/ts3.9/models').Viewport]} entry
* @returns {Array<[`${Key}${'Portrait' | 'Landscape'}`, import('@storybook/addon-viewport/dist/ts3.9/models').Viewport]>}
*/
const convertToLandscapeAndPortraitEntries = ([objectKey, viewport]) => {
const pixelStringToNumber = str => parseInt(str.split('px')[0]);
const dimensions = [viewport.styles.width, viewport.styles.height].map(pixelStringToNumber);
const minDimension = Math.min(...dimensions);
const maxDimension = Math.max(...dimensions);
return [
[
`${objectKey}Portrait`,
{
...viewport,
name: viewport.name + ' (Portrait)',
styles: {
...viewport.styles,
height: maxDimension + 'px',
width: minDimension + 'px',
},
},
],
[
`${objectKey}Landscape`,
{
...viewport,
name: viewport.name + ' (Landscape)',
styles: {
...viewport.styles,
height: minDimension + 'px',
width: maxDimension + 'px',
},
},
],
];
};
/**
* Takes an object and a function f and returns a new object.
* f takes the original object's entries (key-value-pairs
* from Object.entries) and returns a list of new entries
* (also key-value-pairs). These new entries then form the
* result.
* @template {string | number} OriginalKey
* @template {string | number} NewKey
* @template OriginalValue
* @template OriginalValue
*
* @param {Record<OriginalKey, OriginalValue>} obj
* @param {(entry: [OriginalKey, OriginalValue], index: number, all: Array<[OriginalKey, OriginalValue]>) => Array<[NewKey, NewValue]>} f
* @returns {Record<NewKey, NevValue>}
*/
const flatMapObject = (obj, f) => Object.fromEntries(Object.entries(obj).flatMap(f));
2022-04-18 03:50:39 +02:00
export const parameters = {
fetchMock: {
mocks: [],
},
2022-04-18 03:50:39 +02:00
actions: { argTypesRegex: '^on[A-Z].*' },
2022-05-17 23:23:52 +02:00
docs: {
container: DocsContainer,
},
actions: { argTypesRegex: '^on[A-Z].*' },
viewMode: 'docs',
2022-04-18 03:50:39 +02:00
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
2022-05-17 23:23:52 +02:00
viewMode: 'docs',
2022-04-18 03:50:39 +02:00
},
2022-05-07 10:13:26 +02:00
darkMode: {
current: 'dark',
// Override the default dark theme
dark: {
...themes.dark,
appBg: '#171523',
brandImage: 'https://owncast.online/images/logo.svg',
brandTitle: 'Owncast',
brandUrl: 'https://owncast.online',
2022-05-17 23:23:52 +02:00
appContentBg: '#171523',
2022-05-07 10:13:26 +02:00
},
// Override the default light theme
light: { ...themes.normal },
},
viewport: {
// Take a bunch of viewports from the storybook addon and convert them
// to portrait + landscape. Keys are appended with 'Landscape' or 'Portrait'.
viewports: flatMapObject(INITIAL_VIEWPORTS, convertToLandscapeAndPortraitEntries),
},
2022-04-18 03:50:39 +02:00
};