From f4384afdca99938be67421e2a57132da07000491 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Sirois Date: Mon, 29 Jul 2019 12:10:19 -0400 Subject: [PATCH] feat: set up basic typography system for Markdown content --- src/components/Markdown/index.tsx | 22 ++++++++++ src/components/Markdown/styles.tsx | 68 ++++++++++++++++++++++++++++++ src/templates/languagePost.tsx | 3 +- 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/components/Markdown/index.tsx create mode 100644 src/components/Markdown/styles.tsx diff --git a/src/components/Markdown/index.tsx b/src/components/Markdown/index.tsx new file mode 100644 index 0000000..43038a4 --- /dev/null +++ b/src/components/Markdown/index.tsx @@ -0,0 +1,22 @@ +import React from "react" +import * as SC from "./styles" + +interface MarkdownProps { + content: string +} + +/* + This component is used as a wrapper around Markdown generated content, + mainly to provide styles to the html generated. +*/ +export function Markdown({ + content, + ...restProps +}: MarkdownProps): JSX.Element { + return ( + + ) +} diff --git a/src/components/Markdown/styles.tsx b/src/components/Markdown/styles.tsx new file mode 100644 index 0000000..bf6e89e --- /dev/null +++ b/src/components/Markdown/styles.tsx @@ -0,0 +1,68 @@ +import styled, { css } from "styled-components" + +const BASE_FONT_SIZE = 18 +const BASE_LINE_HEIGHT = 26 +const MODULAR_SCALE = 1.1487 + +function modularFontSize(power: number) { + return BASE_FONT_SIZE * Math.pow(MODULAR_SCALE, power) +} + +function modularScale(power: number) { + const fontSize = modularFontSize(power) + + // attempt to fit line-height a little larger than font-size + const paddedLineHeight = fontSize * 1.1 + const lineHeight = + paddedLineHeight - (paddedLineHeight % BASE_LINE_HEIGHT) + BASE_LINE_HEIGHT + + return css` + font-size: ${fontSize}px; + line-height: ${lineHeight}px; + ` +} + +export const MarkdownWrapper = styled.div` + font-size: ${BASE_FONT_SIZE}px; + line-height: ${BASE_LINE_HEIGHT}px; + + p { + margin: ${BASE_LINE_HEIGHT}px 0; + } + + h1, + h2, + h3, + h4, + h5, + h6 { + font-family: "Montserrat"; + letter-spacing: -1.75px; + margin-top: ${BASE_LINE_HEIGHT * 2}px; + margin-bottom: ${BASE_LINE_HEIGHT}px; + } + + h1 { + ${modularScale(6)}; + } + + h2 { + ${modularScale(5)}; + } + + h3 { + ${modularScale(4)}; + } + + h4 { + ${modularScale(3)}; + } + + h5 { + ${modularScale(2)}; + } + + h6 { + ${modularScale(1)}; + } +` diff --git a/src/templates/languagePost.tsx b/src/templates/languagePost.tsx index 8689af2..599af62 100644 --- a/src/templates/languagePost.tsx +++ b/src/templates/languagePost.tsx @@ -1,5 +1,6 @@ import React from "react" import { graphql } from "gatsby" +import { Markdown } from "../components/Markdown" import { SEO } from "../components/SEO" import { DocsLayout } from "../components/DocsLayout" @@ -10,7 +11,7 @@ function LanguagePost({ data }: any) { return ( -
+ ) }