index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. export class SpecialRadio extends Component {
  4. render() {
  5. const { checked, children, onClick } = this.props;
  6. return (
  7. <div className={`g-special-radio-wrapper ${checked ? 'checked' : ''}`}>
  8. <div className="g-special-radio" onClick={() => onClick && onClick()}>
  9. {children}
  10. </div>
  11. </div>
  12. );
  13. }
  14. }
  15. export class SpecialRadioGroup extends Component {
  16. onClickItem(key) {
  17. const { onChange } = this.props;
  18. if (onChange) onChange(key);
  19. }
  20. render() {
  21. const { list = [], value } = this.props;
  22. return (
  23. <div className="g-special-radio-group">
  24. {list.map(item => {
  25. return (
  26. <SpecialRadio checked={value === item.key} onClick={() => this.onClickItem(item.key)}>
  27. {item.label}
  28. </SpecialRadio>
  29. );
  30. })}
  31. </div>
  32. );
  33. }
  34. }
  35. export default class Radio extends Component {
  36. render() {
  37. const { checked, children, onClick } = this.props;
  38. return (
  39. <div className={`g-radio-wrapper ${checked ? 'checked' : ''}`}>
  40. <div className="g-radio" onClick={() => onClick && onClick()}>
  41. {children}
  42. </div>
  43. </div>
  44. );
  45. }
  46. }
  47. export class RadioGroup extends Component {
  48. onClickItem(key) {
  49. const { onChange } = this.props;
  50. if (onChange) onChange(key);
  51. }
  52. render() {
  53. const { list = [], value } = this.props;
  54. return (
  55. <div className="g-radio-group">
  56. {list.map(item => {
  57. return (
  58. <Radio checked={value === item.key} onClick={() => this.onClickItem(item.key)}>
  59. {item.label}
  60. </Radio>
  61. );
  62. })}
  63. </div>
  64. );
  65. }
  66. }