Skip to content

Commit 5203359

Browse files
committed
fix(CommandPalette): generics and default types
1 parent 3608bcd commit 5203359

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/runtime/components/CommandPalette.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import type { ListboxRootProps, ListboxRootEmits } from 'reka-ui'
2+
import type { AcceptableValue, ListboxRootProps, ListboxRootEmits } from 'reka-ui'
33
import type { FuseResult } from 'fuse.js'
44
import type { AppConfig } from '@nuxt/schema'
55
import type { UseFuseOptions } from '@vueuse/integrations/useFuse'
@@ -30,7 +30,7 @@ export interface CommandPaletteItem extends Omit<LinkProps, 'type' | 'raw' | 'cu
3030
onSelect?(e?: Event): void
3131
}
3232
33-
export interface CommandPaletteGroup<T> {
33+
export interface CommandPaletteGroup<T extends CommandPaletteItem = CommandPaletteItem> {
3434
id: string
3535
label?: string
3636
slot?: string
@@ -47,7 +47,7 @@ export interface CommandPaletteGroup<T> {
4747
highlightedIcon?: string
4848
}
4949
50-
export interface CommandPaletteProps<G, T> extends Pick<ListboxRootProps, 'multiple' | 'disabled' | 'modelValue' | 'defaultValue' | 'highlightOnHover'>, Pick<UseComponentIconsProps, 'loading' | 'loadingIcon'> {
50+
export interface CommandPaletteProps<T extends CommandPaletteItem = CommandPaletteItem, G extends CommandPaletteGroup<T> = CommandPaletteGroup<T>> extends Pick<ListboxRootProps, 'multiple' | 'disabled' | 'modelValue' | 'defaultValue' | 'highlightOnHover'>, Pick<UseComponentIconsProps, 'loading' | 'loadingIcon'> {
5151
/**
5252
* The element or component this component should render as.
5353
* @defaultValue 'div'
@@ -108,13 +108,13 @@ export interface CommandPaletteProps<G, T> extends Pick<ListboxRootProps, 'multi
108108
ui?: PartialString<typeof commandPalette.slots>
109109
}
110110
111-
export type CommandPaletteEmits<T> = ListboxRootEmits<T> & {
111+
export type CommandPaletteEmits<T extends AcceptableValue = AcceptableValue> = ListboxRootEmits<T> & {
112112
'update:open': [value: boolean]
113113
}
114114
115-
type SlotProps<T> = (props: { item: T, index: number }) => any
115+
type SlotProps<T extends CommandPaletteItem = CommandPaletteItem> = (props: { item: T, index: number }) => any
116116
117-
export type CommandPaletteSlots<G extends { slot?: string }, T extends { slot?: string }> = {
117+
export type CommandPaletteSlots<T extends CommandPaletteItem = CommandPaletteItem, G extends CommandPaletteGroup<T> = CommandPaletteGroup<T>> = {
118118
'empty'(props: { searchTerm?: string }): any
119119
'close'(props: { ui: any }): any
120120
'item': SlotProps<T>
@@ -126,7 +126,7 @@ export type CommandPaletteSlots<G extends { slot?: string }, T extends { slot?:
126126
extendDevtoolsMeta({ example: 'CommandPaletteExample', ignoreProps: ['groups'] })
127127
</script>
128128

129-
<script setup lang="ts" generic="G extends CommandPaletteGroup<T>, T extends CommandPaletteItem">
129+
<script setup lang="ts" generic="T extends CommandPaletteItem = CommandPaletteItem, G extends CommandPaletteGroup<T> = CommandPaletteGroup<T>">
130130
import { computed } from 'vue'
131131
import { ListboxRoot, ListboxFilter, ListboxContent, ListboxGroup, ListboxGroupLabel, ListboxItem, ListboxItemIndicator, useForwardProps, useForwardPropsEmits } from 'reka-ui'
132132
import { defu } from 'defu'
@@ -146,13 +146,13 @@ import ULink from './Link.vue'
146146
import UInput from './Input.vue'
147147
import UKbd from './Kbd.vue'
148148
149-
const props = withDefaults(defineProps<CommandPaletteProps<G, T>>(), {
149+
const props = withDefaults(defineProps<CommandPaletteProps<T, G>>(), {
150150
modelValue: '',
151151
labelKey: 'label',
152152
autofocus: true
153153
})
154154
const emits = defineEmits<CommandPaletteEmits<T>>()
155-
const slots = defineSlots<CommandPaletteSlots<G, T>>()
155+
const slots = defineSlots<CommandPaletteSlots<T, G>>()
156156
157157
const searchTerm = defineModel<string>('searchTerm', { default: '' })
158158

0 commit comments

Comments
 (0)