JGuang

可选卡片

SelectableCard · Astryx

交互预览
npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0

可选卡片 · SelectableCard

通过卡片选择一个或多个选项。

安装与前置条件

npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0

需要 React 19+,按顺序导入基础 CSS 和主题,并设置 Theme Provider。参见开始使用。

示例与使用方式

  • 可选卡片 · 综合展示 1:首先体验这个示例,再查看代码理解组件的组合方式。
  • 可选卡片 · 交互示例 2:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 可选卡片 · 交互示例 3:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。

API 与上游详细参考

优先使用 0.7.1 官方中文说明;上游尚未提供中文的条目保留英文。属性名、类型及默认值保持原生 API,不把示例状态名称当成组件属性。

Selectable Card

A card that toggles between selected and unselected states with an accent border. For navigation use ClickableCard.

属性类型默认值说明
label *stringAccessibility label.
isSelected *booleanControlled selection state.
onChange *(isSelected: boolean) => voidCalled when toggled.
isDisabledbooleanfalseDisables the card.
childrenReactNodeCard content.
padding0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 104Inner padding.
variant'default' | 'transparent' | 'muted' | 'blue' | 'cyan' | 'gray' | 'green' | 'orange' | 'pink' | 'purple' | 'red' | 'teal' | 'yellow''default'Background color variant.
elevation'none' | 'low' | 'med' | 'high''none'Resting shadow depth. The selection ring composes on top, so a selected card keeps its shadow.
widthSizeValueCard width.
heightSizeValueCard height.
maxWidthSizeValueMaximum card width.
xstyleStyleXStylesStyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.

使用建议

  • Use for plan pickers, filter chips, or option grids.
  • For single-select track one ID; for multi-select use a Set.
  • When focused, toggle selection with Space or Enter.
  • 避免:Use for navigation; use ClickableCard for that.

主题 API

{
  "container": true,
  "targets": [
    {
      "className": "astryx-selectable-card",
      "visualProps": [
        "selected",
        "variant"
      ]
    }
  ],
  "vars": [
    {
      "name": "--selectable-card-ring-color",
      "description": "Colour of the selection ring drawn for a variant a theme added. The built-in variants each ring in their own border token and ignore this; a theme that adds a variant sets it in the same rule as that variant's `backgroundColor`, because no token the component could pick is guaranteed to contrast with a fill it cannot know.",
      "default": "var(--color-accent)"
    },
    {
      "name": "--_press-overlay",
      "description": "Fill of the ::after interaction overlay: transparent at rest, the hover overlay token on hover (hover-capable pointers), the pressed overlay token while pressed (`:active` on a mouse; `data-astryx-press=\"on\"` written by the touch press controller under a finger) and the hover token for the release fade. Set on the card element by its own interaction arms.",
      "default": "transparent",
      "private": true
    },
    {
      "name": "--_press-overlay-transition",
      "description": "Duration of the overlay's background-color transition: the fast duration token, except 0s while a believed touch press paints so it lands on the first frame.",
      "default": "var(--duration-fast)",
      "private": true
    }
  ]
}

组件结构

  • Container: Interactive div with accent border on selection.
  • Content: Children rendered inside the card.