Button
通过 Proto UI 适配器运行的 Shadcn 风格按钮。
按钮用于触发操作。这是 Proto UI 基于 Base Button 维护的非官方 Shadcn 投射。预览使用当前工作区的 WC、React、Vue 3 与 Vue 2.6 源码;包安装与视觉验收结果分别记录。
Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div id="button-demo" class="flex flex-wrap items-center justify-center gap-3">
<proto-ui-shadcn-button>Default</proto-ui-shadcn-button>
<div>
<proto-ui-shadcn-button>Default2</proto-ui-shadcn-button>
</div>
<proto-ui-shadcn-button>Outline</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Destructive</proto-ui-shadcn-button>
<proto-ui-shadcn-button><span aria-hidden="true">+</span><span class="sr-only">Add</span></proto-ui-shadcn-button>
<proto-ui-shadcn-button>Disabled</proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const props = [
{ styleProfile: 'rhea' },
{ styleProfile: 'rhea' },
{ styleProfile: 'rhea', variant: 'outline' },
{ styleProfile: 'rhea', variant: 'destructive' },
{ styleProfile: 'rhea', variant: 'ghost', size: 'icon' },
{ styleProfile: 'rhea', disabled: true },
];
document.querySelectorAll('#button-demo proto-ui-shadcn-button').forEach((button, index) => {
if (!(button instanceof HTMLElement)) throw new Error('Missing example Button');
setElementProps(button, props[index]);
});
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<div>
<ShadcnButton styleProfile="rhea">Default2</ShadcnButton>
</div>
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost" size="icon">
<span aria-hidden="true">+</span><span className="sr-only">Add</span>
</ShadcnButton>
<ShadcnButton styleProfile="rhea" disabled>Disabled</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<div>
<ShadcnButton styleProfile="rhea">Default2</ShadcnButton>
</div>
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost" size="icon"><span aria-hidden="true">+</span><span class="sr-only">Add</span></ShadcnButton>
<ShadcnButton styleProfile="rhea" :disabled="true">Disabled</ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<div>
<ShadcnButton styleProfile="rhea">Default2</ShadcnButton>
</div>
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost" size="icon"><span aria-hidden="true">+</span><span class="sr-only">Add</span></ShadcnButton>
<ShadcnButton styleProfile="rhea" :disabled="true">Disabled</ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }先初始化已有应用。已发布的稳定版 0.2.0 基线使用:
npx @proto.ui/cli@0.2.0 add wc shadcn-button
pnpm dlx @proto.ui/cli@0.2.0 add wc shadcn-button稳定版 React、Vue 3 分别把 wc 换为 react、vue。CLI 按自身精确版本安装 @proto.ui/prototypes-shadcn 与对应 Adapter,并生成本地 facade。Vue 2.6(>=2.6.0 <2.7)与下面的命名 style profile 需要配套的工作区 0.3 CLI/Adapter/Prototype 源码。稳定版 @latest 不能证明这些能力已交付,工作区 0.3.0-alpha.1 manifest 也不能证明 registry 已发布。
每个 Code 面板都包含注册或 import 与应用示例样式表。生成的 proto-ui-style.css 应在应用入口导入一次。WC 使用生成的 proto-ui-shadcn-button 标签;React 导出具名示例供已有应用渲染,Vue 示例是单文件组件。相对路径应与初始化后的项目布局一致。少量布局与隐藏标签样式由应用拥有,不要求额外配置 Tailwind。
这些 Shadcn Rhea 示例显式请求 styleProfile="rhea",与预览的公开 Shadcn style scope 选择一致。当前源码识别 vega、nova、maia、lyra、mira、luma、sera、rhea 与 new-york-v4,new-york 是旧风格别名。省略或使用 inherit 时先读取最近 scope,再回退到 Button 的 Rhea 配方。这些示例展示 Rhea,不代表每个 profile 或组件都已完成视觉验收。
Variant 矩阵
Section titled “Variant 矩阵”下面一起展示当前六种 variant。link 是命令按钮的视觉 variant,不提供 href 或导航行为。
Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div id="button-variants-demo" class="flex flex-wrap items-center justify-center gap-3">
<proto-ui-shadcn-button>Default</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Secondary</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Outline</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Ghost</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Destructive</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Link</proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const props = [
{ styleProfile: 'rhea', variant: 'default' },
{ styleProfile: 'rhea', variant: 'secondary' },
{ styleProfile: 'rhea', variant: 'outline' },
{ styleProfile: 'rhea', variant: 'ghost' },
{ styleProfile: 'rhea', variant: 'destructive' },
{ styleProfile: 'rhea', variant: 'link' },
];
document.querySelectorAll('#button-variants-demo proto-ui-shadcn-button').forEach((button, index) => {
if (!(button instanceof HTMLElement)) throw new Error('Missing variant Button');
setElementProps(button, props[index]);
});
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonVariantsDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="secondary">Secondary</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost">Ghost</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="link">Link</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="secondary">Secondary</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost">Ghost</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="link">Link</ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="secondary">Secondary</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost">Ghost</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="link">Link</ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div class="flex flex-wrap items-center gap-3">
<proto-ui-shadcn-button id="default-button">Default</proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const button = document.querySelector('#default-button');
if (!(button instanceof HTMLElement)) throw new Error('Missing #default-button');
setElementProps(button, { styleProfile: 'rhea' });
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonDefaultDemo() {
return (
<div className="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div class="flex flex-wrap items-center gap-3">
<proto-ui-shadcn-button id="secondary-button">Secondary</proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const button = document.querySelector('#secondary-button');
if (!(button instanceof HTMLElement)) throw new Error('Missing #secondary-button');
setElementProps(button, { styleProfile: 'rhea', variant: 'secondary' });
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonSecondaryDemo() {
return (
<div className="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="secondary">Secondary</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="secondary">Secondary</ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="secondary">Secondary</ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div class="flex flex-wrap items-center gap-3">
<proto-ui-shadcn-button id="outline-button">Outline</proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const button = document.querySelector('#outline-button');
if (!(button instanceof HTMLElement)) throw new Error('Missing #outline-button');
setElementProps(button, { styleProfile: 'rhea', variant: 'outline' });
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonOutlineDemo() {
return (
<div className="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="outline">Outline</ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div id="ghost-demo" class="flex flex-wrap items-center gap-3">
<proto-ui-shadcn-button>Ghost</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Disabled ghost</proto-ui-shadcn-button>
<div role="status" aria-live="polite">Enabled activations: 0; disabled activations: 0</div>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const demo = document.querySelector('#ghost-demo');
if (!(demo instanceof HTMLElement)) throw new Error('Missing #ghost-demo');
const buttons = demo.querySelectorAll('proto-ui-shadcn-button');
const counts = [0, 0];
buttons.forEach((button, index) => {
if (!(button instanceof HTMLElement)) throw new Error('Missing Ghost Button');
setElementProps(button, { styleProfile: 'rhea', variant: 'ghost', disabled: index === 1 });
button.addEventListener('click', (event) => {
if (!(event instanceof CustomEvent) || event.target !== button) return;
counts[index]++;
demo.querySelector('[role="status"]').textContent =
'Enabled activations: ' + counts[0] + '; disabled activations: ' + counts[1];
});
});
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { useState } from 'react';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonGhostDemo() {
const [enabled, setEnabled] = useState(0);
const [disabled, setDisabled] = useState(0);
return (
<div className="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="ghost" onClick={() => setEnabled((n) => n + 1)}>Ghost</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost" disabled onClick={() => setDisabled((n) => n + 1)}>Disabled ghost</ShadcnButton>
<div role="status" aria-live="polite">Enabled activations: {enabled}; disabled activations: {disabled}</div>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ref } from 'vue';
import { ShadcnButton } from '../proto-ui/components/vue';
const enabled = ref(0);
const disabled = ref(0);
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="ghost" @click="enabled++">Ghost</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost" :disabled="true" @click="disabled++">Disabled ghost</ShadcnButton>
<div role="status" aria-live="polite">Enabled activations: {{ enabled }}; disabled activations: {{ disabled }}</div>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="ghost" @click="enabled++">Ghost</ShadcnButton>
<ShadcnButton styleProfile="rhea" variant="ghost" :disabled="true" @click="disabled++">Disabled ghost</ShadcnButton>
<div role="status" aria-live="polite">Enabled activations: {{ enabled }}; disabled activations: {{ disabled }}</div>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: { ShadcnButton },
data() { return { enabled: 0, disabled: 0 }; },
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div class="flex flex-wrap items-center gap-3">
<proto-ui-shadcn-button id="destructive-button">Destructive</proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const button = document.querySelector('#destructive-button');
if (!(button instanceof HTMLElement)) throw new Error('Missing #destructive-button');
setElementProps(button, { styleProfile: 'rhea', variant: 'destructive' });
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonDestructiveDemo() {
return (
<div className="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" variant="destructive">Destructive</ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }可以使用 sm、default、lg、icon 或扩展的 icon-compact。icon-compact 固定为 1.75rem 正方形,启用 wrap 后也不会改变。
两个图标尺寸示例都保留视觉隐藏的“Add”内容,并把装饰性加号从可访问树中隐藏。Button 发出通常的 click signal,具体动作由消费应用拥有。仅有 glyph 不能提供可访问名称。
Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div id="button-sizes-demo" class="flex flex-wrap items-center justify-center gap-3">
<proto-ui-shadcn-button>Small</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Default</proto-ui-shadcn-button>
<proto-ui-shadcn-button>Large</proto-ui-shadcn-button>
<proto-ui-shadcn-button><span aria-hidden="true">+</span><span class="sr-only">Add</span></proto-ui-shadcn-button>
<proto-ui-shadcn-button><span aria-hidden="true">+</span><span class="sr-only">Add</span></proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const props = [
{ styleProfile: 'rhea', size: 'sm' },
{ styleProfile: 'rhea', size: 'default' },
{ styleProfile: 'rhea', size: 'lg' },
{ styleProfile: 'rhea', size: 'icon', variant: 'outline' },
{ styleProfile: 'rhea', size: 'icon-compact', variant: 'outline' },
];
document.querySelectorAll('#button-sizes-demo proto-ui-shadcn-button').forEach((button, index) => {
if (!(button instanceof HTMLElement)) throw new Error('Missing size Button');
setElementProps(button, props[index]);
});
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonSizesDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea" size="sm">Small</ShadcnButton>
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<ShadcnButton styleProfile="rhea" size="lg">Large</ShadcnButton>
<ShadcnButton styleProfile="rhea" size="icon" variant="outline">
<span aria-hidden="true">+</span><span className="sr-only">Add</span>
</ShadcnButton>
<ShadcnButton styleProfile="rhea" size="icon-compact" variant="outline">
<span aria-hidden="true">+</span><span className="sr-only">Add</span>
</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea" size="sm">Small</ShadcnButton>
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<ShadcnButton styleProfile="rhea" size="lg">Large</ShadcnButton>
<ShadcnButton styleProfile="rhea" size="icon" variant="outline"><span aria-hidden="true">+</span><span class="sr-only">Add</span></ShadcnButton>
<ShadcnButton styleProfile="rhea" size="icon-compact" variant="outline"><span aria-hidden="true">+</span><span class="sr-only">Add</span></ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center justify-center gap-3">
<ShadcnButton styleProfile="rhea" size="sm">Small</ShadcnButton>
<ShadcnButton styleProfile="rhea">Default</ShadcnButton>
<ShadcnButton styleProfile="rhea" size="lg">Large</ShadcnButton>
<ShadcnButton styleProfile="rhea" size="icon" variant="outline"><span aria-hidden="true">+</span><span class="sr-only">Add</span></ShadcnButton>
<ShadcnButton styleProfile="rhea" size="icon-compact" variant="outline"><span aria-hidden="true">+</span><span class="sr-only">Add</span></ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }禁用按钮会抑制激活,并在所有宿主中保留一致的禁用语义。
Scroll to see all hosts →
import './styles/proto-ui-style.css';
import './button-demo.css';
import '../proto-ui/components/wc';<div class="flex flex-wrap items-center gap-3">
<proto-ui-shadcn-button id="disabled-button">Disabled</proto-ui-shadcn-button>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const button = document.querySelector('#disabled-button');
if (!(button instanceof HTMLElement)) throw new Error('Missing #disabled-button');
setElementProps(button, { styleProfile: 'rhea', disabled: true });
</script>
<script type="module" src="/src/main.ts"></script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/react';
export function DemoButtonDisabledDemo() {
return (
<div className="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" disabled>Disabled</ShadcnButton>
</div>
);
}/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<script setup lang="ts">
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue';
</script>
<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" :disabled="true">Disabled</ShadcnButton>
</div>
</template>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }<template>
<div class="flex flex-wrap items-center gap-3">
<ShadcnButton styleProfile="rhea" :disabled="true">Disabled</ShadcnButton>
</div>
</template>
<script>
import './styles/proto-ui-style.css';
import './button-demo.css';
import { ShadcnButton } from '../proto-ui/components/vue2';
export default {
components: {
ShadcnButton,
},
};
</script>/* Application-owned example layout and visually hidden labels. */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-3 { gap: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }导航、分组与 busy 状态
Section titled “导航、分组与 busy 状态”导航使用原生 anchor,保留真实 URL 与完整文本:阅读快速开始。等价的应用组合为:
<a href="/zh-cn/start-here/quick-start/">阅读快速开始</a>不要把 anchor 放进 Button,也不要发明 asChild、href、loading 或 isLoading prop。Base 始终拥有激活与禁用。真实异步动作由应用维护 pending 状态、驱动 disabled、保留有意义的名称并报告进度与完成;仅显示 spinner 既不是 busy 状态,也不是激活门控。
普通布局可以把独立动作排列成组;需要相应键盘模型时采用文档中的 Toolbar。专门的 Button Group API、loading/spinner 组合、图标与文本矩阵、全 profile 证据和原生链接视觉对比仍是 #1042 的独立条件,本试点不声称已完成这些条件。
| 属性 | 类型 | 默认值 |
|---|---|---|
styleProfile | ShadcnStyleChoice(见用法) | inherit → 最近 scope → rhea |
variant | 'default' 'destructive' 'outline' 'secondary' 'ghost' 'link' | default |
size | 'default' 'sm' 'lg' 'icon' 'icon-compact' | default |
disabled | boolean | false |
wrap | boolean | false |
生命周期与证据
Section titled “生命周期与证据”P-SHADCN-BUTTON 与 P-BASE-BUTTON 保持 draft。既有预览与源码不是新的包、浏览器、焦点、屏幕阅读器或完整上游对齐证据。文档检查点与 Button 实现证据保留其实际 revision。运行时切换、窄屏、移动端与文字放大仍需要绑定候选源码的观察。