CheckboxRow.tsx 1.9 KB

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