RadioSelector.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React, { Component } from "react";
  2. import styled from "styled-components";
  3. type PropsType = {
  4. selected: string;
  5. setSelected: (x: string) => void;
  6. options: { value: string; label: string }[];
  7. };
  8. type StateType = {};
  9. export default class RadioSelector extends Component<PropsType, StateType> {
  10. render() {
  11. return (
  12. <StyledRadioSelector>
  13. {this.props.options.map(
  14. (option: { label: string; value: string }, i: number) => {
  15. let selected = option.value === this.props.selected;
  16. return (
  17. <RadioRow onClick={() => this.props.setSelected(option.value)}>
  18. <Indicator selected={selected}>
  19. {selected && <Circle />}
  20. </Indicator>
  21. {option.label}
  22. </RadioRow>
  23. );
  24. }
  25. )}
  26. </StyledRadioSelector>
  27. );
  28. }
  29. }
  30. const RadioRow = styled.div`
  31. display: flex;
  32. align-items: center;
  33. cursor: pointer;
  34. margin-bottom: 12px;
  35. :hover {
  36. > div {
  37. background: #ffffff22;
  38. }
  39. }
  40. `;
  41. const Indicator = styled.div<{ selected: boolean }>`
  42. border-radius: 15px;
  43. display: flex;
  44. margin-right: 4px;
  45. align-items: center;
  46. justify-content: center;
  47. width: 16px;
  48. height: 16px;
  49. border: 1px solid #ffffff55;
  50. margin: 1px 10px 0px 1px;
  51. background: ${(props) => (props.selected ? "#ffffff22" : "#ffffff11")};
  52. `;
  53. const Circle = styled.div`
  54. width: 8px;
  55. height: 8px;
  56. background: #ffffff55;
  57. border-radius: 15px;
  58. `;
  59. const StyledRadioSelector = styled.div``;