Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/add Dialog stories #3751

Merged
merged 11 commits into from
Oct 10, 2023
Original file line number Diff line number Diff line change
@@ -1,52 +1,15 @@
import React, {useState, useRef, useCallback} from 'react'
import {Meta} from '@storybook/react'
import {BaseStyles, Box, ThemeProvider, useTheme} from '..'
import React, {useState, useCallback} from 'react'
import {ComponentMeta} from '@storybook/react'
import {Box, useTheme} from '..'
import {Button} from '../Button'
import {ActionMenu} from '../ActionMenu'
import {ActionList} from '../ActionList'
import {ConfirmationDialog, useConfirm} from '../Dialog/ConfirmationDialog'
import {ConfirmationDialog, useConfirm} from './ConfirmationDialog'

export default {
title: 'Components/ConfirmationDialog',
title: 'Components/ConfirmationDialog/Features',
component: ConfirmationDialog,
decorators: [
Story => {
// Since portal roots are registered globally, we need this line so that each storybook
// story works in isolation.
return (
<ThemeProvider>
<BaseStyles>
<Story />
</BaseStyles>
</ThemeProvider>
)
},
],
} as Meta

export const BasicConfirmationDialog = () => {
const [isOpen, setIsOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
const onDialogClose = useCallback(() => setIsOpen(false), [])
return (
<>
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
Show dialog
</Button>
{isOpen && (
<ConfirmationDialog
title="Delete universe?"
onClose={onDialogClose}
confirmButtonContent="Delete it!"
confirmButtonType="danger"
>
Deleting the universe could have disastrous effects, including but not limited to destroying all life on
Earth.
</ConfirmationDialog>
)}
</>
)
}
} as ComponentMeta<typeof ConfirmationDialog>

export const ShorthandHook = () => {
const confirm = useConfirm()
Expand Down
46 changes: 46 additions & 0 deletions src/ConfirmationDialog/ConfirmationDialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, {useCallback, useRef, useState} from 'react'
import {Meta} from '@storybook/react'
import {BaseStyles, Button, ThemeProvider} from '..'
import {ConfirmationDialog} from './ConfirmationDialog'

export default {
title: 'Components/ConfirmationDialog',
component: ConfirmationDialog,
decorators: [
Story => {
// Since portal roots are registered globally, we need this line so that each storybook
// story works in isolation.
return (
<ThemeProvider>
<BaseStyles>
<Story />
</BaseStyles>
</ThemeProvider>
)
},
],
} as Meta

export const Default = () => {
const [isOpen, setIsOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
const onDialogClose = useCallback(() => setIsOpen(false), [])
return (
<>
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
Show dialog
</Button>
{isOpen && (
<ConfirmationDialog
title="Delete universe?"
onClose={onDialogClose}
confirmButtonContent="Delete it!"
confirmButtonType="danger"
>
Deleting the universe could have disastrous effects, including but not limited to destroying all life on
Earth.
</ConfirmationDialog>
)}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ActionMenu} from '../deprecated/ActionMenu'
import BaseStyles from '../BaseStyles'
import Box from '../Box'
import Button from '../deprecated/Button/Button'
import {ConfirmationDialog, useConfirm} from '../Dialog/ConfirmationDialog'
import {ConfirmationDialog, useConfirm} from './ConfirmationDialog'
import theme from '../theme'
import {ThemeProvider} from '../ThemeProvider'
import {SSRProvider} from '../utils/ssr'
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('ConfirmationDialog', () => {
options: {skipAs: true, skipSx: true},
})

checkExports('Dialog/ConfirmationDialog', {
checkExports('ConfirmationDialog/ConfirmationDialog', {
default: undefined,
useConfirm,
ConfirmationDialog,
Expand Down
2 changes: 1 addition & 1 deletion src/DataTable/ErrorDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {ConfirmationDialog} from '../Dialog/ConfirmationDialog'
import {ConfirmationDialog} from '../ConfirmationDialog/ConfirmationDialog'

export type TableErrorDialogProps = React.PropsWithChildren<{
/**
Expand Down
145 changes: 145 additions & 0 deletions src/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import React, {useState, useRef, useCallback} from 'react'
import {Meta} from '@storybook/react'

import {BaseStyles, ThemeProvider} from '.'
import {Button} from './Button'
import {Dialog, DialogWidth, DialogHeight} from './Dialog/Dialog'

/* Dialog Version 1? */

export default {
title: 'Components/DialogV1',
component: Dialog,
decorators: [
Story => {
// Since portal roots are registered globally, we need this line so that each storybook
// story works in isolation.
return (
<ThemeProvider>
<BaseStyles>
<Story />
</BaseStyles>
</ThemeProvider>
)
},
],
args: {
width: 'xlarge',
height: 'auto',
subtitle: true,
},
argTypes: {
width: {
control: {
type: 'radio',
},
options: ['small', 'medium', 'large', 'xlarge'],
},
height: {
control: {
type: 'radio',
},
options: ['small', 'large', 'auto'],
},
subtitle: {
name: 'show subtitle',
control: {
type: 'boolean',
},
},
title: {table: {disable: true}},

renderHeader: {table: {disable: true}},
renderBody: {table: {disable: true}},
renderFooter: {table: {disable: true}},
onClose: {table: {disable: true}},
role: {table: {disable: true}},
ref: {table: {disable: true}},
key: {table: {disable: true}},
footerButtons: {table: {disable: true}},
},
} as Meta

const lipsum = (
<div style={{fontSize: '14px'}}>
<p style={{marginBlockStart: 0}}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sollicitudin mauris maximus elit sagittis, nec
lobortis ligula elementum. Nam iaculis, urna nec lobortis posuere, eros urna venenatis eros, vel accumsan turpis
nunc vitae enim. Maecenas et lorem lectus. Vivamus iaculis tortor eget ante placerat, nec posuere nisl tincidunt.
Cras condimentum ante in accumsan ultricies. Morbi quis porta est, sit amet congue augue. Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Ut consequat nunc id quam tempus, id tincidunt neque venenatis. Mauris
fringilla tempor est, vitae fermentum enim elementum vitae. Nullam eleifend odio ut porta efficitur. Phasellus
luctus tempus posuere.
</p>

<p>
Curabitur scelerisque bibendum faucibus. Duis rhoncus nunc est, at pharetra eros tristique a. Nam sodales turpis
lectus, quis faucibus felis fermentum in. Curabitur vel velit vel eros laoreet pharetra. Aenean in facilisis
sapien, eu porttitor ex. Donec ultrices ac arcu ut lobortis. Pellentesque vitae rutrum orci. Etiam pretium et enim
sit amet scelerisque. Nulla sed odio nec lorem dapibus condimentum at sagittis quam. Sed in ornare ex, sed luctus
sem. Mauris a est tellus.
</p>

<p>
Sed fringilla est ac urna aliquet, eget condimentum felis vulputate. Sed sagittis eros non mauris sodales
molestie. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Nullam ante leo,
condimentum sed lectus non, rutrum octopodes urna. Mauris neque ante, interdum molestie tellus pharetra, eleifend
dapibus justo. Sed at diam ligula. Donec dapibus ipsum quis elit euismod, sed suscipit eros euismod. Aliquam
pretium felis quis risus luctus fringilla. Ut purus lacus, mattis a turpis eget, sollicitudin pellentesque neque.
</p>

<p>
Nunc sodales quis ante quis porttitor. Vestibulum ornare lacinia ante. Donec a nisi nec arcu aliquam pretium in
nec nunc. Donec fringilla erat vitae viverra feugiat. Sed non odio vel ipsum porttitor maximus. Donec id eleifend
lectus. Proin varius felis sit amet neque eleifend, vitae porttitor ligula commodo.
</p>

<p>
Vivamus felis quam, porttitor a justo sit amet, placerat ultricies nisl. Suspendisse potenti. Maecenas non
consequat lorem, eu porta ante. Pellentesque elementum diam sapien, nec ultrices risus convallis eget. Nam
pharetra dolor at dictum tempor. Quisque ut est a ligula hendrerit sodales. Curabitur ornare a nulla in laoreet.
Maecenas semper mi egestas, dignissim nisi et, elementum neque.
</p>
</div>
)
interface DialogStoryProps {
width: DialogWidth
height: DialogHeight
subtitle: boolean
}
export const Default = ({width, height, subtitle}: DialogStoryProps) => {
const [isOpen, setIsOpen] = useState(false)
const [secondOpen, setSecondOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
const onDialogClose = useCallback(() => setIsOpen(false), [])
const onSecondDialogClose = useCallback(() => setSecondOpen(false), [])
const openSecondDialog = useCallback(() => setSecondOpen(true), [])
return (
<>
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
Show dialog
</Button>
{isOpen && (
<Dialog
title="My Dialog"
subtitle={subtitle ? 'This is a subtitle!' : undefined}
onClose={onDialogClose}
width={width}
height={height}
footerButtons={[
{buttonType: 'normal', content: 'Open Second Dialog', onClick: openSecondDialog},
{buttonType: 'danger', content: 'Delete the universe', onClick: onDialogClose},
{buttonType: 'primary', content: 'Proceed', onClick: openSecondDialog, autoFocus: true},
]}
>
{lipsum}
{secondOpen && (
<Dialog title="Inner dialog!" onClose={onSecondDialogClose} width="small">
Hello world
</Dialog>
)}
</Dialog>
)}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {Meta} from '@storybook/react'

import {BaseStyles, ThemeProvider, Box, TextInput} from '..'
import {Button} from '../Button'
import {Dialog, DialogProps, DialogWidth, DialogHeight} from '../Dialog/Dialog'
import {Dialog, DialogProps, DialogWidth, DialogHeight} from './Dialog'

/* Dialog Version 2 */

export default {
title: 'Components/Dialog',
title: 'Components/Dialog/Features',
component: Dialog,
decorators: [
Story => {
Expand Down Expand Up @@ -105,41 +107,6 @@ interface DialogStoryProps {
height: DialogHeight
subtitle: boolean
}
export const BasicDialog = ({width, height, subtitle}: DialogStoryProps) => {
const [isOpen, setIsOpen] = useState(false)
const [secondOpen, setSecondOpen] = useState(false)
const buttonRef = useRef<HTMLButtonElement>(null)
const onDialogClose = useCallback(() => setIsOpen(false), [])
const onSecondDialogClose = useCallback(() => setSecondOpen(false), [])
const openSecondDialog = useCallback(() => setSecondOpen(true), [])
return (
<>
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
Show dialog
</Button>
{isOpen && (
<Dialog
title="My Dialog"
subtitle={subtitle ? 'This is a subtitle!' : undefined}
onClose={onDialogClose}
width={width}
height={height}
footerButtons={[
{buttonType: 'danger', content: 'Delete the universe', onClick: onDialogClose},
{buttonType: 'primary', content: 'Proceed', onClick: openSecondDialog, autoFocus: true},
]}
>
{lipsum}
{secondOpen && (
<Dialog title="Inner dialog!" onClose={onSecondDialogClose} width="small">
Hello world
</Dialog>
)}
</Dialog>
)}
</>
)
}

function CustomHeader({
title,
Expand Down
Loading
Loading