Skip to content

Commit 95b30f0

Browse files
committed
Refactor: StyledText 리팩토링
1 parent efe7e66 commit 95b30f0

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/components/Text/StyledText.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
import styled from 'styled-components';
2-
import theme from '../../styles/theme';
2+
import theme from '@styles/theme';
33
import { useMediaQuery } from 'react-responsive';
4-
5-
export type FontStyleKey = keyof typeof theme.fontStyles;
6-
7-
// 플랫폼 별 폰트가 다른 경우
8-
interface FontStylesByPlatform {
9-
mobile: FontStyleKey;
10-
tablet: FontStyleKey;
11-
desktop: FontStyleKey;
12-
}
13-
14-
export interface StyledTextProps {
15-
$textTheme: {
16-
style: FontStyleKey | FontStylesByPlatform;
17-
lineHeight?: number;
18-
};
19-
color?: string;
20-
children: any;
21-
}
4+
import type { StyledTextProps } from './dto';
225

236
export const StyledText = styled.div<StyledTextProps>`
247
color: ${(props) => props.color || theme.colors.black};
258
white-space: pre-line;
26-
line-height: ${(props) => props.$textTheme.lineHeight || 1.5};
279
${(props) => {
2810
const isMobile = useMediaQuery({ maxWidth: '767px' });
2911
const isTabletPortrait = useMediaQuery({ minWidth: '768px', maxWidth: '991px' });
3012
const isTabletLandscape = useMediaQuery({ minWidth: '992px', maxWidth: '1219px' });
3113
const isDesktop = useMediaQuery({ minWidth: '1220px' });
3214
3315
let fontStyle;
16+
3417
if (typeof props.$textTheme.style === 'string') {
18+
// style이 문자열이면 일괄적으로 사용
3519
fontStyle = theme.fontStyles[props.$textTheme.style];
3620
} else if (typeof props.$textTheme.style === 'object') {
21+
// style이 객체면 기기에 따른 분기
3722
if (isMobile) {
3823
fontStyle = theme.fontStyles[props.$textTheme.style.mobile];
3924
} else if (isTabletPortrait || isTabletLandscape) {

src/components/Text/dto.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import theme from '@styles/theme';
2+
3+
// 플랫폼 별 폰트가 다른 경우
4+
interface FontStylesByPlatform {
5+
mobile: FontStyleKey;
6+
tablet: FontStyleKey;
7+
desktop: FontStyleKey;
8+
}
9+
10+
export interface StyledTextProps {
11+
$textTheme: {
12+
style: FontStyleKey | FontStylesByPlatform;
13+
lineHeight?: number;
14+
};
15+
color?: string;
16+
children: any;
17+
}
18+
19+
export type FontStyleKey = keyof typeof theme.fontStyles;

0 commit comments

Comments
 (0)