1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| import React, { useState } from 'react'; import { Meta, StoryObj } from '@storybook/react'; import { Modal } from '@hardyhu-ui/core'; import { Button } from '@hardyhu-ui/core';
const meta: Meta<typeof Modal> = { title: 'Components/Modal', component: Modal, argTypes: { isOpen: { control: 'boolean', description: 'Controls modal visibility', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, }, }, size: { control: { type: 'select' }, options: ['small', 'medium', 'large', 'full'], description: 'Modal size', table: { type: { summary: 'string' }, defaultValue: { summary: 'medium' }, }, }, animation: { control: { type: 'select' }, options: ['scale', 'fade', 'slide'], description: 'Animation type', table: { type: { summary: 'string' }, defaultValue: { summary: 'scale' }, }, }, title: { control: 'text', description: 'Modal title', }, closeOnOutsideClick: { control: 'boolean', description: 'Whether to close when clicking outside', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'true' }, }, }, closeOnEscape: { control: 'boolean', description: 'Whether to close when pressing Escape key', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'true' }, }, }, centeredFooter: { control: 'boolean', description: 'Center aligns footer content', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'false' }, }, }, showCloseButton: { control: 'boolean', description: 'Show close button in header', table: { type: { summary: 'boolean' }, defaultValue: { summary: 'true' }, }, }, onClose: { action: 'closed' }, }, parameters: { docs: { description: { component: 'A customizable modal component with different sizes and animations.', }, }, }, };
export default meta; type Story = StoryObj<typeof Modal>;
const ModalExample = (args: any) => { const [isOpen, setIsOpen] = useState(false);
return ( <> <Button onClick={() => setIsOpen(true)}>Open Modal</Button> <Modal {...args} isOpen={isOpen} onClose={() => setIsOpen(false)} footer={ <> <Button variant="outline" onClick={() => setIsOpen(false)}>Cancel</Button> <Button onClick={() => setIsOpen(false)}>Confirm</Button> </> } > {args.children} </Modal> </> ); };
export const Basic: Story = { render: (args) => ( <ModalExample {...args} title="Basic Modal"> <p>This is a basic modal with a title and footer buttons.</p> <p>Click outside or press Escape to close it.</p> </ModalExample> ), };
export const Sizes: Story = { render: () => ( <div style={{ display: 'flex', gap: '1rem' }}> <ModalExample size="small" title="Small Modal"> <p>This is a small modal dialog.</p> </ModalExample>
<ModalExample size="medium" title="Medium Modal"> <p>This is a medium modal dialog (default size).</p> </ModalExample>
<ModalExample size="large" title="Large Modal"> <p>This is a large modal dialog with more space for content.</p> </ModalExample>
<ModalExample size="full" title="Full Modal"> <p>This is a full-size modal that takes up most of the viewport.</p> </ModalExample> </div> ), };
export const NoHeader: Story = { render: () => ( <ModalExample showCloseButton={false}> <p>This modal has no header or title.</p> <p>You can close it by clicking outside or using the footer buttons.</p> </ModalExample> ), };
export const LongContent: Story = { render: () => ( <ModalExample title="Modal with Scrollable Content"> <div> <p>This modal contains long content that will scroll.</p> {Array(20).fill(0).map((_, i) => ( <p key={i}>This is paragraph {i + 1} to demonstrate scrolling behavior.</p> ))} </div> </ModalExample> ), };
export const CenteredFooter: Story = { render: () => ( <ModalExample title="Centered Footer Buttons" centeredFooter={true}> <p>This modal has its footer buttons centered instead of right-aligned.</p> </ModalExample> ), };
export const Animations: Story = { render: () => ( <div style={{ display: 'flex', gap: '1rem' }}> <ModalExample animation="scale" title="Scale Animation"> <p>This modal uses the default scale animation.</p> </ModalExample>
<ModalExample animation="fade" title="Fade Animation"> <p>This modal uses a simple fade animation.</p> </ModalExample>
<ModalExample animation="slide" title="Slide Animation"> <p>This modal slides up from below.</p> </ModalExample> </div> ), };
export const CustomDialogExample: Story = { render: () => ( <ModalExample title="Confirm Action" size="small" footer={ <> <Button variant="outline" onClick={() => alert('Action cancelled')}>No, Cancel</Button> <Button variant="primary" onClick={() => alert('Action confirmed!')}>Yes, Proceed</Button> </> } > <div style={{ textAlign: 'center', padding: '1rem 0' }}> <div style={{ fontSize: '3rem', marginBottom: '1rem' }}>⚠️</div> <p style={{ fontWeight: 'bold' }}>Are you sure you want to proceed with this action?</p> <p>This action cannot be undone.</p> </div> </ModalExample> ), };
|