123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119import React,{ ReactElement }from"react";import{ MessageQueue, ToastMessage, 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>);}exportdefaultfunctionDemoContainer(): ReactElement {return(<MessageQueueid="simple-message-queue"><Demo/></MessageQueue>);}