StatsHead.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. flex: 1 1 auto;
  7. justify-content: space-between;
  8. align-items: center;
  9. padding: 24px 32px;
  10. background-color: #f1f1f1;
  11. border-top-left-radius: 12px;
  12. border-top-right-radius: 12px;
  13. @media only screen and (max-width: 768px) {
  14. padding: 16px;
  15. }
  16. `;
  17. const TotalText = styled.p`
  18. margin: 0;
  19. padding: 0;
  20. span {
  21. font-weight: bold;
  22. border-bottom: 1px dotted #999;
  23. }
  24. @media only screen and (max-width: 768px) {
  25. font-size: 13px;
  26. }
  27. `;
  28. const TimeWrapper = styled.div`
  29. display: flex;
  30. `;
  31. const Button = styled.button`
  32. display: flex;
  33. padding: 6px 12px;
  34. margin: 0 4px;
  35. border: none;
  36. font-size: 12px;
  37. border-radius: 4px;
  38. box-shadow: 0 0px 10px rgba(100, 100, 100, 0.1);
  39. background-color: white;
  40. cursor: pointer;
  41. transition: all 0.2s ease-out;
  42. box-sizing: border-box;
  43. :last-child {
  44. margin-right: 0;
  45. }
  46. ${({ active }) =>
  47. !active &&
  48. css`
  49. border: 1px solid #ddd;
  50. background-color: #f5f5f5;
  51. box-shadow: 0 2px 6px rgba(150, 150, 150, 0.2);
  52. :hover {
  53. border-color: 1px solid #ccc;
  54. background-color: white;
  55. }
  56. `};
  57. @media only screen and (max-width: 768px) {
  58. padding: 4px 8px;
  59. margin: 0 2px;
  60. font-size: 11px;
  61. }
  62. `;
  63. const StatsHead = ({ changePeriod, period, total }) => {
  64. const buttonWithPeriod = (periodText, text) => (
  65. <Button active={period === periodText} data-period={periodText} onClick={changePeriod}>
  66. {text}
  67. </Button>
  68. );
  69. return (
  70. <Wrapper>
  71. <TotalText>
  72. Total clicks: <span>{total}</span>
  73. </TotalText>
  74. <TimeWrapper>
  75. {buttonWithPeriod('allTime', 'All Time')}
  76. {buttonWithPeriod('lastMonth', 'Month')}
  77. {buttonWithPeriod('lastWeek', 'Week')}
  78. {buttonWithPeriod('lastDay', 'Day')}
  79. </TimeWrapper>
  80. </Wrapper>
  81. );
  82. };
  83. StatsHead.propTypes = {
  84. changePeriod: PropTypes.func.isRequired,
  85. period: PropTypes.string.isRequired,
  86. total: PropTypes.number.isRequired,
  87. };
  88. export default StatsHead;