1- import { useState } from 'react'
2-
3- import { atomToastAutoCloseTimes , atomToastPositions } from 'components/atom/toast/src/index.js'
1+ import { type ChangeEvent , type FormEvent , useState } from 'react'
42
53import {
64 AntDesignIcon ,
@@ -21,18 +19,24 @@ import {
2119} from '@s-ui/documentation-library'
2220import AtomIcon from '@s-ui/react-atom-icon'
2321
24- import ToastDemo from './ToastDemo.js'
22+ import { type AutoCloseTime , type Position , AUTO_CLOSE_TIMES } from '../src/config'
23+ import { type AtomToastProps , atomToastAutoCloseTimes } from '../src/index'
24+ import ToastDemo from './ToastDemo'
2525
2626import './index.scss'
2727
28+ interface AtomToastPropsWithId extends AtomToastProps {
29+ id : number
30+ }
31+
2832const Demo = ( ) => {
29- const [ toasts , setToasts ] = useState ( [ ] )
30- const pushToast = props => {
33+ const [ toasts , setToasts ] = useState < AtomToastPropsWithId [ ] > ( [ ] )
34+ const pushToast = ( props : AtomToastProps ) => {
3135 const newToasts = [ ...toasts , { id : performance . now ( ) , ...props } ]
3236 setToasts ( newToasts )
3337 return newToasts
3438 }
35- const popToast = id => {
39+ const popToast = ( id : number ) => {
3640 if ( ! show ) {
3741 const newToasts = toasts . filter ( toast => toast . id !== id )
3842 setToasts ( newToasts )
@@ -41,13 +45,48 @@ const Demo = () => {
4145 return toasts
4246 }
4347
44- const [ iconClose , setIconClose ] = useState ( )
48+ const [ iconClose , setIconClose ] = useState < React . ReactNode > ( )
4549 const [ show , setShow ] = useState ( true )
4650 const [ autoClose , setAutoClose ] = useState ( true )
47- const [ autoCloseTime , setAutoCloseTime ] = useState ( atomToastAutoCloseTimes . short )
48- const [ globalClose , setGlobalClose ] = useState ( )
51+ const [ autoCloseTime , setAutoCloseTime ] = useState < AutoCloseTime > ( AUTO_CLOSE_TIMES . short )
52+ const [ globalClose , setGlobalClose ] = useState ( false )
4953 const [ effect , setEffect ] = useState ( true )
5054
55+ const gridOptions : Array < {
56+ position ?: Position
57+ span ?: number
58+ style : React . CSSProperties
59+ } > = [
60+ {
61+ position : 'top-left' ,
62+ style : { justifyContent : 'flex-start' , display : 'flex' }
63+ } ,
64+ {
65+ position : 'top' ,
66+ style : { justifyContent : 'center' , display : 'flex' }
67+ } ,
68+ {
69+ position : 'top-right' ,
70+ style : { justifyContent : 'flex-end' , display : 'flex' }
71+ } ,
72+ {
73+ span : 3 ,
74+ style : { justifyContent : 'center' , display : 'flex' }
75+ } ,
76+ {
77+ position : 'bottom-left' ,
78+ style : { justifyContent : 'flex-start' , display : 'flex' }
79+ } ,
80+ {
81+ position : 'bottom' ,
82+ style : { justifyContent : 'center' , display : 'flex' }
83+ } ,
84+ {
85+ position : 'bottom-right' ,
86+ style : { justifyContent : 'flex-end' , display : 'flex' }
87+ }
88+ ]
89+
5190 return (
5291 < div className = "sui-StudioPreview" >
5392 < H1 > Toast</ H1 >
@@ -62,38 +101,9 @@ const Demo = () => {
62101 </ Paragraph >
63102 < Box outline >
64103 < Grid cols = { 3 } gutter = { [ 8 , 8 ] } >
65- { [
66- {
67- position : atomToastPositions . topLeft ,
68- style : { justifyContent : 'flex-start' , display : 'flex' }
69- } ,
70- {
71- position : atomToastPositions . top ,
72- style : { justifyContent : 'center' , display : 'flex' }
73- } ,
74- {
75- position : atomToastPositions . topRight ,
76- style : { justifyContent : 'flex-end' , display : 'flex' }
77- } ,
78- {
79- span : 3 ,
80- style : { justifyContent : 'center' , display : 'flex' }
81- } ,
82- {
83- position : atomToastPositions . bottomLeft ,
84- style : { justifyContent : 'flex-start' , display : 'flex' }
85- } ,
86- {
87- position : atomToastPositions . bottom ,
88- style : { justifyContent : 'center' , display : 'flex' }
89- } ,
90- {
91- position : atomToastPositions . bottomRight ,
92- style : { justifyContent : 'flex-end' , display : 'flex' }
93- }
94- ] . map ( ( { position, span, style} , index ) => (
95- < Cell key = { position || index } span = { span } >
96- { position ? (
104+ { gridOptions . map ( ( { position, span, style} , index ) => (
105+ < Cell key = { position !== undefined ? position : index } span = { span } >
106+ { position !== undefined ? (
97107 < div style = { style } >
98108 < Button onClick = { ( ) => pushToast ( { position} ) } > { position } </ Button >
99109 </ div >
@@ -112,7 +122,7 @@ const Demo = () => {
112122 autoCloseTime = { autoCloseTime }
113123 effect = { effect }
114124 iconClose = {
115- iconClose && (
125+ iconClose !== undefined && (
116126 < AtomIcon >
117127 < AntDesignIcon icon = { iconClose } style = { { color : 'currentColor' } } />
118128 </ AtomIcon >
@@ -151,7 +161,7 @@ const Demo = () => {
151161 < Grid cols = { 1 } gutter = { [ 8 , 0 ] } >
152162 < Cell >
153163 < RadioButtonGroup
154- onChange = { ( event , value ) => {
164+ onChange = { ( _event : FormEvent , value : AutoCloseTime ) => {
155165 setAutoCloseTime ( value === undefined ? autoCloseTime : value )
156166 } }
157167 >
@@ -168,7 +178,13 @@ const Demo = () => {
168178 </ RadioButtonGroup >
169179 </ Cell >
170180 < Cell >
171- < Input value = { autoCloseTime } onChange = { event => setAutoCloseTime ( event . target . value ) } tyype = "number" />
181+ < Input
182+ value = { autoCloseTime }
183+ onChange = { ( event : ChangeEvent < HTMLInputElement > ) =>
184+ setAutoCloseTime ( Number ( event . target . value ) as AutoCloseTime )
185+ }
186+ type = "number"
187+ />
172188 </ Cell >
173189 </ Grid >
174190 </ Cell >
@@ -191,21 +207,21 @@ const Demo = () => {
191207 The < Code > iconClose</ Code > (node) prop gives the posibility to customize the closing button.
192208 </ Paragraph >
193209 < RadioButtonGroup
194- onChange = { ( event , value ) => {
210+ onChange = { ( _event : ChangeEvent < HTMLInputElement > , value : React . ReactNode ) => {
195211 setIconClose ( value )
196212 } }
197213 >
198- { [ undefined , 'AiOutlineClose' , 'AiOutlinePoweroff' , 'AiFillCloseCircle' ] . map ( ( iconKey , index ) => (
214+ { [ undefined , 'AiOutlineClose' , 'AiOutlinePoweroff' , 'AiFillCloseCircle' ] . map ( iconKey => (
199215 < RadioButton
200- key = { ` ${ iconKey } ` }
216+ key = { iconKey }
201217 checked = { iconClose === iconKey }
202218 label = {
203- iconKey ? (
219+ iconKey !== undefined ? (
204220 < AtomIcon >
205221 < AntDesignIcon icon = { iconKey } style = { { color : 'currentColor' } } />
206222 </ AtomIcon >
207223 ) : (
208- ` ${ iconKey } `
224+ String ( iconKey )
209225 )
210226 }
211227 value = { iconKey }
0 commit comments