Skip to content

Commit

Permalink
fix(menu): vue sfc and context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Aug 23, 2023
1 parent 0f7f0d1 commit 244d9b5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
33 changes: 33 additions & 0 deletions examples/nuxt-ts/pages/context-menu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script setup lang="ts">
import * as menu from "@zag-js/menu"
import { normalizeProps, useMachine } from "@zag-js/vue"
const [state, send] = useMachine(
menu.machine({
id: "v1",
onSelect: console.log,
}),
)
const api = computed(() => menu.connect(state.value, send, normalizeProps))
</script>

<template>
<main className="context-menu">
<div v-bind="api.contextTriggerProps">Right Click here</div>
<Teleport to="body">
<div v-bind="api.positionerProps">
<ul v-bind="api.contentProps">
<li v-bind="api.getItemProps({ id: 'edit' })">Edit</li>
<li v-bind="api.getItemProps({ id: 'duplicate' })">Duplicate</li>
<li v-bind="api.getItemProps({ id: 'delete' })">Delete</li>
<li v-bind="api.getItemProps({ id: 'export' })">Export...</li>
</ul>
</div>
</Teleport>
</main>

<Toolbar>
<StateVisualizer :state="state" />
</Toolbar>
</template>
1 change: 1 addition & 0 deletions packages/machines/menu/src/menu.connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
const popperStyles = getPlacementStyles({
...state.context.positioning,
placement: state.context.currentPlacement,
anchorPoint: state.context.anchorPoint,
})

const api = {
Expand Down
11 changes: 9 additions & 2 deletions packages/utilities/popper/src/get-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ const ARROW_FLOATING_STYLE = {
right: "rotate(315deg)",
} as const

export function getPlacementStyles(options: PositioningOptions = {}) {
const { placement = "bottom", sameWidth, fitViewport, strategy = "absolute" } = options
type PlacementStyleOptions = PositioningOptions & {
anchorPoint?: { x: number; y: number } | null
}

export function getPlacementStyles(options: PlacementStyleOptions = {}) {
const { placement = "bottom", sameWidth, fitViewport, strategy = "absolute", anchorPoint } = options
const point = anchorPoint || { x: 0, y: 0 }

return {
arrow: {
Expand Down Expand Up @@ -44,6 +49,8 @@ export function getPlacementStyles(options: PositioningOptions = {}) {
maxHeight: fitViewport ? "var(--available-height)" : undefined,
top: "0px",
left: "0px",
"--x": `${point.x}px`,
"--y": `${point.y}px`,
transform: `translate3d(var(--x), var(--y), 0)`,
} as const,
}
Expand Down

3 comments on commit 244d9b5

@vercel
Copy link

@vercel vercel bot commented on 244d9b5 Aug 23, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

zag-nextjs – ./examples/next-ts

zag-nextjs-chakra-ui.vercel.app
zag-two.vercel.app
zag-nextjs-git-main-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 244d9b5 Aug 23, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

zag-vue – ./examples/vue-ts

zag-vue-chakra-ui.vercel.app
zag-vue-git-main-chakra-ui.vercel.app
zag-vue.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 244d9b5 Aug 23, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

zag-solid – ./examples/solid-ts

zag-solid.vercel.app
zag-solid-chakra-ui.vercel.app
zag-solid-git-main-chakra-ui.vercel.app

Please sign in to comment.