@@ -11,7 +11,6 @@ export interface CToasterProps extends HTMLAttributes<HTMLDivElement> {
11
11
* Describes the placement of your component. [docs]
12
12
*
13
13
* @type 'top-start' | 'top' | 'top-end' | 'middle-start' | 'middle' | 'middle-end' | 'bottom-start' | 'bottom' | 'bottom-end' | string
14
- * @default 'top-end'
15
14
*/
16
15
placement ?:
17
16
| 'top-start'
@@ -25,13 +24,13 @@ export interface CToasterProps extends HTMLAttributes<HTMLDivElement> {
25
24
| 'bottom-end'
26
25
| string
27
26
/**
28
- * TODO: . [docs]
27
+ * Adds new `CToast` to `CToaster` . [docs]
29
28
*/
30
29
push ?: ReactElement
31
30
}
32
31
33
32
export const CToaster = forwardRef < HTMLDivElement , CToasterProps > (
34
- ( { children, className, placement = 'top-end' , push, ...rest } , ref ) => {
33
+ ( { children, className, placement, push, ...rest } , ref ) => {
35
34
const [ toasts , setToasts ] = useState < ReactElement [ ] > ( [ ] )
36
35
const index = useRef < number > ( 0 )
37
36
@@ -40,13 +39,14 @@ export const CToaster = forwardRef<HTMLDivElement, CToasterProps>(
40
39
push && addToast ( push )
41
40
} , [ push ] )
42
41
43
- // TODO: remove invisible items
44
42
const addToast = ( push : ReactElement ) => {
45
43
setToasts ( ( state ) => [
46
44
...state ,
47
45
React . cloneElement ( push , {
46
+ index : index . current ,
48
47
key : index . current ,
49
- onDismiss : ( ) => setToasts ( ( state ) => state . filter ( ( i ) => i . key !== index . current ) ) ,
48
+ onDismiss : ( index : number ) =>
49
+ setToasts ( ( state ) => state . filter ( ( i ) => i . props . index !== index ) ) ,
50
50
} ) ,
51
51
] )
52
52
}
0 commit comments