Skip to content

Commit ac2a7ae

Browse files
committed
Export mkFadeInCss utils for direct styling
1 parent 5e57f4e commit ac2a7ae

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

src/lib/components/FadeIn.tsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ClassNames, keyframes } from '@emotion/react';
22
import React, { ReactElement } from 'react';
3+
import { css } from 'twin.macro';
34

45
export type Orientation = 'left' | 'right' | 'up' | 'down' | 'none';
56

@@ -17,21 +18,38 @@ export const FadeIn = ({
1718
duration = 0.2,
1819
distance = 10,
1920
children,
20-
}: FadeInProps): ReactElement => {
21-
return (
22-
<ClassNames>
23-
{({ css /*cx*/ }) => {
24-
const animation = css`
25-
opacity: 0;
26-
animation: ${fadeIn(orientation, distance)} ${duration}s ease-in-out
27-
${delay}s forwards;
28-
`;
29-
return <div className={animation}>{children}</div>;
30-
}}
31-
</ClassNames>
32-
);
21+
}: FadeInProps): ReactElement => (
22+
<ClassNames>
23+
{({ css }) => (
24+
<div
25+
className={css`
26+
${mkFadeInCss({ orientation, delay, duration, distance })}
27+
`}
28+
>
29+
{children}
30+
</div>
31+
)}
32+
</ClassNames>
33+
);
34+
35+
type MkFadeInCssArgs = {
36+
orientation: Orientation;
37+
delay: number;
38+
duration: number;
39+
distance: number;
3340
};
3441

42+
export const mkFadeInCss = ({
43+
orientation,
44+
delay,
45+
duration,
46+
distance,
47+
}: MkFadeInCssArgs) => css`
48+
opacity: 0;
49+
animation: ${fadeIn(orientation, distance)} ${duration}s ease-in-out ${delay}s
50+
forwards;
51+
`;
52+
3553
const fadeIn = (orientation: Orientation, distance: number): string => {
3654
return keyframes`
3755
from {

src/lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
export { FadeIn } from './components/FadeIn';
55
export { ZoomIn } from './components/ZoomIn';
66

7+
// --------------------------- CSS
8+
9+
export { mkFadeInCss } from './components/FadeIn';
10+
711
// --------------------------- Utils
812

913
export { getCounter, getIncrementor } from './lib/getCounter';

0 commit comments

Comments
 (0)