-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathLabelEditable.tsx
More file actions
57 lines (51 loc) · 1.67 KB
/
LabelEditable.tsx
File metadata and controls
57 lines (51 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Fragment, useState } from 'react';
import { Label, LabelColor } from '@patternfly/react-core';
export const LabelEditable: React.FunctionComponent = () => {
const [labelText, setLabelText] = useState('Editable label');
const [compactLabelText, setCompactLabelText] = useState('Compact editable label');
const onEditCancel = (_event: KeyboardEvent, prevText: string) => {
setLabelText(prevText);
};
const onEditComplete = (_event: MouseEvent | KeyboardEvent, text: string) => {
setLabelText(text);
};
const onCompactEditCancel = (_event: KeyboardEvent, prevText: string) => {
setCompactLabelText(prevText);
};
const onCompactEditComplete = (_event: MouseEvent | KeyboardEvent, text: string) => {
setCompactLabelText(text);
};
return (
<Fragment>
<Label
color={LabelColor.blue}
onClose={() => {}}
closeBtnAriaLabel="Custom close button for editable label"
onEditCancel={onEditCancel}
onEditComplete={onEditComplete}
isEditable
editableProps={{
'aria-label': `Editable label with text ${labelText}`,
id: 'editable-label'
}}
>
{labelText}
</Label>
<Label
color={LabelColor.grey}
isCompact
onClose={() => {}}
closeBtnAriaLabel="Custom close button for compact editable label"
onEditCancel={onCompactEditCancel}
onEditComplete={onCompactEditComplete}
isEditable
editableProps={{
'aria-label': `Editable compact label with text ${compactLabelText}`,
id: 'compact-editable-label'
}}
>
{compactLabelText}
</Label>
</Fragment>
);
};