CheckboxRow.tsx 1.5 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. required?: boolean;
  8. };
  9. type StateType = {};
  10. export default class CheckboxRow extends Component<PropsType, StateType> {
  11. render() {
  12. return (
  13. <StyledCheckboxRow>
  14. <CheckboxWrapper onClick={this.props.toggle}>
  15. <Checkbox checked={this.props.checked}>
  16. <i className="material-icons">done</i>
  17. </Checkbox>
  18. {this.props.label}
  19. {
  20. this.props.required && (
  21. <Required>*</Required>
  22. )
  23. }
  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`
  34. display: flex;
  35. align-items: center;
  36. cursor: pointer;
  37. :hover {
  38. > div {
  39. background: #ffffff22;
  40. }
  41. }
  42. `;
  43. const Checkbox = styled.div`
  44. width: 16px;
  45. height: 16px;
  46. border: 1px solid #ffffff55;
  47. margin: 1px 10px 0px 1px;
  48. border-radius: 3px;
  49. background: ${(props: { checked: boolean }) =>
  50. 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: { checked: boolean }) => (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. `;