import { View } from "@tarojs/components"; import Taro, { Component, useState } from "@tarojs/taro"; import { classNames } from "../../../lib"; import { IProps } from "../../../../@types/switch"; export default class ClSwitch_h5 extends Component { static options = { addGlobalClass: true }; static defaultProps: IProps = { title: "", color: "green", shape: "normal", type: "normal", checked: false, onChange: () => {} }; onChange(flag) { this.props.onChange && this.props.onChange(flag); } render() { const title = this.props.title; const color = this.props.color || "green"; const shapeClassName = this.props.shape !== "radius" ? "" : "radius"; const type = this.props.type === "form" ? "form" : "normal"; const checked = !!this.props.checked; const [checkedSwitch, setCheckedSwitch] = useState(checked); const switchComponent = ( { if (!this.props.disabled) { const currentCheck = !checkedSwitch; setCheckedSwitch(currentCheck); this.onChange(currentCheck); } }} > ); const formSwitchComponent = ( {title} {switchComponent} ); return type === "form" ? formSwitchComponent : switchComponent; } }