@hzab/sider 0.0.2 → 0.1.0
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/CHANGELOG.md +7 -0
- package/README.md +58 -5
- package/lib/index.js +1 -1
- package/package.json +6 -5
- package/src/index.module.less +34 -19
- package/src/index.tsx +28 -13
- package/CHANGELOG +0 -2
- package/lib/css/main.92f5a23dbd5c9e3ccf8f.css +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzab/sider",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "侧边栏",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"publish-major": "npm run build && git add . && git commit -m \"build: major\" && npm version major && npm publish --access public"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
+
"CHANGELOG.md",
|
|
14
15
|
"lib",
|
|
15
16
|
"src"
|
|
16
17
|
],
|
|
@@ -18,14 +19,14 @@
|
|
|
18
19
|
"author": "CaiYansong",
|
|
19
20
|
"license": "ISC",
|
|
20
21
|
"devDependencies": {
|
|
21
|
-
"@hzab/webpack-config": "0.
|
|
22
|
+
"@hzab/webpack-config": "0.1.1",
|
|
22
23
|
"@types/react": "^18.0.26",
|
|
23
24
|
"@types/react-dom": "^18.0.9",
|
|
24
25
|
"eslint": "^8.30.0",
|
|
25
26
|
"less": "^4.1.3",
|
|
26
|
-
"react": "^
|
|
27
|
-
"react-dom": "^
|
|
28
|
-
"react-router-dom": "^6.
|
|
27
|
+
"react": "^17.0.2",
|
|
28
|
+
"react-dom": "^17.0.2",
|
|
29
|
+
"react-router-dom": "^6.14.1",
|
|
29
30
|
"typescript": "^4.9.4"
|
|
30
31
|
},
|
|
31
32
|
"directories": {
|
package/src/index.module.less
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
|
-
.sider
|
|
1
|
+
.layout-sider {
|
|
2
|
+
position: relative;
|
|
3
|
+
background-color: transparent;
|
|
2
4
|
height: 100%;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
.sider-box {
|
|
6
|
+
height: 100%;
|
|
7
|
+
overflow-x: hidden;
|
|
8
|
+
overflow-y: auto;
|
|
9
|
+
/* 滚动条整体样式 */
|
|
10
|
+
&::-webkit-scrollbar {
|
|
11
|
+
width: 4px;
|
|
12
|
+
height: 4px;
|
|
13
|
+
}
|
|
14
|
+
/* 滚动条轨道 */
|
|
15
|
+
&::-webkit-scrollbar-track {
|
|
16
|
+
background: rgb(239, 239, 239);
|
|
17
|
+
}
|
|
18
|
+
/* 滚动条里面的滑块 */
|
|
19
|
+
&::-webkit-scrollbar-thumb {
|
|
20
|
+
background: rgba(144, 147, 153, 0.3);
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
}
|
|
23
|
+
/* 滚动条里面的滑块 hover 的情况 */
|
|
24
|
+
&::-webkit-scrollbar-thumb:hover {
|
|
25
|
+
background: rgba(144, 147, 153, 0.5);
|
|
26
|
+
}
|
|
9
27
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/* 滚动条里面的滑块 hover 的情况 */
|
|
20
|
-
&::-webkit-scrollbar-thumb:hover {
|
|
21
|
-
background: rgba(144, 147, 153, 0.5);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
:global {
|
|
31
|
+
.layout-sider {
|
|
32
|
+
.ant-layout-sider-zero-width-trigger {
|
|
33
|
+
background-color: #fff;
|
|
34
|
+
color: #333;
|
|
35
|
+
border: 1px solid #f0f0f0;
|
|
36
|
+
}
|
|
22
37
|
}
|
|
23
38
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { useNavigate, useLocation } from "react-router-dom";
|
|
3
|
-
import { Menu } from "antd";
|
|
3
|
+
import { Layout, Menu } from "antd";
|
|
4
4
|
import * as Icon from "@ant-design/icons";
|
|
5
5
|
import _ from "lodash";
|
|
6
6
|
|
|
7
7
|
import style from "./index.module.less";
|
|
8
8
|
|
|
9
|
+
const { Sider: ASider } = Layout;
|
|
10
|
+
|
|
9
11
|
function Sider(props) {
|
|
12
|
+
const { collapsible, collapsedWidth } = props;
|
|
10
13
|
const navigate = useNavigate();
|
|
11
14
|
const location = useLocation();
|
|
15
|
+
|
|
16
|
+
const [isFloat, setIsFloat] = useState(false);
|
|
17
|
+
const [collapsed, setCollapsed] = useState(false);
|
|
12
18
|
const [selected, setSelected] = useState([location.pathname]);
|
|
13
19
|
const [open, setOpen] = useState(location.pathname.split(/(?=\/)/)?.slice(0, 1));
|
|
14
|
-
const [menus, setMenus] = useState(props.menus || []);
|
|
20
|
+
const [menus, setMenus] = useState(_.cloneDeep(props.menus) || []);
|
|
15
21
|
|
|
16
22
|
useEffect(() => {
|
|
17
23
|
const keyPaths: Array<string> = location.pathname.split(/(?=\/)/);
|
|
@@ -42,7 +48,7 @@ function Sider(props) {
|
|
|
42
48
|
iconDom = React.createElement(Icon && (Icon as any)[iconDom], {
|
|
43
49
|
style: { fontSize: "14px" },
|
|
44
50
|
});
|
|
45
|
-
} else if (iconDom?.startsWith("icon-")) {
|
|
51
|
+
} else if (iconDom?.startsWith && iconDom?.startsWith("icon-")) {
|
|
46
52
|
iconDom = <i className={"sider-icon icon-iconfont " + iconDom}></i>;
|
|
47
53
|
}
|
|
48
54
|
it.icon = iconDom;
|
|
@@ -66,16 +72,25 @@ function Sider(props) {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
return (
|
|
69
|
-
<
|
|
70
|
-
className={`sider
|
|
71
|
-
style={{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
<ASider
|
|
76
|
+
className={`layout-sider ${style["layout-sider"]} ${props.layoutSiderClassName || ""}`}
|
|
77
|
+
style={{ ...(props.siderStyle || {}) }}
|
|
78
|
+
collapsedWidth={collapsedWidth}
|
|
79
|
+
collapsible={collapsible}
|
|
80
|
+
collapsed={collapsed}
|
|
81
|
+
onCollapse={setCollapsed}
|
|
82
|
+
>
|
|
83
|
+
<Menu
|
|
84
|
+
className={`sider-box ${style["sider-box"]} ${props.className || ""}`}
|
|
85
|
+
style={{ ...(props.style || {}) }}
|
|
86
|
+
onClick={onClick}
|
|
87
|
+
onOpenChange={onOpenChange}
|
|
88
|
+
selectedKeys={selected}
|
|
89
|
+
openKeys={open}
|
|
90
|
+
mode="inline"
|
|
91
|
+
items={menus}
|
|
92
|
+
/>
|
|
93
|
+
</ASider>
|
|
79
94
|
);
|
|
80
95
|
}
|
|
81
96
|
|
package/CHANGELOG
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.sider-box_V6sF9{height:100%;overflow-x:hidden;overflow-y:auto}.sider-box_V6sF9::-webkit-scrollbar{height:4px;width:4px}.sider-box_V6sF9::-webkit-scrollbar-track{background:#efefef}.sider-box_V6sF9::-webkit-scrollbar-thumb{background:hsla(220,4%,58%,.3);border-radius:4px}.sider-box_V6sF9::-webkit-scrollbar-thumb:hover{background:hsla(220,4%,58%,.5)}
|