index.js 1.9 KB

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