diff --git a/packages/app-elements/src/ui/composite/Dropdown/Dropdown.tsx b/packages/app-elements/src/ui/composite/Dropdown/Dropdown.tsx index ffea9cc2..22eb66fd 100644 --- a/packages/app-elements/src/ui/composite/Dropdown/Dropdown.tsx +++ b/packages/app-elements/src/ui/composite/Dropdown/Dropdown.tsx @@ -108,10 +108,10 @@ export const Dropdown: React.FC = ({ // biome-ignore lint/a11y/useKeyWithClickEvents: Using click handler to close the dropdown
diff --git a/packages/app-elements/src/ui/composite/Dropdown/DropdownMenu.tsx b/packages/app-elements/src/ui/composite/Dropdown/DropdownMenu.tsx index 5c6e3084..2056d451 100644 --- a/packages/app-elements/src/ui/composite/Dropdown/DropdownMenu.tsx +++ b/packages/app-elements/src/ui/composite/Dropdown/DropdownMenu.tsx @@ -1,11 +1,14 @@ import cn from "classnames" -import { type FC, useEffect, useState } from "react" +import type { FC } from "react" import { DropdownDivider } from "./DropdownDivider" export interface DropdownMenuProps extends React.HTMLAttributes { /** Menu content */ children?: React.ReactNode - /** Set to `none` to hide the top arrow */ + /** + * Set to `none` to hide the top arrow + * @deprecated We decided to remove the arrow from the dropdown menu + */ arrow?: "none" /** Optional header for the dropdown menu */ menuHeader?: string @@ -28,18 +31,12 @@ export interface DropdownMenuProps extends React.HTMLAttributes { export const DropdownMenu: FC = ({ children, - arrow, menuHeader, menuPosition = "bottom-right", parentElementRef, menuWidth, ...rest }) => { - const [centerToWidth, setCenterToWidth] = useState() - useEffect(() => { - setCenterToWidth(parentElementRef?.current?.clientWidth) - }, [parentElementRef]) - return (
= ({ "flex-col-reverse items-start": menuPosition === "top-left", })} > - {arrow === "none" ? null : ( - - )}
= ({ } DropdownMenu.displayName = "DropdownMenu" - -const Arrow: FC<{ - menuPosition: DropdownMenuProps["menuPosition"] - centerToWidth?: number -}> = ({ menuPosition = "bottom-right", centerToWidth }) => { - const arrowHeight = 5 - const arrowWidth = 12 - - const centeringOffset = calculateArrowCenteringOffset({ - arrowWidth, - centerToWidth, - }) - - const alignProp = menuPosition.includes("right") ? "right" : "left" - const arrowDirection = - menuPosition === "bottom-right" || menuPosition === "bottom-left" - ? "top" - : "bottom" - const cssForPointingDirection = - arrowDirection === "top" - ? { - borderBottomWidth: arrowHeight, - borderTopColor: "transparent", - } - : { - borderTopWidth: arrowHeight, - borderBottomColor: "transparent", - } - - return ( - - ) -} - -// Calculate the offset for centering the arrow on the dropdown button when this does not excide 50px -// This means that for smaller buttons (up to 50px) the arrow will be centered on the button -// otherwise it will 10px from the left or right as design system -function calculateArrowCenteringOffset({ - arrowWidth, - centerToWidth, -}: { - arrowWidth: number - centerToWidth?: number -}): number { - if (centerToWidth == null || centerToWidth > 50) { - return 10 // default offset calculated on a base of 32px button width - } - - const centeringOffset = centerToWidth / 2 - arrowWidth / 2 - return centeringOffset -} diff --git a/packages/app-elements/src/ui/composite/Dropdown/__snapshots__/Dropdown.test.tsx.snap b/packages/app-elements/src/ui/composite/Dropdown/__snapshots__/Dropdown.test.tsx.snap index f04595c6..20bfa787 100644 --- a/packages/app-elements/src/ui/composite/Dropdown/__snapshots__/Dropdown.test.tsx.snap +++ b/packages/app-elements/src/ui/composite/Dropdown/__snapshots__/Dropdown.test.tsx.snap @@ -25,15 +25,11 @@ exports[`Dropdown > Should be rendering bottom-left 1`] = `
-
@@ -70,15 +66,11 @@ exports[`Dropdown > Should be rendering top-left 1`] = `
-
@@ -115,15 +107,11 @@ exports[`Dropdown > Should be rendering top-right 1`] = `
-
@@ -160,15 +148,11 @@ exports[`Dropdown > Should be rendering with default bottom-right position 1`] =
-