Button Group
Split Save Button
A split button: the frequent action fires straight away while the rare ones live in a native popover menu — top layer, Esc and outside click come from the browser.
- buttongroup
- split
- popover
- menu
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-003?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-003" (Split Save Button) 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-003.json
Registry item: https://vibeui.ru/r/buttongroup-003.json
Installs to: components/vibeui/buttongroup-003.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
A split button: the frequent action fires straight away while the rare ones live in a native popover menu — top layer, Esc and outside click come from the browser.
A split button with an alternatives menu on the native popover: the main action in one click, the rest behind the caret. Zero dependencies, one file, a server component.
## 3. How to use it
import { Buttongroup003 } from "@/components/vibeui/buttongroup-003"
<Buttongroup003
action="Save"
options={[{ label: "Save and close", hint: "Back to the list" }]}
menuLabel="Other ways to save"
menuId="save-menu"
/>
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-003-* palette — do not swap it for your theme tokens
- the native popover instead of a hand-rolled menu: Esc, outside click and the top layer are already done
- the aria-label on the caret: a button without text is otherwise announced as a meaningless "button"
- the divider drawn with an inset box-shadow — a border between two identical fills leaves a dark seam
- the @supports guard around anchor positioning: without it older browsers park the menu anywhere
- the :not(:popover-open){display:none} rule — otherwise the menu occupies flow space before it opens
## 6. You may change
- the main action caption through action
- the menu contents through options
- the caret's screen-reader name through menuLabel and the menu id through menuId
- the fill colour through accent
## 7. Rules
- menuId must be unique on the page: two split buttons sharing an id open the same menu.
- Menu items are plain buttons without handlers: wire your own onClick at install time.
- The caret is narrow by design, but on a phone the target is under 44 px — enlarge it for touch.
- 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-003.jsonhttps://vibeui.ru/r/buttongroup-003.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в переменных --vibeui-buttongroup-003-*. Серверный: состояние меню держит браузер через popover и popovertarget, клиентского JS нет. Позиционирование берётся из CSS anchor positioning внутри @supports (anchor-name), с position-try-fallbacks:flip-block; где anchor-positioning не поддержан, popover остаётся карточкой по центру экрана — это рабочий вид, а не поломка. Граница между двумя заливками одного цвета нарисована inset box-shadow, потому что рамка на стыке дала бы тёмную линию. Правило [data-part="menu"]:not(:popover-open){display:none} прячет меню до открытия.
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 Buttongroup003Option = {
label: string
hint?: string
}
export type Buttongroup003Props = Omit<
ComponentPropsWithoutRef<"div">,
"children"
> & {
action?: string
options?: Buttongroup003Option[]
menuLabel?: string
menuId?: string
accent?: string
}
// Идея компонента: split-кнопка — частое действие нажимается одним движением,
// а редкие прячутся за стрелкой. Меню открывает нативный popover: верхний
// слой, Esc и клик мимо достаются от браузера, клиентского JS нет вовсе.
// Позицию берёт CSS anchor positioning там, где он поддержан; где нет —
// popover остаётся карточкой по центру экрана, и это рабочий вид.
const STYLES = `
:where([data-vibeui-block="buttongroup-003"]){
--vibeui-buttongroup-003-surface:oklch(1 0 0);
--vibeui-buttongroup-003-fg:oklch(0.26 0.016 265);
--vibeui-buttongroup-003-muted:oklch(0.55 0.014 265);
--vibeui-buttongroup-003-border:oklch(0.9 0.006 265);
--vibeui-buttongroup-003-hover:oklch(0.96 0.004 265);
--vibeui-buttongroup-003-accent:oklch(0.52 0.17 265);
--vibeui-buttongroup-003-accent-dark:oklch(0.45 0.16 265);
--vibeui-buttongroup-003-on-accent:oklch(0.99 0.005 265);
--vibeui-buttongroup-003-radius:0.625rem;
--vibeui-buttongroup-003-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="buttongroup-003"]{
box-sizing:border-box;display:inline-flex;isolation:isolate;
border-radius:var(--vibeui-buttongroup-003-radius);
font-family:var(--vibeui-buttongroup-003-font);
}
[data-vibeui-block="buttongroup-003"] *{box-sizing:border-box}
[data-vibeui-block="buttongroup-003"] [data-part="main"],
[data-vibeui-block="buttongroup-003"] [data-part="more"]{
appearance:none;cursor:pointer;font:inherit;position:relative;z-index:0;
display:inline-flex;align-items:center;justify-content:center;gap:0.5rem;
height:2.375rem;border:0;
background:var(--vibeui-buttongroup-003-accent);
color:var(--vibeui-buttongroup-003-on-accent);
font-size:0.8125rem;font-weight:650;line-height:1;
transition:background-color .16s ease;
}
[data-vibeui-block="buttongroup-003"] [data-part="main"]{
padding:0 1rem;
border-start-start-radius:var(--vibeui-buttongroup-003-radius);
border-end-start-radius:var(--vibeui-buttongroup-003-radius);
}
/* Тонкая светлая полоса вместо рамки: у двух заливок одного цвета
граница между ними иначе не читается. */
[data-vibeui-block="buttongroup-003"] [data-part="more"]{
width:2.125rem;
box-shadow:inset 1px 0 0 var(--vibeui-buttongroup-003-on-accent);
border-start-end-radius:var(--vibeui-buttongroup-003-radius);
border-end-end-radius:var(--vibeui-buttongroup-003-radius);
}
[data-vibeui-block="buttongroup-003"] [data-part="main"]:hover,
[data-vibeui-block="buttongroup-003"] [data-part="more"]:hover{background:var(--vibeui-buttongroup-003-accent-dark)}
[data-vibeui-block="buttongroup-003"] [data-part="main"]:focus-visible,
[data-vibeui-block="buttongroup-003"] [data-part="more"]:focus-visible{
z-index:1;
outline:2px solid var(--vibeui-buttongroup-003-accent-dark);outline-offset:2px;
}
[data-vibeui-block="buttongroup-003"] [data-part="caret"]{
width:0.4375rem;height:0.4375rem;margin-top:-0.25rem;
border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;
transform:rotate(45deg);
}
[data-vibeui-block="buttongroup-003"] [data-part="menu"]{
box-sizing:border-box;width:min(15rem,calc(100vw - 2rem));
padding:0.3125rem;margin:0;
border:1px solid var(--vibeui-buttongroup-003-border);
border-radius:var(--vibeui-buttongroup-003-radius);
background:var(--vibeui-buttongroup-003-surface);
font-family:var(--vibeui-buttongroup-003-font);
box-shadow:0 18px 40px -22px oklch(0.2 0.02 265 / 60%);
}
[data-vibeui-block="buttongroup-003"] [data-part="menu"]:not(:popover-open){display:none}
[data-vibeui-block="buttongroup-003"] [data-part="menu"] button{
appearance:none;cursor:pointer;font:inherit;
display:block;width:100%;text-align:start;
padding:0.4375rem 0.5rem;border:0;border-radius:0.4375rem;background:transparent;
color:var(--vibeui-buttongroup-003-fg);font-size:0.8125rem;font-weight:500;
}
[data-vibeui-block="buttongroup-003"] [data-part="menu"] button:hover{background:var(--vibeui-buttongroup-003-hover)}
[data-vibeui-block="buttongroup-003"] [data-part="menu"] button:focus-visible{
outline:2px solid var(--vibeui-buttongroup-003-accent);outline-offset:-2px;
}
[data-vibeui-block="buttongroup-003"] [data-part="hint"]{
display:block;margin-top:0.0625rem;
font-size:0.75rem;font-weight:400;color:var(--vibeui-buttongroup-003-muted);
}
@supports (anchor-name:--vibeui-buttongroup-003-a){
[data-vibeui-block="buttongroup-003"] [data-part="more"]{anchor-name:--vibeui-buttongroup-003-a}
[data-vibeui-block="buttongroup-003"] [data-part="menu"]{
position:fixed;position-anchor:--vibeui-buttongroup-003-a;
position-area:bottom span-left;margin-top:0.375rem;
position-try-fallbacks:flip-block;
}
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="buttongroup-003"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_OPTIONS: Buttongroup003Option[] = [
{ label: "Сохранить и закрыть", hint: "Вернуться к списку" },
{ label: "Сохранить как черновик", hint: "Не показывать читателям" },
{ label: "Сохранить копию", hint: "Оригинал останется без изменений" },
]
/**
* Split-кнопка: основное действие слева, остальные — в popover-меню.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Buttongroup003({
action = "Сохранить",
options = DEFAULT_OPTIONS,
menuLabel = "Другие способы сохранить",
menuId = "vibeui-buttongroup-003-menu",
accent,
className,
style,
...props
}: Buttongroup003Props) {
const palette = {
...(accent ? { "--vibeui-buttongroup-003-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-buttongroup-003" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="buttongroup-003"
role="group"
aria-label={action}
className={className}
style={palette}
>
<button type="button" data-part="main">
{action}
</button>
<button
type="button"
data-part="more"
popoverTarget={menuId}
aria-label={menuLabel}
>
<span data-part="caret" aria-hidden="true" />
</button>
<div id={menuId} popover="auto" data-part="menu" aria-label={menuLabel}>
{options.map((option) => (
<button key={option.label} type="button">
{option.label}
{option.hint ? <span data-part="hint">{option.hint}</span> : null}
</button>
))}
</div>
</div>
</>
)
}