跳转到内容
Nacre
组件配色
EN

行内动作 InlineAction

experimentalInlineAction · InlineLink在画廊运行
InlineAction
在浏览器里运行真实组件。

行内操作用 InlineAction;正文里指向地址的文字用 InlineLink。

状态:experimental · 组件:InlineAction、InlineLink

import { InlineAction, InlineLink } from 'nacre'

包任意行内内容,文字排版由调用处决定。

import { Text, View, signal } from 'nsh'
import { InlineAction, Icon, TEXT_SIZE } from 'nacre'
export function InlineActionUsage() {
const count = signal(0)
const label = () => '打开工单'
return <View class="gap-3 items-start">
<InlineAction testID="inline-action" label={label()} tooltip={label()} onPress={() => count.update((n) => n + 1)}>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>已创建工单 <Text class="font-medium">C20261125</Text></Text>
</InlineAction>
<InlineAction label="回拨" padded={false} class="flex-row items-center gap-1" onPress={() => count.update((n) => n + 1)}>
<Text class={`${TEXT_SIZE.title} text-foreground`}>138 0000 0000</Text><Icon name="phone" size={12} />
</InlineAction>
<InlineAction testID="inline-disabled" disabled label={label()} onPress={() => count.update((n) => n + 1)}><Text class={`${TEXT_SIZE.small}`}>不可用</Text></InlineAction>
<Text testID="inline-count" class={`${TEXT_SIZE.caption} tabular-nums text-muted-foreground`}>{`count=${count()}`}</Text>
</View>
}

参照 Radix Themes Link 的行内排版和下划线:https://www.radix-ui.com/themes/docs/components/link 。显示文案可短于完整地址。原生版用 NSH Text 文字跨度跟随段落折行,由 onOpen 打开目的地;嵌在正文中时没有独立 Tab 停靠点。

import { Text, View, signal } from 'nsh'
import { InlineLink, TEXT_SIZE } from 'nacre'
export function InlineLinkUsage() {
const target = signal('')
const href = 'https://example.com/help'
return (
<View class="gap-2">
<Text testID="demo-link-paragraph" class={`${TEXT_SIZE.body} text-foreground`}>
参阅:
<InlineLink testID="demo-inline-link" label="example.com/help" href={href} onOpen={(url) => target.set(url)} />
</Text>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>{target()}</Text>
</View>
)
}
键 行为
Tab 聚焦入口
Space / Return 触发动作
  • InlineAction 的 label 是按钮名;InlineLink 报 link 角色,独立使用时读完整地址,macOS 段内链接读可见文字。

该用

  • 保留业务读屏名
  • 按下只换底色,不缩放

不该用

  • 嵌套可点控件
属性 类型 默认 说明
label * string — 读屏名;内容可以有分段字重与外部字阶
tooltip string —
padded boolean — 默认水平内缩 6pt;贴齐外部文字时关闭
disabled boolean —
onPress () => void —
class string —
testID string —
viewRef (node: ViewRef) => void —
children JSX.Element —

* 必填

属性 类型 默认 说明
label * string — 显示的文字;可短于完整地址
href * string — 完整目的地,由调用方打开;独立链接以此命名,macOS 段内链接读可见文字
onOpen * (href: string) => void —
tone 'brand' | 'neutral' | 'inverse' — 默认品牌链接色;次要资料用正文色,品牌实底用反色,始终保留下划线
class string —
testID string —

* 必填