@spaced-out/ui-design-system 0.1.20 → 0.1.22
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/CHANGELOG.md +15 -0
- package/config.js +24 -1
- package/lib/components/ButtonDropdown/ButtonDropdown.js +17 -2
- package/lib/components/ButtonDropdown/ButtonDropdown.js.flow +47 -23
- package/lib/components/ConditionalWrapper/ConditionalWrapper.js +19 -0
- package/lib/components/ConditionalWrapper/ConditionalWrapper.js.flow +16 -0
- package/lib/components/ConditionalWrapper/index.js +12 -0
- package/lib/components/ConditionalWrapper/index.js.flow +3 -0
- package/lib/components/OptionButton/OptionButton.js +28 -10
- package/lib/components/OptionButton/OptionButton.js.flow +72 -17
- package/lib/components/OptionButton/OptionButton.module.css +4 -2
- package/lib/components/OptionButton/index.js.flow +1 -1
- package/lib/components/Tooltip/Tooltip.js +4 -3
- package/lib/components/Tooltip/Tooltip.js.flow +45 -35
- package/lib/components/index.js +11 -0
- package/lib/components/index.js.flow +1 -0
- package/lib/styles/index.css +427 -15
- package/lib/styles/index.js +432 -99
- package/lib/styles/index.js.flow +427 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.1.22](https://github.com/spaced-out/ui-design-system/compare/v0.1.21...v0.1.22) (2023-04-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* add tooltip for option button ([#106](https://github.com/spaced-out/ui-design-system/issues/106)) ([aa9a91f](https://github.com/spaced-out/ui-design-system/commit/aa9a91f7fd9e65336d4f617790fe26077884b8d8))
|
|
11
|
+
* hidden prop support in tooltip ([49b7c21](https://github.com/spaced-out/ui-design-system/commit/49b7c2123b367d1e2e50253380700688ab7d01cd))
|
|
12
|
+
|
|
13
|
+
### [0.1.21](https://github.com/spaced-out/ui-design-system/compare/v0.1.20...v0.1.21) (2023-04-24)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* style-dictionary build process changes and global style variable export from styles/index.css ([9a7f418](https://github.com/spaced-out/ui-design-system/commit/9a7f418fa6da4d1266034ee56bd5e052361c809e))
|
|
19
|
+
|
|
5
20
|
### [0.1.20](https://github.com/spaced-out/ui-design-system/compare/v0.1.19...v0.1.20) (2023-04-24)
|
|
6
21
|
|
|
7
22
|
|
package/config.js
CHANGED
|
@@ -40,7 +40,18 @@ module.exports = {
|
|
|
40
40
|
},
|
|
41
41
|
})),
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
'css/global': {
|
|
44
|
+
transforms: ['attribute/cti', 'name/cti/camel'],
|
|
45
|
+
buildPath: `src/styles/`,
|
|
46
|
+
files: [
|
|
47
|
+
{
|
|
48
|
+
destination: `index.css`,
|
|
49
|
+
format: `customCssFormat`,
|
|
50
|
+
filter: ({attributes}) => !attributes.category.includes('base'),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
'js/category': {
|
|
44
55
|
transforms: ['attribute/cti', 'name/cti/camel'],
|
|
45
56
|
transformGroup: 'js',
|
|
46
57
|
buildPath: `src/styles/variables/`,
|
|
@@ -54,5 +65,17 @@ module.exports = {
|
|
|
54
65
|
},
|
|
55
66
|
})),
|
|
56
67
|
},
|
|
68
|
+
'js/global': {
|
|
69
|
+
transforms: ['attribute/cti', 'name/cti/camel'],
|
|
70
|
+
transformGroup: 'js',
|
|
71
|
+
buildPath: `src/styles/`,
|
|
72
|
+
files: [
|
|
73
|
+
{
|
|
74
|
+
destination: `index.js`,
|
|
75
|
+
format: `customJsFormat`,
|
|
76
|
+
filter: ({attributes}) => !attributes.category.includes('base'),
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
57
80
|
},
|
|
58
81
|
};
|
|
@@ -11,7 +11,9 @@ var _space = require("../../styles/variables/_space");
|
|
|
11
11
|
var _classify = require("../../utils/classify");
|
|
12
12
|
var _clickAway = require("../../utils/click-away");
|
|
13
13
|
var _Button = require("../Button");
|
|
14
|
+
var _ConditionalWrapper = require("../ConditionalWrapper");
|
|
14
15
|
var _Menu = require("../Menu");
|
|
16
|
+
var _Tooltip = require("../Tooltip");
|
|
15
17
|
var _ButtonDropdownModule = _interopRequireDefault(require("./ButtonDropdown.module.css"));
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -40,9 +42,11 @@ const ButtonDropdown = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
|
40
42
|
iconRightName,
|
|
41
43
|
iconRightType = 'solid',
|
|
42
44
|
isFluid,
|
|
45
|
+
tooltip,
|
|
43
46
|
...restButtonProps
|
|
44
47
|
} = _ref;
|
|
45
48
|
const menuBtnRef = React.useRef(null);
|
|
49
|
+
const [isMenuOpen, setIsMenuOpen] = React.useState(false);
|
|
46
50
|
React.useImperativeHandle(forwardRef, () => menuBtnRef.current);
|
|
47
51
|
const {
|
|
48
52
|
x,
|
|
@@ -57,7 +61,13 @@ const ButtonDropdown = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
|
57
61
|
middleware: [(0, _reactDom.shift)(), (0, _reactDom.flip)(), (0, _reactDom.offset)(parseInt(_space.spaceXXSmall))]
|
|
58
62
|
});
|
|
59
63
|
const onMenuToggle = isOpen => {
|
|
60
|
-
|
|
64
|
+
if (isOpen) {
|
|
65
|
+
onMenuOpen?.();
|
|
66
|
+
setIsMenuOpen(true);
|
|
67
|
+
} else {
|
|
68
|
+
onMenuClose?.();
|
|
69
|
+
setIsMenuOpen(false);
|
|
70
|
+
}
|
|
61
71
|
};
|
|
62
72
|
return /*#__PURE__*/React.createElement(_clickAway.ClickAway, {
|
|
63
73
|
onChange: onMenuToggle
|
|
@@ -74,6 +84,11 @@ const ButtonDropdown = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
|
74
84
|
[_ButtonDropdownModule.default.isFluid]: isFluid === true
|
|
75
85
|
}, classNames?.dropdownContainer),
|
|
76
86
|
ref: menuBtnRef
|
|
87
|
+
}, /*#__PURE__*/React.createElement(_ConditionalWrapper.ConditionalWrapper, {
|
|
88
|
+
condition: Boolean(tooltip),
|
|
89
|
+
wrapper: children => /*#__PURE__*/React.createElement(_Tooltip.Tooltip, _extends({}, tooltip, {
|
|
90
|
+
hidden: isMenuOpen ? true : tooltip?.hidden
|
|
91
|
+
}), children)
|
|
77
92
|
}, /*#__PURE__*/React.createElement(_Button.Button, _extends({}, restButtonProps, {
|
|
78
93
|
iconRightName: children ? iconRightName || (isOpen ? 'caret-up' : 'caret-down') : iconRightName,
|
|
79
94
|
iconRightType: iconRightType,
|
|
@@ -89,7 +104,7 @@ const ButtonDropdown = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
|
|
|
89
104
|
wrapper: classNames?.buttonWrapper,
|
|
90
105
|
icon: classNames?.buttonIcon
|
|
91
106
|
}
|
|
92
|
-
}), children), isOpen && menu && /*#__PURE__*/React.createElement("div", {
|
|
107
|
+
}), children)), isOpen && menu && /*#__PURE__*/React.createElement("div", {
|
|
93
108
|
onClickCapture: cancelNext,
|
|
94
109
|
ref: floating,
|
|
95
110
|
style: {
|
|
@@ -20,8 +20,11 @@ import {classify} from '../../utils/classify';
|
|
|
20
20
|
import {ClickAway} from '../../utils/click-away';
|
|
21
21
|
import type {ButtonProps} from '../Button';
|
|
22
22
|
import {Button} from '../Button';
|
|
23
|
+
import {ConditionalWrapper} from '../ConditionalWrapper';
|
|
23
24
|
import type {MenuOption, MenuProps} from '../Menu';
|
|
24
25
|
import {Menu} from '../Menu';
|
|
26
|
+
import type {BaseTooltipProps} from '../Tooltip';
|
|
27
|
+
import {Tooltip} from '../Tooltip';
|
|
25
28
|
|
|
26
29
|
import css from './ButtonDropdown.module.css';
|
|
27
30
|
|
|
@@ -50,6 +53,7 @@ export type ButtonDropdownProps = {
|
|
|
50
53
|
onOptionSelect?: (option: MenuOption) => mixed,
|
|
51
54
|
onMenuOpen?: () => mixed,
|
|
52
55
|
onMenuClose?: () => mixed,
|
|
56
|
+
tooltip?: BaseTooltipProps,
|
|
53
57
|
...
|
|
54
58
|
};
|
|
55
59
|
|
|
@@ -71,11 +75,13 @@ export const ButtonDropdown: React$AbstractComponent<
|
|
|
71
75
|
iconRightName,
|
|
72
76
|
iconRightType = 'solid',
|
|
73
77
|
isFluid,
|
|
78
|
+
tooltip,
|
|
74
79
|
...restButtonProps
|
|
75
80
|
}: ButtonDropdownProps,
|
|
76
81
|
forwardRef,
|
|
77
82
|
) => {
|
|
78
83
|
const menuBtnRef = React.useRef(null);
|
|
84
|
+
const [isMenuOpen, setIsMenuOpen] = React.useState(false);
|
|
79
85
|
React.useImperativeHandle(forwardRef, () => menuBtnRef.current);
|
|
80
86
|
const {x, y, reference, floating, strategy} = useFloating({
|
|
81
87
|
strategy: 'absolute',
|
|
@@ -85,7 +91,13 @@ export const ButtonDropdown: React$AbstractComponent<
|
|
|
85
91
|
});
|
|
86
92
|
|
|
87
93
|
const onMenuToggle = (isOpen: boolean) => {
|
|
88
|
-
|
|
94
|
+
if (isOpen) {
|
|
95
|
+
onMenuOpen?.();
|
|
96
|
+
setIsMenuOpen(true);
|
|
97
|
+
} else {
|
|
98
|
+
onMenuClose?.();
|
|
99
|
+
setIsMenuOpen(false);
|
|
100
|
+
}
|
|
89
101
|
};
|
|
90
102
|
|
|
91
103
|
return (
|
|
@@ -102,29 +114,41 @@ export const ButtonDropdown: React$AbstractComponent<
|
|
|
102
114
|
)}
|
|
103
115
|
ref={menuBtnRef}
|
|
104
116
|
>
|
|
105
|
-
<
|
|
106
|
-
{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
ref={reference}
|
|
116
|
-
onClick={(e) => {
|
|
117
|
-
e.stopPropagation();
|
|
118
|
-
onOpen();
|
|
119
|
-
}}
|
|
120
|
-
isFluid={isFluid}
|
|
121
|
-
classNames={{
|
|
122
|
-
wrapper: classNames?.buttonWrapper,
|
|
123
|
-
icon: classNames?.buttonIcon,
|
|
124
|
-
}}
|
|
117
|
+
<ConditionalWrapper
|
|
118
|
+
condition={Boolean(tooltip)}
|
|
119
|
+
wrapper={(children) => (
|
|
120
|
+
<Tooltip
|
|
121
|
+
{...tooltip}
|
|
122
|
+
hidden={isMenuOpen ? true : tooltip?.hidden}
|
|
123
|
+
>
|
|
124
|
+
{children}
|
|
125
|
+
</Tooltip>
|
|
126
|
+
)}
|
|
125
127
|
>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
<Button
|
|
129
|
+
{...restButtonProps}
|
|
130
|
+
iconRightName={
|
|
131
|
+
children
|
|
132
|
+
? iconRightName || (isOpen ? 'caret-up' : 'caret-down')
|
|
133
|
+
: iconRightName
|
|
134
|
+
}
|
|
135
|
+
iconRightType={iconRightType}
|
|
136
|
+
disabled={disabled}
|
|
137
|
+
size={size}
|
|
138
|
+
ref={reference}
|
|
139
|
+
onClick={(e) => {
|
|
140
|
+
e.stopPropagation();
|
|
141
|
+
onOpen();
|
|
142
|
+
}}
|
|
143
|
+
isFluid={isFluid}
|
|
144
|
+
classNames={{
|
|
145
|
+
wrapper: classNames?.buttonWrapper,
|
|
146
|
+
icon: classNames?.buttonIcon,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{children}
|
|
150
|
+
</Button>
|
|
151
|
+
</ConditionalWrapper>
|
|
128
152
|
|
|
129
153
|
{isOpen && menu && (
|
|
130
154
|
<div
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ConditionalWrapper = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
|
|
11
|
+
const ConditionalWrapper = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
condition,
|
|
14
|
+
wrapper,
|
|
15
|
+
children
|
|
16
|
+
} = _ref;
|
|
17
|
+
return condition ? wrapper?.(children) : children;
|
|
18
|
+
};
|
|
19
|
+
exports.ConditionalWrapper = ConditionalWrapper;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export type ConditionalWrapperProps = {
|
|
6
|
+
condition?: boolean,
|
|
7
|
+
wrapper?: (children: React.Node) => React.Node,
|
|
8
|
+
children?: React.Node,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const ConditionalWrapper = ({
|
|
12
|
+
condition,
|
|
13
|
+
wrapper,
|
|
14
|
+
children,
|
|
15
|
+
}: ConditionalWrapperProps): React.Node =>
|
|
16
|
+
condition ? wrapper?.(children) : children;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ConditionalWrapper", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ConditionalWrapper.ConditionalWrapper;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _ConditionalWrapper = require("./ConditionalWrapper");
|
|
@@ -5,13 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.OptionButton = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
8
9
|
var _Button = require("../Button");
|
|
9
10
|
var _ButtonDropdown = require("../ButtonDropdown");
|
|
11
|
+
var _ConditionalWrapper = require("../ConditionalWrapper");
|
|
12
|
+
var _Tooltip = require("../Tooltip");
|
|
10
13
|
var _OptionButtonModule = _interopRequireDefault(require("./OptionButton.module.css"));
|
|
11
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
15
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
|
|
17
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
15
18
|
const OptionButton = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
16
19
|
let {
|
|
17
20
|
children,
|
|
@@ -29,43 +32,58 @@ const OptionButton = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
29
32
|
onMenuOpen,
|
|
30
33
|
onMenuClose,
|
|
31
34
|
ariaLabel,
|
|
32
|
-
actionType
|
|
35
|
+
actionType,
|
|
36
|
+
tooltip,
|
|
37
|
+
classNames
|
|
33
38
|
} = _ref;
|
|
34
39
|
const [iconName, setIconName] = React.useState('chevron-down');
|
|
40
|
+
const [isMenuOpen, setIsMenuOpen] = React.useState(false);
|
|
35
41
|
return /*#__PURE__*/React.createElement("div", {
|
|
36
|
-
className: _OptionButtonModule.default.container,
|
|
42
|
+
className: (0, _classify.default)(_OptionButtonModule.default.container, {
|
|
43
|
+
[_OptionButtonModule.default.isFluid]: isFluid
|
|
44
|
+
}, classNames?.wrapper),
|
|
37
45
|
ref: ref
|
|
46
|
+
}, /*#__PURE__*/React.createElement(_ConditionalWrapper.ConditionalWrapper, {
|
|
47
|
+
condition: Boolean(tooltip?.baseButton),
|
|
48
|
+
wrapper: children => /*#__PURE__*/React.createElement(_Tooltip.Tooltip, _extends({}, tooltip?.baseButton, {
|
|
49
|
+
hidden: isMenuOpen ? true : tooltip?.optionsButton?.hidden
|
|
50
|
+
}), children)
|
|
38
51
|
}, /*#__PURE__*/React.createElement(_Button.Button, {
|
|
39
52
|
iconLeftName: iconLeftName,
|
|
40
53
|
iconLeftType: iconLeftType,
|
|
41
54
|
onClick: onButtonClick,
|
|
42
55
|
size: size,
|
|
43
56
|
type: type,
|
|
44
|
-
classNames: {
|
|
45
|
-
wrapper: _OptionButtonModule.default.leftButton
|
|
46
|
-
},
|
|
47
57
|
disabled: disabled,
|
|
48
58
|
isFluid: isFluid,
|
|
49
59
|
ariaLabel: ariaLabel,
|
|
50
60
|
actionType: actionType,
|
|
51
|
-
isLoading: isLoading
|
|
52
|
-
|
|
61
|
+
isLoading: isLoading,
|
|
62
|
+
classNames: {
|
|
63
|
+
wrapper: (0, _classify.default)(_OptionButtonModule.default.leftButton, classNames?.baseButtonWrapper),
|
|
64
|
+
icon: classNames?.baseButtonIcon
|
|
65
|
+
}
|
|
66
|
+
}, children)), /*#__PURE__*/React.createElement(_ButtonDropdown.ButtonDropdown, {
|
|
53
67
|
anchorPosition: anchorPosition,
|
|
54
68
|
ariaLabel: ariaLabel,
|
|
55
69
|
iconLeftName: iconName,
|
|
70
|
+
tooltip: tooltip?.optionsButton,
|
|
56
71
|
classNames: {
|
|
57
|
-
buttonWrapper: _OptionButtonModule.default.rightButton,
|
|
58
|
-
dropdownContainer: _OptionButtonModule.default.dropDownContainer
|
|
72
|
+
buttonWrapper: (0, _classify.default)(_OptionButtonModule.default.rightButton, classNames?.optionsButtonWrapper),
|
|
73
|
+
dropdownContainer: (0, _classify.default)(_OptionButtonModule.default.dropDownContainer, classNames?.dropdownContainer),
|
|
74
|
+
buttonIcon: classNames?.optionsButtonIcon
|
|
59
75
|
},
|
|
60
76
|
type: type,
|
|
61
77
|
disabled: disabled,
|
|
62
78
|
menu: menu,
|
|
63
79
|
onMenuClose: () => {
|
|
64
80
|
setIconName('chevron-down');
|
|
81
|
+
setIsMenuOpen(false);
|
|
65
82
|
onMenuOpen && onMenuOpen();
|
|
66
83
|
},
|
|
67
84
|
onMenuOpen: () => {
|
|
68
85
|
setIconName('chevron-up');
|
|
86
|
+
setIsMenuOpen(true);
|
|
69
87
|
onMenuClose && onMenuClose();
|
|
70
88
|
},
|
|
71
89
|
onOptionSelect: onOptionSelect,
|
|
@@ -2,15 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
|
|
5
|
+
import classify from '../../utils/classify';
|
|
5
6
|
import type {ButtonProps} from '../Button';
|
|
6
7
|
import {Button} from '../Button';
|
|
7
8
|
import type {AnchorType} from '../ButtonDropdown';
|
|
8
9
|
import {ButtonDropdown} from '../ButtonDropdown';
|
|
10
|
+
import {ConditionalWrapper} from '../ConditionalWrapper';
|
|
9
11
|
import type {MenuOption, MenuProps} from '../Menu';
|
|
12
|
+
import type {BaseTooltipProps} from '../Tooltip';
|
|
13
|
+
import {Tooltip} from '../Tooltip';
|
|
10
14
|
|
|
11
15
|
import css from './OptionButton.module.css';
|
|
12
16
|
|
|
13
17
|
|
|
18
|
+
type ClassNames = $ReadOnly<{
|
|
19
|
+
wrapper?: string,
|
|
20
|
+
baseButtonWrapper?: string,
|
|
21
|
+
baseButtonIcon?: string,
|
|
22
|
+
optionsButtonWrapper?: string,
|
|
23
|
+
optionsButtonIcon?: string,
|
|
24
|
+
dropdownContainer?: string,
|
|
25
|
+
}>;
|
|
26
|
+
|
|
27
|
+
export type OptionButtonTooltipProps = {
|
|
28
|
+
baseButton?: BaseTooltipProps,
|
|
29
|
+
optionsButton?: BaseTooltipProps,
|
|
30
|
+
};
|
|
31
|
+
|
|
14
32
|
export type OptionButtonProps = {
|
|
15
33
|
...ButtonProps,
|
|
16
34
|
menu?: MenuProps,
|
|
@@ -19,6 +37,8 @@ export type OptionButtonProps = {
|
|
|
19
37
|
onButtonClick?: ?(SyntheticEvent<HTMLElement>) => mixed,
|
|
20
38
|
onMenuOpen?: () => mixed,
|
|
21
39
|
onMenuClose?: () => mixed,
|
|
40
|
+
tooltip?: OptionButtonTooltipProps,
|
|
41
|
+
classNames?: ClassNames,
|
|
22
42
|
...
|
|
23
43
|
};
|
|
24
44
|
|
|
@@ -44,45 +64,80 @@ export const OptionButton: React$AbstractComponent<
|
|
|
44
64
|
onMenuClose,
|
|
45
65
|
ariaLabel,
|
|
46
66
|
actionType,
|
|
67
|
+
tooltip,
|
|
68
|
+
classNames,
|
|
47
69
|
}: OptionButtonProps,
|
|
48
70
|
ref,
|
|
49
71
|
): React.Node => {
|
|
50
72
|
const [iconName, setIconName] = React.useState('chevron-down');
|
|
73
|
+
const [isMenuOpen, setIsMenuOpen] = React.useState(false);
|
|
51
74
|
|
|
52
75
|
return (
|
|
53
|
-
<div
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
<div
|
|
77
|
+
className={classify(
|
|
78
|
+
css.container,
|
|
79
|
+
{[css.isFluid]: isFluid},
|
|
80
|
+
classNames?.wrapper,
|
|
81
|
+
)}
|
|
82
|
+
ref={ref}
|
|
83
|
+
>
|
|
84
|
+
<ConditionalWrapper
|
|
85
|
+
condition={Boolean(tooltip?.baseButton)}
|
|
86
|
+
wrapper={(children) => (
|
|
87
|
+
<Tooltip
|
|
88
|
+
{...tooltip?.baseButton}
|
|
89
|
+
hidden={isMenuOpen ? true : tooltip?.optionsButton?.hidden}
|
|
90
|
+
>
|
|
91
|
+
{children}
|
|
92
|
+
</Tooltip>
|
|
93
|
+
)}
|
|
66
94
|
>
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
<Button
|
|
96
|
+
iconLeftName={iconLeftName}
|
|
97
|
+
iconLeftType={iconLeftType}
|
|
98
|
+
onClick={onButtonClick}
|
|
99
|
+
size={size}
|
|
100
|
+
type={type}
|
|
101
|
+
disabled={disabled}
|
|
102
|
+
isFluid={isFluid}
|
|
103
|
+
ariaLabel={ariaLabel}
|
|
104
|
+
actionType={actionType}
|
|
105
|
+
isLoading={isLoading}
|
|
106
|
+
classNames={{
|
|
107
|
+
wrapper: classify(css.leftButton, classNames?.baseButtonWrapper),
|
|
108
|
+
icon: classNames?.baseButtonIcon,
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
{children}
|
|
112
|
+
</Button>
|
|
113
|
+
</ConditionalWrapper>
|
|
69
114
|
<ButtonDropdown
|
|
70
115
|
anchorPosition={anchorPosition}
|
|
71
116
|
ariaLabel={ariaLabel}
|
|
72
117
|
iconLeftName={iconName}
|
|
118
|
+
tooltip={tooltip?.optionsButton}
|
|
73
119
|
classNames={{
|
|
74
|
-
buttonWrapper:
|
|
75
|
-
|
|
120
|
+
buttonWrapper: classify(
|
|
121
|
+
css.rightButton,
|
|
122
|
+
classNames?.optionsButtonWrapper,
|
|
123
|
+
),
|
|
124
|
+
dropdownContainer: classify(
|
|
125
|
+
css.dropDownContainer,
|
|
126
|
+
classNames?.dropdownContainer,
|
|
127
|
+
),
|
|
128
|
+
buttonIcon: classNames?.optionsButtonIcon,
|
|
76
129
|
}}
|
|
77
130
|
type={type}
|
|
78
131
|
disabled={disabled}
|
|
79
132
|
menu={menu}
|
|
80
133
|
onMenuClose={() => {
|
|
81
134
|
setIconName('chevron-down');
|
|
135
|
+
setIsMenuOpen(false);
|
|
82
136
|
onMenuOpen && onMenuOpen();
|
|
83
137
|
}}
|
|
84
138
|
onMenuOpen={() => {
|
|
85
139
|
setIconName('chevron-up');
|
|
140
|
+
setIsMenuOpen(true);
|
|
86
141
|
onMenuClose && onMenuClose();
|
|
87
142
|
}}
|
|
88
143
|
onOptionSelect={onOptionSelect}
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
@value (spaceXXSmall) from '../../styles/variables/_space.css';
|
|
6
6
|
|
|
7
|
-
@value (
|
|
7
|
+
@value (sizeFluid) from '../../styles/variables/_size.css';
|
|
8
8
|
|
|
9
9
|
.container {
|
|
10
10
|
display: flex;
|
|
11
|
-
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.isFluid {
|
|
12
14
|
width: sizeFluid;
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -38,7 +38,8 @@ const Tooltip = _ref => {
|
|
|
38
38
|
bodyMaxLines = 2,
|
|
39
39
|
titleMaxLines = 1,
|
|
40
40
|
delayMotionDuration = 'none',
|
|
41
|
-
elevation = ELEVATION['elevationTooltip']
|
|
41
|
+
elevation = ELEVATION['elevationTooltip'],
|
|
42
|
+
hidden
|
|
42
43
|
} = _ref;
|
|
43
44
|
const bodyRef = React.useRef(document.querySelector('body'));
|
|
44
45
|
const [open, setOpen] = React.useState(false);
|
|
@@ -75,7 +76,7 @@ const Tooltip = _ref => {
|
|
|
75
76
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.cloneElement(children, getReferenceProps({
|
|
76
77
|
ref,
|
|
77
78
|
...children.props
|
|
78
|
-
})), open && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/React.createElement("div", _extends({
|
|
79
|
+
})), open && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/React.createElement(React.Fragment, null, !hidden && /*#__PURE__*/React.createElement("div", _extends({
|
|
79
80
|
ref: floating,
|
|
80
81
|
className: (0, _classify.classify)(_TooltipModule.default.tooltip, classNames?.tooltip),
|
|
81
82
|
style: {
|
|
@@ -94,6 +95,6 @@ const Tooltip = _ref => {
|
|
|
94
95
|
className: (0, _classify.classify)(_TooltipModule.default.body, {
|
|
95
96
|
[_TooltipModule.default.hasTitle]: !!title
|
|
96
97
|
}, classNames?.body)
|
|
97
|
-
}, body))), bodyRef.current));
|
|
98
|
+
}, body)))), bodyRef.current));
|
|
98
99
|
};
|
|
99
100
|
exports.Tooltip = Tooltip;
|