Text.tsx 1.4 KB

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