Button Group
File Or Link
An attachment source switcher: two joined tabs swap the panel below, and the hidden panel leaves both the flow and the Tab order.
- buttongroup
- tabs
- upload
- css-only
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/buttongroup-037?lang=en
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "buttongroup-037" (File Or Link) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/buttongroup-037.json
Registry item: https://vibeui.ru/r/buttongroup-037.json
Installs to: components/vibeui/buttongroup-037.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
An attachment source switcher: two joined tabs swap the panel below, and the hidden panel leaves both the flow and the Tab order.
Two tabs swapping the panel beneath them without a line of JS. Zero dependencies, one file, a server component.
## 3. How to use it
import { Buttongroup037 } from "@/components/vibeui/buttongroup-037"
<Buttongroup037
fileLabel="Upload a file"
linkLabel="Paste a link"
defaultValue="file"
name="source"
/>
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-buttongroup-037-* palette — do not swap it for your theme tokens
- display:none on the hidden panel: only it removes those fields from the Tab order and the accessibility tree
- radios as the source of state — tab switching would otherwise need JS and its own keyboard
- the inset box-shadow instead of a bottom border on the active tab: a border would shift the content by a pixel
- the shared card border: the track and the panel are one part, not two adjacent blocks
- the label above the URL field — a placeholder is not a label and disappears on input
## 6. You may change
- the tab captions through fileLabel and linkLabel
- the panel copy through filePrompt and linkPrompt
- the initial tab through defaultValue
- the form field prefix through name and the accent through accent
## 7. Rules
- The hidden panel stays in the HTML: its markup is shipped even though it is not shown.
- The two panels use different field names: check on the server which one arrived non-empty.
- There is no real drag and drop here — it is a label for input[type=file], not a handler-driven drop zone.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/buttongroup-037.jsonhttps://vibeui.ru/r/buttongroup-037.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-037-*. Серверный: переключение держат radio, панели показываются правилами [data-vibeui-block]:has([data-mode="file"] input:checked) [data-panel="file"]{display:block}. display:none выбран сознательно: скрытая панель вместе со своими полями честно уходит из доступного дерева и из обхода Tab, чего не даст visibility или прозрачность. Сцепка и панель склеены в одну карточку общей рамкой: у трека скруглены только верхние углы, у карточки — внешние, всё лишнее срезает overflow:hidden. Выбранная вкладка помечена inset box-shadow снизу, а не border, чтобы не сдвигать содержимое.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Buttongroup037Props = Omit<
ComponentPropsWithoutRef<"fieldset">,
"children"
> & {
fileLabel?: string
linkLabel?: string
filePrompt?: string
linkPrompt?: string
defaultValue?: "file" | "link"
name?: string
accent?: string
}
// Идея компонента: сцепка из двух сегментов управляет тем, что лежит под
// ней. Обе панели присутствуют в разметке, но неактивная скрыта правилом
// display:none по состоянию radio — так переключение стоит ноль JS, а
// скрытая панель вместе со своими полями честно уходит из доступного дерева
// и из обхода Tab. Панель и сцепка склеены в одну карточку: у сцепки скруглены
// только верхние углы, у панели — только нижние, и общая рамка не разрывается.
const STYLES = `
:where([data-vibeui-block="buttongroup-037"]){
--vibeui-buttongroup-037-surface:oklch(1 0 0);
--vibeui-buttongroup-037-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-037-muted:oklch(0.57 0.014 265);
--vibeui-buttongroup-037-border:oklch(0.89 0.008 265);
--vibeui-buttongroup-037-accent:oklch(0.5 0.16 265);
--vibeui-buttongroup-037-radius:0.75rem;
--vibeui-buttongroup-037-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-037"]{
box-sizing:border-box;display:block;width:100%;max-width:24rem;
margin:0;padding:0;
border:1px solid var(--vibeui-buttongroup-037-border);
border-radius:var(--vibeui-buttongroup-037-radius);
background:var(--vibeui-buttongroup-037-surface);
overflow:hidden;
font-family:var(--vibeui-buttongroup-037-font);
}
[data-vibeui-block="buttongroup-037"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-037"] legend{
position:absolute;width:1px;height:1px;padding:0;margin:-1px;
overflow:hidden;clip-path:inset(50%);white-space:nowrap;
}
[data-vibeui-block="buttongroup-037"] [data-part="track"]{
display:grid;grid-template-columns:1fr 1fr;
border-bottom:1px solid var(--vibeui-buttongroup-037-border);
background:oklch(0.975 0.003 265);
}
[data-vibeui-block="buttongroup-037"] [data-part="segment"]{
position:relative;
display:inline-flex;align-items:center;justify-content:center;gap:0.4375rem;
height:2.5rem;
color:var(--vibeui-buttongroup-037-muted);
font-size:0.8125rem;font-weight:650;line-height:1;cursor:pointer;
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="buttongroup-037"] [data-part="segment"] + [data-part="segment"]{
border-inline-start:1px solid var(--vibeui-buttongroup-037-border);
}
[data-vibeui-block="buttongroup-037"] input[type="radio"]{
position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer;
}
[data-vibeui-block="buttongroup-037"] svg{
width:1rem;height:1rem;
stroke:currentColor;fill:none;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;
}
[data-vibeui-block="buttongroup-037"] [data-part="segment"]:hover{color:var(--vibeui-buttongroup-037-fg)}
[data-vibeui-block="buttongroup-037"] [data-part="segment"]:has(input:checked){
background:var(--vibeui-buttongroup-037-surface);
color:var(--vibeui-buttongroup-037-accent);
box-shadow:inset 0 -2px 0 var(--vibeui-buttongroup-037-accent);
}
[data-vibeui-block="buttongroup-037"] [data-part="segment"]:has(input:focus-visible){
outline:2px solid var(--vibeui-buttongroup-037-accent);outline-offset:-2px;
}
/* Неактивная панель уходит и из потока, и из обхода Tab. */
[data-vibeui-block="buttongroup-037"] [data-part="panel"]{display:none;padding:0.875rem}
[data-vibeui-block="buttongroup-037"]:has([data-mode="file"] input:checked) [data-panel="file"]{display:block}
[data-vibeui-block="buttongroup-037"]:has([data-mode="link"] input:checked) [data-panel="link"]{display:block}
[data-vibeui-block="buttongroup-037"] [data-part="drop"]{
display:flex;flex-direction:column;align-items:center;gap:0.375rem;
padding:1.125rem 0.75rem;
border:1.5px dashed oklch(0.84 0.01 265);border-radius:0.625rem;
color:var(--vibeui-buttongroup-037-muted);
font-size:0.75rem;line-height:1.4;text-align:center;cursor:pointer;
transition:border-color .16s ease,color .16s ease;
}
[data-vibeui-block="buttongroup-037"] [data-part="drop"]:hover{
border-color:var(--vibeui-buttongroup-037-accent);color:var(--vibeui-buttongroup-037-fg);
}
[data-vibeui-block="buttongroup-037"] [data-part="drop"] input{
position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);
}
[data-vibeui-block="buttongroup-037"] [data-part="url"]{
display:flex;flex-direction:column;gap:0.375rem;
color:var(--vibeui-buttongroup-037-muted);
font-size:0.75rem;line-height:1.4;
}
[data-vibeui-block="buttongroup-037"] [data-part="url"] input{
width:100%;height:2.375rem;padding:0 0.6875rem;
border:1px solid var(--vibeui-buttongroup-037-border);border-radius:0.5rem;
background:var(--vibeui-buttongroup-037-surface);
color:var(--vibeui-buttongroup-037-fg);
font:inherit;font-size:0.8125rem;
}
[data-vibeui-block="buttongroup-037"] [data-part="url"] input:focus-visible{
outline:2px solid var(--vibeui-buttongroup-037-accent);outline-offset:1px;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-037"] *{animation:none!important;transition:none!important}}
`
/**
* Переключатель источника: сцепка из двух сегментов меняет панель под собой.
* Один файл, ноль зависимостей, серверный компонент без JS.
*/
export function Buttongroup037({
fileLabel = "Загрузить файл",
linkLabel = "Дать ссылку",
filePrompt = "Перетащите файл или нажмите, чтобы выбрать. PDF, PNG, до 10 МБ.",
linkPrompt = "Ссылка на файл в вашем хранилище",
defaultValue = "file",
name = "buttongroup-037",
accent,
className,
style,
...props
}: Buttongroup037Props) {
const palette = {
...(accent ? { "--vibeui-buttongroup-037-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-buttongroup-037" precedence="medium">
{STYLES}
</style>
<fieldset
{...props}
data-vibeui-block="buttongroup-037"
className={className}
style={palette}
>
<legend>Источник вложения</legend>
<div data-part="track">
<label data-part="segment" data-mode="file">
<input
type="radio"
name={name}
value="file"
defaultChecked={defaultValue === "file"}
/>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 16V4M8 8l4-4 4 4M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" />
</svg>
{fileLabel}
</label>
<label data-part="segment" data-mode="link">
<input
type="radio"
name={name}
value="link"
defaultChecked={defaultValue === "link"}
/>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M10 13a5 5 0 0 0 7 0l2-2a5 5 0 0 0-7-7l-1 1M14 11a5 5 0 0 0-7 0l-2 2a5 5 0 0 0 7 7l1-1" />
</svg>
{linkLabel}
</label>
</div>
<div data-part="panel" data-panel="file">
<label data-part="drop">
<input type="file" name={`${name}-file`} />
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 16V4M8 8l4-4 4 4M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" />
</svg>
<span>{filePrompt}</span>
</label>
</div>
<div data-part="panel" data-panel="link">
<label data-part="url">
<span>{linkPrompt}</span>
<input
type="url"
name={`${name}-url`}
placeholder="https://disk.example.com/act.pdf"
/>
</label>
</div>
</fieldset>
</>
)
}