Radio单选框 - 图1

Radio 单选框

基本用法

  1. import { Radio, Cell } from 'zarm';
  2. ReactDOM.render(
  3. <>
  4. <Cell><Radio>普通</Radio></Cell>
  5. <Cell><Radio defaultChecked>默认选中</Radio></Cell>
  6. <Cell><Radio disabled>禁用</Radio></Cell>
  7. <Cell><Radio defaultChecked disabled>选中且禁用</Radio></Cell>
  8. </>
  9. , mountNode);

组合使用

  1. import { Cell, Radio } from 'zarm';
  2. ReactDOM.render(
  3. <Cell>
  4. <Radio.Group>
  5. <Radio value="0">选项一</Radio>
  6. <Radio value="1">选项二</Radio>
  7. <Radio value="2">选项三</Radio>
  8. </Radio.Group>
  9. </Cell>
  10. , mountNode);

按钮样式

  1. import { Radio, Cell } from 'zarm';
  2. class Demo extends React.Component {
  3. state = {
  4. radio: '0',
  5. };
  6. render() {
  7. return (
  8. <>
  9. <Cell
  10. description={
  11. <Radio.Group
  12. type="button"
  13. value={this.state.radio}
  14. onChange={value => {
  15. this.setState({ radio: value });
  16. console.log(`radio to ${value}`)
  17. }}
  18. >
  19. <Radio value="0">选项一</Radio>
  20. <Radio value="1">选项二</Radio>
  21. <Radio value="2">选项三</Radio>
  22. </Radio.Group>
  23. }
  24. >
  25. 普通
  26. </Cell>
  27. <Cell
  28. description={
  29. <Radio.Group type="button" defaultValue="1">
  30. <Radio value="0">选项一</Radio>
  31. <Radio value="1">选项二</Radio>
  32. <Radio value="2">选项三</Radio>
  33. </Radio.Group>
  34. }
  35. >
  36. 指定默认值
  37. </Cell>
  38. <Cell
  39. description={
  40. <Radio.Group type="button">
  41. <Radio value="0">选项一</Radio>
  42. <Radio value="1" disabled>选项二</Radio>
  43. <Radio value="2" disabled checked>选项三</Radio>
  44. </Radio.Group>
  45. }
  46. >
  47. 禁用指定项
  48. </Cell>
  49. <Cell
  50. description={
  51. <Radio.Group type="button" shape="rect">
  52. <Radio value="0">选项一</Radio>
  53. <Radio value="1">选项二</Radio>
  54. <Radio value="2">选项三</Radio>
  55. </Radio.Group>
  56. }
  57. >
  58. 直角
  59. </Cell>
  60. <Cell
  61. description={
  62. <Radio.Group type="button" shape="round">
  63. <Radio value="0">选项一</Radio>
  64. <Radio value="1">选项二</Radio>
  65. <Radio value="2">选项三</Radio>
  66. </Radio.Group>
  67. }
  68. >
  69. 椭圆角
  70. </Cell>
  71. <Cell
  72. description={
  73. <Radio.Group compact type="button" defaultValue="0">
  74. <Radio value="0">选项一</Radio>
  75. <Radio value="1">选项二</Radio>
  76. <Radio value="2">选项三</Radio>
  77. </Radio.Group>
  78. }
  79. >
  80. 紧凑模式
  81. </Cell>
  82. <Cell
  83. description={
  84. <Radio.Group compact ghost type="button" defaultValue="0">
  85. <Radio value="0">选项一</Radio>
  86. <Radio value="1">选项二</Radio>
  87. <Radio value="2">选项三</Radio>
  88. </Radio.Group>
  89. }
  90. >
  91. 幽灵按钮
  92. </Cell>
  93. </>
  94. )
  95. }
  96. }
  97. ReactDOM.render(<Demo />, mountNode);

块级样式

  1. import { Cell, Radio } from 'zarm';
  2. ReactDOM.render(
  3. <Cell>
  4. <Radio.Group block type="button">
  5. <Radio value="0">选项一</Radio>
  6. <Radio value="1">选项二</Radio>
  7. <Radio value="2">选项三</Radio>
  8. </Radio.Group>
  9. </Cell>
  10. , mountNode);

列表样式

  1. import { Radio } from 'zarm';
  2. ReactDOM.render(
  3. <Radio.Group type="cell">
  4. <Radio value="0">选项一</Radio>
  5. <Radio value="1">选项二</Radio>
  6. <Radio value="2" disabled>选项三(禁止选择)</Radio>
  7. </Radio.Group>
  8. , mountNode);

列表样式禁用状态

  1. import { Radio } from 'zarm';
  2. ReactDOM.render(
  3. <Radio.Group disabled type="cell">
  4. <Radio value="0">选项一</Radio>
  5. <Radio value="1">选项二</Radio>
  6. <Radio value="2">选项三</Radio>
  7. </Radio.Group>
  8. , mountNode);

API

Radio

属性类型默认值说明
valuestring | number-
checkedboolean-当前是否选中
defaultCheckedboolean-初始是否选中
disabledbooleanfalse是否禁用
onChange(e: ChangeEvent) => void-值变化时触发的回调函数

Radio.Group

属性类型默认值说明
typestring-显示类型,可选值 button, cell
valuestring | number-选中值
defaultValuestring | number-初始选中值
disabledbooleanfalse是否禁用
blockbooleanfalse子项是否为块级元素
onChange(value?: string | number) => void-值变化时触发的回调函数
sizestring'xs'按钮类型时的大小,可选值为 lgmdsmxs
shapestring'radius'按钮类型时的形状,可选值 rect, radius, round
ghostbooleanfalse按钮类型时,选中项样式是否为幽灵按钮
compactbooleanfalse按钮类型时,是否为紧凑模式