123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import React,{ ReactElement, useState }from"react";import{ Button }from"@react-md/button";import{ Dialog, DialogContent, DialogFooter }from"@react-md/dialog";import{ TextArea }from"@react-md/form";import{ Text }from"@react-md/typography";import styles from"./AlertDialogsAndModals.module.scss";constDRAFT=`This is some initial text to show in the draft area.
When you click on "Reset", a dialog will ask you if you want to discard the
draft. When you click on "Submit", a modal confirmation dialog will ask you
if you really want to submit this.
`.replace(/\r?\n/g," ");exportdefaultfunctionDemo(): ReactElement {const[state, setState]=useState({ visible:false, modal:false});const hide =():void=>{setState((prevState)=>({...prevState, visible:false}));};const show =(event: React.MouseEvent<HTMLButtonElement>):void=>{setState({
visible:true,
modal: event.currentTarget.id ==="draft-submit",});};const{ visible, modal }= state;return(<><formid="draft-form"onSubmit={(e)=>{
e.preventDefault();}}><TextAreaid="draft-area"defaultValue={DRAFT}className={styles.textarea}resize="none"/><DialogFooter><Buttonid="draft-discard"onClick={show}type="reset"theme="warning">
Reset
</Button><Buttonid="draft-submit"onClick={show}type="submit">
Submit
</Button></DialogFooter></form><Dialogid="draft-dialog"role="alertdialog"modal={modal}visible={visible}onRequestClose={hide}aria-labelledby="dialog-title"><DialogContent><Textid="dialog-title"type="subtitle-1"margin="none"color="secondary">{!modal ?"Discard draft?":"Are you sure?"}</Text></DialogContent><DialogFooter><Buttonid="dialog-cancel"onClick={hide}>
Cancel
</Button><Buttonid="dialog-discard"onClick={hide}theme={modal ?"primary":"error"}>{!modal ?"Discard":"Submit"}</Button></DialogFooter></Dialog></>);}