Skip to content

Commit 31cde8d

Browse files
committed
feat: @emotion/css 를 적용한다
1 parent a12f175 commit 31cde8d

File tree

6 files changed

+327
-162
lines changed

6 files changed

+327
-162
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
"@docusaurus/preset-classic": "2.1.0",
140140
"@docusaurus/remark-plugin-npm2yarn": "2.1.0",
141141
"@docusaurus/theme-live-codeblock": "2.1.0",
142+
"@emotion/css": "11.13.5",
142143
"@emotion/native": "11.9.3",
143144
"@emotion/react": "11.10.4",
144145
"@emotion/styled": "11.10.4",

packages/vibrant-core/src/lib/Box/Box.tsx

+42-38
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,58 @@
11
import type { ComponentType, FC, ReactElement } from 'react';
22
import { createElement, forwardRef, memo } from 'react';
3-
import styled from '@emotion/styled';
3+
import { css } from '@emotion/css';
44
import { useComposedRef, useLayoutEvent } from '@vibrant-ui/utils';
55
import { OnColorContainer } from '../OnColorContainer';
66
import type { BoxElements, BoxProps } from './BoxProps';
77
import { interpolation, shouldForwardProp } from './BoxProps';
88

99
export const Box = memo(
10-
styled(
11-
forwardRef<HTMLDivElement, BoxProps>(
12-
(
13-
{
14-
as,
15-
base,
16-
onLayout,
17-
ariaLabel,
18-
ariaChecked,
19-
ariaLabelledBy,
20-
ariaCurrent,
21-
ariaSelected,
22-
backgroundColor,
23-
...restProps
24-
},
25-
ref
26-
) => {
27-
const { ref: layoutEventRef } = useLayoutEvent(onLayout);
28-
const composeRef = useComposedRef(ref, layoutEventRef);
10+
forwardRef<HTMLDivElement, BoxProps>(
11+
(
12+
{
13+
as,
14+
base,
15+
onLayout,
16+
ariaLabel,
17+
ariaChecked,
18+
ariaLabelledBy,
19+
ariaCurrent,
20+
ariaSelected,
21+
backgroundColor,
22+
...restProps
23+
},
24+
ref
25+
) => {
26+
const { ref: layoutEventRef } = useLayoutEvent(onLayout);
27+
const composeRef = useComposedRef(ref, layoutEventRef);
2928

30-
const element = createElement(base ?? as ?? 'div', {
31-
ref: composeRef,
32-
...(base && as ? { as } : {}),
33-
'aria-label': ariaLabel,
34-
'aria-checked': ariaChecked,
35-
'aria-labelledby': ariaLabelledBy,
36-
'aria-current': ariaCurrent,
37-
'aria-selected': ariaSelected,
38-
...restProps,
39-
});
29+
const className = Object.entries(interpolation({ ...restProps, backgroundColor } ?? {}))
30+
.map(([key, value]) => css({ [key]: value }))
31+
.join(' ');
4032

41-
if (backgroundColor) {
42-
return <OnColorContainer backgroundColor={backgroundColor}>{element}</OnColorContainer>;
43-
}
33+
const domAttributeProps = Object.fromEntries(
34+
Object.entries({ ...restProps }).filter(([key, _]) => shouldForwardProp(key))
35+
);
4436

45-
return element;
37+
const element = createElement(base ?? as ?? 'div', {
38+
ref: composeRef,
39+
...(base && as ? { as } : {}),
40+
'aria-label': ariaLabel,
41+
'aria-checked': ariaChecked,
42+
'aria-labelledby': ariaLabelledBy,
43+
'aria-current': ariaCurrent,
44+
'aria-selected': ariaSelected,
45+
...domAttributeProps,
46+
className,
47+
});
48+
49+
if (backgroundColor) {
50+
return <OnColorContainer backgroundColor={backgroundColor}>{element}</OnColorContainer>;
4651
}
47-
),
48-
{
49-
shouldForwardProp,
52+
53+
return element;
5054
}
51-
)(interpolation)
55+
)
5256
) as <
5357
BaseComponent extends ComponentType<any> | undefined = undefined,
5458
ElementName extends BoxElements | undefined = undefined

packages/vibrant-core/src/lib/ScrollBox/ScrollBox.tsx

+40-27
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
11
import { createElement, forwardRef } from 'react';
2-
import styled from '@emotion/styled';
2+
import { css } from '@emotion/css';
33
import { useComposedRef, useLayoutEvent } from '@vibrant-ui/utils';
44
import { transformResponsiveValue } from '../transformResponsiveValue';
55
import type { ScrollBoxProps } from './ScrollBoxProps';
66
import { interpolation, shouldForwardProp } from './ScrollBoxProps';
77

8-
const SystemScrollBox = styled(
9-
forwardRef<any, ScrollBoxProps>(
10-
({ as = 'div', ariaChecked, ariaCurrent, ariaLabel, ariaLabelledBy, ariaSelected, ...restProps }, ref) =>
11-
createElement(as, {
12-
ref,
13-
'aria-label': ariaLabel,
14-
'aria-checked': ariaChecked,
15-
'aria-labelledby': ariaLabelledBy,
16-
'aria-current': ariaCurrent,
17-
'aria-selected': ariaSelected,
18-
...restProps,
19-
})
20-
),
21-
{
22-
shouldForwardProp,
23-
}
24-
)(interpolation);
25-
26-
export const ScrollBox = forwardRef<any, ScrollBoxProps>(
27-
({ keyboardShouldPersistTaps: _, scrollEnabled = true, onLayout, ...restProps }, ref) => {
8+
export const ScrollBox = forwardRef<unknown, ScrollBoxProps>(
9+
(
10+
{
11+
as = 'div',
12+
ariaChecked,
13+
ariaCurrent,
14+
ariaLabel,
15+
ariaLabelledBy,
16+
ariaSelected,
17+
scrollEnabled = true,
18+
onLayout,
19+
...restProps
20+
},
21+
ref
22+
) => {
2823
const { ref: layoutEventRef } = useLayoutEvent(onLayout);
2924
const composeRef = useComposedRef(ref, layoutEventRef);
3025

31-
return (
32-
<SystemScrollBox
33-
ref={composeRef}
34-
{...restProps}
35-
overflow={transformResponsiveValue(scrollEnabled, value => (value ? 'auto' : 'hidden'))}
36-
/>
26+
const className = Object.entries(
27+
interpolation({
28+
...restProps,
29+
overflow: transformResponsiveValue(scrollEnabled, value => (value ? 'auto' : 'hidden')),
30+
})
31+
)
32+
.map(([key, value]) => css({ [key]: value }))
33+
.join(' ');
34+
35+
const domAttributeProps = Object.fromEntries(
36+
Object.entries({ ...restProps }).filter(([key, _]) => shouldForwardProp(key))
3737
);
38+
39+
const element = createElement(as, {
40+
ref: composeRef,
41+
'aria-label': ariaLabel,
42+
'aria-checked': ariaChecked,
43+
'aria-labelledby': ariaLabelledBy,
44+
'aria-current': ariaCurrent,
45+
'aria-selected': ariaSelected,
46+
...domAttributeProps,
47+
className,
48+
});
49+
50+
return element;
3851
}
3952
);
4053

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import type { FC } from 'react';
22
import { createElement, forwardRef } from 'react';
3-
import styled from '@emotion/styled';
3+
import { css } from '@emotion/css';
44
import { nl2br } from '../nl2br';
55
import type { TextProps } from './TextProps';
66
import { interpolation, shouldForwardProp } from './TextProps';
77

8-
export const Text: FC<TextProps> = styled(
9-
forwardRef<unknown, TextProps>(({ as = 'span', children, ...restProps }, ref) =>
10-
createElement(as, {
11-
ref,
12-
children: typeof children === 'string' ? nl2br(children) : children,
13-
...restProps,
14-
})
15-
),
16-
{
17-
shouldForwardProp,
18-
}
19-
)(interpolation);
8+
export const Text: FC<TextProps> = forwardRef<unknown, TextProps>(({ as = 'span', children, ...restProps }, ref) => {
9+
const className = Object.entries(interpolation({ ...restProps } ?? {}))
10+
.map(([key, value]) => css({ [key]: value }))
11+
.join(' ');
2012

13+
const domAttributeProps = Object.fromEntries(
14+
Object.entries({ ...restProps }).filter(([key, _]) => shouldForwardProp(key))
15+
);
16+
17+
return createElement(as, {
18+
ref,
19+
children: typeof children === 'string' ? nl2br(children) : children,
20+
domAttributeProps,
21+
className,
22+
});
23+
});
2124
(Text as FC).displayName = 'Text';

0 commit comments

Comments
 (0)