Text.tsx 1.4 KB

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