JGuang

引用来源

Citation · Astryx

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

引用来源 · Citation

引用来源用于内容展示场景。下面的官方示例展示原生用法与状态,属性名保持上游 API。

安装与前置条件

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,不把示例状态名称当成组件属性。

Citation

Citations display inline references to external sources. Use them to attribute information within AI-generated responses, articles, or anywhere provenance and source links are needed.

属性类型默认值说明
source *CitationSourceThe citation source object containing title, url, an optional image src, and an optional icon node. The url follows the shared navigation rule described on the Link href prop; rejected destinations leave the citation visible without navigation. Image src uses separate resource handling.
number *numberThe display index for this citation.
variant'label' | 'number''label'Display style: a label chip showing the source title or a compact numbered badge.

使用建议

  • Use the label variant when the source title adds meaningful context for the reader.
  • Use the number variant for compact inline references within body text, like footnotes.
  • 避免:Mix label and number variants in the same paragraph. Pick one style per context for visual consistency.

主题 API

{
  "targets": [
    {
      "className": "astryx-citation",
      "visualProps": [
        "variant"
      ]
    }
  ]
}

组件结构

  • Container: The root wrapper. Accepted source URLs render an anchor; missing or rejected URLs render an inert span.
  • Icon: An optional source icon shown before the label text. Accepts a favicon/logo image URL (via source.src) or a React node such as an Astryx <Icon>. Only available in the label variant.
  • Label text: The source title, truncated with ellipsis when it exceeds the max width. Shown in the label variant.
  • Number: The citation index displayed as a superscript badge. Shown in the number variant.