Box
布局组件

布局组件 / 通用容器

Box

轻量矩形样式容器,支持全部 StyleProps 修饰符。常用于绘制内嵌子卡片、图标圆角底托、色块指示点、渐变块与带边框分组面板。

签名#

签名
<Box
  padding={12}
  background="theme.faint"
  cornerRadius={12}
  borderColor="theme.divider"
  borderWidth={1}
>
  <Text fontWeight="semibold">Subcard</Text>
</Box>
Box · 圆角 12 · 内边距 12
Subcard

属性#

继承全部 StyleProps,常用组合如下:

backgroundstring可选
背景色,可填语义色令牌(如 "theme.faint")、十六进制色值或 "clear"。
gradientGradientSpec可选
渐变背景 { colors: ["#0EA5E9", "#6366F1"], kind?: "linear" }。
materialstring可选
原生毛玻璃材质,可选 "ultraThin"、"thin"、"regular"、"thick"、"pill" 或 "glass"。
cornerRadiusnumber可选
连续曲率圆角半径(pt)。
clipboolean可选
设为 true 时按 cornerRadius 裁剪超出边界的子内容。
borderColorstring可选
描边颜色(需配合 borderWidth)。
borderWidthnumber可选
描边粗细(pt)。
widthnumber可选
固定宽度(pt),例如 width={8} height={8} cornerRadius={4} 可画状态圆点。
heightnumber可选
固定高度(pt)。

示例:状态圆点、图标底托与渐变块#

TSX
<Box width={10} height={10} cornerRadius={5}
  background="theme.success" />

<Box width={36} height={36}
  cornerRadius={10}
  background="theme.accent">
  <Icon name="bolt.fill" color="#FFFFFF" />
</Box>

<Box padding={10} cornerRadius={12}
  gradient={{
    colors: ["#0EA5E9", "#6366F1"],
  }}>
  <Text color="#FFFFFF">Gradient Box</Text>
</Box>
状态点 · 图标底托 · 渐变块
Gradient Box