// // Copyright 2023 DXOS.org // import { type Decorator } from '@storybook/react'; import React, { type FC, type PropsWithChildren, memo } from 'react'; import { type ClassNameValue, type ThemedClassName } from '@dxos/react-ui'; import { mx } from '@dxos/ui-theme'; export type ContainerProps = ThemedClassName; export type ContainerType = 'default' | 'fullscreen' | 'centered' | 'column'; export type WithLayoutProps = | FC | { classNames?: ClassNameValue; layout?: ContainerType; scroll?: boolean; }; /** * Adds layout container. */ export const withLayout = (props: WithLayoutProps = {}): Decorator => (Story) => { // Prevent re-rendering of the story. const MemoizedStory = memo(Story); if (typeof props === 'function') { const Container = props; return ( ); } else { const { layout = 'default', classNames, scroll } = props; const Container = layouts[layout] ?? layouts.fullscreen; return ( ); } }; const layouts: Record> = { default: ({ classNames, children }: ContainerProps) =>
{children}
, fullscreen: ({ classNames, children }: ContainerProps) => (
{children}
), centered: ({ classNames, children }: ContainerProps) => (
{children}
), column: ({ classNames, children }: ContainerProps) => (
{children}
), };