Skip to content
Open
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
2 changes: 1 addition & 1 deletion docs/components/Menu/Web.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const Composable = () => {
<Menu.Item
key={item.label}
onClick={item.onClick}
destructive={item.destructive}
variation={item.destructive ? "destructive" : undefined}
textValue={item.label}
>
<Menu.ItemLabel>{item.label}</Menu.ItemLabel>
Expand Down
29 changes: 18 additions & 11 deletions packages/components/src/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const composeOverlayVariation = {
visible: { opacity: 1 },
};

const variation = {
const animationVariation = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"variation" was getting in the way of the new prop name

this version is just internal anyway for the framer config

overlayStartStop: { opacity: 0 },
startOrStop: (placement: string | undefined) => {
let y = Y_TRANSLATION_DESKTOP;
Expand Down Expand Up @@ -276,7 +276,7 @@ export function MenuLegacy({
<motion.div
className={styles.overlay}
onClick={toggle()}
variants={variation}
variants={animationVariation}
initial="overlayStartStop"
animate="done"
exit="overlayStartStop"
Expand Down Expand Up @@ -305,7 +305,7 @@ export function MenuLegacy({
aria-labelledby={buttonID}
id={menuID}
onClick={hide}
variants={variation}
variants={animationVariation}
initial="startOrStop"
animate="done"
exit="startOrStop"
Expand Down Expand Up @@ -702,7 +702,7 @@ const MenuItemComposable = React.forwardRef<
rel={rel}
onClick={onClick as ((e: React.MouseEvent) => void) | undefined}
>
<MenuItemContext.Provider value={{ destructive: props.destructive }}>
<MenuItemContext.Provider value={{ variation: props.variation }}>
{props.children}
</MenuItemContext.Provider>
</AriaMenuItem>
Expand All @@ -720,40 +720,47 @@ const MenuItemComposable = React.forwardRef<
props.onClick?.();
}}
>
<MenuItemContext.Provider value={{ destructive: props.destructive }}>
<MenuItemContext.Provider value={{ variation: props.variation }}>
{props.children}
</MenuItemContext.Provider>
</AriaMenuItem>
);
});

const MenuItemContext = createContext<{ destructive?: boolean } | null>(null);
const MenuItemContext = createContext<{
variation?: MenuItemComposableProps["variation"];
} | null>(null);

function useMenuItemContext(): { destructive?: boolean } {
function useMenuItemContext(): {
variation?: MenuItemComposableProps["variation"];
} {
const ctx = useContext(MenuItemContext);

return ctx ?? {};
}

function MenuItemIconComposable(props: MenuItemIconComposableProps) {
const { destructive } = useMenuItemContext();
const { variation } = useMenuItemContext();

return (
<div data-menu-slot="icon">
<Icon {...props} color={destructive ? "destructive" : props.color} />
<Icon
{...props}
color={variation === "destructive" ? "destructive" : props.color}
/>
</div>
);
}

function MenuItemLabelComposable(props: { readonly children: string }) {
const { destructive } = useMenuItemContext();
const { variation } = useMenuItemContext();

return (
<div data-menu-slot="label">
<Typography
element="span"
fontWeight="semiBold"
textColor={destructive ? "destructive" : "text"}
textColor={variation === "destructive" ? "destructive" : "text"}
>
{props.children}
</Typography>
Expand Down
17 changes: 13 additions & 4 deletions packages/components/src/Menu/Menu.types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import type { IconColorNames, IconNames } from "@jobber/design";
import type React from "react";
import type { CSSProperties, ReactElement, ReactNode } from "react";
import type {
CSSProperties,
ComponentProps,
ReactElement,
ReactNode,
} from "react";
import type { Pressable as AriaPressable } from "react-aria-components";
import type { IconProps } from "../Icon";

type PressableChild = ComponentProps<typeof AriaPressable>["children"];
export interface MenuLegacyProps extends MenuBaseProps {
/**
* Custom menu activator. If this is not provided a default [… More] will be used.
Expand Down Expand Up @@ -151,11 +158,13 @@ export interface MenuHeaderComposableProps extends UnsafeProps {
readonly children: ReactNode;
}

type MenuItemVariants = "destructive";

export interface MenuItemComposableProps extends UnsafeProps {
/**
* Apply destructive styling to the item label and icon.
* Visual style variations for the MenuItem default content.
*/
readonly destructive?: boolean;
readonly variation?: MenuItemVariants;

/**
* Item content.
Expand Down Expand Up @@ -207,7 +216,7 @@ export interface MenuTriggerComposableProps {
* If you want to access the open event, use the onOpenChange on the Menu component.
* If it does not have an interactive role, or a focus style it will have issues.
*/
readonly children: ReactNode;
readonly children: PressableChild;
}

export interface MenuSeparatorComposableProps extends UnsafeProps {}
Expand Down