cpk-ui 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { Text } from 'react-native';
|
|
4
2
|
import { isEmptyObject } from '../../../utils/theme';
|
|
5
3
|
import { withTheme } from '../../../providers/ThemeProvider';
|
|
6
4
|
import { light } from '../../../utils/colors';
|
|
7
5
|
import styled, { css } from '@emotion/native';
|
|
8
|
-
// Base Styled Component Factory
|
|
9
6
|
const createBaseText = (colorResolver, fallbackColor) => styled.Text `
|
|
10
|
-
font-family: ${({ fontWeight }) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
font-family: ${({ fontWeight }) => {
|
|
8
|
+
const { normal, thin = normal, bold = normal } = getFontFamilies();
|
|
9
|
+
switch (fontWeight) {
|
|
10
|
+
case 'bold':
|
|
11
|
+
return bold;
|
|
12
|
+
case 'thin':
|
|
13
|
+
return thin;
|
|
14
|
+
default:
|
|
15
|
+
return normal;
|
|
16
|
+
}
|
|
17
|
+
}};
|
|
15
18
|
color: ${({ theme }) => {
|
|
16
19
|
if (!theme || isEmptyObject(theme)) {
|
|
17
20
|
return fallbackColor;
|
|
@@ -28,10 +31,8 @@ const createTextComponent = ({ BaseText, fontSize, lineHeight, fontWeight, }) =>
|
|
|
28
31
|
{ includeFontPadding: false },
|
|
29
32
|
style,
|
|
30
33
|
], children: children })));
|
|
31
|
-
// Standard and Inverted Base Components
|
|
32
34
|
const StandardBaseText = createBaseText((theme) => theme.text.basic, 'gray');
|
|
33
35
|
const InvertedBaseText = createBaseText((theme) => theme.text.contrast, light.text.contrast);
|
|
34
|
-
// Standard Typography Components
|
|
35
36
|
const Title = createTextComponent({
|
|
36
37
|
BaseText: StandardBaseText,
|
|
37
38
|
fontSize: 36,
|
|
@@ -88,7 +89,6 @@ const Body4 = createTextComponent({
|
|
|
88
89
|
fontSize: 12,
|
|
89
90
|
lineHeight: 16.4,
|
|
90
91
|
});
|
|
91
|
-
// Inverted Typography Components
|
|
92
92
|
const InvertedTitle = createTextComponent({
|
|
93
93
|
BaseText: InvertedBaseText,
|
|
94
94
|
fontSize: 36,
|
|
@@ -145,6 +145,15 @@ const InvertedBody4 = createTextComponent({
|
|
|
145
145
|
fontSize: 12,
|
|
146
146
|
lineHeight: 16.4,
|
|
147
147
|
});
|
|
148
|
+
let currentFontFamilies = {
|
|
149
|
+
normal: 'Pretendard',
|
|
150
|
+
thin: 'Pretendard-Thin',
|
|
151
|
+
bold: 'Pretendard-Bold',
|
|
152
|
+
};
|
|
153
|
+
export const setFontFamily = (fontFamilies) => {
|
|
154
|
+
currentFontFamilies = { ...currentFontFamilies, ...fontFamilies };
|
|
155
|
+
};
|
|
156
|
+
export const getFontFamilies = () => currentFontFamilies;
|
|
148
157
|
export const Typography = {
|
|
149
158
|
Title,
|
|
150
159
|
Heading1,
|
|
@@ -169,18 +178,3 @@ export const TypographyInverted = {
|
|
|
169
178
|
Body3: InvertedBody3,
|
|
170
179
|
Body4: InvertedBody4,
|
|
171
180
|
};
|
|
172
|
-
export const setFontFamily = (fontFamily) => {
|
|
173
|
-
const style = {
|
|
174
|
-
includeFontPadding: false,
|
|
175
|
-
fontFamily,
|
|
176
|
-
};
|
|
177
|
-
// @ts-ignore
|
|
178
|
-
let oldRender = Text.render;
|
|
179
|
-
// @ts-ignore
|
|
180
|
-
Text.render = (...args) => {
|
|
181
|
-
let origin = oldRender.call(this, ...args);
|
|
182
|
-
return React.cloneElement(origin, {
|
|
183
|
-
style: [style, origin.props.style],
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
};
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import React, {ReactNode} from 'react';
|
|
2
2
|
import {StyleProp, Text} from 'react-native';
|
|
3
|
-
|
|
4
3
|
import {CpkTheme, isEmptyObject} from '../../../utils/theme';
|
|
5
4
|
import {withTheme} from '../../../providers/ThemeProvider';
|
|
6
5
|
import {light} from '../../../utils/colors';
|
|
7
6
|
import {type TextStyle} from 'react-native';
|
|
8
7
|
import styled, {css} from '@emotion/native';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
type FontFamilyOptions = {
|
|
10
|
+
normal: string;
|
|
11
|
+
thin?: string;
|
|
12
|
+
bold?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
11
15
|
const createBaseText = (
|
|
12
16
|
colorResolver: (theme: CpkTheme) => string,
|
|
13
17
|
fallbackColor: string,
|
|
14
18
|
) => styled.Text<{theme?: CpkTheme; fontWeight?: 'normal' | 'bold' | 'thin'}>`
|
|
15
|
-
font-family: ${({fontWeight}) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
font-family: ${({fontWeight}) => {
|
|
20
|
+
const {normal, thin = normal, bold = normal} = getFontFamilies();
|
|
21
|
+
switch (fontWeight) {
|
|
22
|
+
case 'bold':
|
|
23
|
+
return bold;
|
|
24
|
+
case 'thin':
|
|
25
|
+
return thin;
|
|
26
|
+
default:
|
|
27
|
+
return normal;
|
|
28
|
+
}
|
|
29
|
+
}};
|
|
21
30
|
color: ${({theme}) => {
|
|
22
31
|
if (!theme || isEmptyObject(theme)) {
|
|
23
32
|
return fallbackColor;
|
|
@@ -26,7 +35,6 @@ const createBaseText = (
|
|
|
26
35
|
}};
|
|
27
36
|
`;
|
|
28
37
|
|
|
29
|
-
// Common Text Component Factory
|
|
30
38
|
type TextComponentType = ReturnType<typeof styled.Text>;
|
|
31
39
|
|
|
32
40
|
const createTextComponent = ({
|
|
@@ -68,14 +76,12 @@ const createTextComponent = ({
|
|
|
68
76
|
),
|
|
69
77
|
) as unknown as TextComponentType;
|
|
70
78
|
|
|
71
|
-
// Standard and Inverted Base Components
|
|
72
79
|
const StandardBaseText = createBaseText((theme) => theme.text.basic, 'gray');
|
|
73
80
|
const InvertedBaseText = createBaseText(
|
|
74
81
|
(theme) => theme.text.contrast,
|
|
75
82
|
light.text.contrast,
|
|
76
83
|
);
|
|
77
84
|
|
|
78
|
-
// Standard Typography Components
|
|
79
85
|
const Title = createTextComponent({
|
|
80
86
|
BaseText: StandardBaseText,
|
|
81
87
|
fontSize: 36,
|
|
@@ -142,7 +148,6 @@ const Body4 = createTextComponent({
|
|
|
142
148
|
lineHeight: 16.4,
|
|
143
149
|
});
|
|
144
150
|
|
|
145
|
-
// Inverted Typography Components
|
|
146
151
|
const InvertedTitle = createTextComponent({
|
|
147
152
|
BaseText: InvertedBaseText,
|
|
148
153
|
fontSize: 36,
|
|
@@ -209,6 +214,18 @@ const InvertedBody4 = createTextComponent({
|
|
|
209
214
|
lineHeight: 16.4,
|
|
210
215
|
});
|
|
211
216
|
|
|
217
|
+
let currentFontFamilies: FontFamilyOptions = {
|
|
218
|
+
normal: 'Pretendard',
|
|
219
|
+
thin: 'Pretendard-Thin',
|
|
220
|
+
bold: 'Pretendard-Bold',
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const setFontFamily = (fontFamilies: FontFamilyOptions): void => {
|
|
224
|
+
currentFontFamilies = {...currentFontFamilies, ...fontFamilies};
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export const getFontFamilies = (): FontFamilyOptions => currentFontFamilies;
|
|
228
|
+
|
|
212
229
|
export const Typography = {
|
|
213
230
|
Title,
|
|
214
231
|
Heading1,
|
|
@@ -234,22 +251,3 @@ export const TypographyInverted = {
|
|
|
234
251
|
Body3: InvertedBody3,
|
|
235
252
|
Body4: InvertedBody4,
|
|
236
253
|
};
|
|
237
|
-
|
|
238
|
-
export const setFontFamily = (fontFamily: string): void => {
|
|
239
|
-
const style = {
|
|
240
|
-
includeFontPadding: false,
|
|
241
|
-
fontFamily,
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
// @ts-ignore
|
|
245
|
-
let oldRender = Text.render;
|
|
246
|
-
|
|
247
|
-
// @ts-ignore
|
|
248
|
-
Text.render = (...args: any) => {
|
|
249
|
-
let origin = oldRender.call(this, ...args);
|
|
250
|
-
|
|
251
|
-
return React.cloneElement(origin, {
|
|
252
|
-
style: [style, origin.props.style],
|
|
253
|
-
});
|
|
254
|
-
};
|
|
255
|
-
};
|