Checkbox.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled, { css } from 'styled-components';
  4. const Wrapper = styled.div`
  5. display: flex;
  6. justify-content: flex-start;
  7. align-items: center;
  8. margin: 24px 32px 24px 0;
  9. `;
  10. const Box = styled.span`
  11. position: relative;
  12. display: flex;
  13. align-items: center;
  14. font-weight: normal;
  15. color: #666;
  16. transition: color 0.3s ease-out;
  17. cursor: pointer;
  18. :hover {
  19. color: black;
  20. }
  21. :before {
  22. content: '';
  23. display: block;
  24. width: 18px;
  25. height: 18px;
  26. margin-right: 10px;
  27. border-radius: 4px;
  28. background-color: white;
  29. box-shadow: 0 2px 4px rgba(50, 50, 50, 0.2);
  30. cursor: pointer;
  31. @media only screen and (max-width: 768px) {
  32. width: 14px;
  33. height: 14px;
  34. margin-right: 8px;
  35. }
  36. }
  37. ${({ checked }) =>
  38. checked &&
  39. css`
  40. :before {
  41. box-shadow: 0 3px 5px rgba(50, 50, 50, 0.4);
  42. }
  43. :after {
  44. content: '';
  45. position: absolute;
  46. left: 2px;
  47. top: 4px;
  48. width: 14px;
  49. height: 14px;
  50. display: block;
  51. margin-right: 10px;
  52. border-radius: 2px;
  53. background-color: #9575cd;
  54. box-shadow: 0 2px 4px rgba(50, 50, 50, 0.2);
  55. cursor: pointer;
  56. @media only screen and (max-width: 768px) {
  57. left: 2px;
  58. top: 5px;
  59. width: 10px;
  60. height: 10px;
  61. }
  62. }
  63. `};
  64. `;
  65. const Checkbox = ({ checked, label, id, onClick }) => (
  66. <Wrapper>
  67. <Box checked={checked} id={id} onClick={onClick}>
  68. {label}
  69. </Box>
  70. </Wrapper>
  71. );
  72. Checkbox.propTypes = {
  73. checked: PropTypes.bool,
  74. label: PropTypes.string.isRequired,
  75. id: PropTypes.string.isRequired,
  76. onClick: PropTypes.func,
  77. };
  78. Checkbox.defaultProps = {
  79. checked: false,
  80. onClick: f => f,
  81. };
  82. export default Checkbox;