Skip to content

Commit

Permalink
refactor(projectcard): use menu component over buttondropdown (#1647)
Browse files Browse the repository at this point in the history
* refactor(projectcard): use menu component over buttondropdown

* refactor(courseplanneredit): address pr comments
  • Loading branch information
jinlee93 authored Jun 2, 2023
1 parent 0e505a9 commit 201c95f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
}
}

/**
* Destructive variant of the Menu item.
*
* For indicating deletion of the project.
*/
.menu-item--destructive {
color: var(--eds-theme-color-text-utility-error);
}

/*------------------------------------*\
# TABLE CARD
\*------------------------------------*/
Expand Down
92 changes: 34 additions & 58 deletions .storybook/pages/CoursePlannerEdit/CoursePlannerEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ import type { ReactNode } from 'react';
import ProjectCard from './ProjectCard';

import {
PageHeader,
Panel,
ButtonGroup,
Button,
Heading,
LayoutContainer,
Layout,
LayoutSection,
ButtonGroup,
Card,
CardBody,
CardFooter,
DataBar,
DragDrop,
DragDropContainerHeader,
Icon,
HorizontalStepper,
DataBar,
Toolbar,
ToolbarItem,
Grid,
GridItem,
Text,
DropdownMenuItem,
Card,
CardBody,
Heading,
HorizontalStepper,
Icon,
Layout,
LayoutContainer,
LayoutSection,
Menu,
NumberIcon,
TableHeader,
TableRow,
PageHeader,
Panel,
Table,
TableBody,
TableCell,
TableHeader,
TableHeaderCell,
CardFooter,
TableRow,
Text,
Toolbar,
ToolbarItem,
} from '../../../src';

import type { NewState } from '../../../src/components/DragDrop/DragDrop';
Expand Down Expand Up @@ -403,45 +403,23 @@ export const CoursePlannerEdit = () => {
const projectCardMenuItems = () => {
return (
<>
<DropdownMenuItem>
<Icon name="schedule" purpose="decorative" size="1.25rem" />
Move to other section
</DropdownMenuItem>
<DropdownMenuItem>
<Icon name="schedule" purpose="decorative" size="1.25rem" />
Move up
</DropdownMenuItem>
<DropdownMenuItem>
<Icon name="schedule" purpose="decorative" size="1.25rem" />
Move down
</DropdownMenuItem>
<DropdownMenuItem>
<Icon name="schedule" purpose="decorative" size="1.25rem" />
Move view details
</DropdownMenuItem>
<Menu.Item icon="schedule">Move to other section</Menu.Item>
<Menu.Item icon="schedule">Move up</Menu.Item>
<Menu.Item icon="schedule">Move down</Menu.Item>
<Menu.Item icon="schedule">Move view details</Menu.Item>
</>
);
};

const projectCardMenuItemsWithDelete = () => {
return (
<>
<DropdownMenuItem>
<Icon name="schedule" purpose="decorative" size="1.25rem" />
Move to other section
</DropdownMenuItem>
<DropdownMenuItem>
<Icon name="schedule" purpose="decorative" size="1.25rem" />
Move up
</DropdownMenuItem>
<DropdownMenuItem>
<Icon name="schedule" purpose="decorative" size="1.25rem" />
Move down
</DropdownMenuItem>
<DropdownMenuItem status="error">
<Icon name="delete" purpose="decorative" size="1.25rem" />
<Menu.Item icon="schedule">Move to other section</Menu.Item>
<Menu.Item icon="schedule">Move up</Menu.Item>
<Menu.Item icon="schedule">Move down</Menu.Item>
<Menu.Item className={styles['menu-item--destructive']} icon="delete">
Delete item
</DropdownMenuItem>
</Menu.Item>
</>
);
};
Expand Down Expand Up @@ -497,7 +475,7 @@ export const CoursePlannerEdit = () => {
children: (
<ProjectCard
behavior="draggable"
buttonDropdownItems={projectCardMenuItemsWithDelete()}
menuItems={projectCardMenuItemsWithDelete()}
meta="12 days"
metaIconName="event-note"
number={1}
Expand All @@ -511,7 +489,7 @@ export const CoursePlannerEdit = () => {
children: (
<ProjectCard
behavior="draggable"
buttonDropdownItems={projectCardMenuItems()}
menuItems={projectCardMenuItems()}
meta="12 days"
metaIconName="event-note"
number={indexState}
Expand All @@ -525,7 +503,7 @@ export const CoursePlannerEdit = () => {
children: (
<ProjectCard
behavior="draggable"
buttonDropdownItems={projectCardMenuItems()}
menuItems={projectCardMenuItems()}
meta="12 days"
metaIconName="event-note"
number={3}
Expand All @@ -539,7 +517,7 @@ export const CoursePlannerEdit = () => {
children: (
<ProjectCard
behavior="draggable"
buttonDropdownItems={projectCardMenuItems()}
menuItems={projectCardMenuItems()}
meta="12 days"
metaIconName="event-note"
number={4}
Expand All @@ -553,8 +531,7 @@ export const CoursePlannerEdit = () => {
children: (
<ProjectCard
behavior="draggable"
buttonDropdownItems={projectCardMenuItems()}
buttonDropdownPosition="top-left"
menuItems={projectCardMenuItems()}
meta="12 days"
metaIconName="event-note"
number={5}
Expand All @@ -568,8 +545,7 @@ export const CoursePlannerEdit = () => {
children: (
<ProjectCard
behavior="draggable"
buttonDropdownItems={projectCardMenuItems()}
buttonDropdownPosition="top-left"
menuItems={projectCardMenuItems()}
meta="12 days"
metaIconName="event-note"
number={6}
Expand Down
56 changes: 25 additions & 31 deletions .storybook/pages/CoursePlannerEdit/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
CardHeader,
Heading,
Icon,
Button,
Menu,
NumberIcon,
ButtonDropdown,
} from '../../../../src';
import type { HeadingElement } from '../../../../src/components/Heading';

Expand All @@ -23,19 +22,11 @@ export interface Props {
*/
behavior?: 'draggable';
/**
* Button dropdown items
* Menu items
*
* If not declared, the button dropdown does not render.
* If not declared, the menu does not render.
*/
buttonDropdownItems?: ReactNode;
/**
* Determines type of clickable
* - default renders a dropdown menu to the bottom left of the button
* - **top-left** renders a dropdown menu to the top left of the button
* - **top-right** renders a dropdown menu to the top right of the button
* - **bottom-right** renders a dropdown menu to the bottom right of the button
*/
buttonDropdownPosition?: 'top-left' | 'top-right' | 'bottom-right';
menuItems?: ReactNode;
/**
* CSS class names that can be appended to the component.
*/
Expand Down Expand Up @@ -82,8 +73,7 @@ export const ProjectCard = ({
metaIconName,
number,
headingAs = 'h3',
buttonDropdownItems,
buttonDropdownPosition,
menuItems,
numberAriaLabel,
isDragging,
...other
Expand Down Expand Up @@ -139,24 +129,28 @@ export const ProjectCard = ({
</div>
)}
</Card.Body>
{buttonDropdownItems && (
{menuItems && (
<Card.Footer className={styles['project-card__footer']}>
<ButtonDropdown
dropdownMenuTrigger={
<Button
aria-label="Open project dropdown"
className={styles['project-card__menu-button']}
size="sm"
status="neutral"
variant="icon"
>
<Icon name="dots-vertical" purpose="decorative" />
</Button>
}
position={buttonDropdownPosition}
<Menu
modifiers={[
// Brings the Menu closer to the dots-vertical icon trigger button
{
name: 'offset',
options: { offset: [0, 0] },
},
]}
placement="bottom-end"
>
{buttonDropdownItems}
</ButtonDropdown>
<Menu.PlainButton>
<Icon
name="dots-vertical"
purpose="informative"
size="1.5rem"
title="Open project dropdown"
/>
</Menu.PlainButton>
<Menu.Items>{menuItems}</Menu.Items>
</Menu>
</Card.Footer>
)}
</Card>
Expand Down

0 comments on commit 201c95f

Please sign in to comment.