Skip to content

Commit 8d75161

Browse files
committed
Wire up the ConnectButton
1 parent 2d554b5 commit 8d75161

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-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: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,36 @@ 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
import type { Actions } from './constants';
1013

1114
const menuItemStyles = css({
12-
width: 'max-content',
15+
minWidth: 'max-content',
1316
});
1417

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

1739
export function ConnectButton({
@@ -51,17 +73,24 @@ export function ConnectButton({
5173
darkMode={false}
5274
open={isOpen}
5375
setOpen={setOpen}
76+
triggerAriaLabel="see more connection options"
5477
menuItems={[
55-
<MenuItem key="connect-here" glyph={<Icon glyph="Connect" />}>
78+
<ConnectMenuItem
79+
key="connection-connect"
80+
action="connection-connect"
81+
glyph="Connect"
82+
onClick={onClick}
83+
>
5684
Connect Here
57-
</MenuItem>,
58-
<MenuItem
59-
key="connect-in-new-window"
60-
className={menuItemStyles}
61-
glyph={<Icon glyph="OpenNewTab" />}
85+
</ConnectMenuItem>,
86+
<ConnectMenuItem
87+
key="connection-connect-in-new-window"
88+
action="connection-connect-in-new-window"
89+
glyph="OpenNewTab"
90+
onClick={onClick}
6291
>
6392
Connect in a New Window
64-
</MenuItem>,
93+
</ConnectMenuItem>,
6594
]}
6695
>
6796
{label}

0 commit comments

Comments
 (0)