Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions src/lib/cmdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Writable } from 'svelte/store';

export type LoadingProps = {
/** Estimated loading progress */
progress?: number;
progress?: number | undefined;

/**
* Whether to delegate rendering to a custom element.
Expand All @@ -19,7 +19,7 @@ export type LoadingProps = {
* as `aria-hidden` to prevent screen readers from reading the
* contents while loading.
*/
asChild?: boolean;
asChild?: boolean | undefined;
} & HTMLDivAttributes;

export type EmptyProps = {
Expand All @@ -28,41 +28,41 @@ export type EmptyProps = {
*
* Only receives `attrs`, no `action`.
*/
asChild?: boolean;
asChild?: boolean | undefined;
} & HTMLDivAttributes;

export type SeparatorProps = {
/**
* Whether this separator is always rendered, regardless
* of the filter.
*/
alwaysRender?: boolean;
alwaysRender?: boolean | undefined;

/**
* Whether to delegate rendering to a custom element.
*/
asChild?: boolean;
asChild?: boolean | undefined;
} & HTMLDivAttributes;

type BaseCommandProps = {
/**
* Controlled state store for the command menu.
* Initialize state using the `createState` function.
*/
state?: Writable<State>;
state?: Writable<State> | undefined;

/**
* An accessible label for the command menu.
* Not visible & only used for screen readers.
*/
label?: string;
label?: string | undefined;

/**
* Optionally set to `false` to turn off the automatic filtering
* and sorting. If `false`, you must conditionally render valid
* items yourself.
*/
shouldFilter?: boolean;
shouldFilter?: boolean | undefined;

/**
* A custom filter function for whether each command item should
Expand All @@ -72,24 +72,24 @@ type BaseCommandProps = {
*
* By default, it will use the `command-score` package to score.
*/
filter?: (value: string, search: string) => number;
filter?: ((value: string, search: string) => number) | undefined;

/**
* Optionally provide or bind to the selected command menu item.
*/
value?: string;
value?: string | undefined;

/**
* A function that is called when the selected command menu item
* changes. It receives the new value as an argument.
*/
onValueChange?: (value: string) => void;
onValueChange?: ((value: string) => void) | undefined;

/**
* Optionally set to `true` to enable looping through the items
* when the user reaches the end of the list using the keyboard.
*/
loop?: boolean;
loop?: boolean | undefined;
};

export type CommandProps = Expand<
Expand All @@ -99,19 +99,19 @@ export type CommandProps = Expand<
* elements. These ids should be unique and are only
* necessary in very specific cases. Use with caution.
*/
ids?: Partial<CommandIds>;
ids?: Partial<CommandIds> | undefined;
}
> &
HTMLDivAttributes & {
onKeydown?: (e: KeyboardEvent) => void;
asChild?: boolean;
onKeydown?: ((e: KeyboardEvent) => void) | undefined;
asChild?: boolean | undefined;
};

export type ListProps = {
/**
* The list element
*/
el?: HTMLElement;
el?: HTMLElement | undefined;

/**
* Whether to delegate rendering to a custom element.
Expand All @@ -124,38 +124,38 @@ export type ListProps = {
* is responsible for measuring the height of the items and setting the
* CSS variable to the height of the items.
*/
asChild?: boolean;
asChild?: boolean | undefined;
} & HTMLDivAttributes;

export type InputProps = {
/**
* The input element
*/
el?: HTMLInputElement;
el?: HTMLInputElement | undefined;

/**
* Whether to delegate rendering to a custom element.
*/
asChild?: boolean;
asChild?: boolean | undefined;
} & HTMLInputAttributes;

export type GroupProps = {
/**
* Optional heading to render for the group
*/
heading?: string;
heading?: string | undefined;

/**
* If heading isn't provided, you must provide a unique
* value for the group.
*/
value?: string;
value?: string | undefined;

/**
* Whether or not this group is always rendered,
* regardless of filtering.
*/
alwaysRender?: boolean;
alwaysRender?: boolean | undefined;

/**
* Whether to delegate rendering to custom elements.
Expand All @@ -164,47 +164,47 @@ export type GroupProps = {
* Container has `attrs` & `action`, while `heading` & `group`
* only have `attrs` to be applied to the respective elements.
*/
asChild?: boolean;
asChild?: boolean | undefined;
} & HTMLDivAttributes;

export type ItemProps = {
/**
* Whether this item is disabled.
*/
disabled?: boolean;
disabled?: boolean | undefined;

/**
* A function called when this item is selected, either
* via click or keyboard selection.
*/
onSelect?: (value: string) => void;
onSelect?: ((value: string) => void) | undefined;

/**
* A unique value for this item.
* If not provided, it will be inferred from the rendered
* `textContent`. If your `textContent` is dynamic, you must
* provide a stable unique `value`.
*/
value?: string;
value?: string | undefined;

/**
* Whether or not this item is always rendered,
* regardless of filtering.
*/
alwaysRender?: boolean;
alwaysRender?: boolean | undefined;

/**
* Whether to delegate rendering to a custom element.
* Will pass the `attrs` & `action` to be applied to the custom element.
*/
asChild?: boolean;
asChild?: boolean | undefined;

/**
* Optionally override the default `id` generated for this item.
* NOTE: This must be unique across all items and is only necessary
* in very specific cases.
*/
id?: string;
id?: string | undefined;
} & HTMLDivAttributes;

type TransitionProps =
Expand All @@ -220,15 +220,15 @@ export type OverlayProps<
In extends Transition = Transition,
Out extends Transition = Transition
> = PrefixKeys<Pick<DialogPrimitive.OverlayProps<T, In, Out>, TransitionProps>, 'overlay'> & {
overlayClasses?: string;
overlayClasses?: string | undefined;
};

export type ContentProps<
T extends Transition = Transition,
In extends Transition = Transition,
Out extends Transition = Transition
> = PrefixKeys<Pick<DialogPrimitive.ContentProps<T, In, Out>, TransitionProps>, 'content'> & {
contentClasses?: string;
contentClasses?: string | undefined;
};

export type DialogProps<
Expand Down Expand Up @@ -294,7 +294,7 @@ export type Context = {
type UpdateState = <K extends keyof State>(
key: K,
value: State[K],
preventScroll?: boolean
preventScroll?: boolean | undefined
) => void;

export type ConextStore = Writable<Context>;
Expand Down