layout.js
4.07 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _extends from "@babel/runtime/helpers/extends";
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
import * as React from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider';
export var LayoutContext = /*#__PURE__*/React.createContext({
siderHook: {
addSider: function addSider() {
return null;
},
removeSider: function removeSider() {
return null;
}
}
});
function generator(_ref) {
var suffixCls = _ref.suffixCls,
tagName = _ref.tagName,
displayName = _ref.displayName;
return function (BasicComponent) {
var Adapter = function Adapter(props) {
var _React$useContext = React.useContext(ConfigContext),
getPrefixCls = _React$useContext.getPrefixCls;
var customizePrefixCls = props.prefixCls;
var prefixCls = getPrefixCls(suffixCls, customizePrefixCls);
return /*#__PURE__*/React.createElement(BasicComponent, _extends({
prefixCls: prefixCls,
tagName: tagName
}, props));
};
Adapter.displayName = displayName;
return Adapter;
};
}
var Basic = function Basic(props) {
var prefixCls = props.prefixCls,
className = props.className,
children = props.children,
tagName = props.tagName,
others = __rest(props, ["prefixCls", "className", "children", "tagName"]);
var classString = classNames(prefixCls, className);
return /*#__PURE__*/React.createElement(tagName, _extends({
className: classString
}, others), children);
};
var BasicLayout = function BasicLayout(props) {
var _classNames;
var _React$useContext2 = React.useContext(ConfigContext),
direction = _React$useContext2.direction;
var _React$useState = React.useState([]),
_React$useState2 = _slicedToArray(_React$useState, 2),
siders = _React$useState2[0],
setSiders = _React$useState2[1];
var prefixCls = props.prefixCls,
className = props.className,
children = props.children,
hasSider = props.hasSider,
Tag = props.tagName,
others = __rest(props, ["prefixCls", "className", "children", "hasSider", "tagName"]);
var classString = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-has-sider"), typeof hasSider === 'boolean' ? hasSider : siders.length > 0), _defineProperty(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _classNames), className);
return /*#__PURE__*/React.createElement(LayoutContext.Provider, {
value: {
siderHook: {
addSider: function addSider(id) {
setSiders(function (prev) {
return [].concat(_toConsumableArray(prev), [id]);
});
},
removeSider: function removeSider(id) {
setSiders(function (prev) {
return prev.filter(function (currentId) {
return currentId !== id;
});
});
}
}
}
}, /*#__PURE__*/React.createElement(Tag, _extends({
className: classString
}, others), children));
};
var Layout = generator({
suffixCls: 'layout',
tagName: 'section',
displayName: 'Layout'
})(BasicLayout);
var Header = generator({
suffixCls: 'layout-header',
tagName: 'header',
displayName: 'Header'
})(Basic);
var Footer = generator({
suffixCls: 'layout-footer',
tagName: 'footer',
displayName: 'Footer'
})(Basic);
var Content = generator({
suffixCls: 'layout-content',
tagName: 'main',
displayName: 'Content'
})(Basic);
export { Header, Footer, Content };
export default Layout;