Skip to content

Shortcuts

Import component

vue
import { Shortcuts } from 'quick-shortcuts'

Types

vue
import type { Option, StyleProp, SearchAlgoType } from "quick-shortcuts"
Click to see props definition
ts
type OnSelectFunction = {
    (): void;
};

type Option = {
    id: string | number
    title: string
    description?: string
    suffixText?: string
    icon?: Component
    isVisible: boolean
    isDisabled?: boolean
    onSelect?: OnSelectFunction
    children?: Omit<Option, 'children'>[]
}
ts
type SearchAlgoType = 'normal' | 'word-break'
ts
type StyleProp = {
	// Dialog
    dialogColor?: string
    dialogShadowColor?: string
    dialogBorderRadius?: string
    dialogZIndex?: number
    dialogHeight?: string
    dialogWidth: string

    // Title
    titleColor?: string
    titleFontSize?: string

    // Search
    searchTextColor?: string
    searchPlaceholder?: string
    searchPlaceholderColor?: string
    searchTextFontSize?: string

	// Option
    optionTextColor?: string
    optionDescriptionColor?: string
    optionHoverColor?: string
}

Usage

vue
<Shortcuts
    searchAlgoType="normal"
    activationKey="m"
    dialogTitle="Quick shortcuts"
    :options="options"
    :customStyles="customStyles"
    @select="optionSelected"
/>

Props

PropsTypeDefaultDescription
activationKeystring - OptionalkSupported characters are a-z. It is used to trigger dialog. Ctrl will always be there. eg. Ctrl + J
searchAlgoTypeSearchAlgoType - OptionalnormalIt is a search algorithm type. Supported types are: normal and word-break. Learn more
dialogTitlestring - OptionalShortcutsTitle show above the search input
customStylesStyleProp🔗 - OptionalColors and font sizes for dialog
optionsOption[]🔗 - RequiredundefineData to render list of option for searching and performing actions

Events

change - Trigger when any option is selected.

Function definition

ts
function optionSelected(option: Option) {
    console.log('Selected option: ', option)
}

Labelled image

Labelled image

Search algorithm

ts
const stringMatching = (option: Option, searchQuery: string) => {
    const query = searchQuery.toLowerCase()
    if (!query) return true

    const { title, description, suffixText } = option

    return (
        title.toLowerCase().includes(query) ||
        description?.toLowerCase().includes(query) ||
        suffixText?.toLowerCase().includes(query)
    )
}
ts
const workBreakStringMatching = (option: Option, searchQuery: string) => {
    const query = searchQuery.trim().toLowerCase().split(' ')
    if (!query.length) return true

    const { title, description, suffixText } = option

    const searchableString =`
		${title.toLowerCase()}
		${description?.toLowerCase() ?? ''}
		${suffixText?.toLowerCase() ?? ''}
	`
    return query.every((word) => searchableString.includes(word))
}