@cleartrip/ct-design-typography 4.0.0 → 5.1.0
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/README.md +169 -0
- package/dist/Typography.d.ts +2 -2
- package/dist/Typography.d.ts.map +1 -1
- package/dist/Typography.native.d.ts +6 -0
- package/dist/Typography.native.d.ts.map +1 -0
- package/dist/constants.d.ts +53 -0
- package/dist/constants.d.ts.map +1 -0
- 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 +103 -55
- package/dist/ct-design-typography.cjs.js.map +1 -1
- package/dist/ct-design-typography.esm.js +103 -55
- package/dist/ct-design-typography.esm.js.map +1 -1
- package/dist/ct-design-typography.umd.js +1752 -95
- package/dist/ct-design-typography.umd.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/style.d.ts +174 -498
- package/dist/style.d.ts.map +1 -1
- package/dist/type.d.ts +10 -48
- package/dist/type.d.ts.map +1 -1
- package/package.json +21 -11
- package/src/Typography.native.tsx +109 -0
- package/src/Typography.tsx +122 -0
- package/src/constants.ts +53 -0
- package/src/index.ts +4 -0
- package/src/style.ts +306 -0
- package/src/type.ts +94 -0
- package/dist/StyledTypography/StyledTypography.d.ts +0 -8
- package/dist/StyledTypography/StyledTypography.d.ts.map +0 -1
- package/dist/StyledTypography/index.d.ts +0 -2
- package/dist/StyledTypography/index.d.ts.map +0 -1
- package/dist/StyledTypography/style.d.ts +0 -6
- package/dist/StyledTypography/style.d.ts.map +0 -1
- package/dist/StyledTypography/type.d.ts +0 -18
- package/dist/StyledTypography/type.d.ts.map +0 -1
package/dist/style.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Typography/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Typography/src/style.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,eAAO,MAAM,oBAAoB,GAAI,OAAO,KAAK,EAAE,SAAS,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyKhF,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,KAAK,EAAE,OAAO,mBAAmB,WAmE1E,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM;aAGvB,SAAS,CAAC,SAAS,CAAC;;;;;;;;;CAQjD,CAAC;AAEF,eAAO,MAAM,4BAA4B,GAAI,OAAO,KAAK,EAAE,SAAS,qBAAqB,EAAE,eAAe,OAAO,qCAmBhH,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,iEAOjC;IACD,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;;;eAMqD,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;;;;eAAtB,SAAS,CAAC,WAAW,CAAC;;;;;;CAE3E,CAAC"}
|
package/dist/type.d.ts
CHANGED
|
@@ -1,65 +1,27 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export declare enum TypographyVariant {
|
|
5
|
-
HD1 = "HD1",
|
|
6
|
-
HD2 = "HD2",
|
|
7
|
-
HD3 = "HD3",
|
|
8
|
-
HM1 = "HM1",
|
|
9
|
-
HM2 = "HM2",
|
|
10
|
-
HM3 = "HM3",
|
|
11
|
-
HM4 = "HM4",
|
|
12
|
-
B1 = "B1",
|
|
13
|
-
B2 = "B2",
|
|
14
|
-
B3 = "B3",
|
|
15
|
-
B3CAPS = "B3CAPS",
|
|
16
|
-
B4 = "B4",
|
|
17
|
-
B4CAPS = "B4CAPS",
|
|
18
|
-
P1 = "P1",
|
|
19
|
-
P2 = "P2",
|
|
20
|
-
P3 = "P3",
|
|
21
|
-
L1 = "L1",
|
|
22
|
-
L2 = "L2",
|
|
23
|
-
L3 = "L3",
|
|
24
|
-
OVERLINE = "OVERLINE",
|
|
25
|
-
TAG = "TAG"
|
|
26
|
-
}
|
|
2
|
+
import { TextStyle, Styles } from '@cleartrip/ct-design-types';
|
|
3
|
+
import { TypographyVariant, TypographyColor } from './constants';
|
|
27
4
|
export type TypographyVariantType = `${TypographyVariant}`;
|
|
28
|
-
export declare enum TypographyColor {
|
|
29
|
-
PRIMARY = "primary",
|
|
30
|
-
SECONDARY = "secondary",
|
|
31
|
-
TERTIARY = "tertiary",
|
|
32
|
-
HEADING = "heading",
|
|
33
|
-
SUBHEADING = "subheading",
|
|
34
|
-
SUCCESS = "success",
|
|
35
|
-
ALERT = "alert",
|
|
36
|
-
WARNING = "warning",
|
|
37
|
-
DISABLED = "disabled",
|
|
38
|
-
LINK = "link",
|
|
39
|
-
NEUTRAL = "neutral",
|
|
40
|
-
LINK2 = "link2",
|
|
41
|
-
PRIMARY2 = "primary2"
|
|
42
|
-
}
|
|
43
5
|
export type TypographyColorType = `${TypographyColor}`;
|
|
44
6
|
export type TypographyNodeElementType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span' | 'div' | 'li';
|
|
45
|
-
export interface
|
|
46
|
-
|
|
7
|
+
export interface TypographyStyleConfigProps {
|
|
8
|
+
root?: TextStyle[];
|
|
9
|
+
container?: Styles[];
|
|
10
|
+
}
|
|
11
|
+
export interface ITypography {
|
|
12
|
+
children: ReactNode;
|
|
47
13
|
variant: TypographyVariantType;
|
|
48
14
|
color?: TypographyColorType;
|
|
15
|
+
isUnderlined?: boolean;
|
|
49
16
|
isStriked?: boolean;
|
|
50
17
|
isClickable?: boolean;
|
|
51
18
|
onClick?: () => void;
|
|
52
|
-
className?: string;
|
|
53
|
-
containerClassName?: string;
|
|
54
19
|
colorCode?: string;
|
|
55
20
|
showInItalics?: boolean;
|
|
56
|
-
width?:
|
|
21
|
+
width?: TextStyle['width'];
|
|
57
22
|
lineClamp?: number;
|
|
58
23
|
isDisabled?: boolean;
|
|
59
24
|
componentNode?: TypographyNodeElementType;
|
|
60
|
-
css?: CSSProperties;
|
|
61
25
|
styleConfig?: TypographyStyleConfigProps;
|
|
62
26
|
}
|
|
63
|
-
export interface TypographyProps extends HtmlCompositeAttributes<OwnTypographyProps, 'P' | 'Heading' | 'Span' | 'Div' | 'LI'>, OwnTypographyProps {
|
|
64
|
-
}
|
|
65
27
|
//# sourceMappingURL=type.d.ts.map
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/Typography/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/Typography/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,MAAM,qBAAqB,GAAG,GAAG,iBAAiB,EAAE,CAAC;AAE3D,MAAM,MAAM,mBAAmB,GAAG,GAAG,eAAe,EAAE,CAAC;AAEvD,MAAM,MAAM,yBAAyB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;AAE9G,MAAM,WAAW,0BAA0B;IAIzC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC;IAInB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAI1B,QAAQ,EAAE,SAAS,CAAC;IAKpB,OAAO,EAAE,qBAAqB,CAAC;IAK/B,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAK5B,YAAY,CAAC,EAAE,OAAO,CAAC;IAKvB,SAAS,CAAC,EAAE,OAAO,CAAC;IAKpB,WAAW,CAAC,EAAE,OAAO,CAAC;IAKtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAKrB,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,aAAa,CAAC,EAAE,OAAO,CAAC;IAKxB,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAK3B,SAAS,CAAC,EAAE,MAAM,CAAC;IAKnB,UAAU,CAAC,EAAE,OAAO,CAAC;IAKrB,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAK1C,WAAW,CAAC,EAAE,0BAA0B,CAAC;CAC1C"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleartrip/ct-design-typography",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "5.1.0",
|
|
4
|
+
"description": "Typography component with enhanced styleConfig support for RNW compatibility",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/ct-design-typography.cjs.js",
|
|
7
|
+
"react-native": "src/index.ts",
|
|
7
8
|
"jsnext:main": "dist/ct-design-typography.esm.js",
|
|
8
9
|
"module": "dist/ct-design-typography.esm.js",
|
|
9
10
|
"sideEffects": false,
|
|
@@ -12,19 +13,26 @@
|
|
|
12
13
|
"./dist/ct-design-typography.cjs.js": "./dist/ct-design-typography.browser.cjs.js"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
16
18
|
],
|
|
17
19
|
"dependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@cleartrip/ct-design-
|
|
21
|
-
"@cleartrip/ct-design-
|
|
20
|
+
"@emotion/react": "^11.14.0",
|
|
21
|
+
"@emotion/styled": "^11.14.0",
|
|
22
|
+
"@cleartrip/ct-design-theme": "5.1.0",
|
|
23
|
+
"@cleartrip/ct-design-types": "5.1.0",
|
|
24
|
+
"@cleartrip/ct-design-container": "5.1.0",
|
|
25
|
+
"@cleartrip/ct-design-conditional-wrap": "5.1.0",
|
|
26
|
+
"@cleartrip/ct-design-event-propagation": "5.1.0",
|
|
27
|
+
"@cleartrip/ct-design-common-utils": "5.1.0",
|
|
28
|
+
"@cleartrip/ct-design-style-manager": "5.1.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@emotion/babel-plugin": "^11.12.0"
|
|
22
32
|
},
|
|
23
|
-
"devDependencies": {},
|
|
24
33
|
"peerDependencies": {
|
|
25
34
|
"react": ">=16.8.0",
|
|
26
|
-
"react-dom": ">=16.8.0"
|
|
27
|
-
"styled-components": "^5.3.6"
|
|
35
|
+
"react-dom": ">=16.8.0"
|
|
28
36
|
},
|
|
29
37
|
"publishConfig": {
|
|
30
38
|
"access": "public"
|
|
@@ -34,6 +42,8 @@
|
|
|
34
42
|
"scripts": {
|
|
35
43
|
"watch-package": "rollup -c -w",
|
|
36
44
|
"build-package": "rollup -c",
|
|
37
|
-
"build-package:clean": "rm -rf dist && rollup -c"
|
|
45
|
+
"build-package:clean": "rm -rf dist && rollup -c",
|
|
46
|
+
"publish-package:local": "yalc publish --no-scripts",
|
|
47
|
+
"publish-package:local:registry": "pnpm publish --registry http://localhost:4873 --no-git-checks --access public"
|
|
38
48
|
}
|
|
39
49
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Text } from 'react-native';
|
|
4
|
+
import { useStyles } from '@cleartrip/ct-design-style-manager';
|
|
5
|
+
import { useNativeMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
6
|
+
import { getAccessibilityProps } from '@cleartrip/ct-design-common-utils';
|
|
7
|
+
import EventCollectorProvider, { useMergeEvents } from '@cleartrip/ct-design-event-propagation';
|
|
8
|
+
import { useTriggerEvents } from '@cleartrip/ct-design-event-propagation';
|
|
9
|
+
import Conditional from '@cleartrip/ct-design-conditional-wrap';
|
|
10
|
+
|
|
11
|
+
import { ITypography, TypographyVariantType } from './type';
|
|
12
|
+
import { TypographyColor } from './constants';
|
|
13
|
+
import { getTypographyStyles } from './style';
|
|
14
|
+
|
|
15
|
+
const getTextType = (variant: TypographyVariantType) => {
|
|
16
|
+
const variantMapper = {
|
|
17
|
+
HD1: 'h1',
|
|
18
|
+
HD2: 'h2',
|
|
19
|
+
HD3: 'h3',
|
|
20
|
+
HM1: 'h1',
|
|
21
|
+
HM2: 'h2',
|
|
22
|
+
HM3: 'h3',
|
|
23
|
+
HM4: 'h4',
|
|
24
|
+
B1: 'p',
|
|
25
|
+
B2: 'p',
|
|
26
|
+
B3: 'p',
|
|
27
|
+
B4: 'p',
|
|
28
|
+
P1: 'p',
|
|
29
|
+
P2: 'p',
|
|
30
|
+
P3: 'p',
|
|
31
|
+
P4: 'p',
|
|
32
|
+
L1: 'p',
|
|
33
|
+
L2: 'p',
|
|
34
|
+
L3: 'p',
|
|
35
|
+
OVERLINE: 'p',
|
|
36
|
+
M4BOLD: 'p',
|
|
37
|
+
WRAPPER: 'wrapper',
|
|
38
|
+
};
|
|
39
|
+
return variantMapper[variant as keyof typeof variantMapper] as keyof HTMLElementTagNameMap;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const Typography = forwardRef<Text, ITypography>(
|
|
43
|
+
(
|
|
44
|
+
{
|
|
45
|
+
children,
|
|
46
|
+
color = TypographyColor.PRIMARY,
|
|
47
|
+
variant,
|
|
48
|
+
styleConfig,
|
|
49
|
+
isStriked = false,
|
|
50
|
+
lineClamp,
|
|
51
|
+
onClick,
|
|
52
|
+
isDisabled = false,
|
|
53
|
+
colorCode = '',
|
|
54
|
+
}: ITypography,
|
|
55
|
+
ref: React.ForwardedRef<Text>,
|
|
56
|
+
) => {
|
|
57
|
+
const accessibilityProps = getAccessibilityProps(getTextType(variant));
|
|
58
|
+
|
|
59
|
+
const typographyStyles = useStyles(
|
|
60
|
+
(theme) => {
|
|
61
|
+
return {
|
|
62
|
+
root: getTypographyStyles({
|
|
63
|
+
theme: theme,
|
|
64
|
+
color,
|
|
65
|
+
variant,
|
|
66
|
+
isStriked,
|
|
67
|
+
lineClamp,
|
|
68
|
+
colorCode,
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
[color, variant, isStriked, colorCode],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const { root: rootStyles = [] } = styleConfig || {};
|
|
76
|
+
|
|
77
|
+
const mergedTypographyStyles = useNativeMergeStyles(
|
|
78
|
+
[typographyStyles.root, ...rootStyles],
|
|
79
|
+
[typographyStyles, styleConfig?.root],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const mergedEvents = useMergeEvents({ onClick: [onClick] });
|
|
83
|
+
const { onClick: onClickEvent } = useTriggerEvents(mergedEvents);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<Conditional
|
|
87
|
+
condition={!!onClick}
|
|
88
|
+
wrap={(children) => <EventCollectorProvider value={mergedEvents}>{children}</EventCollectorProvider>}
|
|
89
|
+
>
|
|
90
|
+
<Text
|
|
91
|
+
ref={ref}
|
|
92
|
+
{...accessibilityProps}
|
|
93
|
+
style={mergedTypographyStyles}
|
|
94
|
+
numberOfLines={lineClamp}
|
|
95
|
+
onPress={onClick ? onClickEvent : undefined}
|
|
96
|
+
allowFontScaling={false}
|
|
97
|
+
suppressHighlighting
|
|
98
|
+
disabled={isDisabled}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</Text>
|
|
102
|
+
</Conditional>
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
Typography.displayName = 'Typography';
|
|
108
|
+
|
|
109
|
+
export default Typography;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { useTheme } from '@cleartrip/ct-design-theme';
|
|
3
|
+
import { useStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
|
|
4
|
+
import { Container, IContainer } from '@cleartrip/ct-design-container';
|
|
5
|
+
import ConditionalWrap from '@cleartrip/ct-design-conditional-wrap';
|
|
6
|
+
import { getLineClampStyles, getTypographyStyles } from './style';
|
|
7
|
+
import { TypographyVariantType, ITypography, TypographyNodeElementType } from './type';
|
|
8
|
+
import { TypographyColor } from './constants';
|
|
9
|
+
import { css } from '@emotion/css';
|
|
10
|
+
|
|
11
|
+
const getTextType = (variant: TypographyVariantType): TypographyNodeElementType => {
|
|
12
|
+
const variantMapper = {
|
|
13
|
+
HD1: 'h1',
|
|
14
|
+
HD2: 'h2',
|
|
15
|
+
HD3: 'h3',
|
|
16
|
+
HM1: 'h1',
|
|
17
|
+
HM2: 'h2',
|
|
18
|
+
HM3: 'h3',
|
|
19
|
+
HM4: 'h4',
|
|
20
|
+
B1: 'p',
|
|
21
|
+
B2: 'p',
|
|
22
|
+
B3: 'p',
|
|
23
|
+
B4: 'p',
|
|
24
|
+
P1: 'p',
|
|
25
|
+
P2: 'p',
|
|
26
|
+
P3: 'p',
|
|
27
|
+
P4: 'p',
|
|
28
|
+
L1: 'p',
|
|
29
|
+
L2: 'p',
|
|
30
|
+
L3: 'p',
|
|
31
|
+
B4CAPS: 'p',
|
|
32
|
+
OVERLINE: 'p',
|
|
33
|
+
B3CAPS: 'p',
|
|
34
|
+
M4BOLD: 'p',
|
|
35
|
+
TAG: 'p',
|
|
36
|
+
};
|
|
37
|
+
return variantMapper[variant];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const Typography: React.FC<ITypography> = ({
|
|
41
|
+
children = null,
|
|
42
|
+
variant,
|
|
43
|
+
color = TypographyColor.PRIMARY,
|
|
44
|
+
isClickable,
|
|
45
|
+
isStriked = false,
|
|
46
|
+
isUnderlined = false,
|
|
47
|
+
onClick,
|
|
48
|
+
colorCode = '',
|
|
49
|
+
showInItalics = false,
|
|
50
|
+
lineClamp,
|
|
51
|
+
componentNode,
|
|
52
|
+
isDisabled = false,
|
|
53
|
+
styleConfig = {},
|
|
54
|
+
}) => {
|
|
55
|
+
const theme = useTheme();
|
|
56
|
+
const parsedIsClickable = typeof isClickable === 'boolean' ? isClickable : !!onClick;
|
|
57
|
+
|
|
58
|
+
const typographyStyles = useStyles(
|
|
59
|
+
(theme) => {
|
|
60
|
+
return {
|
|
61
|
+
root: getTypographyStyles({
|
|
62
|
+
theme: theme,
|
|
63
|
+
variant,
|
|
64
|
+
color,
|
|
65
|
+
isClickable: parsedIsClickable,
|
|
66
|
+
isStriked,
|
|
67
|
+
isUnderlined,
|
|
68
|
+
colorCode,
|
|
69
|
+
showInItalics,
|
|
70
|
+
lineClamp,
|
|
71
|
+
isDisabled,
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
[
|
|
76
|
+
variant,
|
|
77
|
+
color,
|
|
78
|
+
parsedIsClickable,
|
|
79
|
+
isStriked,
|
|
80
|
+
isUnderlined,
|
|
81
|
+
colorCode,
|
|
82
|
+
showInItalics,
|
|
83
|
+
lineClamp,
|
|
84
|
+
isDisabled,
|
|
85
|
+
theme,
|
|
86
|
+
],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const { root: customRootStyles = [], container: customContainerStyles = [] } = styleConfig || {};
|
|
90
|
+
|
|
91
|
+
const clampClass = useMemo(() => {
|
|
92
|
+
return css(getLineClampStyles(lineClamp));
|
|
93
|
+
}, [lineClamp]);
|
|
94
|
+
|
|
95
|
+
const mergedRootStyles = useWebMergeStyles(
|
|
96
|
+
[typographyStyles.root, clampClass, ...customRootStyles],
|
|
97
|
+
[typographyStyles.root, clampClass, customRootStyles],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const ComponentToRender = componentNode || getTextType(variant);
|
|
101
|
+
|
|
102
|
+
const containerAsSupportedValues: readonly IContainer['as'][] = ['p', 'main', 'section', 'article', 'div'] as const;
|
|
103
|
+
const containerAs: IContainer['as'] =
|
|
104
|
+
componentNode && (containerAsSupportedValues as readonly string[]).includes(componentNode)
|
|
105
|
+
? (componentNode as IContainer['as'])
|
|
106
|
+
: 'div';
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<ConditionalWrap
|
|
110
|
+
condition={parsedIsClickable}
|
|
111
|
+
wrap={(children) => (
|
|
112
|
+
<Container onClick={onClick} styleConfig={{ root: customContainerStyles }} as={containerAs}>
|
|
113
|
+
{children}
|
|
114
|
+
</Container>
|
|
115
|
+
)}
|
|
116
|
+
>
|
|
117
|
+
<ComponentToRender className={mergedRootStyles}>{children}</ComponentToRender>
|
|
118
|
+
</ConditionalWrap>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default Typography;
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export enum TypographyVariant {
|
|
2
|
+
HD1 = 'HD1',
|
|
3
|
+
HD2 = 'HD2',
|
|
4
|
+
HD3 = 'HD3',
|
|
5
|
+
HM1 = 'HM1',
|
|
6
|
+
HM2 = 'HM2',
|
|
7
|
+
HM3 = 'HM3',
|
|
8
|
+
HM4 = 'HM4',
|
|
9
|
+
B1 = 'B1',
|
|
10
|
+
B2 = 'B2',
|
|
11
|
+
B3 = 'B3',
|
|
12
|
+
B3CAPS = 'B3CAPS',
|
|
13
|
+
B4 = 'B4',
|
|
14
|
+
B4CAPS = 'B4CAPS',
|
|
15
|
+
P1 = 'P1',
|
|
16
|
+
P2 = 'P2',
|
|
17
|
+
P3 = 'P3',
|
|
18
|
+
P4 = 'P4',
|
|
19
|
+
L1 = 'L1',
|
|
20
|
+
L2 = 'L2',
|
|
21
|
+
L3 = 'L3',
|
|
22
|
+
OVERLINE = 'OVERLINE',
|
|
23
|
+
TAG = 'TAG',
|
|
24
|
+
M4BOLD = 'M4BOLD',
|
|
25
|
+
WRAPPER = 'WRAPPER',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export enum TypographyColor {
|
|
29
|
+
PRIMARY = 'primary',
|
|
30
|
+
SECONDARY = 'secondary',
|
|
31
|
+
TERTIARY = 'tertiary',
|
|
32
|
+
HEADING = 'heading',
|
|
33
|
+
SUBHEADING = 'subheading',
|
|
34
|
+
SUCCESS = 'success',
|
|
35
|
+
ALERT = 'alert',
|
|
36
|
+
WARNING = 'warning',
|
|
37
|
+
DISABLED = 'disabled',
|
|
38
|
+
LINK = 'link',
|
|
39
|
+
NEUTRAL = 'neutral',
|
|
40
|
+
LINK2 = 'link2',
|
|
41
|
+
PRIMARY2 = 'primary2',
|
|
42
|
+
SECONDARY2 = 'secondary2',
|
|
43
|
+
GRAPETINI = 'grapetini900',
|
|
44
|
+
PINA_COLADA750 = 'pinacolada750',
|
|
45
|
+
BRAND = 'brand',
|
|
46
|
+
ALERT500 = 'alert500',
|
|
47
|
+
NEUTRAL50 = 'neutral50',
|
|
48
|
+
MARGARITA750 = 'margarita750',
|
|
49
|
+
GREEN100 = 'green100',
|
|
50
|
+
RED100 = 'red100',
|
|
51
|
+
CORALPINK = 'coralpink',
|
|
52
|
+
WARNING500 = 'warning500',
|
|
53
|
+
}
|
package/src/index.ts
ADDED