generated from idea2app/Lark-Next-Bootstrap-ts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrawerNav.tsx
More file actions
47 lines (40 loc) · 1.22 KB
/
DrawerNav.tsx
File metadata and controls
47 lines (40 loc) · 1.22 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
import { Icon, PageNav } from 'idea-react';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { Component } from 'react';
import { Button, Offcanvas } from 'react-bootstrap';
import { sleep } from 'web-utility';
@observer
export class DrawerNav extends Component {
@observable
accessor drawerShown = false;
closeDrawer = async () => {
let { scrollTop } = document.scrollingElement || {};
do {
await sleep(0.1);
if (scrollTop === document.scrollingElement?.scrollTop) {
this.drawerShown = false;
break;
}
scrollTop = document.scrollingElement?.scrollTop;
// eslint-disable-next-line no-constant-condition
} while (true);
};
render() {
const { drawerShown, closeDrawer } = this;
return (
<>
<div className="fixed-bottom p-3">
<Button onClick={() => (this.drawerShown = true)}>
<Icon name="layout-text-sidebar" />
</Button>
</div>
<Offcanvas style={{ width: 'max-content' }} show={drawerShown} onHide={closeDrawer}>
<Offcanvas.Body>
<PageNav depth={2} onItemClick={this.closeDrawer} />
</Offcanvas.Body>
</Offcanvas>
</>
);
}
}