Text.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React from "react";
  2. import { switchProp, ifNotProp, ifProp } from "styled-tools";
  3. import { Box, BoxProps } from "rebass/styled-components";
  4. import styled, { css } from "styled-components";
  5. import { FC, CSSProperties } from "react";
  6. import { Colors } from "../consts";
  7. interface Props extends Omit<BoxProps, "as"> {
  8. as?: string;
  9. htmlFor?: string;
  10. light?: boolean;
  11. normal?: boolean;
  12. bold?: boolean;
  13. style?: CSSProperties;
  14. }
  15. const Text: FC<Props> = styled(Box)<Props>`
  16. font-weight: 400;
  17. ${ifNotProp(
  18. "fontSize",
  19. css`
  20. font-size: ${switchProp("a", {
  21. p: "1rem",
  22. h1: "1.802em",
  23. h2: "1.602em",
  24. h3: "1.424em",
  25. h4: "1.266em",
  26. h5: "1.125em"
  27. })};
  28. `
  29. )}
  30. ${ifProp(
  31. "light",
  32. css`
  33. font-weight: 300;
  34. `
  35. )}
  36. ${ifProp(
  37. "normal",
  38. css`
  39. font-weight: 400;
  40. `
  41. )}
  42. ${ifProp(
  43. "bold",
  44. css`
  45. font-weight: 700;
  46. `
  47. )}
  48. `;
  49. Text.defaultProps = {
  50. color: Colors.Text
  51. };
  52. export default Text;
  53. export const H1: FC<Props> = (props) => <Text as="h1" {...props} />;
  54. export const H2: FC<Props> = (props) => <Text as="h2" {...props} />;
  55. export const H3: FC<Props> = (props) => <Text as="h3" {...props} />;
  56. export const H4: FC<Props> = (props) => <Text as="h4" {...props} />;
  57. export const H5: FC<Props> = (props) => <Text as="h5" {...props} />;
  58. export const H6: FC<Props> = (props) => <Text as="h6" {...props} />;
  59. export const Span: FC<Props> = (props) => <Text as="span" {...props} />;