CheckboxRow.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React, { Component } from "react";
  2. import styled from "styled-components";
  3. type PropsType = {
  4. label: string;
  5. checked: boolean;
  6. toggle: () => void;
  7. isRequired?: boolean;
  8. disabled?: boolean;
  9. };
  10. type StateType = {};
  11. export default class CheckboxRow extends Component<PropsType, StateType> {
  12. render() {
  13. return (
  14. <StyledCheckboxRow>
  15. <CheckboxWrapper
  16. disabled={this.props.disabled}
  17. onClick={!this.props.disabled ? this.props.toggle : undefined}
  18. >
  19. <Checkbox checked={this.props.checked}>
  20. <i className="material-icons">done</i>
  21. </Checkbox>
  22. {this.props.label}
  23. {this.props.isRequired && <Required>*</Required>}
  24. </CheckboxWrapper>
  25. </StyledCheckboxRow>
  26. );
  27. }
  28. }
  29. const Required = styled.section`
  30. margin-left: 8px;
  31. color: #fc4976;
  32. `;
  33. const CheckboxWrapper = styled.div<{ disabled?: boolean }>`
  34. display: flex;
  35. align-items: center;
  36. cursor: ${(props) => (props.disabled ? "not-allowed" : "pointer")};
  37. font-size: 13px;
  38. :hover {
  39. > div {
  40. background: #ffffff22;
  41. }
  42. }
  43. `;
  44. const Checkbox = styled.div<{ checked: boolean }>`
  45. width: 16px;
  46. height: 16px;
  47. border: 1px solid #ffffff55;
  48. margin: 1px 10px 0px 1px;
  49. border-radius: 3px;
  50. background: ${(props) => (props.checked ? "#ffffff22" : "#ffffff11")};
  51. display: flex;
  52. align-items: center;
  53. justify-content: center;
  54. > i {
  55. font-size: 12px;
  56. padding-left: 0px;
  57. display: ${(props) => (props.checked ? "" : "none")};
  58. }
  59. `;
  60. const StyledCheckboxRow = styled.div`
  61. display: flex;
  62. align-items: center;
  63. margin-bottom: 15px;
  64. margin-top: 20px;
  65. `;