1
|
1 |
|
import "./styles.css"; |
2
|
1 |
|
import React from "react"; |
3
|
1 |
|
import classNames from "classnames"; |
4
|
|
|
|
5
|
|
|
import { DrawerComponent } from "./types"; |
6
|
|
|
|
7
|
1 |
|
import { buildComponent } from "../../../utils"; |
8
|
|
|
|
9
|
1 |
|
import Button from "../../atoms/Button"; |
10
|
|
|
|
11
|
1 |
|
const ALLOWED_POSITIONS = [ |
12
|
|
|
"right", |
13
|
|
|
"left", |
14
|
|
|
"top", |
15
|
|
|
"bottom", |
16
|
|
|
"top-left", |
17
|
|
|
"top-right", |
18
|
|
|
"bottom-left", |
19
|
|
|
"bottom-right", |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* A modern drawer, easy to integrate and to customize. |
24
|
|
|
* |
25
|
|
|
* @since 0.6.0 |
26
|
|
|
* |
27
|
|
|
* @param {DrawerProps["position"]} position drawer position (relative to the entire window). Possible values are `bottom`, `top`, `right`, `left`, `bottom-left`, `bottom-right`, `top-left` and `top-right` |
28
|
|
|
* @param {DrawerProps["onClose"]} onClose Callback triggered on Drawer close |
29
|
|
|
* @param {string} className `common modular-ui prop` - custom className (to better customize it) |
30
|
|
|
* @param {boolean} unstyled `common modular-ui prop` - Style/unstyle component (to better customize it) |
31
|
|
|
* @param {string} id `common modular-ui prop` - `data-id` parameter (for testing purpose, to easily find the component into the DOM) |
32
|
|
|
* @param {boolean} dark `common modular-ui prop` - Enable/disable dark mode |
33
|
|
|
* @param {boolean} hide `common modular-ui prop` - Hide/show component |
34
|
|
|
* @param {boolean} shadow `common modular-ui prop` - Enable/disable shadow behind component (to better customize it) |
35
|
|
|
* |
36
|
|
|
*@example <caption>Example Drawer usage</caption> |
37
|
|
|
*import { render } from "react-dom"; |
38
|
|
|
*import { Drawer } from '@cianciarusocataldo/modular-ui'; |
39
|
|
|
* |
40
|
|
|
* render(<Drawer children={<div>Drawer content</div>} position="top-left" />, document.getElementById("root")); |
41
|
|
|
* |
42
|
|
|
* @see https://cianciarusocataldo.github.io/modular-ui/components/molecules/Drawer |
43
|
|
|
* |
44
|
|
|
* @author Cataldo Cianciaruso <https://github.com/CianciarusoCataldo> |
45
|
|
|
* |
46
|
|
|
* @copyright 2022 Cataldo Cianciaruso |
47
|
|
|
*/ |
48
|
1 |
|
const Drawer: DrawerComponent = ({ |
49
|
3 |
|
children, |
50
|
3 |
|
onClose, |
51
|
3 |
|
hide, |
52
|
3 |
|
className, |
53
|
3 |
|
position, |
54
|
3 |
|
...commonProps |
55
|
|
|
}) => { |
56
|
|
|
const drawerLocation = |
57
|
4 |
|
position && ALLOWED_POSITIONS.includes(position) ? position : "left"; |
58
|
3 |
|
return buildComponent({ |
59
|
|
|
name: "modular-drawer", |
60
|
|
|
commonProps: { |
61
|
|
|
...commonProps, |
62
|
|
|
className: classNames( |
63
|
|
|
drawerLocation, |
64
|
|
|
{ |
65
|
|
|
"ease-in": !hide, |
66
|
|
|
"ease-out": hide, |
67
|
|
|
}, |
68
|
|
|
className |
69
|
|
|
), |
70
|
|
|
}, |
71
|
|
|
Component: ( |
72
|
|
|
<div className="container-internal"> |
73
|
|
|
<div className="buttons-panel"> |
74
|
|
|
<Button |
75
|
|
|
dark={commonProps.dark} |
76
|
|
|
unstyled |
77
|
|
|
id="drawer_close_button" |
78
|
|
|
onClick={() => { |
79
|
1 |
|
onClose(); |
80
|
|
|
}} |
81
|
|
|
className="close-button" |
82
|
|
|
> |
83
|
|
|
{ |
84
|
|
|
<svg |
85
|
|
|
xmlns="http://www.w3.org/2000/svg" |
86
|
|
|
width="30" |
87
|
|
|
height="37" |
88
|
|
|
viewBox="0 0 11 18" |
89
|
|
|
> |
90
|
|
|
<path d="M8.6812.1963l2.1208928 2.120293-8.484 8.4864L.1972 8.6827z" /> |
91
|
|
|
<path d="M10.8032656 15.0470656l-2.1213 2.1213-8.4852-8.4852 2.1213-2.1213z" /> |
92
|
|
|
</svg> |
93
|
|
|
} |
94
|
|
|
</Button> |
95
|
|
|
</div> |
96
|
|
|
<div className="elements">{children}</div> |
97
|
|
|
</div> |
98
|
|
|
), |
99
|
|
|
}); |
100
|
|
|
}; |
101
|
|
|
|
102
|
|
|
export default Drawer; |
103
|
|
|
|