Debian Codegraph @

node/@patternfly/react-core/src/components/Drawer/examples/DrawerBreakpoint.tsx

raw
1 import { Fragment, useRef, useState } from 'react';
2 import {
3 Drawer,
4 DrawerPanelContent,
5 DrawerContent,
6 DrawerContentBody,
7 DrawerHead,
8 DrawerActions,
9 DrawerCloseButton,
10 Button
11 } from '@patternfly/react-core';
12
13 export const DrawerBreakpoint: React.FunctionComponent = () => {
14 const [isExpanded, setIsExpanded] = useState(false);
15 const drawerRef = useRef<HTMLSpanElement>(null);
16
17 const onExpand = () => {
18 drawerRef.current && drawerRef.current.focus();
19 };
20
21 const onClick = () => {
22 setIsExpanded(!isExpanded);
23 };
24
25 const onCloseClick = () => {
26 setIsExpanded(false);
27 };
28
29 const panelContent = (
30 <DrawerPanelContent widths={{ default: 'width_33' }}>
31 <DrawerHead>
32 <span tabIndex={isExpanded ? 0 : -1} ref={drawerRef}>
33 Drawer panel header
34 </span>
35 <DrawerActions>
36 <DrawerCloseButton onClick={onCloseClick} />
37 </DrawerActions>
38 </DrawerHead>
39 </DrawerPanelContent>
40 );
41
42 const drawerContent =
43 '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.';
44
45 return (
46 <Fragment>
47 <Button aria-expanded={isExpanded} onClick={onClick}>
48 Toggle drawer
49 </Button>
50 <Drawer isExpanded={isExpanded} onExpand={onExpand}>
51 <DrawerContent panelContent={panelContent}>
52 <DrawerContentBody>{drawerContent}</DrawerContentBody>
53 </DrawerContent>
54 </Drawer>
55 </Fragment>
56 );
57 };