@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,66 @@
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 { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
12
+ import { useLatestCallback } from '../../../use-latest/lib/esm/index.js';
13
+
14
+ /** @LICENSE
15
+ * @hi-ui/use-toggle
16
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-toggle#readme
17
+ *
18
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
19
+ *
20
+ * This source code is licensed under the MIT license found in the
21
+ * LICENSE file in the root directory of this source tree.
22
+ */
23
+ /**
24
+ * Handles uncontrolled boolean switching by `on`, `off`, `not`
25
+ */
26
+ function useUncontrolledToggle(_ref) {
27
+ var _ref$defaultVisible = _ref.defaultVisible,
28
+ defaultVisible = _ref$defaultVisible === void 0 ? false : _ref$defaultVisible,
29
+ visibleProp = _ref.visible,
30
+ onClose = _ref.onClose,
31
+ onOpen = _ref.onOpen,
32
+ onToggle = _ref.onToggle,
33
+ isEqual = _ref.isEqual,
34
+ _ref$disabled = _ref.disabled,
35
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
36
+ var onVisibleChange = useLatestCallback(function (nextVisible) {
37
+ var callback = nextVisible ? onOpen : onClose;
38
+ callback === null || callback === void 0 ? void 0 : callback();
39
+ onToggle === null || onToggle === void 0 ? void 0 : onToggle(nextVisible);
40
+ });
41
+ var _useUncontrolledState = useUncontrolledState(defaultVisible, visibleProp, onVisibleChange, isEqual),
42
+ bool = _useUncontrolledState[0],
43
+ setBool = _useUncontrolledState[1];
44
+ var proxySetBool = useLatestCallback(function (stateOrFunction) {
45
+ if (disabled) return;
46
+ setBool(stateOrFunction);
47
+ });
48
+ var toggle = useMemo(function () {
49
+ return {
50
+ set: proxySetBool,
51
+ on: function on() {
52
+ proxySetBool(true);
53
+ },
54
+ off: function off() {
55
+ proxySetBool(false);
56
+ },
57
+ not: function not() {
58
+ proxySetBool(function (prev) {
59
+ return !prev;
60
+ });
61
+ }
62
+ };
63
+ }, [proxySetBool]);
64
+ return [bool, toggle];
65
+ }
66
+ export { useUncontrolledToggle };
@@ -0,0 +1,39 @@
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, useEffect } from 'react';
11
+ import { useLatestCallback } from '../../../use-latest/lib/esm/index.js';
12
+
13
+ /** @LICENSE
14
+ * @hi-ui/use-unmount-effect
15
+ * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-unmount-effect#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
+ * A hook for running when component unmount, will return unmountRef sign
25
+ */
26
+ var useUnmountEffect = function useUnmountEffect(cleanup) {
27
+ var cleanupLatest = useLatestCallback(cleanup);
28
+ var unmountRef = useRef(false);
29
+ useEffect(function () {
30
+ return function () {
31
+ unmountRef.current = true;
32
+ cleanupLatest();
33
+ };
34
+ },
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ []);
37
+ return unmountRef;
38
+ };
39
+ export { useUnmountEffect };
@@ -0,0 +1,53 @@
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 } from 'react';
12
+ import { getPrefixCls, cx } from '@hi-ui/classname';
13
+ import { __DEV__ } from '@hi-ui/env';
14
+
15
+ /** @LICENSE
16
+ * @hi-ui/icons
17
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/icons#readme
18
+ *
19
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
20
+ *
21
+ * This source code is licensed under the MIT license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ */
24
+ var _prefix = getPrefixCls('icon-check-outlined');
25
+ var CheckOutlined = /*#__PURE__*/forwardRef(function (_a, ref) {
26
+ var _a$prefixCls = _a.prefixCls,
27
+ prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
28
+ className = _a.className,
29
+ size = _a.size,
30
+ styleProp = _a.style,
31
+ rest = __rest(_a, ["prefixCls", "className", "children", "size", "style"]);
32
+ var cls = cx(prefixCls, className);
33
+ var style = Object.assign({
34
+ fontSize: size
35
+ }, styleProp);
36
+ return /*#__PURE__*/React.createElement("svg", Object.assign({
37
+ className: cls,
38
+ ref: ref,
39
+ role: "icon",
40
+ style: style
41
+ }, rest, {
42
+ xmlns: "http://www.w3.org/2000/svg",
43
+ viewBox: "0 0 1024 1024",
44
+ version: "1.1"
45
+ }), /*#__PURE__*/React.createElement("path", {
46
+ d: "M840.832 328.832a42.666667 42.666667 0 0 0-57.621333-62.826667l-2.709334 2.496L405.333333 643.626667l-161.834666-161.813334a42.666667 42.666667 0 0 0-57.621334-2.496l-2.709333 2.496a42.666667 42.666667 0 0 0-2.496 57.621334l2.496 2.709333 192 192a42.666667 42.666667 0 0 0 57.621333 2.496l2.709334-2.496 405.333333-405.333333z",
47
+ "p-id": "47651"
48
+ }));
49
+ });
50
+ if (__DEV__) {
51
+ CheckOutlined.displayName = 'CheckOutlined';
52
+ }
53
+ export { CheckOutlined };
@@ -0,0 +1,53 @@
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 } from 'react';
12
+ import { getPrefixCls, cx } from '@hi-ui/classname';
13
+ import { __DEV__ } from '@hi-ui/env';
14
+
15
+ /** @LICENSE
16
+ * @hi-ui/icons
17
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/icons#readme
18
+ *
19
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
20
+ *
21
+ * This source code is licensed under the MIT license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ */
24
+ var _prefix = getPrefixCls('icon-right-outlined');
25
+ var RightOutlined = /*#__PURE__*/forwardRef(function (_a, ref) {
26
+ var _a$prefixCls = _a.prefixCls,
27
+ prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
28
+ className = _a.className,
29
+ size = _a.size,
30
+ styleProp = _a.style,
31
+ rest = __rest(_a, ["prefixCls", "className", "children", "size", "style"]);
32
+ var cls = cx(prefixCls, className);
33
+ var style = Object.assign({
34
+ fontSize: size
35
+ }, styleProp);
36
+ return /*#__PURE__*/React.createElement("svg", Object.assign({
37
+ className: cls,
38
+ ref: ref,
39
+ role: "icon",
40
+ style: style
41
+ }, rest, {
42
+ xmlns: "http://www.w3.org/2000/svg",
43
+ viewBox: "0 0 1024 1024",
44
+ version: "1.1"
45
+ }), /*#__PURE__*/React.createElement("path", {
46
+ d: "M414.165333 225.834667a42.666667 42.666667 0 0 0-62.826666 57.621333l2.496 2.709333L579.626667 512 353.834667 737.834667a42.666667 42.666667 0 0 0-2.496 57.621333l2.496 2.709333a42.666667 42.666667 0 0 0 57.621333 2.496l2.709333-2.496 256-256a42.666667 42.666667 0 0 0 2.496-57.621333l-2.496-2.709333-256-256z",
47
+ "p-id": "49596"
48
+ }));
49
+ });
50
+ if (__DEV__) {
51
+ RightOutlined.displayName = 'RightOutlined';
52
+ }
53
+ export { RightOutlined };
@@ -0,0 +1,97 @@
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, useImperativeHandle, useMemo, isValidElement, cloneElement } from 'react';
12
+ import { getPrefixCls, cx } from '@hi-ui/classname';
13
+ import { __DEV__, invariant } from '@hi-ui/env';
14
+ import Popper from '@hi-ui/popper';
15
+ import { usePopover } from './use-popover.js';
16
+ import { isString } from '../../../../utils/type-assertion/lib/esm/index.js';
17
+
18
+ /** @LICENSE
19
+ * @hi-ui/popover
20
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/popover#readme
21
+ *
22
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
23
+ *
24
+ * This source code is licensed under the MIT license found in the
25
+ * LICENSE file in the root directory of this source tree.
26
+ */
27
+ var _role = 'popover';
28
+ var prefix = getPrefixCls(_role);
29
+ /**
30
+ * 气泡卡片
31
+ */
32
+ var Popover = /*#__PURE__*/forwardRef(function (_a, ref) {
33
+ var _a$prefixCls = _a.prefixCls,
34
+ prefixCls = _a$prefixCls === void 0 ? prefix : _a$prefixCls,
35
+ innerRef = _a.innerRef,
36
+ className = _a.className,
37
+ children = _a.children,
38
+ title = _a.title,
39
+ content = _a.content,
40
+ _a$shouldWrapChildren = _a.shouldWrapChildren,
41
+ shouldWrapChildren = _a$shouldWrapChildren === void 0 ? false : _a$shouldWrapChildren,
42
+ _a$autoWrapChildren = _a.autoWrapChildren,
43
+ autoWrapChildren = _a$autoWrapChildren === void 0 ? true : _a$autoWrapChildren,
44
+ _a$wrapTagName = _a.wrapTagName,
45
+ wrapTagName = _a$wrapTagName === void 0 ? 'span' : _a$wrapTagName,
46
+ _a$showTitleDivider = _a.showTitleDivider,
47
+ showTitleDivider = _a$showTitleDivider === void 0 ? false : _a$showTitleDivider,
48
+ rest = __rest(_a, ["prefixCls", "innerRef", "className", "children", "title", "content", "shouldWrapChildren", "autoWrapChildren", "wrapTagName", "showTitleDivider"]);
49
+ var _usePopover = usePopover(rest),
50
+ rootProps = _usePopover.rootProps,
51
+ getTriggerProps = _usePopover.getTriggerProps,
52
+ getPopperProps = _usePopover.getPopperProps,
53
+ getOverlayProps = _usePopover.getOverlayProps,
54
+ visibleAction = _usePopover.visibleAction;
55
+ useImperativeHandle(innerRef, function () {
56
+ return {
57
+ open: visibleAction.on,
58
+ close: visibleAction.off
59
+ };
60
+ });
61
+ var triggerMemo = useMemo(function () {
62
+ var trigger;
63
+ if ( /*#__PURE__*/isValidElement(children)) {
64
+ trigger = /*#__PURE__*/cloneElement(children,
65
+ // @ts-ignore
66
+ getTriggerProps(children.props, children.ref));
67
+ } else {
68
+ var TagName = wrapTagName;
69
+ if (shouldWrapChildren || autoWrapChildren && isString(children)) {
70
+ trigger = /*#__PURE__*/React.createElement(TagName, Object.assign({
71
+ tabIndex: 0
72
+ }, getTriggerProps()), children);
73
+ } else {
74
+ trigger = children;
75
+ if (__DEV__) {
76
+ invariant(false, 'Make sure that the children supports the event corresponding to the trigger, you can set `shouldWrapChildren=true` to solve it.');
77
+ }
78
+ }
79
+ }
80
+ return trigger;
81
+ }, [children, getTriggerProps, autoWrapChildren, shouldWrapChildren, wrapTagName]);
82
+ var cls = cx(prefixCls, showTitleDivider && prefixCls + "--divided", className);
83
+ return /*#__PURE__*/React.createElement(React.Fragment, null, triggerMemo, /*#__PURE__*/React.createElement(Popper, Object.assign({}, getPopperProps(), getOverlayProps(), {
84
+ autoFocus: false
85
+ }), /*#__PURE__*/React.createElement("div", Object.assign({
86
+ ref: ref,
87
+ className: cls
88
+ }, rootProps), title ? /*#__PURE__*/React.createElement("div", {
89
+ className: prefixCls + "__title"
90
+ }, title) : null, /*#__PURE__*/React.createElement("div", {
91
+ className: prefixCls + "__content"
92
+ }, content))));
93
+ });
94
+ if (__DEV__) {
95
+ Popover.displayName = 'Popover';
96
+ }
97
+ export { Popover, prefix };
@@ -0,0 +1,25 @@
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 './styles/index.scss.js';
11
+ import { Popover as Popover$1 } from './Popover.js';
12
+ export { prefix } from './Popover.js';
13
+ import { withPopover } from './with-api.js';
14
+
15
+ /** @LICENSE
16
+ * @hi-ui/popover
17
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/popover#readme
18
+ *
19
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
20
+ *
21
+ * This source code is licensed under the MIT license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ */
24
+ var Popover = withPopover(Popover$1);
25
+ export { Popover, Popover as default };
@@ -0,0 +1,23 @@
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 __styleInject__ from '@hi-ui/style-inject';
11
+
12
+ /** @LICENSE
13
+ * @hi-ui/popover
14
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/popover#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
+ var css_248z = ".hi-v5-popover {overflow-wrap: break-word;font-size: var(--hi-v5-text-size-md, 0.875rem);line-height: var(--hi-v5-text-lineheight-md, 1.375rem);background: var(--hi-v5-color-static-white, #fff);padding: var(--hi-v5-spacing-6, 12px) var(--hi-v5-spacing-8, 16px);border-radius: var(--hi-v5-border-radius-xl, 8px);border: var(--hi-v5-border-size-normal, 1px solid) var(--hi-v5-color-gray-200, #e6e8eb);}.hi-v5-popover__title {-webkit-box-sizing: border-box;box-sizing: border-box;margin-bottom: var(--hi-v5-spacing-2, 4px);color: var(--hi-v5-color-gray-700, #1a1d26);font-size: var(--hi-v5-text-size-md, 0.875rem);font-weight: var(--hi-v5-text-weight-medium, 500);line-height: var(--hi-v5-text-lineheight-md, 1.375rem);}.hi-v5-popover--divided > .hi-v5-popover__title {padding-bottom: var(--hi-v5-spacing-6, 12px);margin-bottom: var(--hi-v5-spacing-6, 12px);font-size: var(--hi-v5-text-size-md, 0.875rem);line-height: var(--hi-v5-text-lineheight-md, 1.375rem);border-bottom: var(--hi-v5-border-size-normal, 1px solid) var(--hi-v5-color-gray-200, #e6e8eb);}.hi-v5-popover__content {-webkit-box-sizing: border-box;box-sizing: border-box;color: var(--hi-v5-color-gray-700, #1a1d26);line-height: var(--hi-v5-text-lineheight-md, 1.375rem);font-size: var(--hi-v5-text-size-md, 0.875rem);}";
22
+ __styleInject__(css_248z);
23
+ export { css_248z as default };
@@ -0,0 +1,25 @@
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
+ /** @LICENSE
11
+ * @hi-ui/popover
12
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/popover#readme
13
+ *
14
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ */
19
+ var PopoverTriggerActionEnum = {
20
+ CLICK: 'click',
21
+ CONTEXTMENU: 'contextmenu',
22
+ HOVER: 'hover',
23
+ FOCUS: 'focus'
24
+ };
25
+ export { PopoverTriggerActionEnum };
@@ -0,0 +1,175 @@
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, { useCallback } from 'react';
12
+ import { PopoverTriggerActionEnum } from './types.js';
13
+ import { useUncontrolledToggle } from '../../../../hooks/use-toggle/lib/esm/index.js';
14
+ import { omitPopperOverlayProps } from '@hi-ui/popper';
15
+ import { mockDefaultHandlers } from '../../../../utils/dom-utils/lib/esm/index.js';
16
+ import { mergeRefs, withDefaultProps } from '../../../../utils/react-utils/lib/esm/index.js';
17
+ import { useUID } from '../../../../hooks/use-id/lib/esm/index.js';
18
+ import { useUnmountEffect } from '../../../../hooks/use-unmount-effect/lib/esm/index.js';
19
+ import { normalizeArray } from '../../../../utils/array-utils/lib/esm/index.js';
20
+ import { useTimeout } from '../../../../hooks/use-timeout/lib/esm/index.js';
21
+ import { useLatestCallback } from '../../../../hooks/use-latest/lib/esm/index.js';
22
+
23
+ /** @LICENSE
24
+ * @hi-ui/popover
25
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/popover#readme
26
+ *
27
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
28
+ *
29
+ * This source code is licensed under the MIT license found in the
30
+ * LICENSE file in the root directory of this source tree.
31
+ */
32
+
33
+ // TODO: 和 Tooltip 复用
34
+ var usePopover = function usePopover(_a) {
35
+ var visibleProp = _a.visible,
36
+ onOpen = _a.onOpen,
37
+ _onClose = _a.onClose,
38
+ _a$trigger = _a.trigger,
39
+ triggerProp = _a$trigger === void 0 ? 'click' : _a$trigger,
40
+ _a$mouseEnterDelay = _a.mouseEnterDelay,
41
+ mouseEnterDelay = _a$mouseEnterDelay === void 0 ? 100 : _a$mouseEnterDelay,
42
+ _a$mouseLeaveDelay = _a.mouseLeaveDelay,
43
+ mouseLeaveDelay = _a$mouseLeaveDelay === void 0 ? 100 : _a$mouseLeaveDelay,
44
+ attachEl = _a.attachEl,
45
+ popperClassName = _a.popperClassName,
46
+ restProps = __rest(_a, ["visible", "onOpen", "onClose", "trigger", "mouseEnterDelay", "mouseLeaveDelay", "attachEl", "popperClassName"]);
47
+ // TODO: 移除 popper,使用 hook 重写
48
+ var _omitPopperOverlayPro = omitPopperOverlayProps(restProps),
49
+ popper = _omitPopperOverlayPro[0],
50
+ rest = _omitPopperOverlayPro[1];
51
+ var _useUncontrolledToggl = useUncontrolledToggle({
52
+ defaultVisible: false,
53
+ visible: visibleProp,
54
+ onOpen: onOpen,
55
+ onClose: function onClose() {
56
+ clearToggleTimer();
57
+ _onClose === null || _onClose === void 0 ? void 0 : _onClose();
58
+ }
59
+ }),
60
+ visible = _useUncontrolledToggl[0],
61
+ visibleAction = _useUncontrolledToggl[1];
62
+ var _useTimeout = useTimeout(function () {
63
+ visibleAction.on();
64
+ }, mouseEnterDelay),
65
+ startOpenTimer = _useTimeout.start,
66
+ clearOpenTimer = _useTimeout.clear;
67
+ var _useTimeout2 = useTimeout(function () {
68
+ if (hoveringRef.current) return;
69
+ visibleAction.off();
70
+ }, mouseLeaveDelay),
71
+ startCloseTimer = _useTimeout2.start,
72
+ clearCloseTimer = _useTimeout2.clear;
73
+ var clearToggleTimer = useCallback(function () {
74
+ clearOpenTimer();
75
+ clearCloseTimer();
76
+ }, [clearOpenTimer, clearCloseTimer]);
77
+ useUnmountEffect(clearToggleTimer);
78
+ var _React$useState = React.useState(null),
79
+ triggerEl = _React$useState[0],
80
+ setTriggerEl = _React$useState[1];
81
+ var hoveringRef = React.useRef(false);
82
+ var trigger = normalizeArray(triggerProp);
83
+ // eslint-disable-next-line react-hooks/exhaustive-deps
84
+ var triggersMemo = React.useMemo(function () {
85
+ return trigger;
86
+ }, trigger);
87
+ var popoverId = useUID('popover');
88
+ var handlePopoverLeave = useLatestCallback(function () {
89
+ hoveringRef.current = false;
90
+ clearOpenTimer();
91
+ startCloseTimer();
92
+ });
93
+ var handlePopoverEnter = useLatestCallback(function () {
94
+ hoveringRef.current = true;
95
+ startOpenTimer();
96
+ });
97
+ var getOverlayProps = React.useCallback(function (props, ref) {
98
+ if (props === void 0) {
99
+ props = {};
100
+ }
101
+ if (ref === void 0) {
102
+ ref = null;
103
+ }
104
+ var popoverProps = Object.assign(Object.assign({}, props), {
105
+ ref: ref,
106
+ role: 'dialog',
107
+ id: popoverId
108
+ });
109
+ if (triggersMemo.includes(PopoverTriggerActionEnum.HOVER)) {
110
+ popoverProps.onMouseEnter = mockDefaultHandlers(props.onMouseEnter, function () {
111
+ hoveringRef.current = true;
112
+ });
113
+ popoverProps.onMouseLeave = mockDefaultHandlers(props.onMouseLeave, handlePopoverLeave);
114
+ }
115
+ return popoverProps;
116
+ }, [triggersMemo, popoverId, handlePopoverLeave]);
117
+ var getTriggerProps = React.useCallback(function (props, ref) {
118
+ if (props === void 0) {
119
+ props = {};
120
+ }
121
+ if (ref === void 0) {
122
+ ref = null;
123
+ }
124
+ var triggerProps = Object.assign(Object.assign({}, props), {
125
+ ref: mergeRefs(setTriggerEl, ref),
126
+ 'aria-controls': popoverId,
127
+ 'aria-haspopup': 'dialog',
128
+ 'aria-expanded': visible
129
+ });
130
+ if (triggersMemo.includes(PopoverTriggerActionEnum.CLICK)) {
131
+ triggerProps.onClick = mockDefaultHandlers(props.onClick, visibleAction.not);
132
+ }
133
+ if (triggersMemo.includes(PopoverTriggerActionEnum.HOVER)) {
134
+ // @ref https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus.html
135
+ triggerProps.onFocus = mockDefaultHandlers(props.onFocus, visibleAction.on);
136
+ triggerProps.onBlur = mockDefaultHandlers(props.onBlur, visibleAction.off);
137
+ triggerProps.onMouseEnter = mockDefaultHandlers(props.onMouseEnter, handlePopoverEnter);
138
+ triggerProps.onMouseLeave = mockDefaultHandlers(props.onMouseLeave, handlePopoverLeave);
139
+ } else if (triggersMemo.includes(PopoverTriggerActionEnum.FOCUS)) {
140
+ triggerProps.onFocus = mockDefaultHandlers(props.onFocus, visibleAction.on);
141
+ triggerProps.onBlur = mockDefaultHandlers(props.onBlur, visibleAction.off);
142
+ }
143
+ if (triggersMemo.includes(PopoverTriggerActionEnum.CONTEXTMENU)) {
144
+ triggerProps.onContextMenu = mockDefaultHandlers(props.onContextMenu, function (evt) {
145
+ evt.preventDefault();
146
+ visibleAction.not();
147
+ });
148
+ }
149
+ return triggerProps;
150
+ }, [triggersMemo, popoverId, visibleAction, visible, handlePopoverEnter, handlePopoverLeave]);
151
+ var getPopperProps = React.useCallback(function () {
152
+ var popperProps = withDefaultProps(popper, {
153
+ arrow: true,
154
+ placement: 'top',
155
+ // @DesignToken zIndex: `popper`
156
+ zIndex: 1030,
157
+ // @DesignToken 10
158
+ gutterGap: 14
159
+ });
160
+ return Object.assign(Object.assign({}, popperProps), {
161
+ visible: visible,
162
+ attachEl: attachEl !== null && attachEl !== void 0 ? attachEl : triggerEl,
163
+ onClose: visibleAction.off,
164
+ className: popperClassName
165
+ });
166
+ }, [popper, visible, attachEl, triggerEl, visibleAction.off, popperClassName]);
167
+ return {
168
+ rootProps: rest,
169
+ getOverlayProps: getOverlayProps,
170
+ getTriggerProps: getTriggerProps,
171
+ getPopperProps: getPopperProps,
172
+ visibleAction: visibleAction
173
+ };
174
+ };
175
+ export { usePopover };
@@ -0,0 +1,60 @@
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
+ /** @LICENSE
11
+ * @hi-ui/popover
12
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/popover#readme
13
+ *
14
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ */
19
+ /** @LICENSE
20
+ * @hi-ui/container
21
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/container#readme
22
+ *
23
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
24
+ *
25
+ * This source code is licensed under the MIT license found in the
26
+ * LICENSE file in the root directory of this source tree.
27
+ */
28
+ /**
29
+ * 获取用于承载组件的容器,将挂载在 body 下面
30
+ *
31
+ * @param selector 以 `.` 开头的选择器类
32
+ * @returns 容器元素
33
+ */
34
+ var getContainer = function getContainer(selector, doc, customWrapper) {
35
+ if (doc === void 0) {
36
+ doc = document;
37
+ }
38
+ var rootElm = doc.querySelector(selector);
39
+ if (rootElm) return rootElm;
40
+ rootElm = doc.createElement('div');
41
+ rootElm.className = selector.slice(1);
42
+ var wrapper = customWrapper !== null && customWrapper !== void 0 ? customWrapper : doc.body;
43
+ wrapper.appendChild(rootElm);
44
+ return rootElm;
45
+ };
46
+ /**
47
+ * 从 DOM 中移除指定的承载容器
48
+ *
49
+ * @param selector 以 `.` 开头的选择器类
50
+ */
51
+ var removeContainer = function removeContainer(selector, doc) {
52
+ if (doc === void 0) {
53
+ doc = document;
54
+ }
55
+ var rootElm = doc.querySelector(selector);
56
+ if (rootElm && rootElm.parentNode) {
57
+ rootElm.parentNode.removeChild(rootElm);
58
+ }
59
+ };
60
+ export { getContainer, removeContainer };