-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathDrawerResizeDemo.tsx
90 lines (81 loc) · 2.82 KB
/
DrawerResizeDemo.tsx
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Component, createRef } from 'react';
import {
Button,
Drawer,
DrawerPanelContent,
DrawerContent,
DrawerContentBody,
DrawerSection,
DrawerHead,
DrawerActions,
DrawerCloseButton,
DrawerProps
} from '@patternfly/react-core';
export interface DrawerResizeDemoState {
isExpanded: boolean;
panelWidth: number;
}
export class DrawerResizeDemo extends Component<DrawerProps, DrawerResizeDemoState> {
static displayName = 'DrawerDemo';
constructor(props: DrawerProps) {
super(props);
this.state = {
isExpanded: false,
panelWidth: 200
};
}
drawerRef = createRef<HTMLButtonElement>();
onExpand = () => {
this.drawerRef.current && this.drawerRef.current.focus();
};
onResize = (_event: MouseEvent | TouchEvent | React.KeyboardEvent, newWidth: number, id: string) => {
this.setState(
{
panelWidth: newWidth
},
// eslint-disable-next-line no-console
() => console.log(`${id} has new width: ${newWidth}`)
);
};
onClick = () => {
const isExpanded = !this.state.isExpanded;
this.setState({
isExpanded
});
};
onCloseClick = () => {
this.setState({
isExpanded: false
});
};
render() {
const { isExpanded } = this.state;
const panelContent = (
<DrawerPanelContent isResizable increment={50} onResize={this.onResize} id="panel" defaultSize={'200px'}>
<DrawerHead>
<span ref={this.drawerRef} tabIndex={isExpanded ? 0 : -1}>
drawer-panel
</span>
<DrawerActions>
<DrawerCloseButton onClick={this.onCloseClick} />
</DrawerActions>
</DrawerHead>
</DrawerPanelContent>
);
const drawerContent =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pretium est a porttitor vehicula. Quisque vel commodo urna. Morbi mattis rutrum ante, id vehicula ex accumsan ut. Morbi viverra, eros vel porttitor facilisis, eros purus aliquet erat,nec lobortis felis elit pulvinar sem. Vivamus vulputate, risus eget commodo eleifend, eros nibh porta quam, vitae lacinia leo libero at magna. Maecenas aliquam sagittis orci, et posuere nisi ultrices sit amet. Aliquam ex odio, malesuada sed posuere quis, pellentesque at mauris. Phasellus venenatis massa ex, eget pulvinar libero auctor pretium. Aliquam erat volutpat. Duis euismod justo in quam ullamcorper, in commodo massa vulputate.';
return (
<>
<Button id="toggleButton" onClick={this.onClick}>
Toggle Drawer
</Button>
<Drawer isExpanded={isExpanded} onExpand={this.onExpand} position="bottom">
<DrawerSection>drawer-section</DrawerSection>
<DrawerContent panelContent={panelContent}>
<DrawerContentBody>{drawerContent}</DrawerContentBody>
</DrawerContent>
</Drawer>
</>
);
}
}