AI按钮生成器。

描述你的品牌,MeDo即可生成整套按钮体系 — 主要、次要、ghost 与危险操作四种变体,三种尺寸,外加悬停、聚焦、加载和禁用状态。一个提示词,一套统一规范。

按钮
按钮

按钮约占每个设计系统的四分之一

没有哪个组件比按钮用得更频繁。每一次表单提交、每一个CTA、每一个确认弹窗都要经过按钮 — 这正是此处不一致格外扎眼的原因。产品里出现十个略有差异的按钮,早在有人能说清原因之前,就已经给人粗糙的观感。用一段描述一次性生成整套,可以让各个变体在结构上就共享同一套间距阶梯、圆角和聚焦处理,而不必靠人力自律去维持。

6 个模板

可以生成的 按钮 模板

每个模板都是真实的提示词,而不是截图。复制到任意 AI 编辑器,或在 MeDo 中运行,直接拿到 React + Tailwind 代码。

BasicVariant Set

Four Roles, Three Sizes

The set you generate first and edit for a year. Roles rather than colors, so a rebrand moves one token instead of forty class strings.

Create a reusable button component with four role-based variants: primary as a solid brand fill with white text, secondary as a white surface with a grey border, ghost as transparent with a tinted background on hover, and destructive as a solid red. Support sm at 32px tall, md at 40px and lg at 48px, plus a fullWidth prop. Wire hover, active, focus-visible, disabled and loading states for every variant, keeping the focus ring on focus-visible only so mouse clicks do not draw it. Render a real button element with an explicit type attribute, and drive all four variants from one shared spacing and radius scale rather than per-variant values.

在 MeDo 中尝试
IconsIcon + Label

Leading and Trailing Icon Slots

Two slots, one gap token. Most icon bugs are spacing bugs — an icon glued to its label, or optically misaligned because the SVG box is taller than the cap height.

Extend a button component with optional leading and trailing icon slots. Size the icon to 16px at sm and md and 18px at lg, set a consistent 8px gap between icon and label, and add aria-hidden="true" to the icon so screen readers announce the label only. Flip the slot order automatically under a right-to-left direction. Use inline-flex with items-center so the icon aligns to the label cap height rather than the line box, and give the SVG shrink-0 so a long wrapping label cannot squash it. Accept any React node so a spinner or an avatar can occupy the same slot.

在 MeDo 中尝试
LoadingAsync Submit

Loading Button With a Locked Width

A submit button that shrinks when the spinner replaces the label makes the whole form jump. Reserve the width and the click feels instant instead of broken.

Create a submit button with a loading prop. While loading, replace the label with a centered spinner but keep the button at its resting width by rendering the label at zero opacity underneath the spinner rather than removing it from the DOM. Set aria-busy="true" and aria-disabled="true", block repeat submissions, and keep the button focusable so a screen reader can still read the pending state. Respect prefers-reduced-motion by swapping the rotating spinner for a static pulsing dot. Add an optional loadingText prop that announces progress through a polite live region instead of changing the visible label.

在 MeDo 中尝试
ToolbarIcon Only

Square Icon Button With a Tooltip

Dense toolbars need it, and it fails accessibility more often than any other button. No visible text means the accessible name has to come from somewhere explicit.

Create an icon-only button for a dense toolbar: a square target at 32px, 36px and 40px with the icon centered and no label. Require an ariaLabel prop and render it as aria-label on the button, since there is no visible text to name the control. Expand the hit area to at least 44px with a negative-margin pseudo-element so touch targets meet the minimum without widening the toolbar. Pair it with a tooltip that appears on hover and on keyboard focus, referenced with aria-describedby so the tooltip supplements the label rather than replacing it. Include a pressed state driven by aria-pressed for toggle uses.

在 MeDo 中尝试
GroupSplit Action

Split Button With a Menu Half

One default action plus a menu of alternates — Save and Save as, Deploy and Deploy to staging. Two buttons that must look like one and stay independently reachable.

Create a split button: a primary action on the left and a narrow chevron trigger on the right, joined into one visual unit with a 1px divider, the outer corners rounded and the inner corners square. Render them as two separate button elements so each keeps its own accessible name, giving the chevron a label such as "More save options". Wire the chevron to a menu with aria-haspopup="menu" and aria-expanded, opening on click and on ArrowDown, closing on Escape with focus returned to the trigger. Keep the focus ring visible on each half by drawing it outside the shared border rather than inside it.

在 MeDo 中尝试
PolymorphicLink as Button

Anchor With Button Styling

A styled div with an onClick is not a button and a button that navigates is not a link. One asChild prop keeps the styling while the correct element still ships.

Create a polymorphic button that accepts an asChild prop and forwards its variant, size and state classes onto a child element, so a Next.js Link or a plain anchor can carry button styling without nesting an interactive element inside a button. Forward the ref, merge className rather than overwriting it, and skip the type attribute when the rendered element is not a button. When the target is an anchor, omit the disabled attribute — which anchors ignore — and instead drop href and set aria-disabled with pointer-events none. Add an external variant that appends rel="noopener noreferrer" and a visually hidden "opens in a new tab" note.

在 MeDo 中尝试

如何自定义你的 按钮

定义变体,而不只是颜色

按角色而非颜色来要求变体 — primary、secondary、ghost、destructive。基于角色的命名能经受品牌改版:品牌色变更时,"primary"的含义不变,只需改动一个 token。

明确指定加载状态

说明加载指示器应替换文字标签,同时保持按钮宽度。否则按钮会在提交过程中收缩,带动周围布局跳动 — 这是生成式UI中最常见的细节缺陷之一。

要求 focus-visible,而不是 focus

:focus 的聚焦环在鼠标点击时也会出现,看起来像个bug。指定 :focus-visible,聚焦环只对键盘和辅助技术用户显示,这也正是无障碍审计真正检查的行为。

确定禁用状态的语义

决定禁用按钮使用 disabled 属性还是 aria-disabled。前者会拦截包括聚焦在内的所有事件;aria-disabled 让按钮仍可聚焦,屏幕阅读器因而能说明它为何不可用。明确告诉MeDo你要哪一种。

谁在使用 按钮 组件

SaaS 产品

试用CTA用主按钮,"预约演示"用次要按钮,卡片内的三级链接用 ghost,删除账号用危险操作变体 — 全部共享同一圆角与聚焦环,让整个界面读起来像同一个产品。

电商店铺

高对比度的"加入购物车"按钮在库存校验期间展示加载状态,再配一个更低调的"稍后再买"次要变体,不与主按钮争夺注意力。

仪表盘或后台工具

高密度工具栏需要带无障碍标签的小尺寸纯图标按钮,与标准尺寸的操作按钮并列。一套覆盖 sm 到 lg 的尺寸阶梯就能让工具栏保持紧凑,而不必临时造样式。

营销落地页

首屏放一个超大主按钮,页面底部再重复一次;引导滚动而非转化的次要链接"看看它如何工作"使用 ghost 变体。

不同网站的 按钮 方案

同一个 按钮 组件,针对它所在网站的类型做调整。

01 / 06

SaaS Product Buttons

One primary per screen is the rule that keeps a product feeling directed. Everything else drops to secondary or ghost, and destructive stays reserved for irreversible actions so a red button always means the same thing. The moment two primaries appear in one view, users start reading the layout instead of acting on it.

按钮 的风格与变体

挑选与页面其余部分匹配的变体,然后生成它。

01 / 06

Solid Button

A filled surface with white or near-white text, carrying the highest visual weight on the page. Check the contrast against the fill rather than the page background, and remember that a lightened hover state can quietly drop a passing 4.5:1 pairing below the line.

在 React、Next.js、Vue 与 Svelte 中使用 按钮

React、Next.js、Vue 3、SvelteKit、Astro 或纯 HTML —— 同一个 按钮,六种接入方式。

01 / 06

React Button

Derive the class string from variant and size lookups instead of chained ternaries, and forward the ref so tooltips and popovers can anchor to the element. Spread the remaining props last so a caller can still pass type or aria attributes through.

src/components/Button.tsx

export const Button = forwardRef(function Button(
  { variant = 'primary', size = 'md', loading, ...props },
  ref
) {
  return (
    <button
      ref={ref}
      type="button"
      aria-busy={loading}
      className={cn(base, variants[variant], sizes[size])}
      {...props}
    />
  )
})

如何把 按钮 加入项目

四个步骤,从挑选 按钮 模板到上线生产环境。

01~30s

Pick a Button Template

Scan the six templates and start from the closest surface — the full variant set for a design system, the async submit for a form, the icon-only for a toolbar.

02~10s

Copy the Prompt

Take the prompt into MeDo, Lovable, Bolt, v0 or Cursor. Swap in your brand color, radius and font before you run it, since those three values are what every variant inherits.

03~1min

Generate and Refine

You get React + Tailwind back with a live preview. Follow up in plain English — "add an xs size", "make the disabled state use aria-disabled" — rather than hand-editing the class lookups.

04~2min

Replace Your Ad-Hoc Buttons

Import one Button and delete the one-off styles it supersedes. The value is in the variants sharing a spacing scale and focus ring by construction, which only holds if nothing else on the page is styling its own button.

关于 按钮 的常见问题

如何用AI生成按钮组件?

在一个提示词中描述所需的变体、尺寸和状态 — 例如"primary、secondary 和 ghost 三种变体,三个尺寸,带悬停、禁用和加载状态" — MeDo会生成接好全部组合的完整组件。你得到的是覆盖整套的一个文件,而不是一个写死的按钮。

设计系统应该有哪些按钮变体?

多数产品需要四种:primary 对应屏幕上最重要的单一操作,secondary 对应辅助操作,ghost 或三级用于高密度界面中的弱化操作,destructive 用于任何不可撤销的操作。变体多于此通常说明层级关系有问题,而不是缺少样式。

AI能生成无障碍的按钮吗?

可以。MeDo渲染带显式 type 属性的真实 button 元素、focus-visible 聚焦环、纯图标按钮的无障碍名称,以及能被屏幕阅读器正确播报的禁用状态。在提示词中提到无障碍,它还会在加载期间添加 aria-busy。

如何为按钮添加加载状态?

要求一个 loading 属性:用加载指示器替换标签、固定按钮宽度、禁用交互,并设置 aria-busy,让辅助技术播报待处理状态。固定宽度正是最容易被遗漏的一环 — 没有它,每次点击页面都会重排。

按钮应该用 button 还是链接?

如果是跳转,就应该是 anchor;如果是执行操作,就应该是 button。告诉MeDo你想要哪种行为,它会渲染正确的元素;当你需要把按钮样式用在路由链接上时,还提供类似 asChild 的逃生通道。

能生成符合我现有品牌的按钮吗?

可以。在提示词里给出品牌色、圆角半径、字体和已有的间距阶梯,生成的各个变体会一致地使用它们。你也可以粘贴代码库中已有的按钮,请MeDo将它扩展成完整的变体集合。