Skip to content

Commit

Permalink
♻️ #20 - refactor: refactor typogrpahy styling
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Feb 8, 2024
1 parent 948c34a commit 9e35b91
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/components/badge/badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
align-items: center;
border-radius: var(--border-radius-m);
display: inline-flex;
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-xs);
font-weight: var(--typography-font-weight-normal);
height: var(--typography-line-height-body-s);
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
display: inline-flex;
gap: 0.5em;
height: var(--mykn-button-height);
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-body);
font-size: var(--mykn-button-font-size);
font-weight: var(--mykn-button-font-weight);
justify-content: center;
Expand Down
1 change: 0 additions & 1 deletion src/components/card/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
background-color: var(--typography-color-background);
border-radius: var(--border-radius-l);
box-sizing: border-box;
padding: var(--spacing-v-xxl) var(--spacing-h-xxl);

& + & {
margin-top: var(--spacing-v-m);
Expand Down
7 changes: 6 additions & 1 deletion src/components/card/card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import React from "react";

import { Page } from "../page";
import { Body, P } from "../typography";
import { Card } from "./card";

const meta = {
Expand All @@ -24,6 +25,10 @@ type Story = StoryObj<typeof meta>;

export const CardComponent: Story = {
args: {
children: "The quick brown fox jumps over the lazy dog.",
children: (
<Body>
<P>The quick brown fox jumps over the lazy dog.</P>
</Body>
),
},
};
2 changes: 1 addition & 1 deletion src/components/form/input/input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
border-radius: var(--border-radius-m);
box-sizing: border-box;
color: var(--typography-color-body);
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-s);
font-weight: var(--typography-font-weight-normal);
line-height: var(--typography-line-height-body-s);
Expand Down
4 changes: 2 additions & 2 deletions src/components/form/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
cursor: pointer;
display: inline-flex;
justify-content: space-between;
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-s);
font-weight: var(--typography-font-weight-normal);
line-height: var(--typography-line-height-body-s);
Expand Down Expand Up @@ -76,7 +76,7 @@
box-sizing: border-box;
color: var(--mykn-option-color-body);
cursor: pointer;
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-s);
font-weight: var(--mykn-option-font-weight);
line-height: var(--typography-line-height-body-s);
Expand Down
7 changes: 3 additions & 4 deletions src/components/typography/a/a.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@use "../p/p";

.mykn-a {
@extend .mykn-p;
font-family: inherit;
line-height: var(--typography-line-height-body-s);
align-items: center;
color: var(--theme-color-primary-800);
display: inline-flex;
Expand All @@ -24,7 +23,7 @@
}

&#{&}--muted {
@extend .mykn-p--muted;
color: var(--typography-color-muted);
}

&[aria-current] {
Expand Down
11 changes: 9 additions & 2 deletions src/components/typography/body/body.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
@use "../../../settings/constants";

.mykn-body {
padding: var(--spacing-v-xl) var(--spacing-h-xl);

.mykn-h1,
.mykn-h2,
.mykn-h3,
.mykn-hr,
.mykn-p,
.mykn-ol,
.mykn-ul {
&:not(:last-child) {
margin-bottom: 16px;
margin-bottom: var(--spacing-v-l);
}
}

@media screen and (min-width: constants.$breakpoint-desktop) {
padding: var(--spacing-v-xxxl) var(--spacing-h-xxxl);
}
}
3 changes: 2 additions & 1 deletion src/components/typography/body/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type BodyProps = React.PropsWithChildren<{
}>;

/**
* Provides styling (e.g. margins) for a group of typographic components.
* Provides styling (e.g. margins) for a group of (typographic) components.
* Can be used in various components to provide padding.
* @param children
* @param props
* @constructor
Expand Down
2 changes: 1 addition & 1 deletion src/components/typography/h1/h1.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.mykn-h1 {
color: var(--typography-color-h);
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-h);
font-size: var(--typography-font-size-h1);
font-weight: var(--typography-font-weight-bold);
line-height: var(--typography-line-height-h1);
Expand Down
2 changes: 1 addition & 1 deletion src/components/typography/h2/h2.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.mykn-h2 {
color: var(--typography-color-h);
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-h);
font-size: var(--typography-font-size-h2);
font-weight: var(--typography-font-weight-bold);
line-height: var(--typography-line-height-h2);
Expand Down
2 changes: 1 addition & 1 deletion src/components/typography/h3/h3.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.mykn-h3 {
color: var(--typography-color-h);
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-h);
font-size: var(--typography-font-size-h3);
font-weight: var(--typography-font-weight-bold);
line-height: var(--typography-line-height-h3);
Expand Down
6 changes: 5 additions & 1 deletion src/components/typography/hr/hr.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.mykn-hr {
border: 0;
border-bottom: 1px solid var(--typography-color-border);
margin: 0;
margin: var(--spacing-v-l) 0;

&--size-xxl {
margin: var(--spacing-v-xxl) 0;
}
}
11 changes: 8 additions & 3 deletions src/components/typography/hr/hr.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import clsx from "clsx";
import React from "react";

import "./hr.scss";

export type HrProps = React.HTMLAttributes<HTMLHRElement>;
export type HrProps = React.ComponentProps<"hr"> & {
/** The size of the margin. */
size?: "l" | "xxl";
};

/**
* Hr component
* @param size
* @param props
* @constructor
*/
export const Hr: React.FC<HrProps> = ({ ...props }) => (
<hr className="mykn-hr" {...props} />
export const Hr: React.FC<HrProps> = ({ size = "l", ...props }) => (
<hr className={clsx("mykn-hr", `mykn-hr--size-${size}`)} {...props} />
);
1 change: 1 addition & 0 deletions src/components/typography/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./body";
export * from "./h1";
export * from "./h2";
export * from "./h3";
export * from "./hr";
export * from "./p";
11 changes: 7 additions & 4 deletions src/components/typography/li/li.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@use "../p/p";

.mykn-li {
@extend .mykn-p;
color: var(--typography-color-body);
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-s);
font-weight: var(--typography-font-weight-normal);
line-height: var(--typography-line-height-body-s);

&--size-xs {
@extend .mykn-p--size-xs;
font-size: var(--typography-font-size-body-xs);
line-height: var(--typography-line-height-body-xs);
}
}
8 changes: 5 additions & 3 deletions src/components/typography/ol/ol.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@use "../p/p";

.mykn-ol {
@extend .mykn-p;
color: var(--typography-color-body);
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-s);
font-weight: var(--typography-font-weight-normal);
line-height: var(--typography-line-height-body-s);
list-style-position: inside;
padding-inline-start: 0;

Expand Down
2 changes: 1 addition & 1 deletion src/components/typography/p/p.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.mykn-p {
color: var(--typography-color-body);
font-family: Inter, sans-serif;
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-s);
font-weight: var(--typography-font-weight-normal);
line-height: var(--typography-line-height-body-s);
Expand Down
8 changes: 5 additions & 3 deletions src/components/typography/ul/ul.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@use "../p/p";

.mykn-ul {
@extend .mykn-p;
color: var(--typography-color-body);
font-family: var(--typography-font-family-body);
font-size: var(--typography-font-size-body-s);
font-weight: var(--typography-font-weight-normal);
line-height: var(--typography-line-height-body-s);
list-style-position: inside;
padding-inline-start: 0;

Expand Down
5 changes: 4 additions & 1 deletion src/settings/tokens.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
--spacing-v-xxl: 32px;

--spacing-h-xxxl: 40px;
--spacing-v-xxxl: 40px;
--spacing-v-xxxl: 20px;

/* FORM */
--form-color-border: var(--theme-shade-300);
Expand All @@ -79,6 +79,9 @@
--typography-color-border: var(--theme-shade-300);
--typography-color-muted: var(--theme-shade-600);

--typography-font-family-h: Inter, sans-serif;
--typography-font-family-body: Inter, sans-serif;

--typography-font-size-h1: 24px;
--typography-font-size-h2: 20px;
--typography-font-size-h3: 16px;
Expand Down

0 comments on commit 9e35b91

Please sign in to comment.