PXD
v0.2.1-dev

Command Menu

Launch a set of actions as a full-screen overlay.

Default

<script setup>
import { ref } from 'vue'

const showCommandMenu = ref(false)

const options = [
  {
    type: 'group',
    label: 'Suggestions',
    options: [{ label: 'Figma Import', value: 'figma-import' }],
  },
  {
    type: 'group',
    label: 'Commands',
    options: [
      { label: 'Import Extension', value: 'import-extension' },
      { label: 'Manage Extensions', value: 'manage-extensions' },
    ],
  },
  {
    type: 'group',
    label: 'Collaboration',
    options: [
      { label: 'Flags Explorer', value: 'flags-explorer' },
      { label: 'File Explorer', value: 'file-explorer' },
      { label: 'Image Explorer', value: 'image-explorer' },
    ],
  },
]
</script>

<template>
  <PButton variant="primary" @click="showCommandMenu = true"> Open Command Menu </PButton>

  <PCommandMenu v-model="showCommandMenu" :options="options" placeholder="What do you need?">
    <template #item="{ item }">
      {{ item.label }}
    </template>
  </PCommandMenu>
</template>

remote-filter hands every query to it 200ms after the last keystroke instead of going through the local filter-method, and the options it returns replace options while the query is active. Only the latest answer counts, and the list shows its loading mask until one lands. Clearing the input restores options.

<script setup>
import { ref } from 'vue'

const showCommandMenu = ref(false)

const options = [
  { label: 'Import Extension', value: 'import-extension' },
  { label: 'Manage Extensions', value: 'manage-extensions' },
  { label: 'Flags Explorer', value: 'flags-explorer' },
]

// A real one would ask a server; the shape it hands back is the same either way.
function search(query) {
  return new Promise((resolve) => {
    setTimeout(() => resolve(options.filter((option) => option.label.includes(query))), 400)
  })
}
</script>

<template>
  <PButton variant="primary" @click="showCommandMenu = true"> Open Command Menu </PButton>

  <PCommandMenu
    v-model="showCommandMenu"
    placeholder="What do you need?"
    :options="options"
    :remote-filter="search"
  />
</template>

Props

NameTypeDefaultDescription
widthstring | number640pxWidth of the inner dialog, forwarded to PModal
model-valuebooleanfalseWhether the full-screen command menu is open
optionsListOptions-Items or group entries, fuzzy-matched against the typed keyword
filter-method(option: ListOption, query: string) => booleanfuzzy match on label and descriptionPredicate deciding which option shows while the keyword is being typed
remote-filter(query: string) => ListOptions | Promise<ListOptions>-Search through it instead of the local filter-method; the options it returns replace options while the query is active
virtualbooleanfalseEnable virtualized rendering for large option sets
placeholderstring``Placeholder for the filter input
close-on-select-itembooleantrueClose the menu after an item is selected
close-on-press-escapebooleantrueClose the menu when Esc is pressed
close-on-click-overlaybooleantrueClose the menu when the overlay is clicked

Events

NameTypeDescription
update:model-value(value: boolean) => voidEmitted when the open state of the menu changes.
close(reason: ChangeReason) => voidEmitted before the menu closes, saying why: 'escape-key', 'outside-press', 'close-press' from the dialog, or 'item-press' when an item was picked.
change(value: boolean, details: ChangeDetails) => voidEmitted together with update:model-value when the open state of the menu changes, with the same reason in details.reason.
select(item: ListOptionSelected) => voidEmitted when a command is picked, before the menu closes.
show() => voidEmitted when the menu opens.
hide() => voidEmitted when the menu closes.

Slots

NameDescription
itemCustom item content: { item, index, group, groupIndex }
groupCustom group label: { group, index }
footerFooter slot

Source

Source