1.0.0 • Published 4 years ago

durain-ui v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

durain-ui

一套拿来就用的 react-native 纯 js 组件。

TODO

  • Button
  • ButtonGroup
  • ButtonRadio
  • Cell
  • CellGroup
  • InputItem
  • Modal
  • Popup
  • Dialog
  • Toast
  • Tip
  • Carousel

组件使用说明

Button

按钮组件,依赖插件 react-native-linear-gradient 来实现渐变效果

代码示例

<Button type="primary">primary</Button>

<Button gradient gradientColors={['#f00', '#0f0']}>渐变</Button>

API 说明

属性说明类型默认值
type按钮类型,可选值为 defaultprimaryinfowarningsuccesserrorgraygoldentextStringdefault
size按钮大小,可选值为 xssmmdlgxlStringlg
shape按钮形状,可选值为 rectradiuscircleStringcircle
borderRadius圆角大小, 当 shaperadius 时,可通过此属性控制圆角大小Number-
color设置按钮文字颜色String-
backgroundColor设置按钮背景颜色String-
ghost设置幽灵按钮Booleanfalse
outlineType设置按钮边框类型,可选值为 soliddotteddashedStringsolid
outlineColor设置按钮边框颜色String-
outlineWidth设置按钮边框粗细String-
gradient设置渐变按钮Booleanfalse
gradientColors设置渐变颜色Arrayinfo, primary
gradientDirection设置渐变方向Stringhorizontal
gradientProps设置渐变其他属性。因为渐变是通过插件 react-native-linear-gradient 实现的Object-
loading设置按钮为加载中状态Booleanfalse
disabled设置按钮为禁用状态Booleanfalse
icon设置按钮图标Object | Function | element-
iconStyle设置按钮图标样式Object-
iconOnRight设置按钮图标位置在右边Booleanfalse
activityIndicatorColorloading 指示器颜色String默认为文字颜色
containerStyle容器样式Object-
clickInterval连续两次点击间隔 毫秒Numer1000
onPress点击事件event-
onLongPress长按事件event-

ButtonGroup

按钮组 组件

ButtonGroup 代码示例

<ButtonGroup style={styles.btnGroupWrap} size="xs">
  <Button type="primary">是</Button>
  <Button type="error">否</Button>
</ButtonGroup>

ButtonGroup API 说明

属性说明类型默认值
size设置按钮组大小。可选值为:xssmmdlgxlStringmd
radius设置按钮组圆角大小。Number1000
ghost设置幽灵按钮组Booleanfalse
vertical设置垂直按钮组Booleanfalse
style设置按钮组容器样式Object-

Cell

列表组件

Cell 代码示例

<Cell title="2/1期" value="420.0" label="应支付日:2019年06月21日" extra="已逾期" />

<Cell title="验证码" value={<Button size="md" shape="radius" outline type="primary" outlineColor="#f00">获取验证码</Button>} />

Cell API 说明

属性说明类型默认值
title标题 左上角String | element-
value值 右上角String | element-
valuePlace空值 placeholderString | element-
label说明 左下角String | element-
extra附加 右下角String | element-
titleStyle标题样式。同理,还有 valueStylelabelStyleextraStylevaluePlaceStyleObject-
icon设置图标 最左边Object | Function | element-
iconStyle图标样式Object-
link设置箭头样式Booleanfalse
indicator设置指示器 最右边。预设可选值为arrowplus当给定 onPress 后,默认为小箭头Object | Function | elementarrow
indicatorDirection指示器方向 可选值为 updownString-
indicatorStyle指示器样式Object-
line设置底部分割线Boolean-
lineStyle分割线样式Object-
containerWrapStyle容器外层样式 包含内容 和 分割线Object-
containerStyle容器样式 包含 icon 文字 和 指示器Object-
activeOpacity点击透明度,同 TouchableHighlight 属性。当给定 onPress 后,默认为 0.5Number0.5 | 1
underlayColor底色,同 TouchableHighlight 属性。当给定 onPress 后,默认为 #eeeString#eee | transparent
clickInterval点击间隔 毫秒Number0
onPress点击事件Function-

CellGroup

列表容器组件

CellGroup 代码示例

<CellGroup style={{ marginVertical: 20 }} borderOffset={0}>
  <Cell title="2/1期" value="420.0" />
  <Cell title="2/1期" value="420.0" />
  <Cell title="2/1期" value="420.0" />
  <Cell title="2/1期" value="420.0" />
</CellGroup>

CellGroup API 说明

属性说明类型默认值
paddingOffset内部 cell 左右间距Number12
style容器样式Object-

InputItem

输入框组件

InputItem 代码示例

<InputItem label="手机号" />

<InputItem label="密码" type="password" value= {this.state.value1} />

InputItem API 说明

属性说明类型默认值
type输入框类型。可选值为 textareanumberpasswordStringdefault
label标签文字String-
labelPosition标签位置。可选值为 topleftinsideStringleft
labelWidth标签宽度Number-
lableAlign标签对齐方式。可选值为 leftrightStringleft
labelStyle标签样式Object-
icon图标Object | Function | element-
iconStyle图标样式Object-
line设置底部分割线Boolean-
lineColor设置分割线颜色StringTheme.border
lineColorActive设置分割线高亮颜色StringTheme.split_line_active_color
lineStyle分割线样式Object-
showPasswordControl是否显示密码明文控制。当 type 为 passwordBoolean-
extra最右边部分String | Element-
extraStyle最右边部分样式Object-
tip底部提示String | Element-
tipStyle底部提示样式Object-
inputStyle输入框样式Object-
style容器样式Object-
inputRefref。暂时没有搞明白,怎么通过 ref 转发,或者高阶组件的方式实现,只能通过传递属性实现,并且只能是函数Function-
textAlign输入框内文字方向。TextInput 原生属性。可选值为 leftrightStringleft
placeholder占位符。TextInput 原生属性String请输入
placeholderTextColor占位符文字颜色 。TextInput 原生属性String-
maxLength限制文本框中最多的字符数。当 type 为 textarea 时,会显示出来。 TextInput 原生属性Number-
keyboardType键盘类型。TextInput 原生属性String-
clearButtonMode如何展示清除按钮。TextInput 原生属性String-

SplitLine

下划线

SplitLine 代码示例

<SplitLine />

SplitLine API 说明

属性说明类型默认值
width下划线宽度。数字 或者 百分比 '50%'number | string-
type下换线类型。可选值为soliddotteddashedStringsolid
color下划线颜色StringTheme.border
size下划线粗细NumberTheme.pixelSize
opacity下划线透明度number0.9
style自定义下划线样式Object-

Tip

提示组件

Tip 代码示例

<Tip type="error" radius={0}>radius: 0</Tip>

<Tip icon={tipIcon} extra={<Button type="primary" size="xs">立即拨打</Button>}>客服热线:400-0000-0000</Tip>

Tip API 说明

属性说明类型默认值
type主题类型,可选值为 primaryinfowarningsuccesserrorgraygoldenStringprimary
title标题。String-
color自定义主题颜色。边框颜色就是这个值。背景颜色会根据这个颜色变浅。String-
radius圆角大小Number4
icon左边图标Object-
iconStyle图标样式Object-
extra右边追加内容String | Element-
extraStyle右边追加内容样式Object-
style容器样式Object-
children提示文字String | Element-

Carousel

轮播图组件。这个照搬 teaset

Carousel 代码示例

<Carousel
  style={{ height: 100 }}
  horizontal={this.state.horizontal}
  autoPlay={this.state.autoPlay}
  loop={this.state.loop}
  interval={this.state.interval}
  direction={this.state.direction}
  startIndex={this.state.startIndex}
  control={this.state.control}
>
  <View style={{ backgroundColor: Theme.primary, height: '100%' }}><Text>1</Text></View>
  <View style={{ backgroundColor: Theme.info, height: '100%' }}><Text>2</Text></View>
  <View style={{ backgroundColor: Theme.success, height: '100%' }}><Text>3</Text></View>
  <View style={{ backgroundColor: Theme.warning, height: '100%' }}><Text>4</Text></View>
  <View style={{ backgroundColor: Theme.error, height: '100%' }}><Text>5</Text></View>
</Carousel>

Carousel API 说明

属性说明类型默认值
horizontal水平轮播还是垂直轮播Booleantrue
autoPlay自动轮播Booleantrue
interval每页停留时间Number3000
direction方向可选值为 forwardbackwardforward
startIndex初始显示的页数Number0
loop是否循环轮播Booleanfalse
control指示器。为 false 则不显示指示器;若想自定义指示器,传递组件即可,会自动获取三个参数 {index, total, carousel }Boolean | Elementfalse

Modal

弹框组件

Modal 代码示例

<Modal visible={this.state.isShowModal} width="90">
  {this.renderDemoText()}
  <Button type="primary" size="lg">Close</Button>
</Modal>

Modal API 说明

属性说明类型默认值
visible控制弹框显示隐藏Booleanfalse
placement弹框出现位置。可选值为 centertopbottomleftrightString-
animateType弹框动画方式。可选值为 fadescaleslide-topslide-bottomslide-rightslide-leftString-
animateDuration动画持续时间number200
width控制容器宽度。当其值不大于 100 时以百分比显示,大于 100 时为具体值Number100%
radius控制容器圆角大小number5
contentStyle容器样式Object-
mask是否显示遮罩
maskClosable控制点击遮罩层是否可以关闭Booleanfalse
maskBgColor遮罩层背景色Stringrgba(0,0,0,0.6)
onMaskPress遮罩层点击事件Event-
closable是否显示关闭按钮Booleanfalse
closeStyle关闭按钮样式Object-
onClosePress关闭事件Event-
onRequestClose安卓必填。物理键返回函数。Function-

Popup

弹出组件。套用的是 Modal 组件,因此,Modal 的属性,同样适用于 该组件。

Popup 代码示例

<Popup visible={this.state.isShow}>
  ...
</Popup>

Popup API 说明

属性说明类型默认值
visible控制弹框显示隐藏Booleanfalse
placement弹框出现位置Stringbottom
splitLineProps下划线属性Object-

PopupHeader

弹出组件的标题组件。

PopupHeader 代码示例

<Popup visible={this.state.isShow}>
  <PopupHeader onLeftPress={} onRightPress={} />
  ...
</Popup>

PopupHeader API 说明

属性说明类型默认值
title标题string-
leftText左边文字String取消
rightText右边文字String确认
onLeftPress左边点击事件Function-
onRightPress左边点击事件Function-
style自定义 header 样式Object-

ActionSheet

Action Sheet是由用户操作后触发的一种特定的模态弹出框。套用的是 Modal 组件,因此,Modal 的属性,同样适用于 该组件。

menus 数组,是 按钮 的属性对象,因此,可参考 Button 组件

ActionSheet 代码示例

<ActionSheet
  visible={this.state.isShow}
  theme={this.state.theme}
  onMaskPress={() => {this.setValueByKey('isShow', false); }}
  onCancelPress={() => {this.setValueByKey('isShow', false); }}
  menus={menusObj[this.state.menus]}
  maskClosable={this.state.maskClosable}
  showCancel={this.state.showCancel}
  cancelText={this.state.cancelText}
  header={this.state.header ? headerObj[this.state.header] : undefined}
  onMenuPress={(data) => {
    this.setValueByKey('isShow', false);
  }}
>
  {this.renderDemoText()}
  <Button type="primary" size="lg" onPress={() => {this.setValueByKey('isShow', false); }}>close</Button>
</ActionSheet>

ActionSheet API 说明

属性说明类型默认值
visible控制弹框显示隐藏Booleanfalse
menus菜单项列表array-
theme菜单风格。可选值为iosandroidStringios
onMenuPress点击菜单回调事件Function-
showCancel显示取消按钮Booleanfalse
cancelText取消按钮文字number0.9
onCancelPress点击取消事件Function-
cancelProps取消按钮属性Object-
maskClosable背景遮罩是否可点击Booleantrue
header.title标题String | Element-
header.titleSub副标题String | Element-

Dialog

对话框组件,套用的是 Modal 组件,因此,Modal 的属性,同样适用于 该组件。

menus 数组,是 按钮 的属性对象,因此,可参考 Button 组件

Dialog 代码示例

<Dialog
  visible={this.state.isShow}
  onCancelPress={() => {this.setValueByKey('isShow', false); }}
  onMenuPress={(v) => {
    console.log(v, 'menu');
    this.setValueByKey('isShow', false);
  }}
  title="弹框标题"
  msg="弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内"
  menus={this.state.menusObj[this.state.menus]}
>
</Dialog>

Dialog API 说明

属性说明类型默认值
visible控制弹框显示隐藏Booleanfalse
menus操作菜单项列表array-
title标题String-
msg副标题String-
onMenuPress点击菜单回调事件Function-

参考

非常感谢 teaset 这个项目,学到很多。