Skip to content

Commit 8f6801c

Browse files
committed
refactor: update animations
1 parent cf3c247 commit 8f6801c

File tree

4 files changed

+31
-53
lines changed

4 files changed

+31
-53
lines changed

src/components/alert/CAlert.tsx

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { forwardRef, HTMLAttributes, useState } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
4-
import { Transition } from 'react-transition-group'
4+
import { CSSTransition } from 'react-transition-group'
55

66
import { Colors, colorPropType } from '../Types'
77
import { CButtonClose } from '../button/CButtonClose'
@@ -57,53 +57,36 @@ export const CAlert = forwardRef<HTMLDivElement, CAlertProps>(
5757
},
5858
ref,
5959
) => {
60+
const [_visible, setVisible] = useState(visible)
61+
6062
const _className = classNames(
6163
'alert',
6264
variant === 'solid' ? `bg-${color} text-white` : `alert-${color}`,
63-
{ 'alert-dismissible fade': dismissible },
65+
{
66+
'alert-dismissible fade': dismissible,
67+
show: _visible && dismissible,
68+
},
6469
className,
6570
)
66-
const [_visible, setVisible] = useState(visible)
67-
68-
const duration = 150
69-
70-
const defaultStyle = {
71-
opacity: 0,
72-
}
73-
74-
const transitionStyles = {
75-
entering: { opacity: 1 },
76-
entered: { opacity: 1 },
77-
exiting: { opacity: 0 },
78-
exited: { opacity: 0 },
79-
}
8071

8172
return (
82-
<Transition
73+
<CSSTransition
8374
in={_visible}
84-
timeout={duration}
75+
timeout={150}
8576
onExit={onDismiss}
8677
onExited={onDismissed}
8778
unmountOnExit
8879
>
89-
{(state) => {
90-
return (
91-
<div
92-
className={_className}
93-
role="alert"
94-
style={{
95-
...defaultStyle,
96-
...transitionStyles[state],
97-
}}
98-
{...rest}
99-
ref={ref}
100-
>
101-
{children}
102-
{dismissible && <CButtonClose onClick={() => setVisible(false)} />}
103-
</div>
104-
)
105-
}}
106-
</Transition>
80+
<div
81+
className={_className}
82+
role="alert"
83+
{...rest}
84+
ref={ref}
85+
>
86+
{children}
87+
{dismissible && <CButtonClose onClick={() => setVisible(false)} />}
88+
</div>
89+
</CSSTransition>
10790
)
10891
},
10992
)

src/components/collapse/CCollapse.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { CSSProperties, forwardRef, HTMLAttributes, useRef, useState } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
4-
import { Transition } from 'react-transition-group'
4+
import { CSSTransition } from 'react-transition-group'
55

66
import { useForkedRef } from '../../utils/hooks'
77

@@ -22,10 +22,6 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
2222
const collapseRef = useRef<HTMLDivElement>(null)
2323
const forkedRef = useForkedRef(ref, collapseRef)
2424

25-
const style: CSSProperties = {
26-
transition: 'height 350ms ease 0s',
27-
}
28-
2925
const getTransitionClass = (state: string) => {
3026
return state === 'entering'
3127
? 'collapsing'
@@ -49,8 +45,7 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
4945
}
5046

5147
const onExiting = () => {
52-
// @ts-expect-error
53-
const reflow = collapseRef && collapseRef.current && collapseRef.current.offsetHeight
48+
// const reflow = collapseRef && collapseRef.current && collapseRef.current.offsetHeight
5449
setHeight(0)
5550
}
5651

@@ -61,7 +56,7 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
6156
const _className = classNames(className)
6257

6358
return (
64-
<Transition
59+
<CSSTransition
6560
in={visible}
6661
timeout={350}
6762
onEntering={onEntering}
@@ -76,15 +71,15 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
7671
return (
7772
<div
7873
className={classNames(_className, transitionClass)}
79-
style={{ ...style, ...currentHeight }}
74+
style={{ ...currentHeight }}
8075
{...rest}
8176
ref={forkedRef}
8277
>
8378
{children}
8479
</div>
8580
)
8681
}}
87-
</Transition>
82+
</CSSTransition>
8883
)
8984
},
9085
)

src/components/popover/CPopover.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// TODO: fix possition
22

33
import React, { FC, ReactNode, useState } from 'react'
4-
import PropTypes from 'prop-types'
54
import { createPortal } from 'react-dom'
5+
import PropTypes from 'prop-types'
66
import { Manager, Popper, Reference } from 'react-popper'
7-
import { Transition } from 'react-transition-group'
7+
import { CSSTransition } from 'react-transition-group'
88

99
import { CPopoverContent } from './CPopoverContent'
1010
import { Placements, Triggers, triggerPropType } from '../Types'
@@ -81,7 +81,7 @@ export const CPopover: FC<CPopoverProps> = ({
8181
</Reference>
8282
{typeof window !== 'undefined' &&
8383
createPortal(
84-
<Transition
84+
<CSSTransition
8585
in={_visible}
8686
timeout={{
8787
enter: 0,
@@ -105,7 +105,7 @@ export const CPopover: FC<CPopoverProps> = ({
105105
</Popper>
106106
)
107107
}}
108-
</Transition>,
108+
</CSSTransition>,
109109
document.body,
110110
)}
111111
</Manager>

src/components/tooltip/CTooltip.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { FC, ReactNode, useState } from 'react'
22
import PropTypes from "prop-types";
33
import { createPortal } from 'react-dom'
44
import { Manager, Popper, Reference } from 'react-popper'
5-
import { Transition } from 'react-transition-group'
5+
import { CSSTransition } from 'react-transition-group'
66

77
import { CTooltipContent } from './CTooltipContent'
88
import { Placements, Triggers, triggerPropType } from '../Types'
@@ -74,7 +74,7 @@ export const CTooltip: FC<CTooltipProps> = ({
7474
</Reference>
7575
{typeof window !== 'undefined' &&
7676
createPortal(
77-
<Transition
77+
<CSSTransition
7878
in={_visible}
7979
timeout={{
8080
enter: 0,
@@ -98,7 +98,7 @@ export const CTooltip: FC<CTooltipProps> = ({
9898
</Popper>
9999
)
100100
}}
101-
</Transition>,
101+
</CSSTransition>,
102102
document.body,
103103
)}
104104
</Manager>

0 commit comments

Comments
 (0)