@edux-design/buttons

中文文档
0.3.4发布于 2026/11/03TypeScriptESM + CJS近 30 天下载 2175

Headless-ish button primitives wired to the Edux design tokens. The package ships five components:

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Accessibility notes
  4. Key props
  5. Shared control sizes
  6. Development
  7. Additional components

@edux-design/buttons

Headless-ish button primitives wired to the Edux design tokens. The package ships five components:

  • Button - primary action button with size + variant helpers.
  • IconButton - circular icon-only button surface.
  • MenuButton - semantic menu trigger button.
  • ButtonGroup - segmented control with a sliding active state meant for contextual filters.
  • ButtonCounter - increment/decrement control with optional editable value.

Everything is built with Tailwind utilities via the shared cx helper so styling stays consistent with the rest of the system.


Installation

pnpm add @edux-design/buttons @edux-design/utils
# or
npm install @edux-design/buttons @edux-design/utils

Peer deps: @edux-design/tokens@>=0.2.0 <0.3.0, react@^19.1.0, react-dom@^19.1.0.


Usage

import {
  Button,
  ButtonCounter,
  ButtonGroup,
  ButtonGroupItem,
  IconButton,
  MenuButton,
} from "@edux-design/buttons";
import { Close, Warning } from "@edux-design/icons";

export function Actions({ menuOpen, setMenuOpen }) {
  return (
    <div className="flex gap-4">
      <Button size="small">Save</Button>
      <Button isSecondary isStretched>
        Cancel
      </Button>
      <Button isDanger disabled>
        Delete
      </Button>
      <IconButton icon={<Close aria-hidden="true" />} aria-label="Close dialog" />
      <MenuButton
        aria-expanded={menuOpen}
        aria-controls="actions-menu"
        onClick={() => setMenuOpen((prev) => !prev)}
      >
        Options
      </MenuButton>
      <ButtonCounter defaultValue={2} min={1} aria-label="Quantity" />
    </div>
  );
}

export function SegmentedFilter() {
  const [value, setValue] = React.useState("inbox");

  return (
    <ButtonGroup value={value} onChange={(nextValue) => setValue(nextValue)}>
      <ButtonGroupItem value="inbox">Inbox (11)</ButtonGroupItem>
      <ButtonGroupItem value="drafts">Drafts (11)</ButtonGroupItem>
      <ButtonGroupItem
        value="alerts"
        endAdornment={<Warning className="h-4 w-4 text-warning-600" />}
      >
        Alerts
      </ButtonGroupItem>
    </ButtonGroup>
  );
}

Accessibility notes

  • IconButton requires an accessible name via aria-label or aria-labelledby.
  • MenuButton renders a native <button> and defaults aria-haspopup to "menu".
  • ButtonGroup uses radiogroup semantics with roving tabIndex and supports arrow keys plus home/end.
  • ButtonCounter exposes its value through a labelled output in display mode and a native spinbutton in editable mode.

Key props

ComponentImportant props
Button`size="small"
IconButtonicon, size, isBare, isDanger, disabled, aria-label / aria-labelledby
MenuButtonNative button props, size, caret, aria-expanded, aria-controls
ButtonGroupvalue / defaultValue, onChange, size, isStretched, per-option startAdornment / endAdornment, disabled
ButtonCountervalue / defaultValue, min, max, step, isEditable, inputProps

Buttons warn in development if you pass conflicting variant booleans so you know which style wins. IconButton also warns when it is missing an accessible name.

Shared control sizes

Button components map their public size names to the semantic control-size contract from @edux-design/tokens:

Public sizeToken utilityComputed size
smallcontrol-sm36px
mediumcontrol-md44px
largecontrol-lg56px

Button uses the shared height, IconButton and ButtonCounter controls use the shared square size, and MenuButton uses the shared minimum height. Component-specific content widths remain owned by their component.


Development

pnpm --filter @edux-design/buttons lint
pnpm --filter @edux-design/buttons check-types
pnpm --filter @edux-design/buttons build

Stories live under src/demo (for example Button.stories.jsx and ButtonGroup.stories.jsx) for quick visual verification.

Additional components

Toolbar controls.

Button merges className after its defaults using the shared cx contract, as IconButton does. Host utilities follow the existing shared merge rules. Use size for standard control heights; a deliberate Tailwind important utility such as h-32! or a native style can override semantic geometry. Keyboard focus keeps the normal semantic shadow and gains a 2px system Highlight outline with a 2px offset in forced colours. Keep a visible focus indicator when deliberately overriding focus utilities.

版本与发布记录

@edux-design/buttons 共发布 17 个版本,首次发布于 2025/09/10;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.3.4latest2026/11/0310 天前
0.3.32026/11/0113 天前
0.3.22026/10/3114 天前
0.3.12026/10/2915 天前
0.3.02026/10/2816 天前
0.2.02026/09/201 个月前

关于 @edux-design/buttons 的常见问题

@edux-design/buttons 是什么?

Headless-ish button primitives wired to the Edux design tokens. The package ships five components:

如何安装 @edux-design/buttons?

在项目目录运行 npm install @edux-design/buttons,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.1.0)、react-dom(^19.1.0)、@edux-design/tokens(^0.2.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@edux-design/buttons 支持 TypeScript 吗?

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

@edux-design/buttons 支持 ESM 还是 CommonJS?

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

@edux-design/buttons 可以商用吗?

@edux-design/buttons 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@edux-design/buttons 的下载量有多少?

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

@edux-design/buttons 还在维护吗?

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