layout.js
4.88 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.Content = exports.Footer = exports.Header = exports.LayoutContext = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _configProvider = require("../config-provider");
var __rest = void 0 && (void 0).__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;
};
var LayoutContext = /*#__PURE__*/React.createContext({
siderHook: {
addSider: function addSider() {
return null;
},
removeSider: function removeSider() {
return null;
}
}
});
exports.LayoutContext = LayoutContext;
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(_configProvider.ConfigContext),
getPrefixCls = _React$useContext.getPrefixCls;
var customizePrefixCls = props.prefixCls;
var prefixCls = getPrefixCls(suffixCls, customizePrefixCls);
return /*#__PURE__*/React.createElement(BasicComponent, (0, _extends2["default"])({
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 = (0, _classnames["default"])(prefixCls, className);
return /*#__PURE__*/React.createElement(tagName, (0, _extends2["default"])({
className: classString
}, others), children);
};
var BasicLayout = function BasicLayout(props) {
var _classNames;
var _React$useContext2 = React.useContext(_configProvider.ConfigContext),
direction = _React$useContext2.direction;
var _React$useState = React.useState([]),
_React$useState2 = (0, _slicedToArray2["default"])(_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 = (0, _classnames["default"])(prefixCls, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-has-sider"), typeof hasSider === 'boolean' ? hasSider : siders.length > 0), (0, _defineProperty2["default"])(_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((0, _toConsumableArray2["default"])(prev), [id]);
});
},
removeSider: function removeSider(id) {
setSiders(function (prev) {
return prev.filter(function (currentId) {
return currentId !== id;
});
});
}
}
}
}, /*#__PURE__*/React.createElement(Tag, (0, _extends2["default"])({
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);
exports.Header = Header;
var Footer = generator({
suffixCls: 'layout-footer',
tagName: 'footer',
displayName: 'Footer'
})(Basic);
exports.Footer = Footer;
var Content = generator({
suffixCls: 'layout-content',
tagName: 'main',
displayName: 'Content'
})(Basic);
exports.Content = Content;
var _default = Layout;
exports["default"] = _default;