Table.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { Flex } from "reflexbox/styled-components";
  2. import styled, { css } from "styled-components";
  3. import { ifProp, prop } from "styled-tools";
  4. import { Colors } from "../consts";
  5. const Table = styled(Flex)<{ scrollWidth?: string }>`
  6. background-color: white;
  7. border-radius: 12px;
  8. box-shadow: 0 6px 15px ${Colors.TableShadow};
  9. text-align: center;
  10. overflow: auto;
  11. tr,
  12. th,
  13. td,
  14. tbody,
  15. thead,
  16. tfoot {
  17. display: flex;
  18. overflow: hidden;
  19. }
  20. tbody,
  21. thead,
  22. tfoot {
  23. flex-direction: column;
  24. }
  25. tr {
  26. border-bottom: 1px solid ${Colors.TableHeadBorder};
  27. }
  28. tbody {
  29. border-bottom-right-radius: 12px;
  30. border-bottom-left-radius: 12px;
  31. overflow: hidden;
  32. }
  33. tbody + tfoot {
  34. border: none;
  35. }
  36. tbody tr:hover {
  37. background-color: ${Colors.TableRowHover};
  38. }
  39. thead {
  40. background-color: ${Colors.TableHeadBg};
  41. border-top-right-radius: 12px;
  42. border-top-left-radius: 12px;
  43. font-weight: bold;
  44. tr {
  45. border-bottom: 1px solid ${Colors.TableBorder};
  46. }
  47. }
  48. tfoot {
  49. background-color: ${Colors.TableHeadBg};
  50. border-bottom-right-radius: 12px;
  51. border-bottom-left-radius: 12px;
  52. }
  53. ${ifProp(
  54. "scrollWidth",
  55. css`
  56. thead,
  57. tbody,
  58. tfoot {
  59. min-width: ${prop("scrollWidth")};
  60. }
  61. `
  62. )}
  63. `;
  64. Table.defaultProps = {
  65. as: "table",
  66. flex: "1 1 auto",
  67. flexDirection: "column",
  68. width: 1
  69. };
  70. export default Table;