tntd 1.4.4 → 1.4.7

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.
Files changed (88) hide show
  1. package/components/Layout/HeaderActions.js +90 -128
  2. package/components/LoadingButton/index.js +11 -15
  3. package/components/QueryListScene/QueryForm.js +7 -4
  4. package/dist/stats.json +4990 -4990
  5. package/dist/tntd.js +1 -1
  6. package/es/Layout/HeaderActions.js +10 -10
  7. package/es/LoadingButton/index.js +20 -10
  8. package/es/QueryListScene/QueryForm.js +6 -3
  9. package/lib/ArrayInput/icon.js +27 -31
  10. package/lib/ArrayInput/index.js +211 -298
  11. package/lib/AuthContext.js +2 -13
  12. package/lib/Columns/index.js +71 -100
  13. package/lib/DevelopmentLogin/LoginModal.js +79 -141
  14. package/lib/DevelopmentLogin/index.js +28 -55
  15. package/lib/Ellipsis/Svg/CopySVG.js +23 -71
  16. package/lib/Ellipsis/Svg/TickSVG.js +17 -49
  17. package/lib/Ellipsis/index.js +148 -154
  18. package/lib/Handle/index.js +72 -109
  19. package/lib/Icon/fonts/iconfont.js +1 -43
  20. package/lib/Icon/iconList.js +119 -8
  21. package/lib/Icon/index.js +13 -45
  22. package/lib/Img/Contain.js +49 -81
  23. package/lib/Img/Cover.js +88 -136
  24. package/lib/Img/index.js +36 -89
  25. package/lib/Layout/ActionsContext.js +2 -11
  26. package/lib/Layout/AppList.js +262 -256
  27. package/lib/Layout/Application.js +119 -135
  28. package/lib/Layout/Avatar.js +137 -137
  29. package/lib/Layout/CompatibleLanguage.js +214 -195
  30. package/lib/Layout/EnterpriseLayout/Avatar.js +156 -168
  31. package/lib/Layout/EnterpriseLayout/Language.js +75 -100
  32. package/lib/Layout/EnterpriseLayout/Theme.js +96 -94
  33. package/lib/Layout/EnterpriseLayout/index.js +32 -45
  34. package/lib/Layout/GlobalNavigation/NavigationPopup.js +335 -407
  35. package/lib/Layout/GlobalNavigation/index.js +110 -158
  36. package/lib/Layout/Header.js +165 -116
  37. package/lib/Layout/HeaderActions.js +132 -129
  38. package/lib/Layout/HeaderNavs.js +90 -113
  39. package/lib/Layout/HeaderTabs.js +312 -278
  40. package/lib/Layout/Iconfont.js +2 -15
  41. package/lib/Layout/Language.js +63 -102
  42. package/lib/Layout/Layout.js +272 -261
  43. package/lib/Layout/Logo.js +132 -87
  44. package/lib/Layout/OrgAppList.js +440 -319
  45. package/lib/Layout/SideMenu.js +429 -343
  46. package/lib/Layout/Theme.js +95 -124
  47. package/lib/Layout/checkAuth.js +21 -35
  48. package/lib/Layout/createActions.js +38 -51
  49. package/lib/Layout/images/index.js +33 -41
  50. package/lib/Layout/index.js +110 -161
  51. package/lib/Layout/paaslayout/CompactSideMenu.js +200 -178
  52. package/lib/Layout/paaslayout/Header.js +84 -90
  53. package/lib/Layout/paaslayout/Logo.js +27 -32
  54. package/lib/Layout/paaslayout/SideMenu.js +161 -174
  55. package/lib/Layout/paaslayout/index.js +240 -261
  56. package/lib/Layout/storage.js +20 -78
  57. package/lib/Layout/utils.js +93 -143
  58. package/lib/LoadingButton/index.js +25 -57
  59. package/lib/Modal/index.js +83 -108
  60. package/lib/Page/Box.js +56 -81
  61. package/lib/Page/index.js +151 -173
  62. package/lib/Page/utils.js +12 -30
  63. package/lib/QueryForm/Field/Checkbox.js +11 -33
  64. package/lib/QueryForm/Field/Select.js +63 -99
  65. package/lib/QueryForm/Field/SelectInput.js +69 -114
  66. package/lib/QueryForm/Field/fieldsMap.js +30 -52
  67. package/lib/QueryForm/Field/index.js +76 -158
  68. package/lib/QueryForm/createActions.js +50 -65
  69. package/lib/QueryForm/index.js +304 -383
  70. package/lib/QueryForm/useForm.js +6 -17
  71. package/lib/QueryListScene/List.js +290 -366
  72. package/lib/QueryListScene/QueryForm.js +93 -158
  73. package/lib/QueryListScene/QueryListScene.js +33 -87
  74. package/lib/QueryListScene/Title.js +10 -20
  75. package/lib/QueryListScene/Toolbar.js +8 -31
  76. package/lib/QueryListScene/createActions.js +64 -79
  77. package/lib/QueryListScene/index.js +23 -40
  78. package/lib/QueryListScene/useActions.js +6 -17
  79. package/lib/Select/DropDownWrap.js +60 -124
  80. package/lib/Select/index.js +425 -561
  81. package/lib/Table/ResizableTable/index.js +77 -121
  82. package/lib/Table/index.js +19 -51
  83. package/lib/Title/index.js +34 -52
  84. package/lib/index.js +19 -159
  85. package/lib/locale.js +48 -63
  86. package/package.json +1 -1
  87. package/lib/Layout/EnterpriseLayout/Header.js +0 -113
  88. package/lib/Layout/EnterpriseLayout/HeaderActions.js +0 -104
@@ -1,165 +1,114 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- var _exportNames = {
9
- HeaderActionItem: true
10
- };
11
- exports["default"] = exports.HeaderActionItem = void 0;
12
-
13
- var _styledComponents = require("styled-components");
14
-
15
- var _Layout = _interopRequireDefault(require("./Layout"));
16
-
17
- var _EnterpriseLayout = _interopRequireDefault(require("./EnterpriseLayout"));
18
-
19
- var _paaslayout = _interopRequireDefault(require("./paaslayout"));
20
-
21
- var _HeaderNavs = _interopRequireWildcard(require("./HeaderNavs"));
22
-
23
- Object.keys(_HeaderNavs).forEach(function (key) {
24
- if (key === "default" || key === "__esModule") return;
25
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
- Object.defineProperty(exports, key, {
27
- enumerable: true,
28
- get: function get() {
29
- return _HeaderNavs[key];
30
- }
31
- });
32
- });
33
-
34
- var _HeaderTabs = _interopRequireDefault(require("./HeaderTabs"));
35
-
36
- var _checkAuth = _interopRequireDefault(require("./checkAuth"));
37
-
38
- var _AuthContext = _interopRequireDefault(require("../AuthContext"));
39
-
40
- var _utils = require("./utils");
41
-
42
- var _ActionsContext = _interopRequireDefault(require("./ActionsContext"));
43
-
44
- var _createActions = _interopRequireDefault(require("./createActions"));
45
-
46
- var _storage = require("./storage");
47
-
48
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
49
-
50
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
51
-
52
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
53
-
54
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
55
-
56
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
57
-
58
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
59
-
60
- var HeaderActionItem = function HeaderActionItem(props) {
61
- return React.createElement("li", props, props.children);
1
+ import { ThemeProvider } from 'styled-components';
2
+ import Layout from './Layout';
3
+ import EnterpriseLayout from './EnterpriseLayout';
4
+ import PaasLayout from './paaslayout';
5
+ import HeaderNavs from './HeaderNavs';
6
+ import HeaderTabs from './HeaderTabs';
7
+ import getCheckAuth from './checkAuth';
8
+ import AuthContext from '../AuthContext';
9
+ import { safeParseJSON, findMenuInfoByPath } from './utils';
10
+ import ActionsContext from './ActionsContext';
11
+ import createActions from './createActions';
12
+ import { getLanguageStore } from './storage';
13
+
14
+ export const HeaderActionItem = props => (
15
+ <li {...props}>
16
+ {props.children}
17
+ </li>
18
+ );
19
+
20
+ export * from './HeaderNavs';
21
+
22
+
23
+ const TNTLayout = ({ type, config, ...props }) => {
24
+ const headerHeight = props.size === 'large' ? 60 : 50;
25
+ const theme = {
26
+ size: props.size,
27
+ compatible: props.compatible,
28
+ headerHeight,
29
+ primaryColor: '#126BFB',
30
+ secondaryColor: '#005df4',
31
+ primaryTextColor: '#17233D', // 1
32
+ secondaryTextColor: 'rgba(23,35,61,.8)', // .8
33
+ lightIconColor: 'rgba(23,35,61,.7)', // .7
34
+ headerActionsColor: 'rgba(23,35,61,.6)', // .6
35
+ borderColor: '#B2BECD',
36
+ dividerColor: '#E1E6EE',
37
+ lightBgColor: '#F1F2F5',
38
+ blueBgColor: '#1D4295' // 默认的蓝色主题
39
+ };
40
+ const isInIframe = self !== top;
41
+ // 前期拼写错误,导致需要兼容处理
42
+ const extraHeaderActions = props.extraHeaderActions || props.extralHeaderActions;
43
+ const extendMap = typeof props.extendMap === 'string' ? safeParseJSON(props.extendMap, {}) : props.extendMap;
44
+ const { displayType = 'default', menuAlignMode, globalNavigation = false, language = ['cn'], themeSwitch = true } = extendMap || {};
45
+ const userInfo = props.userInfo || {};
46
+ const actionsContextValue = createActions({ language: getLanguageStore() || userInfo.lang || 'cn' });
47
+ const onLanguageChange = language => {
48
+ actionsContextValue.setLanguage(language);
49
+ props?.onLanguageChange(language);
50
+ };
51
+
52
+ // layout上的指定的属性优先级会高于extendMap中的属性
53
+ type = type || displayType;
54
+ config = Object.assign({
55
+ language: language?.length > 1,
56
+ theme: themeSwitch,
57
+ avatar: true,
58
+ globalNavigation
59
+ }, config);
60
+
61
+ return (
62
+ <ThemeProvider theme={theme}>
63
+ <AuthContext.Provider value={getCheckAuth(props.menus)}>
64
+ <ActionsContext.Provider value={actionsContextValue}>
65
+ {
66
+ type === 'paas' &&
67
+ <PaasLayout
68
+ menuAlignMode={menuAlignMode}
69
+ config={config}
70
+ {...props}
71
+ extraHeaderActions={extraHeaderActions}
72
+ isInIframe={isInIframe}
73
+ userInfo={userInfo}
74
+ onLanguageChange={onLanguageChange}
75
+ />
76
+ }
77
+ {
78
+ type === 'enterprise' &&
79
+ <EnterpriseLayout
80
+ menuAlignMode={menuAlignMode}
81
+ config={config}
82
+ {...props}
83
+ extraHeaderActions={extraHeaderActions}
84
+ isInIframe={isInIframe}
85
+ userInfo={userInfo}
86
+ onLanguageChange={onLanguageChange}
87
+ />
88
+ }
89
+ {
90
+ (!type || !['paas','enterprise'].includes(type)) &&
91
+ <Layout
92
+ menuAlignMode={menuAlignMode}
93
+ config={config}
94
+ {...props}
95
+ extraHeaderActions={extraHeaderActions}
96
+ isInIframe={isInIframe}
97
+ userInfo={userInfo}
98
+ onLanguageChange={onLanguageChange}
99
+ />
100
+ }
101
+ </ActionsContext.Provider>
102
+ </AuthContext.Provider>
103
+ </ThemeProvider>
104
+ );
62
105
  };
63
106
 
64
- exports.HeaderActionItem = HeaderActionItem;
65
-
66
- var TNTLayout = function TNTLayout(_ref) {
67
- var type = _ref.type,
68
- config = _ref.config,
69
- props = _objectWithoutProperties(_ref, ["type", "config"]);
70
-
71
- var headerHeight = props.size === 'large' ? 60 : 50;
72
- var theme = {
73
- size: props.size,
74
- compatible: props.compatible,
75
- headerHeight: headerHeight,
76
- primaryColor: '#126BFB',
77
- secondaryColor: '#005df4',
78
- primaryTextColor: '#17233D',
79
- // 1
80
- secondaryTextColor: 'rgba(23,35,61,.8)',
81
- // .8
82
- lightIconColor: 'rgba(23,35,61,.7)',
83
- // .7
84
- headerActionsColor: 'rgba(23,35,61,.6)',
85
- // .6
86
- borderColor: '#B2BECD',
87
- dividerColor: '#E1E6EE',
88
- lightBgColor: '#F1F2F5',
89
- blueBgColor: '#1D4295' // 默认的蓝色主题
90
-
91
- };
92
- var isInIframe = self !== top; // 前期拼写错误,导致需要兼容处理
93
-
94
- var extraHeaderActions = props.extraHeaderActions || props.extralHeaderActions;
95
- var extendMap = typeof props.extendMap === 'string' ? (0, _utils.safeParseJSON)(props.extendMap, {}) : props.extendMap;
96
-
97
- var _ref2 = extendMap || {},
98
- _ref2$displayType = _ref2.displayType,
99
- displayType = _ref2$displayType === void 0 ? 'default' : _ref2$displayType,
100
- menuAlignMode = _ref2.menuAlignMode,
101
- _ref2$globalNavigatio = _ref2.globalNavigation,
102
- globalNavigation = _ref2$globalNavigatio === void 0 ? false : _ref2$globalNavigatio,
103
- _ref2$language = _ref2.language,
104
- language = _ref2$language === void 0 ? ['cn'] : _ref2$language,
105
- _ref2$themeSwitch = _ref2.themeSwitch,
106
- themeSwitch = _ref2$themeSwitch === void 0 ? true : _ref2$themeSwitch;
107
-
108
- var userInfo = props.userInfo || {};
109
- var actionsContextValue = (0, _createActions["default"])({
110
- language: (0, _storage.getLanguageStore)() || userInfo.lang || 'cn'
111
- });
112
-
113
- var onLanguageChange = function onLanguageChange(language) {
114
- actionsContextValue.setLanguage(language);
115
- props == null ? void 0 : props.onLanguageChange(language);
116
- }; // layout上的指定的属性优先级会高于extendMap中的属性
117
-
107
+ TNTLayout.HeaderActionItem = HeaderActionItem;
108
+ TNTLayout.HeaderNavs = HeaderNavs;
109
+ TNTLayout.HeaderTabs = HeaderTabs;
110
+ TNTLayout.AuthContext = AuthContext;
118
111
 
119
- type = type || displayType;
120
- config = Object.assign({
121
- language: (language == null ? void 0 : language.length) > 1,
122
- theme: themeSwitch,
123
- avatar: true,
124
- globalNavigation: globalNavigation
125
- }, config);
126
- return React.createElement(_styledComponents.ThemeProvider, {
127
- theme: theme
128
- }, React.createElement(_AuthContext["default"].Provider, {
129
- value: (0, _checkAuth["default"])(props.menus)
130
- }, React.createElement(_ActionsContext["default"].Provider, {
131
- value: actionsContextValue
132
- }, type === 'paas' && React.createElement(_paaslayout["default"], _extends({
133
- menuAlignMode: menuAlignMode,
134
- config: config
135
- }, props, {
136
- extraHeaderActions: extraHeaderActions,
137
- isInIframe: isInIframe,
138
- userInfo: userInfo,
139
- onLanguageChange: onLanguageChange
140
- })), type === 'enterprise' && React.createElement(_EnterpriseLayout["default"], _extends({
141
- menuAlignMode: menuAlignMode,
142
- config: config
143
- }, props, {
144
- extraHeaderActions: extraHeaderActions,
145
- isInIframe: isInIframe,
146
- userInfo: userInfo,
147
- onLanguageChange: onLanguageChange
148
- })), (!type || !['paas', 'enterprise'].includes(type)) && React.createElement(_Layout["default"], _extends({
149
- menuAlignMode: menuAlignMode,
150
- config: config
151
- }, props, {
152
- extraHeaderActions: extraHeaderActions,
153
- isInIframe: isInIframe,
154
- userInfo: userInfo,
155
- onLanguageChange: onLanguageChange
156
- })))));
157
- };
112
+ TNTLayout.findMenuInfoByPath = findMenuInfoByPath;
158
113
 
159
- TNTLayout.HeaderActionItem = HeaderActionItem;
160
- TNTLayout.HeaderNavs = _HeaderNavs["default"];
161
- TNTLayout.HeaderTabs = _HeaderTabs["default"];
162
- TNTLayout.AuthContext = _AuthContext["default"];
163
- TNTLayout.findMenuInfoByPath = _utils.findMenuInfoByPath;
164
- var _default = TNTLayout;
165
- exports["default"] = _default;
114
+ export default TNTLayout;
@@ -1,185 +1,207 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _react = require("react");
9
-
10
- var _styledComponents = _interopRequireDefault(require("styled-components"));
11
-
12
- var _classnames = _interopRequireDefault(require("classnames"));
13
-
14
- var _utils = require("../utils");
15
-
16
- var _Iconfont = _interopRequireDefault(require("../Iconfont"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
-
20
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
21
-
22
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
23
-
24
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
25
-
26
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
-
28
- function _templateObject2() {
29
- var data = _taggedTemplateLiteral(["\n background: #fff;\n list-style: none;\n font-size: 14px;\n color: #17233D;\n margin: 10px 0 0;\n padding: 0;\n li {\n position: relative;\n line-height: 38px;\n cursor: pointer;\n padding-left: 20px;\n & > a {\n color: #17233D;\n & > span {\n padding-left: 10px;\n }\n }\n &.active {\n background: #EAEDF8;\n &:before {\n position: absolute;\n left: 0;\n top: 0;\n content: '';\n width: 4px;\n height: 100%;\n background-color: #4C79FF;\n }\n }\n }\n"]);
30
-
31
- _templateObject2 = function _templateObject2() {
32
- return data;
33
- };
34
-
35
- return data;
36
- }
37
-
38
- function _templateObject() {
39
- var data = _taggedTemplateLiteral(["\n background: #fff;\n list-style: none;\n margin: 0;\n padding: 30px 0 20px;\n text-rendering: optimizeLegibility;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n .isInIframe & {\n display: none;\n }\n \n & > li {\n position: relative;\n cursor: pointer;\n line-height: 38px;\n font-size: 14px;\n color: #17233D;\n letter-spacing: 0;\n\n &.group-menu-item {\n & > span {\n opacity: 0.4;\n }\n }\n\n &.active {\n &:before {\n position: absolute;\n content: \"\";\n left: 0;\n top: 0;\n width: 3px;\n height: 100%;\n background: #126bfb;\n }\n\n span {\n background: rgba(18,107,251,0.10);\n color: #126bfb;\n opacity: 1;\n }\n }\n\n & > span {\n display: inline-block;\n width: 100%;\n color: #17233D;\n padding-left: 20px;\n\n &:hover {\n color: #323232;\n background: #f5f5f5;\n }\n\n & > .tnt-icon {\n margin-right: 7px;\n }\n }\n }\n"]);
40
-
41
- _templateObject = function _templateObject() {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
49
-
50
- var SideMenu = _styledComponents["default"].ul(_templateObject());
51
-
52
- var SubMenu = _styledComponents["default"].ul(_templateObject2());
53
-
54
- var _default = function _default(props) {
55
- var language = props.language,
56
- _props$menus = props.menus,
57
- menus = _props$menus === void 0 ? [] : _props$menus,
58
- formatMenuPath = props.formatMenuPath,
59
- selectedKey = props.selectedKey,
60
- onBeforeChange = props.onBeforeChange,
61
- onChange = props.onChange,
62
- onSelect = props.onSelect;
63
-
64
- var _useState = (0, _react.useState)(selectedKey),
65
- _useState2 = _slicedToArray(_useState, 2),
66
- activeMenu = _useState2[0],
67
- setActiveMenu = _useState2[1];
68
-
69
- var defaultBeforeChange = function defaultBeforeChange(_ref) {
70
- var data = _ref.data;
71
- return !(0, _utils.isNewTabMenu)(data);
72
- };
73
-
74
- var defaultSelect = function defaultSelect(_ref2) {
75
- var _window$location$path;
76
-
77
- var data = _ref2.data;
78
-
79
- var _ref3 = data || {},
80
- path = _ref3.path;
81
-
82
- var formatPath = formatMenuPath || function (path) {
83
- return path;
84
- };
85
-
86
- if ((0, _utils.isNewTabMenu)(data)) {
87
- (0, _utils.openInNewTab)(formatPath(data == null ? void 0 : data.path, data));
88
- return;
1
+ import { useState, useEffect, Component } from 'react';
2
+ import styled from 'styled-components';
3
+ import cn from 'classnames';
4
+ import { isNewTabMenu, openInNewTab } from '../utils';
5
+ import Iconfont from '../Iconfont';
6
+
7
+ const SideMenu = styled.ul`
8
+ background: #fff;
9
+ list-style: none;
10
+ margin: 0;
11
+ padding: 30px 0 20px;
12
+ text-rendering: optimizeLegibility;
13
+ -webkit-font-smoothing: antialiased;
14
+ -moz-osx-font-smoothing: grayscale;
15
+ .isInIframe & {
16
+ display: none;
89
17
  }
90
-
91
- var routerPrefix = (_window$location$path = window.location.pathname.match(/(^\/[^\/]+)/i)) == null ? void 0 : _window$location$path[1];
92
-
93
- if (window.location.pathname.startsWith(routerPrefix)) {
94
- var forwardPath = formatPath(path, data);
95
- changeRouter ? changeRouter(forwardPath, data) : window.history.pushState(data, data == null ? void 0 : data.name, forwardPath);
96
- } else {
97
- window.location.href = formatPath(path, data);
18
+
19
+ & > li {
20
+ position: relative;
21
+ cursor: pointer;
22
+ line-height: 38px;
23
+ font-size: 14px;
24
+ color: #17233D;
25
+ letter-spacing: 0;
26
+
27
+ &.group-menu-item {
28
+ & > span {
29
+ opacity: 0.4;
30
+ }
31
+ }
32
+
33
+ &.active {
34
+ &:before {
35
+ position: absolute;
36
+ content: "";
37
+ left: 0;
38
+ top: 0;
39
+ width: 3px;
40
+ height: 100%;
41
+ background: #126bfb;
42
+ }
43
+
44
+ span {
45
+ background: rgba(18,107,251,0.10);
46
+ color: #126bfb;
47
+ opacity: 1;
48
+ }
49
+ }
50
+
51
+ & > span {
52
+ display: inline-block;
53
+ width: 100%;
54
+ color: #17233D;
55
+ padding-left: 20px;
56
+
57
+ &:hover {
58
+ color: #323232;
59
+ background: #f5f5f5;
60
+ }
61
+
62
+ & > .tnt-icon {
63
+ margin-right: 7px;
64
+ }
65
+ }
98
66
  }
99
- };
100
-
101
- var selectMenu = function selectMenu() {
102
- var param = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
103
- var finalBeforeChange = onBeforeChange || defaultBeforeChange;
104
- var finalSelect = onSelect || defaultSelect;
105
-
106
- if (param.key !== activeMenu) {
107
- if (finalBeforeChange(param, activeMenu)) {
108
- setActiveMenu(param.key);
109
- onChange && onChange(param);
110
- }
67
+ `;
68
+
69
+ const SubMenu = styled.ul`
70
+ background: #fff;
71
+ list-style: none;
72
+ font-size: 14px;
73
+ color: #17233D;
74
+ margin: 10px 0 0;
75
+ padding: 0;
76
+ li {
77
+ position: relative;
78
+ line-height: 38px;
79
+ cursor: pointer;
80
+ padding-left: 20px;
81
+ & > a {
82
+ color: #17233D;
83
+ & > span {
84
+ padding-left: 10px;
85
+ }
86
+ }
87
+ &.active {
88
+ background: #EAEDF8;
89
+ &:before {
90
+ position: absolute;
91
+ left: 0;
92
+ top: 0;
93
+ content: '';
94
+ width: 4px;
95
+ height: 100%;
96
+ background-color: #4C79FF;
97
+ }
98
+ }
111
99
  }
112
-
113
- finalSelect(param);
114
- };
115
-
116
- var MenuItem = function MenuItem(_ref4) {
117
- var item = _ref4.item;
118
- var code = item.code,
119
- groupName = item.groupName,
120
- enName = item.enName,
121
- _item$children = item.children,
122
- children = _item$children === void 0 ? [] : _item$children;
123
-
124
- var SubMenuItem = function SubMenuItem(_ref5) {
125
- var menu = _ref5.menu;
126
- var code = menu.code,
127
- menuName = menu.menuName,
128
- enName = menu.enName,
129
- icon = menu.icon;
130
- return React.createElement("li", {
131
- key: code,
132
- onClick: function onClick(evt) {
133
- return selectMenu({
134
- key: code,
135
- data: menu,
136
- domEvent: evt
137
- });
138
- },
139
- className: (0, _classnames["default"])({
140
- active: code === activeMenu
141
- })
142
- }, React.createElement("span", null, typeof (icon || '') === 'string' ? React.createElement(_Iconfont["default"], {
143
- type: icon
144
- }) : icon, {
145
- cn: menuName,
146
- en: enName
147
- }[language]));
100
+ `;
101
+
102
+ export default props => {
103
+ const { language, menus = [], formatMenuPath, selectedKey, onBeforeChange, onChange, onSelect } = props;
104
+ const [activeMenu, setActiveMenu] = useState(selectedKey);
105
+ const defaultBeforeChange = ({ data }) => !isNewTabMenu(data);
106
+ const defaultSelect = ({ data }) => {
107
+ const { path } = data || {};
108
+ const formatPath = formatMenuPath || (path => path);
109
+
110
+ if (isNewTabMenu(data)) {
111
+ openInNewTab(formatPath(data?.path, data));
112
+ return;
113
+ }
114
+
115
+ const routerPrefix = window.location.pathname.match(/(^\/[^\/]+)/i)?.[1];
116
+
117
+ if (window.location.pathname.startsWith(routerPrefix)) {
118
+ const forwardPath = formatPath(path, data);
119
+ changeRouter ? changeRouter(forwardPath, data) : window.history.pushState(data, data?.name, forwardPath);
120
+ } else {
121
+ window.location.href = formatPath(path, data);
122
+ }
123
+ };
124
+ const selectMenu = (param = {}) => {
125
+ const finalBeforeChange = onBeforeChange || defaultBeforeChange;
126
+ const finalSelect = onSelect || defaultSelect;
127
+
128
+ if (param.key !== activeMenu) {
129
+ if (finalBeforeChange(param, activeMenu)) {
130
+ setActiveMenu(param.key);
131
+ onChange && onChange(param);
132
+ }
133
+ }
134
+
135
+ finalSelect(param);
148
136
  };
149
137
 
150
- if (groupName && children.length) {
151
- return React.createElement("li", {
152
- key: code,
153
- className: "group-menu-item"
154
- }, React.createElement("span", null, icon instanceof _react.Component ? icon : React.createElement(_Iconfont["default"], {
155
- type: icon
156
- }), {
157
- cn: groupName,
158
- en: enName
159
- }[language]), React.createElement(SubMenu, null, children.map(function (subItem) {
160
- return React.createElement(SubMenuItem, {
161
- menu: subItem,
162
- key: subItem == null ? void 0 : subItem.code
163
- });
164
- })));
165
- }
138
+ const MenuItem = ({ item }) => {
139
+ const { code, groupName, enName, children = [] } = item;
140
+ const SubMenuItem = ({ menu }) => {
141
+ const { code, menuName, enName, icon } = menu;
142
+
143
+ return (
144
+ <li
145
+ key={code}
146
+ onClick={evt => selectMenu({ key: code, data: menu, domEvent: evt })}
147
+ className={cn({ active: code === activeMenu })}
148
+ >
149
+ <span>
150
+ {
151
+ typeof (icon || '') === 'string' ? (
152
+ <Iconfont type={icon} />
153
+ ) : icon
154
+ }
155
+ {
156
+ {
157
+ cn: menuName,
158
+ en: enName
159
+ }[language]
160
+ }
161
+ </span>
162
+ </li>
163
+ );
164
+ };
165
+
166
+ if (groupName && children.length) {
167
+ return (
168
+ <li key={code} className="group-menu-item">
169
+ <span>
170
+ {
171
+ icon instanceof Component ? icon : (
172
+ <Iconfont type={icon} />
173
+ )
174
+ }
175
+ {
176
+ {
177
+ cn: groupName,
178
+ en: enName
179
+ }[language]
180
+ }
181
+ </span>
182
+ <SubMenu>
183
+ {
184
+ children.map(subItem => <SubMenuItem menu={subItem} key={subItem?.code} />)
185
+ }
186
+ </SubMenu>
187
+ </li>
188
+ );
189
+ }
190
+
191
+ return <SubMenuItem menu={item} />;
192
+ };
166
193
 
167
- return React.createElement(SubMenuItem, {
168
- menu: item
169
- });
170
- };
171
-
172
- (0, _react.useEffect)(function () {
173
- setActiveMenu(selectedKey);
174
- }, [selectedKey]);
175
- return React.createElement(SideMenu, {
176
- className: "tnt-compact-sidemenu"
177
- }, menus.map(function (menu) {
178
- return React.createElement(MenuItem, {
179
- item: menu,
180
- key: menu.code
181
- });
182
- }));
194
+ useEffect(() => {
195
+ setActiveMenu(selectedKey);
196
+ }, [selectedKey]);
197
+
198
+ return (
199
+ <SideMenu className="tnt-compact-sidemenu">
200
+ {
201
+ menus.map(menu => (
202
+ <MenuItem item={menu} key={menu.code} />
203
+ ))
204
+ }
205
+ </SideMenu>
206
+ );
183
207
  };
184
-
185
- exports["default"] = _default;