1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = undefined;
|
7 |
|
8 | var _class, _temp, _initialiseProps;
|
9 |
|
10 |
|
11 | var _react = require('react');
|
12 |
|
13 | var _react2 = _interopRequireDefault(_react);
|
14 |
|
15 | var _classnames = require('classnames');
|
16 |
|
17 | var _classnames2 = _interopRequireDefault(_classnames);
|
18 |
|
19 | var _layout = require('@icedesign/layout');
|
20 |
|
21 | var _layout2 = _interopRequireDefault(_layout);
|
22 |
|
23 | var _menu = require('@icedesign/menu');
|
24 |
|
25 | var _menu2 = _interopRequireDefault(_menu);
|
26 |
|
27 | var _reactRouter = require('react-router');
|
28 |
|
29 | var _foundationSymbol = require('foundation-symbol');
|
30 |
|
31 | var _foundationSymbol2 = _interopRequireDefault(_foundationSymbol);
|
32 |
|
33 | var _reactContainerQuery = require('react-container-query');
|
34 |
|
35 | var _enquireJs = require('enquire-js');
|
36 |
|
37 | var _Header = require('./Header');
|
38 |
|
39 | var _Header2 = _interopRequireDefault(_Header);
|
40 |
|
41 | var _Footer = require('./Footer');
|
42 |
|
43 | var _Footer2 = _interopRequireDefault(_Footer);
|
44 |
|
45 | var _Logo = require('./Logo');
|
46 |
|
47 | var _Logo2 = _interopRequireDefault(_Logo);
|
48 |
|
49 | var _navs = require('./navs');
|
50 |
|
51 | require('./scss/light.scss');
|
52 |
|
53 | require('./scss/dark.scss');
|
54 |
|
55 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
56 |
|
57 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
58 |
|
59 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
60 |
|
61 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
62 |
|
63 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
|
64 |
|
65 | var Icon = require('@icedesign/base/lib/icon');
|
66 |
|
67 | var theme = typeof THEME === 'undefined' ? 'dark' : THEME;
|
68 |
|
69 | var query = {
|
70 | 'screen-xs': {
|
71 | maxWidth: 720
|
72 | },
|
73 | 'screen-sm': {
|
74 | minWidth: 721,
|
75 | maxWidth: 1199
|
76 | },
|
77 | 'screen-xl': {
|
78 | minWidth: 1200
|
79 | }
|
80 | };
|
81 |
|
82 | var HeaderAsideFooterResponsiveLayout = (_temp = _class = function (_Component) {
|
83 | _inherits(HeaderAsideFooterResponsiveLayout, _Component);
|
84 |
|
85 | function HeaderAsideFooterResponsiveLayout(props) {
|
86 | _classCallCheck(this, HeaderAsideFooterResponsiveLayout);
|
87 |
|
88 | var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
89 |
|
90 | _initialiseProps.call(_this);
|
91 |
|
92 | var openKeys = _this.getOpenKeys();
|
93 | _this.state = {
|
94 | collapse: false,
|
95 | openDrawer: false,
|
96 | isScreen: undefined,
|
97 | openKeys: openKeys
|
98 | };
|
99 | _this.openKeysCache = openKeys;
|
100 | return _this;
|
101 | }
|
102 |
|
103 | HeaderAsideFooterResponsiveLayout.prototype.componentDidMount = function componentDidMount() {
|
104 | this.enquireScreenRegister();
|
105 | };
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | HeaderAsideFooterResponsiveLayout.prototype.render = function render() {
|
111 | var _this2 = this;
|
112 |
|
113 | var _props$location = this.props.location,
|
114 | location = _props$location === undefined ? {} : _props$location;
|
115 | var pathname = location.pathname;
|
116 |
|
117 |
|
118 | return _react2.default.createElement(
|
119 | _reactContainerQuery.ContainerQuery,
|
120 | { query: query },
|
121 | function (params) {
|
122 | return _react2.default.createElement(
|
123 | 'div',
|
124 | { className: (0, _classnames2.default)(params) },
|
125 | _react2.default.createElement(
|
126 | _layout2.default,
|
127 | {
|
128 | style: { minHeight: '100vh' },
|
129 | className: (0, _classnames2.default)('ice-design-header-aside-footer-responsive-layout-' + theme, {
|
130 | 'ice-design-layout': true
|
131 | })
|
132 | },
|
133 | _react2.default.createElement(_Header2.default, {
|
134 | theme: theme,
|
135 | isMobile: _this2.state.isScreen !== 'isDesktop' ? true : undefined
|
136 | }),
|
137 | _react2.default.createElement(
|
138 | _layout2.default.Section,
|
139 | null,
|
140 | _this2.state.isScreen === 'isMobile' && _react2.default.createElement(
|
141 | 'a',
|
142 | { className: 'menu-btn', onClick: _this2.toggleMenu },
|
143 | _react2.default.createElement(Icon, { type: 'category', size: 'small' })
|
144 | ),
|
145 | _this2.state.openDrawer && _react2.default.createElement('div', { className: 'open-drawer-bg', onClick: _this2.toggleMenu }),
|
146 | _react2.default.createElement(
|
147 | _layout2.default.Aside,
|
148 | {
|
149 | width: 'auto',
|
150 | theme: theme,
|
151 | className: (0, _classnames2.default)('ice-design-layout-aside', {
|
152 | 'open-drawer': _this2.state.openDrawer
|
153 | })
|
154 | },
|
155 | _this2.state.isScreen !== 'isMobile' && _react2.default.createElement(
|
156 | 'a',
|
157 | { className: 'collapse-btn', onClick: _this2.toggleCollapse },
|
158 | _react2.default.createElement(Icon, {
|
159 | type: _this2.state.collapse ? 'arrow-right' : 'arrow-left',
|
160 | size: 'small'
|
161 | })
|
162 | ),
|
163 | _this2.state.isScreen === 'isMobile' && _react2.default.createElement(_Logo2.default, null),
|
164 | _react2.default.createElement(
|
165 | _menu2.default,
|
166 | {
|
167 | style: { width: _this2.state.collapse ? 60 : 200 },
|
168 | inlineCollapsed: _this2.state.collapse,
|
169 | mode: 'inline',
|
170 | selectedKeys: [pathname],
|
171 | openKeys: _this2.state.openKeys,
|
172 | defaultSelectedKeys: [pathname],
|
173 | onOpenChange: _this2.onOpenChange,
|
174 | onClick: _this2.onMenuClick
|
175 | },
|
176 | _navs.asideNavs && _navs.asideNavs.length > 0 && _navs.asideNavs.map(function (nav, index) {
|
177 | if (nav.children && nav.children.length > 0) {
|
178 | return _react2.default.createElement(
|
179 | _menu.SubMenu,
|
180 | {
|
181 | key: index,
|
182 | title: _react2.default.createElement(
|
183 | 'span',
|
184 | null,
|
185 | nav.icon ? _react2.default.createElement(_foundationSymbol2.default, {
|
186 | size: 'small',
|
187 | type: nav.icon
|
188 | }) : null,
|
189 | _react2.default.createElement(
|
190 | 'span',
|
191 | { className: 'ice-menu-collapse-hide' },
|
192 | nav.text
|
193 | )
|
194 | )
|
195 | },
|
196 | nav.children.map(function (item) {
|
197 | var linkProps = {};
|
198 | if (item.newWindow) {
|
199 | linkProps.href = item.to;
|
200 | linkProps.target = '_blank';
|
201 | } else if (item.external) {
|
202 | linkProps.href = item.to;
|
203 | } else {
|
204 | linkProps.to = item.to;
|
205 | }
|
206 |
|
207 | return _react2.default.createElement(
|
208 | _menu.Item,
|
209 | { key: item.to },
|
210 | _react2.default.createElement(
|
211 | _reactRouter.Link,
|
212 | linkProps,
|
213 | item.text
|
214 | )
|
215 | );
|
216 | })
|
217 | );
|
218 | }
|
219 |
|
220 | var linkProps = {};
|
221 | if (nav.newWindow) {
|
222 | linkProps.href = nav.to;
|
223 | linkProps.target = '_blank';
|
224 | } else if (nav.external) {
|
225 | linkProps.href = nav.to;
|
226 | } else {
|
227 | linkProps.to = nav.to;
|
228 | }
|
229 |
|
230 | return _react2.default.createElement(
|
231 | _menu.Item,
|
232 | { key: nav.to },
|
233 | _react2.default.createElement(
|
234 | _reactRouter.Link,
|
235 | linkProps,
|
236 | _react2.default.createElement(
|
237 | 'span',
|
238 | null,
|
239 | nav.icon ? _react2.default.createElement(_foundationSymbol2.default, {
|
240 | size: 'small',
|
241 | type: nav.icon
|
242 | }) : null,
|
243 | _react2.default.createElement(
|
244 | 'span',
|
245 | { className: 'ice-menu-collapse-hide' },
|
246 | nav.text
|
247 | )
|
248 | )
|
249 | )
|
250 | );
|
251 | })
|
252 | )
|
253 | ),
|
254 | _react2.default.createElement(
|
255 | _layout2.default.Main,
|
256 | null,
|
257 | _this2.props.children
|
258 | )
|
259 | ),
|
260 | _react2.default.createElement(_Footer2.default, null)
|
261 | )
|
262 | );
|
263 | }
|
264 | );
|
265 | };
|
266 |
|
267 | return HeaderAsideFooterResponsiveLayout;
|
268 | }(_react.Component), _class.propTypes = {}, _class.defaultProps = {}, _initialiseProps = function _initialiseProps() {
|
269 | var _this3 = this;
|
270 |
|
271 | this.enquireScreenRegister = function () {
|
272 | var isMobile = 'screen and (max-width: 720px)';
|
273 | var isTablet = 'screen and (min-width: 721px) and (max-width: 1199px)';
|
274 | var isDesktop = 'screen and (min-width: 1200px)';
|
275 |
|
276 | _enquireJs.enquire.register(isMobile, _this3.enquireScreenHandle('isMobile'));
|
277 | _enquireJs.enquire.register(isTablet, _this3.enquireScreenHandle('isTablet'));
|
278 | _enquireJs.enquire.register(isDesktop, _this3.enquireScreenHandle('isDesktop'));
|
279 | };
|
280 |
|
281 | this.enquireScreenHandle = function (type) {
|
282 | var collapse = void 0;
|
283 | if (type === 'isMobile') {
|
284 | collapse = false;
|
285 | } else if (type === 'isTablet') {
|
286 | collapse = true;
|
287 | } else {
|
288 | collapse = _this3.state.collapse;
|
289 | }
|
290 |
|
291 | var handler = {
|
292 | match: function match() {
|
293 | _this3.setState({
|
294 | isScreen: type,
|
295 | collapse: collapse
|
296 | });
|
297 | },
|
298 | unmatch: function unmatch() {
|
299 |
|
300 | }
|
301 | };
|
302 |
|
303 | return handler;
|
304 | };
|
305 |
|
306 | this.toggleCollapse = function () {
|
307 | var collapse = _this3.state.collapse;
|
308 |
|
309 | var openKeys = !collapse ? [] : _this3.openKeysCache;
|
310 |
|
311 | _this3.setState({
|
312 | collapse: !collapse,
|
313 | openKeys: openKeys
|
314 | });
|
315 | };
|
316 |
|
317 | this.toggleMenu = function () {
|
318 | var openDrawer = _this3.state.openDrawer;
|
319 |
|
320 | _this3.setState({
|
321 | openDrawer: !openDrawer
|
322 | });
|
323 | };
|
324 |
|
325 | this.onOpenChange = function (openKeys) {
|
326 | _this3.setState({
|
327 | openKeys: openKeys
|
328 | });
|
329 | _this3.openKeysCache = openKeys;
|
330 | };
|
331 |
|
332 | this.onMenuClick = function () {
|
333 | _this3.toggleMenu();
|
334 | };
|
335 |
|
336 | this.getOpenKeys = function () {
|
337 | var routes = _this3.props.routes;
|
338 |
|
339 | if (!routes) return [];
|
340 | var matched = routes[0].path;
|
341 | var openKeys = [];
|
342 |
|
343 | _navs.asideNavs && _navs.asideNavs.length > 0 && _navs.asideNavs.map(function (item, index) {
|
344 | if (item.to === matched) {
|
345 | openKeys = ['' + index];
|
346 | }
|
347 | });
|
348 |
|
349 | return openKeys;
|
350 | };
|
351 | }, _temp);
|
352 | exports.default = HeaderAsideFooterResponsiveLayout;
|
353 | module.exports = exports['default']; |
\ | No newline at end of file |