@targetprocess/menu 12.29.0-alpha.0 → 12.31.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/Menu.jsx +19 -9
- package/__tests__/Menu.tests.jsx +46 -1
- package/dist/menu.es.js +24 -23
- package/dist/menu.js +24 -23
- package/package.json +4 -4
package/Menu.jsx
CHANGED
|
@@ -251,15 +251,12 @@ export class Menu extends React.Component {
|
|
|
251
251
|
|
|
252
252
|
const trigger = typeof children === 'function' ? children(renderCallbackArgs) : children
|
|
253
253
|
|
|
254
|
-
const getPopoverPosition =
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
return isLeftOpen ? {right: hostRect.width, top: 0} : {left: hostRect.width, top: 0}
|
|
262
|
-
}
|
|
254
|
+
const getPopoverPosition = menuGetPosition(
|
|
255
|
+
this.props.getPopoverPosition,
|
|
256
|
+
isLeftOpen,
|
|
257
|
+
isAnchoredBottom
|
|
258
|
+
)
|
|
259
|
+
|
|
263
260
|
return {trigger, getPopoverPosition}
|
|
264
261
|
}
|
|
265
262
|
|
|
@@ -287,6 +284,19 @@ export class Menu extends React.Component {
|
|
|
287
284
|
}
|
|
288
285
|
}
|
|
289
286
|
|
|
287
|
+
export function menuGetPosition(getPopoverPosition, isLeftOpen, isAnchoredBottom) {
|
|
288
|
+
const result =
|
|
289
|
+
typeof getPopoverPosition === 'undefined'
|
|
290
|
+
? hostRect => {
|
|
291
|
+
if (isAnchoredBottom) {
|
|
292
|
+
return isLeftOpen ? {right: 0, top: hostRect.height} : {left: 0, top: hostRect.height}
|
|
293
|
+
}
|
|
294
|
+
return isLeftOpen ? {right: hostRect.width, top: 0} : {left: hostRect.width, top: 0}
|
|
295
|
+
}
|
|
296
|
+
: getPopoverPosition
|
|
297
|
+
return result
|
|
298
|
+
}
|
|
299
|
+
|
|
290
300
|
Menu.propTypes = {
|
|
291
301
|
open: PropTypes.bool,
|
|
292
302
|
/** Indicates that submenu will be inserted into DOM as siblings to menu trigger */
|
package/__tests__/Menu.tests.jsx
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
/* eslint-env jest */
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import {shallow} from 'enzyme'
|
|
3
|
+
import {shallow, mount} from 'enzyme'
|
|
4
4
|
import {Menu} from '../index'
|
|
5
|
+
import {menuGetPosition} from '../Menu'
|
|
5
6
|
import {CaretIcon} from '@targetprocess/icons'
|
|
6
7
|
|
|
8
|
+
describe('Menu', () => {
|
|
9
|
+
it('should render trigger', () => {
|
|
10
|
+
const props = {}
|
|
11
|
+
const wrapper = mount(
|
|
12
|
+
<Menu {...props}>
|
|
13
|
+
<Menu.Trigger>
|
|
14
|
+
{({setOpened, isOpen}) => (
|
|
15
|
+
<button className="testTrigger" onClick={() => setOpened(!isOpen)}>
|
|
16
|
+
testButton
|
|
17
|
+
</button>
|
|
18
|
+
)}
|
|
19
|
+
</Menu.Trigger>
|
|
20
|
+
</Menu>
|
|
21
|
+
)
|
|
22
|
+
expect(
|
|
23
|
+
wrapper.containsMatchingElement(<button className="testTrigger">testButton</button>)
|
|
24
|
+
).toBeTruthy()
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
7
28
|
describe('MenuItem', () => {
|
|
8
29
|
it('should render item', () => {
|
|
9
30
|
const wrapper = shallow(<Menu.Item>Test Menu Item</Menu.Item>)
|
|
@@ -94,3 +115,27 @@ describe('MenuSeparator', () => {
|
|
|
94
115
|
expect(title.text()).toEqual('test')
|
|
95
116
|
})
|
|
96
117
|
})
|
|
118
|
+
|
|
119
|
+
describe('menuGetPosition', () => {
|
|
120
|
+
it('should return getPopoverPosition if getPopoverPosition is provided', () => {
|
|
121
|
+
const getPopoverPosition = 'top'
|
|
122
|
+
const result = menuGetPosition(getPopoverPosition, false, false)
|
|
123
|
+
|
|
124
|
+
expect(result).toBe(getPopoverPosition)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test.each([
|
|
128
|
+
[false, false, {left: 222, top: 0}],
|
|
129
|
+
[false, true, {left: 0, top: 111}],
|
|
130
|
+
[true, false, {right: 222, top: 0}],
|
|
131
|
+
[true, true, {right: 0, top: 111}]
|
|
132
|
+
])(
|
|
133
|
+
'should return correct value in case of getPopoverPosition is undefiend and isLeftOpen:%s isAnchoredBottom:%s',
|
|
134
|
+
(isLeftOpen, isAnchoredBottom, expected) => {
|
|
135
|
+
const result = menuGetPosition(undefined, isLeftOpen, isAnchoredBottom)
|
|
136
|
+
|
|
137
|
+
const position = result({height: 111, width: 222})
|
|
138
|
+
expect(position).toEqual(expected)
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
})
|
package/dist/menu.es.js
CHANGED
|
@@ -166,8 +166,8 @@ function styleInject(css, ref) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.menu__menu__12-
|
|
170
|
-
var styles = {"menu":"menu__menu__12-
|
|
169
|
+
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.menu__menu__12-31-0 {\n -webkit-transition-property: opacity !important;\n transition-property: opacity !important;\n -webkit-transform: none !important;\n transform: none !important;\n padding: 0;\n}\n.menu__item__menu__12-31-0 {\n font-size: var(--FontSizeDefault, 13px);\n position: relative;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n padding: var(--SpaceS, 8px) var(--SpaceSM, 12px);\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n }\n.menu__item__content__menu__12-31-0 {\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n }\n.menu__item__content--left__menu__12-31-0 {\n padding-left: var(--IconsSizeDefault, 16px);\n }\n.menu__item__menu__12-31-0 .submenu-icon__menu__12-31-0 {\n -webkit-box-flex: 0;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n }\n.menu__item__menu__12-31-0 .submenu-icon--left__menu__12-31-0 {\n margin-right: var(--SpaceS, 8px);\n }\n.menu__item__menu__12-31-0 .submenu-icon--right__menu__12-31-0 {\n margin-left: var(--SpaceS, 8px);\n }\n.menu__item__menu__12-31-0:not(.menu__item--disabled__menu__12-31-0):hover {\n cursor: pointer;\n }\n.menu__item--disabled__menu__12-31-0 {\n opacity: var(--ControlDisabledOpacity, 0.5);\n cursor: not-allowed;\n }\n.menu__item--danger__menu__12-31-0 {\n color: var(--ActionColorDelete, #AE304A);\n }\n.menu__item--danger__menu__12-31-0:not(.menu__item--disabled__menu__12-31-0):hover {\n background-color: var(--ActionBackgroundDelete, #F3E0E4);\n }\n.menu__item--current__menu__12-31-0 {\n background-color: var(--HighlightBlockBackground, #F5F6F6); /* keyboard current background */\n }\n.menu__item--selected__menu__12-31-0:not(.menu__item--danger__menu__12-31-0) {\n background-color: var(--ActionBackgroundSelected, #F1CE4A);\n }\n.menu__item__menu__12-31-0:not(.menu__item--danger__menu__12-31-0):not(.menu__item--disabled__menu__12-31-0):not(.menu__item--selected__menu__12-31-0):hover {\n background-color: var(--ActionBackgroundHover, #F9E9AE);\n }\n.menu__item__menu__12-31-0:last-child {\n border-radius: 0 0 var(--BorderRadiusDefault, 3px) var(--BorderRadiusDefault, 3px);\n }\n.menu__separator__menu__12-31-0 {\n margin: var(--SpaceXS, 4px) 0;\n border-top: solid 1px var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n }\n.menu__separator__title__menu__12-31-0 {\n padding: var(--SpaceS, 8px) var(--SpaceSM, 12px) var(--SpaceXS, 4px) var(--SpaceSM, 12px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n font-size: var(--FontSizeLabel, 11px);\n line-height: 1.3;\n font-weight: var(--FontWeightSemibold, 600);\n text-transform: uppercase;\n color: var(--FontColorGray, rgba(0, 0, 0, 0.7));\n letter-spacing: 0.4px;\n }\n";
|
|
170
|
+
var styles = {"menu":"menu__menu__12-31-0","menu__item":"menu__item__menu__12-31-0","menu__item__content":"menu__item__content__menu__12-31-0","menu__item__content--left":"menu__item__content--left__menu__12-31-0","submenu-icon":"submenu-icon__menu__12-31-0","submenu-icon--left":"submenu-icon--left__menu__12-31-0","submenu-icon--right":"submenu-icon--right__menu__12-31-0","menu__item--disabled":"menu__item--disabled__menu__12-31-0","menu__item--danger":"menu__item--danger__menu__12-31-0","menu__item--current":"menu__item--current__menu__12-31-0","menu__item--selected":"menu__item--selected__menu__12-31-0","menu__separator":"menu__separator__menu__12-31-0","menu__separator__title":"menu__separator__title__menu__12-31-0"};
|
|
171
171
|
styleInject(css);
|
|
172
172
|
|
|
173
173
|
/**
|
|
@@ -407,27 +407,7 @@ var Menu = /*#__PURE__*/function (_React$Component) {
|
|
|
407
407
|
setOpened: _this.setOpened
|
|
408
408
|
};
|
|
409
409
|
var trigger = typeof children === 'function' ? children(renderCallbackArgs) : children;
|
|
410
|
-
var getPopoverPosition =
|
|
411
|
-
if (typeof _this.props.getPopoverPosition !== 'undefined') {
|
|
412
|
-
return _this.props.getPopoverPosition;
|
|
413
|
-
}
|
|
414
|
-
if (isAnchoredBottom) {
|
|
415
|
-
return isLeftOpen ? {
|
|
416
|
-
right: 0,
|
|
417
|
-
top: hostRect.height
|
|
418
|
-
} : {
|
|
419
|
-
left: 0,
|
|
420
|
-
top: hostRect.height
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
return isLeftOpen ? {
|
|
424
|
-
right: hostRect.width,
|
|
425
|
-
top: 0
|
|
426
|
-
} : {
|
|
427
|
-
left: hostRect.width,
|
|
428
|
-
top: 0
|
|
429
|
-
};
|
|
430
|
-
};
|
|
410
|
+
var getPopoverPosition = menuGetPosition(_this.props.getPopoverPosition, isLeftOpen, isAnchoredBottom);
|
|
431
411
|
return {
|
|
432
412
|
trigger: trigger,
|
|
433
413
|
getPopoverPosition: getPopoverPosition
|
|
@@ -586,6 +566,27 @@ var Menu = /*#__PURE__*/function (_React$Component) {
|
|
|
586
566
|
}]);
|
|
587
567
|
return Menu;
|
|
588
568
|
}(React.Component);
|
|
569
|
+
function menuGetPosition(getPopoverPosition, isLeftOpen, isAnchoredBottom) {
|
|
570
|
+
var result = typeof getPopoverPosition === 'undefined' ? function (hostRect) {
|
|
571
|
+
if (isAnchoredBottom) {
|
|
572
|
+
return isLeftOpen ? {
|
|
573
|
+
right: 0,
|
|
574
|
+
top: hostRect.height
|
|
575
|
+
} : {
|
|
576
|
+
left: 0,
|
|
577
|
+
top: hostRect.height
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
return isLeftOpen ? {
|
|
581
|
+
right: hostRect.width,
|
|
582
|
+
top: 0
|
|
583
|
+
} : {
|
|
584
|
+
left: hostRect.width,
|
|
585
|
+
top: 0
|
|
586
|
+
};
|
|
587
|
+
} : getPopoverPosition;
|
|
588
|
+
return result;
|
|
589
|
+
}
|
|
589
590
|
Menu.defaultProps = {
|
|
590
591
|
closeOnOuterAction: true,
|
|
591
592
|
navigationState: {}
|
package/dist/menu.js
CHANGED
|
@@ -172,8 +172,8 @@ function styleInject(css, ref) {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.menu__menu__12-
|
|
176
|
-
var styles = {"menu":"menu__menu__12-
|
|
175
|
+
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.menu__menu__12-31-0 {\n -webkit-transition-property: opacity !important;\n transition-property: opacity !important;\n -webkit-transform: none !important;\n transform: none !important;\n padding: 0;\n}\n.menu__item__menu__12-31-0 {\n font-size: var(--FontSizeDefault, 13px);\n position: relative;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n padding: var(--SpaceS, 8px) var(--SpaceSM, 12px);\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n }\n.menu__item__content__menu__12-31-0 {\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n }\n.menu__item__content--left__menu__12-31-0 {\n padding-left: var(--IconsSizeDefault, 16px);\n }\n.menu__item__menu__12-31-0 .submenu-icon__menu__12-31-0 {\n -webkit-box-flex: 0;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n }\n.menu__item__menu__12-31-0 .submenu-icon--left__menu__12-31-0 {\n margin-right: var(--SpaceS, 8px);\n }\n.menu__item__menu__12-31-0 .submenu-icon--right__menu__12-31-0 {\n margin-left: var(--SpaceS, 8px);\n }\n.menu__item__menu__12-31-0:not(.menu__item--disabled__menu__12-31-0):hover {\n cursor: pointer;\n }\n.menu__item--disabled__menu__12-31-0 {\n opacity: var(--ControlDisabledOpacity, 0.5);\n cursor: not-allowed;\n }\n.menu__item--danger__menu__12-31-0 {\n color: var(--ActionColorDelete, #AE304A);\n }\n.menu__item--danger__menu__12-31-0:not(.menu__item--disabled__menu__12-31-0):hover {\n background-color: var(--ActionBackgroundDelete, #F3E0E4);\n }\n.menu__item--current__menu__12-31-0 {\n background-color: var(--HighlightBlockBackground, #F5F6F6); /* keyboard current background */\n }\n.menu__item--selected__menu__12-31-0:not(.menu__item--danger__menu__12-31-0) {\n background-color: var(--ActionBackgroundSelected, #F1CE4A);\n }\n.menu__item__menu__12-31-0:not(.menu__item--danger__menu__12-31-0):not(.menu__item--disabled__menu__12-31-0):not(.menu__item--selected__menu__12-31-0):hover {\n background-color: var(--ActionBackgroundHover, #F9E9AE);\n }\n.menu__item__menu__12-31-0:last-child {\n border-radius: 0 0 var(--BorderRadiusDefault, 3px) var(--BorderRadiusDefault, 3px);\n }\n.menu__separator__menu__12-31-0 {\n margin: var(--SpaceXS, 4px) 0;\n border-top: solid 1px var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n }\n.menu__separator__title__menu__12-31-0 {\n padding: var(--SpaceS, 8px) var(--SpaceSM, 12px) var(--SpaceXS, 4px) var(--SpaceSM, 12px);\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n font-size: var(--FontSizeLabel, 11px);\n line-height: 1.3;\n font-weight: var(--FontWeightSemibold, 600);\n text-transform: uppercase;\n color: var(--FontColorGray, rgba(0, 0, 0, 0.7));\n letter-spacing: 0.4px;\n }\n";
|
|
176
|
+
var styles = {"menu":"menu__menu__12-31-0","menu__item":"menu__item__menu__12-31-0","menu__item__content":"menu__item__content__menu__12-31-0","menu__item__content--left":"menu__item__content--left__menu__12-31-0","submenu-icon":"submenu-icon__menu__12-31-0","submenu-icon--left":"submenu-icon--left__menu__12-31-0","submenu-icon--right":"submenu-icon--right__menu__12-31-0","menu__item--disabled":"menu__item--disabled__menu__12-31-0","menu__item--danger":"menu__item--danger__menu__12-31-0","menu__item--current":"menu__item--current__menu__12-31-0","menu__item--selected":"menu__item--selected__menu__12-31-0","menu__separator":"menu__separator__menu__12-31-0","menu__separator__title":"menu__separator__title__menu__12-31-0"};
|
|
177
177
|
styleInject(css);
|
|
178
178
|
|
|
179
179
|
/**
|
|
@@ -413,27 +413,7 @@ var Menu = /*#__PURE__*/function (_React$Component) {
|
|
|
413
413
|
setOpened: _this.setOpened
|
|
414
414
|
};
|
|
415
415
|
var trigger = typeof children === 'function' ? children(renderCallbackArgs) : children;
|
|
416
|
-
var getPopoverPosition =
|
|
417
|
-
if (typeof _this.props.getPopoverPosition !== 'undefined') {
|
|
418
|
-
return _this.props.getPopoverPosition;
|
|
419
|
-
}
|
|
420
|
-
if (isAnchoredBottom) {
|
|
421
|
-
return isLeftOpen ? {
|
|
422
|
-
right: 0,
|
|
423
|
-
top: hostRect.height
|
|
424
|
-
} : {
|
|
425
|
-
left: 0,
|
|
426
|
-
top: hostRect.height
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
return isLeftOpen ? {
|
|
430
|
-
right: hostRect.width,
|
|
431
|
-
top: 0
|
|
432
|
-
} : {
|
|
433
|
-
left: hostRect.width,
|
|
434
|
-
top: 0
|
|
435
|
-
};
|
|
436
|
-
};
|
|
416
|
+
var getPopoverPosition = menuGetPosition(_this.props.getPopoverPosition, isLeftOpen, isAnchoredBottom);
|
|
437
417
|
return {
|
|
438
418
|
trigger: trigger,
|
|
439
419
|
getPopoverPosition: getPopoverPosition
|
|
@@ -592,6 +572,27 @@ var Menu = /*#__PURE__*/function (_React$Component) {
|
|
|
592
572
|
}]);
|
|
593
573
|
return Menu;
|
|
594
574
|
}(React.Component);
|
|
575
|
+
function menuGetPosition(getPopoverPosition, isLeftOpen, isAnchoredBottom) {
|
|
576
|
+
var result = typeof getPopoverPosition === 'undefined' ? function (hostRect) {
|
|
577
|
+
if (isAnchoredBottom) {
|
|
578
|
+
return isLeftOpen ? {
|
|
579
|
+
right: 0,
|
|
580
|
+
top: hostRect.height
|
|
581
|
+
} : {
|
|
582
|
+
left: 0,
|
|
583
|
+
top: hostRect.height
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
return isLeftOpen ? {
|
|
587
|
+
right: hostRect.width,
|
|
588
|
+
top: 0
|
|
589
|
+
} : {
|
|
590
|
+
left: hostRect.width,
|
|
591
|
+
top: 0
|
|
592
|
+
};
|
|
593
|
+
} : getPopoverPosition;
|
|
594
|
+
return result;
|
|
595
|
+
}
|
|
595
596
|
Menu.defaultProps = {
|
|
596
597
|
closeOnOuterAction: true,
|
|
597
598
|
navigationState: {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targetprocess/menu",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.31.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/menu.js",
|
|
6
6
|
"module": "dist/menu.es.js",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"prepack": "node -r ../../.ts-node.js ../../config/rollup.config.js ."
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@targetprocess/icons": "^12.
|
|
14
|
-
"@targetprocess/popover": "^12.
|
|
13
|
+
"@targetprocess/icons": "^12.31.0",
|
|
14
|
+
"@targetprocess/popover": "^12.31.0",
|
|
15
15
|
"classnames": "^2.2.5",
|
|
16
16
|
"prop-types": "^15.6.0",
|
|
17
17
|
"react": "^16.7.0",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"sideEffects": false,
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "2174b9cd34ffabf4dfb8b2a42adce64e3f7b7895"
|
|
25
25
|
}
|