Cell 单元格

介绍

单元格为列表中的单个展示项。

引入

import { Cell } from "@taroify/core"

代码演示

基础用法

Cell 可以单独使用,也可以与 Cell.Group 搭配使用,Cell.Group 可以为 Cell 提供上下外边框。

<Cell title="单元格">内容</Cell>
<Cell title="单元格" brief="描述信息">内容</Cell>

卡片风格

通过 Cell.Groupinset 属性,可以将单元格转换为圆角卡片风格。卡片模式不会显示上下外边框。

<Cell.Group inset>
  <Cell title="单元格">内容</Cell>
  <Cell title="单元格">内容</Cell>
</Cell.Group>

单元格大小

通过 size 属性可以控制单元格的大小。

<Cell title="单元格">内容</Cell>
<Cell title="单元格" brief="描述信息" size="large">内容</Cell>

展示图标

通过 icon 属性在标题左侧展示图标。

<Cell icon={<LocationOutlined />} title="单元格">
  内容
</Cell>

只设置内容

只设置 children 时,内容会靠左对齐。

<Cell>内容</Cell>

展示箭头

设置 isLink 属性后会在单元格右侧展示箭头,并且可以通过 arrowDirection 控制箭头方向。

<Cell title="单元格" isLink />
<Cell title="单元格" isLink children="内容" />
<Cell title="单元格" isLink arrowDirection="down" children="内容" />

页面导航 v1.0.1

使用 Cell.Link 可以通过 Taro Navigator 完成页面跳转。Cell.Link 默认展示右侧箭头并开启点击反馈。

<Cell.Link title="订单详情" url="/pages/order/detail/index">
  查看
</Cell.Link>
<Cell.Link title="返回上一页" openType="navigateBack" />

额外内容 v1.0.1

通过 extra 属性可以在右侧图标之后放置额外内容。

<Cell title="消息通知" isLink extra={<Switch checked />}>
  已开启
</Cell>

分组标题

通过 Cell.Grouptitle 属性可以指定分组标题。

<Cell.Group title="分组 1">
  <Cell title="单元格">内容</Cell>
</Cell.Group>
<Cell.Group title="分组 2">
  <Cell title="单元格">内容</Cell>
</Cell.Group>

对齐方式

通过 align 属性可以改变 Cell 的左右内容的对齐方式。

<Cell title="单元格" brief="align start" size="large" align="start">内容</Cell>
<Cell title="单元格" brief="align center" size="large" align="center">内容</Cell>
<Cell title="单元格" brief="align end" size="large" align="end">内容</Cell>

升级提示

  • Cell.Group 的标题和内容容器现在是同级节点,传入的原生 View 属性会作用于内容容器。
  • Cell.Groupinset 模式下不再显示上下外边框。
  • Cell 显式设置的 clickable 优先于 isLinkCell.Group clickable
  • iconrightIcon 会被统一的布局节点包裹,自定义图标会自动获得标准间距和对齐。
  • size="large" 现在会正确应用大尺寸描述文字样式。

API

Cell.Group Props

参数说明类型默认值
title分组标题ReactNode-
inset是否展示为圆角卡片风格booleanfalse
bordered是否显示非卡片模式的外边框booleantrue
clickable是否为子单元格开启点击反馈booleanfalse

Cell Props

参数说明类型默认值
title左侧标题ReactNode-
children右侧内容ReactNode-
brief标题下方的描述信息ReactNode-
size v1.0.1单元格大小,可选值为 normal largemedium 已废弃stringnormal
icon左侧图标图片ReactNode-
rightIcon右侧自定义图标ReactNode-
extra v1.0.1右侧图标之后的额外内容ReactNode-
bordered是否显示内边框booleantrue
clickable是否开启点击反馈,显式值优先于分组和链接状态boolean-
isLink是否展示右侧箭头并开启点击反馈booleanfalse
arrowDirection箭头方向,可选值为 left right up downstringright
required是否显示表单必填星号booleanfalse
align对齐方式,可选值为 start center endstring-
titleStyle左侧标题额外样式CSSProperties-
titleClass左侧标题额外类名string-
valueClass右侧内容额外类名string-
briefClass标题下方的描述信息额外类名string-

Cell 还继承了 Taro View 的原生属性。

Cell.Link 支持 Cell 内容与样式属性,并继承 Taro NavigatorurlopenTypetarget 等原生属性。isLinkclickable 的默认值均为 true

Cell Events

事件名说明回调参数
onClick点击单元格时触发event: ITouchEvent

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件。

名称默认值描述
--cell-font-sizevar(--font-size-md)-
--cell-line-height24px * $hd-
--cell-colorvar(--text-color)-
--cell-background-colorvar(--background-color-2)-
--cell-border-colorvar(--border-color)-
--cell-value-colorvar(--gray-6)-
--cell-value-font-size v1.0.1inherit-
--cell-active-colorvar(--active-color)-
--cell-required-colorvar(--danger-color)-
--cell-required-padding-right2px * $hd-
--cell-icon-size16px * $hd-
--cell-left-icon-margin-right v1.0.14px * $hd-
--cell-right-icon-margin-left v1.0.14px * $hd-
--cell-right-icon-color v1.0.1var(--cell-value-color)-
--cell-extra-margin-left v1.0.1var(--padding-base)-
--cell-icon-margin-left4px * $hd即将废弃
--cell-right-icon-margin-right4px * $hd即将废弃
--cell-brief-margin-topvar(--padding-base)-
--cell-brief-font-sizevar(--font-size-sm)-
--cell-brief-line-heightvar(--line-height-sm)-
--cell-brief-colorvar(--gray-6)-
--cell-vertical-padding10px * $hd-
--cell-horizontal-paddingvar(--padding-md)-
--cell-vertical-padding-largevar(--padding-sm)-
--cell-title-font-size-largevar(--font-size-lg)-
--cell-brief-font-size-large v1.0.1var(--font-size-md)-
--cell-value-font-size-large v1.0.1inherit-
--cell-subtitle-font-size-largevar(--font-size-md)即将废弃
--cell-group-background-colorvar(--background-color-2)-
--cell-group-title-colorvar(--gray-6)-
--cell-group-title-paddingvar(--padding-md) var(--padding-md) var(--padding-xs)-
--cell-group-title-font-sizevar(--font-size-md)-
--cell-group-title-line-height16px * $hd-
--cell-group-inset-padding0 var(--padding-md)-
--cell-group-inset-border-radiusvar(--border-radius-lg)-
--cell-group-inset-title-paddingvar(--padding-md) var(--padding-md) var(--padding-xs) var(--padding-xl)-