Skip to content

Commit 2d3fc68

Browse files
committed
fix: fixed registry issues of the command component
1 parent 9ba44c4 commit 2d3fc68

File tree

7 files changed

+62
-46
lines changed

7 files changed

+62
-46
lines changed

apps/docs/public/registry/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
"dialog"
129129
],
130130
"files": [
131-
"ui/combobox.tsx"
131+
"ui/command.tsx"
132132
],
133133
"type": "ui"
134134
},

apps/docs/public/registry/ui/command.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
],
1010
"files": [
1111
{
12-
"name": "combobox.tsx",
13-
"content": "import type { Component } from \"solid-js\"\nimport { splitProps } from \"solid-js\"\n\nimport { Combobox as ComboboxPrimitive } from \"@kobalte/core\"\nimport { TbCheck, TbSelector } from \"solid-icons/tb\"\n\nimport { cn } from \"~/lib/utils\"\n\nconst Combobox = ComboboxPrimitive.Root\n\nconst ComboboxItem: Component<ComboboxPrimitive.ComboboxItemProps> = (props) => {\n const [, rest] = splitProps(props, [\"class\"])\n return (\n <ComboboxPrimitive.Item\n class={cn(\n \"relative flex cursor-default select-none items-center justify-between rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:opacity-50\",\n props.class\n )}\n {...rest}\n />\n )\n}\n\nconst ComboboxItemLabel = ComboboxPrimitive.ItemLabel\n\nconst ComboboxItemIndicator: Component<ComboboxPrimitive.ComboboxItemIndicatorProps> = (props) => {\n const [, rest] = splitProps(props, [\"children\"])\n return (\n <ComboboxPrimitive.ItemIndicator {...rest}>\n {props.children ?? <TbCheck />}\n </ComboboxPrimitive.ItemIndicator>\n )\n}\n\nconst ComboboxSection: Component<ComboboxPrimitive.ComboboxSectionProps> = (props) => {\n const [, rest] = splitProps(props, [\"class\"])\n return (\n <ComboboxPrimitive.Section\n class={cn(\n \"overflow-hidden p-1 px-2 py-1.5 text-xs font-medium text-muted-foreground \",\n props.class\n )}\n {...rest}\n />\n )\n}\n\n// due to the generic typing this needs to be a function\nfunction ComboboxControl<T>(props: ComboboxPrimitive.ComboboxControlProps<T>) {\n const [, rest] = splitProps(props, [\"class\"])\n return (\n <ComboboxPrimitive.Control\n class={cn(\"flex items-center rounded-md border px-3\", props.class)}\n {...rest}\n />\n )\n}\n\nconst ComboboxInput: Component<ComboboxPrimitive.ComboboxInputProps> = (props) => {\n const [, rest] = splitProps(props, [\"class\"])\n return (\n <ComboboxPrimitive.Input\n class={cn(\n \"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n props.class\n )}\n {...rest}\n />\n )\n}\n\nconst ComboboxHiddenSelect = ComboboxPrimitive.HiddenSelect\n\nconst ComboboxTrigger: Component<ComboboxPrimitive.ComboboxTriggerProps> = (props) => {\n const [, rest] = splitProps(props, [\"class\", \"children\"])\n return (\n <ComboboxPrimitive.Trigger class={cn(\"size-4 opacity-50\", props.class)} {...rest}>\n <ComboboxPrimitive.Icon>{props.children ?? <TbSelector />}</ComboboxPrimitive.Icon>\n </ComboboxPrimitive.Trigger>\n )\n}\n\nconst ComboboxContent: Component<ComboboxPrimitive.ComboboxContentProps> = (props) => {\n const [, rest] = splitProps(props, [\"class\"])\n return (\n <ComboboxPrimitive.Portal>\n <ComboboxPrimitive.Content\n class={cn(\n \"relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in fade-in-80\",\n props.class\n )}\n {...rest}\n >\n <ComboboxPrimitive.Listbox class=\"m-0 p-1\" />\n </ComboboxPrimitive.Content>\n </ComboboxPrimitive.Portal>\n )\n}\n\nexport {\n Combobox,\n ComboboxItem,\n ComboboxItemLabel,\n ComboboxItemIndicator,\n ComboboxSection,\n ComboboxControl,\n ComboboxTrigger,\n ComboboxInput,\n ComboboxHiddenSelect,\n ComboboxContent\n}\n"
12+
"name": "command.tsx",
13+
"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\"\nimport { TbSearch } from \"solid-icons/tb\"\n\nimport { cn } from \"~/lib/utils\"\nimport { Dialog, DialogContent } from \"~/registry/ui/dialog\"\n\ntype CommandProps<Option, OptGroup> = Omit<\n ComboboxPrimitive.ComboboxRootProps<Option, OptGroup>,\n | \"open\"\n | \"defaultOpen\"\n | \"multiple\"\n | \"value\"\n | \"defaultValue\"\n | \"removeOnBackspace\"\n | \"readOnly\"\n | \"allowsEmptyCollection\"\n>\n\nconst Command = <Option, OptGroup>(props: CommandProps<Option, OptGroup>) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n <ComboboxPrimitive.Root\n // force render list\n open\n // @ts-ignore -- prevent select\n value=\"\"\n allowsEmptyCollection\n class={cn(\n \"flex size-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground\",\n local.class\n )}\n {...rest}\n />\n )\n}\n\nconst CommandInput: VoidComponent<ComboboxPrimitive.ComboboxInputProps> = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n <ComboboxPrimitive.Control class=\"flex items-center border-b px-3\" cmdk-input-wrapper=\"\">\n <TbSearch class=\"mr-2 size-4 shrink-0 opacity-50\" />\n <ComboboxPrimitive.Input\n cmdk-input=\"\"\n class={cn(\n \"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n local.class\n )}\n {...rest}\n />\n </ComboboxPrimitive.Control>\n )\n}\n\nconst CommandList = <Option, OptGroup>(\n props: VoidProps<ComboboxPrimitive.ComboboxListboxProps<Option, OptGroup>>\n) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n <ComboboxPrimitive.Listbox\n cmdk-list=\"\"\n class={cn(\"max-h-[300px] overflow-y-auto overflow-x-hidden p-1\", local.class)}\n {...rest}\n />\n )\n}\n\nconst CommandItem: ParentComponent<ComboboxPrimitive.ComboboxItemProps> = (props) => {\n const [local, rest] = splitProps(props, [\"class\", \"item\"])\n\n return (\n <ComboboxPrimitive.Item\n item={local.item}\n cmdk-item=\"\"\n class={cn(\n \"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:opacity-50\",\n local.class\n )}\n {...rest}\n />\n )\n}\n\nconst CommandItemLabel = ComboboxPrimitive.ItemLabel\n\nconst CommandHeading: ParentComponent<ComboboxPrimitive.ComboboxSectionProps> = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n <ComboboxPrimitive.Section\n cmdk-heading=\"\"\n class={cn(\n \"px-2 py-1.5 text-xs font-medium text-muted-foreground [&:not(&:first-of-type)]:mt-2\",\n local.class\n )}\n {...rest}\n />\n )\n}\n\nconst CommandItemShortcut: ParentComponent<ComponentProps<\"span\">> = (props) => {\n const [local, rest] = splitProps(props, [\"class\"])\n\n return (\n <span\n class={cn(\"ml-auto text-xs tracking-widest text-muted-foreground\", local.class)}\n {...rest}\n />\n )\n}\n\ntype CommandDialogProps<Option, OptGroup> = DialogPrimitive.DialogRootProps &\n CommandProps<Option, OptGroup>\n\nconst CommandDialog = <Option, OptGroup>(props: CommandDialogProps<Option, OptGroup>) => {\n const [local, rest] = splitProps(props, [\"children\"])\n\n return (\n <Dialog {...rest}>\n <DialogContent class=\"overflow-hidden p-0\">\n <Command\n class=\"[&_[cmdk-heading]]:px-2 [&_[cmdk-heading]]:font-medium [&_[cmdk-heading]]:text-muted-foreground [&_[cmdk-input-wrapper]_svg]:size-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:size-5 [&_[cmdk-list]:not([hidden])_~[cmdk-list]]:pt-0 [&_[cmdk-list]]:px-2\"\n {...rest}\n >\n {local.children}\n </Command>\n </DialogContent>\n </Dialog>\n )\n}\n\nexport {\n Command,\n CommandInput,\n CommandList,\n CommandItem,\n CommandItemLabel,\n CommandItemShortcut,\n CommandHeading,\n CommandDialog\n}\n"
1414
}
1515
],
1616
"type": "ui"

apps/docs/src/__registry__/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const Index: Record<string, any> = {
9595
type: "ui",
9696
registryDependencies: ["dialog"],
9797
component: lazy(() => import("~/registry/ui/command")),
98-
files: ["registry/ui/combobox.tsx"],
98+
files: ["registry/ui/command.tsx"],
9999
},
100100
"context-menu": {
101101
name: "context-menu",

apps/docs/src/registry/example/command-demo.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
CommandInput,
99
CommandItem,
1010
CommandItemLabel,
11-
CommandList,
12-
CommandShortcut
11+
CommandItemShortcut,
12+
CommandList
1313
} from "~/registry/ui/command"
1414

1515
type ListOption = {
@@ -53,19 +53,19 @@ export default function CommandDemo() {
5353
icon: <TbUser class="mr-2 size-4" />,
5454
label: "Profile",
5555
value: "Profile",
56-
shortcut: <CommandShortcut>⌘P</CommandShortcut>
56+
shortcut: <CommandItemShortcut>⌘P</CommandItemShortcut>
5757
},
5858
{
5959
icon: <TbMail class="mr-2 size-4" />,
6060
label: "Mail",
6161
value: "Mail",
62-
shortcut: <CommandShortcut>⌘B</CommandShortcut>
62+
shortcut: <CommandItemShortcut>⌘B</CommandItemShortcut>
6363
},
6464
{
6565
icon: <TbSettings class="mr-2 size-4" />,
6666
label: "Setting",
6767
value: "Setting",
68-
shortcut: <CommandShortcut>⌘S</CommandShortcut>
68+
shortcut: <CommandItemShortcut>⌘S</CommandItemShortcut>
6969
}
7070
]
7171
}

apps/docs/src/registry/example/command-dialog-demo.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
CommandInput,
99
CommandItem,
1010
CommandItemLabel,
11-
CommandList,
12-
CommandShortcut
11+
CommandItemShortcut,
12+
CommandList
1313
} from "~/registry/ui/command"
1414

1515
type ListOption = {
@@ -53,19 +53,19 @@ export default function CommandDialogDemo() {
5353
icon: <TbUser class="mr-2 size-4" />,
5454
label: "Profile",
5555
value: "Profile",
56-
shortcut: <CommandShortcut>⌘P</CommandShortcut>
56+
shortcut: <CommandItemShortcut>⌘P</CommandItemShortcut>
5757
},
5858
{
5959
icon: <TbMail class="mr-2 size-4" />,
6060
label: "Mail",
6161
value: "Mail",
62-
shortcut: <CommandShortcut>⌘B</CommandShortcut>
62+
shortcut: <CommandItemShortcut>⌘B</CommandItemShortcut>
6363
},
6464
{
6565
icon: <TbSettings class="mr-2 size-4" />,
6666
label: "Setting",
6767
value: "Setting",
68-
shortcut: <CommandShortcut>⌘S</CommandShortcut>
68+
shortcut: <CommandItemShortcut>⌘S</CommandItemShortcut>
6969
}
7070
]
7171
}

apps/docs/src/registry/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const ui: Registry = [
7676
type: "ui",
7777
dependencies: ["@kobalte/core", "solid-icons"],
7878
registryDependencies: ["dialog"],
79-
files: ["ui/combobox.tsx"]
79+
files: ["ui/command.tsx"]
8080
},
8181
{
8282
name: "context-menu",

apps/docs/src/registry/ui/command.tsx

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { TbSearch } from "solid-icons/tb"
88
import { cn } from "~/lib/utils"
99
import { Dialog, DialogContent } from "~/registry/ui/dialog"
1010

11-
export const CommandItemLabel = ComboboxPrimitive.ItemLabel
12-
1311
type CommandProps<Option, OptGroup> = Omit<
1412
ComboboxPrimitive.ComboboxRootProps<Option, OptGroup>,
1513
| "open"
@@ -22,7 +20,7 @@ type CommandProps<Option, OptGroup> = Omit<
2220
| "allowsEmptyCollection"
2321
>
2422

25-
export const Command = <Option, OptGroup>(props: CommandProps<Option, OptGroup>) => {
23+
const Command = <Option, OptGroup>(props: CommandProps<Option, OptGroup>) => {
2624
const [local, rest] = splitProps(props, ["class"])
2725

2826
return (
@@ -41,21 +39,7 @@ export const Command = <Option, OptGroup>(props: CommandProps<Option, OptGroup>)
4139
)
4240
}
4341

44-
export const CommandList = <Option, OptGroup>(
45-
props: VoidProps<ComboboxPrimitive.ComboboxListboxProps<Option, OptGroup>>
46-
) => {
47-
const [local, rest] = splitProps(props, ["class"])
48-
49-
return (
50-
<ComboboxPrimitive.Listbox
51-
cmdk-list=""
52-
class={cn("max-h-[300px] overflow-y-auto overflow-x-hidden p-1", local.class)}
53-
{...rest}
54-
/>
55-
)
56-
}
57-
58-
export const CommandInput: VoidComponent<ComboboxPrimitive.ComboboxInputProps> = (props) => {
42+
const CommandInput: VoidComponent<ComboboxPrimitive.ComboboxInputProps> = (props) => {
5943
const [local, rest] = splitProps(props, ["class"])
6044

6145
return (
@@ -73,7 +57,21 @@ export const CommandInput: VoidComponent<ComboboxPrimitive.ComboboxInputProps> =
7357
)
7458
}
7559

76-
export const CommandItem: ParentComponent<ComboboxPrimitive.ComboboxItemProps> = (props) => {
60+
const CommandList = <Option, OptGroup>(
61+
props: VoidProps<ComboboxPrimitive.ComboboxListboxProps<Option, OptGroup>>
62+
) => {
63+
const [local, rest] = splitProps(props, ["class"])
64+
65+
return (
66+
<ComboboxPrimitive.Listbox
67+
cmdk-list=""
68+
class={cn("max-h-[300px] overflow-y-auto overflow-x-hidden p-1", local.class)}
69+
{...rest}
70+
/>
71+
)
72+
}
73+
74+
const CommandItem: ParentComponent<ComboboxPrimitive.ComboboxItemProps> = (props) => {
7775
const [local, rest] = splitProps(props, ["class", "item"])
7876

7977
return (
@@ -89,27 +87,29 @@ export const CommandItem: ParentComponent<ComboboxPrimitive.ComboboxItemProps> =
8987
)
9088
}
9189

92-
export const CommandShortcut: ParentComponent<ComponentProps<"span">> = (props) => {
90+
const CommandItemLabel = ComboboxPrimitive.ItemLabel
91+
92+
const CommandHeading: ParentComponent<ComboboxPrimitive.ComboboxSectionProps> = (props) => {
9393
const [local, rest] = splitProps(props, ["class"])
9494

9595
return (
96-
<span
97-
class={cn("ml-auto text-xs tracking-widest text-muted-foreground", local.class)}
96+
<ComboboxPrimitive.Section
97+
cmdk-heading=""
98+
class={cn(
99+
"px-2 py-1.5 text-xs font-medium text-muted-foreground [&:not(&:first-of-type)]:mt-2",
100+
local.class
101+
)}
98102
{...rest}
99103
/>
100104
)
101105
}
102106

103-
export const CommandHeading: ParentComponent<ComboboxPrimitive.ComboboxSectionProps> = (props) => {
107+
const CommandItemShortcut: ParentComponent<ComponentProps<"span">> = (props) => {
104108
const [local, rest] = splitProps(props, ["class"])
105109

106110
return (
107-
<ComboboxPrimitive.Section
108-
cmdk-heading=""
109-
class={cn(
110-
"px-2 py-1.5 text-xs font-medium text-muted-foreground [&:not(&:first-of-type)]:mt-2",
111-
local.class
112-
)}
111+
<span
112+
class={cn("ml-auto text-xs tracking-widest text-muted-foreground", local.class)}
113113
{...rest}
114114
/>
115115
)
@@ -118,14 +118,30 @@ export const CommandHeading: ParentComponent<ComboboxPrimitive.ComboboxSectionPr
118118
type CommandDialogProps<Option, OptGroup> = DialogPrimitive.DialogRootProps &
119119
CommandProps<Option, OptGroup>
120120

121-
export const CommandDialog = <Option, OptGroup>(props: CommandDialogProps<Option, OptGroup>) => {
121+
const CommandDialog = <Option, OptGroup>(props: CommandDialogProps<Option, OptGroup>) => {
122122
const [local, rest] = splitProps(props, ["children"])
123123

124124
return (
125125
<Dialog {...rest}>
126126
<DialogContent class="overflow-hidden p-0">
127-
<Command {...rest}>{local.children}</Command>
127+
<Command
128+
class="[&_[cmdk-heading]]:px-2 [&_[cmdk-heading]]:font-medium [&_[cmdk-heading]]:text-muted-foreground [&_[cmdk-input-wrapper]_svg]:size-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:size-5 [&_[cmdk-list]:not([hidden])_~[cmdk-list]]:pt-0 [&_[cmdk-list]]:px-2"
129+
{...rest}
130+
>
131+
{local.children}
132+
</Command>
128133
</DialogContent>
129134
</Dialog>
130135
)
131136
}
137+
138+
export {
139+
Command,
140+
CommandInput,
141+
CommandList,
142+
CommandItem,
143+
CommandItemLabel,
144+
CommandItemShortcut,
145+
CommandHeading,
146+
CommandDialog
147+
}

0 commit comments

Comments
 (0)