Material Components React Dialog
npm install @material/react-dialogA React version of an MDC Dialog.
```
npm install @material/react-dialog
with Sass:
`js`
import '@material/react-dialog/index.scss';
with CSS:
`js`
import "@material/react-dialog/dist/dialog.css";
#### Basic Usage
Below is a basic example of a dialog. is not defined, but
can be any element.
`js
import React, {Component} from 'react';
import Dialog, {
DialogTitle,
DialogContent,
DialogFooter,
DialogButton,
} from '@material/react-dialog';
class MyApp extends Component {
state = {isOpen: true};
render() {
return (
);
}
}
`mdc-typography-baseline-top()
>NOTE: Titles cannot contain leading whitespace due to how works.
The Alert Dialog interrupt users with urgent information, details, or actions.
`js
import React, {Component} from 'react';
import Dialog, {
DialogContent,
DialogFooter,
DialogButton,
} from '@material/react-dialog';
class Alert extends Component {
state = {isOpen: true, action: ''};
render() { Discard Draft?
return (
onClose={(action: string) => this.setState({isOpen: false, action})}
open={this.state.isOpen}>
);
}
}
`
#### Simple Dialog
The Simple Dialog contains a list of potential actions. It does not contain buttons.
`js
import React, {Component} from 'react';
import Dialog, {DialogTitle, DialogContent} from '@material/react-dialog';
import List, {ListItem, ListItemGraphic, ListItemText} from '@material/react-list';
import MaterialIcon from '@material/react-material-icon';
class Simple extends Component {
state = {
isOpen: true
choices: ['user1@example.com', 'user2@example.com', 'Add Account']
action: ''
};
render() {
return (
open={isOpen}
onClose={(action) => this.setState({action, isOpen: false})}>
{choices.map((choice, i) => (
}/>
))
}
);
}
}
`avatarList
>NOTES: (1) the inclusion of the , which aligns with the Simpledata-mdc-dialog-action
>Dialog spec. (2) the which singals the chosen action onClose()
The Confirmation Dialog contains a list of choices, and buttons to confirm or
cancel. Choices are accompanied by radio buttons (indicating single selection)
or checkboxes (indicating multiple selection).
`js
import React, {Component} from 'react';
import Dialog, {
DialogTitle,
DialogContent,
DialogFooter,
DialogButton,
} from '@material/react-dialog';
import List, {ListItem, ListItemText} from '@material/react-list';
import Radio, {NativeRadioControl} from '@material/react-radio';
class Confirmation extends Component
state = {
isOpen: false,
action: '',
selectedIndex: -1,
choices: ['Never gonna give you up', 'Host cross buns', 'None'];
};
isChecked = (i) => i === this.state.selectedIndex;
render() {
return (
onClose={(action) => this.setState({isOpen: false, action})}
open={this.state.isOpen}>
singleSelection
handleSelect={ (selectedIndex) => this.setState({selectedIndex})}
>{choices.map((choice, i) => {
let cleanChoice = choice.replace(/\s/g, '-');
return (
value={choice}
id={cleanChoice}
checked={this.isChecked(i)}
onChange={() => {}}
/>
);
})}
);
}
}
`
Prop Name | Type | Description | Default
--- | --- | --- | ---
autoStackButtons | Boolean | reverses the buttons when applying the stacked layout. | trueDialogTitle
className | String | classes to applied to the root element | n/a
children | Node | ReactElement to render in the dialog only available children are ,DialogContent, or DialogFooter. | n/a''
escapeKeyAction | String | the action reflected when the Escape key is pressed. Setting to disables closing via the escape key | closemdc-dialog
id | String | the id attribute placed on the root element | () => {}
onClose | Function (action) => void | Callback after the dialog has closed. | n/a
onClosing | Function (action) => void | Callback for when the dialog begins to close. | () => {}
onOpen | Function () => void | Callback after the dialog has opened | n/a
onOpening | Function () => void | Callback for when the dialog begins to open. | false
open | Boolean | If true opens the dialog. If false closes the dialog | alertdialog
role | String | ARIA attribute that specifies the role of dialog. Must be or dialog | alertdialog''
scrimClickAction | String | the action reflected when the scrim is clicked. Setting to disables closing via scrim click| close Dialog
tag | String | Customizes the tag type. | div$3
Prop Name | Type | Description
--- | --- | ---
className | String | the classes applied to the root element of DialogTitleDialogTitle
id | String | the id attribute placed on the root element.
tag | String | customizes the tag type. (defaults: h2)id
> NOTE: that is also set to aria-labelledby on the element .id
Additionally, if unset will default to the of with the suffix-title
.
Prop Name | Type | Description
--- | --- | ---
className | String | the classes applied to the root element of DialogContentDialogContent
id | String | the id attribute placed on the root element.
tag | String | customizes the tag type. (defaults: div)id
> NOTE: that value is also set to aria-describedby on the id
element. Additionally, if unset will default the to of with the -content
suffix .
Prop Name | Type | Description
--- | --- | ---
className | String | the classes applied to the root element of DialogContentDialogFooter
tag | String | customizes the tag type. (defaults: footer)
Prop Name | Type | Description
--- | --- | ---
action | String | required action of the button. Returned onClose && onClosing in DialogButton
className | String | the classes applied to the root element of false`)
isDefault | Boolean | represents the default action, triggered by pressing the Enter key (defaults:
Sass mixins may be available to customize various aspects of the Components. Please refer to the
MDC Web repository for more information on what mixins are available, and how to use them.