@doist/reactist 10.0.0-beta.7 → 11.0.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.
- package/dist/reactist.cjs.development.js +253 -411
- package/dist/reactist.cjs.development.js.map +1 -1
- package/dist/reactist.cjs.production.min.js +1 -1
- package/dist/reactist.cjs.production.min.js.map +1 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +34 -20
- package/es/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/es/components/deprecated-button/deprecated-button.js +2 -1
- package/es/components/deprecated-button/deprecated-button.js.map +1 -1
- package/es/components/deprecated-modal/deprecated-modal.js +1 -1
- package/es/components/deprecated-modal/deprecated-modal.js.map +1 -1
- package/es/components/dropdown/dropdown.js +3 -1
- package/es/components/dropdown/dropdown.js.map +1 -1
- package/es/components/key-capturer/key-capturer.js.map +1 -1
- package/es/components/keyboard-shortcut/keyboard-shortcut.js +2 -1
- package/es/components/keyboard-shortcut/keyboard-shortcut.js.map +1 -1
- package/es/components/menu/menu.js +32 -12
- package/es/components/menu/menu.js.map +1 -1
- package/es/components/notification/notification.js +8 -3
- package/es/components/notification/notification.js.map +1 -1
- package/es/components/popover/popover.js.map +1 -1
- package/es/components/popover/positioning-utils.js.map +1 -1
- package/es/components/progress-bar/progress-bar.js +8 -2
- package/es/components/progress-bar/progress-bar.js.map +1 -1
- package/es/components/select/select.js +3 -1
- package/es/components/select/select.js.map +1 -1
- package/es/components/time/time-utils.js.map +1 -1
- package/es/components/time/time.js.map +1 -1
- package/es/components/tooltip/tooltip.js +3 -1
- package/es/components/tooltip/tooltip.js.map +1 -1
- package/es/index.js +0 -4
- package/es/index.js.map +1 -1
- package/es/new-components/base-button/base-button.js +3 -1
- package/es/new-components/base-button/base-button.js.map +1 -1
- package/es/new-components/base-button/base-button.module.css.js +1 -1
- package/es/new-components/box/box.js +5 -3
- package/es/new-components/box/box.js.map +1 -1
- package/es/new-components/box/box.module.css.js +1 -1
- package/es/new-components/box/width.module.css.js +4 -0
- package/es/new-components/box/width.module.css.js.map +1 -0
- package/es/new-components/button/button.js +2 -1
- package/es/new-components/button/button.js.map +1 -1
- package/es/new-components/button-link/button-link.js +2 -1
- package/es/new-components/button-link/button-link.js.map +1 -1
- package/es/new-components/checkbox-field/checkbox-field.js +27 -10
- package/es/new-components/checkbox-field/checkbox-field.js.map +1 -1
- package/es/new-components/checkbox-field/checkbox-field.module.css.js +1 -1
- package/es/new-components/checkbox-field/checkbox-icon.js +2 -1
- package/es/new-components/checkbox-field/checkbox-icon.js.map +1 -1
- package/es/new-components/columns/columns.js +4 -2
- package/es/new-components/columns/columns.js.map +1 -1
- package/es/new-components/divider/divider.js +5 -3
- package/es/new-components/divider/divider.js.map +1 -1
- package/es/new-components/divider/divider.module.css.js +1 -1
- package/es/new-components/heading/heading.js +2 -1
- package/es/new-components/heading/heading.js.map +1 -1
- package/es/new-components/hidden/hidden.js +2 -1
- package/es/new-components/hidden/hidden.js.map +1 -1
- package/es/new-components/icons/alert-icon.js +2 -1
- package/es/new-components/icons/alert-icon.js.map +1 -1
- package/es/new-components/inline/inline.js +2 -1
- package/es/new-components/inline/inline.js.map +1 -1
- package/es/new-components/loading/loading.js +6 -2
- package/es/new-components/loading/loading.js.map +1 -1
- package/es/new-components/modal/modal.js +32 -9
- package/es/new-components/modal/modal.js.map +1 -1
- package/es/new-components/modal/modal.module.css.js +1 -1
- package/es/new-components/password-field/password-field.js +2 -1
- package/es/new-components/password-field/password-field.js.map +1 -1
- package/es/new-components/select-field/select-field.js +2 -1
- package/es/new-components/select-field/select-field.js.map +1 -1
- package/es/new-components/select-field/select-field.module.css.js +1 -1
- package/es/new-components/stack/stack.js +5 -4
- package/es/new-components/stack/stack.js.map +1 -1
- package/es/new-components/switch-field/switch-field.js +28 -5
- package/es/new-components/switch-field/switch-field.js.map +1 -1
- package/es/new-components/switch-field/switch-field.module.css.js +1 -1
- package/es/new-components/tabs/tabs.js +10 -5
- package/es/new-components/tabs/tabs.js.map +1 -1
- package/es/new-components/tabs/tabs.module.css.js +1 -1
- package/es/new-components/text/text.js +2 -1
- package/es/new-components/text/text.js.map +1 -1
- package/es/new-components/text-area/text-area.js +3 -1
- package/es/new-components/text-area/text-area.js.map +1 -1
- package/es/new-components/text-area/text-area.module.css.js +1 -1
- package/es/new-components/text-field/text-field.js +2 -1
- package/es/new-components/text-field/text-field.js.map +1 -1
- package/es/new-components/text-field/text-field.module.css.js +1 -1
- package/es/new-components/text-link/text-link.js +2 -1
- package/es/new-components/text-link/text-link.js.map +1 -1
- package/lib/_virtual/_rollupPluginBabelHelpers.js +1 -1
- package/lib/components/deprecated-button/deprecated-button.js +1 -1
- package/lib/components/deprecated-button/deprecated-button.js.map +1 -1
- package/lib/components/deprecated-modal/deprecated-modal.js +1 -1
- package/lib/components/deprecated-modal/deprecated-modal.js.map +1 -1
- package/lib/components/dropdown/dropdown.js +1 -1
- package/lib/components/dropdown/dropdown.js.map +1 -1
- package/lib/components/keyboard-shortcut/keyboard-shortcut.js +1 -1
- package/lib/components/keyboard-shortcut/keyboard-shortcut.js.map +1 -1
- package/lib/components/menu/menu.js +1 -1
- package/lib/components/menu/menu.js.map +1 -1
- package/lib/components/notification/notification.d.ts +4 -2
- package/lib/components/notification/notification.js +1 -1
- package/lib/components/notification/notification.js.map +1 -1
- package/lib/components/progress-bar/progress-bar.d.ts +3 -1
- package/lib/components/progress-bar/progress-bar.js +1 -1
- package/lib/components/progress-bar/progress-bar.js.map +1 -1
- package/lib/components/select/select.js +1 -1
- package/lib/components/select/select.js.map +1 -1
- package/lib/components/tooltip/tooltip.js +1 -1
- package/lib/components/tooltip/tooltip.js.map +1 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.js +1 -1
- package/lib/new-components/base-button/base-button.js +1 -1
- package/lib/new-components/base-button/base-button.js.map +1 -1
- package/lib/new-components/base-button/base-button.module.css.js +1 -1
- package/lib/new-components/box/box.d.ts +10 -9
- package/lib/new-components/box/box.js +1 -1
- package/lib/new-components/box/box.js.map +1 -1
- package/lib/new-components/box/box.module.css.js +1 -1
- package/lib/new-components/box/width.module.css.js +2 -0
- package/lib/new-components/box/width.module.css.js.map +1 -0
- package/lib/new-components/button/button.js +1 -1
- package/lib/new-components/button/button.js.map +1 -1
- package/lib/new-components/button-link/button-link.js +1 -1
- package/lib/new-components/button-link/button-link.js.map +1 -1
- package/lib/new-components/checkbox-field/checkbox-field.d.ts +15 -2
- package/lib/new-components/checkbox-field/checkbox-field.js +1 -1
- package/lib/new-components/checkbox-field/checkbox-field.js.map +1 -1
- package/lib/new-components/checkbox-field/checkbox-field.module.css.js +1 -1
- package/lib/new-components/checkbox-field/checkbox-icon.js +1 -1
- package/lib/new-components/checkbox-field/checkbox-icon.js.map +1 -1
- package/lib/new-components/columns/columns.js +1 -1
- package/lib/new-components/columns/columns.js.map +1 -1
- package/lib/new-components/common-types.d.ts +1 -0
- package/lib/new-components/divider/divider.d.ts +2 -2
- package/lib/new-components/divider/divider.js +1 -1
- package/lib/new-components/divider/divider.js.map +1 -1
- package/lib/new-components/divider/divider.module.css.js +1 -1
- package/lib/new-components/heading/heading.js +1 -1
- package/lib/new-components/heading/heading.js.map +1 -1
- package/lib/new-components/hidden/hidden.js +1 -1
- package/lib/new-components/hidden/hidden.js.map +1 -1
- package/lib/new-components/icons/alert-icon.js +1 -1
- package/lib/new-components/icons/alert-icon.js.map +1 -1
- package/lib/new-components/inline/inline.js +1 -1
- package/lib/new-components/inline/inline.js.map +1 -1
- package/lib/new-components/loading/loading.d.ts +8 -7
- package/lib/new-components/loading/loading.js +1 -1
- package/lib/new-components/loading/loading.js.map +1 -1
- package/lib/new-components/modal/modal.d.ts +7 -3
- package/lib/new-components/modal/modal.js +1 -1
- package/lib/new-components/modal/modal.js.map +1 -1
- package/lib/new-components/modal/modal.module.css.js +1 -1
- package/lib/new-components/password-field/password-field.js +1 -1
- package/lib/new-components/password-field/password-field.js.map +1 -1
- package/lib/new-components/select-field/select-field.js +1 -1
- package/lib/new-components/select-field/select-field.js.map +1 -1
- package/lib/new-components/select-field/select-field.module.css.js +1 -1
- package/lib/new-components/stack/stack.d.ts +3 -4
- package/lib/new-components/stack/stack.js +1 -1
- package/lib/new-components/stack/stack.js.map +1 -1
- package/lib/new-components/switch-field/switch-field.d.ts +9 -2
- package/lib/new-components/switch-field/switch-field.js +1 -1
- package/lib/new-components/switch-field/switch-field.js.map +1 -1
- package/lib/new-components/switch-field/switch-field.module.css.js +1 -1
- package/lib/new-components/tabs/tabs.js +1 -1
- package/lib/new-components/tabs/tabs.js.map +1 -1
- package/lib/new-components/tabs/tabs.module.css.js +1 -1
- package/lib/new-components/text/text.js +1 -1
- package/lib/new-components/text/text.js.map +1 -1
- package/lib/new-components/text-area/text-area.js +1 -1
- package/lib/new-components/text-area/text-area.js.map +1 -1
- package/lib/new-components/text-area/text-area.module.css.js +1 -1
- package/lib/new-components/text-field/text-field.js +1 -1
- package/lib/new-components/text-field/text-field.js.map +1 -1
- package/lib/new-components/text-field/text-field.module.css.js +1 -1
- package/lib/new-components/text-link/text-link.js +1 -1
- package/lib/new-components/text-link/text-link.js.map +1 -1
- package/package.json +15 -12
- package/styles/alert.css +2 -1
- package/styles/base-button.css +4 -3
- package/styles/base-button.module.css.css +1 -1
- package/styles/base-field.css +3 -2
- package/styles/box.css +3 -2
- package/styles/box.module.css.css +1 -1
- package/styles/checkbox-field.css +3 -3
- package/styles/checkbox-field.module.css.css +1 -1
- package/styles/color-picker.css +1 -1
- package/styles/columns.css +2 -1
- package/styles/deprecated-button.css +1 -1
- package/styles/deprecated-loading.css +1 -1
- package/styles/deprecated-modal.css +1 -1
- package/styles/divider.css +3 -2
- package/styles/divider.module.css.css +1 -1
- package/styles/dropdown.css +1 -1
- package/styles/heading.css +2 -1
- package/styles/hidden-visually.css +2 -1
- package/styles/hidden.css +2 -1
- package/styles/inline.css +2 -1
- package/styles/loading.css +3 -2
- package/styles/modal.css +6 -5
- package/styles/modal.module.css.css +1 -1
- package/styles/notice.css +2 -1
- package/styles/password-field.css +4 -3
- package/styles/progress-bar.css +5 -0
- package/styles/reactist.css +16 -19
- package/styles/select-field.css +4 -3
- package/styles/select-field.module.css.css +1 -1
- package/styles/spinner.module.css.css +1 -1
- package/styles/stack.css +3 -2
- package/styles/switch-field.css +4 -3
- package/styles/switch-field.module.css.css +1 -1
- package/styles/tabs.css +3 -2
- package/styles/tabs.module.css.css +1 -1
- package/styles/text-area.css +4 -3
- package/styles/text-area.module.css.css +1 -1
- package/styles/text-field.css +4 -3
- package/styles/text-field.module.css.css +1 -1
- package/styles/text-link.css +2 -1
- package/styles/text.css +2 -1
- package/styles/width.module.css.css +1 -0
- package/es/components/error-message/error-message.js +0 -90
- package/es/components/error-message/error-message.js.map +0 -1
- package/es/components/error-message/index.js +0 -6
- package/es/components/error-message/index.js.map +0 -1
- package/es/components/icon/icon.js +0 -96
- package/es/components/icon/icon.js.map +0 -1
- package/es/components/icon/index.js +0 -6
- package/es/components/icon/index.js.map +0 -1
- package/es/components/icons/ThinQuestionMarkIcon.svg.js +0 -24
- package/es/components/icons/ThinQuestionMarkIcon.svg.js.map +0 -1
- package/es/components/icons/ThreeDotsIcon.svg.js +0 -40
- package/es/components/icons/ThreeDotsIcon.svg.js.map +0 -1
- package/es/components/range-input/index.js +0 -6
- package/es/components/range-input/index.js.map +0 -1
- package/es/components/range-input/range-input.js +0 -55
- package/es/components/range-input/range-input.js.map +0 -1
- package/es/components/tip/index.js +0 -6
- package/es/components/tip/index.js.map +0 -1
- package/es/components/tip/tip.js +0 -30
- package/es/components/tip/tip.js.map +0 -1
- package/lib/components/error-message/error-message.d.ts +0 -23
- package/lib/components/error-message/error-message.js +0 -2
- package/lib/components/error-message/error-message.js.map +0 -1
- package/lib/components/error-message/error-message.test.d.ts +0 -1
- package/lib/components/error-message/index.d.ts +0 -2
- package/lib/components/error-message/index.js +0 -2
- package/lib/components/error-message/index.js.map +0 -1
- package/lib/components/icon/icon.d.ts +0 -31
- package/lib/components/icon/icon.js +0 -2
- package/lib/components/icon/icon.js.map +0 -1
- package/lib/components/icon/icon.test.d.ts +0 -1
- package/lib/components/icon/index.d.ts +0 -2
- package/lib/components/icon/index.js +0 -2
- package/lib/components/icon/index.js.map +0 -1
- package/lib/components/icons/ThinQuestionMarkIcon.svg.js +0 -2
- package/lib/components/icons/ThinQuestionMarkIcon.svg.js.map +0 -1
- package/lib/components/icons/ThreeDotsIcon.svg.js +0 -2
- package/lib/components/icons/ThreeDotsIcon.svg.js.map +0 -1
- package/lib/components/range-input/index.d.ts +0 -2
- package/lib/components/range-input/index.js +0 -2
- package/lib/components/range-input/index.js.map +0 -1
- package/lib/components/range-input/range-input.d.ts +0 -25
- package/lib/components/range-input/range-input.js +0 -2
- package/lib/components/range-input/range-input.js.map +0 -1
- package/lib/components/range-input/range-input.test.d.ts +0 -1
- package/lib/components/tip/index.d.ts +0 -2
- package/lib/components/tip/index.js +0 -2
- package/lib/components/tip/index.js.map +0 -1
- package/lib/components/tip/tip.d.ts +0 -20
- package/lib/components/tip/tip.js +0 -2
- package/lib/components/tip/tip.js.map +0 -1
- package/lib/components/tip/tip.test.d.ts +0 -1
- package/styles/error-message.css +0 -1
- package/styles/icon.css +0 -2
- package/styles/range-input.css +0 -1
- package/styles/tip.css +0 -4
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
1
|
function ownKeys(object, enumerableOnly) {
|
|
17
2
|
var keys = Object.keys(object);
|
|
18
3
|
|
|
19
4
|
if (Object.getOwnPropertySymbols) {
|
|
20
5
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
|
|
7
|
+
if (enumerableOnly) {
|
|
8
|
+
symbols = symbols.filter(function (sym) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
24
13
|
keys.push.apply(keys, symbols);
|
|
25
14
|
}
|
|
26
15
|
|
|
@@ -47,10 +36,35 @@ function _objectSpread2(target) {
|
|
|
47
36
|
return target;
|
|
48
37
|
}
|
|
49
38
|
|
|
39
|
+
function _defineProperty(obj, key, value) {
|
|
40
|
+
if (key in obj) {
|
|
41
|
+
Object.defineProperty(obj, key, {
|
|
42
|
+
value: value,
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
obj[key] = value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return obj;
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
function _inheritsLoose(subClass, superClass) {
|
|
51
55
|
subClass.prototype = Object.create(superClass.prototype);
|
|
52
56
|
subClass.prototype.constructor = subClass;
|
|
53
|
-
|
|
57
|
+
|
|
58
|
+
_setPrototypeOf(subClass, superClass);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function _setPrototypeOf(o, p) {
|
|
62
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
63
|
+
o.__proto__ = p;
|
|
64
|
+
return o;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return _setPrototypeOf(o, p);
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
@@ -76,5 +90,5 @@ function _assertThisInitialized(self) {
|
|
|
76
90
|
return self;
|
|
77
91
|
}
|
|
78
92
|
|
|
79
|
-
export { _assertThisInitialized as assertThisInitialized, _defineProperty as defineProperty, _inheritsLoose as inheritsLoose, _objectSpread2 as objectSpread2, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose };
|
|
93
|
+
export { _assertThisInitialized as assertThisInitialized, _defineProperty as defineProperty, _inheritsLoose as inheritsLoose, _objectSpread2 as objectSpread2, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose, _setPrototypeOf as setPrototypeOf };
|
|
80
94
|
//# sourceMappingURL=_rollupPluginBabelHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,6 +3,7 @@ import React__default from 'react';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { Tooltip } from '../tooltip/tooltip.js';
|
|
5
5
|
|
|
6
|
+
var _excluded = ["type", "variant", "size", "loading", "disabled", "tooltip", "onClick", "children"];
|
|
6
7
|
/**
|
|
7
8
|
* @deprecated
|
|
8
9
|
*/
|
|
@@ -20,7 +21,7 @@ var Button = /*#__PURE__*/React__default.forwardRef(function Button(_ref, ref) {
|
|
|
20
21
|
tooltip = _ref.tooltip,
|
|
21
22
|
onClick = _ref.onClick,
|
|
22
23
|
children = _ref.children,
|
|
23
|
-
props = _objectWithoutPropertiesLoose(_ref,
|
|
24
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
24
25
|
|
|
25
26
|
var className = classNames('reactist_button', variant ? "reactist_button--" + variant : null, size !== 'default' ? "reactist_button--" + size : null, {
|
|
26
27
|
'reactist_button--loading': loading
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecated-button.js","sources":["../../../src/components/deprecated-button/deprecated-button.tsx"],"sourcesContent":["import React from 'react'\nimport classNames from 'classnames'\n\nimport { Tooltip } from '../tooltip'\n\nimport './deprecated-button.less'\n\ntype NativeButtonProps = React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n>\n\n/** @deprecated */\nexport type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'link'\n\n/** @deprecated */\nexport type ButtonSize = 'default' | 'small' | 'large'\n\n/** @deprecated */\nexport type ButtonProps = Omit<NativeButtonProps, 'title' | 'ref'> & {\n /**\n * Loading style. When true it disables the button, but it also adds a visual indication of\n * some in-progress operation going on.\n */\n loading?: boolean\n /**\n * Controls visually how the button shows up from a predefined set of kinds of buttons.\n */\n variant?: ButtonVariant\n /**\n * The size of the button. If not provided it shows up in a normal size.\n */\n size?: ButtonSize\n /**\n * Tooltip that is displayed on hover.\n *\n * This replaces `title` which is not supported for these buttons to avoid confusion.\n */\n tooltip?: React.ReactNode\n}\n\n/**\n * @deprecated\n */\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button(\n {\n type = 'button',\n variant,\n size = 'default',\n loading = false,\n disabled = false,\n tooltip,\n onClick,\n children,\n ...props\n },\n ref,\n) {\n const className = classNames(\n 'reactist_button',\n variant ? `reactist_button--${variant}` : null,\n size !== 'default' ? `reactist_button--${size}` : null,\n { 'reactist_button--loading': loading },\n props.className,\n )\n\n const button = (\n <button\n {...props}\n ref={ref}\n type={type}\n className={className}\n aria-disabled={disabled || loading}\n onClick={disabled || loading ? undefined : onClick}\n >\n {children}\n </button>\n )\n\n return tooltip ? <Tooltip content={tooltip}>{button}</Tooltip> : button\n})\n\nButton.displayName = 'Button'\n\nButton.defaultProps = {\n size: 'default',\n loading: false,\n disabled: false,\n}\n\nexport { Button }\n"],"names":["Button","React","forwardRef","ref","type","variant","size","loading","disabled","tooltip","onClick","children","props","className","classNames","button","undefined","Tooltip","content","displayName","defaultProps"],"mappings":"
|
|
1
|
+
{"version":3,"file":"deprecated-button.js","sources":["../../../src/components/deprecated-button/deprecated-button.tsx"],"sourcesContent":["import React from 'react'\nimport classNames from 'classnames'\n\nimport { Tooltip } from '../tooltip'\n\nimport './deprecated-button.less'\n\ntype NativeButtonProps = React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n>\n\n/** @deprecated */\nexport type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'link'\n\n/** @deprecated */\nexport type ButtonSize = 'default' | 'small' | 'large'\n\n/** @deprecated */\nexport type ButtonProps = Omit<NativeButtonProps, 'title' | 'ref'> & {\n /**\n * Loading style. When true it disables the button, but it also adds a visual indication of\n * some in-progress operation going on.\n */\n loading?: boolean\n /**\n * Controls visually how the button shows up from a predefined set of kinds of buttons.\n */\n variant?: ButtonVariant\n /**\n * The size of the button. If not provided it shows up in a normal size.\n */\n size?: ButtonSize\n /**\n * Tooltip that is displayed on hover.\n *\n * This replaces `title` which is not supported for these buttons to avoid confusion.\n */\n tooltip?: React.ReactNode\n}\n\n/**\n * @deprecated\n */\nconst Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button(\n {\n type = 'button',\n variant,\n size = 'default',\n loading = false,\n disabled = false,\n tooltip,\n onClick,\n children,\n ...props\n },\n ref,\n) {\n const className = classNames(\n 'reactist_button',\n variant ? `reactist_button--${variant}` : null,\n size !== 'default' ? `reactist_button--${size}` : null,\n { 'reactist_button--loading': loading },\n props.className,\n )\n\n const button = (\n <button\n {...props}\n ref={ref}\n type={type}\n className={className}\n aria-disabled={disabled || loading}\n onClick={disabled || loading ? undefined : onClick}\n >\n {children}\n </button>\n )\n\n return tooltip ? <Tooltip content={tooltip}>{button}</Tooltip> : button\n})\n\nButton.displayName = 'Button'\n\nButton.defaultProps = {\n size: 'default',\n loading: false,\n disabled: false,\n}\n\nexport { Button }\n"],"names":["Button","React","forwardRef","ref","type","variant","size","loading","disabled","tooltip","onClick","children","props","className","classNames","button","undefined","Tooltip","content","displayName","defaultProps"],"mappings":";;;;;;AAyCA;;;;IAGMA,MAAM,gBAAGC,cAAK,CAACC,UAAN,CAAiD,SAASF,MAAT,OAY5DG,GAZ4D;uBAExDC;MAAAA,8BAAO;MACPC,eAAAA;uBACAC;MAAAA,8BAAO;0BACPC;MAAAA,oCAAU;2BACVC;MAAAA,sCAAW;MACXC,eAAAA;MACAC,eAAAA;MACAC,gBAAAA;MACGC;;AAIP,MAAMC,SAAS,GAAGC,UAAU,CACxB,iBADwB,EAExBT,OAAO,yBAAuBA,OAAvB,GAAmC,IAFlB,EAGxBC,IAAI,KAAK,SAAT,yBAAyCA,IAAzC,GAAkD,IAH1B,EAIxB;AAAE,gCAA4BC;AAA9B,GAJwB,EAKxBK,KAAK,CAACC,SALkB,CAA5B;AAQA,MAAME,MAAM,gBACRd,4BAAA,SAAA,oBACQW;AACJT,IAAAA,GAAG,EAAEA;AACLC,IAAAA,IAAI,EAAEA;AACNS,IAAAA,SAAS,EAAEA;qBACIL,QAAQ,IAAID;AAC3BG,IAAAA,OAAO,EAAEF,QAAQ,IAAID,OAAZ,GAAsBS,SAAtB,GAAkCN;IAN/C,EAQKC,QARL,CADJ;AAaA,SAAOF,OAAO,gBAAGR,4BAAA,CAACgB,OAAD;AAASC,IAAAA,OAAO,EAAET;GAAlB,EAA4BM,MAA5B,CAAH,GAAmDA,MAAjE;AACH,CApCc;AAsCff,MAAM,CAACmB,WAAP,GAAqB,QAArB;AAEAnB,MAAM,CAACoB,YAAP,GAAsB;AAClBd,EAAAA,IAAI,EAAE,SADY;AAElBC,EAAAA,OAAO,EAAE,KAFS;AAGlBC,EAAAA,QAAQ,EAAE;AAHQ,CAAtB;;;;"}
|
|
@@ -215,7 +215,7 @@ var Actions = /*#__PURE__*/function (_React$Component4) {
|
|
|
215
215
|
this.props.children, function (child) {
|
|
216
216
|
var _child$props;
|
|
217
217
|
|
|
218
|
-
if (child
|
|
218
|
+
if (child !== null && child !== void 0 && (_child$props = child.props) !== null && _child$props !== void 0 && _child$props.close) {
|
|
219
219
|
return /*#__PURE__*/React__default.cloneElement(child, {
|
|
220
220
|
onClick: function onClick() {
|
|
221
221
|
return _this2._onClick(child.props.onClick);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deprecated-modal.js","sources":["../../../src/components/deprecated-modal/deprecated-modal.tsx"],"sourcesContent":["import React from 'react'\nimport ReactDOM from 'react-dom'\nimport classnames from 'classnames'\n\nimport CloseIcon from '../icons/CloseIcon.svg'\n\nimport './deprecated-modal.less'\n\ntype Props = {\n /** Additional css class applied to the Modal.Box. */\n className?: string\n /** Sometimes a class name is not enough so you can use this to set the style directly. */\n style?: React.CSSProperties\n /** Large style. */\n large: boolean\n /** Medium size syle. */\n medium?: boolean\n /** Close the Modal when clicking on the overlay. */\n closeOnOverlayClick: boolean\n}\n\n/** @deprecated */\nclass Box extends React.Component<React.PropsWithChildren<Props>> {\n public static displayName: string\n public static defaultProps: Props\n\n componentDidMount() {\n window.addEventListener('keydown', this._handleKeyDown)\n }\n\n componentWillUnmount() {\n window.removeEventListener('keydown', this._handleKeyDown)\n }\n\n _closeModal = () => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n _handleKeyDown = (event: Partial<KeyboardEvent>) => {\n if (event.keyCode === 27) {\n // ESC\n this._closeModal()\n if (event.preventDefault) event.preventDefault()\n }\n }\n\n _handleOverlayClick = (event: React.MouseEvent<Element>) => {\n if (\n event.target instanceof Element &&\n (event.target.id === 'reactist-overlay' || event.target.id === 'reactist-overlay-inner')\n ) {\n this._closeModal()\n }\n }\n\n render() {\n const { large, medium, style, children, closeOnOverlayClick } = this.props\n\n const className = classnames('reactist_modal_box', { large, medium }, this.props.className)\n\n return (\n <div\n className=\"reactist_overlay\"\n id=\"reactist-overlay\"\n onClick={closeOnOverlayClick ? this._handleOverlayClick : undefined}\n >\n <div className=\"reactist_overlay_inner\" id=\"reactist-overlay-inner\">\n <div style={style} className={className}>\n {children}\n </div>\n </div>\n </div>\n )\n }\n}\nBox.displayName = 'Modal.Box'\nBox.defaultProps = {\n large: false,\n closeOnOverlayClick: false,\n}\n\ntype HeaderProps = {\n /** Title of the Modal.Header. */\n title?: string | React.ReactNode\n /** Subtitle of the Modal.Header. */\n subtitle?: string | React.ReactNode\n /** Function that is called right before the Modal unmounts itself. */\n beforeClose?: () => void\n}\n\n/** @deprecated */\nclass Header extends React.Component<HeaderProps> {\n public static displayName: string\n public static defaultProps: HeaderProps\n\n _closeModal(event: React.MouseEvent) {\n event.preventDefault()\n if (typeof this.props.beforeClose === 'function') {\n this.props.beforeClose()\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n render() {\n return (\n /* eslint-disable jsx-a11y/anchor-is-valid */\n <div className=\"reactist_modal_box__header\">\n <p>\n {this.props.title && <span className=\"title\">{this.props.title}</span>}\n {this.props.subtitle && <span className=\"subtitle\">{this.props.subtitle}</span>}\n {this.props.children}\n </p>\n <a className=\"close\" onClick={this._closeModal.bind(this)} href=\"#\">\n <CloseIcon />\n </a>\n </div>\n /* eslint-enable jsx-a11y/anchor-is-valid */\n )\n }\n}\nHeader.displayName = 'Modal.Header'\n\ntype BodyProps = {\n /** Display an icon (or basically any component) on the right hand side of the Modal.Body. */\n icon?: React.ReactNode\n /** Applies less styles on the body (e.g. no padding) */\n plain?: boolean\n /** Sometimes a class name is not enough so you can use this to set the style directly. */\n style?: React.CSSProperties\n /** Additionall css class applied to the Modal.Body. */\n className?: string\n /**\n * Render a close icon in the top right corner of the Modal.Body.\n * Recommended to use when no Modal.Header is used.\n */\n showCloseIcon?: boolean\n}\n\n/** @deprecated */\nclass Body extends React.Component<BodyProps> {\n public static displayName: string\n public static defaultProps: BodyProps\n\n _closeModal(event: React.MouseEvent) {\n event.preventDefault()\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n render() {\n const { icon, plain, children, style, showCloseIcon } = this.props\n const className = classnames('reactist_modal_box__body', { plain }, this.props.className)\n\n return (\n /* eslint-disable jsx-a11y/anchor-is-valid */\n <div className={className} style={style}>\n {showCloseIcon && (\n <a className=\"close\" onClick={this._closeModal.bind(this)} href=\"#\">\n <CloseIcon />\n </a>\n )}\n {icon ? (\n <div className=\"dialog\">\n <div className=\"reactist_icon\">{icon}</div>\n <div className=\"content\">{children}</div>\n </div>\n ) : (\n children\n )}\n </div>\n /* eslint-enable jsx-a11y/anchor-is-valid */\n )\n }\n}\nBody.displayName = 'Modal.Body'\nBody.defaultProps = {\n showCloseIcon: false,\n}\n\ntype ActionProps = {\n /**\n * Children to render inside the Modal.Actions. They can have an optional `close` property (boolean).\n * When that is supplied and set to true it will close the modal after the onClick function\n */\n children?: React.ReactNode\n}\n\ntype ActionChildrenProps = {\n close?: boolean\n onClick?: () => void\n}\n\n/** @deprecated */\nclass Actions extends React.Component<ActionProps> {\n public static displayName: string\n\n _onClick(onClick: ActionChildrenProps['onClick']) {\n if (onClick) {\n onClick()\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n render() {\n const children = React.Children.map(\n // see: https://github.com/microsoft/TypeScript/issues/21699\n // @ts-expect-error Children cannot be typed properly yet in React\n this.props.children,\n (child: React.ReactElement<ActionChildrenProps>) => {\n if (child?.props?.close) {\n return React.cloneElement(child, {\n onClick: () => this._onClick(child.props.onClick),\n })\n } else {\n return child ? React.cloneElement(child) : <></>\n }\n },\n )\n\n return <div className=\"reactist_modal_box__actions\">{children}</div>\n }\n}\n\nActions.displayName = 'Modal.Actions'\n\n/** @deprecated */\ntype Modal = {\n Box: Box\n Header: Header\n Body: Body\n Actions: Actions\n}\n\nexport type { Modal }\n\nexport { Box, Header, Body, Actions }\n"],"names":["Box","modalElement","document","getElementById","ReactDOM","unmountComponentAtNode","event","keyCode","_closeModal","preventDefault","target","Element","id","componentDidMount","window","addEventListener","_handleKeyDown","componentWillUnmount","removeEventListener","render","props","large","medium","style","children","closeOnOverlayClick","className","classnames","React","onClick","_handleOverlayClick","undefined","Component","displayName","defaultProps","Header","beforeClose","title","subtitle","bind","href","CloseIcon","Body","icon","plain","showCloseIcon","Actions","_onClick","Children","map","child","close","cloneElement"],"mappings":";;;;;;AAqBA;;IACMA;;;AAAN;;;;;AAYI,qBAAA,GAAc;AACV;AACA,UAAMC,YAAY,GAAGC,QAAQ,CAACC,cAAT,CAAwB,WAAxB,CAArB;AACAC,MAAAA,QAAQ,CAACC,sBAAT,CAAgCJ,YAAhC;AACH,KAJD;;AAMA,wBAAA,GAAiB,UAACK,KAAD;AACb,UAAIA,KAAK,CAACC,OAAN,KAAkB,EAAtB,EAA0B;AACtB;AACA,cAAKC,WAAL;;AACA,YAAIF,KAAK,CAACG,cAAV,EAA0BH,KAAK,CAACG,cAAN;AAC7B;AACJ,KAND;;AAQA,6BAAA,GAAsB,UAACH,KAAD;AAClB,UACIA,KAAK,CAACI,MAAN,YAAwBC,OAAxB,KACCL,KAAK,CAACI,MAAN,CAAaE,EAAb,KAAoB,kBAApB,IAA0CN,KAAK,CAACI,MAAN,CAAaE,EAAb,KAAoB,wBAD/D,CADJ,EAGE;AACE,cAAKJ,WAAL;AACH;AACJ,KAPD;;;AA4BH;;;;SAlDGK,oBAAA;AACIC,IAAAA,MAAM,CAACC,gBAAP,CAAwB,SAAxB,EAAmC,KAAKC,cAAxC;AACH;;SAEDC,uBAAA;AACIH,IAAAA,MAAM,CAACI,mBAAP,CAA2B,SAA3B,EAAsC,KAAKF,cAA3C;AACH;;SAyBDG,SAAA;sBACoE,KAAKC;QAA7DC,oBAAAA;QAAOC,qBAAAA;QAAQC,oBAAAA;QAAOC,uBAAAA;QAAUC,kCAAAA;AAExC,QAAMC,SAAS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AAAKF,MAAAA,SAAS,EAAC;KAAf,EAA8CF,QAA9C,CAAP;AACH;;;EA7BiBI,cAAK,CAACI;;AAgC5Bc,OAAO,CAACb,WAAR,GAAsB,eAAtB;;;;"}
|
|
1
|
+
{"version":3,"file":"deprecated-modal.js","sources":["../../../src/components/deprecated-modal/deprecated-modal.tsx"],"sourcesContent":["import React from 'react'\nimport ReactDOM from 'react-dom'\nimport classnames from 'classnames'\n\nimport CloseIcon from '../icons/CloseIcon.svg'\n\nimport './deprecated-modal.less'\n\ntype Props = {\n /** Additional css class applied to the Modal.Box. */\n className?: string\n /** Sometimes a class name is not enough so you can use this to set the style directly. */\n style?: React.CSSProperties\n /** Large style. */\n large: boolean\n /** Medium size syle. */\n medium?: boolean\n /** Close the Modal when clicking on the overlay. */\n closeOnOverlayClick: boolean\n}\n\n/** @deprecated */\nclass Box extends React.Component<React.PropsWithChildren<Props>> {\n public static displayName: string\n public static defaultProps: Props\n\n componentDidMount() {\n window.addEventListener('keydown', this._handleKeyDown)\n }\n\n componentWillUnmount() {\n window.removeEventListener('keydown', this._handleKeyDown)\n }\n\n _closeModal = () => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n _handleKeyDown = (event: Partial<KeyboardEvent>) => {\n if (event.keyCode === 27) {\n // ESC\n this._closeModal()\n if (event.preventDefault) event.preventDefault()\n }\n }\n\n _handleOverlayClick = (event: React.MouseEvent<Element>) => {\n if (\n event.target instanceof Element &&\n (event.target.id === 'reactist-overlay' || event.target.id === 'reactist-overlay-inner')\n ) {\n this._closeModal()\n }\n }\n\n render() {\n const { large, medium, style, children, closeOnOverlayClick } = this.props\n\n const className = classnames('reactist_modal_box', { large, medium }, this.props.className)\n\n return (\n <div\n className=\"reactist_overlay\"\n id=\"reactist-overlay\"\n onClick={closeOnOverlayClick ? this._handleOverlayClick : undefined}\n >\n <div className=\"reactist_overlay_inner\" id=\"reactist-overlay-inner\">\n <div style={style} className={className}>\n {children}\n </div>\n </div>\n </div>\n )\n }\n}\nBox.displayName = 'Modal.Box'\nBox.defaultProps = {\n large: false,\n closeOnOverlayClick: false,\n}\n\ntype HeaderProps = {\n /** Title of the Modal.Header. */\n title?: string | React.ReactNode\n /** Subtitle of the Modal.Header. */\n subtitle?: string | React.ReactNode\n /** Function that is called right before the Modal unmounts itself. */\n beforeClose?: () => void\n}\n\n/** @deprecated */\nclass Header extends React.Component<HeaderProps> {\n public static displayName: string\n public static defaultProps: HeaderProps\n\n _closeModal(event: React.MouseEvent) {\n event.preventDefault()\n if (typeof this.props.beforeClose === 'function') {\n this.props.beforeClose()\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n render() {\n return (\n /* eslint-disable jsx-a11y/anchor-is-valid */\n <div className=\"reactist_modal_box__header\">\n <p>\n {this.props.title && <span className=\"title\">{this.props.title}</span>}\n {this.props.subtitle && <span className=\"subtitle\">{this.props.subtitle}</span>}\n {this.props.children}\n </p>\n <a className=\"close\" onClick={this._closeModal.bind(this)} href=\"#\">\n <CloseIcon />\n </a>\n </div>\n /* eslint-enable jsx-a11y/anchor-is-valid */\n )\n }\n}\nHeader.displayName = 'Modal.Header'\n\ntype BodyProps = {\n /** Display an icon (or basically any component) on the right hand side of the Modal.Body. */\n icon?: React.ReactNode\n /** Applies less styles on the body (e.g. no padding) */\n plain?: boolean\n /** Sometimes a class name is not enough so you can use this to set the style directly. */\n style?: React.CSSProperties\n /** Additionall css class applied to the Modal.Body. */\n className?: string\n /**\n * Render a close icon in the top right corner of the Modal.Body.\n * Recommended to use when no Modal.Header is used.\n */\n showCloseIcon?: boolean\n}\n\n/** @deprecated */\nclass Body extends React.Component<BodyProps> {\n public static displayName: string\n public static defaultProps: BodyProps\n\n _closeModal(event: React.MouseEvent) {\n event.preventDefault()\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n render() {\n const { icon, plain, children, style, showCloseIcon } = this.props\n const className = classnames('reactist_modal_box__body', { plain }, this.props.className)\n\n return (\n /* eslint-disable jsx-a11y/anchor-is-valid */\n <div className={className} style={style}>\n {showCloseIcon && (\n <a className=\"close\" onClick={this._closeModal.bind(this)} href=\"#\">\n <CloseIcon />\n </a>\n )}\n {icon ? (\n <div className=\"dialog\">\n <div className=\"reactist_icon\">{icon}</div>\n <div className=\"content\">{children}</div>\n </div>\n ) : (\n children\n )}\n </div>\n /* eslint-enable jsx-a11y/anchor-is-valid */\n )\n }\n}\nBody.displayName = 'Modal.Body'\nBody.defaultProps = {\n showCloseIcon: false,\n}\n\ntype ActionProps = {\n /**\n * Children to render inside the Modal.Actions. They can have an optional `close` property (boolean).\n * When that is supplied and set to true it will close the modal after the onClick function\n */\n children?: React.ReactNode\n}\n\ntype ActionChildrenProps = {\n close?: boolean\n onClick?: () => void\n}\n\n/** @deprecated */\nclass Actions extends React.Component<ActionProps> {\n public static displayName: string\n\n _onClick(onClick: ActionChildrenProps['onClick']) {\n if (onClick) {\n onClick()\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const modalElement = document.getElementById('modal_box')!\n ReactDOM.unmountComponentAtNode(modalElement)\n }\n\n render() {\n const children = React.Children.map(\n // see: https://github.com/microsoft/TypeScript/issues/21699\n // @ts-expect-error Children cannot be typed properly yet in React\n this.props.children,\n (child: React.ReactElement<ActionChildrenProps>) => {\n if (child?.props?.close) {\n return React.cloneElement(child, {\n onClick: () => this._onClick(child.props.onClick),\n })\n } else {\n return child ? React.cloneElement(child) : <></>\n }\n },\n )\n\n return <div className=\"reactist_modal_box__actions\">{children}</div>\n }\n}\n\nActions.displayName = 'Modal.Actions'\n\n/** @deprecated */\ntype Modal = {\n Box: Box\n Header: Header\n Body: Body\n Actions: Actions\n}\n\nexport type { Modal }\n\nexport { Box, Header, Body, Actions }\n"],"names":["Box","modalElement","document","getElementById","ReactDOM","unmountComponentAtNode","event","keyCode","_closeModal","preventDefault","target","Element","id","componentDidMount","window","addEventListener","_handleKeyDown","componentWillUnmount","removeEventListener","render","props","large","medium","style","children","closeOnOverlayClick","className","classnames","React","onClick","_handleOverlayClick","undefined","Component","displayName","defaultProps","Header","beforeClose","title","subtitle","bind","href","CloseIcon","Body","icon","plain","showCloseIcon","Actions","_onClick","Children","map","child","close","cloneElement"],"mappings":";;;;;;AAqBA;;IACMA;;;AAAN;;;;;AAYI,qBAAA,GAAc;AACV;AACA,UAAMC,YAAY,GAAGC,QAAQ,CAACC,cAAT,CAAwB,WAAxB,CAArB;AACAC,MAAAA,QAAQ,CAACC,sBAAT,CAAgCJ,YAAhC;AACH,KAJD;;AAMA,wBAAA,GAAiB,UAACK,KAAD;AACb,UAAIA,KAAK,CAACC,OAAN,KAAkB,EAAtB,EAA0B;AACtB;AACA,cAAKC,WAAL;;AACA,YAAIF,KAAK,CAACG,cAAV,EAA0BH,KAAK,CAACG,cAAN;AAC7B;AACJ,KAND;;AAQA,6BAAA,GAAsB,UAACH,KAAD;AAClB,UACIA,KAAK,CAACI,MAAN,YAAwBC,OAAxB,KACCL,KAAK,CAACI,MAAN,CAAaE,EAAb,KAAoB,kBAApB,IAA0CN,KAAK,CAACI,MAAN,CAAaE,EAAb,KAAoB,wBAD/D,CADJ,EAGE;AACE,cAAKJ,WAAL;AACH;AACJ,KAPD;;;AA4BH;;;;SAlDGK,oBAAA;AACIC,IAAAA,MAAM,CAACC,gBAAP,CAAwB,SAAxB,EAAmC,KAAKC,cAAxC;AACH;;SAEDC,uBAAA;AACIH,IAAAA,MAAM,CAACI,mBAAP,CAA2B,SAA3B,EAAsC,KAAKF,cAA3C;AACH;;SAyBDG,SAAA;AACI,sBAAgE,KAAKC,KAArE;AAAA,QAAQC,KAAR,eAAQA,KAAR;AAAA,QAAeC,MAAf,eAAeA,MAAf;AAAA,QAAuBC,KAAvB,e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AAYS,OAA1B,CAAN;AAAA;AADoB,SAA1B,CAAP;AAGH,OAJD,MAIO;AACH,eAAOqB,KAAK,gBAAGtB,cAAK,CAACwB,YAAN,CAAmBF,KAAnB,CAAH,gBAA+BtB,4BAAA,wBAAA,MAAA,CAA3C;AACH;AACJ,KAZY,CAAjB;AAeA,wBAAOA,4BAAA,MAAA;AAAKF,MAAAA,SAAS,EAAC;KAAf,EAA8CF,QAA9C,CAAP;AACH;;;EA7BiBI,cAAK,CAACI;;AAgC5Bc,OAAO,CAACb,WAAR,GAAsB,eAAtB;;;;"}
|
|
@@ -4,6 +4,8 @@ import classNames from 'classnames';
|
|
|
4
4
|
import ReactDOM from 'react-dom';
|
|
5
5
|
import Button from '../deprecated-button/index.js';
|
|
6
6
|
|
|
7
|
+
var _excluded = ["children", "onClick", "tooltip", "className"];
|
|
8
|
+
|
|
7
9
|
var Box = /*#__PURE__*/function (_React$Component) {
|
|
8
10
|
_inheritsLoose(Box, _React$Component);
|
|
9
11
|
|
|
@@ -154,7 +156,7 @@ var Trigger = /*#__PURE__*/React__default.forwardRef(function Trigger(_ref, ref)
|
|
|
154
156
|
onClick = _ref.onClick,
|
|
155
157
|
tooltip = _ref.tooltip,
|
|
156
158
|
className = _ref.className,
|
|
157
|
-
props = _objectWithoutPropertiesLoose(_ref,
|
|
159
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
158
160
|
|
|
159
161
|
function handleClick(event) {
|
|
160
162
|
event.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown.js","sources":["../../../src/components/dropdown/dropdown.tsx"],"sourcesContent":["import React from 'react'\nimport ReactDOM from 'react-dom'\nimport classNames from 'classnames'\n\nimport Button from '../deprecated-button'\n\nimport './dropdown.less'\n\ntype BoxProps = {\n onShowBody?: () => void\n onHideBody?: () => void\n allowBodyInteractions?: boolean\n top?: boolean\n right?: boolean\n scrolling_parent?: string\n children?: [\n React.ReactElement<TriggerProps>,\n React.ReactElement<BodyProps> | ((props: BodyProps) => JSX.Element),\n ]\n className?: string\n}\n\ntype BoxState = {\n top: boolean\n showBody: boolean\n}\n\nclass Box extends React.Component<React.PropsWithChildren<BoxProps>, BoxState> {\n public static displayName: string\n\n constructor(props: BoxProps, context: React.Context<unknown>) {\n super(props, context)\n this.state = {\n showBody: false,\n top: props.top || false,\n }\n\n this._timeout = undefined\n }\n\n componentWillUnmount() {\n document.removeEventListener('click', this._handleClickOutside, true)\n if (this._timeout) {\n clearTimeout(this._timeout)\n }\n }\n _timeout?: ReturnType<typeof setTimeout>\n\n _handleClickOutside = (event: MouseEvent) => {\n const dropdownDOMNode = ReactDOM.findDOMNode(this)\n\n if (dropdownDOMNode && !dropdownDOMNode.contains(event.target as Node))\n this._toggleShowBody()\n else if (!this.props.allowBodyInteractions) {\n // won't close when body interactions are allowed\n this._timeout = setTimeout(() => {\n if (this.state.showBody) {\n this._toggleShowBody()\n }\n }, 100)\n }\n }\n\n _toggleShowBody = () => {\n if (!this.state.showBody) {\n // will show\n if (this.props.onShowBody) this.props.onShowBody()\n document.addEventListener('click', this._handleClickOutside, true)\n } else {\n // will hide\n if (this.props.onHideBody) this.props.onHideBody()\n document.removeEventListener('click', this._handleClickOutside, true)\n }\n\n this.setState({\n showBody: !this.state.showBody,\n })\n }\n\n _getTriggerComponent() {\n const _trigger = this.props.children?.[0]\n return _trigger\n ? React.cloneElement(_trigger, { onClick: this._toggleShowBody })\n : undefined\n }\n\n // https://facebook.github.io/react/docs/refs-and-the-dom.html#exposing-dom-refs-to-parent-components\n _setPosition = (body: HTMLElement | null) => {\n if (body) {\n const scrollingParent = document.getElementById(\n this.props.scrolling_parent ? this.props.scrolling_parent : '',\n )\n\n if (scrollingParent) {\n const dropdown = ReactDOM.findDOMNode(this)\n if (!dropdown) {\n return\n }\n const dropdownVerticalPosition = (ReactDOM.findDOMNode(this) as HTMLElement)\n .offsetTop\n const dropdownTrigger = (dropdown as Element).querySelector('.trigger')\n if (!dropdownTrigger) {\n return\n }\n const dropdownTriggerHeight = dropdownTrigger.clientHeight\n const dropdownBodyHeight = body.clientHeight\n\n const scrollingParentHeight = scrollingParent.clientHeight\n const scrollingParentOffset = scrollingParent.scrollTop\n\n const bottomOffset =\n scrollingParentHeight +\n scrollingParentOffset -\n dropdownVerticalPosition -\n dropdownTriggerHeight\n\n const top = bottomOffset < dropdownBodyHeight\n\n if (top !== this.state.top) {\n this.setState({ top })\n }\n }\n }\n }\n\n _getBodyComponent() {\n if (!this.state.showBody) {\n return null\n }\n const { top } = this.state\n const { right = false, children } = this.props\n const props = { top, right, setPosition: this._setPosition }\n\n const className = classNames({\n body_wrapper: true,\n with_arrow: true,\n top: top,\n bottom: !top,\n })\n\n const body = children?.[1]\n\n const contentMarkup =\n typeof body === 'function'\n ? body(props)\n : body\n ? React.cloneElement(body, props)\n : undefined\n return (\n <div className={className} style={{ position: 'relative' }}>\n {contentMarkup}\n </div>\n )\n }\n\n render() {\n const className = classNames('reactist_dropdown', this.props.className)\n const { top } = this.state\n\n return (\n <div style={{ display: 'inline-block' }} className={className}>\n {top && this._getBodyComponent()}\n {this._getTriggerComponent()}\n {!top && this._getBodyComponent()}\n </div>\n )\n }\n}\n\nBox.displayName = 'Dropdown.Box'\n\ntype NativeButtonProps = React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n>\n\ntype TriggerProps = Omit<NativeButtonProps, 'title'> & {\n tooltip?: React.ReactNode\n}\n\nconst Trigger = React.forwardRef<HTMLButtonElement, TriggerProps>(function Trigger(\n { children, onClick, tooltip, className, ...props },\n ref,\n) {\n function handleClick(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {\n event.preventDefault()\n event.stopPropagation()\n if (onClick) onClick(event)\n }\n\n return (\n <Button\n {...props}\n className={classNames('trigger', className)}\n onClick={handleClick}\n tooltip={tooltip}\n ref={ref}\n >\n {children}\n </Button>\n )\n})\n\nTrigger.displayName = 'Dropdown.Trigger'\n\ntype BodyProps = {\n setPosition?: React.Ref<HTMLDivElement>\n children?: React.ReactNode\n top?: boolean\n right?: boolean\n}\n\nfunction Body({ top, right, children, setPosition }: BodyProps) {\n const style: React.CSSProperties = { position: 'absolute', right: 0, top: 0 }\n\n if (top) {\n style.top = 'auto'\n style.bottom = 0\n }\n\n if (right) {\n style.right = 'auto'\n style.left = 0\n }\n\n return (\n <div ref={setPosition} style={style} className=\"body\" id=\"reactist-dropdown-body\">\n {children}\n </div>\n )\n}\n\nBody.displayName = 'Dropdown.Body'\n\nconst Dropdown = {\n Box,\n Trigger,\n Body,\n}\n\nexport { Dropdown }\n"],"names":["Box","props","context","event","dropdownDOMNode","ReactDOM","findDOMNode","contains","target","_toggleShowBody","allowBodyInteractions","_timeout","setTimeout","state","showBody","onShowBody","document","addEventListener","_handleClickOutside","onHideBody","removeEventListener","setState","body","scrollingParent","getElementById","scrolling_parent","dropdown","dropdownVerticalPosition","offsetTop","dropdownTrigger","querySelector","dropdownTriggerHeight","clientHeight","dropdownBodyHeight","scrollingParentHeight","scrollingParentOffset","scrollTop","bottomOffset","top","undefined","componentWillUnmount","clearTimeout","_getTriggerComponent","_trigger","children","React","cloneElement","onClick","_getBodyComponent","right","setPosition","_setPosition","className","classNames","body_wrapper","with_arrow","bottom","contentMarkup","style","position","render","display","Component","displayName","Trigger","forwardRef","ref","tooltip","handleClick","preventDefault","stopPropagation","Button","Body","left","id","Dropdown"],"mappings":";;;;;;IA2BMA;;;AAGF,eAAYC,KAAZ,EAA6BC,OAA7B;;;AACI,wCAAMD,KAAN,EAAaC,OAAb;;AAiBJ,6BAAA,GAAsB,UAACC,KAAD;AAClB,UAAMC,eAAe,GAAGC,QAAQ,CAACC,WAAT,+BAAxB;AAEA,UAAIF,eAAe,IAAI,CAACA,eAAe,CAACG,QAAhB,CAAyBJ,KAAK,CAACK,MAA/B,CAAxB,EACI,MAAKC,eAAL,GADJ,KAEK,IAAI,CAAC,MAAKR,KAAL,CAAWS,qBAAhB,EAAuC;AACx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MY,QAAQ,GAAG;AACb3E,EAAAA,GAAG,EAAHA,GADa;AAEbgE,EAAAA,OAAO,EAAPA,OAFa;AAGbQ,EAAAA,IAAI,EAAJA;AAHa;;;;"}
|
|
1
|
+
{"version":3,"file":"dropdown.js","sources":["../../../src/components/dropdown/dropdown.tsx"],"sourcesContent":["import React from 'react'\nimport ReactDOM from 'react-dom'\nimport classNames from 'classnames'\n\nimport Button from '../deprecated-button'\n\nimport './dropdown.less'\n\ntype BoxProps = {\n onShowBody?: () => void\n onHideBody?: () => void\n allowBodyInteractions?: boolean\n top?: boolean\n right?: boolean\n scrolling_parent?: string\n children?: [\n React.ReactElement<TriggerProps>,\n React.ReactElement<BodyProps> | ((props: BodyProps) => JSX.Element),\n ]\n className?: string\n}\n\ntype BoxState = {\n top: boolean\n showBody: boolean\n}\n\nclass Box extends React.Component<React.PropsWithChildren<BoxProps>, BoxState> {\n public static displayName: string\n\n constructor(props: BoxProps, context: React.Context<unknown>) {\n super(props, context)\n this.state = {\n showBody: false,\n top: props.top || false,\n }\n\n this._timeout = undefined\n }\n\n componentWillUnmount() {\n document.removeEventListener('click', this._handleClickOutside, true)\n if (this._timeout) {\n clearTimeout(this._timeout)\n }\n }\n _timeout?: ReturnType<typeof setTimeout>\n\n _handleClickOutside = (event: MouseEvent) => {\n const dropdownDOMNode = ReactDOM.findDOMNode(this)\n\n if (dropdownDOMNode && !dropdownDOMNode.contains(event.target as Node))\n this._toggleShowBody()\n else if (!this.props.allowBodyInteractions) {\n // won't close when body interactions are allowed\n this._timeout = setTimeout(() => {\n if (this.state.showBody) {\n this._toggleShowBody()\n }\n }, 100)\n }\n }\n\n _toggleShowBody = () => {\n if (!this.state.showBody) {\n // will show\n if (this.props.onShowBody) this.props.onShowBody()\n document.addEventListener('click', this._handleClickOutside, true)\n } else {\n // will hide\n if (this.props.onHideBody) this.props.onHideBody()\n document.removeEventListener('click', this._handleClickOutside, true)\n }\n\n this.setState({\n showBody: !this.state.showBody,\n })\n }\n\n _getTriggerComponent() {\n const _trigger = this.props.children?.[0]\n return _trigger\n ? React.cloneElement(_trigger, { onClick: this._toggleShowBody })\n : undefined\n }\n\n // https://facebook.github.io/react/docs/refs-and-the-dom.html#exposing-dom-refs-to-parent-components\n _setPosition = (body: HTMLElement | null) => {\n if (body) {\n const scrollingParent = document.getElementById(\n this.props.scrolling_parent ? this.props.scrolling_parent : '',\n )\n\n if (scrollingParent) {\n const dropdown = ReactDOM.findDOMNode(this)\n if (!dropdown) {\n return\n }\n const dropdownVerticalPosition = (ReactDOM.findDOMNode(this) as HTMLElement)\n .offsetTop\n const dropdownTrigger = (dropdown as Element).querySelector('.trigger')\n if (!dropdownTrigger) {\n return\n }\n const dropdownTriggerHeight = dropdownTrigger.clientHeight\n const dropdownBodyHeight = body.clientHeight\n\n const scrollingParentHeight = scrollingParent.clientHeight\n const scrollingParentOffset = scrollingParent.scrollTop\n\n const bottomOffset =\n scrollingParentHeight +\n scrollingParentOffset -\n dropdownVerticalPosition -\n dropdownTriggerHeight\n\n const top = bottomOffset < dropdownBodyHeight\n\n if (top !== this.state.top) {\n this.setState({ top })\n }\n }\n }\n }\n\n _getBodyComponent() {\n if (!this.state.showBody) {\n return null\n }\n const { top } = this.state\n const { right = false, children } = this.props\n const props = { top, right, setPosition: this._setPosition }\n\n const className = classNames({\n body_wrapper: true,\n with_arrow: true,\n top: top,\n bottom: !top,\n })\n\n const body = children?.[1]\n\n const contentMarkup =\n typeof body === 'function'\n ? body(props)\n : body\n ? React.cloneElement(body, props)\n : undefined\n return (\n <div className={className} style={{ position: 'relative' }}>\n {contentMarkup}\n </div>\n )\n }\n\n render() {\n const className = classNames('reactist_dropdown', this.props.className)\n const { top } = this.state\n\n return (\n <div style={{ display: 'inline-block' }} className={className}>\n {top && this._getBodyComponent()}\n {this._getTriggerComponent()}\n {!top && this._getBodyComponent()}\n </div>\n )\n }\n}\n\nBox.displayName = 'Dropdown.Box'\n\ntype NativeButtonProps = React.DetailedHTMLProps<\n React.ButtonHTMLAttributes<HTMLButtonElement>,\n HTMLButtonElement\n>\n\ntype TriggerProps = Omit<NativeButtonProps, 'title'> & {\n tooltip?: React.ReactNode\n}\n\nconst Trigger = React.forwardRef<HTMLButtonElement, TriggerProps>(function Trigger(\n { children, onClick, tooltip, className, ...props },\n ref,\n) {\n function handleClick(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) {\n event.preventDefault()\n event.stopPropagation()\n if (onClick) onClick(event)\n }\n\n return (\n <Button\n {...props}\n className={classNames('trigger', className)}\n onClick={handleClick}\n tooltip={tooltip}\n ref={ref}\n >\n {children}\n </Button>\n )\n})\n\nTrigger.displayName = 'Dropdown.Trigger'\n\ntype BodyProps = {\n setPosition?: React.Ref<HTMLDivElement>\n children?: React.ReactNode\n top?: boolean\n right?: boolean\n}\n\nfunction Body({ top, right, children, setPosition }: BodyProps) {\n const style: React.CSSProperties = { position: 'absolute', right: 0, top: 0 }\n\n if (top) {\n style.top = 'auto'\n style.bottom = 0\n }\n\n if (right) {\n style.right = 'auto'\n style.left = 0\n }\n\n return (\n <div ref={setPosition} style={style} className=\"body\" id=\"reactist-dropdown-body\">\n {children}\n </div>\n )\n}\n\nBody.displayName = 'Dropdown.Body'\n\nconst Dropdown = {\n Box,\n Trigger,\n Body,\n}\n\nexport { Dropdown }\n"],"names":["Box","props","context","event","dropdownDOMNode","ReactDOM","findDOMNode","contains","target","_toggleShowBody","allowBodyInteractions","_timeout","setTimeout","state","showBody","onShowBody","document","addEventListener","_handleClickOutside","onHideBody","removeEventListener","setState","body","scrollingParent","getElementById","scrolling_parent","dropdown","dropdownVerticalPosition","offsetTop","dropdownTrigger","querySelector","dropdownTriggerHeight","clientHeight","dropdownBodyHeight","scrollingParentHeight","scrollingParentOffset","scrollTop","bottomOffset","top","undefined","componentWillUnmount","clearTimeout","_getTriggerComponent","_trigger","children","React","cloneElement","onClick","_getBodyComponent","right","setPosition","_setPosition","className","classNames","body_wrapper","with_arrow","bottom","contentMarkup","style","position","render","display","Component","displayName","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AAwBV,IAAAA,KAAK,EAAE,CAA/B;AAAkCX,IAAAA,GAAG,EAAE;AAAvC,GAAnC;;AAEA,MAAIA,GAAJ,EAAS;AACLoB,IAAAA,KAAK,CAACpB,GAAN,GAAY,MAAZ;AACAoB,IAAAA,KAAK,CAACF,MAAN,GAAe,CAAf;AACH;;AAED,MAAIP,KAAJ,EAAW;AACPS,IAAAA,KAAK,CAACT,KAAN,GAAc,MAAd;AACAS,IAAAA,KAAK,CAACe,IAAN,GAAa,CAAb;AACH;;AAED,sBACI5B,4BAAA,MAAA;AAAKqB,IAAAA,GAAG,EAAEhB;AAAaQ,IAAAA,KAAK,EAAEA;AAAON,IAAAA,SAAS,EAAC;AAAOsB,IAAAA,EAAE,EAAC;GAAzD,EACK9B,QADL,CADJ;AAKH;;AAED4B,IAAI,CAACT,WAAL,GAAmB,eAAnB;IAEMY,QAAQ,GAAG;AACb3E,EAAAA,GAAG,EAAHA,GADa;AAEbgE,EAAAA,OAAO,EAAPA,OAFa;AAGbQ,EAAAA,IAAI,EAAJA;AAHa;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-capturer.js","sources":["../../../src/components/key-capturer/key-capturer.tsx"],"sourcesContent":["import React, { useRef } from 'react'\n\ntype Key = 'ArrowUp' | 'ArrowRight' | 'ArrowDown' | 'ArrowLeft' | 'Enter' | 'Backspace' | 'Escape'\n\nconst SUPPORTED_KEYS: Record<string, Key> = {\n ARROW_UP: 'ArrowUp',\n ARROW_RIGHT: 'ArrowRight',\n ARROW_DOWN: 'ArrowDown',\n ARROW_LEFT: 'ArrowLeft',\n ENTER: 'Enter',\n BACKSPACE: 'Backspace',\n ESCAPE: 'Escape',\n}\n\nconst KeyCapturerResolver = {\n resolveByKey(eventKey: string): Key | null {\n switch (eventKey) {\n case 'Left': // IE specific\n case 'ArrowLeft': {\n return 'ArrowLeft'\n }\n case 'Up': // IE specific\n case 'ArrowUp': {\n return 'ArrowUp'\n }\n case 'Right': // IE specific\n case 'ArrowRight': {\n return 'ArrowRight'\n }\n case 'Down': // IE specific\n case 'ArrowDown': {\n return 'ArrowDown'\n }\n case 'Enter': {\n return 'Enter'\n }\n case 'Backspace': {\n return 'Backspace'\n }\n case 'Esc': // IE specific\n case 'Escape': {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n\n resolveByKeyCode(keyCode: number): Key | null {\n switch (keyCode) {\n case 37: {\n return 'ArrowLeft'\n }\n case 38: {\n return 'ArrowUp'\n }\n case 39: {\n return 'ArrowRight'\n }\n case 40: {\n return 'ArrowDown'\n }\n case 13: {\n return 'Enter'\n }\n case 8: {\n return 'Backspace'\n }\n case 27: {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n}\n\ntype EventHandler = (event: React.SyntheticEvent) => void\n\ntype EventHandlerProps = {\n onArrowUp?: EventHandler\n onArrowDown?: EventHandler\n onArrowLeft?: EventHandler\n onArrowRight?: EventHandler\n onEnter?: EventHandler\n onBackspace?: EventHandler\n onEscape?: EventHandler\n}\n\ntype PropagateProps = {\n propagateArrowUp?: boolean\n propagateArrowDown?: boolean\n propagateArrowLeft?: boolean\n propagateArrowRight?: boolean\n propagateEnter?: boolean\n propagateBackspace?: boolean\n propagateEscape?: boolean\n}\n\nconst keyEventHandlerMapping: Record<Key, keyof EventHandlerProps> = {\n ArrowUp: 'onArrowUp',\n ArrowDown: 'onArrowDown',\n ArrowLeft: 'onArrowLeft',\n ArrowRight: 'onArrowRight',\n Enter: 'onEnter',\n Backspace: 'onBackspace',\n Escape: 'onEscape',\n}\n\nconst keyPropagatePropMapping: Record<Key, keyof PropagateProps> = {\n ArrowUp: 'propagateArrowUp',\n ArrowDown: 'propagateArrowDown',\n ArrowLeft: 'propagateArrowLeft',\n ArrowRight: 'propagateArrowRight',\n Enter: 'propagateEnter',\n Backspace: 'propagateBackspace',\n Escape: 'propagateEscape',\n}\n\ntype KeyCapturerProps = EventHandlerProps &\n PropagateProps & {\n eventName?: 'onKeyDown' | 'onKeyDownCapture' | 'onKeyUp' | 'onKeyUpCapture'\n children: React.ReactElement<unknown>\n }\n\n/**\n * Use this component to wrap anything you want to handle key events for (e.g. an input).\n * You can specify the `eventName` to capture (defaults to `onKeyDown`).\n * Check the SUPPORTED_KEYS map to see which keys are supported and supply the respective\n * `on${Key}` prop (i.e. `onEnter` or `onArrowDown`).\n * If you want the default behaviour to be preserved (i.e. only want to hook into the event\n * instead of replacing it) set the `propagate${Key}` prop (e.g. propagateBackspace).\n */\nfunction KeyCapturer(props: KeyCapturerProps) {\n const { children, eventName = 'onKeyDown' } = props\n const composingRef = useRef(false)\n const composingEventHandlers = props.onEnter\n ? {\n onCompositionStart: () => {\n composingRef.current = true\n },\n onCompositionEnd: () => {\n composingRef.current = false\n },\n }\n : undefined\n\n function handleKeyEvent(event: React.KeyboardEvent<HTMLInputElement>) {\n // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode\n const key =\n event.key !== undefined\n ? KeyCapturerResolver.resolveByKey(event.key)\n : KeyCapturerResolver.resolveByKeyCode(event.keyCode)\n\n if (!key) return\n const propagateEvent = props[keyPropagatePropMapping[key]] || false\n const eventHandler = props[keyEventHandlerMapping[key]]\n\n if (key === 'Enter' && eventHandler) {\n if (\n composingRef.current ||\n // Safari fires the onCompositionEnd event before the keydown event, so we\n // have to rely on the 229 keycode, which is Enter when fired from an IME\n // https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode\n (event.keyCode || event.which) === 229\n ) {\n return\n }\n }\n\n if (eventHandler) {\n eventHandler(event)\n if (!propagateEvent) {\n event.preventDefault()\n event.stopPropagation()\n }\n }\n }\n\n return React.cloneElement(children, {\n [eventName]: handleKeyEvent,\n ...composingEventHandlers,\n })\n}\n\nexport { KeyCapturer, KeyCapturerResolver, SUPPORTED_KEYS }\n"],"names":["SUPPORTED_KEYS","ARROW_UP","ARROW_RIGHT","ARROW_DOWN","ARROW_LEFT","ENTER","BACKSPACE","ESCAPE","KeyCapturerResolver","resolveByKey","eventKey","resolveByKeyCode","keyCode","keyEventHandlerMapping","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter","Backspace","Escape","keyPropagatePropMapping","KeyCapturer","props","children","eventName","composingRef","useRef","composingEventHandlers","onEnter","onCompositionStart","current","onCompositionEnd","undefined","handleKeyEvent","event","key","propagateEvent","eventHandler","which","preventDefault","stopPropagation","React","cloneElement"],"mappings":";;;IAIMA,cAAc,GAAwB;AACxCC,EAAAA,QAAQ,EAAE,SAD8B;AAExCC,EAAAA,WAAW,EAAE,YAF2B;AAGxCC,EAAAA,UAAU,EAAE,WAH4B;AAIxCC,EAAAA,UAAU,EAAE,WAJ4B;AAKxCC,EAAAA,KAAK,EAAE,OALiC;AAMxCC,EAAAA,SAAS,EAAE,WAN6B;AAOxCC,EAAAA,MAAM,EAAE;AAPgC;IAUtCC,mBAAmB,GAAG;AACxBC,EAAAA,YADwB,wBACXC,QADW;AAEpB,YAAQA,QAAR;AACI,WAAK,MAAL,CADJ;;AAEI,WAAK,WAAL;AAAkB;AACd,iBAAO,WAAP;AACH;;AACD,WAAK,IAAL,CALJ;;AAMI,WAAK,SAAL;AAAgB;AACZ,iBAAO,SAAP;AACH;;AACD,WAAK,OAAL,CATJ;;AAUI,WAAK,YAAL;AAAmB;AACf,iBAAO,YAAP;AACH;;AACD,WAAK,MAAL,CAbJ;;AAcI,WAAK,WAAL;AAAkB;AACd,iBAAO,WAAP;AACH;;AACD,WAAK,OAAL;AAAc;AACV,iBAAO,OAAP;AACH;;AACD,WAAK,WAAL;AAAkB;AACd,iBAAO,WAAP;AACH;;AACD,WAAK,KAAL,CAvBJ;;AAwBI,WAAK,QAAL;AAAe;AACX,iBAAO,QAAP;AACH;;AACD;AAAS;AACL,iBAAO,IAAP;AACH;AA7BL;AA+BH,GAjCuB;AAmCxBC,EAAAA,gBAnCwB,4BAmCPC,OAnCO;AAoCpB,YAAQA,OAAR;AACI,WAAK,EAAL;AAAS;AACL,iBAAO,WAAP;AACH;;AACD,WAAK,EAAL;AAAS;AACL,iBAAO,SAAP;AACH;;AACD,WAAK,EAAL;AAAS;AACL,iBAAO,YAAP;AACH;;AACD,WAAK,EAAL;AAAS;AACL,iBAAO,WAAP;AACH;;AACD,WAAK,EAAL;AAAS;AACL,iBAAO,OAAP;AACH;;AACD,WAAK,CAAL;AAAQ;AACJ,iBAAO,WAAP;AACH;;AACD,WAAK,EAAL;AAAS;AACL,iBAAO,QAAP;AACH;;AACD;AAAS;AACL,iBAAO,IAAP;AACH;AAxBL;AA0BH;AA9DuB;AAuF5B,IAAMC,sBAAsB,GAAyC;AACjEC,EAAAA,OAAO,EAAE,WADwD;AAEjEC,EAAAA,SAAS,EAAE,aAFsD;AAGjEC,EAAAA,SAAS,EAAE,aAHsD;AAIjEC,EAAAA,UAAU,EAAE,cAJqD;AAKjEC,EAAAA,KAAK,EAAE,SAL0D;AAMjEC,EAAAA,SAAS,EAAE,aANsD;AAOjEC,EAAAA,MAAM,EAAE;AAPyD,CAArE;AAUA,IAAMC,uBAAuB,GAAsC;AAC/DP,EAAAA,OAAO,EAAE,kBADsD;AAE/DC,EAAAA,SAAS,EAAE,oBAFoD;AAG/DC,EAAAA,SAAS,EAAE,oBAHoD;AAI/DC,EAAAA,UAAU,EAAE,qBAJmD;AAK/DC,EAAAA,KAAK,EAAE,gBALwD;AAM/DC,EAAAA,SAAS,EAAE,oBANoD;AAO/DC,EAAAA,MAAM,EAAE;AAPuD,CAAnE;AAgBA;;;;;;;;;AAQA,SAASE,WAAT,CAAqBC,KAArB;;;
|
|
1
|
+
{"version":3,"file":"key-capturer.js","sources":["../../../src/components/key-capturer/key-capturer.tsx"],"sourcesContent":["import React, { useRef } from 'react'\n\ntype Key = 'ArrowUp' | 'ArrowRight' | 'ArrowDown' | 'ArrowLeft' | 'Enter' | 'Backspace' | 'Escape'\n\nconst SUPPORTED_KEYS: Record<string, Key> = {\n ARROW_UP: 'ArrowUp',\n ARROW_RIGHT: 'ArrowRight',\n ARROW_DOWN: 'ArrowDown',\n ARROW_LEFT: 'ArrowLeft',\n ENTER: 'Enter',\n BACKSPACE: 'Backspace',\n ESCAPE: 'Escape',\n}\n\nconst KeyCapturerResolver = {\n resolveByKey(eventKey: string): Key | null {\n switch (eventKey) {\n case 'Left': // IE specific\n case 'ArrowLeft': {\n return 'ArrowLeft'\n }\n case 'Up': // IE specific\n case 'ArrowUp': {\n return 'ArrowUp'\n }\n case 'Right': // IE specific\n case 'ArrowRight': {\n return 'ArrowRight'\n }\n case 'Down': // IE specific\n case 'ArrowDown': {\n return 'ArrowDown'\n }\n case 'Enter': {\n return 'Enter'\n }\n case 'Backspace': {\n return 'Backspace'\n }\n case 'Esc': // IE specific\n case 'Escape': {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n\n resolveByKeyCode(keyCode: number): Key | null {\n switch (keyCode) {\n case 37: {\n return 'ArrowLeft'\n }\n case 38: {\n return 'ArrowUp'\n }\n case 39: {\n return 'ArrowRight'\n }\n case 40: {\n return 'ArrowDown'\n }\n case 13: {\n return 'Enter'\n }\n case 8: {\n return 'Backspace'\n }\n case 27: {\n return 'Escape'\n }\n default: {\n return null\n }\n }\n },\n}\n\ntype EventHandler = (event: React.SyntheticEvent) => void\n\ntype EventHandlerProps = {\n onArrowUp?: EventHandler\n onArrowDown?: EventHandler\n onArrowLeft?: EventHandler\n onArrowRight?: EventHandler\n onEnter?: EventHandler\n onBackspace?: EventHandler\n onEscape?: EventHandler\n}\n\ntype PropagateProps = {\n propagateArrowUp?: boolean\n propagateArrowDown?: boolean\n propagateArrowLeft?: boolean\n propagateArrowRight?: boolean\n propagateEnter?: boolean\n propagateBackspace?: boolean\n propagateEscape?: boolean\n}\n\nconst keyEventHandlerMapping: Record<Key, keyof EventHandlerProps> = {\n ArrowUp: 'onArrowUp',\n ArrowDown: 'onArrowDown',\n ArrowLeft: 'onArrowLeft',\n ArrowRight: 'onArrowRight',\n Enter: 'onEnter',\n Backspace: 'onBackspace',\n Escape: 'onEscape',\n}\n\nconst keyPropagatePropMapping: Record<Key, keyof PropagateProps> = {\n ArrowUp: 'propagateArrowUp',\n ArrowDown: 'propagateArrowDown',\n ArrowLeft: 'propagateArrowLeft',\n ArrowRight: 'propagateArrowRight',\n Enter: 'propagateEnter',\n Backspace: 'propagateBackspace',\n Escape: 'propagateEscape',\n}\n\ntype KeyCapturerProps = EventHandlerProps &\n PropagateProps & {\n eventName?: 'onKeyDown' | 'onKeyDownCapture' | 'onKeyUp' | 'onKeyUpCapture'\n children: React.ReactElement<unknown>\n }\n\n/**\n * Use this component to wrap anything you want to handle key events for (e.g. an input).\n * You can specify the `eventName` to capture (defaults to `onKeyDown`).\n * Check the SUPPORTED_KEYS map to see which keys are supported and supply the respective\n * `on${Key}` prop (i.e. `onEnter` or `onArrowDown`).\n * If you want the default behaviour to be preserved (i.e. only want to hook into the event\n * instead of replacing it) set the `propagate${Key}` prop (e.g. propagateBackspace).\n */\nfunction KeyCapturer(props: KeyCapturerProps) {\n const { children, eventName = 'onKeyDown' } = props\n const composingRef = useRef(false)\n const composingEventHandlers = props.onEnter\n ? {\n onCompositionStart: () => {\n composingRef.current = true\n },\n onCompositionEnd: () => {\n composingRef.current = false\n },\n }\n : undefined\n\n function handleKeyEvent(event: React.KeyboardEvent<HTMLInputElement>) {\n // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode\n const key =\n event.key !== undefined\n ? KeyCapturerResolver.resolveByKey(event.key)\n : KeyCapturerResolver.resolveByKeyCode(event.keyCode)\n\n if (!key) return\n const propagateEvent = props[keyPropagatePropMapping[key]] || false\n const eventHandler = props[keyEventHandlerMapping[key]]\n\n if (key === 'Enter' && eventHandler) {\n if (\n composingRef.current ||\n // Safari fires the onCompositionEnd event before the keydown event, so we\n // have to rely on the 229 keycode, which is Enter when fired from an IME\n // https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode\n (event.keyCode || event.which) === 229\n ) {\n return\n }\n }\n\n if (eventHandler) {\n eventHandler(event)\n if (!propagateEvent) {\n event.preventDefault()\n event.stopPropagation()\n }\n }\n }\n\n return React.cloneElement(children, {\n [eventName]: handleKeyEvent,\n ...composingEventHandlers,\n })\n}\n\nexport { KeyCapturer, KeyCapturerResolver, SUPPORTED_KEYS }\n"],"names":["SUPPORTED_KEYS","ARROW_UP","ARROW_RIGHT","ARROW_DOWN","ARROW_LEFT","ENTER","BACKSPACE","ESCAPE","KeyCapturerResolver","resolveByKey","eventKey","resolveByKeyCode","keyCode","keyEventHandlerMapping","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Enter","Backspace","Escape","keyPropagatePropMapping","KeyCapturer","props","children","eventName","composingRef","useRef","composingEventHandlers","onEnter","onCompositionStart","current","onCompositionEnd","undefined","handleKeyEvent","event","key","propagateEvent","eventHandler","which","preventDefault","stopPropagation","React","cloneElement"],"mappings":";;;IAIMA,cAAc,GAAwB;AACxCC,EAAAA,QAAQ,EAAE,SAD8B;AAExCC,EAAAA,WAAW,EAAE,YAF2B;AAGxCC,EAAAA,UAAU,EAAE,WAH4B;AAIxCC,EAAAA,UAAU,EAAE,WAJ4B;AAKxCC,EAAAA,KAAK,EAAE,OALiC;AAMxCC,EAAAA,SAAS,EAAE,WAN6B;AAOxCC,EAAAA,MAAM,EAAE;AAPgC;IAUtCC,mBAAmB,GAAG;AACxBC,EAAAA,YADwB,wBACXC,QADW;AAEpB,YAAQA,QAAR;AACI,WAAK,MAAL,CADJ;;AAEI,WAAK,WAAL;AAAkB;AACd,iBAAO,WAAP;AACH;;AACD,WAAK,IAAL,CALJ;;AAMI,WAAK,SAAL;AAAgB;AACZ,iBAAO,SAAP;AACH;;AACD,WAAK,OAAL,CATJ;;AAUI,WAAK,YAAL;AAAmB;AACf,iBAAO,YAAP;AACH;;AACD,WAAK,MAAL,CAbJ;;AAcI,WAAK,WAAL;AAAkB;AACd,iBAAO,WAAP;AACH;;AACD,WAAK,OAAL;AAAc;AACV,iBAAO,OAAP;AACH;;AACD,WAAK,WAAL;AAAkB;AACd,iBAAO,WAAP;AACH;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qBAEAN,sBAFA,EAAP;AAIH;;;;"}
|
|
@@ -2,6 +2,7 @@ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '.
|
|
|
2
2
|
import { createElement, Fragment } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
|
|
5
|
+
var _excluded = ["children", "className", "translateKey", "isMac"];
|
|
5
6
|
// Support for setting up how to translate modifiers globally.
|
|
6
7
|
//
|
|
7
8
|
|
|
@@ -85,7 +86,7 @@ function KeyboardShortcut(_ref) {
|
|
|
85
86
|
translateKey = _ref$translateKey === void 0 ? globalTranslateKey : _ref$translateKey,
|
|
86
87
|
_ref$isMac = _ref.isMac,
|
|
87
88
|
isMac = _ref$isMac === void 0 ? (_navigator$platform$t = (_navigator$platform = navigator.platform) === null || _navigator$platform === void 0 ? void 0 : _navigator$platform.toUpperCase().includes('MAC')) !== null && _navigator$platform$t !== void 0 ? _navigator$platform$t : false : _ref$isMac,
|
|
88
|
-
props = _objectWithoutPropertiesLoose(_ref,
|
|
89
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
89
90
|
|
|
90
91
|
var shortcuts = typeof children === 'string' ? [children] : children;
|
|
91
92
|
return /*#__PURE__*/createElement("span", Object.assign({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard-shortcut.js","sources":["../../../src/components/keyboard-shortcut/keyboard-shortcut.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\n//\n// Support for setting up how to translate modifiers globally.\n//\n\nlet globalTranslateKey = (key: string) => key\n\ntype TranslateKey = typeof globalTranslateKey\n\nKeyboardShortcut.setTranslateKey = (tr: TranslateKey) => {\n globalTranslateKey = tr\n}\n\nfunction translateKeyMac(key: string) {\n switch (key.toLowerCase()) {\n case 'cmd':\n case 'mod':\n return '⌘'\n case 'control':\n case 'ctrl':\n return '⌃'\n case 'alt':\n return '⌥'\n case 'shift':\n return '⇧'\n case 'space':\n return '␣'\n default:\n return key\n }\n}\n\n//\n// Some helpers\n//\n\nfunction capitalize(str: string) {\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()\n}\n\nfunction hasModifiers(str: string) {\n return /\\b(mod|cmd|ctrl|control|alt|shift)\\b/i.test(str)\n}\n\nfunction isSpecialKey(str: string) {\n return /^(mod|cmd|ctrl|control|alt|shift|space|super)$/i.test(str)\n}\n\nfunction parseKeys(shortcut: string, isMac: boolean, translateKey: TranslateKey) {\n const t = isMac ? translateKeyMac : translateKey\n const _hasModifiers = hasModifiers(shortcut)\n\n function mapIndividualKey(str: string) {\n if (isSpecialKey(str)) {\n return capitalize(t(str))\n }\n if (_hasModifiers && str.length === 1) {\n return str.toUpperCase()\n }\n return str\n }\n\n if (!isMac) {\n shortcut = shortcut.replace(/\\b(mod|cmd)\\b/i, 'ctrl')\n }\n\n return shortcut.split(/\\s*\\+\\s*/).map(mapIndividualKey)\n}\n\n//\n// The KeyboardShortcut component\n//\n\ntype NativeSpanProps = React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLSpanElement>,\n HTMLSpanElement\n>\n\ntype Props = Omit<NativeSpanProps, 'children'> & {\n /**\n * The shortcut to be represented as markup. It supports an intuitive syntax where you can\n * combine modifiers (cmd, ctrl, shift, alt) with single keys all concatenated with plus signs.\n * You can also pass various shortcuts as an array, which will be depicted separated by commas.\n */\n children: string | string[]\n /**\n * A function that allows you to change how some key names are represented. This may be useful,\n * for instance, to translate modifier names that are expressed differently in other languages\n * (e.g. `Ctrl` is named `Strg` in German).\n *\n * It defaults to a global version that leaves the key as is. You can pass your version as a\n * prop, or you can also set your own version of this global default one, so you don't need to\n * pass your own on each invocation of this component.\n *\n * ```js\n * import { KeyboardShortcut } from '@doist/reactist'\n * KeyboardShortcut.setTranslateKey = key => { ... }\n * ```\n *\n * Note: When the component detects the macOS operating system it bypasses key translation for\n * most modifiers and uses macOS-specific symbols. See the `isMac` prop for details.\n */\n translateKey?: TranslateKey\n /**\n * This prop is not meant to be passed. The component will automatically initialize it to `true`\n * if it detects that the current browser / operating system is on macOS, in which case modifier\n * keys are represented using macOS' notation (e.g. ⌘ ⌃ ⌥ ⇧).\n *\n * Though it is discouraged, if you don't want this special treatment in macOS, you can pass\n * `isMac={false}` in all invocations of this component.\n */\n isMac?: boolean\n}\n\nfunction KeyboardShortcut({\n children,\n className,\n translateKey = globalTranslateKey,\n isMac = navigator.platform?.toUpperCase().includes('MAC') ?? false,\n ...props\n}: Props) {\n const shortcuts = typeof children === 'string' ? [children] : children\n return (\n <span\n className={classNames('reactist_keyboard_shortcut', className, {\n 'reactist_keyboard_shortcut--macos': isMac,\n })}\n {...props}\n >\n {shortcuts.map((shortcut, i) => (\n <React.Fragment key={i}>\n {i === 0 ? null : ', '}\n <kbd>\n {parseKeys(shortcut, isMac, translateKey).map((key, j) => (\n <kbd key={j}>{key}</kbd>\n ))}\n </kbd>\n </React.Fragment>\n ))}\n </span>\n )\n}\n\nexport { KeyboardShortcut }\n"],"names":["globalTranslateKey","key","KeyboardShortcut","setTranslateKey","tr","translateKeyMac","toLowerCase","capitalize","str","charAt","toUpperCase","slice","hasModifiers","test","isSpecialKey","parseKeys","shortcut","isMac","translateKey","t","_hasModifiers","mapIndividualKey","length","replace","split","map","children","className","navigator","platform","includes","props","shortcuts","React","classNames","i","j"],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyboard-shortcut.js","sources":["../../../src/components/keyboard-shortcut/keyboard-shortcut.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\n\n//\n// Support for setting up how to translate modifiers globally.\n//\n\nlet globalTranslateKey = (key: string) => key\n\ntype TranslateKey = typeof globalTranslateKey\n\nKeyboardShortcut.setTranslateKey = (tr: TranslateKey) => {\n globalTranslateKey = tr\n}\n\nfunction translateKeyMac(key: string) {\n switch (key.toLowerCase()) {\n case 'cmd':\n case 'mod':\n return '⌘'\n case 'control':\n case 'ctrl':\n return '⌃'\n case 'alt':\n return '⌥'\n case 'shift':\n return '⇧'\n case 'space':\n return '␣'\n default:\n return key\n }\n}\n\n//\n// Some helpers\n//\n\nfunction capitalize(str: string) {\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()\n}\n\nfunction hasModifiers(str: string) {\n return /\\b(mod|cmd|ctrl|control|alt|shift)\\b/i.test(str)\n}\n\nfunction isSpecialKey(str: string) {\n return /^(mod|cmd|ctrl|control|alt|shift|space|super)$/i.test(str)\n}\n\nfunction parseKeys(shortcut: string, isMac: boolean, translateKey: TranslateKey) {\n const t = isMac ? translateKeyMac : translateKey\n const _hasModifiers = hasModifiers(shortcut)\n\n function mapIndividualKey(str: string) {\n if (isSpecialKey(str)) {\n return capitalize(t(str))\n }\n if (_hasModifiers && str.length === 1) {\n return str.toUpperCase()\n }\n return str\n }\n\n if (!isMac) {\n shortcut = shortcut.replace(/\\b(mod|cmd)\\b/i, 'ctrl')\n }\n\n return shortcut.split(/\\s*\\+\\s*/).map(mapIndividualKey)\n}\n\n//\n// The KeyboardShortcut component\n//\n\ntype NativeSpanProps = React.DetailedHTMLProps<\n React.HTMLAttributes<HTMLSpanElement>,\n HTMLSpanElement\n>\n\ntype Props = Omit<NativeSpanProps, 'children'> & {\n /**\n * The shortcut to be represented as markup. It supports an intuitive syntax where you can\n * combine modifiers (cmd, ctrl, shift, alt) with single keys all concatenated with plus signs.\n * You can also pass various shortcuts as an array, which will be depicted separated by commas.\n */\n children: string | string[]\n /**\n * A function that allows you to change how some key names are represented. This may be useful,\n * for instance, to translate modifier names that are expressed differently in other languages\n * (e.g. `Ctrl` is named `Strg` in German).\n *\n * It defaults to a global version that leaves the key as is. You can pass your version as a\n * prop, or you can also set your own version of this global default one, so you don't need to\n * pass your own on each invocation of this component.\n *\n * ```js\n * import { KeyboardShortcut } from '@doist/reactist'\n * KeyboardShortcut.setTranslateKey = key => { ... }\n * ```\n *\n * Note: When the component detects the macOS operating system it bypasses key translation for\n * most modifiers and uses macOS-specific symbols. See the `isMac` prop for details.\n */\n translateKey?: TranslateKey\n /**\n * This prop is not meant to be passed. The component will automatically initialize it to `true`\n * if it detects that the current browser / operating system is on macOS, in which case modifier\n * keys are represented using macOS' notation (e.g. ⌘ ⌃ ⌥ ⇧).\n *\n * Though it is discouraged, if you don't want this special treatment in macOS, you can pass\n * `isMac={false}` in all invocations of this component.\n */\n isMac?: boolean\n}\n\nfunction KeyboardShortcut({\n children,\n className,\n translateKey = globalTranslateKey,\n isMac = navigator.platform?.toUpperCase().includes('MAC') ?? false,\n ...props\n}: Props) {\n const shortcuts = typeof children === 'string' ? [children] : children\n return (\n <span\n className={classNames('reactist_keyboard_shortcut', className, {\n 'reactist_keyboard_shortcut--macos': isMac,\n })}\n {...props}\n >\n {shortcuts.map((shortcut, i) => (\n <React.Fragment key={i}>\n {i === 0 ? null : ', '}\n <kbd>\n {parseKeys(shortcut, isMac, translateKey).map((key, j) => (\n <kbd key={j}>{key}</kbd>\n ))}\n </kbd>\n </React.Fragment>\n ))}\n </span>\n )\n}\n\nexport { KeyboardShortcut }\n"],"names":["globalTranslateKey","key","KeyboardShortcut","setTranslateKey","tr","translateKeyMac","toLowerCase","capitalize","str","charAt","toUpperCase","slice","hasModifiers","test","isSpecialKey","parseKeys","shortcut","isMac","translateKey","t","_hasModifiers","mapIndividualKey","length","replace","split","map","children","className","navigator","platform","includes","props","shortcuts","React","classNames","i","j"],"mappings":";;;;;AAIA;AACA;;AAEA,IAAIA,kBAAkB,GAAG,4BAACC,GAAD;AAAA,SAAiBA,GAAjB;AAAA,CAAzB;;AAIAC,gBAAgB,CAACC,eAAjB,GAAmC,UAACC,EAAD;AAC/BJ,EAAAA,kBAAkB,GAAGI,EAArB;AACH,CAFD;;AAIA,SAASC,eAAT,CAAyBJ,GAAzB;AACI,UAAQA,GAAG,CAACK,WAAJ,EAAR;AACI,SAAK,KAAL;AACA,SAAK,KAAL;AACI,aAAO,GAAP;;AACJ,SAAK,SAAL;AACA,SAAK,MAAL;AACI,aAAO,GAAP;;AACJ,SAAK,KAAL;AACI,aAAO,GAAP;;A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BAAoBnB,WAApB,GAAkCoB,QAAlC,CAA2C,KAA3C,0EAAqD;MAC1DC;;AAEH,MAAMC,SAAS,GAAG,OAAON,QAAP,KAAoB,QAApB,GAA+B,CAACA,QAAD,CAA/B,GAA4CA,QAA9D;AACA,sBACIO,aAAA,OAAA;AACIN,IAAAA,SAAS,EAAEO,UAAU,CAAC,4BAAD,EAA+BP,SAA/B,EAA0C;AAC3D,2CAAqCV;AADsB,KAA1C;KAGjBc,MAJR,EAMKC,SAAS,CAACP,GAAV,CAAc,UAACT,QAAD,EAAWmB,CAAX;AAAA,wBACXF,aAAA,CAACA,QAAD;AAAgBhC,MAAAA,GAAG,EAAEkC;KAArB,EACKA,CAAC,KAAK,CAAN,GAAU,IAAV,GAAiB,IADtB,eAEIF,aAAA,MAAA,MAAA,EACKlB,SAAS,CAACC,QAAD,EAAWC,KAAX,EAAkBC,YAAlB,CAAT,CAAyCO,GAAzC,CAA6C,UAACxB,GAAD,EAAMmC,CAAN;AAAA,0BAC1CH,aAAA,MAAA;AAAKhC,QAAAA,GAAG,EAAEmC;OAAV,EAAcnC,GAAd,CAD0C;AAAA,KAA7C,CADL,CAFJ,CADW;AAAA,GAAd,CANL,CADJ;AAmBH;;;;"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
-
import { useCallback, useMemo, createElement, useContext, forwardRef, Children, cloneElement, createContext } from 'react';
|
|
2
|
+
import { useCallback, useMemo, createElement, useContext, useEffect, forwardRef, Children, cloneElement, createContext } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { polymorphicComponent } from '../../utils/polymorphism.js';
|
|
5
|
+
import { usePrevious } from '../../hooks/use-previous/use-previous.js';
|
|
5
6
|
import { useMenuState, MenuButton as MenuButton$1, Menu as Menu$1, MenuItem as MenuItem$1, MenuGroup as MenuGroup$1 } from 'reakit/Menu';
|
|
6
7
|
import { PopoverBackdrop } from 'reakit/Popover';
|
|
7
8
|
|
|
9
|
+
var _excluded = ["children", "onItemSelect"],
|
|
10
|
+
_excluded2 = ["exceptionallySetClassName"],
|
|
11
|
+
_excluded3 = ["handleItemSelect"],
|
|
12
|
+
_excluded4 = ["exceptionallySetClassName"],
|
|
13
|
+
_excluded5 = ["handleItemSelect"],
|
|
14
|
+
_excluded6 = ["value", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName"],
|
|
15
|
+
_excluded7 = ["handleItemSelect"],
|
|
16
|
+
_excluded8 = ["children", "onItemSelect"],
|
|
17
|
+
_excluded9 = ["handleItemSelect"],
|
|
18
|
+
_excluded10 = ["label", "children", "exceptionallySetClassName"],
|
|
19
|
+
_excluded11 = ["handleItemSelect"];
|
|
8
20
|
var MenuContext = /*#__PURE__*/createContext( // Reakit gives us no means to obtain a valid initial/default value of type MenuStateReturn
|
|
9
21
|
// (it is normally obtained by calling useMenuState but we can't call hooks outside components).
|
|
10
22
|
// This is however of little consequence since this value is only used if some of the components
|
|
@@ -19,7 +31,7 @@ var MenuContext = /*#__PURE__*/createContext( // Reakit gives us no means to obt
|
|
|
19
31
|
function Menu(_ref) {
|
|
20
32
|
var children = _ref.children,
|
|
21
33
|
onItemSelect = _ref.onItemSelect,
|
|
22
|
-
props = _objectWithoutPropertiesLoose(_ref,
|
|
34
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
35
|
|
|
24
36
|
var state = useMenuState(_objectSpread2({
|
|
25
37
|
loop: true
|
|
@@ -43,10 +55,10 @@ function Menu(_ref) {
|
|
|
43
55
|
|
|
44
56
|
var MenuButton = /*#__PURE__*/polymorphicComponent(function MenuButton(_ref2, ref) {
|
|
45
57
|
var exceptionallySetClassName = _ref2.exceptionallySetClassName,
|
|
46
|
-
props = _objectWithoutPropertiesLoose(_ref2,
|
|
58
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
47
59
|
|
|
48
60
|
var _React$useContext = useContext(MenuContext),
|
|
49
|
-
state = _objectWithoutPropertiesLoose(_React$useContext,
|
|
61
|
+
state = _objectWithoutPropertiesLoose(_React$useContext, _excluded3);
|
|
50
62
|
|
|
51
63
|
return /*#__PURE__*/createElement(MenuButton$1, Object.assign({}, props, state, {
|
|
52
64
|
ref: ref,
|
|
@@ -90,11 +102,19 @@ function MenuBackdrop(_ref3) {
|
|
|
90
102
|
|
|
91
103
|
var MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref4, ref) {
|
|
92
104
|
var exceptionallySetClassName = _ref4.exceptionallySetClassName,
|
|
93
|
-
props = _objectWithoutPropertiesLoose(_ref4,
|
|
105
|
+
props = _objectWithoutPropertiesLoose(_ref4, _excluded4);
|
|
94
106
|
|
|
95
107
|
var _React$useContext2 = useContext(MenuContext),
|
|
96
|
-
state = _objectWithoutPropertiesLoose(_React$useContext2,
|
|
108
|
+
state = _objectWithoutPropertiesLoose(_React$useContext2, _excluded5);
|
|
97
109
|
|
|
110
|
+
var previousVisible = usePrevious(state.visible);
|
|
111
|
+
useEffect(function focusTriggerOnClose() {
|
|
112
|
+
if (state.visible === false && previousVisible === true) {
|
|
113
|
+
var _state$unstable_refer, _state$unstable_refer2;
|
|
114
|
+
|
|
115
|
+
(_state$unstable_refer = state.unstable_referenceRef) === null || _state$unstable_refer === void 0 ? void 0 : (_state$unstable_refer2 = _state$unstable_refer.current) === null || _state$unstable_refer2 === void 0 ? void 0 : _state$unstable_refer2.focus();
|
|
116
|
+
}
|
|
117
|
+
}, [state.visible, previousVisible, state.unstable_referenceRef]);
|
|
98
118
|
return state.visible ? /*#__PURE__*/createElement(MenuBackdrop, Object.assign({}, state), /*#__PURE__*/createElement(Menu$1, Object.assign({}, props, state, {
|
|
99
119
|
ref: ref,
|
|
100
120
|
className: classNames('reactist_menulist', exceptionallySetClassName)
|
|
@@ -113,11 +133,11 @@ var MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref) {
|
|
|
113
133
|
hideOnSelect = _ref5$hideOnSelect === void 0 ? true : _ref5$hideOnSelect,
|
|
114
134
|
onClick = _ref5.onClick,
|
|
115
135
|
exceptionallySetClassName = _ref5.exceptionallySetClassName,
|
|
116
|
-
props = _objectWithoutPropertiesLoose(_ref5,
|
|
136
|
+
props = _objectWithoutPropertiesLoose(_ref5, _excluded6);
|
|
117
137
|
|
|
118
138
|
var _React$useContext3 = useContext(MenuContext),
|
|
119
139
|
handleItemSelect = _React$useContext3.handleItemSelect,
|
|
120
|
-
state = _objectWithoutPropertiesLoose(_React$useContext3,
|
|
140
|
+
state = _objectWithoutPropertiesLoose(_React$useContext3, _excluded7);
|
|
121
141
|
|
|
122
142
|
var hide = state.hide;
|
|
123
143
|
var handleClick = useCallback(function handleClick(event) {
|
|
@@ -158,11 +178,11 @@ var MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref) {
|
|
|
158
178
|
var SubMenu = /*#__PURE__*/forwardRef(function SubMenu(_ref6, ref) {
|
|
159
179
|
var children = _ref6.children,
|
|
160
180
|
onItemSelect = _ref6.onItemSelect,
|
|
161
|
-
props = _objectWithoutPropertiesLoose(_ref6,
|
|
181
|
+
props = _objectWithoutPropertiesLoose(_ref6, _excluded8);
|
|
162
182
|
|
|
163
183
|
var _React$useContext4 = useContext(MenuContext),
|
|
164
184
|
parentMenuItemSelect = _React$useContext4.handleItemSelect,
|
|
165
|
-
state = _objectWithoutPropertiesLoose(_React$useContext4,
|
|
185
|
+
state = _objectWithoutPropertiesLoose(_React$useContext4, _excluded9);
|
|
166
186
|
|
|
167
187
|
var parentMenuHide = state.hide;
|
|
168
188
|
var handleSubItemSelect = useCallback(function handleSubItemSelect(value) {
|
|
@@ -196,10 +216,10 @@ var MenuGroup = /*#__PURE__*/polymorphicComponent(function MenuGroud(_ref7, ref)
|
|
|
196
216
|
var label = _ref7.label,
|
|
197
217
|
children = _ref7.children,
|
|
198
218
|
exceptionallySetClassName = _ref7.exceptionallySetClassName,
|
|
199
|
-
props = _objectWithoutPropertiesLoose(_ref7,
|
|
219
|
+
props = _objectWithoutPropertiesLoose(_ref7, _excluded10);
|
|
200
220
|
|
|
201
221
|
var _React$useContext5 = useContext(MenuContext),
|
|
202
|
-
state = _objectWithoutPropertiesLoose(_React$useContext5,
|
|
222
|
+
state = _objectWithoutPropertiesLoose(_React$useContext5, _excluded11);
|
|
203
223
|
|
|
204
224
|
return /*#__PURE__*/createElement(MenuGroup$1, Object.assign({
|
|
205
225
|
ref: ref
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","sources":["../../../src/components/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\nimport { polymorphicComponent } from '../../utils/polymorphism'\n\n//\n// Reactist menu is a thin wrapper around Reakit's menu components. This may or may not be\n// temporary. Our goal is to make it transparent for the users of Reactist of this implementation\n// detail. We may change in the future the external lib we use, or even implement it all internally,\n// as long as we keep the same outer interface as intact as possible.\n//\n// Around the heavy lifting of the external lib we just add some features to better integrate the\n// menu to Reactist's more opinionated approach (e.g. using our button with its custom variants and\n// other features, easily show keyboard shortcuts in menu items, etc.)\n//\nimport * as Reakit from 'reakit/Menu'\nimport { PopoverBackdrop } from 'reakit/Popover'\n\nimport './menu.less'\n\ntype NativeProps<E extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<E>, E>\n\ntype MenuContextState = Reakit.MenuStateReturn & {\n handleItemSelect: (value: string | null | undefined) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>(\n // Reakit gives us no means to obtain a valid initial/default value of type MenuStateReturn\n // (it is normally obtained by calling useMenuState but we can't call hooks outside components).\n // This is however of little consequence since this value is only used if some of the components\n // are used outside Menu, something that should not happen and we do not support.\n // @ts-expect-error\n {},\n)\n\n//\n// Menu\n//\n\ntype MenuProps = Omit<Reakit.MenuInitialState, 'visible'> & {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const state = Reakit.useMenuState({ loop: true, ...props })\n\n const handleItemSelect = React.useCallback(\n function handleItemSelect(value: string | null | undefined) {\n if (onItemSelect) onItemSelect(value)\n },\n [onItemSelect],\n )\n\n const value: MenuContextState = React.useMemo(\n () => ({\n ...state,\n handleItemSelect,\n }),\n [state, handleItemSelect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ntype MenuButtonProps = Omit<Reakit.MenuButtonProps, keyof Reakit.MenuStateReturn | 'className'>\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = polymorphicComponent<'button', MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n return (\n <Reakit.MenuButton\n {...props}\n {...state}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// MenuList\n//\n\ntype MenuBackdropProps = Reakit.MenuStateReturn & {\n children: React.ReactNode\n}\n\nconst BACKDROP_STYLE: React.CSSProperties = {\n width: '100%',\n height: '100%',\n position: 'fixed',\n top: 0,\n left: 0,\n}\n\n/**\n * Internal component to provide a backdrop/overlay to all menus. This is needed because reakit's\n * menus do not show an overlay by default.\n */\nfunction MenuBackdrop({\n baseId,\n visible,\n animated,\n animating,\n stopAnimation,\n modal,\n children,\n}: MenuBackdropProps) {\n return (\n <PopoverBackdrop\n baseId={baseId}\n visible={visible}\n animated={animated}\n animating={animating}\n stopAnimation={stopAnimation}\n modal={modal}\n style={BACKDROP_STYLE}\n >\n {children}\n </PopoverBackdrop>\n )\n}\n\ntype MenuListProps = Omit<Reakit.MenuProps, keyof Reakit.MenuStateReturn | 'className'>\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = polymorphicComponent<'div', MenuListProps>(function MenuList(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n return state.visible ? (\n <MenuBackdrop {...state}>\n <Reakit.Menu\n {...props}\n {...state}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n />\n </MenuBackdrop>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ntype MenuItemProps = {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n /**\n * The content inside the menu item.\n */\n children: React.ReactNode\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = polymorphicComponent<'button', MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n const { hide } = state\n\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent<HTMLButtonElement>) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <Reakit.MenuItem\n {...props}\n {...state}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n >\n {children}\n </Reakit.MenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLButtonElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect, ...props },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, ...state } = React.useContext(MenuContext)\n const { hide: parentMenuHide } = state\n\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value) {\n if (onItemSelect) onItemSelect(value)\n parentMenuItemSelect(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n\n return (\n <Reakit.MenuItem {...state} {...props} ref={ref}>\n {(buttonProps) => (\n <Menu onItemSelect={handleSubItemSelect}>\n {React.cloneElement(button as React.ReactElement, {\n ...buttonProps,\n className: classNames(buttonProps.className, 'reactist_submenu_button'),\n })}\n {list}\n </Menu>\n )}\n </Reakit.MenuItem>\n )\n})\n\n//\n// MenuGroup\n//\n\ntype MenuGroupProps = Omit<NativeProps<HTMLDivElement>, 'className'> & {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = polymorphicComponent<'div', MenuGroupProps>(function MenuGroud(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n return (\n <Reakit.MenuGroup ref={ref} {...props} {...state} className={exceptionallySetClassName}>\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </Reakit.MenuGroup>\n )\n})\n\nexport { Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, SubMenuProps, MenuGroupProps }\n"],"names":["MenuContext","React","Menu","children","onItemSelect","props","state","Reakit","loop","handleItemSelect","value","Provider","MenuButton","polymorphicComponent","ref","exceptionallySetClassName","className","classNames","BACKDROP_STYLE","width","height","position","top","left","MenuBackdrop","baseId","visible","animated","animating","stopAnimation","modal","PopoverBackdrop","style","MenuList","MenuItem","onSelect","hideOnSelect","onClick","hide","handleClick","event","onSelectResult","defaultPrevented","undefined","shouldClose","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","toArray","button","list","buttonProps","MenuGroup","Menu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AAEGpC,MAAAA,SAAS,EAAEC,UAAU,CAACmC,WAAW,CAACpC,SAAb,EAAwB,yBAAxB;AAFxB,OADL,EAKKmC,IALL,CADH;AAAA,GADL,CADJ;AAaH,CA/Be;AA4ChB;;;;;;;IAMME,SAAS,gBAAGxC,oBAAoB,CAAwB,SAASyC,SAAT,QAE1DxC,GAF0D;MACxDyC,cAAAA;MAAOpD,iBAAAA;MAAUY,kCAAAA;MAA8BV;;2BAGVJ,UAAA,CAAiBD,WAAjB;MAAVM;;AAC7B,sBACIL,aAAA,CAACM,WAAD;AAAkBO,IAAAA,GAAG,EAAEA;KAAST,OAAWC;AAAOU,IAAAA,SAAS,EAAED;IAA7D,EACKwC,KAAK,gBACFtD,aAAA,MAAA;AAAKuD,IAAAA,IAAI,EAAC;AAAexC,IAAAA,SAAS,EAAC;GAAnC,EACKuC,KADL,CADE,GAIF,IALR,EAMKpD,QANL,CADJ;AAUH,CAfqC;;;;"}
|
|
1
|
+
{"version":3,"file":"menu.js","sources":["../../../src/components/menu/menu.tsx"],"sourcesContent":["import * as React from 'react'\nimport classNames from 'classnames'\nimport { polymorphicComponent } from '../../utils/polymorphism'\nimport { usePrevious } from '../../hooks/use-previous'\n\n//\n// Reactist menu is a thin wrapper around Reakit's menu components. This may or may not be\n// temporary. Our goal is to make it transparent for the users of Reactist of this implementation\n// detail. We may change in the future the external lib we use, or even implement it all internally,\n// as long as we keep the same outer interface as intact as possible.\n//\n// Around the heavy lifting of the external lib we just add some features to better integrate the\n// menu to Reactist's more opinionated approach (e.g. using our button with its custom variants and\n// other features, easily show keyboard shortcuts in menu items, etc.)\n//\nimport * as Reakit from 'reakit/Menu'\nimport { PopoverBackdrop } from 'reakit/Popover'\n\nimport './menu.less'\n\ntype NativeProps<E extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<E>, E>\n\ntype MenuContextState = Reakit.MenuStateReturn & {\n handleItemSelect: (value: string | null | undefined) => void\n}\n\nconst MenuContext = React.createContext<MenuContextState>(\n // Reakit gives us no means to obtain a valid initial/default value of type MenuStateReturn\n // (it is normally obtained by calling useMenuState but we can't call hooks outside components).\n // This is however of little consequence since this value is only used if some of the components\n // are used outside Menu, something that should not happen and we do not support.\n // @ts-expect-error\n {},\n)\n\n//\n// Menu\n//\n\ntype MenuProps = Omit<Reakit.MenuInitialState, 'visible'> & {\n /**\n * The `Menu` must contain a `MenuList` that defines the menu options. It must also contain a\n * `MenuButton` that triggers the menu to be opened or closed.\n */\n children: React.ReactNode\n\n /**\n * An optional callback that will be called back whenever a menu item is selected. It receives\n * the `value` of the selected `MenuItem`.\n *\n * If you pass down this callback, it is recommended that you properly memoize it so it does not\n * change on every render.\n */\n onItemSelect?: (value: string | null | undefined) => void\n}\n\n/**\n * Wrapper component to control a menu. It does not render anything, only providing the state\n * management for the menu components inside it.\n */\nfunction Menu({ children, onItemSelect, ...props }: MenuProps) {\n const state = Reakit.useMenuState({ loop: true, ...props })\n\n const handleItemSelect = React.useCallback(\n function handleItemSelect(value: string | null | undefined) {\n if (onItemSelect) onItemSelect(value)\n },\n [onItemSelect],\n )\n\n const value: MenuContextState = React.useMemo(\n () => ({\n ...state,\n handleItemSelect,\n }),\n [state, handleItemSelect],\n )\n\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>\n}\n\n//\n// MenuButton\n//\n\ntype MenuButtonProps = Omit<Reakit.MenuButtonProps, keyof Reakit.MenuStateReturn | 'className'>\n\n/**\n * A button to toggle a dropdown menu open or closed.\n */\nconst MenuButton = polymorphicComponent<'button', MenuButtonProps>(function MenuButton(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n return (\n <Reakit.MenuButton\n {...props}\n {...state}\n ref={ref}\n className={classNames('reactist_menubutton', exceptionallySetClassName)}\n />\n )\n})\n\n//\n// MenuList\n//\n\ntype MenuBackdropProps = Reakit.MenuStateReturn & {\n children: React.ReactNode\n}\n\nconst BACKDROP_STYLE: React.CSSProperties = {\n width: '100%',\n height: '100%',\n position: 'fixed',\n top: 0,\n left: 0,\n}\n\n/**\n * Internal component to provide a backdrop/overlay to all menus. This is needed because reakit's\n * menus do not show an overlay by default.\n */\nfunction MenuBackdrop({\n baseId,\n visible,\n animated,\n animating,\n stopAnimation,\n modal,\n children,\n}: MenuBackdropProps) {\n return (\n <PopoverBackdrop\n baseId={baseId}\n visible={visible}\n animated={animated}\n animating={animating}\n stopAnimation={stopAnimation}\n modal={modal}\n style={BACKDROP_STYLE}\n >\n {children}\n </PopoverBackdrop>\n )\n}\n\ntype MenuListProps = Omit<Reakit.MenuProps, keyof Reakit.MenuStateReturn | 'className'>\n\n/**\n * The dropdown menu itself, containing a list of menu items.\n */\nconst MenuList = polymorphicComponent<'div', MenuListProps>(function MenuList(\n { exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n const previousVisible = usePrevious(state.visible)\n\n React.useEffect(\n function focusTriggerOnClose() {\n if (state.visible === false && previousVisible === true) {\n state.unstable_referenceRef?.current?.focus()\n }\n },\n [state.visible, previousVisible, state.unstable_referenceRef],\n )\n\n return state.visible ? (\n <MenuBackdrop {...state}>\n <Reakit.Menu\n {...props}\n {...state}\n ref={ref}\n className={classNames('reactist_menulist', exceptionallySetClassName)}\n />\n </MenuBackdrop>\n ) : null\n})\n\n//\n// MenuItem\n//\n\ntype MenuItemProps = {\n /**\n * An optional value given to this menu item. It is passed on to the parent `Menu`'s\n * `onItemSelect` when you provide that instead of (or alongside) providing individual\n * `onSelect` callbacks to each menu item.\n */\n value?: string\n /**\n * The content inside the menu item.\n */\n children: React.ReactNode\n /**\n * When `true` the menu item is disabled and won't be selectable or be part of the keyboard\n * navigation across the menu options.\n *\n * @default true\n */\n disabled?: boolean\n /**\n * When `true` the menu will close when the menu item is selected, in addition to performing the\n * action that the menu item is set out to do.\n *\n * Set this to `false` to make sure that a given menu item does not auto-closes the menu when\n * selected. This should be the exception and not the norm, as the default is to auto-close.\n *\n * @default true\n */\n hideOnSelect?: boolean\n /**\n * The action to perform when the menu item is selected.\n *\n * If you return `false` from this function, the menu will not auto-close when this menu item\n * is selected. Though you should use `hideOnSelect` for this purpose, this allows you to\n * achieve the same effect conditionally and dynamically deciding at run time.\n */\n onSelect?: () => unknown\n /**\n * The event handler called when the menu item is clicked.\n *\n * This is similar to `onSelect`, but a bit different. You can certainly use it to trigger the\n * action that the menu item represents. But in general you should prefer `onSelect` for that.\n *\n * The main use for this handler is to get access to the click event. This can be used, for\n * example, to call `event.preventDefault()`, which will effectively prevent the rest of the\n * consequences of the click, including preventing `onSelect` from being called. In particular,\n * this is useful in menu items that are links, and you want the click to not trigger navigation\n * under some circumstances.\n */\n onClick?: (event: React.MouseEvent) => void\n}\n\n/**\n * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`\n * callback.\n */\nconst MenuItem = polymorphicComponent<'button', MenuItemProps>(function MenuItem(\n {\n value,\n children,\n onSelect,\n hideOnSelect = true,\n onClick,\n exceptionallySetClassName,\n ...props\n },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n const { hide } = state\n\n const handleClick = React.useCallback(\n function handleClick(event: React.MouseEvent<HTMLButtonElement>) {\n onClick?.(event)\n const onSelectResult: unknown =\n onSelect && !event.defaultPrevented ? onSelect() : undefined\n const shouldClose = onSelectResult !== false && hideOnSelect\n handleItemSelect(value)\n if (shouldClose) hide()\n },\n [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value],\n )\n\n return (\n <Reakit.MenuItem\n {...props}\n {...state}\n ref={ref}\n onClick={handleClick}\n className={exceptionallySetClassName}\n >\n {children}\n </Reakit.MenuItem>\n )\n})\n\n//\n// SubMenu\n//\n\ntype SubMenuProps = Pick<MenuProps, 'children' | 'onItemSelect'>\n\n/**\n * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have\n * a sub-menu.\n *\n * Its children are expected to have the structure of a first level menu (a `MenuButton` and a\n * `MenuList`).\n *\n * ```jsx\n * <MenuItem label=\"Edit profile\" />\n * <SubMenu>\n * <MenuButton>More options</MenuButton>\n * <MenuList>\n * <MenuItem label=\"Preferences\" />\n * <MenuItem label=\"Sign out\" />\n * </MenuList>\n * </SubMenu>\n * ```\n *\n * The `MenuButton` will become a menu item in the current menu items list, and it will lead to\n * opening a sub-menu with the menu items list below it.\n */\nconst SubMenu = React.forwardRef<HTMLButtonElement, SubMenuProps>(function SubMenu(\n { children, onItemSelect, ...props },\n ref,\n) {\n const { handleItemSelect: parentMenuItemSelect, ...state } = React.useContext(MenuContext)\n const { hide: parentMenuHide } = state\n\n const handleSubItemSelect = React.useCallback(\n function handleSubItemSelect(value) {\n if (onItemSelect) onItemSelect(value)\n parentMenuItemSelect(value)\n parentMenuHide()\n },\n [parentMenuHide, parentMenuItemSelect, onItemSelect],\n )\n\n const [button, list] = React.Children.toArray(children)\n\n return (\n <Reakit.MenuItem {...state} {...props} ref={ref}>\n {(buttonProps) => (\n <Menu onItemSelect={handleSubItemSelect}>\n {React.cloneElement(button as React.ReactElement, {\n ...buttonProps,\n className: classNames(buttonProps.className, 'reactist_submenu_button'),\n })}\n {list}\n </Menu>\n )}\n </Reakit.MenuItem>\n )\n})\n\n//\n// MenuGroup\n//\n\ntype MenuGroupProps = Omit<NativeProps<HTMLDivElement>, 'className'> & {\n /**\n * A label to be shown visually and also used to semantically label the group.\n */\n label: string\n}\n\n/**\n * A way to semantically group some menu items.\n *\n * This group does not add any visual separator. You can do that yourself adding `<hr />` elements\n * before and/or after the group if you so wish.\n */\nconst MenuGroup = polymorphicComponent<'div', MenuGroupProps>(function MenuGroud(\n { label, children, exceptionallySetClassName, ...props },\n ref,\n) {\n const { handleItemSelect, ...state } = React.useContext(MenuContext)\n return (\n <Reakit.MenuGroup ref={ref} {...props} {...state} className={exceptionallySetClassName}>\n {label ? (\n <div role=\"presentation\" className=\"reactist_menugroup__label\">\n {label}\n </div>\n ) : null}\n {children}\n </Reakit.MenuGroup>\n )\n})\n\nexport { Menu, MenuButton, MenuList, MenuItem, SubMenu, MenuGroup }\nexport type { MenuButtonProps, MenuListProps, MenuItemProps, SubMenuProps, MenuGroupProps }\n"],"names":["MenuContext","React","Menu","children","onItemSelect","props","state","Reakit","loop","handleItemSelect","value","Provider","MenuButton","polymorphicComponent","ref","exceptionallySetClassName","className","classNames","BACKDROP_STYLE","width","height","position","top","left","MenuBackdrop","baseId","visible","animated","animating","stopAnimation","modal","PopoverBackdrop","style","MenuList","previousVisible","usePrevious","focusTriggerOnClose","unstable_referenceRef","current","focus","MenuItem","onSelect","hideOnSelect","onClick","hide","handleClick","event","onSelectResult","defaultPrevented","undefined","shouldClose","SubMenu","parentMenuItemSelect","parentMenuHide","handleSubItemSelect","toArray","button","list","buttonProps","MenuGroup","MenuGroud","label","role"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,IAAMA,WAAW,gBAAGC,aAAA;AAEhB;AACA;AACA;AACA;AACA,EANgB,CAApB;AA8BA;;;;;AAIA,SAASC,IAAT;MAAgBC,gBAAAA;MAAUC,oBAAAA;MAAiBC;;AACvC,MAAMC,KAAK,GAAGC,YAAA;AAAsBC,IAAAA,IAAI,EAAE;AAA5B,KAAqCH,KAArC,EAAd;AAEA,MAAMI,gBAAgB,GAAGR,WAAA,CACrB,SAASQ,gBAAT,CAA0BC,KAA1B;AACI,QAAIN,YAAJ,EAAkBA,YAAY,CAACM,KAAD,CAAZ;AACrB,GAHoB,EAIrB,CAACN,YAAD,CAJqB,CAAzB;AAOA,MAAMM,KAAK,GAAqBT,OAAA,CAC5B;AAAA,6CACOK,KADP;AAEIG,MAAAA,gBAAgB,EAAhBA;AAFJ;AAAA,GAD4B,EAK5B,CAACH,KAAD,EAAQG,gBAAR,CAL4B,CAAhC;AAQA,sBAAOR,aAAA,CAACD,WAAW,CAACW,QAAb;AAAsBD,IAAAA,KAAK,EAAEA;GAA7B,EAAqCP,QAArC,CAAP;AACH;AAQD;;;;;IAGMS,UAAU,gBAAGC,oBAAoB,CAA4B,SAASD,UAAT,QAE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