@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.
@@ -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
- 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',
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: 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
- 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';
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
- 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
- );
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;