Skip to content

Commit 1ac5f17

Browse files
committed
Wire up the ConnectButton
1 parent dc01b32 commit 1ac5f17

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

packages/compass-components/src/components/leafygreen.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import Code, { Language } from '@leafygreen-ui/code';
1111
import ConfirmationModal from '@leafygreen-ui/confirmation-modal';
1212
import { default as LeafyGreenIcon } from '@leafygreen-ui/icon';
1313
import type { Size as LeafyGreenIconSize } from '@leafygreen-ui/icon';
14+
export type { GlyphName } from '@leafygreen-ui/icon';
1415
import {
1516
AtlasNavGraphic,
1617
MongoDBLogoMark,
1718
MongoDBLogo,
1819
} from '@leafygreen-ui/logo';
1920
import { Menu, MenuSeparator, MenuItem } from '@leafygreen-ui/menu';
21+
export type { MenuItemProps } from '@leafygreen-ui/menu';
2022
import { InfoSprinkle } from '@leafygreen-ui/info-sprinkle';
2123

2224
// If a leafygreen Menu (and therefore MenuItems) makes its way into a <form>,
@@ -30,6 +32,10 @@ import { InfoSprinkle } from '@leafygreen-ui/info-sprinkle';
3032
import Modal, { Footer as ModalFooter } from '@leafygreen-ui/modal';
3133
import MarketingModal from '@leafygreen-ui/marketing-modal';
3234
import { Pipeline, Stage } from '@leafygreen-ui/pipeline';
35+
export type {
36+
InferredPolymorphicProps,
37+
PolymorphicProps,
38+
} from '@leafygreen-ui/polymorphic';
3339
import Popover from '@leafygreen-ui/popover';
3440
import { RadioBox, RadioBoxGroup } from '@leafygreen-ui/radio-box-group';
3541
import { Radio, RadioGroup } from '@leafygreen-ui/radio-group';

packages/compass-connections-navigation/src/connect-button.tsx

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,37 @@ import {
44
Icon,
55
MenuItem,
66
SplitButton,
7+
type GlyphName,
78
type ItemComponentProps,
9+
type PolymorphicProps,
10+
type MenuItemProps,
811
} from '@mongodb-js/compass-components';
912

13+
import type { Actions } from './constants';
14+
1015
const menuItemStyles = css({
11-
width: 'max-content',
16+
minWidth: 'max-content',
1217
});
1318

19+
type ConnectMenuItemProps = {
20+
action: Actions;
21+
glyph: GlyphName;
22+
} & PolymorphicProps<'button', Omit<MenuItemProps, 'glyph'>>;
23+
24+
function ConnectMenuItem({ action, glyph, ...rest }: ConnectMenuItemProps) {
25+
return (
26+
<MenuItem
27+
data-action={action}
28+
className={menuItemStyles}
29+
glyph={<Icon glyph={glyph} />}
30+
{...rest}
31+
/>
32+
);
33+
}
34+
35+
// Hack to make SplitButton consider this as a MenuItem
36+
ConnectMenuItem.displayName = 'MenuItem';
37+
1438
type ConnectButtonProps = ItemComponentProps;
1539

1640
export function ConnectButton({
@@ -50,17 +74,24 @@ export function ConnectButton({
5074
darkMode={false}
5175
open={isOpen}
5276
setOpen={setOpen}
77+
triggerAriaLabel="see more connection options"
5378
menuItems={[
54-
<MenuItem key="connect-here" glyph={<Icon glyph="Connect" />}>
79+
<ConnectMenuItem
80+
key="connection-connect"
81+
action="connection-connect"
82+
glyph="Connect"
83+
onClick={onClick}
84+
>
5585
Connect Here
56-
</MenuItem>,
57-
<MenuItem
58-
key="connect-in-new-window"
59-
className={menuItemStyles}
60-
glyph={<Icon glyph="OpenNewTab" />}
86+
</ConnectMenuItem>,
87+
<ConnectMenuItem
88+
key="connection-connect-in-new-window"
89+
action="connection-connect-in-new-window"
90+
glyph="OpenNewTab"
91+
onClick={onClick}
6192
>
6293
Connect in a New Window
63-
</MenuItem>,
94+
</ConnectMenuItem>,
6495
]}
6596
>
6697
{label}

0 commit comments

Comments
 (0)