Skip to content

Commit 07edb05

Browse files
committed
feat(Chart): Improve enter transitions
1 parent e55a672 commit 07edb05

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/components/ui/chart/dots.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Text } from "./fragments/text"
66
import { createTransition } from "./utils/get-transition"
77

88
const { runTransition } = createTransition({
9+
timingFunction: "bounce",
910
initStyles: {
1011
translate: "0 -16px",
1112
opacity: "0",

src/components/ui/chart/line.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ const { runTransition } = createTransition<SVGPolylineElement>({
88
initStyles: node => ({
99
strokeDashoffset: String(node.getTotalLength()),
1010
strokeDasharray: String(node.getTotalLength()),
11+
opacity: "0",
1112
}),
1213
targetStyles: {
14+
opacity: "1",
1315
strokeDashoffset: "0",
1416
},
1517
})

src/components/ui/chart/utils/get-transition.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { CSSProperties } from "react"
33
import { ease } from "utils/ease"
44

55
const DURATION = 1000
6-
const TIMING_FUNCTION = `cubic-bezier(${ease.out.join(",")})`
76

87
type AllowedElement = HTMLElement | SVGElement
98

@@ -22,6 +21,7 @@ const applyStyles = (node: AllowedElement, styles: CSSProperties) => {
2221
interface TransitionProps<TElement extends AllowedElement> {
2322
initStyles: CSSProperties | ((node: TElement) => CSSProperties)
2423
targetStyles: CSSProperties | ((node: TElement) => CSSProperties)
24+
timingFunction?: keyof typeof ease
2525
}
2626

2727
interface InitTransitionProps<TElement extends AllowedElement> {
@@ -33,6 +33,7 @@ interface InitTransitionProps<TElement extends AllowedElement> {
3333
export const createTransition = <TElement extends AllowedElement>({
3434
initStyles,
3535
targetStyles,
36+
timingFunction = "out",
3637
}: TransitionProps<TElement>) => {
3738
const initTransition = (node: TElement) => {
3839
const styles =
@@ -56,7 +57,7 @@ export const createTransition = <TElement extends AllowedElement>({
5657
transitionProperty: toCssProperties(styles),
5758
transitionDuration: `${DURATION}ms`,
5859
transitionDelay: `${itemDelay}ms`,
59-
transitionTimingFunction: TIMING_FUNCTION,
60+
transitionTimingFunction: `cubic-bezier(${ease[timingFunction].join(",")})`,
6061
})
6162
}
6263

0 commit comments

Comments
 (0)