index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import React from 'react';
  2. /*import PropTypes from 'prop-types';*/
  3. import on from './img/on.png';
  4. import off from './img/off.png';
  5. import disable from './img/disable.png';
  6. import style from './index.less';
  7. /**
  8. * 单选按钮
  9. * handleClick:点击触发按键 会将输入的props信息作为参数传入
  10. * isSelect:是否选中
  11. * name:右侧显示文字
  12. */
  13. class Radio extends React.Component {
  14. constructor(props){
  15. super(props);
  16. this.handleClick = this.handleClick.bind(this);
  17. }
  18. handleClick(id){
  19. this.props.handleClick(id);
  20. }
  21. getStyle(){
  22. if(this.props.display=='block'){
  23. return {
  24. display:'block',
  25. // marginBottom:'10px'
  26. }
  27. }
  28. return {
  29. display:'inline-block',
  30. marginLeft:'10px'
  31. }
  32. }
  33. render() {
  34. const {id,name,isSelect,disabled} = this.props;
  35. if(disabled){
  36. return (
  37. <div className={style['radio']}
  38. style={this.getStyle()}>
  39. <img src={isSelect?disable:off}/>
  40. <span style={{color:'#aaa'}}>{name}</span>
  41. </div>
  42. )
  43. }
  44. return (
  45. <div className={style['radio']}
  46. onClick={() =>this.handleClick(id)}
  47. style={this.getStyle()}>
  48. <img src={isSelect?on:off}/>
  49. <span>{name}</span>
  50. </div>
  51. )
  52. }
  53. }
  54. /*Radio.propTypes = {
  55. handleClick:PropTypes.func,
  56. isSelect:PropTypes.bool,
  57. name:PropTypes.string
  58. };*/
  59. export default Radio;