@asphalt-react/button

中文文档
2.19.0发布于 2026/10/29UNLICENSEDTypeScriptESM + CJS近 30 天下载 1965

Button

原始使用文档
文档目录29 节
  1. Usage
  2. Variants & Intents
  3. Sizes
  4. Link styled as Button
  5. Split Button
  6. Accessibility
  7. Accessibility must-haves
  8. Props
  9. children
  10. primary
  11. secondary
  12. tertiary
  13. nude
  14. brand
  15. danger
  16. system
  17. link
  18. as
  19. asProps
  20. icon
  21. compact
  22. qualifier
  23. qualifierEnd
  24. size
  25. stretch
  26. stickStart
  27. stickEnd
  28. stick
  29. underline

Button

npm npm version

Buttons provide a way to trigger an action. The caption of a Button should hint what action it'll perform. The caption is typically text but Buttons can also have an icon with text or just an icon (which we call as Icon Button).

Buttons's caption decides its width by default, but it can also stretch to take its container's width. Buttons can form a group by sticking to each other enabling use cases like split button.

Usage

import { Button } from '@asphalt-react/button'

<Button>Click me</Button>

Variants & Intents

Buttons come in 4 variants to emphasize different levels:

  • Primary (default): For strong call to an action.
  • Secondary: For supporting primary buttons.
  • Tertiary: For actions less important than primary actions.
  • Nude: For least important actions.

There are 3 intents, which paired with the above variants address multiple supportive actions:

  • Brand (default): For most recommended action.
  • Danger: For actions that have some element of risk like deletion.
  • System: For less recommended actions.

Variants and an intents are mutually exclusive. Button falls back to the default value if a variant or intent occurs more than once. For example, using primary and nude together will fallback to a primary variant.

Sizes

Buttons support 4 sizes: - extra small (xs) - small (s) - medium (m) - large (l)

Button features the ability to render a semantic link styled as a button (which we call Link Button). Link Buttons and Icon Link Buttons — icon as caption — handle security and privacy risks if the link opens in a new tab.

Split Button

You can make a split button by grouping a default action button with a menu button.

Set stickEnd to true on start button and stickStart to true on the end button.

Use stick prop optionally on the the end button to enhance it's style in order to make default and menu button look good together. stick adds spacing to the left of the primary, tertiary & nude variant buttons, in case of secondary variant it removes the left border.

import { Button } from '@asphalt-react/button'

<div>
    <Button stickEnd>Default action</Button>
    <Button stickStart stick>Menu</Button>
</div>

Accessibility

  1. Buttons accept React ref to give access to the underlying element.

  2. They accept most of the button element's attributes such as disabled & onClick and supports data-* attributes.

  3. The rendered button element has a type attribute set to "button". You may override the type attribute if needed.

  4. All buttons are focusable and keyboard navigable; tab (or shift+tab when tabbing backwards).

  5. space and enter keys trigger the buttons when in focus.

  6. enter key triggers the link buttons when in focus.

  7. All buttons accept the aria-* attributes button role.

  8. Link buttons accept the aria-* attributes for the link role.

Accessibility must-haves

Add aria-label or aria-labelledby in Icon Button to help assistive technologies.

Props

children

React node for button's caption

typerequireddefault
nodetrueN/A

primary

Renders a primary variant

typerequireddefault
boolfalsefalse

secondary

Renders a secondary variant

typerequireddefault
boolfalsefalse

tertiary

Renders a tertiary variant

typerequireddefault
boolfalsefalse

nude

Renders a nude variant

typerequireddefault
boolfalsefalse

brand

Renders brand intent

typerequireddefault
boolfalsefalse

danger

Renders danger intent

typerequireddefault
boolfalsefalse

system

Renders system intent

typerequireddefault
boolfalsefalse

Renders a link button

typerequireddefault
boolfalsefalse

as

Link element to render. Accepts an HTML element or a React component.

typerequireddefault
elementTypefalse"a"

asProps

Accepts props & attributes for the link element.

typerequireddefault
objectfalse{ href: "." }

icon

Renders an icon button

typerequireddefault
boolfalsefalse

compact

Shrinks the size of the Button keeping the size of the contents intact. Useful for use-cases with space-constraints.

typerequireddefault
boolfalsefalse

qualifier

Qualifier is an icon or a word that enhances the caption. Button prepends the qualifier by default. Accepts SVG for icons. Checkout @asphalt-react/iconpack for SVG wrapped React components.

⚠️ Do not use qualifier to render an icon button, use icon prop instead

typerequireddefault
unionfalsenull

qualifierEnd

Appends qualifier to the caption

typerequireddefault
boolfalsefalse

size

Controls size of button. Possible values are "xs", "s", "m", "l" for extra small, small, medium & large respectively

typerequireddefault
enumfalse"m"

stretch

Stretches Button to take it's container width

typerequireddefault
boolfalsefalse

stickStart

Adapts to let other buttons stick to its start

typerequireddefault
boolfalsefalse

stickEnd

Adapts to let other buttons stick to its end

typerequireddefault
boolfalsefalse

stick

Enhances the style of the supporting button.

typerequireddefault
boolfalsefalse

underline

Adds underline in link Button

typerequireddefault
boolfalsetrue

版本与发布记录

@asphalt-react/button 共发布 48 个版本,首次发布于 2022/03/30;过去 12 个月发布了 12 个版本。

版本发布日期距今
2.19.0latest2026/10/2910 天前
2.18.02026/10/071 个月前
2.16.1-canary.02026/08/172 个月前
2.16.02026/07/283 个月前
2.15.12026/04/286 个月前
2.15.02026/04/136 个月前

其他发布通道:next → 2.0.0-alpha.29。

关于 @asphalt-react/button 的常见问题

@asphalt-react/button 是什么?

Button

如何安装 @asphalt-react/button?

在项目目录运行 npm install @asphalt-react/button,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>= 16.8.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@asphalt-react/button 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@asphalt-react/button 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@asphalt-react/button 可以商用吗?

@asphalt-react/button 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@asphalt-react/button 的下载量有多少?

根据 npm 官方下载统计,@asphalt-react/button 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,965 次,日均约 66 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@asphalt-react/button 还在维护吗?

最新版本 2.19.0 发布于 2026/10/29(10 天前);至今共发布 48 个版本,其中过去 12 个月发布了 12 个;首次发布于 2022/03/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。