@spaced-out/ui-design-system 0.0.21 → 0.0.23-beta.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/CHANGELOG.md +21 -0
- package/design-tokens/color/app-color.json +7 -0
- package/design-tokens/size/base-size.json +6 -0
- package/lib/components/Button/Button.js +9 -5
- package/lib/components/Button/Button.js.flow +11 -3
- package/lib/components/Button/Button.module.css +1 -1
- package/lib/components/ButtonTabs/ButtonTab/ButtonTab.js +48 -0
- package/lib/components/ButtonTabs/ButtonTab/ButtonTab.js.flow +67 -0
- package/lib/components/ButtonTabs/ButtonTab/ButtonTab.module.css +75 -0
- package/lib/components/ButtonTabs/ButtonTab/index.js +16 -0
- package/lib/components/ButtonTabs/ButtonTab/index.js.flow +3 -0
- package/lib/components/ButtonTabs/ButtonTabs.js +47 -0
- package/lib/components/ButtonTabs/ButtonTabs.js.flow +62 -0
- package/lib/components/ButtonTabs/ButtonTabs.module.css +27 -0
- package/lib/components/ButtonTabs/index.js +27 -0
- package/lib/components/ButtonTabs/index.js.flow +4 -0
- package/lib/components/Chip/Chip.js +11 -3
- package/lib/components/Chip/Chip.js.flow +12 -2
- package/lib/components/Chip/Chip.module.css +31 -0
- package/lib/components/Icon/Icon.js.flow +1 -1
- package/lib/components/SideMenuLink/SideMenuLink.module.css +1 -0
- package/lib/components/StatusIndicator/StatusIndicator.js +36 -0
- package/lib/components/StatusIndicator/StatusIndicator.js.flow +47 -0
- package/lib/components/StatusIndicator/StatusIndicator.module.css +37 -0
- package/lib/components/StatusIndicator/index.js +16 -0
- package/lib/components/StatusIndicator/index.js.flow +3 -0
- package/lib/components/SubMenu/SubMenu.js +168 -0
- package/lib/components/SubMenu/SubMenu.js.flow +243 -0
- package/lib/components/SubMenu/SubMenu.module.css +119 -0
- package/lib/components/SubMenu/index.js +42 -0
- package/lib/components/SubMenu/index.js.flow +11 -0
- package/lib/components/Tabs/Tab/Tab.js +2 -2
- package/lib/components/Tabs/Tab/Tab.js.flow +24 -19
- package/lib/components/Tabs/Tab/Tab.module.css +5 -1
- package/lib/styles/variables/_color.css +2 -0
- package/lib/styles/variables/_color.js +3 -1
- package/lib/styles/variables/_color.js.flow +2 -0
- package/lib/styles/variables/_size.css +4 -0
- package/lib/styles/variables/_size.js +6 -2
- package/lib/styles/variables/_size.js.flow +4 -0
- package/package.json +1 -1
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
@value (
|
|
2
2
|
colorNeutralLightest,
|
|
3
|
+
colorNeutralLight,
|
|
3
4
|
colorInformationLightest,
|
|
5
|
+
colorInformationLight,
|
|
4
6
|
colorSuccessLightest,
|
|
7
|
+
colorSuccessLight,
|
|
5
8
|
colorWarningLightest,
|
|
9
|
+
colorWarningLight,
|
|
6
10
|
colorDangerLightest,
|
|
11
|
+
colorDangerLight,
|
|
12
|
+
colorGrayLightest,
|
|
7
13
|
colorBackgroundTertiary,
|
|
8
14
|
colorTextDisabled,
|
|
9
15
|
colorFillDisabled
|
|
@@ -28,33 +34,58 @@
|
|
|
28
34
|
padding: spaceXXSmall spaceSmall;
|
|
29
35
|
gap: spaceXXSmall;
|
|
30
36
|
border-radius: borderRadiusXSmall;
|
|
37
|
+
cursor: pointer;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
.primary {
|
|
34
41
|
background-color: colorNeutralLightest;
|
|
35
42
|
}
|
|
36
43
|
|
|
44
|
+
.primary:hover {
|
|
45
|
+
background-color: colorNeutralLight;
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
.information {
|
|
38
49
|
background-color: colorInformationLightest;
|
|
39
50
|
}
|
|
40
51
|
|
|
52
|
+
.information:hover {
|
|
53
|
+
background-color: colorInformationLight;
|
|
54
|
+
}
|
|
55
|
+
|
|
41
56
|
.success {
|
|
42
57
|
background-color: colorSuccessLightest;
|
|
43
58
|
}
|
|
44
59
|
|
|
60
|
+
.success:hover {
|
|
61
|
+
background-color: colorSuccessLight;
|
|
62
|
+
}
|
|
63
|
+
|
|
45
64
|
.warning {
|
|
46
65
|
background-color: colorWarningLightest;
|
|
47
66
|
}
|
|
48
67
|
|
|
68
|
+
.warning:hover {
|
|
69
|
+
background-color: colorWarningLight;
|
|
70
|
+
}
|
|
71
|
+
|
|
49
72
|
.danger {
|
|
50
73
|
background-color: colorDangerLightest;
|
|
51
74
|
}
|
|
52
75
|
|
|
76
|
+
.danger:hover {
|
|
77
|
+
background-color: colorDangerLight;
|
|
78
|
+
}
|
|
79
|
+
|
|
53
80
|
.secondary {
|
|
54
81
|
composes: borderPrimary from '../../styles/border.module.css';
|
|
55
82
|
background-color: colorBackgroundTertiary;
|
|
56
83
|
}
|
|
57
84
|
|
|
85
|
+
.secondary:hover {
|
|
86
|
+
background-color: colorGrayLightest;
|
|
87
|
+
}
|
|
88
|
+
|
|
58
89
|
.withIcon {
|
|
59
90
|
padding: spaceXXSmall spaceSmall spaceXXSmall spaceXSmall;
|
|
60
91
|
}
|
|
@@ -12,7 +12,7 @@ import classify from '../../utils/classify';
|
|
|
12
12
|
import typographyStyle from '../../styles/typography.module.css';
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
export type IconType = 'regular' | 'solid' | 'duotone';
|
|
15
|
+
export type IconType = 'regular' | 'solid' | 'duotone' | 'brands';
|
|
16
16
|
|
|
17
17
|
export const ICON_SIZE = Object.freeze({
|
|
18
18
|
small: 'small',
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StatusIndicator = exports.STATUS_SEMANTIC = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
9
|
+
var _StatusIndicatorModule = _interopRequireDefault(require("./StatusIndicator.module.css"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
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); }
|
|
14
|
+
const STATUS_SEMANTIC = Object.freeze({
|
|
15
|
+
information: 'information',
|
|
16
|
+
success: 'success',
|
|
17
|
+
warning: 'warning',
|
|
18
|
+
danger: 'danger',
|
|
19
|
+
neutral: 'neutral'
|
|
20
|
+
});
|
|
21
|
+
exports.STATUS_SEMANTIC = STATUS_SEMANTIC;
|
|
22
|
+
const StatusIndicator = _ref => {
|
|
23
|
+
let {
|
|
24
|
+
classNames,
|
|
25
|
+
status = 'information',
|
|
26
|
+
withBorder,
|
|
27
|
+
...props
|
|
28
|
+
} = _ref;
|
|
29
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
30
|
+
"data-testid": "StatusIndicator",
|
|
31
|
+
className: (0, _classify.default)(_StatusIndicatorModule.default.statusWrapper, _StatusIndicatorModule.default[status], {
|
|
32
|
+
[_StatusIndicatorModule.default.withBorder]: withBorder
|
|
33
|
+
}, classNames?.wrapper)
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
exports.StatusIndicator = StatusIndicator;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import classify from '../../utils/classify';
|
|
6
|
+
|
|
7
|
+
import css from './StatusIndicator.module.css';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
type ClassNames = $ReadOnly<{wrapper?: string}>;
|
|
11
|
+
|
|
12
|
+
export const STATUS_SEMANTIC = Object.freeze({
|
|
13
|
+
information: 'information',
|
|
14
|
+
success: 'success',
|
|
15
|
+
warning: 'warning',
|
|
16
|
+
danger: 'danger',
|
|
17
|
+
neutral: 'neutral',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type StatusSemanticType = $Values<typeof STATUS_SEMANTIC>;
|
|
21
|
+
|
|
22
|
+
export type StatusIndicatorProps = {
|
|
23
|
+
classNames?: ClassNames,
|
|
24
|
+
status?: StatusSemanticType,
|
|
25
|
+
withBorder?: boolean,
|
|
26
|
+
...
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const StatusIndicator = ({
|
|
30
|
+
classNames,
|
|
31
|
+
status = 'information',
|
|
32
|
+
withBorder,
|
|
33
|
+
...props
|
|
34
|
+
}: StatusIndicatorProps): React.Node => (
|
|
35
|
+
<div
|
|
36
|
+
{...props}
|
|
37
|
+
data-testid="StatusIndicator"
|
|
38
|
+
className={classify(
|
|
39
|
+
css.statusWrapper,
|
|
40
|
+
css[status],
|
|
41
|
+
{
|
|
42
|
+
[css.withBorder]: withBorder,
|
|
43
|
+
},
|
|
44
|
+
classNames?.wrapper,
|
|
45
|
+
)}
|
|
46
|
+
></div>
|
|
47
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@value (colorInformation, colorSuccess, colorWarning, colorDanger, colorNeutral, colorBackgroundTertiary) from '../../styles/variables/_color.css';
|
|
2
|
+
@value (size8) from '../../styles/variables/_size.css';
|
|
3
|
+
@value (borderRadiusCircle, borderWidthTertiary) from '../../styles/variables/_border.css';
|
|
4
|
+
|
|
5
|
+
.statusWrapper {
|
|
6
|
+
display: flex;
|
|
7
|
+
color: colorFillPrimary;
|
|
8
|
+
width: size8;
|
|
9
|
+
height: size8;
|
|
10
|
+
border-radius: borderRadiusCircle;
|
|
11
|
+
background-color: colorInformation;
|
|
12
|
+
box-sizing: content-box;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.information {
|
|
16
|
+
background-color: colorInformation;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.success {
|
|
20
|
+
background-color: colorSuccess;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.warning {
|
|
24
|
+
background-color: colorWarning;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.danger {
|
|
28
|
+
background-color: colorDanger;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.neutral {
|
|
32
|
+
background-color: colorNeutral;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.withBorder {
|
|
36
|
+
border: borderWidthTertiary solid colorBackgroundTertiary;
|
|
37
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _StatusIndicator = require("./StatusIndicator");
|
|
7
|
+
Object.keys(_StatusIndicator).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _StatusIndicator[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _StatusIndicator[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SubMenuItemText = exports.SubMenuItemIcon = exports.SubMenuItemAction = exports.SubMenuItem = exports.SubMenuGroup = exports.SubMenu = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
9
|
+
var _Icon = require("../Icon");
|
|
10
|
+
var _Text = require("../Text");
|
|
11
|
+
var _SubMenuModule = _interopRequireDefault(require("./SubMenu.module.css"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
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); }
|
|
16
|
+
const SubMenuItemIcon = _ref => {
|
|
17
|
+
let {
|
|
18
|
+
className,
|
|
19
|
+
...props
|
|
20
|
+
} = _ref;
|
|
21
|
+
return /*#__PURE__*/React.createElement(_Icon.Icon, _extends({}, props, {
|
|
22
|
+
size: "small",
|
|
23
|
+
color: _Text.TEXT_COLORS.inverseSecondary,
|
|
24
|
+
className: (0, _classify.default)(_SubMenuModule.default.menuIcon, className)
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
exports.SubMenuItemIcon = SubMenuItemIcon;
|
|
28
|
+
SubMenuItemIcon.displayName = 'SubMenuItemIcon';
|
|
29
|
+
const SubMenuItemText = _ref2 => {
|
|
30
|
+
let {
|
|
31
|
+
children,
|
|
32
|
+
className,
|
|
33
|
+
...props
|
|
34
|
+
} = _ref2;
|
|
35
|
+
return /*#__PURE__*/React.createElement(_Text.ButtonTextSmall, _extends({}, props, {
|
|
36
|
+
className: (0, _classify.default)(_SubMenuModule.default.subMenuItemText, className),
|
|
37
|
+
color: _Text.TEXT_COLORS.inversePrimary
|
|
38
|
+
}), children);
|
|
39
|
+
};
|
|
40
|
+
exports.SubMenuItemText = SubMenuItemText;
|
|
41
|
+
SubMenuItemText.displayName = 'SubMenuItemText';
|
|
42
|
+
const SubMenuItemAction = _ref3 => {
|
|
43
|
+
let {
|
|
44
|
+
children,
|
|
45
|
+
className,
|
|
46
|
+
...props
|
|
47
|
+
} = _ref3;
|
|
48
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
49
|
+
className: (0, _classify.default)(_SubMenuModule.default.subMenuItemAction, className)
|
|
50
|
+
}), children);
|
|
51
|
+
};
|
|
52
|
+
exports.SubMenuItemAction = SubMenuItemAction;
|
|
53
|
+
SubMenuItemAction.displayName = 'SubMenuItemAction';
|
|
54
|
+
const SubMenuItem = _ref4 => {
|
|
55
|
+
let {
|
|
56
|
+
children,
|
|
57
|
+
selectedMenuKey,
|
|
58
|
+
disabled,
|
|
59
|
+
classNames,
|
|
60
|
+
onChange,
|
|
61
|
+
menuKey
|
|
62
|
+
} = _ref4;
|
|
63
|
+
const onChangeHandler = () => {
|
|
64
|
+
if (!disabled) {
|
|
65
|
+
onChange && onChange(menuKey);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const selected = selectedMenuKey === menuKey;
|
|
69
|
+
const getNamedComp = comp => {
|
|
70
|
+
const childrenArray = React.Children.toArray(children);
|
|
71
|
+
if (childrenArray.length) {
|
|
72
|
+
const nodes = [];
|
|
73
|
+
for (const child of childrenArray) {
|
|
74
|
+
if (child?.type?.displayName === comp) {
|
|
75
|
+
nodes.push( /*#__PURE__*/React.cloneElement(child, {
|
|
76
|
+
selected,
|
|
77
|
+
disabled
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return nodes.length > 1 ? nodes : nodes[0];
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
};
|
|
85
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
86
|
+
className: (0, _classify.default)(_SubMenuModule.default.menuItem, {
|
|
87
|
+
[_SubMenuModule.default.selected]: selected,
|
|
88
|
+
[_SubMenuModule.default.disabled]: disabled
|
|
89
|
+
}, classNames?.wrapper),
|
|
90
|
+
onClick: onChangeHandler
|
|
91
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
92
|
+
className: _SubMenuModule.default.menuIconName
|
|
93
|
+
}, getNamedComp('SubMenuItemIcon'), getNamedComp('SubMenuItemText')), getNamedComp('SubMenuItemAction'));
|
|
94
|
+
};
|
|
95
|
+
exports.SubMenuItem = SubMenuItem;
|
|
96
|
+
const SubMenuGroup = _ref5 => {
|
|
97
|
+
let {
|
|
98
|
+
children,
|
|
99
|
+
groupTitle,
|
|
100
|
+
collapsible = false,
|
|
101
|
+
disabled = false,
|
|
102
|
+
onChange,
|
|
103
|
+
selectedMenuKey,
|
|
104
|
+
classNames
|
|
105
|
+
} = _ref5;
|
|
106
|
+
const [collapsed, setCollapsed] = React.useState(false);
|
|
107
|
+
const collapseHandler = () => {
|
|
108
|
+
collapsible && setCollapsed(!collapsed);
|
|
109
|
+
};
|
|
110
|
+
const onChangeHandler = value => {
|
|
111
|
+
if (onChange) {
|
|
112
|
+
onChange(value);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const childrenWithProps = React.Children.map(children, child => {
|
|
116
|
+
if ( /*#__PURE__*/React.isValidElement(child)) {
|
|
117
|
+
const {
|
|
118
|
+
disabled: disabledChild
|
|
119
|
+
} = child.props;
|
|
120
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
|
121
|
+
selectedMenuKey,
|
|
122
|
+
onChange: onChangeHandler,
|
|
123
|
+
disabled: disabledChild || disabled
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return child;
|
|
127
|
+
});
|
|
128
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
129
|
+
className: (0, _classify.default)(_SubMenuModule.default.subMenuGroupWrapper, classNames?.wrapper)
|
|
130
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
131
|
+
className: (0, _classify.default)(_SubMenuModule.default.subMenuGroupHeader, classNames?.groupHeader),
|
|
132
|
+
onClick: collapseHandler
|
|
133
|
+
}, /*#__PURE__*/React.createElement(_Text.SubTitleExtraSmall, {
|
|
134
|
+
color: _Text.TEXT_COLORS.inverseSecondary,
|
|
135
|
+
className: _SubMenuModule.default.groupTitle
|
|
136
|
+
}, groupTitle), collapsible && /*#__PURE__*/React.createElement(_Icon.Icon, {
|
|
137
|
+
color: _Text.TEXT_COLORS.inverseSecondary,
|
|
138
|
+
name: collapsed ? 'chevron-down' : 'chevron-up',
|
|
139
|
+
size: "small"
|
|
140
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
141
|
+
className: (0, _classify.default)(_SubMenuModule.default.subMenuGroup, {
|
|
142
|
+
[_SubMenuModule.default.collapsed]: collapsible && collapsed
|
|
143
|
+
}, classNames?.menuGroup)
|
|
144
|
+
}, childrenWithProps));
|
|
145
|
+
};
|
|
146
|
+
exports.SubMenuGroup = SubMenuGroup;
|
|
147
|
+
const SubMenu = _ref6 => {
|
|
148
|
+
let {
|
|
149
|
+
classNames,
|
|
150
|
+
children,
|
|
151
|
+
title
|
|
152
|
+
} = _ref6;
|
|
153
|
+
const childrenWithProps = React.Children.map(children, child => {
|
|
154
|
+
if ( /*#__PURE__*/React.isValidElement(child)) {
|
|
155
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
156
|
+
className: _SubMenuModule.default.menuChildWrap
|
|
157
|
+
}, child);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
161
|
+
className: (0, _classify.default)(_SubMenuModule.default.subMenuWrapper, classNames?.wrapper)
|
|
162
|
+
}, /*#__PURE__*/React.createElement(_Text.SubTitleMedium, {
|
|
163
|
+
className: _SubMenuModule.default.subMenuHeader,
|
|
164
|
+
color: _Text.TEXT_COLORS.inversePrimary
|
|
165
|
+
}, title), childrenWithProps);
|
|
166
|
+
};
|
|
167
|
+
exports.SubMenu = SubMenu;
|
|
168
|
+
SubMenu.displayName = 'SubMenu';
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
import type {ColorTypes} from '../../types/typography';
|
|
6
|
+
import classify from '../../utils/classify';
|
|
7
|
+
import type {IconProps} from '../Icon';
|
|
8
|
+
import {Icon} from '../Icon';
|
|
9
|
+
import type {TextProps} from '../Text';
|
|
10
|
+
import {
|
|
11
|
+
ButtonTextSmall,
|
|
12
|
+
SubTitleExtraSmall,
|
|
13
|
+
SubTitleMedium,
|
|
14
|
+
TEXT_COLORS,
|
|
15
|
+
} from '../Text';
|
|
16
|
+
|
|
17
|
+
import css from './SubMenu.module.css';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
type ClassNames = $ReadOnly<{wrapper?: string}>;
|
|
21
|
+
|
|
22
|
+
export const SubMenuItemIcon = ({
|
|
23
|
+
className,
|
|
24
|
+
...props
|
|
25
|
+
}: IconProps): React.Node => (
|
|
26
|
+
<Icon
|
|
27
|
+
{...props}
|
|
28
|
+
size="small"
|
|
29
|
+
color={TEXT_COLORS.inverseSecondary}
|
|
30
|
+
className={classify(css.menuIcon, className)}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
SubMenuItemIcon.displayName = 'SubMenuItemIcon';
|
|
35
|
+
|
|
36
|
+
export const SubMenuItemText = ({
|
|
37
|
+
children,
|
|
38
|
+
className,
|
|
39
|
+
...props
|
|
40
|
+
}: TextProps): React.Node => (
|
|
41
|
+
<ButtonTextSmall
|
|
42
|
+
{...props}
|
|
43
|
+
className={classify(css.subMenuItemText, className)}
|
|
44
|
+
color={TEXT_COLORS.inversePrimary}
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
</ButtonTextSmall>
|
|
48
|
+
);
|
|
49
|
+
SubMenuItemText.displayName = 'SubMenuItemText';
|
|
50
|
+
|
|
51
|
+
export type SubMenuItemActionProps = {
|
|
52
|
+
children?: React.Node,
|
|
53
|
+
color?: ColorTypes,
|
|
54
|
+
className?: string,
|
|
55
|
+
...
|
|
56
|
+
};
|
|
57
|
+
export const SubMenuItemAction = ({
|
|
58
|
+
children,
|
|
59
|
+
className,
|
|
60
|
+
...props
|
|
61
|
+
}: SubMenuItemActionProps): React.Node => (
|
|
62
|
+
<div {...props} className={classify(css.subMenuItemAction, className)}>
|
|
63
|
+
{children}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
SubMenuItemAction.displayName = 'SubMenuItemAction';
|
|
67
|
+
|
|
68
|
+
export type SubMenuItemProps = {
|
|
69
|
+
classNames?: ClassNames,
|
|
70
|
+
children?: React.Node,
|
|
71
|
+
selectedMenuKey?: string,
|
|
72
|
+
disabled?: boolean,
|
|
73
|
+
onChange?: (selectedMenuKey: string) => mixed,
|
|
74
|
+
menuKey: string,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const SubMenuItem = ({
|
|
78
|
+
children,
|
|
79
|
+
selectedMenuKey,
|
|
80
|
+
disabled,
|
|
81
|
+
classNames,
|
|
82
|
+
onChange,
|
|
83
|
+
menuKey,
|
|
84
|
+
}: SubMenuItemProps): React.Node => {
|
|
85
|
+
const onChangeHandler = () => {
|
|
86
|
+
if (!disabled) {
|
|
87
|
+
onChange && onChange(menuKey);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const selected = selectedMenuKey === menuKey;
|
|
92
|
+
|
|
93
|
+
const getNamedComp = (comp: string) => {
|
|
94
|
+
const childrenArray = React.Children.toArray(children);
|
|
95
|
+
if (childrenArray.length) {
|
|
96
|
+
const nodes: React.Node[] = [];
|
|
97
|
+
for (const child of childrenArray) {
|
|
98
|
+
if (child?.type?.displayName === comp) {
|
|
99
|
+
nodes.push(
|
|
100
|
+
React.cloneElement(child, {
|
|
101
|
+
selected,
|
|
102
|
+
disabled,
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return nodes.length > 1 ? nodes : nodes[0];
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<div
|
|
114
|
+
className={classify(
|
|
115
|
+
css.menuItem,
|
|
116
|
+
{
|
|
117
|
+
[css.selected]: selected,
|
|
118
|
+
[css.disabled]: disabled,
|
|
119
|
+
},
|
|
120
|
+
classNames?.wrapper,
|
|
121
|
+
)}
|
|
122
|
+
onClick={onChangeHandler}
|
|
123
|
+
>
|
|
124
|
+
<div className={css.menuIconName}>
|
|
125
|
+
{getNamedComp('SubMenuItemIcon')}
|
|
126
|
+
{getNamedComp('SubMenuItemText')}
|
|
127
|
+
</div>
|
|
128
|
+
{getNamedComp('SubMenuItemAction')}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
type SubMenuGroupClassNames = $ReadOnly<{
|
|
134
|
+
wrapper?: string,
|
|
135
|
+
groupHeader?: string,
|
|
136
|
+
menuGroup?: string,
|
|
137
|
+
}>;
|
|
138
|
+
|
|
139
|
+
export type SubMenuGroupProps = {
|
|
140
|
+
children?: React.Node,
|
|
141
|
+
groupTitle?: string,
|
|
142
|
+
collapsible?: boolean,
|
|
143
|
+
disabled?: boolean,
|
|
144
|
+
onChange?: (value: string) => mixed,
|
|
145
|
+
selectedMenuKey?: string,
|
|
146
|
+
classNames?: SubMenuGroupClassNames,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const SubMenuGroup = ({
|
|
150
|
+
children,
|
|
151
|
+
groupTitle,
|
|
152
|
+
collapsible = false,
|
|
153
|
+
disabled = false,
|
|
154
|
+
onChange,
|
|
155
|
+
selectedMenuKey,
|
|
156
|
+
classNames,
|
|
157
|
+
}: SubMenuGroupProps): React.Node => {
|
|
158
|
+
const [collapsed, setCollapsed] = React.useState(false);
|
|
159
|
+
const collapseHandler = () => {
|
|
160
|
+
collapsible && setCollapsed(!collapsed);
|
|
161
|
+
};
|
|
162
|
+
const onChangeHandler = (value) => {
|
|
163
|
+
if (onChange) {
|
|
164
|
+
onChange(value);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const childrenWithProps = React.Children.map(children, (child) => {
|
|
168
|
+
if (React.isValidElement(child)) {
|
|
169
|
+
const {disabled: disabledChild} = child.props;
|
|
170
|
+
return React.cloneElement(child, {
|
|
171
|
+
selectedMenuKey,
|
|
172
|
+
onChange: onChangeHandler,
|
|
173
|
+
disabled: disabledChild || disabled,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return child;
|
|
177
|
+
});
|
|
178
|
+
return (
|
|
179
|
+
<div className={classify(css.subMenuGroupWrapper, classNames?.wrapper)}>
|
|
180
|
+
<div
|
|
181
|
+
className={classify(css.subMenuGroupHeader, classNames?.groupHeader)}
|
|
182
|
+
onClick={collapseHandler}
|
|
183
|
+
>
|
|
184
|
+
<SubTitleExtraSmall
|
|
185
|
+
color={TEXT_COLORS.inverseSecondary}
|
|
186
|
+
className={css.groupTitle}
|
|
187
|
+
>
|
|
188
|
+
{groupTitle}
|
|
189
|
+
</SubTitleExtraSmall>
|
|
190
|
+
{collapsible && (
|
|
191
|
+
<Icon
|
|
192
|
+
color={TEXT_COLORS.inverseSecondary}
|
|
193
|
+
name={collapsed ? 'chevron-down' : 'chevron-up'}
|
|
194
|
+
size="small"
|
|
195
|
+
/>
|
|
196
|
+
)}
|
|
197
|
+
</div>
|
|
198
|
+
<div
|
|
199
|
+
className={classify(
|
|
200
|
+
css.subMenuGroup,
|
|
201
|
+
{
|
|
202
|
+
[css.collapsed]: collapsible && collapsed,
|
|
203
|
+
},
|
|
204
|
+
classNames?.menuGroup,
|
|
205
|
+
)}
|
|
206
|
+
>
|
|
207
|
+
{childrenWithProps}
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export type SubMenuProps = {
|
|
214
|
+
classNames?: ClassNames,
|
|
215
|
+
title: string,
|
|
216
|
+
children?: React.Node,
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export const SubMenu = ({
|
|
220
|
+
classNames,
|
|
221
|
+
children,
|
|
222
|
+
title,
|
|
223
|
+
}: SubMenuProps): React.Node => {
|
|
224
|
+
const childrenWithProps = React.Children.map(children, (child) => {
|
|
225
|
+
if (React.isValidElement(child)) {
|
|
226
|
+
return <div className={css.menuChildWrap}>{child}</div>;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<div className={classify(css.subMenuWrapper, classNames?.wrapper)}>
|
|
232
|
+
<SubTitleMedium
|
|
233
|
+
className={css.subMenuHeader}
|
|
234
|
+
color={TEXT_COLORS.inversePrimary}
|
|
235
|
+
>
|
|
236
|
+
{title}
|
|
237
|
+
</SubTitleMedium>
|
|
238
|
+
{childrenWithProps}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
SubMenu.displayName = 'SubMenu';
|