0.4.0 • Published 5 years ago

cat-react-tool v0.4.0

Weekly downloads
24
License
BSD
Repository
github
Last release
5 years ago

react-tool 组件库

工具列表

Demo (组件不包括UI样式)

Button 按钮

<Button
    className={ 'my-btn br1' }
    onClick={ this.onClick }
    disabled={ false }
>我是一个按钮</Button>
属性说明类型默认值
disabled?是否禁止点击boolean
onClick?点击触发() => void
className?样式名string
style?styleReact.CSSProperties
type?html的typestring

Toast 提示

Toast({
    duration: 3000,
    text: '我是一个3秒的toast',
})
属性说明类型默认值
text提示文字string
duration?持续时间number3000

Alert 弹出窗口

Alert({
    subtitle: '我是副标题',
    title: '我是一个alert',
})
属性说明类型默认值
title提示标题string
subtitle?提示内容string
noDefault?设置没有取消按钮booleanfalse
noPrimary?设置没有确定按钮booleanfalse
default?点击取消时调用() => void
primary?点击确定时调用() => void

Loading 加载动画

<Loading
   loading={ true }
/>
属性说明类型默认值
loadingloading状态booleanfalse
text?文字内容string加载中

Image 图片

<Image
   className={ 'my-image' }
   src={ 'https://img7.kcimg.cn/uploads/c7/4c/c74cd79689721906d4a5831031a5c8e4.jpg' }
   alt={ '图片' }
/>
属性说明类型默认值
src显示图片地址string
alt?图片文案string
className?样式名称string
defaultSrc?默认图片地址string
onSuccess?成功加载的回调() => void
onError?错误加载的回调(e: any) => void

Select 选择器

// 数据
let data = [{
    value: 0,
    text: '选项1',
    children: [{
        value: 0,
        text: '选项1-1',
    },{
        value: 1,
        text: '选项1-2',
    }]
},{
    value: 1,
    text: '选项2',
    children: [{
        value: 0,
        text: '选项2-1',
    },{
        value: 1,
        text: '选项2-2',
    }]
}]
<Select
    data={ data }
    onConfirm={ this.onConfirm }
    name={ 'username' }
    className={ 'my-select' }
    placeholder={ '请选择名称' }
    length={ 2 }
    error={ '请选择名称' }
/>

举例: 时间选择器城市选择器

// 接口
interface Value {
    text: string;
    value: string | number;
    children?: Value[] | undefined;
}
属性说明类型默认值
data选择器数据Value[][]
nameselect的name属性string
onChange?选择器改变后触发(item: Value[]) => void
onConfirm?确认按钮触发(item: Value[]) => void
placeholder?未选择默认文案string请选择
defaultValue?默认选项Value
className?样式名称string
length?选择器数量number1
type?选择器类型,可选 'date'string
error?错误提示,配合form表单使用,如果设置此项,在form中表示必填string

Input 输入框

<Input
   type={ 'password' }
   maxLength={ 10 }
   name={ 'password' }
   className={ 'my-input' }
   placeholder={ '请输入密码' }
   error={ '请输入密码' }
/>
属性说明类型默认值
nameinput的name属性string
type?input的type属性,若设置为 textarea 则为 textarea元素,mobile 自动设置长度11位验证,调用数字键盘string
maxLength?input的maxLength属性number
className?样式名string
style?styleReact.CSSProperties
placeholder?默认文案string
onInputoninput事件(e) => void
onChangeonchange事件(e) => void
error?错误提示,配合form表单使用,如果设置此项,在form中表示必填string

Form 表单

<Form submit={ this.submit } toast={ Toast }>
   <Input
       type={ 'password' }
       maxLength={ 10 }
       name={ 'password' }
       className={ 'my-input' }
       placeholder={ '请输入密码' }
       error={ '请输入密码' }
   />
   <Date
       begin={ 2008 }
       end={ 2019 }
       onConfirm={ this.onConfirm }
       name={ 'time' }
       className={ 'my-select' }
       placeholder={ '请选择时间' }
       error={ '请选择时间' }
   />
   <Input
       type={ 'textarea' }
       maxLength={ 100 }
       name={ 'textarea' }
       className={ 'my-textarea' }
       placeholder={ '请输入文字' }
       error={ '请输入文字' }
   />
   <Button type={ 'submit' } className={ 'my-btn br1' }>提交</Button>
</Form>
属性说明类型默认值
submit?提交表单 返回表单内input、select、textarea等原生html元素的json对象,例:{password: 123, textarea: 666}(json:object) => void
toast?提示器any
rules?表单字段校验object

Tool 工具

Rem.set(750); 设置html font-size 以设计稿750为基准 1rem == 100px
Rem.get(750); 返回 以750为基准的像素值
@Mounted 装饰器,用于装饰react组件,可以防止组件卸载后调用setState 导致报错的问题
@readonly 装饰器,用于设置属性只读,不可被修改
0.4.0

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago