@@ -11,7 +11,6 @@ export interface CToasterProps extends HTMLAttributes<HTMLDivElement> {
1111 * Describes the placement of your component. [docs]
1212 *
1313 * @type 'top-start' | 'top' | 'top-end' | 'middle-start' | 'middle' | 'middle-end' | 'bottom-start' | 'bottom' | 'bottom-end' | string
14- * @default 'top-end'
1514 */
1615 placement ?:
1716 | 'top-start'
@@ -25,13 +24,13 @@ export interface CToasterProps extends HTMLAttributes<HTMLDivElement> {
2524 | 'bottom-end'
2625 | string
2726 /**
28- * TODO: . [docs]
27+ * Adds new `CToast` to `CToaster` . [docs]
2928 */
3029 push ?: ReactElement
3130}
3231
3332export const CToaster = forwardRef < HTMLDivElement , CToasterProps > (
34- ( { children, className, placement = 'top-end' , push, ...rest } , ref ) => {
33+ ( { children, className, placement, push, ...rest } , ref ) => {
3534 const [ toasts , setToasts ] = useState < ReactElement [ ] > ( [ ] )
3635 const index = useRef < number > ( 0 )
3736
@@ -40,13 +39,14 @@ export const CToaster = forwardRef<HTMLDivElement, CToasterProps>(
4039 push && addToast ( push )
4140 } , [ push ] )
4241
43- // TODO: remove invisible items
4442 const addToast = ( push : ReactElement ) => {
4543 setToasts ( ( state ) => [
4644 ...state ,
4745 React . cloneElement ( push , {
46+ index : index . current ,
4847 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 ) ) ,
5050 } ) ,
5151 ] )
5252 }
0 commit comments