Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/@next/Menu/Menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ const options = [
active: false,
disabled: false,
id: '2',
label: 'Completed',
value: 'Completed',
label: 'Tooltip Added',
value: 'Tooltip Added',
tooltip: {
content: 'Sample Tooltip',
preferredPosition: 'right-middle',
},
},
{
active: false,
Expand Down Expand Up @@ -84,8 +88,12 @@ Basic.parameters = {
active: false,
disabled: false,
id: '2',
label: 'Completed',
value: 'Completed',
label: 'Tooltip Added',
value: 'Tooltip Added',
tooltip: {
content: "Sample Tooltip",
preferredPosition: 'right-middle'
}
},
{
active: false,
Expand Down Expand Up @@ -169,8 +177,12 @@ AllowMultiple.parameters = {
active: false,
disabled: false,
id: '2',
label: 'Completed',
value: 'Completed',
label: 'Tooltip Added',
value: 'Tooltip Added',
tooltip: {
content: "Sample Tooltip",
preferredPosition: 'right-middle'
}
},
{
active: false,
Expand Down
52 changes: 44 additions & 8 deletions src/@next/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ import React from 'react';
import nextId from 'react-id-generator';
import { Typography } from '../Typography';
import { Neutral } from '../utilities/colors';
import { StyledMenu, StyledSections, TitleContainer } from './MenuStyle';
import {
StyledMenu,
StyledSections,
StyledTooltip,
TitleContainer,
TitleNodeContainer,
} from './MenuStyle';
import { MenuOptionLabel } from './components/MenuOptionLabel';
import { MenuOption } from './components/MenuOption';
import { MenuOptionCheckbox } from './components/MenuOptionCheckbox';
import { TooltipPosition } from '../Tooltip/Tooltip';

export interface Option {
disabled?: boolean;
id?: string;
label: string | React.ReactNode;
sublabel?: React.ReactNode;
value: string;
tooltip?: {
content: React.ReactNode;
preferredPosition?: TooltipPosition;
};
}

export interface Section {
title?: string;
title?: string | React.ReactNode;
options: Option[];
}
export interface MenuProps {
Expand All @@ -25,7 +36,7 @@ export interface MenuProps {
options?: Option[];
/** Selected value based on Option.value */
selectedValues?: string[];
title?: string;
title?: string | React.ReactNode;
allowMultiple?: boolean;
sections?: Section[];
}
Expand All @@ -42,7 +53,10 @@ export const Menu = ({
const randomId = nextId('glints-menu');
const menuId = id ? id : randomId;

const renderTitle = ({ title }: { title: string }) => {
const renderTitle = ({ title }: { title: string | React.ReactNode }) => {
if (React.isValidElement(title)) {
return <TitleNodeContainer>{title}</TitleNodeContainer>;
}
return (
<TitleContainer>
<Typography variant="subtitle2" as="span" color={Neutral.B40}>
Expand All @@ -56,12 +70,12 @@ export const Menu = ({
return (
<StyledMenu>
{options?.map((option: Option) => {
const { value, label, sublabel, disabled, id } = option;
const { value, label, sublabel, disabled, id, tooltip } = option;
const randomId = nextId('glints-menu-option');
const menuOptionId = id ? id : randomId;
const isSelected = selectedValues?.includes(value);

return (
const menuOption = (
<MenuOption
key={menuOptionId}
value={value}
Expand All @@ -73,6 +87,17 @@ export const Menu = ({
<MenuOptionLabel label={label} sublabel={sublabel} />
</MenuOption>
);

return tooltip ? (
<StyledTooltip
content={tooltip.content}
preferredPosition={tooltip.preferredPosition ?? 'left-middle'}
>
{menuOption}
</StyledTooltip>
) : (
menuOption
);
})}
</StyledMenu>
);
Expand All @@ -82,12 +107,12 @@ export const Menu = ({
return (
<StyledMenu>
{options?.map((option: Option) => {
const { value, label, disabled, id } = option;
const { value, label, disabled, id, tooltip } = option;
const randomId = nextId('glints-menu-option');
const menuOptionId = id ? id : randomId;
const isSelected = selectedValues?.includes(value);

return (
const menuOption = (
<MenuOption
key={menuOptionId}
value={value}
Expand All @@ -103,6 +128,17 @@ export const Menu = ({
/>
</MenuOption>
);

return tooltip ? (
<StyledTooltip
content={tooltip.content}
preferredPosition={tooltip.preferredPosition ?? 'left-middle'}
>
{menuOption}
</StyledTooltip>
) : (
menuOption
);
})}
</StyledMenu>
);
Expand Down
12 changes: 12 additions & 0 deletions src/@next/Menu/MenuStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Blue, Neutral } from '../utilities/colors';
import { space16, space4, space8 } from '../utilities/spacing';

import { MenuProps } from './Menu';
import { Tooltip } from '../Tooltip/Tooltip';

export const StyledMenu = styled.ul<MenuProps>`
list-style: none;
Expand Down Expand Up @@ -73,6 +74,13 @@ export const StyledMenu = styled.ul<MenuProps>`
}
`;

export const StyledTooltip = styled(Tooltip).attrs({
zIndex: 500,
})`
display: block;
width: 100%;
`;

export const TitleContainer = styled.div`
margin: ${space8} 0 ${space4};
padding: ${space8} ${space16};
Expand All @@ -82,6 +90,10 @@ export const TitleContainer = styled.div`
}
`;

export const TitleNodeContainer = styled.div`
margin: ${space8} 0 ${space4};
`;

export const ListContainer = styled.div`
padding: 0 ${space8};
`;
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/menu/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MenuPage } from './menuPage';

test('Menu - basic without title', async ({ page }) => {
const menuPage = new MenuPage(page);
await menuPage.goto('args=title:');
await menuPage.goto('args=title:!null');
await expect(menuPage.canvas).toHaveScreenshot(
'menu-basic-without-title.png'
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading