UNPKG

mp-colorui

Version:

MP ColorUI 是一款基于 Taro 框架并且联合 Color-UI CSS 库开发的多端 UI 组件库(目前仅支持小程序端)

28 lines (26 loc) 996 B
import Taro from "@tarojs/taro-h5"; import Nerv from "nervjs"; import { Switch, View } from '@tarojs/components'; export default class ClSwitch extends Taro.Component { render() { const props = this.props; const title = props.title; const color = props.color || 'green'; const shapeClassName = props.shape !== 'radius' ? '' : 'radius'; const type = props.type === 'form' ? 'form' : 'normal'; const checked = !!props.checked; const hasChecked = checked ? 'checked' : ''; const onChange = e => { props.onChange && props.onChange(e.detail.value); }; const switchComponent = <Switch className={`${color} ${hasChecked} ${shapeClassName} sm`} checked={checked} onChange={onChange} />; const formSwitchComponent = <View className="cu-form-group"> <View className="title">{title}</View> {switchComponent} </View>; return type === 'form' ? formSwitchComponent : switchComponent; } } ClSwitch.options = { addGlobalClass: true };