@zohodesk/components 1.0.0-temp-233 → 1.0.0-temp-235

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.
Files changed (51) hide show
  1. package/.cli/propValidation_report.html +1 -1
  2. package/README.md +13 -0
  3. package/assets/Appearance/dark/mode/Component_DarkMode.module.css +4 -4
  4. package/assets/Appearance/dark/themes/blue/blue_CTA_DarkModifyCategory.module.css +461 -8
  5. package/assets/Appearance/dark/themes/green/green_CTA_DarkModifyCategory.module.css +461 -8
  6. package/assets/Appearance/dark/themes/orange/orange_CTA_DarkModifyCategory.module.css +461 -8
  7. package/assets/Appearance/dark/themes/red/red_CTA_DarkModifyCategory.module.css +461 -8
  8. package/assets/Appearance/dark/themes/yellow/yellow_CTA_DarkModifyCategory.module.css +461 -8
  9. package/assets/Appearance/light/mode/Component_LightMode.module.css +6 -6
  10. package/assets/Appearance/light/themes/blue/blue_CTA_LightModifyCategory.module.css +461 -8
  11. package/assets/Appearance/light/themes/green/green_CTA_LightModifyCategory.module.css +461 -8
  12. package/assets/Appearance/light/themes/orange/orange_CTA_LightModifyCategory.module.css +461 -8
  13. package/assets/Appearance/light/themes/red/red_CTA_LightModifyCategory.module.css +461 -8
  14. package/assets/Appearance/light/themes/yellow/yellow_CTA_LightModifyCategory.module.css +461 -8
  15. package/assets/Appearance/pureDark/mode/Component_PureDarkMode.module.css +3 -3
  16. package/assets/Appearance/pureDark/themes/blue/blue_CTA_PureDarkModifyCategory.module.css +461 -8
  17. package/assets/Appearance/pureDark/themes/green/green_CTA_PureDarkModifyCategory.module.css +461 -8
  18. package/assets/Appearance/pureDark/themes/orange/orange_CTA_PureDarkModifyCategory.module.css +461 -8
  19. package/assets/Appearance/pureDark/themes/red/red_CTA_PureDarkModifyCategory.module.css +461 -8
  20. package/assets/Appearance/pureDark/themes/yellow/yellow_CTA_PureDarkModifyCategory.module.css +461 -8
  21. package/es/MultiSelect/MultiSelect.js +36 -12
  22. package/es/MultiSelect/Suggestions.js +171 -100
  23. package/es/MultiSelect/props/defaultProps.js +2 -0
  24. package/es/MultiSelect/props/propTypes.js +4 -0
  25. package/es/Select/Select.js +41 -12
  26. package/es/Select/props/defaultProps.js +1 -0
  27. package/es/Select/props/propTypes.js +1 -0
  28. package/es/Typography/Typography.js +9 -2
  29. package/es/Typography/__tests__/Typography.spec.js +334 -0
  30. package/es/Typography/__tests__/__snapshots__/Typography.spec.js.snap +451 -0
  31. package/es/Typography/highlight.js +144 -0
  32. package/es/Typography/props/defaultProps.js +2 -1
  33. package/es/Typography/props/propTypes.js +26 -1
  34. package/es/utils/Common.js +2 -1
  35. package/es/utils/dropDownUtils.js +3 -1
  36. package/lib/MultiSelect/MultiSelect.js +36 -10
  37. package/lib/MultiSelect/Suggestions.js +174 -104
  38. package/lib/MultiSelect/props/defaultProps.js +2 -0
  39. package/lib/MultiSelect/props/propTypes.js +4 -0
  40. package/lib/Select/Select.js +40 -9
  41. package/lib/Select/props/defaultProps.js +1 -0
  42. package/lib/Select/props/propTypes.js +1 -0
  43. package/lib/Typography/Typography.js +9 -2
  44. package/lib/Typography/__tests__/Typography.spec.js +342 -0
  45. package/lib/Typography/__tests__/__snapshots__/Typography.spec.js.snap +451 -0
  46. package/lib/Typography/highlight.js +151 -0
  47. package/lib/Typography/props/defaultProps.js +2 -1
  48. package/lib/Typography/props/propTypes.js +31 -1
  49. package/lib/utils/Common.js +4 -2
  50. package/lib/utils/dropDownUtils.js +3 -1
  51. package/package.json +6 -6
@@ -0,0 +1,451 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Typography component should be render with text children 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class=""
7
+ >
8
+ Text testing
9
+ </div>
10
+ </DocumentFragment>
11
+ `;
12
+
13
+ exports[`Typography component should be render with the basic set of default props 1`] = `
14
+ <DocumentFragment>
15
+ <div
16
+ class=""
17
+ />
18
+ </DocumentFragment>
19
+ `;
20
+
21
+ exports[`Typography component should render customised render the highlight element for all highlighted words 1`] = `
22
+ <DocumentFragment>
23
+ <div
24
+ class=""
25
+ >
26
+ The
27
+ <div
28
+ aria-labelledby="1"
29
+ class="container effect medium lgRadius default "
30
+ data-id="tag_Tag"
31
+ data-selector-id="tag"
32
+ data-test-id="tag_Tag"
33
+ data-title="Sun"
34
+ tabindex="0"
35
+ >
36
+ <div
37
+ aria-hidden="true"
38
+ class="text mediumtext"
39
+ id="1"
40
+ >
41
+ Sun
42
+ </div>
43
+ </div>
44
+ was bright.
45
+ </div>
46
+ </DocumentFragment>
47
+ `;
48
+
49
+ exports[`Typography component should render globally skip highlights at given indexes, with isExcludedIndex 1`] = `
50
+ <DocumentFragment>
51
+ <div
52
+ class=""
53
+ >
54
+ The sun was bright, the
55
+ <span
56
+ class="font_bold decoration_underline"
57
+ >
58
+ sun
59
+ </span>
60
+ was warm, the
61
+ <span
62
+ class="font_bold decoration_underline"
63
+ >
64
+ sun
65
+ </span>
66
+ was high in the sky.
67
+ </div>
68
+ </DocumentFragment>
69
+ `;
70
+
71
+ exports[`Typography component should render highlight by Index 1`] = `
72
+ <DocumentFragment>
73
+ <div
74
+ class=""
75
+ >
76
+ The
77
+ <span
78
+ class="font_bold decoration_underline"
79
+ >
80
+ sun
81
+ </span>
82
+ was bright, I walked
83
+ <span
84
+ class="font_bold decoration_underline"
85
+ >
86
+ under
87
+ </span>
88
+ the
89
+ <span
90
+ class="font_bold decoration_underline"
91
+ >
92
+ sun
93
+ </span>
94
+ , I talked under the sun.
95
+ </div>
96
+ </DocumentFragment>
97
+ `;
98
+
99
+ exports[`Typography component should render highlighted word 1`] = `
100
+ <DocumentFragment>
101
+ <div
102
+ class=""
103
+ >
104
+ The
105
+ <span
106
+ class="font_bold"
107
+ >
108
+ sun
109
+ </span>
110
+ was bright, the
111
+ <span
112
+ class="font_bold"
113
+ >
114
+ sun
115
+ </span>
116
+ was warm, the
117
+ <span
118
+ class="font_bold"
119
+ >
120
+ sun
121
+ </span>
122
+ was high in the sky.
123
+ </div>
124
+ </DocumentFragment>
125
+ `;
126
+
127
+ exports[`Typography component should render separate Styles per Word 1`] = `
128
+ <DocumentFragment>
129
+ <div
130
+ class=""
131
+ >
132
+ The
133
+ <span
134
+ class="font_bold"
135
+ >
136
+ sun
137
+ </span>
138
+ was bright, I walked
139
+ <span
140
+ class="decoration_underline"
141
+ >
142
+ under
143
+ </span>
144
+ the
145
+ <span
146
+ class="font_bold"
147
+ >
148
+ sun
149
+ </span>
150
+ , I talked
151
+ <span
152
+ class="decoration_underline"
153
+ >
154
+ under
155
+ </span>
156
+ the
157
+ <span
158
+ class="font_bold"
159
+ >
160
+ sun
161
+ </span>
162
+ .
163
+ </div>
164
+ </DocumentFragment>
165
+ `;
166
+
167
+ exports[`Typography component should render separate customised render the highlight element for each highlighted word 1`] = `
168
+ <DocumentFragment>
169
+ <div
170
+ class=""
171
+ >
172
+ The
173
+ <div
174
+ aria-labelledby="2"
175
+ class="container effect medium lgRadius default "
176
+ data-id="tag_Tag"
177
+ data-selector-id="tag"
178
+ data-test-id="tag_Tag"
179
+ data-title="Sun"
180
+ tabindex="0"
181
+ >
182
+ <div
183
+ aria-hidden="true"
184
+ class="text mediumtext"
185
+ id="2"
186
+ >
187
+ Sun
188
+ </div>
189
+ </div>
190
+ and
191
+ <div
192
+ aria-labelledby="3"
193
+ class="container effect medium lgRadius default "
194
+ data-id="tag_Tag"
195
+ data-selector-id="tag"
196
+ data-test-id="tag_Tag"
197
+ data-title="Moon"
198
+ tabindex="0"
199
+ >
200
+ <div
201
+ aria-hidden="true"
202
+ class="text mediumtext"
203
+ id="3"
204
+ >
205
+ Moon
206
+ </div>
207
+ </div>
208
+ were bright.
209
+ </div>
210
+ </DocumentFragment>
211
+ `;
212
+
213
+ exports[`Typography component should render with global case-sensitive option 1`] = `
214
+ <DocumentFragment>
215
+ <div
216
+ class=""
217
+ >
218
+ The
219
+ <span
220
+ class="font_bold decoration_underline"
221
+ >
222
+ Sun
223
+ </span>
224
+ was bright, the
225
+ <span
226
+ class="font_bold decoration_underline"
227
+ >
228
+ moon
229
+ </span>
230
+ was bright, the sun was warm.
231
+ </div>
232
+ </DocumentFragment>
233
+ `;
234
+
235
+ exports[`Typography component should render with global custom class for all highlights 1`] = `
236
+ <DocumentFragment>
237
+ <div
238
+ class=""
239
+ >
240
+ The
241
+ <span
242
+ class="global_custom_class"
243
+ >
244
+ sun
245
+ </span>
246
+ and
247
+ <span
248
+ class="global_custom_class"
249
+ >
250
+ moon
251
+ </span>
252
+ were bright.
253
+ </div>
254
+ </DocumentFragment>
255
+ `;
256
+
257
+ exports[`Typography component should render with global custom style for all highlights 1`] = `
258
+ <DocumentFragment>
259
+ <div
260
+ class=""
261
+ >
262
+ The
263
+ <span
264
+ class=""
265
+ style="background-color: lightgreen;"
266
+ >
267
+ sun
268
+ </span>
269
+ and
270
+ <span
271
+ class=""
272
+ style="background-color: lightgreen;"
273
+ >
274
+ moon
275
+ </span>
276
+ were bright.
277
+ </div>
278
+ </DocumentFragment>
279
+ `;
280
+
281
+ exports[`Typography component should render with global tagName applied to all highlights 1`] = `
282
+ <DocumentFragment>
283
+ <div
284
+ class=""
285
+ >
286
+ The
287
+ <i
288
+ class=""
289
+ >
290
+ sun
291
+ </i>
292
+ and
293
+ <i
294
+ class=""
295
+ >
296
+ moon
297
+ </i>
298
+ were bright.
299
+ </div>
300
+ </DocumentFragment>
301
+ `;
302
+
303
+ exports[`Typography component should render with global whole-word match only 1`] = `
304
+ <DocumentFragment>
305
+ <div
306
+ class=""
307
+ >
308
+ Sunflower is a flower. The
309
+ <span
310
+ class="font_bold decoration_underline"
311
+ >
312
+ Sun
313
+ </span>
314
+ was bright, the moonlight was bright.
315
+ </div>
316
+ </DocumentFragment>
317
+ `;
318
+
319
+ exports[`Typography component should render with separate case-sensitive option per word 1`] = `
320
+ <DocumentFragment>
321
+ <div
322
+ class=""
323
+ >
324
+ The
325
+ <span
326
+ class="font_bold decoration_underline"
327
+ >
328
+ Sun
329
+ </span>
330
+ was bright, the
331
+ <span
332
+ class="font_bold decoration_underline"
333
+ >
334
+ Moon
335
+ </span>
336
+ was bright, the sun was warm.
337
+ </div>
338
+ </DocumentFragment>
339
+ `;
340
+
341
+ exports[`Typography component should render with separate custom class for each highlighted word 1`] = `
342
+ <DocumentFragment>
343
+ <div
344
+ class=""
345
+ >
346
+ The
347
+ <span
348
+ class="separate_custom_class_sun"
349
+ >
350
+ sun
351
+ </span>
352
+ and
353
+ <span
354
+ class="separate_custom_class_moon"
355
+ >
356
+ moon
357
+ </span>
358
+ were bright.
359
+ </div>
360
+ </DocumentFragment>
361
+ `;
362
+
363
+ exports[`Typography component should render with separate custom style per word 1`] = `
364
+ <DocumentFragment>
365
+ <div
366
+ class=""
367
+ >
368
+ The
369
+ <span
370
+ class=""
371
+ style="background-color: lightgreen;"
372
+ >
373
+ sun
374
+ </span>
375
+ and
376
+ <span
377
+ class=""
378
+ style="background-color: orange;"
379
+ >
380
+ moon
381
+ </span>
382
+ were bright.
383
+ </div>
384
+ </DocumentFragment>
385
+ `;
386
+
387
+ exports[`Typography component should render with separate excluded index option per word 1`] = `
388
+ <DocumentFragment>
389
+ <div
390
+ class=""
391
+ >
392
+ The sun was bright, the moon was bright, the
393
+ <span
394
+ class="font_bold decoration_underline"
395
+ >
396
+ sun
397
+ </span>
398
+ and
399
+ <span
400
+ class="font_bold decoration_underline"
401
+ >
402
+ moon
403
+ </span>
404
+ again.
405
+ </div>
406
+ </DocumentFragment>
407
+ `;
408
+
409
+ exports[`Typography component should render with separate tagName for each highlighted word 1`] = `
410
+ <DocumentFragment>
411
+ <div
412
+ class=""
413
+ >
414
+ The
415
+ <i
416
+ class=""
417
+ >
418
+ sun
419
+ </i>
420
+ and
421
+ <u
422
+ class=""
423
+ >
424
+ moon
425
+ </u>
426
+ were bright.
427
+ </div>
428
+ </DocumentFragment>
429
+ `;
430
+
431
+ exports[`Typography component should render with separate whole-word option per word 1`] = `
432
+ <DocumentFragment>
433
+ <div
434
+ class=""
435
+ >
436
+ Sunflower is a flower. The
437
+ <span
438
+ class="font_bold decoration_underline"
439
+ >
440
+ Sun
441
+ </span>
442
+ was bright, the
443
+ <span
444
+ class="font_bold decoration_underline"
445
+ >
446
+ moon
447
+ </span>
448
+ light was bright.
449
+ </div>
450
+ </DocumentFragment>
451
+ `;
@@ -0,0 +1,144 @@
1
+ import React from 'react';
2
+ import { compileClassNames } from '@zohodesk/utils';
3
+ import style from "./css/Typography.module.css";
4
+ export function highlight(data) {
5
+ const {
6
+ text,
7
+ highlightData,
8
+ customStyle: globalCustomStyle = {},
9
+ highlightsStyle: globalHighlightsStyle = {},
10
+ isExcludedIndex: hasGlobalExcludedIndex = false,
11
+ isCaseSensitive: hasGlobalCaseSensitive = false,
12
+ isWholeWord: hasGlobalWholeWord = false,
13
+ tagName: globalTagName = 'span',
14
+ render: globalRender
15
+ } = data;
16
+ let patternParts = [];
17
+ let highlightTextList = [];
18
+ const highlightListArray = highlightData.map(item => {
19
+ const {
20
+ highlightText,
21
+ index,
22
+ isExcludedIndex,
23
+ isCaseSensitive,
24
+ highlightsStyle,
25
+ customStyle,
26
+ isWholeWord,
27
+ tagName,
28
+ render
29
+ } = item || {};
30
+ let selectedHighlightText = '';
31
+ let selectedIndex = [];
32
+ let selectedExcludedIndex = hasGlobalExcludedIndex;
33
+ let selectedCaseSensitive = hasGlobalCaseSensitive;
34
+ let selectedHighlightsStyle = globalHighlightsStyle;
35
+ let selectedCustomStyle = globalCustomStyle;
36
+ let selectedWholeWord = hasGlobalWholeWord;
37
+ let selectedTagName = globalTagName;
38
+ let selectedRender = globalRender;
39
+
40
+ if (typeof item === 'string') {
41
+ selectedHighlightText = item;
42
+ } else if (item && typeof highlightText === 'string') {
43
+ selectedHighlightText = highlightText;
44
+ selectedIndex = index !== undefined ? index : [];
45
+ selectedExcludedIndex = isExcludedIndex !== undefined ? isExcludedIndex : hasGlobalExcludedIndex;
46
+ selectedCaseSensitive = isCaseSensitive !== undefined ? isCaseSensitive : hasGlobalCaseSensitive;
47
+ selectedCustomStyle = customStyle !== undefined ? customStyle : globalCustomStyle;
48
+ selectedHighlightsStyle = highlightsStyle !== undefined ? highlightsStyle : globalHighlightsStyle;
49
+ selectedWholeWord = isWholeWord !== undefined ? isWholeWord : hasGlobalWholeWord;
50
+ selectedTagName = tagName !== undefined ? tagName : globalTagName;
51
+ selectedRender = render !== undefined ? render : globalRender;
52
+ }
53
+
54
+ const {
55
+ highlightsClass
56
+ } = getClassFromStyle(selectedHighlightsStyle);
57
+
58
+ if (selectedHighlightText.trim() !== '') {
59
+ const escaped = selectedHighlightText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
60
+ patternParts.push(selectedWholeWord ? `\\b${escaped}\\b` : escaped);
61
+ highlightTextList.push(isCaseSensitive ? selectedHighlightText : selectedHighlightText.toLowerCase());
62
+ }
63
+
64
+ return {
65
+ highlightText: selectedHighlightText,
66
+ index: selectedIndex,
67
+ isExcludedIndex: selectedExcludedIndex,
68
+ isCaseSensitive: selectedCaseSensitive,
69
+ highlightsClass,
70
+ customStyle: selectedCustomStyle,
71
+ tagName: selectedTagName,
72
+ render: selectedRender
73
+ };
74
+ });
75
+ const pattern = patternParts.join('|');
76
+
77
+ if (!pattern) {
78
+ return text;
79
+ }
80
+
81
+ const splittedChild = text.split(new RegExp(`(${pattern})`, 'gi'));
82
+ const indexCount = {};
83
+ return splittedChild.map((part, i) => {
84
+ let Tag = 'span';
85
+ const match = highlightListArray.find(_ref => {
86
+ let {
87
+ highlightText,
88
+ isCaseSensitive
89
+ } = _ref;
90
+ const inputText = isCaseSensitive ? part : part.toLowerCase();
91
+ const target = isCaseSensitive ? highlightText : highlightText.toLowerCase();
92
+ return inputText === target;
93
+ });
94
+
95
+ if (!match) {
96
+ return part;
97
+ }
98
+
99
+ const key = match.highlightText;
100
+ indexCount[key] = (indexCount[key] || 0) + 1;
101
+ const {
102
+ tagName,
103
+ index,
104
+ isExcludedIndex,
105
+ render,
106
+ highlightsClass,
107
+ customStyle
108
+ } = match;
109
+ Tag = tagName;
110
+ const currentIndex = indexCount[key];
111
+ const isArrayIndex = Array.isArray(index);
112
+ const isMatch = isArrayIndex ? (index.length === 0 || index.includes(currentIndex)) !== isExcludedIndex : (index === 0 || index === currentIndex) !== isExcludedIndex;
113
+
114
+ if (!isMatch) {
115
+ return part;
116
+ }
117
+
118
+ return render || /*#__PURE__*/React.createElement(Tag, {
119
+ key: i,
120
+ style: customStyle,
121
+ className: highlightsClass
122
+ }, part);
123
+ });
124
+ }
125
+
126
+ function getClassFromStyle(styleObj) {
127
+ const {
128
+ weight,
129
+ typeFace,
130
+ transform,
131
+ decoration,
132
+ customClass
133
+ } = styleObj;
134
+ const highlightsClass = compileClassNames({
135
+ [style[`font_${weight}`]]: !!weight,
136
+ [style[`fontStyles_${typeFace}`]]: !!typeFace,
137
+ [style[`transform_${transform}`]]: !!transform,
138
+ [style[`decoration_${decoration}`]]: !!decoration,
139
+ [customClass]: !!customClass
140
+ });
141
+ return {
142
+ highlightsClass
143
+ };
144
+ }
@@ -4,5 +4,6 @@ export const defaultProps = {
4
4
  $flag_reset: false,
5
5
  $flag_dotted: false,
6
6
  $tagAttributes_text: {},
7
- $a11yAttributes_text: {}
7
+ $a11yAttributes_text: {},
8
+ highlights: {}
8
9
  };
@@ -1,4 +1,20 @@
1
1
  import PropTypes from 'prop-types';
2
+ const highlightsStyleShape = PropTypes.shape({
3
+ weight: PropTypes.oneOf(['regular', 'light', 'semibold', 'bold']),
4
+ transform: PropTypes.oneOf(['default', 'upper', 'lower', 'capital']),
5
+ decoration: PropTypes.oneOf(['default', 'underline', 'strike', 'overline']),
6
+ typeFace: PropTypes.oneOf(['normal', 'italic']),
7
+ customClass: PropTypes.object
8
+ });
9
+ const commonHighlightProps = {
10
+ customStyle: PropTypes.object,
11
+ isExcludedIndex: PropTypes.bool,
12
+ isCaseSensitive: PropTypes.bool,
13
+ isWholeWord: PropTypes.bool,
14
+ tagName: PropTypes.string,
15
+ render: PropTypes.element,
16
+ highlightsStyle: PropTypes.objectOf(highlightsStyleShape)
17
+ };
2
18
  export const propTypes = {
3
19
  children: PropTypes.node,
4
20
  $ui_className: PropTypes.string,
@@ -23,5 +39,14 @@ export const propTypes = {
23
39
  customId: PropTypes.string,
24
40
  customStyle: PropTypes.object,
25
41
  $a11yAttributes_text: PropTypes.object,
26
- $tagAttributes_text: PropTypes.object
42
+ $tagAttributes_text: PropTypes.object,
43
+ highlights: PropTypes.objectOf(PropTypes.shape({
44
+ text: PropTypes.string,
45
+ highlightData: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
46
+ highlightText: PropTypes.string,
47
+ index: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
48
+ ...commonHighlightProps
49
+ })])),
50
+ ...commonHighlightProps
51
+ }))
27
52
  };
@@ -413,4 +413,5 @@ export function isTextSelected() {
413
413
 
414
414
  return false;
415
415
  }
416
- export const DUMMY_OBJECT = {};
416
+ export const DUMMY_OBJECT = {};
417
+ export const DUMMY_ARRAY = [];
@@ -43,8 +43,10 @@ const getDisabledOptions = props => props.disabledOptions || dummyArray;
43
43
 
44
44
  const getListItemProps = props => props.listItemProps || '';
45
45
 
46
+ const defaultSearchFields = ['value'];
47
+
46
48
  const getSearchFields = props => {
47
- return props.searchFields || ['value'];
49
+ return props.searchFields || defaultSearchFields;
48
50
  }; // const isObjectContainsSearchString = (searchFields = [], searchStr = '', obj) => {
49
51
  // const matchedFields = searchFields.filter(element => {
50
52
  // return getSearchString(obj[element]).indexOf(searchStr) !== -1