Skip to content

Commit

Permalink
Wire up the ConnectButton
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Dec 19, 2024
1 parent 0a81806 commit f8ad9ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/compass-components/src/components/leafygreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import Code, { Language } from '@leafygreen-ui/code';
import ConfirmationModal from '@leafygreen-ui/confirmation-modal';
import { default as LeafyGreenIcon } from '@leafygreen-ui/icon';
import type { Size as LeafyGreenIconSize } from '@leafygreen-ui/icon';
export type { GlyphName } from '@leafygreen-ui/icon';
import {
AtlasNavGraphic,
MongoDBLogoMark,
MongoDBLogo,
} from '@leafygreen-ui/logo';
import { Menu, MenuSeparator, MenuItem } from '@leafygreen-ui/menu';
export type { MenuItemProps } from '@leafygreen-ui/menu';
import { InfoSprinkle } from '@leafygreen-ui/info-sprinkle';

// If a leafygreen Menu (and therefore MenuItems) makes its way into a <form>,
Expand All @@ -30,6 +32,10 @@ import { InfoSprinkle } from '@leafygreen-ui/info-sprinkle';
import Modal, { Footer as ModalFooter } from '@leafygreen-ui/modal';
import MarketingModal from '@leafygreen-ui/marketing-modal';
import { Pipeline, Stage } from '@leafygreen-ui/pipeline';
export type {
InferredPolymorphicProps,
PolymorphicProps,
} from '@leafygreen-ui/polymorphic';
import Popover from '@leafygreen-ui/popover';
import { RadioBox, RadioBoxGroup } from '@leafygreen-ui/radio-box-group';
import { Radio, RadioGroup } from '@leafygreen-ui/radio-group';
Expand Down
47 changes: 39 additions & 8 deletions packages/compass-connections-navigation/src/connect-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,37 @@ import {
Icon,
MenuItem,
SplitButton,
type GlyphName,
type ItemComponentProps,
type PolymorphicProps,
type MenuItemProps,
} from '@mongodb-js/compass-components';

import type { Actions } from './constants';

const menuItemStyles = css({
width: 'max-content',
minWidth: 'max-content',
});

type ConnectMenuItemProps = {
action: Actions;
glyph: GlyphName;
} & PolymorphicProps<'button', Omit<MenuItemProps, 'glyph'>>;

function ConnectMenuItem({ action, glyph, ...rest }: ConnectMenuItemProps) {
return (
<MenuItem
data-action={action}
className={menuItemStyles}
glyph={<Icon glyph={glyph} />}
{...rest}
/>
);
}

// Hack to make SplitButton consider this as a MenuItem
ConnectMenuItem.displayName = 'MenuItem';

type ConnectButtonProps = ItemComponentProps;

export function ConnectButton({
Expand Down Expand Up @@ -50,17 +74,24 @@ export function ConnectButton({
darkMode={false}
open={isOpen}
setOpen={setOpen}
triggerAriaLabel="see more connection options"
menuItems={[
<MenuItem key="connect-here" glyph={<Icon glyph="Connect" />}>
<ConnectMenuItem
key="connection-connect"
action="connection-connect"
glyph="Connect"
onClick={onClick}
>
Connect Here
</MenuItem>,
<MenuItem
key="connect-in-new-window"
className={menuItemStyles}
glyph={<Icon glyph="OpenNewTab" />}
</ConnectMenuItem>,
<ConnectMenuItem
key="connection-connect-in-new-window"
action="connection-connect-in-new-window"
glyph="OpenNewTab"
onClick={onClick}
>
Connect in a New Window
</MenuItem>,
</ConnectMenuItem>,
]}
>
{label}
Expand Down

0 comments on commit f8ad9ac

Please sign in to comment.