@patternfly/react-core 4.191.3 → 4.192.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/CHANGELOG.md +38 -0
- package/dist/esm/components/DataList/DataListCheck.d.ts +1 -1
- package/dist/esm/components/DataList/DataListCheck.d.ts.map +1 -1
- package/dist/esm/components/Modal/ModalBoxCloseButton.d.ts +2 -1
- package/dist/esm/components/Modal/ModalBoxCloseButton.d.ts.map +1 -1
- package/dist/esm/components/Modal/ModalBoxCloseButton.js +2 -2
- package/dist/esm/components/Modal/ModalBoxCloseButton.js.map +1 -1
- package/dist/esm/components/Modal/ModalContent.js +1 -1
- package/dist/esm/components/Modal/ModalContent.js.map +1 -1
- package/dist/esm/components/TextInputGroup/TextInputGroupMain.d.ts +4 -0
- package/dist/esm/components/TextInputGroup/TextInputGroupMain.d.ts.map +1 -1
- package/dist/esm/components/TextInputGroup/TextInputGroupMain.js +2 -2
- package/dist/esm/components/TextInputGroup/TextInputGroupMain.js.map +1 -1
- package/dist/esm/components/Truncate/Truncate.d.ts +21 -0
- package/dist/esm/components/Truncate/Truncate.d.ts.map +1 -0
- package/dist/esm/components/Truncate/Truncate.js +34 -0
- package/dist/esm/components/Truncate/Truncate.js.map +1 -0
- package/dist/esm/components/Truncate/index.d.ts +2 -0
- package/dist/esm/components/Truncate/index.d.ts.map +1 -0
- package/dist/esm/components/Truncate/index.js +2 -0
- package/dist/esm/components/Truncate/index.js.map +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/js/components/DataList/DataListCheck.d.ts +1 -1
- package/dist/js/components/DataList/DataListCheck.d.ts.map +1 -1
- package/dist/js/components/Modal/ModalBoxCloseButton.d.ts +2 -1
- package/dist/js/components/Modal/ModalBoxCloseButton.d.ts.map +1 -1
- package/dist/js/components/Modal/ModalBoxCloseButton.js +2 -2
- package/dist/js/components/Modal/ModalBoxCloseButton.js.map +1 -1
- package/dist/js/components/Modal/ModalContent.js +1 -1
- package/dist/js/components/Modal/ModalContent.js.map +1 -1
- package/dist/js/components/TextInputGroup/TextInputGroupMain.d.ts +4 -0
- package/dist/js/components/TextInputGroup/TextInputGroupMain.d.ts.map +1 -1
- package/dist/js/components/TextInputGroup/TextInputGroupMain.js +2 -2
- package/dist/js/components/TextInputGroup/TextInputGroupMain.js.map +1 -1
- package/dist/js/components/Truncate/Truncate.d.ts +21 -0
- package/dist/js/components/Truncate/Truncate.d.ts.map +1 -0
- package/dist/js/components/Truncate/Truncate.js +38 -0
- package/dist/js/components/Truncate/Truncate.js.map +1 -0
- package/dist/js/components/Truncate/index.d.ts +2 -0
- package/dist/js/components/Truncate/index.d.ts.map +1 -0
- package/dist/js/components/Truncate/index.js +5 -0
- package/dist/js/components/Truncate/index.js.map +1 -0
- package/dist/js/components/index.d.ts +1 -0
- package/dist/js/components/index.d.ts.map +1 -1
- package/dist/js/components/index.js +1 -0
- package/dist/js/components/index.js.map +1 -1
- package/dist/umd/react-core.css +119 -66
- package/dist/umd/react-core.js +943 -903
- package/dist/umd/react-core.min.css +59 -6
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +6 -6
- package/src/components/BackToTop/examples/BackToTop.md +1 -1
- package/src/components/Button/examples/Button.md +13 -298
- package/src/components/Button/examples/ButtonAriaDisabled.tsx +43 -0
- package/src/components/Button/examples/ButtonAriaDisabledLinkTooltip.tsx +10 -0
- package/src/components/Button/examples/ButtonAriaDisabledTooltip.tsx +10 -0
- package/src/components/Button/examples/ButtonBlock.tsx +4 -0
- package/src/components/Button/examples/ButtonCallToAction.tsx +20 -0
- package/src/components/Button/examples/ButtonDisabled.tsx +43 -0
- package/src/components/Button/examples/ButtonInlineSpanLink.tsx +36 -0
- package/src/components/Button/examples/ButtonLinks.tsx +19 -0
- package/src/components/Button/examples/ButtonProgress.tsx +29 -0
- package/src/components/Button/examples/ButtonRouterLink.tsx +9 -0
- package/src/components/Button/examples/ButtonSmall.tsx +22 -0
- package/src/components/Button/examples/ButtonTypes.tsx +10 -0
- package/src/components/Button/examples/ButtonVariations.tsx +47 -0
- package/src/components/DataList/DataListCheck.tsx +1 -1
- package/src/components/Modal/ModalBoxCloseButton.tsx +11 -2
- package/src/components/Modal/ModalContent.tsx +1 -1
- package/src/components/Modal/examples/Modal.md +3 -200
- package/src/components/Modal/examples/ModalWithForm.tsx +209 -0
- package/src/components/TextInputGroup/TextInputGroupMain.tsx +7 -1
- package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroup.test.tsx.snap +6 -0
- package/src/components/TextInputGroup/examples/TextInputGroupFilters.tsx +12 -7
- package/src/components/TextInputGroup/examples/TextInputGroupUtilitiesAndIcon.tsx +12 -7
- package/src/components/Truncate/Truncate.tsx +63 -0
- package/src/components/Truncate/__tests__/Truncate.test.tsx +18 -0
- package/src/components/Truncate/__tests__/__snapshots__/Truncate.test.tsx.snap +58 -0
- package/src/components/Truncate/examples/Truncate.md +59 -0
- package/src/components/Truncate/examples/TruncateExamples.css +9 -0
- package/src/components/Truncate/index.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/demos/examples/TextInputGroup/AttributeValueFiltering.tsx +13 -8
- package/src/demos/examples/TextInputGroup/AutoCompleteSearch.tsx +29 -15
|
@@ -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>‎</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
|
+
`;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Truncate
|
|
3
|
+
section: components
|
|
4
|
+
propComponents: [Truncate]
|
|
5
|
+
beta: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
import './TruncateExamples.css';
|
|
9
|
+
|
|
10
|
+
## Examples
|
|
11
|
+
|
|
12
|
+
### Default
|
|
13
|
+
```js
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { Truncate } from '@patternfly/react-core';
|
|
16
|
+
<div className="pf-c-truncate--example">
|
|
17
|
+
<Truncate
|
|
18
|
+
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
|
|
19
|
+
/>
|
|
20
|
+
</div>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Middle
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { Truncate } from '@patternfly/react-core';
|
|
28
|
+
<div className="pf-c-truncate--example">
|
|
29
|
+
<Truncate
|
|
30
|
+
content={'redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip'}
|
|
31
|
+
trailingNumChars={10}
|
|
32
|
+
position={'middle'}
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Start
|
|
38
|
+
```js
|
|
39
|
+
import React from 'react';
|
|
40
|
+
import { Truncate } from '@patternfly/react-core';
|
|
41
|
+
<div className="pf-c-truncate--example">
|
|
42
|
+
<Truncate
|
|
43
|
+
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
|
|
44
|
+
position={'start'}
|
|
45
|
+
/>
|
|
46
|
+
</div>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Default with tooltip at the bottom
|
|
50
|
+
```js
|
|
51
|
+
import React from 'react';
|
|
52
|
+
import { Truncate } from '@patternfly/react-core';
|
|
53
|
+
<div className="pf-c-truncate--example">
|
|
54
|
+
<Truncate
|
|
55
|
+
content={'Vestibulum interdum risus et enim faucibus, sit amet molestie est accumsan.'}
|
|
56
|
+
tooltipPosition={'bottom'}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Truncate';
|
package/src/components/index.ts
CHANGED
|
@@ -205,12 +205,15 @@ export const AttributeValueFiltering: React.FunctionComponent = () => {
|
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
207
|
|
|
208
|
-
/**
|
|
208
|
+
/** show the search icon only when there are no chips to prevent the chips from being displayed behind the icon */
|
|
209
209
|
const showSearchIcon = !currentChips.length;
|
|
210
210
|
|
|
211
211
|
/** only show the clear button when there is something that can be cleared */
|
|
212
212
|
const showClearButton = !!inputValue || !!currentChips.length;
|
|
213
213
|
|
|
214
|
+
/** render the utilities component only when a component it contains is being rendered */
|
|
215
|
+
const showUtilities = showClearButton;
|
|
216
|
+
|
|
214
217
|
const inputGroup = (
|
|
215
218
|
<div ref={textInputGroupRef}>
|
|
216
219
|
<TextInputGroup>
|
|
@@ -229,13 +232,15 @@ export const AttributeValueFiltering: React.FunctionComponent = () => {
|
|
|
229
232
|
))}
|
|
230
233
|
</ChipGroup>
|
|
231
234
|
</TextInputGroupMain>
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
<
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
235
|
+
{showUtilities && (
|
|
236
|
+
<TextInputGroupUtilities>
|
|
237
|
+
{showClearButton && (
|
|
238
|
+
<Button variant="plain" onClick={clearChipsAndInput} aria-label="Clear button and input">
|
|
239
|
+
<TimesIcon />
|
|
240
|
+
</Button>
|
|
241
|
+
)}
|
|
242
|
+
</TextInputGroupUtilities>
|
|
243
|
+
)}
|
|
239
244
|
</TextInputGroup>
|
|
240
245
|
</div>
|
|
241
246
|
);
|
|
@@ -92,11 +92,11 @@ export const AutoCompleteSearch: React.FunctionComponent = () => {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
const handleTab = (
|
|
95
|
+
const handleTab = () => {
|
|
96
96
|
if (menuItems.length === 3) {
|
|
97
97
|
setInputValue(menuItems[2].props.children);
|
|
98
|
-
event.preventDefault();
|
|
99
98
|
}
|
|
99
|
+
setMenuIsOpen(false);
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
/** close the menu when escape is hit */
|
|
@@ -129,7 +129,7 @@ export const AutoCompleteSearch: React.FunctionComponent = () => {
|
|
|
129
129
|
handleEscape();
|
|
130
130
|
break;
|
|
131
131
|
case 'Tab':
|
|
132
|
-
handleTab(
|
|
132
|
+
handleTab();
|
|
133
133
|
break;
|
|
134
134
|
case 'ArrowUp':
|
|
135
135
|
case 'ArrowDown':
|
|
@@ -166,19 +166,29 @@ export const AutoCompleteSearch: React.FunctionComponent = () => {
|
|
|
166
166
|
|
|
167
167
|
/** enable keyboard only usage while focused on the menu */
|
|
168
168
|
const handleMenuKeyDown = (event: React.KeyboardEvent) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
switch (event.key) {
|
|
170
|
+
case 'Tab':
|
|
171
|
+
case 'Escape':
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
focusTextInput();
|
|
174
|
+
setMenuIsOpen(false);
|
|
175
|
+
break;
|
|
176
|
+
case 'Enter':
|
|
177
|
+
case ' ':
|
|
178
|
+
setTimeout(() => setMenuIsOpen(false), 0);
|
|
179
|
+
break;
|
|
173
180
|
}
|
|
174
181
|
};
|
|
175
182
|
|
|
176
|
-
/**
|
|
183
|
+
/** show the search icon only when there are no chips to prevent the chips from being displayed behind the icon */
|
|
177
184
|
const showSearchIcon = !currentChips.length;
|
|
178
185
|
|
|
179
186
|
/** only show the clear button when there is something that can be cleared */
|
|
180
187
|
const showClearButton = !!inputValue || !!currentChips.length;
|
|
181
188
|
|
|
189
|
+
/** render the utilities component only when a component it contains is being rendered */
|
|
190
|
+
const showUtilities = showClearButton;
|
|
191
|
+
|
|
182
192
|
const inputGroup = (
|
|
183
193
|
<div ref={textInputGroupRef}>
|
|
184
194
|
<TextInputGroup>
|
|
@@ -188,6 +198,8 @@ export const AutoCompleteSearch: React.FunctionComponent = () => {
|
|
|
188
198
|
onChange={handleInputChange}
|
|
189
199
|
onFocus={() => setMenuIsOpen(true)}
|
|
190
200
|
onKeyDown={handleTextInputKeyDown}
|
|
201
|
+
placeholder="search"
|
|
202
|
+
aria-label="Search input"
|
|
191
203
|
>
|
|
192
204
|
<ChipGroup>
|
|
193
205
|
{currentChips.map(currentChip => (
|
|
@@ -197,13 +209,15 @@ export const AutoCompleteSearch: React.FunctionComponent = () => {
|
|
|
197
209
|
))}
|
|
198
210
|
</ChipGroup>
|
|
199
211
|
</TextInputGroupMain>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
{showUtilities && (
|
|
213
|
+
<TextInputGroupUtilities>
|
|
214
|
+
{showClearButton && (
|
|
215
|
+
<Button variant="plain" onClick={clearChipsAndInput} aria-label="Clear button for chips and input">
|
|
216
|
+
<TimesIcon />
|
|
217
|
+
</Button>
|
|
218
|
+
)}
|
|
219
|
+
</TextInputGroupUtilities>
|
|
220
|
+
)}
|
|
207
221
|
</TextInputGroup>
|
|
208
222
|
</div>
|
|
209
223
|
);
|