@cleartrip/ct-design-typography 5.6.0 → 5.7.0-SNAPSHOT-native-main.1
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.
- package/dist/Typography.d.ts.map +1 -1
- package/dist/ct-design-typography.browser.cjs.js +1 -1
- package/dist/ct-design-typography.browser.cjs.js.map +1 -1
- package/dist/ct-design-typography.browser.esm.js +1 -1
- package/dist/ct-design-typography.browser.esm.js.map +1 -1
- package/dist/ct-design-typography.cjs.js +30 -29
- package/dist/ct-design-typography.cjs.js.map +1 -1
- package/dist/ct-design-typography.esm.js +30 -25
- package/dist/ct-design-typography.esm.js.map +1 -1
- package/dist/ct-design-typography.umd.js +34 -32
- package/dist/ct-design-typography.umd.js.map +1 -1
- package/package.json +18 -8
- package/src/Typography.tsx +38 -38
package/src/Typography.tsx
CHANGED
|
@@ -2,14 +2,14 @@ import React, { useMemo } from 'react';
|
|
|
2
2
|
import { useTheme } from '@cleartrip/ct-design-theme';
|
|
3
3
|
import { useStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
4
4
|
import { Container, IContainer } from '@cleartrip/ct-design-container';
|
|
5
|
-
import ConditionalWrap from '@cleartrip/ct-design-conditional-wrap';
|
|
6
5
|
import { getLineClampStyles, getTypographyStyles } from './style';
|
|
6
|
+
import type { Styles } from '@cleartrip/ct-design-types';
|
|
7
7
|
import { TypographyVariantType, ITypography, TypographyNodeElementType } from './type';
|
|
8
8
|
import { TypographyColor } from './constants';
|
|
9
9
|
import { css } from '@emotion/css';
|
|
10
10
|
|
|
11
11
|
const getTextType = (variant: TypographyVariantType): TypographyNodeElementType => {
|
|
12
|
-
const variantMapper = {
|
|
12
|
+
const variantMapper: Record<TypographyVariantType, TypographyNodeElementType> = {
|
|
13
13
|
HD1: 'h1',
|
|
14
14
|
HD2: 'h2',
|
|
15
15
|
HD3: 'h3',
|
|
@@ -17,24 +17,27 @@ const getTextType = (variant: TypographyVariantType): TypographyNodeElementType
|
|
|
17
17
|
HM2: 'h2',
|
|
18
18
|
HM3: 'h3',
|
|
19
19
|
HM4: 'h4',
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
// Body / paragraph / link variants: inline on web
|
|
21
|
+
B1: 'span',
|
|
22
|
+
B2: 'span',
|
|
23
|
+
B3: 'span',
|
|
24
|
+
B4: 'span',
|
|
25
|
+
P1: 'span',
|
|
26
|
+
P2: 'span',
|
|
27
|
+
P3: 'span',
|
|
28
|
+
P4: 'span',
|
|
29
|
+
L1: 'span',
|
|
30
|
+
L2: 'span',
|
|
31
|
+
L3: 'span',
|
|
32
|
+
M4BOLD: 'span',
|
|
33
|
+
// Block-only variants
|
|
34
|
+
B4CAPS: 'div',
|
|
35
|
+
OVERLINE: 'div',
|
|
36
|
+
B3CAPS: 'div',
|
|
37
|
+
TAG: 'div',
|
|
38
|
+
WRAPPER: 'div',
|
|
36
39
|
};
|
|
37
|
-
return variantMapper[variant];
|
|
40
|
+
return variantMapper[variant] ?? 'span';
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
const Typography: React.FC<ITypography> = ({
|
|
@@ -59,7 +62,7 @@ const Typography: React.FC<ITypography> = ({
|
|
|
59
62
|
(theme) => {
|
|
60
63
|
return {
|
|
61
64
|
root: getTypographyStyles({
|
|
62
|
-
theme
|
|
65
|
+
theme,
|
|
63
66
|
variant,
|
|
64
67
|
color,
|
|
65
68
|
isClickable: parsedIsClickable,
|
|
@@ -97,26 +100,23 @@ const Typography: React.FC<ITypography> = ({
|
|
|
97
100
|
[typographyStyles.root, clampClass, customRootStyles],
|
|
98
101
|
);
|
|
99
102
|
|
|
100
|
-
const ComponentToRender = componentNode || getTextType(variant);
|
|
103
|
+
const ComponentToRender = componentNode || getTextType(variant) || 'p';
|
|
104
|
+
const isInlineNode = ComponentToRender === 'span';
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
?
|
|
106
|
-
:
|
|
106
|
+
if (parsedIsClickable) {
|
|
107
|
+
const containerAs: IContainer['as'] = isInlineNode ? 'span' : 'div';
|
|
108
|
+
const clickableContainerStyles = isInlineNode
|
|
109
|
+
? [{ display: 'inline' } as unknown as Styles, ...customContainerStyles]
|
|
110
|
+
: customContainerStyles;
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
>
|
|
117
|
-
<ComponentToRender className={mergedRootStyles}>{children}</ComponentToRender>
|
|
118
|
-
</ConditionalWrap>
|
|
119
|
-
);
|
|
112
|
+
return (
|
|
113
|
+
<Container onClick={onClick} styleConfig={{ root: clickableContainerStyles }} as={containerAs}>
|
|
114
|
+
<ComponentToRender className={mergedRootStyles}>{children}</ComponentToRender>
|
|
115
|
+
</Container>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return <ComponentToRender className={mergedRootStyles}>{children}</ComponentToRender>;
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
export default Typography;
|