index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import styled from 'styled-components';
  2. export const breakpoints = {
  3. xs: 480,
  4. sm: 576,
  5. md: 768,
  6. lg: 992,
  7. xl: 1200,
  8. xxl: 1600,
  9. };
  10. type RowProps = {
  11. alignItems?: string;
  12. flexDirection?: string;
  13. };
  14. export const Row = styled.div<RowProps>`
  15. display: flex;
  16. flex-wrap: wrap;
  17. align-items: ${(props) => props.alignItems || 'flex-start'};
  18. flex-direction: ${(props) => props.flexDirection || 'row'};
  19. `;
  20. interface ICol {
  21. off: {
  22. xs: number;
  23. sm: number;
  24. md: number;
  25. lg: number;
  26. xl: number;
  27. xxl: number;
  28. };
  29. span: {
  30. xs: number;
  31. sm: number;
  32. md: number;
  33. lg: number;
  34. xl: number;
  35. xxl: number;
  36. };
  37. padding?: number;
  38. }
  39. const nCols = 24;
  40. export const Col = styled.div<ICol>`
  41. margin-left: ${(props) => (props.off.xs / nCols) * 100}%;
  42. width: ${(props) => (props.span.xs / nCols) * 100}%;
  43. @media screen and (min-width: ${breakpoints.sm}px) {
  44. margin-left: ${(props) => (props.off.sm / nCols) * 100}%;
  45. width: ${(props) => (props.span.sm / nCols) * 100}%;
  46. }
  47. @media screen and (min-width: ${breakpoints.md}px) {
  48. margin-left: ${(props) => (props.off.md / nCols) * 100}%;
  49. width: ${(props) => (props.span.md / nCols) * 100}%;
  50. }
  51. @media screen and (min-width: ${breakpoints.lg}px) {
  52. margin-left: ${(props) => (props.off.lg / nCols) * 100}%;
  53. width: ${(props) => (props.span.lg / nCols) * 100}%;
  54. }
  55. @media screen and (min-width: ${breakpoints.xl}px) {
  56. margin-left: ${(props) => (props.off.xl / nCols) * 100}%;
  57. width: ${(props) => (props.span.xl / nCols) * 100}%;
  58. }
  59. @media screen and (min-width: ${breakpoints.xxl}px) {
  60. margin-left: ${(props) => (props.off.xxl / nCols) * 100}%;
  61. width: ${(props) => (props.span.xxl / nCols) * 100}%;
  62. }
  63. `;
  64. type SpaceProps = {
  65. h: number;
  66. xsHeight?: number;
  67. };
  68. export const Space = styled.div<SpaceProps>`
  69. flex-shrink: 0;
  70. display: ${(props) => (props.h === 0 ? 'none' : 'block')};
  71. height: ${(props) => (props.h ? props.h : 10)}px;
  72. @media screen and (max-width: ${breakpoints.sm}px) {
  73. display: ${(props) => (props.xsHeight === 0 ? 'none' : 'block')};
  74. height: ${(props) => (props.xsHeight ? props.xsHeight : props.h)}px;
  75. }
  76. `;
  77. export const LeftCol = ({ children }) => (
  78. <Col
  79. off={{ xs: 0, sm: 0, md: 0, lg: 0, xl: 0, xxl: 0 }}
  80. span={{ xs: 24, sm: 16, md: 16, lg: 16, xl: 16, xxl: 16 }}
  81. >
  82. {children}
  83. </Col>
  84. );
  85. export const RightCol = ({ children }) => (
  86. <Col
  87. off={{ xs: 0, sm: 0, md: 0, lg: 0, xl: 0, xxl: 0 }}
  88. span={{ xs: 24, sm: 8, md: 8, lg: 8, xl: 8, xxl: 8 }}
  89. >
  90. {children}
  91. </Col>
  92. );