@patternfly/react-core 4.191.6 → 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 +11 -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/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/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 +942 -902
- 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/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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.192.0",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.
|
|
38
|
-
"@patternfly/react-styles": "^4.
|
|
39
|
-
"@patternfly/react-tokens": "^4.
|
|
37
|
+
"@patternfly/react-icons": "^4.43.0",
|
|
38
|
+
"@patternfly/react-styles": "^4.42.0",
|
|
39
|
+
"@patternfly/react-tokens": "^4.44.0",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
43
43
|
"tslib": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@patternfly/patternfly": "4.
|
|
46
|
+
"@patternfly/patternfly": "4.171.0",
|
|
47
47
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
48
48
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
49
49
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "a41d19dbc31279e77a47110886e4d6173c3b7d96"
|
|
64
64
|
}
|
|
@@ -11,7 +11,7 @@ export interface DataListCheckProps extends Omit<React.HTMLProps<HTMLInputElemen
|
|
|
11
11
|
isDisabled?: boolean;
|
|
12
12
|
/** Flag to show if the DataList checkbox is checked */
|
|
13
13
|
isChecked?: boolean;
|
|
14
|
-
/**
|
|
14
|
+
/** Flag to set default value of DataList checkbox when it is uncontrolled by React state */
|
|
15
15
|
checked?: boolean;
|
|
16
16
|
/** A callback for when the DataList checkbox selection changes */
|
|
17
17
|
onChange?: (checked: boolean, event: React.FormEvent<HTMLInputElement>) => void;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Button } from '../Button';
|
|
3
3
|
import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
|
|
4
|
+
import { OUIAProps } from '../../helpers';
|
|
4
5
|
|
|
5
|
-
export interface ModalBoxCloseButtonProps {
|
|
6
|
+
export interface ModalBoxCloseButtonProps extends OUIAProps {
|
|
6
7
|
/** Additional classes added to the close button */
|
|
7
8
|
className?: string;
|
|
8
9
|
/** A callback for when the close button is clicked */
|
|
@@ -12,9 +13,17 @@ export interface ModalBoxCloseButtonProps {
|
|
|
12
13
|
export const ModalBoxCloseButton: React.FunctionComponent<ModalBoxCloseButtonProps> = ({
|
|
13
14
|
className = '',
|
|
14
15
|
onClose = () => undefined as any,
|
|
16
|
+
ouiaId,
|
|
15
17
|
...props
|
|
16
18
|
}: ModalBoxCloseButtonProps) => (
|
|
17
|
-
<Button
|
|
19
|
+
<Button
|
|
20
|
+
className={className}
|
|
21
|
+
variant="plain"
|
|
22
|
+
onClick={onClose}
|
|
23
|
+
aria-label="Close"
|
|
24
|
+
{...(ouiaId && { ouiaId: `${ouiaId}-${ModalBoxCloseButton.displayName}` })}
|
|
25
|
+
{...props}
|
|
26
|
+
>
|
|
18
27
|
<TimesIcon />
|
|
19
28
|
</Button>
|
|
20
29
|
);
|
|
@@ -162,7 +162,7 @@ export const ModalContent: React.FunctionComponent<ModalContentProps> = ({
|
|
|
162
162
|
aria-describedby={ariaDescribedby || (hasNoBodyWrapper ? null : descriptorId)}
|
|
163
163
|
{...getOUIAProps(ModalContent.displayName, ouiaId, ouiaSafe)}
|
|
164
164
|
>
|
|
165
|
-
{showClose && <ModalBoxCloseButton onClose={onClose} />}
|
|
165
|
+
{showClose && <ModalBoxCloseButton onClose={onClose} ouiaId={ouiaId} />}
|
|
166
166
|
{modalBoxHeader}
|
|
167
167
|
{modalBody}
|
|
168
168
|
{modalBoxFooter}
|
|
@@ -866,203 +866,6 @@ class HelpModal extends React.Component {
|
|
|
866
866
|
|
|
867
867
|
### With form
|
|
868
868
|
|
|
869
|
-
```
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
FormModal = () => {
|
|
874
|
-
const [isModalOpen, setModalOpen] = React.useState(false);
|
|
875
|
-
const [nameValue, setNameValue] = React.useState("");
|
|
876
|
-
const [emailValue, setEmailValue] = React.useState("");
|
|
877
|
-
const [addressValue, setAddressValue] = React.useState("");
|
|
878
|
-
|
|
879
|
-
handleModalToggle = () => {
|
|
880
|
-
setModalOpen(!isModalOpen);
|
|
881
|
-
};
|
|
882
|
-
|
|
883
|
-
handleNameInputChange = value => {
|
|
884
|
-
setNameValue(value);
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
handleEmailInputChange = value => {
|
|
888
|
-
setEmailValue(value);
|
|
889
|
-
};
|
|
890
|
-
handleAddressInputChange = value => {
|
|
891
|
-
setAddressValue(value);
|
|
892
|
-
};
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
return (
|
|
896
|
-
<React.Fragment>
|
|
897
|
-
<Button variant="primary" onClick={handleModalToggle}>
|
|
898
|
-
Show modal
|
|
899
|
-
</Button>
|
|
900
|
-
<Modal
|
|
901
|
-
variant={ModalVariant.small}
|
|
902
|
-
title="Create account"
|
|
903
|
-
description="Enter your personal information below to create an account."
|
|
904
|
-
isOpen={isModalOpen}
|
|
905
|
-
onClose={handleModalToggle}
|
|
906
|
-
actions={[
|
|
907
|
-
<Button key="create" variant="primary" form="modal-with-form-form" onClick={this.handleModalToggle}>
|
|
908
|
-
Confirm
|
|
909
|
-
</Button>,
|
|
910
|
-
<Button key="cancel" variant="link" onClick={this.handleModalToggle}>
|
|
911
|
-
Cancel
|
|
912
|
-
</Button>
|
|
913
|
-
]}
|
|
914
|
-
>
|
|
915
|
-
<Form id="modal-with-form-form">
|
|
916
|
-
<FormGroup
|
|
917
|
-
label="Name"
|
|
918
|
-
labelIcon={
|
|
919
|
-
<Popover
|
|
920
|
-
headerContent={
|
|
921
|
-
<div>
|
|
922
|
-
The
|
|
923
|
-
<a href="https://schema.org/name" target="_blank">
|
|
924
|
-
name
|
|
925
|
-
</a>
|
|
926
|
-
of a
|
|
927
|
-
<a href="https://schema.org/Person" target="_blank">
|
|
928
|
-
Person
|
|
929
|
-
</a>
|
|
930
|
-
</div>
|
|
931
|
-
}
|
|
932
|
-
bodyContent={
|
|
933
|
-
<div>
|
|
934
|
-
Often composed of
|
|
935
|
-
<a href="https://schema.org/givenName" target="_blank">
|
|
936
|
-
givenName
|
|
937
|
-
</a>
|
|
938
|
-
and
|
|
939
|
-
<a href="https://schema.org/familyName" target="_blank">
|
|
940
|
-
familyName
|
|
941
|
-
</a>
|
|
942
|
-
.
|
|
943
|
-
</div>
|
|
944
|
-
}
|
|
945
|
-
>
|
|
946
|
-
<button
|
|
947
|
-
type="button"
|
|
948
|
-
aria-label="More info for name field"
|
|
949
|
-
onClick={e => e.preventDefault()}
|
|
950
|
-
aria-describedby="modal-with-form-form-name"
|
|
951
|
-
className="pf-c-form__group-label-help"
|
|
952
|
-
>
|
|
953
|
-
<HelpIcon noVerticalAlign />
|
|
954
|
-
</button>
|
|
955
|
-
</Popover>
|
|
956
|
-
}
|
|
957
|
-
isRequired
|
|
958
|
-
fieldId="modal-with-form-form-name">
|
|
959
|
-
<TextInput
|
|
960
|
-
isRequired
|
|
961
|
-
type="email"
|
|
962
|
-
id="modal-with-form-form-name"
|
|
963
|
-
name="modal-with-form-form-name"
|
|
964
|
-
value={nameValue}
|
|
965
|
-
onChange={handleNameInputChange}
|
|
966
|
-
/>
|
|
967
|
-
</FormGroup>
|
|
968
|
-
<FormGroup
|
|
969
|
-
label="E-mail"
|
|
970
|
-
labelIcon={
|
|
971
|
-
<Popover
|
|
972
|
-
headerContent={
|
|
973
|
-
<div>
|
|
974
|
-
The
|
|
975
|
-
<a href="https://schema.org/email" target="_blank">
|
|
976
|
-
e-mail
|
|
977
|
-
</a>
|
|
978
|
-
of a
|
|
979
|
-
<a href="https://schema.org/Person" target="_blank">
|
|
980
|
-
person
|
|
981
|
-
</a>
|
|
982
|
-
</div>
|
|
983
|
-
}
|
|
984
|
-
bodyContent={
|
|
985
|
-
<div>
|
|
986
|
-
Valid
|
|
987
|
-
<a href="https://schema.org/email" target="_blank">
|
|
988
|
-
e-mail
|
|
989
|
-
</a>
|
|
990
|
-
address.
|
|
991
|
-
</div>
|
|
992
|
-
}
|
|
993
|
-
>
|
|
994
|
-
<button
|
|
995
|
-
type="button"
|
|
996
|
-
aria-label="More info for e-mail field"
|
|
997
|
-
onClick={e => e.preventDefault()}
|
|
998
|
-
aria-describedby="modal-with-form-form-email"
|
|
999
|
-
className="pf-c-form__group-label-help"
|
|
1000
|
-
>
|
|
1001
|
-
<HelpIcon noVerticalAlign />
|
|
1002
|
-
</button>
|
|
1003
|
-
</Popover>
|
|
1004
|
-
}
|
|
1005
|
-
isRequired
|
|
1006
|
-
fieldId="modal-with-form-form-email">
|
|
1007
|
-
<TextInput
|
|
1008
|
-
isRequired
|
|
1009
|
-
type="email"
|
|
1010
|
-
id="modal-with-form-form-email"
|
|
1011
|
-
name="modal-with-form-form-email"
|
|
1012
|
-
value={emailValue}
|
|
1013
|
-
onChange={handleEmailInputChange}
|
|
1014
|
-
/>
|
|
1015
|
-
</FormGroup>
|
|
1016
|
-
<FormGroup
|
|
1017
|
-
label="Address"
|
|
1018
|
-
labelIcon={
|
|
1019
|
-
<Popover
|
|
1020
|
-
headerContent={
|
|
1021
|
-
<div>
|
|
1022
|
-
The
|
|
1023
|
-
<a href="https://schema.org/address" target="_blank">
|
|
1024
|
-
adress
|
|
1025
|
-
</a>
|
|
1026
|
-
of a
|
|
1027
|
-
<a href="https://schema.org/Person" target="_blank">
|
|
1028
|
-
person
|
|
1029
|
-
</a>
|
|
1030
|
-
</div>
|
|
1031
|
-
}
|
|
1032
|
-
bodyContent={
|
|
1033
|
-
<div>
|
|
1034
|
-
Valid
|
|
1035
|
-
<a href="https://schema.org/PostalAddress" target="_blank">
|
|
1036
|
-
postal address.
|
|
1037
|
-
</a>
|
|
1038
|
-
</div>
|
|
1039
|
-
}
|
|
1040
|
-
>
|
|
1041
|
-
<button
|
|
1042
|
-
type="button"
|
|
1043
|
-
aria-label="More info for address field"
|
|
1044
|
-
onClick={e => e.preventDefault()}
|
|
1045
|
-
aria-describedby="modal-with-form-form-address"
|
|
1046
|
-
className="pf-c-form__group-label-help"
|
|
1047
|
-
>
|
|
1048
|
-
<HelpIcon noVerticalAlign />
|
|
1049
|
-
</button>
|
|
1050
|
-
</Popover>
|
|
1051
|
-
}
|
|
1052
|
-
isRequired
|
|
1053
|
-
fieldId="modal-with-form-form-address">
|
|
1054
|
-
<TextInput
|
|
1055
|
-
isRequired
|
|
1056
|
-
type="email"
|
|
1057
|
-
id="modal-with-form-form-address"
|
|
1058
|
-
name="modal-with-form-form-address"
|
|
1059
|
-
value={addressValue}
|
|
1060
|
-
onChange={handleAddressInputChange}
|
|
1061
|
-
/>
|
|
1062
|
-
</FormGroup>
|
|
1063
|
-
</Form>
|
|
1064
|
-
</Modal>
|
|
1065
|
-
</React.Fragment>
|
|
1066
|
-
);
|
|
1067
|
-
};
|
|
1068
|
-
```
|
|
869
|
+
```ts file="ModalWithForm.tsx"
|
|
870
|
+
|
|
871
|
+
```
|
|
@@ -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
|
+
};
|
|
@@ -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
|
+
`;
|