Skip to content

Commit 2b944fd

Browse files
Add show more button base
1 parent e152af1 commit 2b944fd

File tree

13 files changed

+650
-173
lines changed

13 files changed

+650
-173
lines changed

src/platform/plugins/shared/navigation/public/top_nav_menu/create_top_nav_menu.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ export function createTopNav(
5353
.primaryActionItem,
5454
secondaryActionItem: (props.config as TopNavMenuPropsBeta<QT>['config'])!
5555
.secondaryActionItem,
56-
enableShowMoreButton: (props.config as TopNavMenuPropsBeta<QT>['config'])!
57-
.enableShowMoreButton,
5856
}
5957
: { items: relevantConfig }
6058
}

src/platform/plugins/shared/navigation/public/top_nav_menu/top_nav_menu_data.tsx

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import type { EuiButtonProps, EuiBetaBadgeProps, IconType, EuiButtonColor } from '@elastic/eui';
10+
import type { EuiButtonProps, EuiBetaBadgeProps, IconType } from '@elastic/eui';
1111
import type { InjectedIntl } from '@kbn/i18n-react';
1212
import type { SplitButtonProps } from '@kbn/split-button';
1313

@@ -42,47 +42,3 @@ export interface TopNavMenuData {
4242
export interface RegisteredTopNavMenuData extends TopNavMenuData {
4343
appName?: string;
4444
}
45-
46-
export type TopNavMenuSplitButtonProps = Pick<
47-
SplitButtonProps,
48-
| 'isMainButtonLoading'
49-
| 'isMainButtonDisabled'
50-
| 'isSecondaryButtonLoading'
51-
| 'isSecondaryButtonDisabled'
52-
| 'secondaryButtonAriaLabel'
53-
| 'secondaryButtonTitle'
54-
| 'iconType'
55-
> & {
56-
run: TopNavMenuAction;
57-
};
58-
59-
export interface TopNavMenuItemCommonBeta {
60-
id?: string;
61-
htmlId?: string;
62-
label: string;
63-
run: TopNavMenuAction;
64-
testId?: string;
65-
disableButton?: boolean | (() => boolean);
66-
isLoading?: boolean;
67-
target?: string;
68-
href?: string;
69-
iconType?: IconType;
70-
}
71-
72-
export type TopNavMenuItemBeta = TopNavMenuItemCommonBeta;
73-
74-
export interface TopNavMenuActionItemBeta extends TopNavMenuItemCommonBeta {
75-
splitButtonProps?: TopNavMenuSplitButtonProps;
76-
color?: EuiButtonColor;
77-
}
78-
79-
export interface TopNavMenuDataBeta {
80-
items: TopNavMenuItemBeta[];
81-
enableShowMoreButton?: boolean;
82-
secondaryActionItem?: TopNavMenuActionItemBeta;
83-
primaryActionItem?: TopNavMenuActionItemBeta;
84-
}
85-
86-
export interface RegisteredTopNavMenuDataBeta extends TopNavMenuItemBeta {
87-
appName?: string;
88-
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
export const TOP_NAV_MENU_ITEM_LIMIT = 5;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
export { TopNavMenuItemsBeta } from './top_nav_menu_items_beta';
11+
export { TopNavMenuActionButton } from './top_nav_menu_action_button';
12+
export { TopNavMenuItemBeta } from './top_nav_menu_item_beta';
13+
export { TopNavMenuShowMoreButton } from './top_nav_menu_show_more_button';
14+
15+
export type {
16+
TopNavMenuSplitButtonProps,
17+
TopNavMenuItemBetaType,
18+
TopNavMenuActionItemBeta,
19+
TopNavMenuSecondaryActionItemBeta,
20+
TopNavMenuPrimaryActionItemBeta,
21+
TopNavMenuConfigBeta,
22+
RegisteredTopNavMenuDataBeta,
23+
} from './types';
24+
25+
export { TOP_NAV_MENU_ITEM_LIMIT } from './constants';
26+
export { getTopNavItems, isDisabled, getTooltip } from './utils';

src/platform/plugins/shared/navigation/public/top_nav_menu_beta/top_nav_menu_action_button.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ describe('TopNavMenuActionButton', () => {
1717
label: 'save',
1818
run: jest.fn(),
1919
closePopover: jest.fn(),
20+
iconType: 'save',
2021
};
2122

2223
const splitButtonProps = {
2324
run: jest.fn(),
2425
secondaryButtonAriaLabel: 'More options',
26+
secondaryButtonIcon: 'arrowDown',
2527
};
2628

2729
beforeEach(() => {

src/platform/plugins/shared/navigation/public/top_nav_menu_beta/top_nav_menu_action_button.tsx

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,46 @@
99

1010
import React from 'react';
1111
import { SplitButton } from '@kbn/split-button';
12-
import { isFunction, upperFirst } from 'lodash';
12+
import { upperFirst } from 'lodash';
1313
import type { MouseEvent } from 'react';
14-
import { EuiButton } from '@elastic/eui';
15-
import type { TopNavMenuActionItemBeta } from '../top_nav_menu/top_nav_menu_data';
14+
import { EuiButton, EuiToolTip } from '@elastic/eui';
15+
import { getTooltip, isDisabled } from './utils';
16+
import type {
17+
TopNavMenuPrimaryActionItemBeta,
18+
TopNavMenuSecondaryActionItemBeta,
19+
TopNavMenuSplitButtonProps,
20+
} from './types';
1621

17-
interface TopNavMenuActionButtonProps extends TopNavMenuActionItemBeta {
22+
type TopNavMenuActionButtonProps = (
23+
| TopNavMenuPrimaryActionItemBeta
24+
| TopNavMenuSecondaryActionItemBeta
25+
) & {
1826
closePopover: () => void;
1927
isMobileMenu?: boolean;
20-
}
28+
};
2129

22-
export const TopNavMenuActionButton = ({
23-
run,
24-
htmlId,
25-
label,
26-
testId,
27-
iconType,
28-
disableButton,
29-
href,
30-
target,
31-
isLoading,
32-
color,
33-
splitButtonProps,
34-
isMobileMenu,
35-
closePopover,
36-
}: TopNavMenuActionButtonProps) => {
30+
export const TopNavMenuActionButton = (props: TopNavMenuActionButtonProps) => {
31+
const {
32+
run,
33+
htmlId,
34+
label,
35+
testId,
36+
iconType,
37+
disableButton,
38+
href,
39+
target,
40+
isLoading,
41+
isMobileMenu,
42+
tooltip,
43+
closePopover,
44+
} = props;
3745
const itemText = upperFirst(label);
38-
const { run: splitButtonRun, ...otherSplitButtonProps } = splitButtonProps ?? {};
3946

40-
const isDisabled = () => Boolean(isFunction(disableButton) ? disableButton() : disableButton);
47+
const splitButtonProps = 'splitButtonProps' in props ? props.splitButtonProps : undefined;
48+
const colorProp = 'color' in props ? props.color : undefined;
4149

4250
const handleClick = (e: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
43-
if (isDisabled()) return;
51+
if (isDisabled(disableButton)) return;
4452

4553
run(e.currentTarget);
4654

@@ -52,7 +60,7 @@ export const TopNavMenuActionButton = ({
5260
const handleSecondaryButtonClick = (event: MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
5361
if (splitButtonProps?.isSecondaryButtonDisabled) return;
5462

55-
splitButtonRun?.(event.currentTarget);
63+
splitButtonProps?.run?.(event.currentTarget);
5664

5765
if (isMobileMenu) {
5866
closePopover();
@@ -64,33 +72,36 @@ export const TopNavMenuActionButton = ({
6472
id: htmlId,
6573
'data-test-subj': testId,
6674
iconType,
67-
isDisabled: isDisabled(),
75+
isDisabled: isDisabled(disableButton),
6876
href,
6977
target: href ? target : undefined,
7078
isLoading,
71-
color,
7279
size: 's' as const,
7380
iconSize: 'm' as const,
74-
fill: false,
81+
fullWidth: isMobileMenu,
7582
};
7683

77-
if (splitButtonProps) {
78-
return (
79-
<SplitButton
80-
{...otherSplitButtonProps}
81-
{...commonProps}
82-
secondaryButtonFill={false}
83-
onSecondaryButtonClick={handleSecondaryButtonClick}
84-
secondaryButtonIcon="arrowDown"
85-
>
86-
{itemText}
87-
</SplitButton>
88-
);
89-
}
90-
91-
return (
92-
<EuiButton {...commonProps} iconSide="left">
84+
const button = splitButtonProps ? (
85+
<SplitButton
86+
{...(splitButtonProps as TopNavMenuSplitButtonProps)}
87+
{...commonProps}
88+
secondaryButtonFill={false}
89+
onSecondaryButtonClick={handleSecondaryButtonClick}
90+
color="text"
91+
>
92+
{itemText}
93+
</SplitButton>
94+
) : (
95+
<EuiButton {...commonProps} iconSide="left" color={colorProp}>
9396
{itemText}
9497
</EuiButton>
9598
);
99+
100+
const tooltipContent = getTooltip(tooltip);
101+
102+
if (tooltipContent) {
103+
return <EuiToolTip content={tooltipContent}>{button}</EuiToolTip>;
104+
}
105+
106+
return button;
96107
};

0 commit comments

Comments
 (0)