StatsHead.tsx 2.0 KB

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