diff --git a/e2e/extend.spec.ts b/e2e/extend.spec.ts index 1170c5953b..8d905807ee 100644 --- a/e2e/extend.spec.ts +++ b/e2e/extend.spec.ts @@ -6,6 +6,12 @@ test("ButtonToggle page should have h1", async ({ page }) => { expect(await page.textContent("h1")).toBe("Svelte Button Toggle"); }); +// CommandPalette +test("CommandPalette page should have h1", async ({ page }) => { + await page.goto("/docs/extend/command-palette"); + expect(await page.textContent("h1")).toBe("Svelte Command Palette"); +}); + // flowbite-svelte-starter test("Flowbite Svelte Starter page should have h1", async ({ page }) => { await page.goto("/docs/extend/flowbite-svelte-starter"); diff --git a/src/lib/command-palette/CommandPalette.svelte b/src/lib/command-palette/CommandPalette.svelte new file mode 100644 index 0000000000..1e7d66d147 --- /dev/null +++ b/src/lib/command-palette/CommandPalette.svelte @@ -0,0 +1,240 @@ + + + + +{#if open} + +{/if} diff --git a/src/lib/command-palette/index.ts b/src/lib/command-palette/index.ts new file mode 100644 index 0000000000..dbf465e660 --- /dev/null +++ b/src/lib/command-palette/index.ts @@ -0,0 +1 @@ +export { default as CommandPalette } from "./CommandPalette.svelte"; \ No newline at end of file diff --git a/src/lib/command-palette/theme.ts b/src/lib/command-palette/theme.ts new file mode 100644 index 0000000000..fb537f6f8e --- /dev/null +++ b/src/lib/command-palette/theme.ts @@ -0,0 +1,37 @@ +import { tv, type VariantProps } from "tailwind-variants"; +import type { Classes } from "$lib/theme/themeUtils"; + +export type CommandPaletteVariants = VariantProps & Classes; + +export const commandPalette = tv({ + slots: { + backdrop: + "fixed inset-0 z-50 flex items-start justify-center bg-gray-900/50 dark:bg-gray-900/80 p-4 sm:p-6 md:p-20", + panel: + "w-full max-w-2xl bg-white dark:bg-gray-800 rounded-lg shadow-2xl ring-1 ring-black/5 dark:ring-white/10 overflow-hidden transform transition-all", + inputWrapper: "relative", + icon: + "pointer-events-none absolute left-4 top-3.5 h-5 w-5 text-gray-400 dark:text-gray-500", + input: + "w-full border-0 bg-transparent pl-11 pr-4 py-3 text-gray-900 dark:text-white " + + "placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-primary-500 focus:ring-offset-0 text-sm", + list: + "max-h-80 scroll-py-2 overflow-y-auto border-t border-gray-200 dark:border-gray-700", + item: + "cursor-pointer select-none px-4 py-2 text-sm text-gray-900 dark:text-gray-100 " + + "aria-selected:bg-primary-600 aria-selected:text-white", + itemDescription: + "text-xs truncate text-gray-500 dark:text-gray-400 aria-selected:text-primary-100", + empty: + "px-4 py-14 text-center border-t border-gray-200 dark:border-gray-700 text-sm text-gray-500 dark:text-gray-400", + footer: + "flex flex-wrap items-center justify-between gap-2 bg-gray-50 dark:bg-gray-900/50 " + + "px-4 py-2.5 text-xs text-gray-500 dark:text-gray-400 border-t border-gray-200 dark:border-gray-700", + kbd: + "inline-flex items-center gap-1 rounded border border-gray-300 dark:border-gray-600 " + + "bg-white dark:bg-gray-800 px-2 py-1 font-sans text-xs" + }, + + variants: {}, + defaultVariants: {} +}); diff --git a/src/lib/index.ts b/src/lib/index.ts index 4c88238dde..97b57958cb 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -87,6 +87,7 @@ export * from "./utils"; export * from "./types"; // extend +export * from "./command-palette"; export * from "./virtuallist"; export * from "./kanban"; export * from "./split-pane"; diff --git a/src/lib/theme/themes.ts b/src/lib/theme/themes.ts index 2c6732bafd..1783e5ffb2 100644 --- a/src/lib/theme/themes.ts +++ b/src/lib/theme/themes.ts @@ -78,6 +78,7 @@ export { secondary } from "../typography/secondary"; export { span } from "../typography/span"; // extend +export { commandPalette } from "$lib/command-palette/theme"; export { virtualList } from "$lib/virtuallist"; export { kanbanBoard, kanbanCard } from "$lib/kanban/theme"; export { splitpane, pane, divider, dividerHitArea } from "$lib/split-pane/theme"; diff --git a/src/lib/types.ts b/src/lib/types.ts index 44571264f0..abf55e9b30 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -117,6 +117,7 @@ import type { TagsVariants } from "$lib/forms/tags/theme"; import type { VirtualListVariants } from "$lib/virtuallist/theme"; import type { KanbanBoardVariants, KanbanCardVariants } from "$lib/kanban/theme"; import type { TourVariants } from "$lib/tour/theme"; +import type { CommandPaletteVariants } from "$lib/command-palette/theme"; // utils import type { CloseButtonVariants } from "$lib/utils/theme"; @@ -621,7 +622,7 @@ export interface DrawerProps extends DrawerVariants, Omit, "color"> {} +export interface HelperProps extends HelperVariants, Omit, "color"> { } // input export type InputValue = string | number | string[] | undefined; @@ -976,7 +977,7 @@ export interface TimepickerProps { timeIntervals?: string[]; columns?: ColumnCount; // Callback props instead of events - onselect?: (data: { time: string; endTime: string; [key: string]: string }) => void; + onselect?: (data: { time: string; endTime: string;[key: string]: string }) => void; } // textarea @@ -1165,7 +1166,7 @@ export interface ToolbarProps extends ToolbarVariants, Omit {} +export interface ToolbarGroupProps extends ToolbarGroupVariants, HTMLAttributes { } export type ToolbarButtonProps = ToolbarButtonVariants & AnchorButtonAttributes & { @@ -1482,7 +1483,7 @@ export interface SkeletonProps extends SkeletonVariants, HTMLAttributes {} +export interface TestimonialPlaceholderProps extends TestimonialPlaceholderVariants, HTMLAttributes { } export interface TextPlaceholderProps extends TextPlaceholderVariants, HTMLAttributes { size?: TextPlaceholderVariants["size"]; @@ -1492,7 +1493,7 @@ export interface VideoPlaceholderProps extends VideoPlaceholderVariants, HTMLAtt size?: VideoPlaceholderVariants["size"]; } -export interface WidgetPlaceholderProps extends WidgetPlaceholderVariants, HTMLAttributes {} +export interface WidgetPlaceholderProps extends WidgetPlaceholderVariants, HTMLAttributes { } // speeddial export interface SpeedCtxType { @@ -1886,7 +1887,7 @@ export interface ToastProps extends ToastVaraints, HTMLAttributes void; +} + +export interface CommandPaletteProps extends CommandPaletteVariants, HTMLAttributes { + open?: boolean; + items?: CommandItem[]; + placeholder?: string; + emptyMessage?: string; + shortcutKey?: string; + vim?: boolean; + onclose?: () => void; +} diff --git a/src/routes/docs-examples/extend/command-palette/+page.svelte b/src/routes/docs-examples/extend/command-palette/+page.svelte new file mode 100644 index 0000000000..300c1a19dd --- /dev/null +++ b/src/routes/docs-examples/extend/command-palette/+page.svelte @@ -0,0 +1,189 @@ + + +
+
+

+ Command Palette Demo +

+

+ Press ⌘P (default ⌘K) or + Ctrl+P (default Ctrl+K) to open + the command palette, or click the button below. +

+ + + Vim mode is {vimMode ? 'on' : 'off'} +
+

+ Available Commands +

+ +
+ {#each commands as command (command.id)} +
+
+ {command.icon} +
+

+ {command.label} +

+

+ {command.description} +

+ {#if command.keywords} +
+ {#each command.keywords as keyword (keyword)} + + {keyword} + + {/each} +
+ {/if} +
+
+
+ {/each} +
+
+
+
+ + \ No newline at end of file diff --git a/src/routes/docs/extend/command-palette.md b/src/routes/docs/extend/command-palette.md new file mode 100644 index 0000000000..9510330696 --- /dev/null +++ b/src/routes/docs/extend/command-palette.md @@ -0,0 +1,44 @@ +--- +layout: componentLayout +title: Svelte Command Palette +breadcrumb_title: Command Palette +component_title: Command Palette +dir: Extend +description: AAA. + +--- + + + +## Setup + +```svelte example hideOutput + +``` + +## Usage Examples + +See [examples](/docs-examples/extend/command-palette) and [code](https://github.com/themesberg/flowbite-svelte/tree/main/src/routes/docs-examples/extend/command-palette). + + +## Component data + +The component has the following props, type, and default values. See [types page](/docs/pages/typescript) for type information. + + + +## GitHub Links + + + +## LLM Link + + \ No newline at end of file