Button Group
Save And Close
Two submit buttons sharing a name with different values: the browser tells the intents apart, and the server needs neither a hidden field nor JS.
- buttongroup
- form
- submit
- intent
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-038?lang=en
Enter в поле формы отправит «Сохранить»
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-038" (Save And Close) 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-038.json
Registry item: https://vibeui.ru/r/buttongroup-038.json
Installs to: components/vibeui/buttongroup-038.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
Two submit buttons sharing a name with different values: the browser tells the intents apart, and the server needs neither a hidden field nor JS.
A pair of submit buttons that carry the intent through name and value. Zero dependencies, one file, a server component.
## 3. How to use it
import { Buttongroup038 } from "@/components/vibeui/buttongroup-038"
<Buttongroup038
saveLabel="Save"
closeLabel="Save and close"
intentName="intent"
label="Finish editing"
/>
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-038-* palette — do not swap it for your theme tokens
- the shared name with different values: this is the only way to tell the intents apart without JS
- the button order — Enter in a field submits the first one, and that must be the safe action
- the seam drawn with an inset box-shadow: a border between two identical fills leaves a dark line
- the div root rather than a form: nested forms are invalid, the component lives inside someone else's
- the Enter hint as text — the default behaviour is otherwise invisible
## 6. You may change
- the action captions through saveLabel and closeLabel
- the intent field name through intentName
- the note under the buttons through note and the group name through label
- the fill colour through accent
## 7. Rules
- The values are hard-coded as save and save-and-close: the server has to expect exactly those.
- The buttons do not validate the form themselves: the browser and your code do that.
- Outside a form neither button submits anything — this is part of a form, not a decorative cluster.
- 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-038.jsonhttps://vibeui.ru/r/buttongroup-038.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-038-*. Серверный: обе кнопки — настоящие type="submit" с одинаковым name и разными value, поэтому браузер отправит пару только той кнопки, которую нажали. Это единственная встроенная в HTML возможность различить «сохранить» и «сохранить и закрыть». Главная кнопка стоит первой по DOM: при Enter в поле формы отправляется первая submit-кнопка, и это должно быть безопасное действие. Обе кнопки одного цвета, шов между заливками нарисован inset box-shadow — рамка на стыке дала бы тёмную линию. Корень не form: компонент обязан вставляться внутрь чужой формы.
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 Buttongroup038Props = Omit<
ComponentPropsWithoutRef<"div">,
"children"
> & {
saveLabel?: string
closeLabel?: string
intentName?: string
note?: string
label?: string
accent?: string
}
// Идея компонента: два исхода одной отправки формы. Обе кнопки — настоящие
// submit с одинаковым name и разными value: браузер отправит пару только той
// кнопки, которую нажали, и серверу не нужен ни скрытый input, ни JS, чтобы
// понять намерение. Это единственная встроенная в HTML возможность различить
// «сохранить» и «сохранить и закрыть», и её стоит предпочесть обработчику.
// Главная кнопка первая по порядку DOM: при Enter в поле формы отправляется
// именно первая submit-кнопка, и это должно быть безопасное действие.
const STYLES = `
:where([data-vibeui-block="buttongroup-038"]){
--vibeui-buttongroup-038-surface:oklch(1 0 0);
--vibeui-buttongroup-038-fg:oklch(0.25 0.016 265);
--vibeui-buttongroup-038-muted:oklch(0.56 0.014 265);
--vibeui-buttongroup-038-border:oklch(0.88 0.008 265);
--vibeui-buttongroup-038-accent:oklch(0.48 0.15 265);
--vibeui-buttongroup-038-on-accent:oklch(0.99 0.004 265);
--vibeui-buttongroup-038-radius:0.625rem;
--vibeui-buttongroup-038-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-038"]{
box-sizing:border-box;display:inline-flex;flex-direction:column;gap:0.5rem;
font-family:var(--vibeui-buttongroup-038-font);
}
[data-vibeui-block="buttongroup-038"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-038"] [data-part="track"]{
display:flex;isolation:isolate;
border-radius:var(--vibeui-buttongroup-038-radius);
box-shadow:0 1px 2px oklch(0.2 0.03 265 / 14%);
}
[data-vibeui-block="buttongroup-038"] button{
appearance:none;cursor:pointer;font:inherit;
position:relative;z-index:0;
display:inline-flex;align-items:center;gap:0.4375rem;
height:2.375rem;padding:0 0.9375rem;
border:1px solid var(--vibeui-buttongroup-038-accent);
background:var(--vibeui-buttongroup-038-accent);
color:var(--vibeui-buttongroup-038-on-accent);
font-size:0.8125rem;font-weight:650;line-height:1;white-space:nowrap;
transition:background-color .16s ease;
}
[data-vibeui-block="buttongroup-038"] button:first-child{
border-start-start-radius:var(--vibeui-buttongroup-038-radius);
border-end-start-radius:var(--vibeui-buttongroup-038-radius);
}
[data-vibeui-block="buttongroup-038"] button:last-child{
border-start-end-radius:var(--vibeui-buttongroup-038-radius);
border-end-end-radius:var(--vibeui-buttongroup-038-radius);
}
/* Шов между двумя заливками одного цвета: рамка дала бы тёмную линию. */
[data-vibeui-block="buttongroup-038"] button + button{
margin-inline-start:-1px;
box-shadow:inset 1px 0 0 oklch(1 0 0 / 34%);
background:oklch(0.44 0.14 265);
}
[data-vibeui-block="buttongroup-038"] button:hover{background:oklch(0.42 0.14 265)}
[data-vibeui-block="buttongroup-038"] button:focus-visible{
z-index:1;outline:2px solid var(--vibeui-buttongroup-038-fg);outline-offset:2px;
}
[data-vibeui-block="buttongroup-038"] svg{
width:0.9375rem;height:0.9375rem;
stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;
}
[data-vibeui-block="buttongroup-038"] [data-part="note"]{
margin:0;color:var(--vibeui-buttongroup-038-muted);
font-size:0.75rem;line-height:1.4;
}
[data-vibeui-block="buttongroup-038"] kbd{
padding:0.0625rem 0.3125rem;border-radius:0.25rem;
border:1px solid var(--vibeui-buttongroup-038-border);
background:oklch(0.98 0.003 265);
color:var(--vibeui-buttongroup-038-fg);
font:inherit;font-size:0.6875rem;font-weight:650;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-038"] *{animation:none!important;transition:none!important}}
`
/**
* Пара submit-кнопок с общим name и разными value: намерение различает браузер.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Buttongroup038({
saveLabel = "Сохранить",
closeLabel = "Сохранить и закрыть",
intentName = "intent",
note = "в поле формы отправит «Сохранить»",
label = "Завершение правки",
accent,
className,
style,
...props
}: Buttongroup038Props) {
const palette = {
...(accent ? { "--vibeui-buttongroup-038-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-buttongroup-038" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="buttongroup-038"
className={className}
style={palette}
>
<div data-part="track" role="group" aria-label={label}>
<button type="submit" name={intentName} value="save">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M5 4h11l3 3v13H5zM8 4v5h7M8 20v-6h8v6" />
</svg>
{saveLabel}
</button>
<button type="submit" name={intentName} value="save-and-close">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="m5 13 4.5 4.5L19 7" />
</svg>
{closeLabel}
</button>
</div>
<p data-part="note">
<kbd>Enter</kbd> {note}
</p>
</div>
</>
)
}