@zohodesk/components 1.6.7 → 1.6.8

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.
@@ -177,6 +177,10 @@
177
177
  white-space: pre-wrap
178
178
  }
179
179
 
180
+ .whiteSpace_breakSpaces {
181
+ white-space: break-spaces;
182
+ }
183
+
180
184
 
181
185
 
182
186
  /*...............Font Size Start.........*/
@@ -7,48 +7,80 @@ export default function cssJSLogic(_ref) {
7
7
  } = _ref;
8
8
  let {
9
9
  $flag_reset,
10
+ shouldReset,
10
11
  $flag_dotted,
12
+ isDotted,
11
13
  $ui_size,
14
+ size,
12
15
  $ui_lineClamp,
16
+ lineClamp,
13
17
  $ui_lineHeight,
18
+ lineHeight,
14
19
  $ui_display,
20
+ display,
15
21
  $ui_weight,
22
+ weight,
16
23
  $ui_typeFace,
24
+ typeFace,
17
25
  $ui_textAlign,
26
+ textAlign,
18
27
  $ui_letterSpacing,
28
+ letterSpacing,
19
29
  $ui_transform,
30
+ transform,
20
31
  $ui_decoration,
32
+ decoration,
21
33
  $ui_className,
34
+ customClass,
22
35
  $ui_wordBreak,
36
+ wordBreak,
23
37
  $ui_wordWrap,
24
- $ui_whiteSpace
38
+ wordWrap,
39
+ $ui_whiteSpace,
40
+ whiteSpace
25
41
  } = props;
42
+ const finalReset = shouldReset !== undefined ? shouldReset : $flag_reset;
43
+ const finalDotted = isDotted !== undefined ? isDotted : $flag_dotted;
44
+ const finalSize = size !== undefined ? size : $ui_size;
45
+ const finalLineClamp = lineClamp !== undefined ? lineClamp : $ui_lineClamp;
46
+ const finalDisplay = display !== undefined ? display : $ui_display;
47
+ const finalWeight = weight !== undefined ? weight : $ui_weight;
48
+ const finalTypeFace = typeFace !== undefined ? typeFace : $ui_typeFace;
49
+ const finalTextAlign = textAlign !== undefined ? textAlign : $ui_textAlign;
50
+ const finalTransform = transform !== undefined ? transform : $ui_transform;
51
+ const finalDecoration = decoration !== undefined ? decoration : $ui_decoration;
52
+ const finalClassName = customClass !== undefined ? customClass : $ui_className;
53
+ const finalWordBreak = wordBreak !== undefined ? wordBreak : $ui_wordBreak;
54
+ const finalWordWrap = wordWrap !== undefined ? wordWrap : $ui_wordWrap;
55
+ const finalWhiteSpace = whiteSpace !== undefined ? whiteSpace : $ui_whiteSpace;
56
+ let finalLineHeight = lineHeight !== undefined ? lineHeight : $ui_lineHeight;
57
+ let finalLetterSpacing = letterSpacing !== undefined ? letterSpacing : $ui_letterSpacing;
26
58
 
27
- if ($ui_letterSpacing) {
28
- $ui_letterSpacing = letterspacingMapping[$ui_letterSpacing];
59
+ if (finalLetterSpacing) {
60
+ finalLetterSpacing = letterspacingMapping[finalLetterSpacing];
29
61
  }
30
62
 
31
- if ($ui_lineHeight) {
32
- $ui_lineHeight = lineheightMapping[$ui_lineHeight];
63
+ if (finalLineHeight) {
64
+ finalLineHeight = lineheightMapping[finalLineHeight];
33
65
  }
34
66
 
35
67
  let typographyClass = compileClassNames({
36
- [style.reset]: $flag_reset,
37
- [style.dotted]: $flag_dotted,
38
- [style[`size${$ui_size}`]]: !!$ui_size,
39
- [style[`lineclamp_${$ui_lineClamp}`]]: !!$ui_lineClamp,
40
- [style[`lineheight_${$ui_lineHeight}`]]: !!$ui_lineHeight,
41
- [style[`display_${$ui_display}`]]: !!$ui_display,
42
- [style[`font_${$ui_weight}`]]: !!$ui_weight,
43
- [style[`fontStyles_${$ui_typeFace}`]]: !!$ui_typeFace,
44
- [style[`textalign_${$ui_textAlign}`]]: !!$ui_textAlign,
45
- [style[`letterspacing_${$ui_letterSpacing}`]]: !!$ui_letterSpacing,
46
- [style[`transform_${$ui_transform}`]]: !!$ui_transform,
47
- [style[`decoration_${$ui_decoration}`]]: !!$ui_decoration,
48
- [$ui_className]: !!$ui_className,
49
- [style[`wordBreak_${$ui_wordBreak}`]]: !!$ui_wordBreak,
50
- [style[`wordWrap_${$ui_wordWrap}`]]: !!$ui_wordWrap,
51
- [style[`whiteSpace_${$ui_whiteSpace}`]]: !!$ui_whiteSpace
68
+ [style.reset]: finalReset,
69
+ [style.dotted]: finalDotted,
70
+ [style[`size${finalSize}`]]: !!finalSize,
71
+ [style[`lineclamp_${finalLineClamp}`]]: !!finalLineClamp,
72
+ [style[`lineheight_${finalLineHeight}`]]: !!finalLineHeight,
73
+ [style[`display_${finalDisplay}`]]: !!finalDisplay,
74
+ [style[`font_${finalWeight}`]]: !!finalWeight,
75
+ [style[`fontStyles_${finalTypeFace}`]]: !!finalTypeFace,
76
+ [style[`textalign_${finalTextAlign}`]]: !!finalTextAlign,
77
+ [style[`letterspacing_${finalLetterSpacing}`]]: !!finalLetterSpacing,
78
+ [style[`transform_${finalTransform}`]]: !!finalTransform,
79
+ [style[`decoration_${finalDecoration}`]]: !!finalDecoration,
80
+ [finalClassName]: !!finalClassName,
81
+ [style[`wordBreak_${finalWordBreak}`]]: !!finalWordBreak,
82
+ [style[`wordWrap_${finalWordWrap}`]]: !!finalWordWrap,
83
+ [style[`whiteSpace_${finalWhiteSpace}`]]: !!finalWhiteSpace
52
84
  });
53
85
  return {
54
86
  typographyClass
@@ -1,9 +1,10 @@
1
+ import { DUMMY_OBJECT } from '@zohodesk/dotkit/es/utils/constants';
1
2
  export const defaultProps = {
2
3
  $ui_className: '',
3
4
  $ui_tagName: 'div',
4
5
  $flag_reset: false,
5
6
  $flag_dotted: false,
6
- $tagAttributes_text: {},
7
- $a11yAttributes_text: {},
8
- $ui_highlightConfig: {}
7
+ $tagAttributes_text: DUMMY_OBJECT,
8
+ $a11yAttributes_text: DUMMY_OBJECT,
9
+ $ui_highlightConfig: DUMMY_OBJECT
9
10
  };
@@ -1,46 +1,88 @@
1
- import PropTypes from 'prop-types';
1
+ import PropTypes from 'prop-types'; // Define prop types once to avoid duplication
2
+
3
+ const propTypeDefinitions = {
4
+ shouldReset: PropTypes.bool,
5
+ display: PropTypes.oneOf(['block', 'inlineBlock', 'inline', 'initial']),
6
+ weight: PropTypes.oneOf(['regular', 'light', 'semibold', 'bold']),
7
+ isDotted: PropTypes.bool,
8
+ textAlign: PropTypes.oneOf(['left', 'right', 'center', 'justify']),
9
+ transform: PropTypes.oneOf(['default', 'upper', 'lower', 'capital']),
10
+ lineClamp: PropTypes.oneOf(['1', '2', '3', '4', '5']),
11
+ typeFace: PropTypes.oneOf(['normal', 'italic']),
12
+ decoration: PropTypes.oneOf(['default', 'underline', 'strike', 'overline']),
13
+ size: PropTypes.oneOf(['7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '24', '25', '26', '28', '29', '30', '32', '34', '35', '36', '40', '50', 'inherit']),
14
+ lineHeight: PropTypes.oneOf(['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '2', 'normal', 'initial', 'inherit']),
15
+ letterSpacing: PropTypes.oneOf(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '2', 'inherit']),
16
+ wordBreak: PropTypes.oneOf(['breakAll', 'keepAll', 'breakWord']),
17
+ wordWrap: PropTypes.oneOf(['normal', 'break']),
18
+ whiteSpace: PropTypes.oneOf(['normal', 'noWrap', 'pre', 'preLine', 'preWrap', 'breakSpaces']),
19
+ customClass: PropTypes.string
20
+ };
2
21
  const typoStyleProps = {
3
- $flag_reset: PropTypes.bool,
4
- $flag_dotted: PropTypes.bool,
5
- $ui_display: PropTypes.oneOf(['block', 'inlineBlock', 'inline', 'initial']),
6
- $ui_weight: PropTypes.oneOf(['regular', 'light', 'semibold', 'bold']),
7
- $ui_textAlign: PropTypes.oneOf(['left', 'right', 'center', 'justify']),
8
- $ui_transform: PropTypes.oneOf(['default', 'upper', 'lower', 'capital']),
9
- $ui_lineClamp: PropTypes.oneOf(['1', '2', '3', '4', '5']),
10
- $ui_typeFace: PropTypes.oneOf(['normal', 'italic']),
11
- $ui_decoration: PropTypes.oneOf(['default', 'underline', 'strike', 'overline']),
12
- $ui_size: PropTypes.oneOf(['7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '24', '25', '26', '28', '29', '30', '32', '34', '35', '36', '40', '50', 'inherit']),
13
- $ui_lineHeight: PropTypes.oneOf(['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '2', 'normal', 'initial', 'inherit']),
14
- $ui_letterSpacing: PropTypes.oneOf(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '2', 'inherit']),
15
- $ui_wordBreak: PropTypes.oneOf(['breakAll', 'keepAll', 'breakWord']),
16
- $ui_wordWrap: PropTypes.oneOf(['normal', 'break']),
17
- $ui_whiteSpace: PropTypes.oneOf(['normal', 'noWrap', 'pre', 'preLine', 'preWrap']),
18
- $ui_className: PropTypes.string
22
+ $flag_reset: propTypeDefinitions.shouldReset,
23
+ shouldReset: propTypeDefinitions.shouldReset,
24
+ $flag_dotted: propTypeDefinitions.isDotted,
25
+ isDotted: propTypeDefinitions.isDotted,
26
+ $ui_display: propTypeDefinitions.display,
27
+ display: propTypeDefinitions.display,
28
+ $ui_weight: propTypeDefinitions.weight,
29
+ weight: propTypeDefinitions.weight,
30
+ $ui_textAlign: propTypeDefinitions.textAlign,
31
+ textAlign: propTypeDefinitions.textAlign,
32
+ $ui_transform: propTypeDefinitions.transform,
33
+ transform: propTypeDefinitions.transform,
34
+ $ui_lineClamp: propTypeDefinitions.lineClamp,
35
+ lineClamp: propTypeDefinitions.lineClamp,
36
+ $ui_typeFace: propTypeDefinitions.typeFace,
37
+ typeFace: propTypeDefinitions.typeFace,
38
+ $ui_decoration: propTypeDefinitions.decoration,
39
+ decoration: propTypeDefinitions.decoration,
40
+ $ui_size: propTypeDefinitions.size,
41
+ size: propTypeDefinitions.size,
42
+ $ui_lineHeight: propTypeDefinitions.lineHeight,
43
+ lineHeight: propTypeDefinitions.lineHeight,
44
+ $ui_letterSpacing: propTypeDefinitions.letterSpacing,
45
+ letterSpacing: propTypeDefinitions.letterSpacing,
46
+ $ui_wordBreak: propTypeDefinitions.wordBreak,
47
+ wordBreak: propTypeDefinitions.wordBreak,
48
+ $ui_wordWrap: propTypeDefinitions.wordWrap,
49
+ wordWrap: propTypeDefinitions.wordWrap,
50
+ $ui_whiteSpace: propTypeDefinitions.whiteSpace,
51
+ whiteSpace: propTypeDefinitions.whiteSpace,
52
+ $ui_className: propTypeDefinitions.customClass,
53
+ customClass: propTypeDefinitions.customClass
19
54
  };
20
55
  const highlightProps = {
21
56
  customStyle: PropTypes.object,
22
57
  shouldExcludeIndices: PropTypes.bool,
23
58
  isCaseSensitive: PropTypes.bool,
24
59
  isWholeWord: PropTypes.bool,
25
- tagName: PropTypes.string,
60
+ as: PropTypes.string,
26
61
  renderHighlight: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
27
62
  styleConfiguration: PropTypes.shape(typoStyleProps)
28
63
  };
64
+ const highlightDataItemShape = PropTypes.shape({
65
+ text: PropTypes.string,
66
+ index: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
67
+ ...highlightProps
68
+ });
69
+ const highlightConfigShape = PropTypes.shape({
70
+ data: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, highlightDataItemShape])),
71
+ ...highlightProps
72
+ });
29
73
  export const propTypes = { ...typoStyleProps,
30
74
  children: PropTypes.node,
31
75
  $ui_tagName: PropTypes.string,
76
+ as: PropTypes.string,
32
77
  $i18n_dataTitle: PropTypes.string,
78
+ dataTitle: PropTypes.string,
33
79
  testId: PropTypes.string,
34
80
  customId: PropTypes.string,
35
81
  customStyle: PropTypes.object,
36
82
  $a11yAttributes_text: PropTypes.object,
83
+ a11yAttributes: PropTypes.object,
37
84
  $tagAttributes_text: PropTypes.object,
38
- $ui_highlightConfig: PropTypes.shape({
39
- data: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
40
- text: PropTypes.string,
41
- index: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
42
- ...highlightProps
43
- })])),
44
- ...highlightProps
45
- })
85
+ tagAttributes: PropTypes.object,
86
+ $ui_highlightConfig: highlightConfigShape,
87
+ highlightConfig: highlightConfigShape
46
88
  };
@@ -11,9 +11,11 @@ export function highlightText(config) {
11
11
  shouldExcludeIndices = false,
12
12
  isCaseSensitive: enableCaseSensitiveMatch = false,
13
13
  isWholeWord: matchWholeWordOnly = false,
14
- tagName: wrapperTagName = 'span',
14
+ as: asTag,
15
+ tagName: tagNameLegacy,
15
16
  renderHighlight: customRenderer
16
17
  } = config;
18
+ const wrapperTagName = asTag ?? tagNameLegacy ?? 'span';
17
19
 
18
20
  if (!sourceText || !highlightData?.length) {
19
21
  return sourceText;
@@ -55,7 +57,7 @@ export function highlightText(config) {
55
57
  shouldExcludeIndices: itemConfiguration.shouldExcludeIndices !== undefined ? itemConfiguration.shouldExcludeIndices : shouldExcludeIndices,
56
58
  isCaseSensitive: itemConfiguration.isCaseSensitive !== undefined ? itemConfiguration.isCaseSensitive : enableCaseSensitiveMatch,
57
59
  matchWholeWordOnly: itemConfiguration.isWholeWord !== undefined ? itemConfiguration.isWholeWord : matchWholeWordOnly,
58
- wrapperTagName: itemConfiguration.tagName !== undefined ? itemConfiguration.tagName : wrapperTagName,
60
+ wrapperTagName: itemConfiguration.as !== undefined ? itemConfiguration.as : itemConfiguration.tagName !== undefined ? itemConfiguration.tagName : wrapperTagName,
59
61
  customStyle: customStyle,
60
62
  customRenderer: itemConfiguration.renderHighlight !== undefined ? itemConfiguration.renderHighlight : customRenderer,
61
63
  highlightClasses: typographyClass,
@@ -29,16 +29,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
29
29
 
30
30
  var Typography = function Typography(props) {
31
31
  var children = props.children,
32
+ as = props.as,
32
33
  $ui_tagName = props.$ui_tagName,
34
+ dataTitle = props.dataTitle,
33
35
  $i18n_dataTitle = props.$i18n_dataTitle,
34
36
  testId = props.testId,
35
37
  customId = props.customId,
38
+ tagAttributes = props.tagAttributes,
36
39
  $tagAttributes_text = props.$tagAttributes_text,
40
+ a11yAttributes = props.a11yAttributes,
37
41
  $a11yAttributes_text = props.$a11yAttributes_text,
38
42
  customStyle = props.customStyle,
43
+ highlightConfig = props.highlightConfig,
39
44
  $ui_highlightConfig = props.$ui_highlightConfig;
40
- var _$ui_highlightConfig$ = $ui_highlightConfig.data,
41
- highlightData = _$ui_highlightConfig$ === void 0 ? [] : _$ui_highlightConfig$;
42
45
  var style = (0, _utils.mergeStyle)(_TypographyModule["default"], customStyle);
43
46
 
44
47
  var _cssJSLogic = (0, _cssJSLogic2["default"])({
@@ -47,12 +50,19 @@ var Typography = function Typography(props) {
47
50
  }),
48
51
  typographyClass = _cssJSLogic.typographyClass;
49
52
 
50
- return /*#__PURE__*/_react["default"].createElement($ui_tagName, _objectSpread(_objectSpread({
53
+ var finalTagName = as !== undefined ? as : $ui_tagName;
54
+ var finalA11yAttributes = a11yAttributes !== undefined ? a11yAttributes : $a11yAttributes_text;
55
+ var finalTagAttributes = tagAttributes !== undefined ? tagAttributes : $tagAttributes_text;
56
+ var finalDataTitle = dataTitle !== undefined ? dataTitle : $i18n_dataTitle;
57
+ var finalHighlightConfig = highlightConfig !== undefined ? highlightConfig : $ui_highlightConfig;
58
+ var _finalHighlightConfig = finalHighlightConfig.data,
59
+ highlightData = _finalHighlightConfig === void 0 ? [] : _finalHighlightConfig;
60
+ return /*#__PURE__*/_react["default"].createElement(finalTagName, _objectSpread(_objectSpread({
51
61
  className: typographyClass,
52
- 'data-title': $i18n_dataTitle,
62
+ 'data-title': finalDataTitle,
53
63
  'data-id': customId,
54
64
  'data-test-id': testId
55
- }, $tagAttributes_text), $a11yAttributes_text), highlightData && highlightData.length > 0 && typeof children === 'string' ? (0, _textHighlighter.highlightText)(_objectSpread(_objectSpread({}, $ui_highlightConfig), {}, {
65
+ }, finalTagAttributes), finalA11yAttributes), highlightData && highlightData.length > 0 && typeof children === 'string' ? (0, _textHighlighter.highlightText)(_objectSpread(_objectSpread({}, finalHighlightConfig), {}, {
56
66
  text: children
57
67
  })) : children);
58
68
  };