Skip to content

Commit

Permalink
feat(menubar): simplify link trigger syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed May 8, 2024
1 parent 025db21 commit 50026fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/menubar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import {
type MenuSubTriggerOptions as MenubarSubTriggerOptions,
type MenuSubTriggerProps as MenubarSubTriggerProps,
type MenuSubTriggerRenderProps as MenubarSubTriggerRenderProps,
MenuTrigger as Trigger,
type MenuTriggerCommonProps as MenubarTriggerCommonProps,
type MenuTriggerOptions as MenubarTriggerOptions,
type MenuTriggerProps as MenubarTriggerProps,
Expand Down Expand Up @@ -101,6 +100,7 @@ import {
type MenubarRootProps,
type MenubarRootRenderProps,
} from "./menubar-root";
import { MenubarTrigger as Trigger } from "./menubar-trigger";

export type {
MenubarRootOptions,
Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/menubar/menubar-trigger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ValidComponent } from "solid-js";

import { MenuTrigger, MenuTriggerProps } from "../menu";
import { useOptionalMenuContext } from "../menu/menu-context";
import { PolymorphicProps } from "../polymorphic";
import { MenubarMenu } from "./menubar-menu";

/**
* The button that toggles the menubar menu or a menubar link.
*/
export function MenubarTrigger<T extends ValidComponent = "button">(
props: PolymorphicProps<T, MenuTriggerProps>,
) {
const context = useOptionalMenuContext();

if (context === undefined && Object.hasOwn(props, "href")) {
return (
<MenubarMenu>
<MenuTrigger {...props} />
</MenubarMenu>
);
}

return MenuTrigger(props);
}

0 comments on commit 50026fc

Please sign in to comment.