@patternfly/react-core 4.191.6 → 4.192.3
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/Select/Select.d.ts.map +1 -1
- package/dist/esm/components/Select/Select.js +2 -2
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Select/SelectOption.d.ts +2 -0
- package/dist/esm/components/Select/SelectOption.d.ts.map +1 -1
- package/dist/esm/components/Select/SelectOption.js +70 -48
- package/dist/esm/components/Select/SelectOption.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/Select/Select.d.ts.map +1 -1
- package/dist/js/components/Select/Select.js +2 -2
- package/dist/js/components/Select/Select.js.map +1 -1
- package/dist/js/components/Select/SelectOption.d.ts +2 -0
- package/dist/js/components/Select/SelectOption.d.ts.map +1 -1
- package/dist/js/components/Select/SelectOption.js +70 -48
- package/dist/js/components/Select/SelectOption.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 +59 -6
- package/dist/umd/react-core.js +1002 -940
- package/dist/umd/react-core.min.css +59 -6
- package/dist/umd/react-core.min.js +2 -2
- package/index.d.ts +4 -0
- package/package.json +6 -6
- package/src/components/BackToTop/examples/BackToTop.css +3 -3
- package/src/components/BackToTop/examples/BackToTop.md +2 -6
- package/src/components/BackToTop/examples/BackToTopBasic.tsx +4 -0
- package/src/components/Backdrop/examples/Backdrop.md +3 -12
- package/src/components/Backdrop/examples/BackdropBasic.tsx +4 -0
- package/src/components/Backdrop/examples/BackdropSpinner.tsx +10 -0
- package/src/components/BackgroundImage/examples/BackgroundImage.md +2 -21
- package/src/components/BackgroundImage/examples/BackgroundImageBasic.tsx +15 -0
- package/src/components/Badge/examples/Badge.md +3 -24
- package/src/components/Badge/examples/BadgeRead.tsx +19 -0
- package/src/components/Badge/examples/BadgeUnread.tsx +8 -0
- package/src/components/Banner/examples/Banner.md +1 -14
- package/src/components/Banner/examples/BannerBasic.tsx +16 -0
- package/src/components/Brand/examples/Brand.md +3 -5
- package/src/components/Brand/examples/BrandBasic.tsx +5 -0
- package/src/components/Breadcrumb/examples/Breadcrumb.md +4 -105
- package/src/components/Breadcrumb/examples/BreadcrumbBasic.tsx +13 -0
- package/src/components/Breadcrumb/examples/BreadcrumbDropdown.tsx +53 -0
- package/src/components/Breadcrumb/examples/BreadcrumbWithHeading.tsx +12 -0
- package/src/components/Breadcrumb/examples/BreadcrumbWithoutHomeLink.tsx +15 -0
- package/src/components/Button/examples/ButtonAriaDisabled.tsx +33 -37
- package/src/components/Button/examples/ButtonCallToAction.tsx +8 -6
- package/src/components/Button/examples/ButtonDisabled.tsx +33 -37
- package/src/components/Button/examples/ButtonInlineSpanLink.tsx +2 -2
- package/src/components/Button/examples/ButtonLinks.tsx +6 -6
- package/src/components/Button/examples/ButtonProgress.tsx +8 -5
- package/src/components/Button/examples/ButtonSmall.tsx +9 -7
- package/src/components/Button/examples/ButtonTypes.tsx +4 -6
- package/src/components/Button/examples/ButtonVariations.tsx +31 -36
- 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/Select/Select.tsx +2 -1
- package/src/components/Select/SelectOption.tsx +188 -133
- 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/Tabs/NestedTabsDemo.js +3 -3
- package/src/demos/Tabs.md +4 -0
- package/src/demos/examples/Tabs/GrayTabs.tsx +158 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal, ModalVariant, Button, Form, FormGroup, Popover, TextInput } from '@patternfly/react-core';
|
|
3
|
+
import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
|
|
4
|
+
|
|
5
|
+
export const ModalWithForm: React.FunctionComponent = () => {
|
|
6
|
+
const [isModalOpen, setModalOpen] = React.useState(false);
|
|
7
|
+
const [nameValue, setNameValue] = React.useState('');
|
|
8
|
+
const [emailValue, setEmailValue] = React.useState('');
|
|
9
|
+
const [addressValue, setAddressValue] = React.useState('');
|
|
10
|
+
const nameInputRef = React.useRef();
|
|
11
|
+
|
|
12
|
+
const handleModalToggle = () => {
|
|
13
|
+
setModalOpen(!isModalOpen);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const handleNameInputChange = value => {
|
|
17
|
+
setNameValue(value);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const handleEmailInputChange = value => {
|
|
21
|
+
setEmailValue(value);
|
|
22
|
+
};
|
|
23
|
+
const handleAddressInputChange = value => {
|
|
24
|
+
setAddressValue(value);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
if (isModalOpen && nameInputRef && nameInputRef.current) {
|
|
29
|
+
(nameInputRef.current as HTMLInputElement).focus();
|
|
30
|
+
}
|
|
31
|
+
}, [isModalOpen]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<React.Fragment>
|
|
35
|
+
<Button variant="primary" onClick={handleModalToggle}>
|
|
36
|
+
Show modal
|
|
37
|
+
</Button>
|
|
38
|
+
<Modal
|
|
39
|
+
variant={ModalVariant.small}
|
|
40
|
+
title="Create account"
|
|
41
|
+
description="Enter your personal information below to create an account."
|
|
42
|
+
isOpen={isModalOpen}
|
|
43
|
+
onClose={handleModalToggle}
|
|
44
|
+
actions={[
|
|
45
|
+
<Button key="create" variant="primary" form="modal-with-form-form" onClick={handleModalToggle}>
|
|
46
|
+
Confirm
|
|
47
|
+
</Button>,
|
|
48
|
+
<Button key="cancel" variant="link" onClick={handleModalToggle}>
|
|
49
|
+
Cancel
|
|
50
|
+
</Button>
|
|
51
|
+
]}
|
|
52
|
+
>
|
|
53
|
+
<Form id="modal-with-form-form">
|
|
54
|
+
<FormGroup
|
|
55
|
+
label="Name"
|
|
56
|
+
labelIcon={
|
|
57
|
+
<Popover
|
|
58
|
+
headerContent={
|
|
59
|
+
<div>
|
|
60
|
+
The
|
|
61
|
+
<a href="https://schema.org/name" target="_blank" rel="noopener noreferrer">
|
|
62
|
+
name
|
|
63
|
+
</a>
|
|
64
|
+
of a
|
|
65
|
+
<a href="https://schema.org/Person" target="_blank" rel="noopener noreferrer">
|
|
66
|
+
Person
|
|
67
|
+
</a>
|
|
68
|
+
</div>
|
|
69
|
+
}
|
|
70
|
+
bodyContent={
|
|
71
|
+
<div>
|
|
72
|
+
Often composed of
|
|
73
|
+
<a href="https://schema.org/givenName" target="_blank" rel="noopener noreferrer">
|
|
74
|
+
givenName
|
|
75
|
+
</a>
|
|
76
|
+
and
|
|
77
|
+
<a href="https://schema.org/familyName" target="_blank" rel="noopener noreferrer">
|
|
78
|
+
familyName
|
|
79
|
+
</a>
|
|
80
|
+
.
|
|
81
|
+
</div>
|
|
82
|
+
}
|
|
83
|
+
>
|
|
84
|
+
<button
|
|
85
|
+
type="button"
|
|
86
|
+
aria-label="More info for name field"
|
|
87
|
+
onClick={e => e.preventDefault()}
|
|
88
|
+
aria-describedby="modal-with-form-form-name"
|
|
89
|
+
className="pf-c-form__group-label-help"
|
|
90
|
+
>
|
|
91
|
+
<HelpIcon noVerticalAlign />
|
|
92
|
+
</button>
|
|
93
|
+
</Popover>
|
|
94
|
+
}
|
|
95
|
+
isRequired
|
|
96
|
+
fieldId="modal-with-form-form-name"
|
|
97
|
+
>
|
|
98
|
+
<TextInput
|
|
99
|
+
isRequired
|
|
100
|
+
type="email"
|
|
101
|
+
id="modal-with-form-form-name"
|
|
102
|
+
name="modal-with-form-form-name"
|
|
103
|
+
value={nameValue}
|
|
104
|
+
onChange={handleNameInputChange}
|
|
105
|
+
ref={nameInputRef}
|
|
106
|
+
/>
|
|
107
|
+
</FormGroup>
|
|
108
|
+
<FormGroup
|
|
109
|
+
label="E-mail"
|
|
110
|
+
labelIcon={
|
|
111
|
+
<Popover
|
|
112
|
+
headerContent={
|
|
113
|
+
<div>
|
|
114
|
+
The
|
|
115
|
+
<a href="https://schema.org/email" target="_blank" rel="noopener noreferrer">
|
|
116
|
+
e-mail
|
|
117
|
+
</a>
|
|
118
|
+
of a
|
|
119
|
+
<a href="https://schema.org/Person" target="_blank" rel="noopener noreferrer">
|
|
120
|
+
person
|
|
121
|
+
</a>
|
|
122
|
+
</div>
|
|
123
|
+
}
|
|
124
|
+
bodyContent={
|
|
125
|
+
<div>
|
|
126
|
+
Valid
|
|
127
|
+
<a href="https://schema.org/email" target="_blank" rel="noopener noreferrer">
|
|
128
|
+
e-mail
|
|
129
|
+
</a>
|
|
130
|
+
address.
|
|
131
|
+
</div>
|
|
132
|
+
}
|
|
133
|
+
>
|
|
134
|
+
<button
|
|
135
|
+
type="button"
|
|
136
|
+
aria-label="More info for e-mail field"
|
|
137
|
+
onClick={e => e.preventDefault()}
|
|
138
|
+
aria-describedby="modal-with-form-form-email"
|
|
139
|
+
className="pf-c-form__group-label-help"
|
|
140
|
+
>
|
|
141
|
+
<HelpIcon noVerticalAlign />
|
|
142
|
+
</button>
|
|
143
|
+
</Popover>
|
|
144
|
+
}
|
|
145
|
+
isRequired
|
|
146
|
+
fieldId="modal-with-form-form-email"
|
|
147
|
+
>
|
|
148
|
+
<TextInput
|
|
149
|
+
isRequired
|
|
150
|
+
type="email"
|
|
151
|
+
id="modal-with-form-form-email"
|
|
152
|
+
name="modal-with-form-form-email"
|
|
153
|
+
value={emailValue}
|
|
154
|
+
onChange={handleEmailInputChange}
|
|
155
|
+
/>
|
|
156
|
+
</FormGroup>
|
|
157
|
+
<FormGroup
|
|
158
|
+
label="Address"
|
|
159
|
+
labelIcon={
|
|
160
|
+
<Popover
|
|
161
|
+
headerContent={
|
|
162
|
+
<div>
|
|
163
|
+
The
|
|
164
|
+
<a href="https://schema.org/address" target="_blank" rel="noopener noreferrer">
|
|
165
|
+
adress
|
|
166
|
+
</a>
|
|
167
|
+
of a
|
|
168
|
+
<a href="https://schema.org/Person" target="_blank" rel="noopener noreferrer">
|
|
169
|
+
person
|
|
170
|
+
</a>
|
|
171
|
+
</div>
|
|
172
|
+
}
|
|
173
|
+
bodyContent={
|
|
174
|
+
<div>
|
|
175
|
+
Valid
|
|
176
|
+
<a href="https://schema.org/PostalAddress" target="_blank" rel="noopener noreferrer">
|
|
177
|
+
postal address.
|
|
178
|
+
</a>
|
|
179
|
+
</div>
|
|
180
|
+
}
|
|
181
|
+
>
|
|
182
|
+
<button
|
|
183
|
+
type="button"
|
|
184
|
+
aria-label="More info for address field"
|
|
185
|
+
onClick={e => e.preventDefault()}
|
|
186
|
+
aria-describedby="modal-with-form-form-address"
|
|
187
|
+
className="pf-c-form__group-label-help"
|
|
188
|
+
>
|
|
189
|
+
<HelpIcon noVerticalAlign />
|
|
190
|
+
</button>
|
|
191
|
+
</Popover>
|
|
192
|
+
}
|
|
193
|
+
isRequired
|
|
194
|
+
fieldId="modal-with-form-form-address"
|
|
195
|
+
>
|
|
196
|
+
<TextInput
|
|
197
|
+
isRequired
|
|
198
|
+
type="email"
|
|
199
|
+
id="modal-with-form-form-address"
|
|
200
|
+
name="modal-with-form-form-address"
|
|
201
|
+
value={addressValue}
|
|
202
|
+
onChange={handleAddressInputChange}
|
|
203
|
+
/>
|
|
204
|
+
</FormGroup>
|
|
205
|
+
</Form>
|
|
206
|
+
</Modal>
|
|
207
|
+
</React.Fragment>
|
|
208
|
+
);
|
|
209
|
+
};
|
|
@@ -856,7 +856,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
856
856
|
if (renderableItems.find(item => (item as any)?.key === 'loading') === undefined) {
|
|
857
857
|
if (loadingVariant === 'spinner') {
|
|
858
858
|
renderableItems.push(
|
|
859
|
-
<SelectOption isLoading key="loading" value="loading">
|
|
859
|
+
<SelectOption isLoading key="loading" value="loading" isGrouped>
|
|
860
860
|
<Spinner size="lg" />
|
|
861
861
|
</SelectOption>
|
|
862
862
|
);
|
|
@@ -866,6 +866,7 @@ export class Select extends React.Component<SelectProps & OUIAProps, SelectState
|
|
|
866
866
|
isLoad
|
|
867
867
|
key="loading"
|
|
868
868
|
value={loadingVariant.text}
|
|
869
|
+
isGrouped
|
|
869
870
|
setViewMoreNextIndex={this.setVieMoreNextIndex}
|
|
870
871
|
onClick={loadingVariant?.onClick}
|
|
871
872
|
/>
|
|
@@ -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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
{
|
|
284
|
+
ref={this.liRef}
|
|
285
|
+
>
|
|
286
|
+
{isLoading && children}
|
|
287
|
+
{isLoad && !isGrouped && (
|
|
310
288
|
<button
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
{
|
|
298
|
+
{itemDisplay}
|
|
327
299
|
</button>
|
|
328
300
|
)}
|
|
329
|
-
{
|
|
330
|
-
|
|
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
|
|
325
|
+
this.onKeyDown(event, 0);
|
|
383
326
|
}}
|
|
384
327
|
type="button"
|
|
385
328
|
>
|
|
386
|
-
{
|
|
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
|
-
|
|
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
|
-
|
|
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
|
);
|
|
@@ -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
|
+
});
|