קבוצת קלט
הוסף סמלים, כפתורים ורמזים למקלדת לשדות קלט של סרגלי חיפוש, שדות כתובת URL ומסכי כתיבת הודעות בצ'אט — עם מסגרות וצללים בסגנון ניאו-ברוטליסטי.
import { Search } from "lucide-react"
import {ה-input group עוטף input או textarea יחד עם התוספות שלהם — אייקונים, טקסט בשורה, כפתורים, רמזי מקלדת — בתוך בקרה אחת עם מסגרת. זו קומפוזיציה פנימית של Input, Textarea ו-Button של הספרייה, מעוצבת לפי המתכון הנאו-ברוטליסטי: מסגרות עבות, צללים חדים וטיפוגרפיה מודגשת.
השתמשו בו כש:
- שדות חיפוש — אייקון חיפוש מוביל ועוד רמז
⌘Kאו כפתור ניקוי מאחור. - שדות עם קידומת וסיומת — טקסט קבוע
https://,@או.comכדי שהמשתמשים יקלידו רק את החלק המשתנה. - מקלידי צ'אט ו-prompt — textarea עם סרגל כלים
block-endשל כפתורים ופעולת שליחה.
התקנה#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/input-group.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/input-group.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/input-group.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/input-group.json
העתיקו והדביקו את הקוד הבא לתוך הפרויקט שלכם.
"use client"
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="input-group"
role="group"
className={cn(
"group/input-group relative flex h-8 w-full min-w-0 items-center rounded border-2 bg-input shadow-sm transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:outline-2 has-[[data-slot=input-group-control]:focus-visible]:outline-offset-2 has-[[data-slot=input-group-control]:focus-visible]:outline-primary has-[[data-slot][aria-invalid=true]]:border-destructive has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
className
)}
{...props}
/>
)
}
const inputGroupAddonVariants = cva(
"flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",
{
variants: {
align: {
"inline-start":
"order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]",
"inline-end":
"order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]",
"block-start":
"order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
"block-end":
"order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2",
},
},
defaultVariants: {
align: "inline-start",
},
}
)
function InputGroupAddon({
className,
align = "inline-start",
...props
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
return (
<div
role="group"
data-slot="input-group-addon"
data-align={align}
className={cn(inputGroupAddonVariants({ align }), className)}
onClick={(e) => {
if ((e.target as HTMLElement).closest("button")) {
return
}
e.currentTarget.parentElement?.querySelector("input")?.focus()
}}
{...props}
/>
)
}
const inputGroupButtonVariants = cva(
"flex items-center gap-2 text-sm shadow-none",
{
variants: {
size: {
xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
sm: "",
"icon-xs":
"size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0",
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
},
},
defaultVariants: {
size: "xs",
},
}
)
function InputGroupButton({
className,
type = "button",
variant = "ghost",
size = "xs",
...props
}: Omit<React.ComponentProps<typeof Button>, "size"> &
VariantProps<typeof inputGroupButtonVariants>) {
return (
<Button
type={type}
data-size={size}
variant={variant}
className={cn(inputGroupButtonVariants({ size }), className)}
{...props}
/>
)
}
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
return (
<span
className={cn(
"flex items-center gap-2 text-sm text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
)
}
function InputGroupInput({
className,
...props
}: React.ComponentProps<"input">) {
return (
<Input
data-slot="input-group-control"
className={cn(
"flex-1 rounded-none border-0 bg-transparent shadow-none outline-none focus-visible:outline-none disabled:bg-transparent aria-invalid:outline-none dark:bg-transparent dark:disabled:bg-transparent",
className
)}
{...props}
/>
)
}
function InputGroupTextarea({
className,
...props
}: React.ComponentProps<"textarea">) {
return (
<Textarea
data-slot="input-group-control"
className={cn(
"flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none outline-none focus-visible:outline-none disabled:bg-transparent aria-invalid:outline-none dark:bg-transparent dark:disabled:bg-transparent",
className
)}
{...props}
/>
)
}
export {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupText,
InputGroupInput,
InputGroupTextarea,
}
עדכנו את נתיבי הייבוא כך שיתאימו למבנה הפרויקט שלכם.
שימוש#
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupInput,
InputGroupText,
InputGroupTextarea,
} from "@/components/ui/input-group"<InputGroup>
<InputGroupInput placeholder="Search..." />
<InputGroupAddon>
<SearchIcon />
</InputGroupAddon>
</InputGroup>קומפוזיציה#
השתמשו בקומפוזיציה הבאה כדי לבנות InputGroup:
InputGroup
├── InputGroupInput or InputGroupTextarea
├── InputGroupAddon
├── InputGroupButton
└── InputGroupTextיישור#
השתמשו ב-prop בשם align על InputGroupAddon כדי למקם את התוסף ביחס לשדה הקלט.
לניהול פוקוס תקין, יש למקם את InputGroupAddon תמיד לאחר InputGroupInput או
InputGroupTextarea ב-DOM. השתמשו ב-prop בשם align כדי למקם את התוסף
חזותית.
inline-start#
השתמשו ב-align="inline-start" כדי למקם את התוסף בתחילת שדה הקלט. זו ברירת המחדל.
import { SearchIcon } from "lucide-react"
import {inline-end#
השתמשו ב-align="inline-end" כדי למקם את התוסף בסוף שדה הקלט.
import { EyeOffIcon } from "lucide-react"
import {block-start#
השתמשו ב-align="block-start" כדי למקם את התוסף מעל שדה הקלט.
import { CopyIcon, FileCodeIcon } from "lucide-react"
import {block-end#
השתמשו ב-align="block-end" כדי למקם את התוסף מתחת לשדה הקלט.
import {
Field,
FieldDescription,דוגמאות#
אייקון#
import {
CheckIcon,
CreditCardIcon,טקסט#
import {
InputGroup,
InputGroupAddon,כפתור#
"use client"
import * as React from "react"Kbd#
import { SearchIcon } from "lucide-react"
import {תפריט נפתח#
"use client"
import { ChevronDownIcon, MoreHorizontal } from "lucide-react"Spinner#
import { LoaderIcon } from "lucide-react"
import {Textarea#
import {
IconBrandJavascript,
IconCopy,שדה מותאם אישית#
הוסיפו את המאפיין data-slot="input-group-control" לשדה הקלט המותאם אישית שלכם עבור טיפול אוטומטי במצב הפוקוס.
לפניכם דוגמה ל-textarea מותאם אישית וניתן לשינוי גודל מספרייה חיצונית.
"use client"
import TextareaAutosize from "react-textarea-autosize"RTL#
כדי להפעיל RTL ב-Neobrutalism, עיינו במדריך ההגדרה של RTL.
"use client"
import * as React from "react"נגישות#
אין דפוס ARIA widget לקבוצות input — העטיפה מרנדרת role="group" כדי שטכנולוגיה מסייעת תקשר את התוספות לבקרה, והגישה במקלדת מקורית: Tab מגיע לשדה ולכל InputGroupButton בסדר DOM, ולכן תוספות שייכות אחרי השדה (ממוקמות ויזואלית עם align). שני דברים נשארים עליכם: טקסט תוספת כמו https:// הוא ויזואלי, לא לייבל פרוגרמטי, כך שהשדה עדיין צריך <Label> או aria-label; וכפתורי אייקון בלבד צריכים aria-label — לחיצה על תוספת ממקדת את השדה, אבל זו נוחות מצביע, לא נתיב מקלדת.
תיעוד ה-API#
InputGroup#
הרכיב המרכזי שעוטף שדות קלט ותוספים.
| Prop | Type | Default |
|---|---|---|
className | string |
<InputGroup>
<InputGroupInput />
<InputGroupAddon />
</InputGroup>InputGroupAddon#
מציג אייקונים, טקסט, כפתורים או תוכן אחר לצד שדות הקלט.
לניווט פוקוס תקין, יש למקם את הרכיב InputGroupAddon לאחר שדה הקלט. הגדירו את
ה-prop בשם align כדי למקם את התוסף.
| Prop | Type | Default |
|---|---|---|
align | "inline-start" | "inline-end" | "block-start" | "block-end" | "inline-start" |
className | string |
<InputGroupAddon align="inline-end">
<SearchIcon />
</InputGroupAddon>עבור <InputGroupInput />, השתמשו ביישור inline-start או inline-end. עבור <InputGroupTextarea />, השתמשו ביישור block-start או block-end.
הרכיב InputGroupAddon יכול להכיל כמה רכיבי InputGroupButton ואייקונים.
<InputGroupAddon>
<InputGroupButton>Button</InputGroupButton>
<InputGroupButton>Button</InputGroupButton>
</InputGroupAddon>InputGroupButton#
מציג כפתורים בתוך קבוצות קלט.
| Prop | Type | Default |
|---|---|---|
size | "xs" | "icon-xs" | "sm" | "icon-sm" | "xs" |
variant | "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | "ghost" |
className | string |
<InputGroupButton>Button</InputGroupButton>
<InputGroupButton size="icon-xs" aria-label="Copy">
<CopyIcon />
</InputGroupButton>InputGroupInput#
תחליף ל-<Input /> בבניית קבוצות קלט. הרכיב הזה מגיע עם סגנונות קבוצת הקלט מוחלים מראש ומשתמש ב-data-slot="input-group-control" המאוחד לטיפול במצב הפוקוס.
| Prop | Type | Default |
|---|---|---|
className | string |
כל שאר ה-props מועברים לרכיב <Input /> הבסיסי.
<InputGroup>
<InputGroupInput placeholder="Enter text..." />
<InputGroupAddon>
<SearchIcon />
</InputGroupAddon>
</InputGroup>InputGroupTextarea#
תחליף ל-<Textarea /> בבניית קבוצות קלט. הרכיב הזה מגיע עם סגנונות קבוצת ה-textarea מוחלים מראש ומשתמש ב-data-slot="input-group-control" המאוחד לטיפול במצב הפוקוס.
| Prop | Type | Default |
|---|---|---|
className | string |
כל שאר ה-props מועברים לרכיב <Textarea /> הבסיסי.
<InputGroup>
<InputGroupTextarea placeholder="Enter message..." />
<InputGroupAddon align="block-end">
<InputGroupButton>Send</InputGroupButton>
</InputGroupAddon>
</InputGroup>