Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/Dialog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Dialog
status: Alpha
---

import data from '../../src/Dialog.docs.json'
import data from '../../src/Dialog/Dialog.docs.json'

The dialog component is used for all modals. It renders on top of the rest of the app with an overlay.

Expand Down
113 changes: 59 additions & 54 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,60 +122,6 @@
],
"subcomponents": []
},
"dialog": {
"id": "dialog",
"name": "Dialog",
"status": "alpha",
"a11yReviewed": false,
"stories": [],
"props": [
{
"name": "isOpen",
"type": "boolean",
"description": "Whether or not the dialog is open"
},
{
"name": "onDismiss",
"type": "() => void",
"description": "Function that will be called when the dialog is closed"
},
{
"name": "returnFocusRef",
"type": " React.RefObject<HTMLElement>",
"description": "The element to restore focus back to after the `Dialog` is closed"
},
{
"name": "initialFocusRef",
"type": " React.RefObject<HTMLElement>",
"description": "Element inside of the `Dialog` you'd like to be focused when the Dialog is opened. If nothing is passed to `initialFocusRef` the close button is focused."
},
{
"name": "aria-labelledby",
"type": "string",
"description": "Pass an id to use for the aria-label. Use either a `aria-label` or an `aria-labelledby` but not both."
},
{
"name": "aria-label",
"type": "string",
"description": "Pass a label to be used to describe the Dialog. Use either a `aria-label` or an `aria-labelledby` but not both."
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": [
{
"name": "Dialog.Header",
"props": [
{
"name": "sx",
"type": "SystemStyleObject"
}
]
}
]
},
"filter_list": {
"id": "filter_list",
"name": "FilterList",
Expand Down Expand Up @@ -2025,6 +1971,65 @@
],
"subcomponents": []
},
"dialog": {
"id": "dialog",
"name": "Dialog",
"status": "alpha",
"a11yReviewed": false,
"stories": [
{
"id": "components-dialog--default",
"code": "() => {\n const [isOpen, setIsOpen] = useState(false)\n const returnFocusRef = React.useRef(null)\n return (\n <>\n <Button ref={returnFocusRef} onClick={() => setIsOpen(true)}>\n Open\n </Button>\n <Dialog\n returnFocusRef={returnFocusRef}\n isOpen={isOpen}\n onDismiss={() => setIsOpen(false)}\n aria-labelledby=\"header-id\"\n >\n <Dialog.Header id=\"header-id\">Title</Dialog.Header>\n some content\n </Dialog>\n </>\n )\n}"
}
],
"props": [
{
"name": "isOpen",
"type": "boolean",
"description": "Whether or not the dialog is open"
},
{
"name": "onDismiss",
"type": "() => void",
"description": "Function that will be called when the dialog is closed"
},
{
"name": "returnFocusRef",
"type": " React.RefObject<HTMLElement>",
"description": "The element to restore focus back to after the `Dialog` is closed"
},
{
"name": "initialFocusRef",
"type": " React.RefObject<HTMLElement>",
"description": "Element inside of the `Dialog` you'd like to be focused when the Dialog is opened. If nothing is passed to `initialFocusRef` the close button is focused."
},
{
"name": "aria-labelledby",
"type": "string",
"description": "Pass an id to use for the aria-label. Use either a `aria-label` or an `aria-labelledby` but not both."
},
{
"name": "aria-label",
"type": "string",
"description": "Pass a label to be used to describe the Dialog. Use either a `aria-label` or an `aria-labelledby` but not both."
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": [
{
"name": "Dialog.Header",
"props": [
{
"name": "sx",
"type": "SystemStyleObject"
}
]
}
]
},
"drafts_dialog": {
"id": "drafts_dialog",
"name": "Dialog",
Expand Down
File renamed without changes.
46 changes: 46 additions & 0 deletions src/Dialog/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, {useState} from 'react'
import {Meta} from '@storybook/react'

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

export default {
title: 'Components/Dialog',
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>
)
},
],
} as Meta

export const Default = () => {
const [isOpen, setIsOpen] = useState(false)
const returnFocusRef = React.useRef(null)

return (
<>
<Button ref={returnFocusRef} onClick={() => setIsOpen(true)}>
Open
</Button>
<Dialog
returnFocusRef={returnFocusRef}
isOpen={isOpen}
onDismiss={() => setIsOpen(false)}
aria-labelledby="header-id"
>
<Dialog.Header id="header-id">Title</Dialog.Header>
some content
</Dialog>
</>
)
}
16 changes: 8 additions & 8 deletions src/Dialog.tsx → src/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, {forwardRef, useRef} from 'react'
import styled from 'styled-components'
import ButtonClose from './deprecated/Button/ButtonClose'
import {get} from './constants'
import Box from './Box'
import useDialog from './hooks/useDialog'
import sx, {SxProp} from './sx'
import Text from './Text'
import {ComponentProps} from './utils/types'
import {useRefObjectAsForwardedRef} from './hooks/useRefObjectAsForwardedRef'
import ButtonClose from '../deprecated/Button/ButtonClose'
import {get} from '../constants'
import Box from '../Box'
import useDialog from '../hooks/useDialog'
import sx, {SxProp} from '../sx'
import Text from '../Text'
import {ComponentProps} from '../utils/types'
import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef'

const noop = () => null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {useState, useRef} from 'react'
import {Dialog, Box, Text} from '..'
import {Button} from '../deprecated'
import {Dialog, Box, Text} from '../..'
import {Button} from '../../deprecated'
import {render as HTMLRender, act, fireEvent} from '@testing-library/react'
import {axe, toHaveNoViolations} from 'jest-axe'
import {behavesAsComponent, checkExports} from '../utils/testing'
import {behavesAsComponent, checkExports} from '../../utils/testing'
expect.extend(toHaveNoViolations)

const comp = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import Dialog from '../Dialog'
import Dialog from '..'

export function shouldAcceptCallWithNoProps() {
return <Dialog />
Expand Down
1 change: 1 addition & 0 deletions src/Dialog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default, DialogProps, DialogHeaderProps} from './Dialog'
1 change: 1 addition & 0 deletions src/__tests__/storybook.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const allowlist = [
'CounterLabel',
'DataTable',
'Details',
'Dialog',
'Dialog2',
'Flash',
'Heading',
Expand Down