import React, { useEffect, useRef, useState } from 'react'; import { ComponentStory, ComponentMeta } from '@storybook/react'; import { DISPLAY, JustifyContent, AlignItems, BLOCK_SIZES, TextVariant, TEXT_ALIGN, } from '../../../helpers/constants/design-system'; import Box from '../../ui/box'; import { Button, Text } from '..'; import { ModalContent } from './modal-content'; import { ModalContentSize } from './modal-content.types'; import README from './README.mdx'; export default { title: 'Components/ComponentLibrary/ModalContent', component: ModalContent, parameters: { docs: { page: README, }, }, argTypes: { className: { control: 'text', }, children: { control: 'text', }, size: { control: 'select', options: Object.values(ModalContentSize).map((value) => value.toLowerCase(), ), }, }, args: { children: 'Modal Content', }, } as ComponentMeta; const Template: ComponentStory = (args) => ( ); export const DefaultStory = Template.bind({}); DefaultStory.storyName = 'Default'; /* * !!TODO: Replace with ModalHeader component */ const ModalHeader = () => ( <> Modal Header ); export const Children: ComponentStory = (args) => ( Lorem ipsum dolor sit amet consectetur adipisicing elit. Distinctio, reiciendis assumenda dolorum mollitia saepe, optio at aliquam molestias omnis quae corporis nesciunt natus, quas tempore ut ullam eaque fuga. Velit. ); export const Size: ComponentStory = (args) => ( <> ModalContentSize.Sm default and only size 360px max-width Using width Box props and responsive array props
[ BLOCK_SIZES.FULL, BLOCK_SIZES.THREE_FOURTHS, BLOCK_SIZES.HALF, BLOCK_SIZES.ONE_THIRD, ]
Adding a className and setting a max width (max-width: 800px) ); export const ModalContentRef: ComponentStory = (args) => { const [show, setShow] = useState(false); const modalContentRef = useRef(null); const handleClickOutside = (event: MouseEvent) => { if ( modalContentRef?.current && !modalContentRef.current.contains(event.target as Node) ) { setShow(false); } }; useEffect(() => { document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, []); return ( <> {show && ( Click outside of this ModalContent to close )} ); };