Styled input group
Five input groups: a text prefix, a suffix, icons, an action button and a segment. Each is sized, token-driven, highlights on focus-within and wraps a real input.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/input-group-styledDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install lucide-reactCopy the source
components/ui/input-group-styled.tsx"use client"
import type * as React from "react"
import { AtSign, Copy, Eye, Search } from "lucide-react"
import { cn } from "@/lib/utils"
/* Input group family: a single-framed unit with addons leaning on TEXT, an ICON or a BUTTON. The root wrapper takes a primary border plus ring through focus-within. Colour comes ONLY from tokens. Size = height (aligned with the base scale). Each wraps a real <input> and passes every native prop through; an Omit is required because of the native `size` clash. The transform transitions are guarded with motion-reduce. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const height: Record<StyledSize, string> = {
sm: "h-8 text-sm",
md: "h-9 text-sm",
lg: "h-10 text-base",
xl: "h-12 text-base",
}
const rootBase =
"group inline-flex w-64 max-w-full items-center overflow-hidden rounded-lg border border-field-border bg-transparent transition-colors duration-(--motion-base) focus-within:border-primary focus-within:ring-[3px] focus-within:ring-ring/50"
const fieldBase =
"h-full w-full min-w-0 bg-transparent px-3 text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"
const addonBase =
"flex h-full shrink-0 select-none items-center gap-1.5 bg-surface-2 px-3 text-muted-foreground [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
type Props = Omit<React.ComponentProps<"input">, "size"> & { size?: StyledSize }
/* Prefix: a token text chip on the left (for example "https://"). */
export function PrefixGroup({ className, size = "md", ...props }: Props) {
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], className)}>
<span className={cn(addonBase, "border-r border-field-border")}>https://</span>
<input {...props} className={cn(fieldBase, "pl-2")} />
</div>
)
}
/* Suffix: a token text chip on the right (for example ".com"). */
export function SuffixGroup({ className, size = "md", ...props }: Props) {
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], className)}>
<input {...props} className={cn(fieldBase, "pr-2")} />
<span className={cn(addonBase, "border-l border-field-border")}>.com</span>
</div>
)
}
/* Icon: a token icon leading and trailing inside the field; turns primary on focus. */
export function IconGroup({ className, size = "md", ...props }: Props) {
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], "px-3", className)}>
<AtSign className="size-4 shrink-0 text-muted-foreground transition-colors group-focus-within:text-primary" />
<input {...props} className={cn(fieldBase, "px-2")} />
<Search className="size-4 shrink-0 text-muted-foreground transition-colors group-focus-within:text-primary" />
</div>
)
}
/* Button: saga yaslanmis token aksiyon butonu (ornek Copy). */
export function ButtonGroup({ className, size = "md", ...props }: Props) {
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], className)}>
<input {...props} className={fieldBase} />
<button
type="button"
className="flex h-full shrink-0 select-none items-center gap-1.5 border-l border-field-border bg-secondary px-3 text-sm font-medium text-secondary-foreground outline-none transition-colors hover:bg-surface-3 focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
>
<Copy />
<span>Copy</span>
</button>
</div>
)
}
/* Segment: solda kucuk token select segmenti + alan. */
export function SegmentGroup({ className, size = "md", ...props }: Props) {
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], className)}>
<select
aria-label="Protocol"
className="h-full shrink-0 select-none border-r border-field-border bg-surface-2 pl-3 pr-2 text-muted-foreground outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
<option value="https">https://</option>
<option value="http">http://</option>
</select>
<input {...props} className={cn(fieldBase, "pl-2")} />
<Eye className="mr-3 size-4 shrink-0 text-muted-foreground" />
</div>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Prefix
A token text prefix attached on the left.
import { PrefixGroup } from "@/components/ui/input-group-styled"
<PrefixGroup placeholder="Value" />Suffix
A token text suffix attached on the right.
import { SuffixGroup } from "@/components/ui/input-group-styled"
<SuffixGroup placeholder="Value" />Icon
A leading or trailing token icon inside the field.
import { IconGroup } from "@/components/ui/input-group-styled"
<IconGroup placeholder="Value" />Button
A token action button attached on the right.
import { ButtonGroup } from "@/components/ui/input-group-styled"
<ButtonGroup placeholder="Value" />Segment
A token segment attached before the input.
import { SegmentGroup } from "@/components/ui/input-group-styled"
<SegmentGroup placeholder="Value" />ai2 Styled input group: 5 styled variations on the token system
The ai2 Styled input group are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around inputs with attached addons. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: focus-within highlights run on token CSS transitions. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the transitions are disabled and the field still focuses.
What is in the ai2 Styled input group?
5 exports in one file: Prefix, Suffix, Icon, Button and Segment. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: focus-within highlights run on token CSS transitions.
- Reduced-motion aware: Under prefers-reduced-motion, the transitions are disabled and the field still focuses.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Styled input group sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.