@hi-ui/layout 4.0.0 → 5.0.0-alpha.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.
Files changed (83) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/lib/cjs/AppList.js +163 -0
  3. package/lib/cjs/CollapseIcon.js +56 -0
  4. package/lib/cjs/Content.js +1 -4
  5. package/lib/cjs/FloatMenuContainer.js +93 -0
  6. package/lib/cjs/Footer.js +45 -0
  7. package/lib/cjs/Header.js +45 -0
  8. package/lib/cjs/Layout.js +4 -2
  9. package/lib/cjs/Profile.js +165 -0
  10. package/lib/cjs/SearchTrigger.js +71 -8
  11. package/lib/cjs/Sider.js +32 -18
  12. package/lib/cjs/index.js +26 -3
  13. package/lib/cjs/packages/hooks/use-id/lib/esm/index.js +51 -0
  14. package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/regex.js +16 -0
  15. package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/rng.js +33 -0
  16. package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/stringify.js +41 -0
  17. package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/v4.js +33 -0
  18. package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/validate.js +19 -0
  19. package/lib/cjs/packages/hooks/use-latest/lib/esm/index.js +56 -0
  20. package/lib/cjs/packages/hooks/use-timeout/lib/esm/index.js +50 -0
  21. package/lib/cjs/packages/hooks/use-toggle/lib/esm/index.js +71 -0
  22. package/lib/cjs/packages/hooks/use-unmount-effect/lib/esm/index.js +44 -0
  23. package/lib/cjs/packages/icons/lib/esm/components/alert/check-outlined.js +65 -0
  24. package/lib/cjs/packages/icons/lib/esm/components/direction/right-outlined.js +65 -0
  25. package/lib/cjs/packages/ui/popover/lib/esm/Popover.js +111 -0
  26. package/lib/cjs/packages/ui/popover/lib/esm/index.js +31 -0
  27. package/lib/cjs/packages/ui/popover/lib/esm/styles/index.scss.js +35 -0
  28. package/lib/cjs/packages/ui/popover/lib/esm/types.js +31 -0
  29. package/lib/cjs/packages/ui/popover/lib/esm/use-popover.js +187 -0
  30. package/lib/cjs/packages/ui/popover/lib/esm/utils/container/lib/esm/index.js +67 -0
  31. package/lib/cjs/packages/ui/popover/lib/esm/with-api.js +84 -0
  32. package/lib/cjs/packages/utils/array-utils/lib/esm/index.js +33 -0
  33. package/lib/cjs/packages/utils/dom-utils/lib/esm/index.js +47 -0
  34. package/lib/cjs/packages/utils/react-utils/lib/esm/index.js +72 -0
  35. package/lib/cjs/packages/utils/type-assertion/lib/esm/index.js +36 -0
  36. package/lib/cjs/styles/index.scss.js +1 -1
  37. package/lib/esm/AppList.js +149 -0
  38. package/lib/esm/CollapseIcon.js +44 -0
  39. package/lib/esm/Content.js +1 -4
  40. package/lib/esm/FloatMenuContainer.js +81 -0
  41. package/lib/esm/Footer.js +33 -0
  42. package/lib/esm/Header.js +33 -0
  43. package/lib/esm/Layout.js +4 -2
  44. package/lib/esm/Profile.js +152 -0
  45. package/lib/esm/SearchTrigger.js +70 -8
  46. package/lib/esm/Sider.js +32 -18
  47. package/lib/esm/index.js +22 -4
  48. package/lib/esm/packages/hooks/use-id/lib/esm/index.js +45 -0
  49. package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/regex.js +11 -0
  50. package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/rng.js +27 -0
  51. package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/stringify.js +36 -0
  52. package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/v4.js +28 -0
  53. package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/validate.js +14 -0
  54. package/lib/esm/packages/hooks/use-latest/lib/esm/index.js +50 -0
  55. package/lib/esm/packages/hooks/use-timeout/lib/esm/index.js +45 -0
  56. package/lib/esm/packages/hooks/use-toggle/lib/esm/index.js +66 -0
  57. package/lib/esm/packages/hooks/use-unmount-effect/lib/esm/index.js +39 -0
  58. package/lib/esm/packages/icons/lib/esm/components/alert/check-outlined.js +53 -0
  59. package/lib/esm/packages/icons/lib/esm/components/direction/right-outlined.js +53 -0
  60. package/lib/esm/packages/ui/popover/lib/esm/Popover.js +97 -0
  61. package/lib/esm/packages/ui/popover/lib/esm/index.js +25 -0
  62. package/lib/esm/packages/ui/popover/lib/esm/styles/index.scss.js +23 -0
  63. package/lib/esm/packages/ui/popover/lib/esm/types.js +25 -0
  64. package/lib/esm/packages/ui/popover/lib/esm/use-popover.js +175 -0
  65. package/lib/esm/packages/ui/popover/lib/esm/utils/container/lib/esm/index.js +60 -0
  66. package/lib/esm/packages/ui/popover/lib/esm/with-api.js +79 -0
  67. package/lib/esm/packages/utils/array-utils/lib/esm/index.js +28 -0
  68. package/lib/esm/packages/utils/dom-utils/lib/esm/index.js +42 -0
  69. package/lib/esm/packages/utils/react-utils/lib/esm/index.js +65 -0
  70. package/lib/esm/packages/utils/type-assertion/lib/esm/index.js +29 -0
  71. package/lib/esm/styles/index.scss.js +1 -1
  72. package/lib/types/AppList.d.ts +71 -0
  73. package/lib/types/CollapseIcon.d.ts +1 -0
  74. package/lib/types/Content.d.ts +0 -3
  75. package/lib/types/FloatMenuContainer.d.ts +28 -0
  76. package/lib/types/Footer.d.ts +5 -0
  77. package/lib/types/Header.d.ts +5 -0
  78. package/lib/types/Layout.d.ts +4 -0
  79. package/lib/types/Profile.d.ts +24 -0
  80. package/lib/types/SearchTrigger.d.ts +11 -0
  81. package/lib/types/Sider.d.ts +21 -0
  82. package/lib/types/index.d.ts +17 -1
  83. package/package.json +9 -7
@@ -0,0 +1,152 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { __rest } from 'tslib';
11
+ import React, { forwardRef, useCallback } from 'react';
12
+ import { getPrefixCls, cx } from '@hi-ui/classname';
13
+ import { __DEV__ } from '@hi-ui/env';
14
+ import { Popover } from './packages/ui/popover/lib/esm/index.js';
15
+ import './packages/icons/lib/esm/styles/index.scss.js';
16
+ import { CheckOutlined } from './packages/icons/lib/esm/components/alert/check-outlined.js';
17
+ import { RightOutlined } from './packages/icons/lib/esm/components/direction/right-outlined.js';
18
+ import { useUncontrolledToggle } from './packages/hooks/use-toggle/lib/esm/index.js';
19
+ import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
20
+ var PROFILE_PREFIX = getPrefixCls('profile');
21
+ var Profile = /*#__PURE__*/forwardRef(function (_a, ref) {
22
+ var _b;
23
+ var _a$prefixCls = _a.prefixCls,
24
+ prefixCls = _a$prefixCls === void 0 ? PROFILE_PREFIX : _a$prefixCls,
25
+ _a$role = _a.role,
26
+ role = _a$role === void 0 ? 'profile' : _a$role,
27
+ className = _a.className,
28
+ header = _a.header,
29
+ footer = _a.footer,
30
+ settings = _a.settings,
31
+ rest = __rest(_a, ["prefixCls", "role", "className", "children", "header", "footer", "settings"]);
32
+ var cls = cx(prefixCls, className);
33
+ var _useUncontrolledState = useUncontrolledState((_b = settings === null || settings === void 0 ? void 0 : settings.value) !== null && _b !== void 0 ? _b : {}, settings === null || settings === void 0 ? void 0 : settings.value),
34
+ value = _useUncontrolledState[0],
35
+ setValue = _useUncontrolledState[1];
36
+ return /*#__PURE__*/React.createElement("div", Object.assign({
37
+ ref: ref,
38
+ role: role,
39
+ className: cls
40
+ }, rest), /*#__PURE__*/React.createElement("div", {
41
+ className: prefixCls + "__header"
42
+ }, header), /*#__PURE__*/React.createElement("div", {
43
+ className: prefixCls + "__settings"
44
+ }, settings === null || settings === void 0 ? void 0 : settings.data.map(function (item) {
45
+ var _a, _b, _c, _d;
46
+ return /*#__PURE__*/React.createElement(Popover, Object.assign({
47
+ style: {
48
+ boxSizing: 'border-box',
49
+ width: 200,
50
+ padding: 8
51
+ }
52
+ }, !((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) ? {
53
+ visible: false
54
+ } : {}, {
55
+ key: item.id,
56
+ disabledPortal: true,
57
+ arrow: false,
58
+ placement: (_b = settings === null || settings === void 0 ? void 0 : settings.placement) !== null && _b !== void 0 ? _b : 'right-start',
59
+ content: /*#__PURE__*/React.createElement("div", null, (_c = item.children) === null || _c === void 0 ? void 0 : _c.map(function (child) {
60
+ var _cx;
61
+ var keys = Object.keys(value);
62
+ var currentKey = keys.find(function (key) {
63
+ return key === item.id;
64
+ }) || item.id;
65
+ var checked = currentKey && value[currentKey !== null && currentKey !== void 0 ? currentKey : ''] === child.id;
66
+ return /*#__PURE__*/React.createElement("div", {
67
+ key: child.id,
68
+ className: cx(prefixCls + "__settings-item-leaf", (_cx = {}, _cx[prefixCls + "__settings-item-leaf--checked"] = checked, _cx)),
69
+ onClick: function onClick(evt) {
70
+ var _Object$assign, _Object$assign2;
71
+ var _a, _b;
72
+ var nextValue = checked ? Object.assign(Object.assign({}, value), (_Object$assign = {}, _Object$assign[currentKey || ''] = '', _Object$assign)) : Object.assign(Object.assign({}, value), (_Object$assign2 = {}, _Object$assign2[currentKey || ''] = child.id || '', _Object$assign2));
73
+ setValue(nextValue);
74
+ (_a = settings === null || settings === void 0 ? void 0 : settings.onChange) === null || _a === void 0 ? void 0 : _a.call(settings, nextValue, child);
75
+ (_b = settings === null || settings === void 0 ? void 0 : settings.onItemClick) === null || _b === void 0 ? void 0 : _b.call(settings, evt, child);
76
+ }
77
+ }, /*#__PURE__*/React.createElement("div", {
78
+ className: prefixCls + "__settings-item-leaf__title"
79
+ }, child.title), /*#__PURE__*/React.createElement("div", {
80
+ className: prefixCls + "__settings-item-leaf__checked"
81
+ }, checked && /*#__PURE__*/React.createElement(CheckOutlined, null)));
82
+ }))
83
+ }), /*#__PURE__*/React.createElement("div", {
84
+ className: prefixCls + "__settings-item",
85
+ onClick: function onClick(evt) {
86
+ var _a;
87
+ return (_a = settings === null || settings === void 0 ? void 0 : settings.onItemClick) === null || _a === void 0 ? void 0 : _a.call(settings, evt, item);
88
+ }
89
+ }, /*#__PURE__*/React.createElement("div", {
90
+ className: prefixCls + "__settings-item__title-wrapper"
91
+ }, /*#__PURE__*/React.createElement("div", {
92
+ className: prefixCls + "__settings-item__title"
93
+ }, item.title), item.subtitle ? ( /*#__PURE__*/React.createElement("div", {
94
+ className: prefixCls + "__settings-item__subtitle"
95
+ }, item.subtitle)) : null), ((_d = item.children) === null || _d === void 0 ? void 0 : _d.length) ? ( /*#__PURE__*/React.createElement("div", {
96
+ className: prefixCls + "__settings-item__arrow"
97
+ }, /*#__PURE__*/React.createElement(RightOutlined, null))) : null));
98
+ })), /*#__PURE__*/React.createElement("div", {
99
+ className: prefixCls + "__footer"
100
+ }, /*#__PURE__*/React.createElement("div", {
101
+ className: prefixCls + "__footer__content"
102
+ }, footer)));
103
+ });
104
+ if (__DEV__) {
105
+ Profile.displayName = 'Profile';
106
+ }
107
+ var ProfilePopover = /*#__PURE__*/forwardRef(function (_a, ref) {
108
+ var onOpen = _a.onOpen,
109
+ onClose = _a.onClose,
110
+ visibleProp = _a.visible,
111
+ _a$placement = _a.placement,
112
+ placement = _a$placement === void 0 ? 'right-end' : _a$placement,
113
+ _a$trigger = _a.trigger,
114
+ trigger = _a$trigger === void 0 ? 'click' : _a$trigger,
115
+ children = _a.children,
116
+ restProps = __rest(_a, ["onOpen", "onClose", "visible", "placement", "trigger", "children"]);
117
+ var _useUncontrolledToggl = useUncontrolledToggle({
118
+ defaultVisible: false,
119
+ visible: visibleProp
120
+ }),
121
+ visible = _useUncontrolledToggl[0],
122
+ visibleAction = _useUncontrolledToggl[1];
123
+ var handleOpen = useCallback(function () {
124
+ visibleAction.on();
125
+ onOpen === null || onOpen === void 0 ? void 0 : onOpen();
126
+ }, [onOpen, visibleAction]);
127
+ var handleClose = useCallback(function () {
128
+ visibleAction.off();
129
+ onClose === null || onClose === void 0 ? void 0 : onClose();
130
+ }, [onClose, visibleAction]);
131
+ return /*#__PURE__*/React.createElement(Popover, {
132
+ style: {
133
+ boxSizing: 'border-box',
134
+ padding: 0,
135
+ overflow: 'auto'
136
+ },
137
+ visible: visible,
138
+ arrow: false,
139
+ trigger: trigger,
140
+ placement: placement,
141
+ gutterGap: 16,
142
+ content: /*#__PURE__*/React.createElement(Profile, Object.assign({
143
+ ref: ref
144
+ }, restProps)),
145
+ onOpen: handleOpen,
146
+ onClose: handleClose
147
+ }, children);
148
+ });
149
+ if (__DEV__) {
150
+ ProfilePopover.displayName = 'ProfilePopover';
151
+ }
152
+ export { Profile, ProfilePopover };
@@ -11,8 +11,11 @@ import { __rest } from 'tslib';
11
11
  import React, { forwardRef } from 'react';
12
12
  import { getPrefixCls, cx } from '@hi-ui/classname';
13
13
  import { __DEV__ } from '@hi-ui/env';
14
+ import { useLocaleContext } from '@hi-ui/core';
14
15
  import './packages/icons/lib/esm/styles/index.scss.js';
15
16
  import { SearchOutlined } from './packages/icons/lib/esm/components/common/search-outlined.js';
17
+ import Popper from '@hi-ui/popper';
18
+ import { MenuSearch } from '@hi-ui/menu';
16
19
  var SEARCH_TRIGGER_PREFIX = getPrefixCls('search-trigger');
17
20
  /**
18
21
  * 搜索触发器组件
@@ -25,17 +28,76 @@ var SearchTrigger = /*#__PURE__*/forwardRef(function (_a, ref) {
25
28
  role = _a$role === void 0 ? 'search-trigger' : _a$role,
26
29
  className = _a.className,
27
30
  mini = _a.mini,
28
- _a$placeholder = _a.placeholder,
29
- placeholder = _a$placeholder === void 0 ? '搜索' : _a$placeholder,
30
- rest = __rest(_a, ["prefixCls", "role", "className", "mini", "placeholder"]);
31
+ placeholder = _a.placeholder,
32
+ data = _a.data,
33
+ onClick = _a.onClick,
34
+ rest = __rest(_a, ["prefixCls", "role", "className", "mini", "placeholder", "data", "onClick"]);
35
+ var i18n = useLocaleContext();
36
+ var _React$useState = React.useState(false),
37
+ visible = _React$useState[0],
38
+ setVisible = _React$useState[1];
39
+ var _React$useState2 = React.useState(''),
40
+ value = _React$useState2[0],
41
+ setValue = _React$useState2[1];
42
+ var innerRef = React.useRef(null);
43
+ var searchRef = React.useRef(null);
31
44
  var cls = cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--mini"] = mini, _cx));
32
- return /*#__PURE__*/React.createElement("div", Object.assign({
33
- ref: ref,
45
+ var handleClick = function handleClick(evt) {
46
+ onClick === null || onClick === void 0 ? void 0 : onClick(evt);
47
+ if (evt.defaultPrevented) {
48
+ return;
49
+ }
50
+ setVisible(!visible);
51
+ };
52
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", Object.assign({
53
+ ref: innerRef,
34
54
  role: role,
35
- className: cls
36
- }, rest), /*#__PURE__*/React.createElement(SearchOutlined, null), !mini && /*#__PURE__*/React.createElement("span", {
55
+ className: cls,
56
+ onClick: handleClick
57
+ }, rest), /*#__PURE__*/React.createElement(SearchOutlined, null), !mini && ( /*#__PURE__*/React.createElement("span", {
37
58
  className: prefixCls + "__placeholder"
38
- }, placeholder));
59
+ }, placeholder || i18n.menuSearch.search))), /*#__PURE__*/React.createElement(Popper, {
60
+ classNames: {
61
+ container: prefixCls + "__popper-container"
62
+ },
63
+ visible: visible,
64
+ attachEl: innerRef.current,
65
+ gutterGap: -32,
66
+ unmountOnClose: false,
67
+ onOutsideClick: function onOutsideClick() {
68
+ var _a;
69
+ setVisible(false);
70
+ (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.hide();
71
+ },
72
+ onEntered: function onEntered() {
73
+ var _a, _b;
74
+ if (visible) {
75
+ (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.focus();
76
+ if (value) {
77
+ (_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.show();
78
+ }
79
+ }
80
+ }
81
+ }, /*#__PURE__*/React.createElement(MenuSearch, {
82
+ innerRef: searchRef,
83
+ width: 360,
84
+ value: value,
85
+ onChange: setValue,
86
+ data: data,
87
+ placeholder: i18n.menuSearch.placeholder,
88
+ onSelect: function onSelect(id, item) {
89
+ setVisible(false);
90
+ },
91
+ onClear: function onClear() {
92
+ setValue('');
93
+ },
94
+ onClose: function onClose() {
95
+ setVisible(false);
96
+ },
97
+ onEsc: function onEsc() {
98
+ setVisible(false);
99
+ }
100
+ })));
39
101
  });
40
102
  if (__DEV__) {
41
103
  SearchTrigger.displayName = 'SearchTrigger';
package/lib/esm/Sider.js CHANGED
@@ -14,6 +14,10 @@ import { __DEV__ } from '@hi-ui/env';
14
14
  import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
15
15
  import { Resizable } from './node_modules/react-resizable/index.js';
16
16
  var SIDER_PREFIX = getPrefixCls('sider');
17
+ var DEFAULT_SIDER_WIDTH = 180;
18
+ var SIDER_WIDTH_MIN = 60;
19
+ var SIDER_WIDTH_MIN_COLLAPSED = 150;
20
+ var SIDER_WIDTH_MAX = 360;
17
21
  /**
18
22
  * 侧边栏组件
19
23
  */
@@ -24,31 +28,40 @@ var Sider = /*#__PURE__*/forwardRef(function (_a, ref) {
24
28
  _a$role = _a.role,
25
29
  role = _a$role === void 0 ? 'sider' : _a$role,
26
30
  className = _a.className,
31
+ widthProp = _a.width,
32
+ maxWidthProp = _a.maxWidth,
33
+ _a$resizable = _a.resizable,
34
+ resizable = _a$resizable === void 0 ? true : _a$resizable,
27
35
  collapsedProp = _a.collapsed,
28
36
  onCollapse = _a.onCollapse,
29
37
  children = _a.children,
30
- rest = __rest(_a, ["prefixCls", "role", "className", "collapsed", "onCollapse", "children"]);
38
+ rest = __rest(_a, ["prefixCls", "role", "className", "width", "maxWidth", "resizable", "collapsed", "onCollapse", "children"]);
31
39
  var _useUncontrolledState = useUncontrolledState(false, collapsedProp, onCollapse),
32
40
  collapsed = _useUncontrolledState[0],
33
41
  setCollapsed = _useUncontrolledState[1];
34
- var _useState = useState(collapsedProp ? 68 : 200),
42
+ var siderWidth = widthProp || DEFAULT_SIDER_WIDTH;
43
+ var _useState = useState(collapsedProp ? SIDER_WIDTH_MIN : siderWidth),
35
44
  width = _useState[0],
36
45
  setWidth = _useState[1];
46
+ var maxWidth = maxWidthProp || SIDER_WIDTH_MAX;
37
47
  var handleResize = function handleResize(evt, options) {
38
48
  var _a;
39
49
  var width = (_a = options === null || options === void 0 ? void 0 : options.size) === null || _a === void 0 ? void 0 : _a.width;
40
- if (!collapsed && width < 150) {
41
- width = 68;
50
+ if (!collapsed && width < SIDER_WIDTH_MIN_COLLAPSED) {
51
+ width = SIDER_WIDTH_MIN;
42
52
  setCollapsed(true);
43
53
  }
44
- if (collapsed && width > 68) {
45
- width = 200;
54
+ if (collapsed && width > SIDER_WIDTH_MIN) {
55
+ width = siderWidth;
46
56
  setTimeout(function () {
47
57
  setCollapsed(false);
48
58
  }, 300);
49
59
  }
50
- if (width < 68) {
51
- width = 68;
60
+ if (width <= SIDER_WIDTH_MIN) {
61
+ width = SIDER_WIDTH_MIN;
62
+ }
63
+ if (width > maxWidth) {
64
+ width = maxWidth;
52
65
  }
53
66
  setWidth(width);
54
67
  };
@@ -59,7 +72,16 @@ var Sider = /*#__PURE__*/forwardRef(function (_a, ref) {
59
72
  document.body.style.userSelect = 'auto';
60
73
  }, []);
61
74
  var cls = cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--collapsed"] = collapsed, _cx));
62
- return /*#__PURE__*/React.createElement(Resizable, {
75
+ var Content = /*#__PURE__*/React.createElement("div", Object.assign({
76
+ ref: ref,
77
+ role: role,
78
+ className: cls
79
+ }, rest, {
80
+ style: Object.assign({
81
+ width: width
82
+ }, rest.style)
83
+ }), children);
84
+ return resizable ? ( /*#__PURE__*/React.createElement(Resizable, {
63
85
  className: prefixCls + "__resizable",
64
86
  draggableOpts: {
65
87
  enableUserSelectHack: false
@@ -72,15 +94,7 @@ var Sider = /*#__PURE__*/forwardRef(function (_a, ref) {
72
94
  onResize: handleResize,
73
95
  onResizeStart: handleResizeStart,
74
96
  onResizeStop: handleResizeStop
75
- }, /*#__PURE__*/React.createElement("div", Object.assign({
76
- ref: ref,
77
- role: role,
78
- className: cls
79
- }, rest, {
80
- style: Object.assign({
81
- width: width
82
- }, rest.style)
83
- }), children));
97
+ }, Content)) : Content;
84
98
  });
85
99
  if (__DEV__) {
86
100
  Sider.displayName = 'Sider';
package/lib/esm/index.js CHANGED
@@ -8,7 +8,25 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import './styles/index.scss.js';
11
- export { Layout, Layout as default } from './Layout.js';
12
- export { Sider } from './Sider.js';
13
- export { Content } from './Content.js';
14
- export { SearchTrigger } from './SearchTrigger.js';
11
+ import { Layout as Layout$1 } from './Layout.js';
12
+ import { Header } from './Header.js';
13
+ import { Sider } from './Sider.js';
14
+ import { Content } from './Content.js';
15
+ import { Footer } from './Footer.js';
16
+ import { SearchTrigger } from './SearchTrigger.js';
17
+ import { FloatMenuContainer } from './FloatMenuContainer.js';
18
+ import { AppListPopover } from './AppList.js';
19
+ export { AppList, IconBgColorMap } from './AppList.js';
20
+ import { ProfilePopover } from './Profile.js';
21
+ export { Profile } from './Profile.js';
22
+ var Layout = Object.assign(Layout$1, {
23
+ Header: Header,
24
+ Sider: Sider,
25
+ Content: Content,
26
+ Footer: Footer,
27
+ SearchTrigger: SearchTrigger,
28
+ FloatMenuContainer: FloatMenuContainer,
29
+ AppListPopover: AppListPopover,
30
+ ProfilePopover: ProfilePopover
31
+ });
32
+ export { AppListPopover, Content, FloatMenuContainer, Footer, Header, Layout$1 as Layout, ProfilePopover, SearchTrigger, Sider, Layout as default };
@@ -0,0 +1,45 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { useMemo } from 'react';
11
+ import v4 from '../../node_modules/uuid/dist/esm-browser/v4.js';
12
+
13
+ /** @LICENSE
14
+ * @hi-ui/use-id
15
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-id#readme
16
+ *
17
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
18
+ *
19
+ * This source code is licensed under the MIT license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+
23
+ /**
24
+ * Generate a uuid.
25
+ */
26
+ var uuid = function uuid() {
27
+ return v4();
28
+ };
29
+ var IdGenerator = function IdGenerator() {
30
+ var _this = this;
31
+ this.id = 0;
32
+ this.next = function () {
33
+ return ++_this.id;
34
+ };
35
+ };
36
+ var idGenerator = new IdGenerator();
37
+ /**
38
+ * A hook to generate a uid
39
+ */
40
+ var useUID = function useUID(prefix) {
41
+ return useMemo(function () {
42
+ return prefix + '-' + idGenerator.next();
43
+ }, [prefix]);
44
+ };
45
+ export { useUID, uuid };
@@ -0,0 +1,11 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
11
+ export { REGEX as default };
@@ -0,0 +1,27 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
11
+ // require the crypto API and do not support built-in fallback to lower quality random number
12
+ // generators (like Math.random()).
13
+ var getRandomValues;
14
+ var rnds8 = new Uint8Array(16);
15
+ function rng() {
16
+ // lazy load so that environments that need to polyfill have a chance to do so
17
+ if (!getRandomValues) {
18
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
19
+ // find the complete implementation of crypto (msCrypto) on IE11.
20
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
21
+ if (!getRandomValues) {
22
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
23
+ }
24
+ }
25
+ return getRandomValues(rnds8);
26
+ }
27
+ export { rng as default };
@@ -0,0 +1,36 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import validate from './validate.js';
11
+
12
+ /**
13
+ * Convert array of 16 byte values to UUID string format of the form:
14
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
15
+ */
16
+
17
+ var byteToHex = [];
18
+ for (var i = 0; i < 256; ++i) {
19
+ byteToHex.push((i + 0x100).toString(16).substr(1));
20
+ }
21
+ function stringify(arr) {
22
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
23
+ // Note: Be careful editing this code! It's been tuned for performance
24
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
25
+ var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
26
+ // of the following:
27
+ // - One or more input array values don't map to a hex octet (leading to
28
+ // "undefined" in the uuid)
29
+ // - Invalid input values for the RFC `version` or `variant` fields
30
+
31
+ if (!validate(uuid)) {
32
+ throw TypeError('Stringified UUID is invalid');
33
+ }
34
+ return uuid;
35
+ }
36
+ export { stringify as default };
@@ -0,0 +1,28 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import rng from './rng.js';
11
+ import stringify from './stringify.js';
12
+ function v4(options, buf, offset) {
13
+ options = options || {};
14
+ var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
15
+
16
+ rnds[6] = rnds[6] & 0x0f | 0x40;
17
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
18
+
19
+ if (buf) {
20
+ offset = offset || 0;
21
+ for (var i = 0; i < 16; ++i) {
22
+ buf[offset + i] = rnds[i];
23
+ }
24
+ return buf;
25
+ }
26
+ return stringify(rnds);
27
+ }
28
+ export { v4 as default };
@@ -0,0 +1,14 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import REGEX from './regex.js';
11
+ function validate(uuid) {
12
+ return typeof uuid === 'string' && REGEX.test(uuid);
13
+ }
14
+ export { validate as default };
@@ -0,0 +1,50 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { useCallback, useRef } from 'react';
11
+
12
+ /** @LICENSE
13
+ * @hi-ui/use-latest
14
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-latest#readme
15
+ *
16
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
17
+ *
18
+ * This source code is licensed under the MIT license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ */
21
+
22
+ /**
23
+ * Keep value up-to-date if it changes.
24
+ *
25
+ * @param value
26
+ * @returns
27
+ */
28
+ var useLatestRef = function useLatestRef(value) {
29
+ var ref = useRef(value);
30
+ ref.current = value;
31
+ return ref;
32
+ };
33
+ /**
34
+ * Keep callback function up-to-date if it changes.
35
+ *
36
+ * @param callback
37
+ * @returns
38
+ */
39
+ var useLatestCallback = function useLatestCallback(callback) {
40
+ var ref = useLatestRef(callback);
41
+ return useCallback(function () {
42
+ var _a2;
43
+ var _a;
44
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45
+ args[_key] = arguments[_key];
46
+ }
47
+ return (_a = ref.current) === null || _a === void 0 ? void 0 : (_a2 = _a).call.apply(_a2, [ref].concat(args));
48
+ }, []);
49
+ };
50
+ export { useLatestCallback, useLatestRef };
@@ -0,0 +1,45 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { useRef, useCallback } from 'react';
11
+ import { useLatestCallback } from '../../../use-latest/lib/esm/index.js';
12
+
13
+ /** @LICENSE
14
+ * @hi-ui/use-timeout
15
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-timeout#readme
16
+ *
17
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
18
+ *
19
+ * This source code is licensed under the MIT license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+
23
+ /**
24
+ * TODO: What is useTimeout
25
+ * 1. 负责props变化需要取消定时器以及页面卸载时取消定时器这一套逻辑
26
+ * 2. 处理 window 支持 SSR
27
+ */
28
+ var useTimeout = function useTimeout(callback, timeoutDelayMs) {
29
+ var timerRef = useRef(undefined);
30
+ var callbackLatest = useLatestCallback(callback);
31
+ var clear = useCallback(function () {
32
+ if (timerRef.current === undefined) return;
33
+ window.clearTimeout(timerRef.current);
34
+ timerRef.current = undefined;
35
+ }, []);
36
+ var start = useCallback(function () {
37
+ if (typeof timeoutDelayMs !== 'number' || timeoutDelayMs < 0) return;
38
+ timerRef.current = window.setTimeout(callbackLatest, timeoutDelayMs);
39
+ }, [callbackLatest, timeoutDelayMs]);
40
+ return {
41
+ start: start,
42
+ clear: clear
43
+ };
44
+ };
45
+ export { useTimeout };