CustomTable.ts 1.4 KB

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