Button Group
分段控制风格,将多个按钮/链接束在一起。包装器自动去除中间子元素的 border-radius 并合并相邻边框。悬停时由包装器统一应用柔和色调,组件不显得厚重(v0.3.3 改进)。方向:水平(默认)/ 垂直。子元素无需添加 `class="join-item"`(v0.3.3 起不再需要)。
最简(orientation=horizontal 为默认值,无需 join-item)
<x-button-group>
<x-button appearance="outline" color="neutral">Left</x-button>
<x-button appearance="outline" color="neutral">Center</x-button>
<x-button appearance="outline" color="neutral">Right</x-button>
</x-button-group>
orientation=vertical — 纵向拼接
<x-button-group orientation="vertical">
<x-button appearance="outline" color="neutral">Top</x-button>
<x-button appearance="outline" color="neutral">Middle</x-button>
<x-button appearance="outline" color="neutral">Bottom</x-button>
</x-button-group>
with toggle state — 使用 Alpine.js 构建分段控制器(active 项用 primary 填充 + !important 盖过 hover 效果)
Selected:
<div x-data="{ active: 'center' }" class="flex flex-col gap-4">
<x-button-group>
<x-button appearance="outline" color="neutral"
x-bind:class="active === 'left' && '!bg-primary !text-primary-content !border-primary'"
x-bind:aria-pressed="(active === 'left') ? 'true' : 'false'"
x-on:click="active = 'left'">Left</x-button>
<x-button appearance="outline" color="neutral"
x-bind:class="active === 'center' && '!bg-primary !text-primary-content !border-primary'"
x-bind:aria-pressed="(active === 'center') ? 'true' : 'false'"
x-on:click="active = 'center'">Center</x-button>
<x-button appearance="outline" color="neutral"
x-bind:class="active === 'right' && '!bg-primary !text-primary-content !border-primary'"
x-bind:aria-pressed="(active === 'right') ? 'true' : 'false'"
x-on:click="active = 'right'">Right</x-button>
</x-button-group>
<p class="text-xs text-base-content/60">Selected: <span x-text="active" class="font-medium text-base-content"></span></p>
</div>
icon-only buttons — 将正方形图标按钮组合在一起(工具栏风格)
<x-button-group>
<x-button class="w-10 h-10 !p-0" appearance="outline" color="neutral" aria-label="bold">
<x-i type="text-bold" variant="linear" class="w-4 h-4" />
</x-button>
<x-button class="w-10 h-10 !p-0" appearance="outline" color="neutral" aria-label="italic">
<x-i type="text-italic" variant="linear" class="w-4 h-4" />
</x-button>
<x-button class="w-10 h-10 !p-0" appearance="outline" color="neutral" aria-label="underline">
<x-i type="text-underline" variant="linear" class="w-4 h-4" />
</x-button>
</x-button-group>