diff --git a/apps/docs/public/registry/index.json b/apps/docs/public/registry/index.json index 5392f695..0bb4b41f 100644 --- a/apps/docs/public/registry/index.json +++ b/apps/docs/public/registry/index.json @@ -128,7 +128,8 @@ { "name": "command", "dependencies": [ - "@kobalte/core" + "@kobalte/core", + "cmdk-solid" ], "registryDependencies": [ "dialog" diff --git a/apps/docs/public/registry/ui/command.json b/apps/docs/public/registry/ui/command.json index fe845a79..ac88718c 100644 --- a/apps/docs/public/registry/ui/command.json +++ b/apps/docs/public/registry/ui/command.json @@ -1,7 +1,8 @@ { "name": "command", "dependencies": [ - "@kobalte/core" + "@kobalte/core", + "cmdk-solid" ], "registryDependencies": [ "dialog" @@ -9,7 +10,7 @@ "files": [ { "name": "command.tsx", - "content": "import type { ComponentProps, VoidComponent, VoidProps } from \"solid-js\"\nimport { splitProps, type ParentComponent } from \"solid-js\"\n\nimport type { Dialog as DialogPrimitive } from \"@kobalte/core\"\nimport { Combobox as ComboboxPrimitive } from \"@kobalte/core\"\n\nimport { cn } from \"~/lib/utils\"\nimport { Dialog, DialogContent } from \"~/registry/ui/dialog\"\n\ntype CommandProps = Omit<\n ComboboxPrimitive.ComboboxRootProps,\n | \"open\"\n | \"defaultOpen\"\n | \"multiple\"\n | \"value\"\n | \"defaultValue\"\n | \"removeOnBackspace\"\n | \"readOnly\"\n | \"allowsEmptyCollection\"\n>\n\nconst Command = (props: CommandProps) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\nconst CommandInput: VoidComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n \n \n \n \n \n \n )\n}\n\nconst CommandList = (\n props: VoidProps>\n) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\nconst CommandItem: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\", \"item\"])\n\n return (\n \n )\n}\n\nconst CommandItemLabel = ComboboxPrimitive.ItemLabel\n\nconst CommandHeading: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\nconst CommandItemShortcut: ParentComponent> = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\ntype CommandDialogProps = DialogPrimitive.DialogRootProps &\n CommandProps\n\nconst CommandDialog = (props: CommandDialogProps) => {\n const [local, rest] = splitProps(props, [\"children\"])\n\n return (\n \n \n \n {local.children}\n \n \n \n )\n}\n\nexport {\n Command,\n CommandInput,\n CommandList,\n CommandItem,\n CommandItemLabel,\n CommandItemShortcut,\n CommandHeading,\n CommandDialog\n}\n" + "content": "import type { ComponentProps, VoidComponent } from \"solid-js\"\nimport { splitProps, type ParentComponent } from \"solid-js\"\n\nimport type { Dialog as DialogPrimitive } from \"@kobalte/core\"\nimport {\n CommandEmptyProps,\n CommandGroupProps,\n CommandInputProps,\n CommandItemProps,\n CommandListProps,\n Command as CommandPrimitive,\n CommandRootProps,\n CommandSeparatorProps\n} from \"cmdk-solid\"\n\nimport { cn } from \"~/lib/utils\"\nimport { Dialog, DialogContent } from \"~/registry/ui/dialog\"\n\nconst Command: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\ntype CommandDialogProps = DialogPrimitive.DialogRootProps\n\nconst CommandDialog: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"children\"])\n\n return (\n \n \n \n \n \n )\n}\n\nconst CommandInput: VoidComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n
\n \n \n \n \n \n
\n )\n}\n\nconst CommandList: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\nconst CommandEmpty: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return \n}\n\nconst CommandGroup: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\nconst CommandSeparator: VoidComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return \n}\n\nconst CommandItem: ParentComponent = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\nconst CommandShortcut: ParentComponent> = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n \n )\n}\n\nexport {\n Command,\n CommandDialog,\n CommandInput,\n CommandList,\n CommandEmpty,\n CommandGroup,\n CommandItem,\n CommandShortcut,\n CommandSeparator\n}\n" } ], "type": "ui" diff --git a/apps/docs/src/registry/example/command-demo.tsx b/apps/docs/src/registry/example/command-demo.tsx index cf0a2d12..eb3d1a01 100644 --- a/apps/docs/src/registry/example/command-demo.tsx +++ b/apps/docs/src/registry/example/command-demo.tsx @@ -1,5 +1,3 @@ -import { type JSXElement } from "solid-js" - import { IconCalendar, IconMail, @@ -10,93 +8,54 @@ import { } from "~/components/icons" import { Command, - CommandHeading, + CommandEmpty, + CommandGroup, CommandInput, CommandItem, - CommandItemLabel, - CommandItemShortcut, - CommandList + CommandList, + CommandSeparator, + CommandShortcut } from "~/registry/ui/command" -type ListOption = { - icon: JSXElement - label: string - value: string - shortcut?: JSXElement -} - -type List = { - label: string - options: ListOption[] -} - export default function CommandDemo() { - const data: List[] = [ - { - label: "Suggestions", - options: [ - { - icon: , - label: "Calendar", - value: "Calendar" - }, - { - icon: , - label: "Search emoji", - value: "Search emoji" - }, - { - icon: , - label: "Launch", - value: "Launch" - } - ] - }, - { - label: "Settings", - options: [ - { - icon: , - label: "Profile", - value: "Profile", - shortcut: ⌘P - }, - { - icon: , - label: "Mail", - value: "Mail", - shortcut: ⌘B - }, - { - icon: , - label: "Setting", - value: "Setting", - shortcut: ⌘S - } - ] - } - ] - return ( - - options={data} - optionValue="value" - optionTextValue="label" - optionLabel="label" - optionGroupChildren="options" - placeholder="Type a command or search..." - itemComponent={(props) => ( - - {props.item.rawValue.icon} - {props.item.rawValue.label} - {props.item.rawValue.shortcut} - - )} - sectionComponent={(props) => {props.section.rawValue.label}} - class="rounded-lg border shadow-md" - > - - + + + + No results found. + + + + Calendar + + + + Search Emoji + + + + Launch + + + + + + + Profile + ⌘P + + + + Mail + ⌘B + + + + Settings + ⌘S + + + ) } diff --git a/apps/docs/src/registry/example/command-dialog-demo.tsx b/apps/docs/src/registry/example/command-dialog-demo.tsx index 941ab776..bee61547 100644 --- a/apps/docs/src/registry/example/command-dialog-demo.tsx +++ b/apps/docs/src/registry/example/command-dialog-demo.tsx @@ -1,4 +1,4 @@ -import { createEffect, createSignal, onCleanup, type JSXElement } from "solid-js" +import { createEffect, createSignal, onCleanup } from "solid-js" import { IconCalendar, @@ -10,73 +10,16 @@ import { } from "~/components/icons" import { CommandDialog, - CommandHeading, + CommandEmpty, + CommandGroup, CommandInput, CommandItem, - CommandItemLabel, - CommandItemShortcut, - CommandList + CommandList, + CommandSeparator, + CommandShortcut } from "~/registry/ui/command" -type ListOption = { - icon: JSXElement - label: string - value: string - shortcut?: JSXElement -} - -type List = { - label: string - options: ListOption[] -} - -export default function CommandDemo() { - const data: List[] = [ - { - label: "Suggestions", - options: [ - { - icon: , - label: "Calendar", - value: "Calendar" - }, - { - icon: , - label: "Search emoji", - value: "Search emoji" - }, - { - icon: , - label: "Launch", - value: "Launch" - } - ] - }, - { - label: "Settings", - options: [ - { - icon: , - label: "Profile", - value: "Profile", - shortcut: ⌘P - }, - { - icon: , - label: "Mail", - value: "Mail", - shortcut: ⌘B - }, - { - icon: , - label: "Setting", - value: "Setting", - shortcut: ⌘S - } - ] - } - ] - +export default function CommandDialogDemo() { const [open, setOpen] = createSignal(false) createEffect(() => { @@ -89,9 +32,7 @@ export default function CommandDemo() { document.addEventListener("keydown", down) - onCleanup(() => { - document.removeEventListener("keydown", down) - }) + onCleanup(() => document.removeEventListener("keydown", down)) }) return ( @@ -102,28 +43,43 @@ export default function CommandDemo() { J

- - options={data} - optionValue="value" - optionTextValue="label" - optionLabel="label" - optionGroupChildren="options" - placeholder="Type a command or search..." - itemComponent={(props) => ( - - {props.item.rawValue.icon} - {props.item.rawValue.label} - {props.item.rawValue.shortcut} - - )} - sectionComponent={(props) => ( - {props.section.rawValue.label} - )} - open={open()} - onOpenChange={setOpen} - > - - + + + + No results found. + + + + Calendar + + + + Search Emoji + + + + Launch + + + + + + + Profile + ⌘P + + + + Mail + ⌘B + + + + Settings + ⌘S + + + ) diff --git a/apps/docs/src/registry/registry.ts b/apps/docs/src/registry/registry.ts index daa6d6e8..1c9e4d42 100644 --- a/apps/docs/src/registry/registry.ts +++ b/apps/docs/src/registry/registry.ts @@ -80,7 +80,7 @@ const ui: Registry = [ { name: "command", type: "ui", - dependencies: ["@kobalte/core"], + dependencies: ["@kobalte/core", "cmdk-solid"], registryDependencies: ["dialog"], files: ["ui/command.tsx"] }, diff --git a/apps/docs/src/registry/ui/command.tsx b/apps/docs/src/registry/ui/command.tsx index 22a64a83..1ed271cb 100644 --- a/apps/docs/src/registry/ui/command.tsx +++ b/apps/docs/src/registry/ui/command.tsx @@ -1,34 +1,26 @@ -import type { ComponentProps, VoidComponent, VoidProps } from "solid-js" +import type { ComponentProps, VoidComponent } from "solid-js" import { splitProps, type ParentComponent } from "solid-js" import type { Dialog as DialogPrimitive } from "@kobalte/core" -import { Combobox as ComboboxPrimitive } from "@kobalte/core" +import { + CommandEmptyProps, + CommandGroupProps, + CommandInputProps, + CommandItemProps, + CommandListProps, + Command as CommandPrimitive, + CommandRootProps, + CommandSeparatorProps +} from "cmdk-solid" import { cn } from "~/lib/utils" import { Dialog, DialogContent } from "~/registry/ui/dialog" -type CommandProps = Omit< - ComboboxPrimitive.ComboboxRootProps, - | "open" - | "defaultOpen" - | "multiple" - | "value" - | "defaultValue" - | "removeOnBackspace" - | "readOnly" - | "allowsEmptyCollection" -> - -const Command = (props: CommandProps) => { +const Command: ParentComponent = (props) => { const [local, rest] = splitProps(props, ["class"]) return ( - (props: CommandProps) => { ) } -const CommandInput: VoidComponent = (props) => { +type CommandDialogProps = DialogPrimitive.DialogRootProps + +const CommandDialog: ParentComponent = (props) => { + const [local, rest] = splitProps(props, ["children"]) + + return ( + + + + + + ) +} + +const CommandInput: VoidComponent = (props) => { const [local, rest] = splitProps(props, ["class"]) return ( - +
= (props - - +
) } -const CommandList = ( - props: VoidProps> -) => { +const CommandList: ParentComponent = (props) => { const [local, rest] = splitProps(props, ["class"]) return ( - ) } -const CommandItem: ParentComponent = (props) => { - const [local, rest] = splitProps(props, ["class", "item"]) +const CommandEmpty: ParentComponent = (props) => { + const [local, rest] = splitProps(props, ["class"]) + + return +} + +const CommandGroup: ParentComponent = (props) => { + const [local, rest] = splitProps(props, ["class"]) return ( - = (props ) } -const CommandItemLabel = ComboboxPrimitive.ItemLabel +const CommandSeparator: VoidComponent = (props) => { + const [local, rest] = splitProps(props, ["class"]) -const CommandHeading: ParentComponent = (props) => { + return +} + +const CommandItem: ParentComponent = (props) => { const [local, rest] = splitProps(props, ["class"]) return ( - = ) } -const CommandItemShortcut: ParentComponent> = (props) => { +const CommandShortcut: ParentComponent> = (props) => { const [local, rest] = splitProps(props, ["class"]) return ( @@ -126,33 +139,14 @@ const CommandItemShortcut: ParentComponent> = (props) => ) } -type CommandDialogProps = DialogPrimitive.DialogRootProps & - CommandProps - -const CommandDialog = (props: CommandDialogProps) => { - const [local, rest] = splitProps(props, ["children"]) - - return ( - - - - {local.children} - - - - ) -} - export { Command, + CommandDialog, CommandInput, CommandList, + CommandEmpty, + CommandGroup, CommandItem, - CommandItemLabel, - CommandItemShortcut, - CommandHeading, - CommandDialog + CommandShortcut, + CommandSeparator } diff --git a/apps/docs/src/routes/docs/components/command.mdx b/apps/docs/src/routes/docs/components/command.mdx index 45dbf06b..ad5c9fdd 100644 --- a/apps/docs/src/routes/docs/components/command.mdx +++ b/apps/docs/src/routes/docs/components/command.mdx @@ -2,6 +2,10 @@ +## About + +The `` component uses the [`cmdk-solid`](https://cmdk-solid.vercel.app) component by [create-signal](https://github.com/create-signal/cmdk-solid). + ## Installation @@ -25,7 +29,7 @@ npx solidui-cli@latest add command Install the following dependencies: ```bash -npm install @kobalte/core +npm install @kobalte/core cmdk-solid ``` Copy and paste the following code into your project: @@ -42,28 +46,34 @@ npm install @kobalte/core ```tsx import { Command, + CommandDialog, + CommandEmpty, + CommandGroup, CommandInput, CommandItem, - CommandItemLabel, - CommandList + CommandList, + CommandSeparator, + CommandShortcut, } from "@/components/ui/command" ``` ```tsx -const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"] -``` - -```tsx - ( - - {props.item.rawValue} - - )} -> - - + + + + No results found. + + Calendar + Search Emoji + Calculator + + + + Profile + Billing + Settings + + ``` @@ -86,25 +96,25 @@ export function CommandMenu() { setOpen((open) => !open) } } - + document.addEventListener("keydown", down) - + onCleanup(() => { document.removeEventListener("keydown", down) }) }) return ( - ( - - {props.item.rawValue} - - )} - > - - + + + + No results found. + + Calendar + Search Emoji + Calculator + + ) }