Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaAlex committed Oct 8, 2024
1 parent 298ba01 commit dfef3d8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/components/toast/ToastContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SystemCssProperties } from '@styled-system/css'
import { motion } from 'framer-motion'
import {SystemCssProperties} from '@styled-system/css'
import {motion} from 'framer-motion'
import * as React from 'react'
import { useEffect, useState } from 'react'
import {useEffect, useState} from 'react'
import styled from 'styled-components'

import { LAYOUT_TRANSITION_SPRING } from '../../styles/modules/variables'
import { Box } from '../box/Box'
import { UIEvents } from './enums'
import { Emitter, ToastProps, Toast } from './index'
import {LAYOUT_TRANSITION_SPRING} from '../../styles/modules/variables'
import {Box} from '../box/Box'
import {UIEvents} from './enums'
import {Emitter, ToastProps, Toast} from './index'

const ToastWrapper = styled(motion(Box)).attrs({
width: ['100%', 'auto'],
Expand All @@ -28,13 +28,14 @@ const ToastContainer = () => {
useEffect(() => {
// We use several <ToastContainer> throughout the app
// We check if a Container already exists before creating a new one that could interfere with others, preventing events from working
if (Emitter.listenerCount(UIEvents.ToastShow) === 0) {
if (Emitter.listenerCount(UIEvents.ToastShow) === 0) {
Emitter.on(UIEvents.ToastShow, (newToast: ToastProps) => {
setToast(newToast)
})
Emitter.on(UIEvents.ToastClear, () => {
setToast(null)
})

}

return () => {
Expand All @@ -50,7 +51,7 @@ const ToastContainer = () => {
return (
<Box
className={`toasts-container toasts-container--${toast?.position ||
'top'}`}
'top'}`}
display={visible ? 'flex' : 'none'}
top={toast?.position?.includes('top') ? 2 : 0}
left={toast?.position?.includes('left') ? 2 : 0}
Expand All @@ -61,8 +62,8 @@ const ToastContainer = () => {
alignItems: toast?.position?.includes('left')
? 'flex-start'
: toast?.position?.includes('right')
? 'flex-end'
: 'center',
? 'flex-end'
: 'center',
flexDirection: toast?.position?.includes('bottom')
? 'column-reverse'
: 'column',
Expand Down

0 comments on commit dfef3d8

Please sign in to comment.