From 7296773ae078fad2e9bc06f2db81e8613fc2895c Mon Sep 17 00:00:00 2001 From: Alex Golovanov Date: Wed, 19 Feb 2025 11:30:53 +0300 Subject: [PATCH 1/3] feat: added an ads entity context menu template component --- .../EntityContextMenu.stories.tsx | 34 +++++++++++++ .../EntityContextMenu.styles.ts | 12 +++++ .../EntityContextMenu/EntityContextMenu.tsx | 49 +++++++++++++++++++ .../Templates/EntityContextMenu/constants.ts | 4 ++ .../src/Templates/EntityContextMenu/index.ts | 1 + .../design-system/ads/src/Templates/index.ts | 1 + 6 files changed, 101 insertions(+) create mode 100644 app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.stories.tsx create mode 100644 app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.styles.ts create mode 100644 app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx create mode 100644 app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts create mode 100644 app/client/packages/design-system/ads/src/Templates/EntityContextMenu/index.ts diff --git a/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.stories.tsx b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.stories.tsx new file mode 100644 index 000000000000..16cf311d8ec4 --- /dev/null +++ b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.stories.tsx @@ -0,0 +1,34 @@ +/* eslint-disable no-console */ +import React from "react"; +import type { Meta, StoryObj } from "@storybook/react"; + +import { MenuItem } from "../../Menu"; +import { EntityContextMenu } from "./EntityContextMenu"; + +const meta: Meta = { + title: "ADS/Templates/Entity Context Menu", + component: EntityContextMenu, +}; + +export default meta; + +type Story = StoryObj; + +export const Basic: Story = { + args: { + tooltipContent: "More actions", + children: ( + <> + + Rename + + + Copy + + + Delete + + + ), + }, +}; diff --git a/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.styles.ts b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.styles.ts new file mode 100644 index 000000000000..0faae06bd5dc --- /dev/null +++ b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.styles.ts @@ -0,0 +1,12 @@ +import styled from "styled-components"; + +import { MenuContent as ADSMenuContent } from "../../Menu"; + +export const MenuContent = styled(ADSMenuContent)` + width: 220px; + max-height: unset; +`; + +export const ButtonContainer = styled.div` + position: relative; +`; diff --git a/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx new file mode 100644 index 000000000000..18a0ba2a6777 --- /dev/null +++ b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx @@ -0,0 +1,49 @@ +import React from "react"; +import { useToggle } from "usehooks-ts"; + +import { Button } from "../../Button"; +import { Menu, MenuTrigger } from "../../Menu"; +import { Tooltip } from "../../Tooltip"; + +import { EntityClassNames } from "./constants"; +import * as Styled from "./EntityContextMenu.styles"; + +interface Props { + children?: React.ReactNode[] | React.ReactNode; + tooltipContent: React.ReactNode; +} + +export const EntityContextMenu = (props: Props) => { + const { children, tooltipContent } = props; + const [isMenuOpen, toggleMenuOpen] = useToggle(); + + return ( + + + + + + ); +}; diff --git a/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts new file mode 100644 index 000000000000..5cacb913987f --- /dev/null +++ b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts @@ -0,0 +1,4 @@ +export enum EntityClassNames { + CONTEXT_MENU = "entity-context-menu", + CONTEXT_MENU_CONTENT = "entity-context-menu-content", +} diff --git a/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/index.ts b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/index.ts new file mode 100644 index 000000000000..0c9f3e2fc2d1 --- /dev/null +++ b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/index.ts @@ -0,0 +1 @@ +export { EntityContextMenu } from "./EntityContextMenu"; diff --git a/app/client/packages/design-system/ads/src/Templates/index.ts b/app/client/packages/design-system/ads/src/Templates/index.ts index 119bfd669a2f..00debb2e7685 100644 --- a/app/client/packages/design-system/ads/src/Templates/index.ts +++ b/app/client/packages/design-system/ads/src/Templates/index.ts @@ -4,3 +4,4 @@ export * from "./Sidebar"; export * from "./EditableEntityName"; export * from "./EditableDismissibleTab"; export * from "./EntityTabsHeader"; +export * from "./EntityContextMenu"; From 82b36adebc9ff846c5ce016ed07394fb442df176 Mon Sep 17 00:00:00 2001 From: Alex Golovanov Date: Wed, 19 Feb 2025 18:38:39 +0300 Subject: [PATCH 2/3] perf: add data-testid & default tooltip content --- .../EntityContextMenu/EntityContextMenu.tsx | 19 +++++++++++++++---- .../Templates/EntityContextMenu/constants.ts | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx index 18a0ba2a6777..70cb3e8a9354 100644 --- a/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx +++ b/app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx @@ -5,16 +5,27 @@ import { Button } from "../../Button"; import { Menu, MenuTrigger } from "../../Menu"; import { Tooltip } from "../../Tooltip"; -import { EntityClassNames } from "./constants"; +import { + EntityClassNames, + DEFAULT_DATA_TEST_ID, + DEFAULT_TOOLTIP_CONTENT, +} from "./constants"; + import * as Styled from "./EntityContextMenu.styles"; interface Props { + dataTestid?: string; children?: React.ReactNode[] | React.ReactNode; - tooltipContent: React.ReactNode; + tooltipContent?: React.ReactNode; } export const EntityContextMenu = (props: Props) => { - const { children, tooltipContent } = props; + const { + children, + dataTestid = DEFAULT_DATA_TEST_ID, + tooltipContent = DEFAULT_TOOLTIP_CONTENT, + } = props; + const [isMenuOpen, toggleMenuOpen] = useToggle(); return ( @@ -29,7 +40,7 @@ export const EntityContextMenu = (props: Props) => { >