umwd-components 0.1.222 → 0.1.224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/StrapiErrors.js +1 -0
- package/dist/cjs/components/dashboard/Sidebar.js +220 -0
- package/dist/cjs/index.js +2 -0
- package/dist/esm/components/StrapiErrors.js +2 -1
- package/dist/esm/components/dashboard/Sidebar.js +197 -0
- package/dist/esm/index.js +1 -0
- package/package.json +1 -1
- package/src/components/StrapiErrors.tsx +1 -0
- package/src/components/ZodErrors.tsx +2 -0
- package/src/components/dashboard/Sidebar.tsx +248 -0
- package/src/index.js +1 -0
- package/src/stories/SideBar.stories.js +37 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* UMWD-Components
|
|
3
|
+
* @copyright Jelle Paulus
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
10
|
+
|
|
11
|
+
var React = require('react');
|
|
12
|
+
var router = require('next/router');
|
|
13
|
+
var Link = require('next/link');
|
|
14
|
+
var material = require('@mui/material');
|
|
15
|
+
var MuiDrawer = require('@mui/material/Drawer');
|
|
16
|
+
var MuiAppBar = require('@mui/material/AppBar');
|
|
17
|
+
var iconsMaterial = require('@mui/icons-material');
|
|
18
|
+
|
|
19
|
+
function _interopNamespaceDefault(e) {
|
|
20
|
+
var n = Object.create(null);
|
|
21
|
+
if (e) {
|
|
22
|
+
Object.keys(e).forEach(function (k) {
|
|
23
|
+
if (k !== 'default') {
|
|
24
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return e[k]; }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
n.default = e;
|
|
33
|
+
return Object.freeze(n);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
37
|
+
|
|
38
|
+
const drawerWidth = 290;
|
|
39
|
+
const DrawerHeader = material.styled("div")(_ref => {
|
|
40
|
+
let {
|
|
41
|
+
theme
|
|
42
|
+
} = _ref;
|
|
43
|
+
return {
|
|
44
|
+
display: "flex",
|
|
45
|
+
alignItems: "center",
|
|
46
|
+
justifyContent: "flex-end",
|
|
47
|
+
padding: theme.spacing(0, 1),
|
|
48
|
+
// necessary for content to be below app bar
|
|
49
|
+
...theme.mixins.toolbar
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
function Sidebar(_ref2) {
|
|
53
|
+
let {
|
|
54
|
+
children,
|
|
55
|
+
data
|
|
56
|
+
} = _ref2;
|
|
57
|
+
const {
|
|
58
|
+
sections = [],
|
|
59
|
+
actions = [],
|
|
60
|
+
sx = {},
|
|
61
|
+
title
|
|
62
|
+
} = data;
|
|
63
|
+
console.log("sections", sections);
|
|
64
|
+
console.log("actions", actions);
|
|
65
|
+
router.useRouter();
|
|
66
|
+
const theme = material.useTheme();
|
|
67
|
+
const AppbarSxOpen = {
|
|
68
|
+
zIndex: theme.zIndex.drawer + 1,
|
|
69
|
+
marginLeft: drawerWidth,
|
|
70
|
+
width: "calc(100% - ".concat(drawerWidth, "px)"),
|
|
71
|
+
transition: theme.transitions.create(["width", "margin"], {
|
|
72
|
+
easing: theme.transitions.easing.sharp,
|
|
73
|
+
duration: theme.transitions.duration.enteringScreen
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
const AppbarSxClosed = {
|
|
77
|
+
zIndex: theme.zIndex.drawer + 1,
|
|
78
|
+
transition: theme.transitions.create(["width", "margin"], {
|
|
79
|
+
easing: theme.transitions.easing.sharp,
|
|
80
|
+
duration: theme.transitions.duration.leavingScreen
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
const drawerSxOpen = {
|
|
84
|
+
width: drawerWidth,
|
|
85
|
+
flexShrink: 0,
|
|
86
|
+
whiteSpace: "nowrap",
|
|
87
|
+
boxSizing: "border-box",
|
|
88
|
+
transition: theme.transitions.create("width", {
|
|
89
|
+
easing: theme.transitions.easing.sharp,
|
|
90
|
+
duration: theme.transitions.duration.enteringScreen
|
|
91
|
+
}),
|
|
92
|
+
overflowX: "hidden",
|
|
93
|
+
"& .MuiDrawer-paper": {
|
|
94
|
+
width: drawerWidth,
|
|
95
|
+
transition: theme.transitions.create("width", {
|
|
96
|
+
easing: theme.transitions.easing.sharp,
|
|
97
|
+
duration: theme.transitions.duration.enteringScreen
|
|
98
|
+
}),
|
|
99
|
+
overflowX: "hidden"
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const drawerSxClosed = {
|
|
103
|
+
flexShrink: 0,
|
|
104
|
+
whiteSpace: "nowrap",
|
|
105
|
+
boxSizing: "border-box",
|
|
106
|
+
transition: theme.transitions.create("width", {
|
|
107
|
+
easing: theme.transitions.easing.sharp,
|
|
108
|
+
duration: theme.transitions.duration.leavingScreen
|
|
109
|
+
}),
|
|
110
|
+
overflowX: "hidden",
|
|
111
|
+
width: "calc(".concat(theme.spacing(7), " + 1px)"),
|
|
112
|
+
[theme.breakpoints.up("sm")]: {
|
|
113
|
+
width: "calc(".concat(theme.spacing(8), " + 1px)")
|
|
114
|
+
},
|
|
115
|
+
"& .MuiDrawer-paper": {
|
|
116
|
+
transition: theme.transitions.create("width", {
|
|
117
|
+
easing: theme.transitions.easing.sharp,
|
|
118
|
+
duration: theme.transitions.duration.leavingScreen
|
|
119
|
+
}),
|
|
120
|
+
overflowX: "hidden",
|
|
121
|
+
width: "calc(".concat(theme.spacing(7), " + 1px)"),
|
|
122
|
+
[theme.breakpoints.up("sm")]: {
|
|
123
|
+
width: "calc(".concat(theme.spacing(8), " + 1px)")
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const [open, setOpen] = React__namespace.useState(false);
|
|
128
|
+
const handleDrawerOpen = () => {
|
|
129
|
+
setOpen(true);
|
|
130
|
+
};
|
|
131
|
+
const handleDrawerClose = () => {
|
|
132
|
+
setOpen(false);
|
|
133
|
+
};
|
|
134
|
+
return /*#__PURE__*/React__namespace.createElement(material.Box, {
|
|
135
|
+
sx: {
|
|
136
|
+
display: "flex",
|
|
137
|
+
...sx
|
|
138
|
+
}
|
|
139
|
+
}, /*#__PURE__*/React__namespace.createElement(material.CssBaseline, null), /*#__PURE__*/React__namespace.createElement(MuiAppBar, {
|
|
140
|
+
position: "fixed",
|
|
141
|
+
sx: [open && AppbarSxOpen, !open && AppbarSxClosed]
|
|
142
|
+
}, /*#__PURE__*/React__namespace.createElement(material.Toolbar, null, /*#__PURE__*/React__namespace.createElement(material.IconButton, {
|
|
143
|
+
color: "inherit",
|
|
144
|
+
"aria-label": "open drawer",
|
|
145
|
+
onClick: handleDrawerOpen,
|
|
146
|
+
edge: "start",
|
|
147
|
+
sx: {
|
|
148
|
+
marginRight: 5,
|
|
149
|
+
...(open && {
|
|
150
|
+
display: "none"
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
}, /*#__PURE__*/React__namespace.createElement(iconsMaterial.Menu, null)), /*#__PURE__*/React__namespace.createElement(Link, {
|
|
154
|
+
href: "/dashboard",
|
|
155
|
+
legacyBehavior: true
|
|
156
|
+
}, /*#__PURE__*/React__namespace.createElement(material.Typography, {
|
|
157
|
+
variant: "h6",
|
|
158
|
+
noWrap: true,
|
|
159
|
+
sx: {
|
|
160
|
+
cursor: "pointer"
|
|
161
|
+
}
|
|
162
|
+
}, title !== null && title !== void 0 ? title : "Dashboard")), /*#__PURE__*/React__namespace.createElement(material.Box, {
|
|
163
|
+
sx: {
|
|
164
|
+
position: "relative",
|
|
165
|
+
height: "40px",
|
|
166
|
+
flexGrow: 1
|
|
167
|
+
}
|
|
168
|
+
}, /*#__PURE__*/React__namespace.createElement(material.SpeedDial, {
|
|
169
|
+
ariaLabel: "...",
|
|
170
|
+
icon: /*#__PURE__*/React__namespace.createElement(iconsMaterial.AccountCircle, null),
|
|
171
|
+
direction: "down",
|
|
172
|
+
sx: {
|
|
173
|
+
position: "absolute",
|
|
174
|
+
top: 0,
|
|
175
|
+
right: 0,
|
|
176
|
+
width: 40,
|
|
177
|
+
"& .MuiFab-root": {
|
|
178
|
+
width: 40,
|
|
179
|
+
height: 40
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, actions.map((action, index) => /*#__PURE__*/React__namespace.createElement(material.SpeedDialAction, {
|
|
183
|
+
key: index,
|
|
184
|
+
icon: action.icon,
|
|
185
|
+
"aria-label": action.name,
|
|
186
|
+
tooltipTitle: action.name,
|
|
187
|
+
onClick: action.action
|
|
188
|
+
})))))), /*#__PURE__*/React__namespace.createElement(MuiDrawer, {
|
|
189
|
+
variant: "permanent",
|
|
190
|
+
open: open,
|
|
191
|
+
sx: [open && drawerSxOpen, !open && drawerSxClosed]
|
|
192
|
+
}, /*#__PURE__*/React__namespace.createElement(DrawerHeader, null, /*#__PURE__*/React__namespace.createElement(material.IconButton, {
|
|
193
|
+
onClick: handleDrawerClose
|
|
194
|
+
}, theme.direction === "rtl" ? /*#__PURE__*/React__namespace.createElement(iconsMaterial.ChevronRight, null) : /*#__PURE__*/React__namespace.createElement(iconsMaterial.ChevronLeft, null))), /*#__PURE__*/React__namespace.createElement(material.Divider, null), sections.map((section, index) => /*#__PURE__*/React__namespace.createElement(Link, {
|
|
195
|
+
key: index,
|
|
196
|
+
href: section.link,
|
|
197
|
+
passHref: true
|
|
198
|
+
}, /*#__PURE__*/React__namespace.createElement(material.Box, {
|
|
199
|
+
sx: {
|
|
200
|
+
display: "flex",
|
|
201
|
+
alignItems: "center",
|
|
202
|
+
justifyContent: "center",
|
|
203
|
+
p: 1,
|
|
204
|
+
cursor: "pointer"
|
|
205
|
+
}
|
|
206
|
+
}, section.icon, open && /*#__PURE__*/React__namespace.createElement(material.Typography, {
|
|
207
|
+
sx: {
|
|
208
|
+
pl: 2
|
|
209
|
+
}
|
|
210
|
+
}, section.title))))), /*#__PURE__*/React__namespace.createElement(material.Box, {
|
|
211
|
+
component: "main",
|
|
212
|
+
sx: {
|
|
213
|
+
flexGrow: 1,
|
|
214
|
+
p: 3,
|
|
215
|
+
minHeight: "100vh"
|
|
216
|
+
}
|
|
217
|
+
}, /*#__PURE__*/React__namespace.createElement(DrawerHeader, null), children));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
exports.default = Sidebar;
|
package/dist/cjs/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var ScrollNavbar = require('./components/ScrollNavbar.js');
|
|
|
21
21
|
var FluidBackgroundV2 = require('./components/FluidBackgroundV2.js');
|
|
22
22
|
var RegisterForm = require('./components/forms/RegisterForm.js');
|
|
23
23
|
var SigninForm = require('./components/forms/SigninForm.js');
|
|
24
|
+
var Sidebar = require('./components/dashboard/Sidebar.js');
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
|
|
@@ -39,3 +40,4 @@ exports.ScrollNavbar = ScrollNavbar.default;
|
|
|
39
40
|
exports.FluidBackground = FluidBackgroundV2.default;
|
|
40
41
|
exports.RegisterForm = RegisterForm.default;
|
|
41
42
|
exports.SigninForm = SigninForm.default;
|
|
43
|
+
exports.Sidebar = Sidebar.default;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import React__default from 'react';
|
|
7
8
|
import { Alert } from '@mui/material';
|
|
8
9
|
|
|
9
10
|
function StrapiErrors(_ref) {
|
|
@@ -11,7 +12,7 @@ function StrapiErrors(_ref) {
|
|
|
11
12
|
error
|
|
12
13
|
} = _ref;
|
|
13
14
|
if (!(error !== null && error !== void 0 && error.message)) return null;
|
|
14
|
-
return /*#__PURE__*/
|
|
15
|
+
return /*#__PURE__*/React__default.createElement(Alert, {
|
|
15
16
|
severity: "error"
|
|
16
17
|
}, error.message);
|
|
17
18
|
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* UMWD-Components
|
|
3
|
+
* @copyright Jelle Paulus
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import { useRouter } from 'next/router';
|
|
9
|
+
import Link from 'next/link';
|
|
10
|
+
import { styled, useTheme, Box, CssBaseline, Toolbar, IconButton, Typography, SpeedDial, SpeedDialAction, Divider } from '@mui/material';
|
|
11
|
+
import MuiDrawer from '@mui/material/Drawer';
|
|
12
|
+
import MuiAppBar from '@mui/material/AppBar';
|
|
13
|
+
import { Menu, AccountCircle, ChevronRight, ChevronLeft } from '@mui/icons-material';
|
|
14
|
+
|
|
15
|
+
const drawerWidth = 290;
|
|
16
|
+
const DrawerHeader = styled("div")(_ref => {
|
|
17
|
+
let {
|
|
18
|
+
theme
|
|
19
|
+
} = _ref;
|
|
20
|
+
return {
|
|
21
|
+
display: "flex",
|
|
22
|
+
alignItems: "center",
|
|
23
|
+
justifyContent: "flex-end",
|
|
24
|
+
padding: theme.spacing(0, 1),
|
|
25
|
+
// necessary for content to be below app bar
|
|
26
|
+
...theme.mixins.toolbar
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
function Sidebar(_ref2) {
|
|
30
|
+
let {
|
|
31
|
+
children,
|
|
32
|
+
data
|
|
33
|
+
} = _ref2;
|
|
34
|
+
const {
|
|
35
|
+
sections = [],
|
|
36
|
+
actions = [],
|
|
37
|
+
sx = {},
|
|
38
|
+
title
|
|
39
|
+
} = data;
|
|
40
|
+
console.log("sections", sections);
|
|
41
|
+
console.log("actions", actions);
|
|
42
|
+
useRouter();
|
|
43
|
+
const theme = useTheme();
|
|
44
|
+
const AppbarSxOpen = {
|
|
45
|
+
zIndex: theme.zIndex.drawer + 1,
|
|
46
|
+
marginLeft: drawerWidth,
|
|
47
|
+
width: "calc(100% - ".concat(drawerWidth, "px)"),
|
|
48
|
+
transition: theme.transitions.create(["width", "margin"], {
|
|
49
|
+
easing: theme.transitions.easing.sharp,
|
|
50
|
+
duration: theme.transitions.duration.enteringScreen
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
const AppbarSxClosed = {
|
|
54
|
+
zIndex: theme.zIndex.drawer + 1,
|
|
55
|
+
transition: theme.transitions.create(["width", "margin"], {
|
|
56
|
+
easing: theme.transitions.easing.sharp,
|
|
57
|
+
duration: theme.transitions.duration.leavingScreen
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
const drawerSxOpen = {
|
|
61
|
+
width: drawerWidth,
|
|
62
|
+
flexShrink: 0,
|
|
63
|
+
whiteSpace: "nowrap",
|
|
64
|
+
boxSizing: "border-box",
|
|
65
|
+
transition: theme.transitions.create("width", {
|
|
66
|
+
easing: theme.transitions.easing.sharp,
|
|
67
|
+
duration: theme.transitions.duration.enteringScreen
|
|
68
|
+
}),
|
|
69
|
+
overflowX: "hidden",
|
|
70
|
+
"& .MuiDrawer-paper": {
|
|
71
|
+
width: drawerWidth,
|
|
72
|
+
transition: theme.transitions.create("width", {
|
|
73
|
+
easing: theme.transitions.easing.sharp,
|
|
74
|
+
duration: theme.transitions.duration.enteringScreen
|
|
75
|
+
}),
|
|
76
|
+
overflowX: "hidden"
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const drawerSxClosed = {
|
|
80
|
+
flexShrink: 0,
|
|
81
|
+
whiteSpace: "nowrap",
|
|
82
|
+
boxSizing: "border-box",
|
|
83
|
+
transition: theme.transitions.create("width", {
|
|
84
|
+
easing: theme.transitions.easing.sharp,
|
|
85
|
+
duration: theme.transitions.duration.leavingScreen
|
|
86
|
+
}),
|
|
87
|
+
overflowX: "hidden",
|
|
88
|
+
width: "calc(".concat(theme.spacing(7), " + 1px)"),
|
|
89
|
+
[theme.breakpoints.up("sm")]: {
|
|
90
|
+
width: "calc(".concat(theme.spacing(8), " + 1px)")
|
|
91
|
+
},
|
|
92
|
+
"& .MuiDrawer-paper": {
|
|
93
|
+
transition: theme.transitions.create("width", {
|
|
94
|
+
easing: theme.transitions.easing.sharp,
|
|
95
|
+
duration: theme.transitions.duration.leavingScreen
|
|
96
|
+
}),
|
|
97
|
+
overflowX: "hidden",
|
|
98
|
+
width: "calc(".concat(theme.spacing(7), " + 1px)"),
|
|
99
|
+
[theme.breakpoints.up("sm")]: {
|
|
100
|
+
width: "calc(".concat(theme.spacing(8), " + 1px)")
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const [open, setOpen] = React.useState(false);
|
|
105
|
+
const handleDrawerOpen = () => {
|
|
106
|
+
setOpen(true);
|
|
107
|
+
};
|
|
108
|
+
const handleDrawerClose = () => {
|
|
109
|
+
setOpen(false);
|
|
110
|
+
};
|
|
111
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
112
|
+
sx: {
|
|
113
|
+
display: "flex",
|
|
114
|
+
...sx
|
|
115
|
+
}
|
|
116
|
+
}, /*#__PURE__*/React.createElement(CssBaseline, null), /*#__PURE__*/React.createElement(MuiAppBar, {
|
|
117
|
+
position: "fixed",
|
|
118
|
+
sx: [open && AppbarSxOpen, !open && AppbarSxClosed]
|
|
119
|
+
}, /*#__PURE__*/React.createElement(Toolbar, null, /*#__PURE__*/React.createElement(IconButton, {
|
|
120
|
+
color: "inherit",
|
|
121
|
+
"aria-label": "open drawer",
|
|
122
|
+
onClick: handleDrawerOpen,
|
|
123
|
+
edge: "start",
|
|
124
|
+
sx: {
|
|
125
|
+
marginRight: 5,
|
|
126
|
+
...(open && {
|
|
127
|
+
display: "none"
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
}, /*#__PURE__*/React.createElement(Menu, null)), /*#__PURE__*/React.createElement(Link, {
|
|
131
|
+
href: "/dashboard",
|
|
132
|
+
legacyBehavior: true
|
|
133
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
134
|
+
variant: "h6",
|
|
135
|
+
noWrap: true,
|
|
136
|
+
sx: {
|
|
137
|
+
cursor: "pointer"
|
|
138
|
+
}
|
|
139
|
+
}, title !== null && title !== void 0 ? title : "Dashboard")), /*#__PURE__*/React.createElement(Box, {
|
|
140
|
+
sx: {
|
|
141
|
+
position: "relative",
|
|
142
|
+
height: "40px",
|
|
143
|
+
flexGrow: 1
|
|
144
|
+
}
|
|
145
|
+
}, /*#__PURE__*/React.createElement(SpeedDial, {
|
|
146
|
+
ariaLabel: "...",
|
|
147
|
+
icon: /*#__PURE__*/React.createElement(AccountCircle, null),
|
|
148
|
+
direction: "down",
|
|
149
|
+
sx: {
|
|
150
|
+
position: "absolute",
|
|
151
|
+
top: 0,
|
|
152
|
+
right: 0,
|
|
153
|
+
width: 40,
|
|
154
|
+
"& .MuiFab-root": {
|
|
155
|
+
width: 40,
|
|
156
|
+
height: 40
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}, actions.map((action, index) => /*#__PURE__*/React.createElement(SpeedDialAction, {
|
|
160
|
+
key: index,
|
|
161
|
+
icon: action.icon,
|
|
162
|
+
"aria-label": action.name,
|
|
163
|
+
tooltipTitle: action.name,
|
|
164
|
+
onClick: action.action
|
|
165
|
+
})))))), /*#__PURE__*/React.createElement(MuiDrawer, {
|
|
166
|
+
variant: "permanent",
|
|
167
|
+
open: open,
|
|
168
|
+
sx: [open && drawerSxOpen, !open && drawerSxClosed]
|
|
169
|
+
}, /*#__PURE__*/React.createElement(DrawerHeader, null, /*#__PURE__*/React.createElement(IconButton, {
|
|
170
|
+
onClick: handleDrawerClose
|
|
171
|
+
}, theme.direction === "rtl" ? /*#__PURE__*/React.createElement(ChevronRight, null) : /*#__PURE__*/React.createElement(ChevronLeft, null))), /*#__PURE__*/React.createElement(Divider, null), sections.map((section, index) => /*#__PURE__*/React.createElement(Link, {
|
|
172
|
+
key: index,
|
|
173
|
+
href: section.link,
|
|
174
|
+
passHref: true
|
|
175
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
176
|
+
sx: {
|
|
177
|
+
display: "flex",
|
|
178
|
+
alignItems: "center",
|
|
179
|
+
justifyContent: "center",
|
|
180
|
+
p: 1,
|
|
181
|
+
cursor: "pointer"
|
|
182
|
+
}
|
|
183
|
+
}, section.icon, open && /*#__PURE__*/React.createElement(Typography, {
|
|
184
|
+
sx: {
|
|
185
|
+
pl: 2
|
|
186
|
+
}
|
|
187
|
+
}, section.title))))), /*#__PURE__*/React.createElement(Box, {
|
|
188
|
+
component: "main",
|
|
189
|
+
sx: {
|
|
190
|
+
flexGrow: 1,
|
|
191
|
+
p: 3,
|
|
192
|
+
minHeight: "100vh"
|
|
193
|
+
}
|
|
194
|
+
}, /*#__PURE__*/React.createElement(DrawerHeader, null), children));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { Sidebar as default };
|
package/dist/esm/index.js
CHANGED
|
@@ -19,3 +19,4 @@ export { default as ScrollNavbar } from './components/ScrollNavbar.js';
|
|
|
19
19
|
export { default as FluidBackground } from './components/FluidBackgroundV2.js';
|
|
20
20
|
export { default as RegisterForm } from './components/forms/RegisterForm.js';
|
|
21
21
|
export { default as SigninForm } from './components/forms/SigninForm.js';
|
|
22
|
+
export { default as Sidebar } from './components/dashboard/Sidebar.js';
|
package/package.json
CHANGED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useRouter } from "next/router";
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import {
|
|
5
|
+
styled,
|
|
6
|
+
useTheme,
|
|
7
|
+
Box,
|
|
8
|
+
Divider,
|
|
9
|
+
CssBaseline,
|
|
10
|
+
Typography,
|
|
11
|
+
Toolbar,
|
|
12
|
+
IconButton,
|
|
13
|
+
SpeedDial,
|
|
14
|
+
SpeedDialAction,
|
|
15
|
+
} from "@mui/material";
|
|
16
|
+
import MuiDrawer from "@mui/material/Drawer";
|
|
17
|
+
import MuiAppBar from "@mui/material/AppBar";
|
|
18
|
+
import {
|
|
19
|
+
Menu as MenuIcon,
|
|
20
|
+
ChevronLeft as ChevronLeftIcon,
|
|
21
|
+
ChevronRight as ChevronRightIcon,
|
|
22
|
+
AccountCircle as AccountCircleIcon,
|
|
23
|
+
Dashboard as DashboardIcon,
|
|
24
|
+
Login as LoginIcon,
|
|
25
|
+
Logout as LogoutIcon,
|
|
26
|
+
PeopleAlt as PeopleAltIcon,
|
|
27
|
+
RocketLaunch as RocketLaunchIcon,
|
|
28
|
+
} from "@mui/icons-material";
|
|
29
|
+
import { type Theme } from "@mui/material";
|
|
30
|
+
import { SxProps } from "@mui/system";
|
|
31
|
+
|
|
32
|
+
const drawerWidth = 290;
|
|
33
|
+
|
|
34
|
+
const DrawerHeader = styled("div")(({ theme }) => ({
|
|
35
|
+
display: "flex",
|
|
36
|
+
alignItems: "center",
|
|
37
|
+
justifyContent: "flex-end",
|
|
38
|
+
padding: theme.spacing(0, 1),
|
|
39
|
+
// necessary for content to be below app bar
|
|
40
|
+
...theme.mixins.toolbar,
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
interface SidebarProps {
|
|
44
|
+
title: string;
|
|
45
|
+
sections: Array<{
|
|
46
|
+
title: string;
|
|
47
|
+
icon: React.ReactNode;
|
|
48
|
+
link: string;
|
|
49
|
+
}>;
|
|
50
|
+
actions: Array<{
|
|
51
|
+
icon: React.ReactNode;
|
|
52
|
+
name: string;
|
|
53
|
+
action: () => void;
|
|
54
|
+
}>;
|
|
55
|
+
sx?: SxProps<Theme>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function Sidebar({
|
|
59
|
+
children,
|
|
60
|
+
data,
|
|
61
|
+
}: Readonly<{
|
|
62
|
+
data: SidebarProps;
|
|
63
|
+
children: React.ReactNode;
|
|
64
|
+
}>): React.JSX.Element {
|
|
65
|
+
const { sections = [], actions = [], sx = {}, title } = data;
|
|
66
|
+
|
|
67
|
+
console.log("sections", sections);
|
|
68
|
+
console.log("actions", actions);
|
|
69
|
+
|
|
70
|
+
const router = useRouter();
|
|
71
|
+
|
|
72
|
+
const theme = useTheme();
|
|
73
|
+
|
|
74
|
+
const AppbarSxOpen = {
|
|
75
|
+
zIndex: theme.zIndex.drawer + 1,
|
|
76
|
+
marginLeft: drawerWidth,
|
|
77
|
+
width: `calc(100% - ${drawerWidth}px)`,
|
|
78
|
+
transition: theme.transitions.create(["width", "margin"], {
|
|
79
|
+
easing: theme.transitions.easing.sharp,
|
|
80
|
+
duration: theme.transitions.duration.enteringScreen,
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const AppbarSxClosed = {
|
|
85
|
+
zIndex: theme.zIndex.drawer + 1,
|
|
86
|
+
transition: theme.transitions.create(["width", "margin"], {
|
|
87
|
+
easing: theme.transitions.easing.sharp,
|
|
88
|
+
duration: theme.transitions.duration.leavingScreen,
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const drawerSxOpen = {
|
|
93
|
+
width: drawerWidth,
|
|
94
|
+
flexShrink: 0,
|
|
95
|
+
whiteSpace: "nowrap",
|
|
96
|
+
boxSizing: "border-box",
|
|
97
|
+
transition: theme.transitions.create("width", {
|
|
98
|
+
easing: theme.transitions.easing.sharp,
|
|
99
|
+
duration: theme.transitions.duration.enteringScreen,
|
|
100
|
+
}),
|
|
101
|
+
overflowX: "hidden",
|
|
102
|
+
"& .MuiDrawer-paper": {
|
|
103
|
+
width: drawerWidth,
|
|
104
|
+
transition: theme.transitions.create("width", {
|
|
105
|
+
easing: theme.transitions.easing.sharp,
|
|
106
|
+
duration: theme.transitions.duration.enteringScreen,
|
|
107
|
+
}),
|
|
108
|
+
overflowX: "hidden",
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const drawerSxClosed = {
|
|
113
|
+
flexShrink: 0,
|
|
114
|
+
whiteSpace: "nowrap",
|
|
115
|
+
boxSizing: "border-box",
|
|
116
|
+
transition: theme.transitions.create("width", {
|
|
117
|
+
easing: theme.transitions.easing.sharp,
|
|
118
|
+
duration: theme.transitions.duration.leavingScreen,
|
|
119
|
+
}),
|
|
120
|
+
overflowX: "hidden",
|
|
121
|
+
width: `calc(${theme.spacing(7)} + 1px)`,
|
|
122
|
+
[theme.breakpoints.up("sm")]: {
|
|
123
|
+
width: `calc(${theme.spacing(8)} + 1px)`,
|
|
124
|
+
},
|
|
125
|
+
"& .MuiDrawer-paper": {
|
|
126
|
+
transition: theme.transitions.create("width", {
|
|
127
|
+
easing: theme.transitions.easing.sharp,
|
|
128
|
+
duration: theme.transitions.duration.leavingScreen,
|
|
129
|
+
}),
|
|
130
|
+
overflowX: "hidden",
|
|
131
|
+
width: `calc(${theme.spacing(7)} + 1px)`,
|
|
132
|
+
[theme.breakpoints.up("sm")]: {
|
|
133
|
+
width: `calc(${theme.spacing(8)} + 1px)`,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const [open, setOpen] = React.useState(false);
|
|
139
|
+
|
|
140
|
+
const handleDrawerOpen = () => {
|
|
141
|
+
setOpen(true);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const handleDrawerClose = () => {
|
|
145
|
+
setOpen(false);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<Box sx={{ display: "flex", ...sx }}>
|
|
150
|
+
<CssBaseline />
|
|
151
|
+
|
|
152
|
+
<MuiAppBar
|
|
153
|
+
position="fixed"
|
|
154
|
+
sx={[open && AppbarSxOpen, !open && AppbarSxClosed]}
|
|
155
|
+
>
|
|
156
|
+
<Toolbar>
|
|
157
|
+
<IconButton
|
|
158
|
+
color="inherit"
|
|
159
|
+
aria-label="open drawer"
|
|
160
|
+
onClick={handleDrawerOpen}
|
|
161
|
+
edge="start"
|
|
162
|
+
sx={{
|
|
163
|
+
marginRight: 5,
|
|
164
|
+
...(open && { display: "none" }),
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
<MenuIcon />
|
|
168
|
+
</IconButton>
|
|
169
|
+
<Link href="/dashboard" legacyBehavior>
|
|
170
|
+
<Typography variant="h6" noWrap sx={{ cursor: "pointer" }}>
|
|
171
|
+
{title ?? "Dashboard"}
|
|
172
|
+
</Typography>
|
|
173
|
+
</Link>
|
|
174
|
+
<Box
|
|
175
|
+
sx={{
|
|
176
|
+
position: "relative",
|
|
177
|
+
height: "40px",
|
|
178
|
+
flexGrow: 1,
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<SpeedDial
|
|
182
|
+
ariaLabel="..."
|
|
183
|
+
icon={<AccountCircleIcon />}
|
|
184
|
+
direction="down"
|
|
185
|
+
sx={{
|
|
186
|
+
position: "absolute",
|
|
187
|
+
top: 0,
|
|
188
|
+
right: 0,
|
|
189
|
+
width: 40,
|
|
190
|
+
"& .MuiFab-root": { width: 40, height: 40 },
|
|
191
|
+
}}
|
|
192
|
+
>
|
|
193
|
+
{actions.map((action, index) => (
|
|
194
|
+
<SpeedDialAction
|
|
195
|
+
key={index}
|
|
196
|
+
icon={action.icon}
|
|
197
|
+
aria-label={action.name}
|
|
198
|
+
tooltipTitle={action.name}
|
|
199
|
+
onClick={action.action}
|
|
200
|
+
/>
|
|
201
|
+
))}
|
|
202
|
+
</SpeedDial>
|
|
203
|
+
</Box>
|
|
204
|
+
</Toolbar>
|
|
205
|
+
</MuiAppBar>
|
|
206
|
+
|
|
207
|
+
<MuiDrawer
|
|
208
|
+
variant="permanent"
|
|
209
|
+
open={open}
|
|
210
|
+
sx={[open && drawerSxOpen, !open && drawerSxClosed]}
|
|
211
|
+
>
|
|
212
|
+
<DrawerHeader>
|
|
213
|
+
<IconButton onClick={handleDrawerClose}>
|
|
214
|
+
{theme.direction === "rtl" ? (
|
|
215
|
+
<ChevronRightIcon />
|
|
216
|
+
) : (
|
|
217
|
+
<ChevronLeftIcon />
|
|
218
|
+
)}
|
|
219
|
+
</IconButton>
|
|
220
|
+
</DrawerHeader>
|
|
221
|
+
<Divider />
|
|
222
|
+
{sections.map((section, index) => (
|
|
223
|
+
<Link key={index} href={section.link} passHref>
|
|
224
|
+
<Box
|
|
225
|
+
sx={{
|
|
226
|
+
display: "flex",
|
|
227
|
+
alignItems: "center",
|
|
228
|
+
justifyContent: "center",
|
|
229
|
+
p: 1,
|
|
230
|
+
cursor: "pointer",
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
{section.icon}
|
|
234
|
+
{open && <Typography sx={{ pl: 2 }}>{section.title}</Typography>}
|
|
235
|
+
</Box>
|
|
236
|
+
</Link>
|
|
237
|
+
))}
|
|
238
|
+
</MuiDrawer>
|
|
239
|
+
|
|
240
|
+
<Box component="main" sx={{ flexGrow: 1, p: 3, minHeight: "100vh" }}>
|
|
241
|
+
<DrawerHeader />
|
|
242
|
+
{children}
|
|
243
|
+
</Box>
|
|
244
|
+
</Box>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export default Sidebar;
|
package/src/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { default as ScrollNavbar } from "./components/ScrollNavbar.tsx";
|
|
|
13
13
|
export { default as FluidBackground } from "./components/FluidBackgroundV2.tsx";
|
|
14
14
|
export { default as RegisterForm } from "./components/forms/RegisterForm.tsx";
|
|
15
15
|
export { default as SigninForm } from "./components/forms/SigninForm.tsx";
|
|
16
|
+
export { default as Sidebar } from "./components/dashboard/Sidebar.tsx";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Sidebar from "../components/dashboard/Sidebar.tsx";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import AccountBoxIcon from "@mui/icons-material/AccountBox";
|
|
4
|
+
import DashboardIcon from "@mui/icons-material/Dashboard";
|
|
5
|
+
import RocketLaunchIcon from "@mui/icons-material/RocketLaunch";
|
|
6
|
+
import LogoutIcon from "@mui/icons-material/Logout";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: "UMWD/Sidebar",
|
|
10
|
+
component: Sidebar,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const Template = ({ ...args }) => (
|
|
14
|
+
<Sidebar data={{ ...args }}>
|
|
15
|
+
<h1>Children</h1>
|
|
16
|
+
</Sidebar>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const HelloWorld = Template.bind({});
|
|
20
|
+
|
|
21
|
+
HelloWorld.args = {
|
|
22
|
+
title: "Admin Panel",
|
|
23
|
+
actions: [
|
|
24
|
+
{
|
|
25
|
+
icon: <LogoutIcon />,
|
|
26
|
+
name: "Log-Out",
|
|
27
|
+
action: () => console.log("Log-Out"),
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
sections: [
|
|
31
|
+
{
|
|
32
|
+
title: "My Account",
|
|
33
|
+
icon: <AccountBoxIcon />,
|
|
34
|
+
link: "/account",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|