11import * as React from 'react' ;
22
33import { faker } from '@faker-js/faker/locale/en' ;
4- import type { Meta , StoryFn } from '@storybook/react-webpack5' ;
4+ import type { Meta , StoryObj } from '@storybook/react-webpack5' ;
55
66import { useUniqId } from '../../../hooks' ;
77import { Button } from '../../Button' ;
@@ -10,6 +10,7 @@ import {Dialog} from '../Dialog';
1010import type { DialogProps } from '../Dialog' ;
1111
1212import { DialogShowcase } from './DialogShowcase' ;
13+ import { DynamicHeightStory } from './DynamicHeightStory' ;
1314
1415export default {
1516 title : 'Components/Overlays/Dialog' ,
@@ -22,17 +23,31 @@ export default {
2223 type : 'boolean' ,
2324 } ,
2425 } ,
25- } as Meta < DialogProps > ;
26+ } as Meta ;
27+
28+ type Story = StoryObj < typeof Dialog > ;
2629
2730const largeTextLines = Array . from ( { length : 30 } , ( ) => faker . lorem . sentences ( ) ) ;
2831
32+ interface DialogComponentProps {
33+ buttonText : string ;
34+ content : React . ReactNode ;
35+ showError ?: boolean ;
36+ withHeader ?: boolean ;
37+ withFooter ?: boolean ;
38+ withEmptyBody ?: boolean ;
39+ }
40+
2941function DialogComponent ( {
3042 buttonText,
3143 content,
32- showError,
44+ showError = false ,
45+ withHeader = true ,
46+ withFooter = true ,
47+ withEmptyBody = false ,
3348 ...args
34- } : DialogProps & { buttonText : string ; content : React . ReactNode ; showError : boolean } ) {
35- const titleId = useUniqId ( ) ;
49+ } : DialogProps & DialogComponentProps ) {
50+ const headerId = useUniqId ( ) ;
3651 const [ open , setOpen ] = React . useState ( false ) ;
3752 return (
3853 < React . Fragment >
@@ -45,55 +60,86 @@ function DialogComponent({
4560 onEnterKeyDown = { ( ) => {
4661 alert ( 'onEnterKeyDown' ) ;
4762 } }
48- aria-labelledby = { titleId }
63+ aria-labelledby = { withHeader ? headerId : undefined }
4964 >
50- < Dialog . Header caption = "Header" id = { titleId } />
65+ { withHeader && < Dialog . Header caption = "Header" id = { headerId } /> }
5166 < Dialog . Body >
52- < div
53- style = { {
54- background : 'var(--g-color-base-generic)' ,
55- border : '1px var(--g-color-line-generic) dashed' ,
56- borderRadius : 5 ,
57- padding : 10 ,
58- display : 'flex' ,
59- flexDirection : 'column' ,
60- alignItems : 'center' ,
61- justifyContent : 'center' ,
62- minHeight : 60 ,
63- } }
64- >
65- { content }
66- </ div >
67+ { withEmptyBody ? null : (
68+ < div
69+ style = { {
70+ background : 'var(--g-color-base-generic)' ,
71+ border : '1px var(--g-color-line-generic) dashed' ,
72+ borderRadius : 5 ,
73+ padding : 10 ,
74+ display : 'flex' ,
75+ flexDirection : 'column' ,
76+ alignItems : 'center' ,
77+ justifyContent : 'center' ,
78+ minWidth : 280 ,
79+ minHeight : 60 ,
80+ } }
81+ >
82+ { content }
83+ </ div >
84+ ) }
6785 </ Dialog . Body >
68- < Dialog . Footer
69- onClickButtonCancel = { ( ) => setOpen ( false ) }
70- onClickButtonApply = { ( ) => alert ( 'onApply' ) }
71- textButtonApply = "Apply"
72- textButtonCancel = "Cancel"
73- showError = { showError }
74- errorText = "Error text"
75- />
86+ { withFooter && (
87+ < Dialog . Footer
88+ onClickButtonCancel = { ( ) => setOpen ( false ) }
89+ onClickButtonApply = { ( ) => alert ( 'onApply' ) }
90+ textButtonApply = "Apply"
91+ textButtonCancel = "Cancel"
92+ showError = { showError }
93+ errorText = "Error text"
94+ />
95+ ) }
7696 </ Dialog >
7797 </ React . Fragment >
7898 ) ;
7999}
80100
81- export const Default : StoryFn < DialogProps & { showError : boolean } > = ( args ) => {
82- return (
83- < Flex gap = { 5 } direction = "column" wrap >
84- < DialogComponent buttonText = "Show small dialog" content = "Content" { ...args } />
85- < DialogComponent
86- buttonText = "Show large dialog"
87- content = { largeTextLines . map ( ( text , index ) => (
88- < div key = { index } style = { { padding : 10 } } >
89- { text }
90- </ div >
91- ) ) }
92- { ...args }
93- />
94- </ Flex >
95- ) ;
101+ export const Default : Story = {
102+ render : ( args ) => {
103+ return (
104+ < Flex gap = { 5 } direction = "column" wrap >
105+ < DialogComponent buttonText = "Normal" content = "Content" { ...args } />
106+ < DialogComponent
107+ buttonText = "Large content"
108+ content = { largeTextLines . map ( ( text , index ) => (
109+ < div key = { index } style = { { padding : 10 } } >
110+ { text }
111+ </ div >
112+ ) ) }
113+ { ...args }
114+ />
115+ < DialogComponent
116+ buttonText = "Without Header"
117+ withHeader = { false }
118+ content = "Content"
119+ hasCloseButton = { false }
120+ { ...args }
121+ />
122+ < DialogComponent
123+ buttonText = "Without Footer"
124+ withFooter = { false }
125+ content = "Content"
126+ { ...args }
127+ />
128+ < DialogComponent
129+ buttonText = "With Empty Body"
130+ withEmptyBody = { true }
131+ content = "Content"
132+ { ...args }
133+ />
134+ </ Flex >
135+ ) ;
136+ } ,
96137} ;
97138
98- const ShowcaseTemplate : StoryFn = ( ) => < DialogShowcase /> ;
99- export const Showcase = ShowcaseTemplate . bind ( { } ) ;
139+ export const DynamicHeight : Story = {
140+ render : ( args ) => < DynamicHeightStory { ...args } /> ,
141+ } ;
142+
143+ export const Showcase : Story = {
144+ render : ( ) => < DialogShowcase /> ,
145+ } ;
0 commit comments