Skip to content

Commit cf9bf5b

Browse files
committed
feat: add label,etc.. to select exports
1 parent 0fa206d commit cf9bf5b

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

.changeset/rare-cheetahs-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"docs": patch
3+
---
4+
5+
feat: add label,etc.. to select exports

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"files": [
77
{
88
"name": "select.tsx",
9-
"content": "import type { JSX, ValidComponent } from \"solid-js\"\nimport { splitProps } from \"solid-js\"\n\nimport type { PolymorphicProps } from \"@kobalte/core/polymorphic\"\nimport * as SelectPrimitive from \"@kobalte/core/select\"\n\nimport { cn } from \"~/lib/utils\"\n\nconst Select = SelectPrimitive.Root\nconst SelectValue = SelectPrimitive.Value\nconst SelectHiddenSelect = SelectPrimitive.HiddenSelect\n\ntype SelectTriggerProps<T extends ValidComponent = \"button\"> =\n SelectPrimitive.SelectTriggerProps<T> & {\n class?: string | undefined\n children?: JSX.Element\n }\n\nconst SelectTrigger = <T extends ValidComponent = \"button\">(\n props: PolymorphicProps<T, SelectTriggerProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectTriggerProps, [\"class\", \"children\"])\n return (\n <SelectPrimitive.Trigger\n class={cn(\n \"flex h-10 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50\",\n local.class\n )}\n {...others}\n >\n {local.children}\n <SelectPrimitive.Icon\n as=\"svg\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"size-4 opacity-50\"\n >\n <path d=\"M8 9l4 -4l4 4\" />\n <path d=\"M16 15l-4 4l-4 -4\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n )\n}\n\ntype SelectContentProps<T extends ValidComponent = \"div\"> =\n SelectPrimitive.SelectContentProps<T> & { class?: string | undefined }\n\nconst SelectContent = <T extends ValidComponent = \"div\">(\n props: PolymorphicProps<T, SelectContentProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectContentProps, [\"class\"])\n return (\n <SelectPrimitive.Portal>\n <SelectPrimitive.Content\n class={cn(\n \"relative z-50 min-w-32 overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in fade-in-80\",\n local.class\n )}\n {...others}\n >\n <SelectPrimitive.Listbox class=\"m-0 p-1\" />\n </SelectPrimitive.Content>\n </SelectPrimitive.Portal>\n )\n}\n\ntype SelectItemProps<T extends ValidComponent = \"li\"> = SelectPrimitive.SelectItemProps<T> & {\n class?: string | undefined\n children?: JSX.Element\n}\n\nconst SelectItem = <T extends ValidComponent = \"li\">(\n props: PolymorphicProps<T, SelectItemProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectItemProps, [\"class\", \"children\"])\n return (\n <SelectPrimitive.Item\n class={cn(\n \"relative mt-0 flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50\",\n local.class\n )}\n {...others}\n >\n <SelectPrimitive.ItemIndicator class=\"absolute right-2 flex size-3.5 items-center justify-center\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"size-4\"\n >\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\n <path d=\"M5 12l5 5l10 -10\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemLabel>{local.children}</SelectPrimitive.ItemLabel>\n </SelectPrimitive.Item>\n )\n}\n\nexport { Select, SelectValue, SelectHiddenSelect, SelectTrigger, SelectContent, SelectItem }\n"
9+
"content": "import type { JSX, ValidComponent } from \"solid-js\"\nimport { splitProps } from \"solid-js\"\n\nimport type { PolymorphicProps } from \"@kobalte/core/polymorphic\"\nimport * as SelectPrimitive from \"@kobalte/core/select\"\nimport { cva } from \"class-variance-authority\"\n\nimport { cn } from \"~/lib/utils\"\n\nconst Select = SelectPrimitive.Root\nconst SelectValue = SelectPrimitive.Value\nconst SelectHiddenSelect = SelectPrimitive.HiddenSelect\n\ntype SelectTriggerProps<T extends ValidComponent = \"button\"> =\n SelectPrimitive.SelectTriggerProps<T> & {\n class?: string | undefined\n children?: JSX.Element\n }\n\nconst SelectTrigger = <T extends ValidComponent = \"button\">(\n props: PolymorphicProps<T, SelectTriggerProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectTriggerProps, [\"class\", \"children\"])\n return (\n <SelectPrimitive.Trigger\n class={cn(\n \"flex h-10 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50\",\n local.class\n )}\n {...others}\n >\n {local.children}\n <SelectPrimitive.Icon\n as=\"svg\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"size-4 opacity-50\"\n >\n <path d=\"M8 9l4 -4l4 4\" />\n <path d=\"M16 15l-4 4l-4 -4\" />\n </SelectPrimitive.Icon>\n </SelectPrimitive.Trigger>\n )\n}\n\ntype SelectContentProps<T extends ValidComponent = \"div\"> =\n SelectPrimitive.SelectContentProps<T> & { class?: string | undefined }\n\nconst SelectContent = <T extends ValidComponent = \"div\">(\n props: PolymorphicProps<T, SelectContentProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectContentProps, [\"class\"])\n return (\n <SelectPrimitive.Portal>\n <SelectPrimitive.Content\n class={cn(\n \"relative z-50 min-w-32 overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in fade-in-80\",\n local.class\n )}\n {...others}\n >\n <SelectPrimitive.Listbox class=\"m-0 p-1\" />\n </SelectPrimitive.Content>\n </SelectPrimitive.Portal>\n )\n}\n\ntype SelectItemProps<T extends ValidComponent = \"li\"> = SelectPrimitive.SelectItemProps<T> & {\n class?: string | undefined\n children?: JSX.Element\n}\n\nconst SelectItem = <T extends ValidComponent = \"li\">(\n props: PolymorphicProps<T, SelectItemProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectItemProps, [\"class\", \"children\"])\n return (\n <SelectPrimitive.Item\n class={cn(\n \"relative mt-0 flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50\",\n local.class\n )}\n {...others}\n >\n <SelectPrimitive.ItemIndicator class=\"absolute right-2 flex size-3.5 items-center justify-center\">\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n class=\"size-4\"\n >\n <path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\" />\n <path d=\"M5 12l5 5l10 -10\" />\n </svg>\n </SelectPrimitive.ItemIndicator>\n <SelectPrimitive.ItemLabel>{local.children}</SelectPrimitive.ItemLabel>\n </SelectPrimitive.Item>\n )\n}\n\nconst labelVariants = cva(\n \"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\",\n {\n variants: {\n variant: {\n label: \"data-[invalid]:text-destructive\",\n description: \"font-normal text-muted-foreground\",\n error: \"text-xs text-destructive\"\n }\n },\n defaultVariants: {\n variant: \"label\"\n }\n }\n)\n\ntype SelectLabelProps<T extends ValidComponent = \"label\"> = SelectPrimitive.SelectLabelProps<T> & {\n class?: string | undefined\n}\n\nconst SelectLabel = <T extends ValidComponent = \"label\">(\n props: PolymorphicProps<T, SelectLabelProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectLabelProps, [\"class\"])\n return <SelectPrimitive.Label class={cn(labelVariants(), local.class)} {...others} />\n}\n\ntype SelectDescriptionProps<T extends ValidComponent = \"div\"> =\n SelectPrimitive.SelectDescriptionProps<T> & {\n class?: string | undefined\n }\n\nconst SelectDescription = <T extends ValidComponent = \"div\">(\n props: PolymorphicProps<T, SelectDescriptionProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectDescriptionProps, [\"class\"])\n return (\n <SelectPrimitive.Description\n class={cn(labelVariants({ variant: \"description\" }), local.class)}\n {...others}\n />\n )\n}\n\ntype SelectErrorMessageProps<T extends ValidComponent = \"div\"> =\n SelectPrimitive.SelectErrorMessageProps<T> & {\n class?: string | undefined\n }\n\nconst SelectErrorMessage = <T extends ValidComponent = \"div\">(\n props: PolymorphicProps<T, SelectErrorMessageProps<T>>\n) => {\n const [local, others] = splitProps(props as SelectErrorMessageProps, [\"class\"])\n return (\n <SelectPrimitive.ErrorMessage\n class={cn(labelVariants({ variant: \"error\" }), local.class)}\n {...others}\n />\n )\n}\n\nexport {\n Select,\n SelectValue,\n SelectHiddenSelect,\n SelectTrigger,\n SelectContent,\n SelectItem,\n SelectLabel,\n SelectDescription,\n SelectErrorMessage\n}\n"
1010
}
1111
],
1212
"type": "ui"

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

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { splitProps } from "solid-js"
33

44
import type { PolymorphicProps } from "@kobalte/core/polymorphic"
55
import * as SelectPrimitive from "@kobalte/core/select"
6+
import { cva } from "class-variance-authority"
67

78
import { cn } from "~/lib/utils"
89

@@ -106,4 +107,75 @@ const SelectItem = <T extends ValidComponent = "li">(
106107
)
107108
}
108109

109-
export { Select, SelectValue, SelectHiddenSelect, SelectTrigger, SelectContent, SelectItem }
110+
const labelVariants = cva(
111+
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
112+
{
113+
variants: {
114+
variant: {
115+
label: "data-[invalid]:text-destructive",
116+
description: "font-normal text-muted-foreground",
117+
error: "text-xs text-destructive"
118+
}
119+
},
120+
defaultVariants: {
121+
variant: "label"
122+
}
123+
}
124+
)
125+
126+
type SelectLabelProps<T extends ValidComponent = "label"> = SelectPrimitive.SelectLabelProps<T> & {
127+
class?: string | undefined
128+
}
129+
130+
const SelectLabel = <T extends ValidComponent = "label">(
131+
props: PolymorphicProps<T, SelectLabelProps<T>>
132+
) => {
133+
const [local, others] = splitProps(props as SelectLabelProps, ["class"])
134+
return <SelectPrimitive.Label class={cn(labelVariants(), local.class)} {...others} />
135+
}
136+
137+
type SelectDescriptionProps<T extends ValidComponent = "div"> =
138+
SelectPrimitive.SelectDescriptionProps<T> & {
139+
class?: string | undefined
140+
}
141+
142+
const SelectDescription = <T extends ValidComponent = "div">(
143+
props: PolymorphicProps<T, SelectDescriptionProps<T>>
144+
) => {
145+
const [local, others] = splitProps(props as SelectDescriptionProps, ["class"])
146+
return (
147+
<SelectPrimitive.Description
148+
class={cn(labelVariants({ variant: "description" }), local.class)}
149+
{...others}
150+
/>
151+
)
152+
}
153+
154+
type SelectErrorMessageProps<T extends ValidComponent = "div"> =
155+
SelectPrimitive.SelectErrorMessageProps<T> & {
156+
class?: string | undefined
157+
}
158+
159+
const SelectErrorMessage = <T extends ValidComponent = "div">(
160+
props: PolymorphicProps<T, SelectErrorMessageProps<T>>
161+
) => {
162+
const [local, others] = splitProps(props as SelectErrorMessageProps, ["class"])
163+
return (
164+
<SelectPrimitive.ErrorMessage
165+
class={cn(labelVariants({ variant: "error" }), local.class)}
166+
{...others}
167+
/>
168+
)
169+
}
170+
171+
export {
172+
Select,
173+
SelectValue,
174+
SelectHiddenSelect,
175+
SelectTrigger,
176+
SelectContent,
177+
SelectItem,
178+
SelectLabel,
179+
SelectDescription,
180+
SelectErrorMessage
181+
}

0 commit comments

Comments
 (0)