单选 Radio
到做抉择的时候了
默认
请问您的性别是?
已选择:Helicopter
import { Radio } from "mmixel-ui"
const SelectGender = () => {
const [gender, setGender] = useState("Helicopter")
return (
<>
<span>已选择:{gender}</span>
<br />
<Radio
checked={gender === "Male"}
name="gender"
value="Male"
setValue={setGender}>
男
</Radio>
<Radio
checked={gender === "Female"}
name="gender"
value="Female"
setValue={setGender}>
女
</Radio>
<Radio
checked={gender === "Email"}
name="gender"
value="Email"
setValue={setGender}>
电子邮件
</Radio>
</>
)
}
export default SelectGender
禁用
有些事情总是不尽人意
export const RadioDisabled = () => {
const [hobby, setHobby] = useState("")
return (
<>
<br />
<Radio
checked={hobby === "Ski"}
name="hobby"
value="Ski"
setValue={setHobby}>
滑雪
</Radio>
<Radio
checked={hobby === "Jump"}
name="hobby"
value="Jump"
setValue={setHobby}>
跳伞
</Radio>
<Radio
disabled
checked={hobby === "Fly"}
name="hobby"
value="Fly"
setValue={setHobby}>
翼装飞行
</Radio>
</>
)
}
export default RadioDisabled
Radio Props
Prop | Type | Default | Desc |
---|---|---|---|
checked | boolean | false | 是否被选中 |
name | string | undefined | 组件所属组 |
value | any | undefined | 组件的值 |
setValue | Dispatch<SetStateAction<boolean>> | undefined | 改变值的方法 |
color | string | "#ff8729" | 默认颜色 |
disabled | boolean | false | 是否禁用 |
onChange | (value: string) => void | undefined | 更改值时的回调 |