跳到主要内容

Text 文本

对Text的封装,对主题色、字号等进行了主题配置,对常用css的快捷属性封装

示例

import { Card, TestIcon, Text, Header, ScrollView, TopView, GroupList, Space } from '@/duxuiExample'

export default function TextExample() {
return <TopView>
<Header title='Text' />
<ScrollView>
<GroupList>
<GroupList.Item title='基础用法'>
<Card>
<Space>
<Text type='primary'>primary</Text>
<Text type='secondary'>secondary</Text>
<Text type='success'>success</Text>
<Text type='danger'>danger</Text>
<Text type='warning'>warning</Text>
<Text color={1}>color1</Text>
<Text color={2}>color2</Text>
<Text color={3}>color3</Text>
<Text color={4}>color4</Text>
</Space>
</Card>
</GroupList.Item>
<GroupList.Item title='大小'>
<Card>
<Space>
<Text size={1}>size1</Text>
<Text size={2}>size2</Text>
<Text size={3}>size3</Text>
<Text size={4}>size4</Text>
<Text size={5}>size5</Text>
<Text size={6}>size6</Text>
<Text size={7}>size7</Text>
</Space>
</Card>
</GroupList.Item>
<GroupList.Item title='样式'>
<Card>
<Space>
<Text delete size={5}>删除线</Text>
<Text underline size={5}>下划线</Text>
<Text bold size={5}>加粗</Text>
</Space>
</Card>
</GroupList.Item>
<GroupList.Item title='省略'>
<Card>
<Space>
<Text size={5} numberOfLines={1}>A design is a plan or specification for the construction of an object or system or for the implementation of an activity or process, or the result of that plan or specification in the form of a prototype, product or process. The verb to design expresses the process of developing a design. In some cases, the direct construction of an object without an explicit prior plan (such as in craftwork, some engineering, coding, and graphic design) may also be considered to be a design activity</Text>
<Text size={5} numberOfLines={2}>A design is a plan or specification for the construction of an object or system or for the implementation of an activity or process, or the result of that plan or specification in the form of a prototype, product or process. The verb to design expresses the process of developing a design. In some cases, the direct construction of an object without an explicit prior plan (such as in craftwork, some engineering, coding, and graphic design) may also be considered to be a design activity</Text>
</Space>
</Card>
</GroupList.Item>
<GroupList.Item title='嵌套'>
<Card>
<Space>
<Text delete size={5}>
删除线
<Text underline size={5}>下划线</Text>
<Text color={3}>颜色1</Text>
<Text type='primary'>颜色2</Text>
</Text>
</Space>
</Card>
</GroupList.Item>
<GroupList.Item title='图标组合'>
<Card>
<Space>
<Text size={5} onClick={e => console.log('文本点击')}>
删除线
<Text color={3}>颜色1</Text>
<TestIcon name='weixinzhifu' />
<Text type='primary'>颜色2<TestIcon name='buji' onClick={e => console.log('嵌套使用,里面的元素将失去点击事件')} /></Text>
</Text>
</Space>
</Card>
</GroupList.Item>
</GroupList>
</ScrollView>
</TopView>
}

Props

继承自Taro的Text Props

type

文本主题色

类型必填默认值
enum('primary', 'secondary', 'success', 'danger', 'warning')

color

文本颜色 1-4是配置的主题颜色,优先级高于 type

类型必填默认值
1 | 2 | 3 | 4 | string

size

文字大小 数字1-7使用的是主题配置的字号 数字大于等于12时,将使用px处理

类型必填默认值
1 | 2 | 3 | 4 | 5 | 6 | 7 | number3

bold

是否加粗

类型必填默认值
booleanfalse

delete

是否有删除线

类型必填默认值
booleanfalse

underline

是否有下划线

类型必填默认值
booleanfalse

numberOfLines

显示的行数,超出部分将被截断

可能还需要配合父元素的布局,否则可能不会生效

类型必填默认值
number

break

是否强制换行

RN不支持此属性

类型必填默认值
booleanfalse

align

文本对齐方式

类型必填默认值
enum('left', 'center', 'right', 'justify')left

children

子元素 子元素只能是 文本、Text组件、图标组件

类型必填默认值
string | ReactElement

grow

设置为true相当于 flex: 1

类型必填默认值
booleanfalse

shrink

设置为true相当于 flex-shrink: 0

类型必填默认值
booleanfalse

self

align-self 的封装

类型必填默认值
enum('start', 'end', 'center', 'baseline', 'stretch')