import Taro, { useEffect, useState } from "@tarojs/taro"; import { Text, View } from "@tarojs/components"; import { IProps } from "../../../@types/radio"; import ListRadio from "./components/ListRadio"; import { classNames } from "../../lib"; export default function RadioH5(props: IProps) { const type = props.type || "normal"; const shapeClassName = props.shape || "normal"; const title = props.title || ""; const colorClassName = props.color || "green"; const directionClassName = props.direction === "horizontal" ? "flex" : ""; const list = props.radioGroup || []; const [activeValue, setActiveValue] = useState(props.checkedValue); const clickRadio = (name, index) => { setActiveValue(name); }; useEffect(() => { props.onChange && props.onChange(activeValue); }, [activeValue]); const radioComponent = list.map((item, index) => ( {item.key} { if (!props.disabled) { clickRadio(item.value, index); } }} className={classNames([ "h5-radio", colorClassName, shapeClassName, { checked: activeValue === item.value, disabled: props.disabled } ])} > )); const formRadioComponent = ( {title} {radioComponent} ); const renderListComponent = () => ( { setActiveValue(value); }} list={list} checkedValue={activeValue} disabled={props.disabled} /> ); const formOrNormalComponent = ( {type === "form" ? ( formRadioComponent ) : ( {radioComponent} )} ); const weappComponent = type === "list" ? renderListComponent() : formOrNormalComponent; return {weappComponent}; } RadioH5.defaultProps = { type: "normal", shape: "normal", title: "", colorClassName: "green", directionClassName: "", radioGroup: [] } as IProps; RadioH5.options = { addGlobalClass: true };