From 63e27f8b4bd31f14a7bf92854df6142c1874728b Mon Sep 17 00:00:00 2001 From: Sylvain Marroufin Date: Wed, 22 Feb 2023 12:31:08 +0100 Subject: [PATCH] chore(docs): add `ContextMenu` component page (#128) --- docs/app.vue | 2 +- docs/nuxt.config.ts | 7 ++++ docs/pages/components/[component].vue | 51 ++++++++++++++++++++++++++- docs/pages/examples.vue | 6 ++-- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/docs/app.vue b/docs/app.vue index a0bd8cb9..7a9ac6d3 100644 --- a/docs/app.vue +++ b/docs/app.vue @@ -84,7 +84,7 @@ const sections = [ { label: 'Forms', links: [{ label: 'Checkbox', to: '/components/Checkbox' }, { label: 'Input', to: '/components/Input' }, { label: 'FormGroup', to: '/components/FormGroup' }, { label: 'Radio', to: '/components/Radio' }, { label: 'Select', to: '/components/Select' }, { label: 'SelectCustom', to: '/components/SelectCustom' }, { label: 'Textarea', to: '/components/Textarea' }, { label: 'Toggle', to: '/components/Toggle' }] }, { label: 'Layout', links: [{ label: 'Card', to: '/components/Card' }, { label: 'Container', to: '/components/Container' }] }, { label: 'Navigation', links: [{ label: 'Pills', to: '/components/Pills' }, { label: 'Tabs', to: '/components/Tabs' }, { label: 'VerticalNavigation', to: '/components/VerticalNavigation' }, { label: 'CommandPalette', to: '/components/CommandPalette' }] }, - { label: 'Overlays', links: [{ label: 'Modal', to: '/components/Modal' }, { label: 'Notification', to: '/components/Notification' }, { label: 'Popover', to: '/components/Popover' }, { label: 'Slideover', to: '/components/Slideover' }, { label: 'Tooltip', to: '/components/Tooltip' }] } + { label: 'Overlays', links: [{ label: 'ContextMenu', to: '/components/ContextMenu' }, { label: 'Modal', to: '/components/Modal' }, { label: 'Notification', to: '/components/Notification' }, { label: 'Popover', to: '/components/Popover' }, { label: 'Slideover', to: '/components/Slideover' }, { label: 'Tooltip', to: '/components/Tooltip' }] } ] diff --git a/docs/nuxt.config.ts b/docs/nuxt.config.ts index 96eaa316..dc9afa8a 100644 --- a/docs/nuxt.config.ts +++ b/docs/nuxt.config.ts @@ -3,6 +3,13 @@ import nuxtUI from '../src/module' // https://v3.nuxtjs.org/docs/directory-structure/nuxt.config export default defineNuxtConfig({ + app: { + head: { + htmlAttrs: { + lang: 'en' + } + } + }, modules: [ // @ts-ignore nuxtUI diff --git a/docs/pages/components/[component].vue b/docs/pages/components/[component].vue index 79642e92..21dcc271 100644 --- a/docs/pages/components/[component].vue +++ b/docs/pages/components/[component].vue @@ -56,7 +56,6 @@ v-if="prop.type === 'Boolean'" v-model="prop.value" :name="prop.key" - :label="prop.key" /> ({}) }) + +onMounted(() => { + document.addEventListener('mousemove', ({ clientX, clientY }) => { + x.value = clientX + y.value = clientY + }) +}) + +function openContextMenu () { + const top = unref(y) + const left = unref(x) + + virtualElement.value.getBoundingClientRect = () => ({ + width: 0, + height: 0, + top, + left + }) + isContextMenuOpen.value = true +} + const defaultProps = { Button: { label: 'Button text' @@ -261,6 +285,31 @@ const defaultProps = { title: 'Notification title', callback: 'console.log(\'Timer expired\')' }, + ContextMenu: { + modelValue: isContextMenuOpen, + 'onUpdate:modelValue': (v) => { isContextMenuOpen.value = v }, + virtualElement, + component: { + name: 'Card', + props: { + variant: 'secondary', + label: 'Open context menu', + onClick: () => { isContextMenuOpen.value = false }, + onContextmenu: (e) => { + e?.preventDefault() + openContextMenu() + }, + class: 'relative w-[300px] h-[100px]' + } + }, + slots: { + default: { + tag: 'div', + html: 'Context menu content', + class: 'rounded border u-border-gray-200 p-2' + } + } + }, Modal: { modelValue: modal, 'onUpdate:modelValue': (v) => { modal.value = v }, diff --git a/docs/pages/examples.vue b/docs/pages/examples.vue index 0c7a4a47..5d71e641 100644 --- a/docs/pages/examples.vue +++ b/docs/pages/examples.vue @@ -133,7 +133,7 @@ Context menu: - + Menu @@ -256,7 +256,7 @@ const { $toast } = useNuxtApp() const x = ref(0) const y = ref(0) const isContextMenuOpen = ref(false) -const contextMenuRef = ref(null) +const virtualElement = ref({ getBoundingClientRect: () => ({}) }) const commandPaletteGroups = computed(() => ([{ key: 'people', @@ -277,8 +277,6 @@ onMounted(() => { }) }) -const virtualElement = ref({ getBoundingClientRect: () => ({}) }) - function openContextMenu () { const top = unref(y) const left = unref(x)