importtype{ ReactElement }from"react";importtype{ ToastMessage }from"@react-md/alert";import{ MessageQueue, useAddMessage }from"@react-md/alert";import{ Button }from"@react-md/button";import{ Form, Radio, useChoice }from"@react-md/form";constSINGLE_LINE="SINGLE_LINE";constSINGLE_LINE_ACTION="SINGLE_LINE_ACTION";constTWO_LINES="TWO_LINES";constTWO_LINES_ACTION="TWO_LINES_ACTION";constTWO_LINES_STACKED="TWO_LINES_STACKED";typeMessageKeys=|typeofSINGLE_LINE|typeofSINGLE_LINE_ACTION|typeofTWO_LINES|typeofTWO_LINES_ACTION|typeofTWO_LINES_STACKED;typeMessageRecord= Record<MessageKeys, ToastMessage>;const messages: MessageRecord ={[SINGLE_LINE]:{
children:"This is an example message",},[SINGLE_LINE_ACTION]:{
action:"Action",
children:"This is an example message",},[TWO_LINES]:{
twoLines:true,
children:(<><p>This is an example message</p><p>With a second line of text.</p></>),},[TWO_LINES_ACTION]:{
action:"Action",
twoLines:true,
children:(<><p>This is an example message</p><p>With a second line of text.</p></>),},[TWO_LINES_STACKED]:{
action:"Action",
stacked:true,
twoLines:true,
children:(<><p>This is an example message</p><p>With a second line of text.</p></>),},};functionSimpleMessageQueue(): ReactElement {const addMessage =useAddMessage();const[key, handleKeyChange]=useChoice<MessageKeys>(SINGLE_LINE);return(<FormonSubmit={()=>addMessage(messages[key])}><Radioid="mqr-1"name="message"value={SINGLE_LINE}checked={key ===SINGLE_LINE}onChange={handleKeyChange}label="Single Line Message"/><Radioid="mqr-2"name="message"value={SINGLE_LINE_ACTION}checked={key ===SINGLE_LINE_ACTION}onChange={handleKeyChange}label="Single Line Message with Action"/><Radioid="mqr-3"name="message"value={TWO_LINES}checked={key ===TWO_LINES}onChange={handleKeyChange}label="Two Line Message"/><Radioid="mqr-4"name="message"value={TWO_LINES_ACTION}checked={key ===TWO_LINES_ACTION}onChange={handleKeyChange}label="Two Line Message with Action"/><Radioid="mqr-5"name="message"value={TWO_LINES_STACKED}checked={key ===TWO_LINES_STACKED}onChange={handleKeyChange}label="Two Line Message with Stacked Action"/><Buttonid="mqr-submit"type="submit"theme="primary">
Add Message
</Button></Form>);}exportdefaultfunctionDemo(): ReactElement {return(<MessageQueueid="simple-message-queue"><SimpleMessageQueue/></MessageQueue>);}