@patternfly/react-core 4.191.5 → 4.192.2

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 (92) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/esm/components/DataList/DataListCheck.d.ts +1 -1
  3. package/dist/esm/components/DataList/DataListCheck.d.ts.map +1 -1
  4. package/dist/esm/components/Modal/ModalBoxCloseButton.d.ts +2 -1
  5. package/dist/esm/components/Modal/ModalBoxCloseButton.d.ts.map +1 -1
  6. package/dist/esm/components/Modal/ModalBoxCloseButton.js +2 -2
  7. package/dist/esm/components/Modal/ModalBoxCloseButton.js.map +1 -1
  8. package/dist/esm/components/Modal/ModalContent.js +1 -1
  9. package/dist/esm/components/Modal/ModalContent.js.map +1 -1
  10. package/dist/esm/components/Select/Select.d.ts.map +1 -1
  11. package/dist/esm/components/Select/Select.js +2 -2
  12. package/dist/esm/components/Select/Select.js.map +1 -1
  13. package/dist/esm/components/Select/SelectOption.d.ts +2 -0
  14. package/dist/esm/components/Select/SelectOption.d.ts.map +1 -1
  15. package/dist/esm/components/Select/SelectOption.js +70 -48
  16. package/dist/esm/components/Select/SelectOption.js.map +1 -1
  17. package/dist/esm/components/TextInputGroup/TextInputGroupMain.d.ts +4 -0
  18. package/dist/esm/components/TextInputGroup/TextInputGroupMain.d.ts.map +1 -1
  19. package/dist/esm/components/TextInputGroup/TextInputGroupMain.js +2 -2
  20. package/dist/esm/components/TextInputGroup/TextInputGroupMain.js.map +1 -1
  21. package/dist/esm/components/Truncate/Truncate.d.ts +21 -0
  22. package/dist/esm/components/Truncate/Truncate.d.ts.map +1 -0
  23. package/dist/esm/components/Truncate/Truncate.js +34 -0
  24. package/dist/esm/components/Truncate/Truncate.js.map +1 -0
  25. package/dist/esm/components/Truncate/index.d.ts +2 -0
  26. package/dist/esm/components/Truncate/index.d.ts.map +1 -0
  27. package/dist/esm/components/Truncate/index.js +2 -0
  28. package/dist/esm/components/Truncate/index.js.map +1 -0
  29. package/dist/esm/components/index.d.ts +1 -0
  30. package/dist/esm/components/index.d.ts.map +1 -1
  31. package/dist/esm/components/index.js +1 -0
  32. package/dist/esm/components/index.js.map +1 -1
  33. package/dist/js/components/DataList/DataListCheck.d.ts +1 -1
  34. package/dist/js/components/DataList/DataListCheck.d.ts.map +1 -1
  35. package/dist/js/components/Modal/ModalBoxCloseButton.d.ts +2 -1
  36. package/dist/js/components/Modal/ModalBoxCloseButton.d.ts.map +1 -1
  37. package/dist/js/components/Modal/ModalBoxCloseButton.js +2 -2
  38. package/dist/js/components/Modal/ModalBoxCloseButton.js.map +1 -1
  39. package/dist/js/components/Modal/ModalContent.js +1 -1
  40. package/dist/js/components/Modal/ModalContent.js.map +1 -1
  41. package/dist/js/components/Select/Select.d.ts.map +1 -1
  42. package/dist/js/components/Select/Select.js +2 -2
  43. package/dist/js/components/Select/Select.js.map +1 -1
  44. package/dist/js/components/Select/SelectOption.d.ts +2 -0
  45. package/dist/js/components/Select/SelectOption.d.ts.map +1 -1
  46. package/dist/js/components/Select/SelectOption.js +70 -48
  47. package/dist/js/components/Select/SelectOption.js.map +1 -1
  48. package/dist/js/components/TextInputGroup/TextInputGroupMain.d.ts +4 -0
  49. package/dist/js/components/TextInputGroup/TextInputGroupMain.d.ts.map +1 -1
  50. package/dist/js/components/TextInputGroup/TextInputGroupMain.js +2 -2
  51. package/dist/js/components/TextInputGroup/TextInputGroupMain.js.map +1 -1
  52. package/dist/js/components/Truncate/Truncate.d.ts +21 -0
  53. package/dist/js/components/Truncate/Truncate.d.ts.map +1 -0
  54. package/dist/js/components/Truncate/Truncate.js +38 -0
  55. package/dist/js/components/Truncate/Truncate.js.map +1 -0
  56. package/dist/js/components/Truncate/index.d.ts +2 -0
  57. package/dist/js/components/Truncate/index.d.ts.map +1 -0
  58. package/dist/js/components/Truncate/index.js +5 -0
  59. package/dist/js/components/Truncate/index.js.map +1 -0
  60. package/dist/js/components/index.d.ts +1 -0
  61. package/dist/js/components/index.d.ts.map +1 -1
  62. package/dist/js/components/index.js +1 -0
  63. package/dist/js/components/index.js.map +1 -1
  64. package/dist/umd/react-core.css +59 -6
  65. package/dist/umd/react-core.js +1003 -941
  66. package/dist/umd/react-core.min.css +59 -6
  67. package/dist/umd/react-core.min.js +2 -2
  68. package/package.json +6 -6
  69. package/src/components/BackToTop/examples/BackToTop.md +1 -1
  70. package/src/components/DataList/DataListCheck.tsx +1 -1
  71. package/src/components/Modal/ModalBoxCloseButton.tsx +11 -2
  72. package/src/components/Modal/ModalContent.tsx +1 -1
  73. package/src/components/Modal/examples/Modal.md +3 -200
  74. package/src/components/Modal/examples/ModalWithForm.tsx +209 -0
  75. package/src/components/Select/Select.tsx +2 -1
  76. package/src/components/Select/SelectOption.tsx +188 -133
  77. package/src/components/TextInputGroup/TextInputGroupMain.tsx +7 -1
  78. package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroup.test.tsx.snap +6 -0
  79. package/src/components/TextInputGroup/examples/TextInputGroupFilters.tsx +12 -7
  80. package/src/components/TextInputGroup/examples/TextInputGroupUtilitiesAndIcon.tsx +12 -7
  81. package/src/components/Truncate/Truncate.tsx +63 -0
  82. package/src/components/Truncate/__tests__/Truncate.test.tsx +18 -0
  83. package/src/components/Truncate/__tests__/__snapshots__/Truncate.test.tsx.snap +58 -0
  84. package/src/components/Truncate/examples/Truncate.md +59 -0
  85. package/src/components/Truncate/examples/TruncateExamples.css +9 -0
  86. package/src/components/Truncate/index.ts +1 -0
  87. package/src/components/index.ts +1 -0
  88. package/src/demos/Tabs/NestedTabsDemo.js +3 -3
  89. package/src/demos/Tabs.md +4 -0
  90. package/src/demos/examples/Tabs/GrayTabs.tsx +158 -0
  91. package/src/demos/examples/TextInputGroup/AttributeValueFiltering.tsx +13 -8
  92. package/src/demos/examples/TextInputGroup/AutoCompleteSearch.tsx +29 -15
@@ -69,6 +69,8 @@ export interface SelectOptionProps extends Omit<React.HTMLProps<HTMLElement>, 't
69
69
  setViewMoreNextIndex?: () => void;
70
70
  /** @hide Flag indicating this is the last option when there is a footer */
71
71
  isLastOptionBeforeFooter?: (index: number) => boolean;
72
+ /** @hide Flag indicating that the the option loading variant is in a grouped select */
73
+ isGrouped?: boolean;
72
74
  }
73
75
 
74
76
  export class SelectOption extends React.Component<SelectOptionProps> {
@@ -182,6 +184,7 @@ export class SelectOption extends React.Component<SelectOptionProps> {
182
184
  setViewMoreNextIndex,
183
185
  // eslint-disable-next-line no-console
184
186
  isLastOptionBeforeFooter,
187
+ isGrouped = false,
185
188
  ...props
186
189
  } = this.props;
187
190
  /* eslint-enable @typescript-eslint/no-unused-vars */
@@ -228,166 +231,218 @@ export class SelectOption extends React.Component<SelectOptionProps> {
228
231
  onClick(event);
229
232
  };
230
233
 
231
- return (
232
- <SelectConsumer>
233
- {({ onSelect, onClose, variant, inputIdPrefix, onFavorite }) => (
234
- <React.Fragment>
235
- {variant !== SelectVariant.checkbox && (
236
- <li
237
- id={generatedId}
238
- role="presentation"
239
- className={css(
240
- isLoading && styles.selectListItem,
241
- !isLoad && !isLoading && styles.selectMenuWrapper,
242
- isFavorite && styles.modifiers.favorite,
243
- isFocused && styles.modifiers.focus,
244
- isLoading && styles.modifiers.loading
245
- )}
246
- ref={this.liRef}
247
- >
248
- {isLoading && children}
249
- {!isLoading && (
250
- <>
251
- <Component
252
- {...props}
253
- className={css(
254
- styles.selectMenuItem,
255
- isLoad && styles.modifiers.load,
256
- isSelected && styles.modifiers.selected,
257
- isDisabled && styles.modifiers.disabled,
258
- description && styles.modifiers.description,
259
- isFavorite !== null && styles.modifiers.link,
260
- className
261
- )}
262
- onClick={(event: any) => {
263
- if (isLoad) {
264
- onViewMoreClick(event);
265
- event.stopPropagation();
266
- } else if (!isDisabled && !isLoading) {
267
- onClick(event);
268
- onSelect(event, value, isPlaceholder);
269
- onClose();
270
- }
271
- }}
272
- role="option"
273
- aria-selected={isSelected || null}
274
- ref={this.ref}
275
- onKeyDown={(event: React.KeyboardEvent) => {
276
- this.onKeyDown(event, 0);
277
- }}
278
- type="button"
279
- >
280
- {description && (
281
- <React.Fragment>
282
- <span className={css(styles.selectMenuItemMain)}>
283
- {itemDisplay}
284
- {isSelected && (
285
- <span className={css(styles.selectMenuItemIcon)}>
286
- <CheckIcon aria-hidden />
287
- </span>
288
- )}
289
- </span>
290
- <span className={css(styles.selectMenuItemDescription)}>{description}</span>
291
- </React.Fragment>
292
- )}
293
- {!description && (
294
- <React.Fragment>
295
- {itemDisplay}
296
- {isSelected && (
297
- <span className={css(styles.selectMenuItemIcon)}>
298
- <CheckIcon aria-hidden />
299
- </span>
300
- )}
301
- </React.Fragment>
302
- )}
303
- </Component>
304
- {isFavorite !== null && id && favoriteButton(onFavorite)}
305
- </>
306
- )}
307
- </li>
234
+ const renderOption = (
235
+ onSelect: (
236
+ event: React.MouseEvent<any, MouseEvent> | React.ChangeEvent<HTMLInputElement>,
237
+ value: string | SelectOptionObject,
238
+ isPlaceholder?: boolean
239
+ ) => void,
240
+ onClose: () => void,
241
+ variant: string,
242
+ inputIdPrefix: string,
243
+ onFavorite: (itemId: string, isFavorite: boolean) => void
244
+ ) => {
245
+ if (variant !== SelectVariant.checkbox && isLoading && isGrouped) {
246
+ return (
247
+ <div
248
+ role="presentation"
249
+ className={css(styles.selectListItem, isLoading && styles.modifiers.loading, className)}
250
+ >
251
+ {children}
252
+ </div>
253
+ );
254
+ } else if (variant !== SelectVariant.checkbox && isLoad && isGrouped) {
255
+ return (
256
+ <div>
257
+ <button
258
+ {...props}
259
+ role="presentation"
260
+ className={css(styles.selectMenuItem, styles.modifiers.load, className)}
261
+ onClick={(event: any) => {
262
+ onViewMoreClick(event);
263
+ event.stopPropagation();
264
+ }}
265
+ ref={this.ref}
266
+ type="button"
267
+ >
268
+ {children || value.toString()}
269
+ </button>
270
+ </div>
271
+ );
272
+ } else if (variant !== SelectVariant.checkbox) {
273
+ return (
274
+ <li
275
+ id={generatedId}
276
+ role="presentation"
277
+ className={css(
278
+ isLoading && styles.selectListItem,
279
+ !isLoad && !isLoading && styles.selectMenuWrapper,
280
+ isFavorite && styles.modifiers.favorite,
281
+ isFocused && styles.modifiers.focus,
282
+ isLoading && styles.modifiers.loading
308
283
  )}
309
- {variant === SelectVariant.checkbox && isLoad && (
284
+ ref={this.liRef}
285
+ >
286
+ {isLoading && children}
287
+ {isLoad && !isGrouped && (
310
288
  <button
311
- className={css(
312
- styles.selectMenuItem,
313
- styles.modifiers.load,
314
- isFocused && styles.modifiers.focus,
315
- className
316
- )}
317
- onKeyDown={(event: React.KeyboardEvent) => {
318
- this.onKeyDown(event, 0, undefined, true);
319
- }}
289
+ {...props}
290
+ className={css(styles.selectMenuItem, styles.modifiers.load, className)}
320
291
  onClick={(event: any) => {
321
292
  onViewMoreClick(event);
322
293
  event.stopPropagation();
323
294
  }}
324
295
  ref={this.ref}
296
+ type="button"
325
297
  >
326
- {children || (value && value.toString && value.toString())}
298
+ {itemDisplay}
327
299
  </button>
328
300
  )}
329
- {variant === SelectVariant.checkbox && isLoading && (
330
- <div className={css(styles.selectListItem, isLoading && styles.modifiers.loading, className)}>
331
- {children}
332
- </div>
333
- )}
334
- {variant === SelectVariant.checkbox && !isNoResultsOption && !isLoading && !isLoad && (
335
- <label
336
- {...props}
337
- className={css(
338
- checkStyles.check,
339
- styles.selectMenuItem,
340
- isDisabled && styles.modifiers.disabled,
341
- description && styles.modifiers.description,
342
- className
343
- )}
344
- onKeyDown={(event: React.KeyboardEvent) => {
345
- this.onKeyDown(event, 0, undefined, true);
346
- }}
347
- >
348
- <input
349
- id={inputId || `${inputIdPrefix}-${value.toString()}`}
350
- className={css(checkStyles.checkInput)}
351
- type="checkbox"
352
- onChange={event => {
353
- if (!isDisabled) {
354
- onClick(event);
355
- onSelect(event, value);
356
- }
357
- }}
358
- ref={this.ref}
359
- checked={isChecked || false}
360
- disabled={isDisabled}
361
- />
362
- <span className={css(checkStyles.checkLabel, isDisabled && styles.modifiers.disabled)}>
363
- {itemDisplay}
364
- </span>
365
- {description && <div className={css(checkStyles.checkDescription)}>{description}</div>}
366
- </label>
367
- )}
368
- {variant === SelectVariant.checkbox && isNoResultsOption && !isLoading && !isLoad && (
369
- <div>
301
+ {!isLoading && !isLoad && (
302
+ <>
370
303
  <Component
371
304
  {...props}
372
305
  className={css(
373
306
  styles.selectMenuItem,
307
+ isLoad && styles.modifiers.load,
374
308
  isSelected && styles.modifiers.selected,
375
309
  isDisabled && styles.modifiers.disabled,
310
+ description && styles.modifiers.description,
311
+ isFavorite !== null && styles.modifiers.link,
376
312
  className
377
313
  )}
314
+ onClick={(event: any) => {
315
+ if (!isDisabled) {
316
+ onClick(event);
317
+ onSelect(event, value, isPlaceholder);
318
+ onClose();
319
+ }
320
+ }}
378
321
  role="option"
379
322
  aria-selected={isSelected || null}
380
323
  ref={this.ref}
381
324
  onKeyDown={(event: React.KeyboardEvent) => {
382
- this.onKeyDown(event, 0, undefined, true);
325
+ this.onKeyDown(event, 0);
383
326
  }}
384
327
  type="button"
385
328
  >
386
- {itemDisplay}
329
+ {description && (
330
+ <React.Fragment>
331
+ <span className={css(styles.selectMenuItemMain)}>
332
+ {itemDisplay}
333
+ {isSelected && (
334
+ <span className={css(styles.selectMenuItemIcon)}>
335
+ <CheckIcon aria-hidden />
336
+ </span>
337
+ )}
338
+ </span>
339
+ <span className={css(styles.selectMenuItemDescription)}>{description}</span>
340
+ </React.Fragment>
341
+ )}
342
+ {!description && (
343
+ <React.Fragment>
344
+ {itemDisplay}
345
+ {isSelected && (
346
+ <span className={css(styles.selectMenuItemIcon)}>
347
+ <CheckIcon aria-hidden />
348
+ </span>
349
+ )}
350
+ </React.Fragment>
351
+ )}
387
352
  </Component>
388
- </div>
353
+ {isFavorite !== null && id && favoriteButton(onFavorite)}
354
+ </>
355
+ )}
356
+ </li>
357
+ );
358
+ } else if (variant === SelectVariant.checkbox && isLoad) {
359
+ return (
360
+ <button
361
+ className={css(
362
+ styles.selectMenuItem,
363
+ styles.modifiers.load,
364
+ isFocused && styles.modifiers.focus,
365
+ className
366
+ )}
367
+ onKeyDown={(event: React.KeyboardEvent) => {
368
+ this.onKeyDown(event, 0, undefined, true);
369
+ }}
370
+ onClick={(event: any) => {
371
+ onViewMoreClick(event);
372
+ event.stopPropagation();
373
+ }}
374
+ ref={this.ref}
375
+ >
376
+ {children || (value && value.toString && value.toString())}
377
+ </button>
378
+ );
379
+ } else if (variant === SelectVariant.checkbox && isLoading) {
380
+ return (
381
+ <div className={css(styles.selectListItem, isLoading && styles.modifiers.loading, className)}>{children}</div>
382
+ );
383
+ } else if (variant === SelectVariant.checkbox && !isNoResultsOption && !isLoading && !isLoad) {
384
+ return (
385
+ <label
386
+ {...props}
387
+ className={css(
388
+ checkStyles.check,
389
+ styles.selectMenuItem,
390
+ isDisabled && styles.modifiers.disabled,
391
+ description && styles.modifiers.description,
392
+ className
389
393
  )}
390
- </React.Fragment>
394
+ onKeyDown={(event: React.KeyboardEvent) => {
395
+ this.onKeyDown(event, 0, undefined, true);
396
+ }}
397
+ >
398
+ <input
399
+ id={inputId || `${inputIdPrefix}-${value.toString()}`}
400
+ className={css(checkStyles.checkInput)}
401
+ type="checkbox"
402
+ onChange={event => {
403
+ if (!isDisabled) {
404
+ onClick(event);
405
+ onSelect(event, value);
406
+ }
407
+ }}
408
+ ref={this.ref}
409
+ checked={isChecked || false}
410
+ disabled={isDisabled}
411
+ />
412
+ <span className={css(checkStyles.checkLabel, isDisabled && styles.modifiers.disabled)}>{itemDisplay}</span>
413
+ {description && <div className={css(checkStyles.checkDescription)}>{description}</div>}
414
+ </label>
415
+ );
416
+ } else if (variant === SelectVariant.checkbox && isNoResultsOption && !isLoading && !isLoad) {
417
+ return (
418
+ <div>
419
+ <Component
420
+ {...props}
421
+ className={css(
422
+ styles.selectMenuItem,
423
+ isSelected && styles.modifiers.selected,
424
+ isDisabled && styles.modifiers.disabled,
425
+ className
426
+ )}
427
+ role="option"
428
+ aria-selected={isSelected || null}
429
+ ref={this.ref}
430
+ onKeyDown={(event: React.KeyboardEvent) => {
431
+ this.onKeyDown(event, 0, undefined, true);
432
+ }}
433
+ type="button"
434
+ >
435
+ {itemDisplay}
436
+ </Component>
437
+ </div>
438
+ );
439
+ }
440
+ };
441
+
442
+ return (
443
+ <SelectConsumer>
444
+ {({ onSelect, onClose, variant, inputIdPrefix, onFavorite }) => (
445
+ <React.Fragment>{renderOption(onSelect, onClose, variant, inputIdPrefix, onFavorite)}</React.Fragment>
391
446
  )}
392
447
  </SelectConsumer>
393
448
  );
@@ -31,6 +31,10 @@ export interface TextInputGroupMainProps extends Omit<React.HTMLProps<HTMLDivEle
31
31
  onBlur?: (event?: any) => void;
32
32
  /** Accessibility label for the input */
33
33
  'aria-label'?: string;
34
+ /** Value for the input */
35
+ value?: string | number;
36
+ /** Placeholder value for the input */
37
+ placeholder?: string;
34
38
  }
35
39
 
36
40
  export const TextInputGroupMain: React.FunctionComponent<TextInputGroupMainProps> = ({
@@ -43,6 +47,7 @@ export const TextInputGroupMain: React.FunctionComponent<TextInputGroupMainProps
43
47
  onBlur,
44
48
  'aria-label': ariaLabel = 'Type to filter',
45
49
  value: inputValue,
50
+ placeholder: inputPlaceHolder,
46
51
  ...props
47
52
  }: TextInputGroupMainProps) => {
48
53
  const { isDisabled } = React.useContext(TextInputGroupContext);
@@ -64,7 +69,8 @@ export const TextInputGroupMain: React.FunctionComponent<TextInputGroupMainProps
64
69
  onChange={handleChange}
65
70
  onFocus={onFocus}
66
71
  onBlur={onBlur}
67
- value={inputValue}
72
+ value={inputValue || ''}
73
+ placeholder={inputPlaceHolder}
68
74
  />
69
75
  </span>
70
76
  </div>
@@ -22,6 +22,7 @@ exports[`TextInputGroup gets custom class and id 1`] = `
22
22
  className="pf-c-text-input-group__text-input"
23
23
  onChange={[Function]}
24
24
  type="text"
25
+ value=""
25
26
  />
26
27
  </span>
27
28
  </div>
@@ -53,6 +54,7 @@ exports[`TextInputGroup renders content 1`] = `
53
54
  className="pf-c-text-input-group__text-input"
54
55
  onChange={[Function]}
55
56
  type="text"
57
+ value=""
56
58
  />
57
59
  </span>
58
60
  </div>
@@ -87,6 +89,7 @@ exports[`TextInputGroup renders with the proper stying when disabled 1`] = `
87
89
  disabled={true}
88
90
  onChange={[Function]}
89
91
  type="text"
92
+ value=""
90
93
  />
91
94
  </span>
92
95
  </div>
@@ -115,6 +118,7 @@ exports[`TextInputGroupMain renders content 1`] = `
115
118
  disabled={false}
116
119
  onChange={[Function]}
117
120
  type="text"
121
+ value=""
118
122
  />
119
123
  </span>
120
124
  </div>
@@ -172,6 +176,7 @@ exports[`TextInputGroupMain renders given input icon props 1`] = `
172
176
  disabled={false}
173
177
  onChange={[Function]}
174
178
  type="text"
179
+ value=""
175
180
  />
176
181
  </span>
177
182
  </div>
@@ -195,6 +200,7 @@ exports[`TextInputGroupMain renders the input with custom aria label when given
195
200
  disabled={false}
196
201
  onChange={[Function]}
197
202
  type="text"
203
+ value=""
198
204
  />
199
205
  </span>
200
206
  </div>
@@ -40,6 +40,9 @@ export const TextInputGroupFilters: React.FunctionComponent = () => {
40
40
  /** show the input/chip clearing button only when either the text input or chip group are not empty */
41
41
  const showClearButton = !!inputValue || !!currentChips.length;
42
42
 
43
+ /** render the utilities component only when a component it contains is being rendered */
44
+ const showUtilities = showClearButton;
45
+
43
46
  /** callback for clearing all selected chips and the text input */
44
47
  const clearChipsAndInput = () => {
45
48
  setCurrentChips([]);
@@ -57,13 +60,15 @@ export const TextInputGroupFilters: React.FunctionComponent = () => {
57
60
  ))}
58
61
  </ChipGroup>
59
62
  </TextInputGroupMain>
60
- <TextInputGroupUtilities>
61
- {showClearButton && (
62
- <Button variant="plain" onClick={clearChipsAndInput} aria-label="Clear button and input">
63
- <TimesIcon />
64
- </Button>
65
- )}
66
- </TextInputGroupUtilities>
63
+ {showUtilities && (
64
+ <TextInputGroupUtilities>
65
+ {showClearButton && (
66
+ <Button variant="plain" onClick={clearChipsAndInput} aria-label="Clear button and input">
67
+ <TimesIcon />
68
+ </Button>
69
+ )}
70
+ </TextInputGroupUtilities>
71
+ )}
67
72
  </TextInputGroup>
68
73
  );
69
74
  };
@@ -14,6 +14,9 @@ export const TextInputGroupUtilitiesAndIcon: React.FunctionComponent = () => {
14
14
  /** show the input clearing button only when the input is not empty */
15
15
  const showClearButton = !!inputValue;
16
16
 
17
+ /** render the utilities component only when a component it contains is being rendered */
18
+ const showUtilities = showClearButton;
19
+
17
20
  /** callback for clearing the text input */
18
21
  const clearInput = () => {
19
22
  setInputValue('');
@@ -22,13 +25,15 @@ export const TextInputGroupUtilitiesAndIcon: React.FunctionComponent = () => {
22
25
  return (
23
26
  <TextInputGroup>
24
27
  <TextInputGroupMain icon={<SearchIcon />} value={inputValue} onChange={handleInputChange} />
25
- <TextInputGroupUtilities>
26
- {showClearButton && (
27
- <Button variant="plain" onClick={clearInput} aria-label="Clear button and input">
28
- <TimesIcon />
29
- </Button>
30
- )}
31
- </TextInputGroupUtilities>
28
+ {showUtilities && (
29
+ <TextInputGroupUtilities>
30
+ {showClearButton && (
31
+ <Button variant="plain" onClick={clearInput} aria-label="Clear button and input">
32
+ <TimesIcon />
33
+ </Button>
34
+ )}
35
+ </TextInputGroupUtilities>
36
+ )}
32
37
  </TextInputGroup>
33
38
  );
34
39
  };
@@ -0,0 +1,63 @@
1
+ import * as React from 'react';
2
+ import styles from '@patternfly/react-styles/css/components/Truncate/truncate';
3
+ import { css } from '@patternfly/react-styles';
4
+ import { Tooltip } from '../Tooltip';
5
+
6
+ export enum TruncatePosition {
7
+ start = 'start',
8
+ end = 'end',
9
+ middle = 'middle'
10
+ }
11
+
12
+ const truncateStyles = {
13
+ start: styles.truncateEnd,
14
+ end: styles.truncateStart
15
+ };
16
+
17
+ const minWidthCharacters: number = 12;
18
+
19
+ interface TruncateProps extends React.HTMLProps<HTMLSpanElement> {
20
+ /** Class to add to outer span */
21
+ className?: string;
22
+ /** Text to truncate */
23
+ content: string;
24
+ /** The number of characters displayed in the second half of the truncation */
25
+ trailingNumChars?: number;
26
+ /** Where the text will be truncated */
27
+ position?: 'start' | 'middle' | 'end';
28
+ /** Tooltip position */
29
+ tooltipPosition?: 'auto' | 'top' | 'bottom' | 'left' | 'right';
30
+ }
31
+
32
+ const sliceContent = (str: string, slice: number) => [str.slice(0, str.length - slice), str.slice(-slice)];
33
+
34
+ export const Truncate: React.FunctionComponent<TruncateProps> = ({
35
+ className,
36
+ position = 'end',
37
+ tooltipPosition = 'top',
38
+ trailingNumChars = 7,
39
+ content,
40
+ ...props
41
+ }: TruncateProps) => (
42
+ <Tooltip position={tooltipPosition} content={content}>
43
+ <span className={css(styles.truncate, className)} {...props}>
44
+ {(position === TruncatePosition.end || position === TruncatePosition.start) && (
45
+ <span className={truncateStyles[position]}>
46
+ {content}
47
+ {position === TruncatePosition.start && <React.Fragment>&lrm;</React.Fragment>}
48
+ </span>
49
+ )}
50
+ {position === TruncatePosition.middle &&
51
+ content.slice(0, content.length - trailingNumChars).length > minWidthCharacters && (
52
+ <React.Fragment>
53
+ <span className={styles.truncateStart}>{sliceContent(content, trailingNumChars)[0]}</span>
54
+ <span className={styles.truncateEnd}>{sliceContent(content, trailingNumChars)[1]}</span>
55
+ </React.Fragment>
56
+ )}
57
+ {position === TruncatePosition.middle &&
58
+ content.slice(0, content.length - trailingNumChars).length <= minWidthCharacters &&
59
+ content}
60
+ </span>
61
+ </Tooltip>
62
+ );
63
+ Truncate.displayName = 'Truncate';
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import { Truncate } from '../Truncate';
4
+
5
+ test('renders default truncation', () => {
6
+ const view = shallow(<Truncate content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'} />);
7
+ expect(view).toMatchSnapshot();
8
+ });
9
+
10
+ test('renders start truncation', () => {
11
+ const view = shallow(<Truncate content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'} position={'start'} />);
12
+ expect(view).toMatchSnapshot();
13
+ });
14
+
15
+ test('renders middle truncation', () => {
16
+ const view = shallow(<Truncate content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'} position={'middle'} />);
17
+ expect(view).toMatchSnapshot();
18
+ });
@@ -0,0 +1,58 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`renders default truncation 1`] = `
4
+ <Tooltip
5
+ content="Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan."
6
+ position="top"
7
+ >
8
+ <span
9
+ className="pf-c-truncate"
10
+ >
11
+ <span
12
+ className="pf-c-truncate__start"
13
+ >
14
+ Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.
15
+ </span>
16
+ </span>
17
+ </Tooltip>
18
+ `;
19
+
20
+ exports[`renders middle truncation 1`] = `
21
+ <Tooltip
22
+ content="Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan."
23
+ position="top"
24
+ >
25
+ <span
26
+ className="pf-c-truncate"
27
+ >
28
+ <span
29
+ className="pf-c-truncate__start"
30
+ >
31
+ Vestibulum interdum risus et enim faucibus, sit amet molestie est ac
32
+ </span>
33
+ <span
34
+ className="pf-c-truncate__end"
35
+ >
36
+ cumsan.
37
+ </span>
38
+ </span>
39
+ </Tooltip>
40
+ `;
41
+
42
+ exports[`renders start truncation 1`] = `
43
+ <Tooltip
44
+ content="Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan."
45
+ position="top"
46
+ >
47
+ <span
48
+ className="pf-c-truncate"
49
+ >
50
+ <span
51
+ className="pf-c-truncate__end"
52
+ >
53
+ Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.
54
+ ‎
55
+ </span>
56
+ </span>
57
+ </Tooltip>
58
+ `;