refactor(starter): upgrade and move to typescript

This commit is contained in:
Alexander Shelepenok
2022-04-16 14:25:55 +00:00
parent 67ebabbaac
commit 50a99f57f7
156 changed files with 5350 additions and 7173 deletions

View File

@@ -2,20 +2,22 @@
@import "../../../assets/scss/mixins";
.author {
&__photo {
.photo {
background-clip: padding-box;
border-radius: 50%;
display: inline-block;
margin-bottom: 0;
height: 75px;
width: 75px;
@include margin-bottom(0);
}
&__title {
.title {
font-size: $typographic-base-font-size * 1.125;
font-weight: 600;
@include line-height(1.125);
@include margin(0.5, 0, 0.5, 0);
&-link {
.link {
color: $color-base;
&:hover,
@@ -25,7 +27,7 @@
}
}
&__subtitle {
.subtitle {
color: $color-gray;
@include line-height(1);
@include margin-bottom(1);

View File

@@ -5,9 +5,8 @@ import { Author } from "@/components/Sidebar/Author";
import * as mocks from "@/mocks";
describe("Author", () => {
const props = { isIndex: false, author: mocks.author };
it("renders correctly", () => {
const props = { isIndex: false, author: mocks.author };
const tree = renderer.create(<Author {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});

View File

@@ -1,8 +1,10 @@
import React from "react";
import { Link, withPrefix } from "gatsby";
import { Link } from "gatsby";
import styles from "./Author.module.scss";
import { Image } from "@/components/Image";
import * as styles from "./Author.module.scss";
type Props = {
author: {
@@ -16,29 +18,23 @@ type Props = {
const Author = ({ author, isIndex }: Props) => (
<div className={styles.author}>
<Link to="/">
<img
src={withPrefix(author.photo)}
className={styles.author__photo}
width="75"
height="75"
alt={author.name}
/>
<Image alt={author.name} path={author.photo} className={styles.photo} />
</Link>
{isIndex === true ? (
<h1 className={styles.author__title}>
<Link className={styles["author__title-link"]} to="/">
{isIndex ? (
<h1 className={styles.title}>
<Link className={styles.link} to="/">
{author.name}
</Link>
</h1>
) : (
<h2 className={styles.author__title}>
<Link className={styles["author__title-link"]} to="/">
<h2 className={styles.title}>
<Link className={styles.link} to="/">
{author.name}
</Link>
</h2>
)}
<p className={styles.author__subtitle}>{author.bio}</p>
<p className={styles.subtitle}>{author.bio}</p>
</div>
);

View File

@@ -1,33 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Author renders correctly 1`] = `
<div
className="author"
>
<div>
<a
href="/"
>
<img
alt="John Doe"
className="author__photo"
height="75"
src="/static/photo.jpg"
width="75"
/>
</a>
<h2
className="author__title"
>
/>
<h2>
<a
className="author__title-link"
href="/"
>
John Doe
</a>
</h2>
<p
className="author__subtitle"
>
<p>
Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu.
</p>
</div>

View File

@@ -4,17 +4,17 @@
.contacts {
@include margin-bottom(1);
&__list {
.list {
display: flex;
flex-flow: row wrap;
flex-grow: 0;
flex-shrink: 0;
list-style: none;
margin: 10px -3px;
padding: 0;
width: 140px;
max-width: 150px;
@include padding-equal(0);
@include margin(0.5, 0);
&-item {
.item {
align-content: center;
align-items: center;
border: 1px solid $color-gray-bg;
@@ -23,12 +23,16 @@
height: $button-height;
justify-content: center;
line-height: $button-height;
margin: 4px;
padding: 0;
text-align: center;
width: $button-height;
@include padding-equal(0);
@include margin-equal(0.25);
&-link {
&:nth-child(3n + 1) {
@include margin-left(0);
}
.link {
border: 0;
color: $color-base;
display: flex;

View File

@@ -5,9 +5,8 @@ import { Contacts } from "@/components/Sidebar/Contacts";
import * as mocks from "@/mocks";
describe("Contacts", () => {
const props = { contacts: mocks.contacts };
it("renders correctly", () => {
const props = { contacts: mocks.contacts };
const tree = renderer.create(<Contacts {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});

View File

@@ -1,10 +1,11 @@
import React from "react";
import { Icon } from "@/components/Icon";
import { ICONS } from "@/constants";
import { Dictionary } from "@/types";
import { getContactHref, getIcon } from "@/utils";
import styles from "./Contacts.module.scss";
import * as styles from "./Contacts.module.scss";
type Props = {
contacts: Dictionary<string>;
@@ -12,19 +13,21 @@ type Props = {
const Contacts: React.FC<Props> = ({ contacts }: Props) => (
<div className={styles.contacts}>
<ul className={styles.contacts__list}>
{Object.keys(contacts).map(name => (
<li className={styles["contacts__list-item"]} key={name}>
<a
className={styles["contacts__list-item-link"]}
href={getContactHref(name, contacts[name])}
rel="noopener noreferrer"
target="_blank"
>
<Icon name={name} icon={getIcon(name)} />
</a>
</li>
))}
<ul className={styles.list}>
{(Object.keys(contacts) as Array<keyof typeof ICONS>).map(name =>
contacts[name] ? (
<li className={styles.item} key={name}>
<a
className={styles.link}
href={getContactHref(name, contacts[name])}
rel="noopener noreferrer"
target="_blank"
>
<Icon name={name} icon={getIcon(name)} />
</a>
</li>
) : null,
)}
</ul>
</div>
);

View File

@@ -1,23 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Contacts renders correctly 1`] = `
<div
className="contacts"
>
<ul
className="contacts__list"
>
<li
className="contacts__list-item"
>
<div>
<ul>
<li>
<a
className="contacts__list-item-link"
href="#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 22 28"
>
<title>
@@ -29,17 +21,13 @@ exports[`Contacts renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="mailto:#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 28 28"
>
<title>
@@ -51,17 +39,13 @@ exports[`Contacts renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="https://github.com/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 26 28"
>
<title>
@@ -73,17 +57,13 @@ exports[`Contacts renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="https://www.twitter.com/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 26 28"
>
<title>
@@ -95,17 +75,13 @@ exports[`Contacts renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="https://t.me/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 28 28"
>
<title>
@@ -117,28 +93,6 @@ exports[`Contacts renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<a
className="contacts__list-item-link"
href="https://vk.com/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 31 28"
>
<title>
vkontakte
</title>
<path
d="M29.953 8.125c0.234 0.641-0.5 2.141-2.344 4.594-3.031 4.031-3.359 3.656-0.859 5.984 2.406 2.234 2.906 3.313 2.984 3.453 0 0 1 1.75-1.109 1.766l-4 0.063c-0.859 0.172-2-0.609-2-0.609-1.5-1.031-2.906-3.703-4-3.359 0 0-1.125 0.359-1.094 2.766 0.016 0.516-0.234 0.797-0.234 0.797s-0.281 0.297-0.828 0.344h-1.797c-3.953 0.25-7.438-3.391-7.438-3.391s-3.813-3.938-7.156-11.797c-0.219-0.516 0.016-0.766 0.016-0.766s0.234-0.297 0.891-0.297l4.281-0.031c0.406 0.063 0.688 0.281 0.688 0.281s0.25 0.172 0.375 0.5c0.703 1.75 1.609 3.344 1.609 3.344 1.563 3.219 2.625 3.766 3.234 3.437 0 0 0.797-0.484 0.625-4.375-0.063-1.406-0.453-2.047-0.453-2.047-0.359-0.484-1.031-0.625-1.328-0.672-0.234-0.031 0.156-0.594 0.672-0.844 0.766-0.375 2.125-0.391 3.734-0.375 1.266 0.016 1.625 0.094 2.109 0.203 1.484 0.359 0.984 1.734 0.984 5.047 0 1.062-0.203 2.547 0.562 3.031 0.328 0.219 1.141 0.031 3.141-3.375 0 0 0.938-1.625 1.672-3.516 0.125-0.344 0.391-0.484 0.391-0.484s0.25-0.141 0.594-0.094l4.5-0.031c1.359-0.172 1.578 0.453 1.578 0.453z"
/>
</svg>
</a>
</li>
</ul>
</div>
`;

View File

@@ -4,6 +4,6 @@
@import "../../../assets/scss/mixins";
.copyright {
color: color.adjust($color-gray, 18%);
color: color.adjust($color-gray, $whiteness: 18%);
font-size: $typographic-small-font-size;
}

View File

@@ -2,10 +2,11 @@ import React from "react";
import renderer from "react-test-renderer";
import { Copyright } from "@/components/Sidebar/Copyright";
import * as mocks from "@/mocks";
describe("Copyright", () => {
it("renders correctly", () => {
const props = { copyright: "copyright" };
const props = { copyright: mocks.siteMetadata.site.siteMetadata.copyright };
const tree = renderer.create(<Copyright {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});

View File

@@ -1,6 +1,6 @@
import React from "react";
import styles from "./Copyright.module.scss";
import * as styles from "./Copyright.module.scss";
type Props = {
copyright: string;

View File

@@ -1,9 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Copyright renders correctly 1`] = `
<div
className="copyright"
>
copyright
<div>
All rights reserved.
</div>
`;

View File

@@ -4,16 +4,16 @@
.menu {
@include margin-bottom(1);
&__list {
.list {
list-style: none;
margin: 0;
padding: 0;
@include margin-equal(0);
@include padding-equal(0);
&-item {
margin: 10px 0;
padding: 0;
.item {
@include margin(0.5, 0);
@include padding-equal(0);
&-link {
.link {
border: 0;
color: $typographic-base-font-color;
font-size: $typographic-base-font-size;
@@ -25,7 +25,7 @@
color: $color-primary;
}
&--active {
&.active {
border-bottom: 1px solid $color-base;
color: $color-base;
}

View File

@@ -5,11 +5,8 @@ import { Menu } from "@/components/Sidebar/Menu";
import * as mocks from "@/mocks";
describe("Menu", () => {
const props = {
menu: mocks.menu,
};
it("renders correctly", () => {
const props = { menu: mocks.menu };
const tree = renderer.create(<Menu {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});

View File

@@ -2,24 +2,24 @@ import React from "react";
import { Link } from "gatsby";
import styles from "./Menu.module.scss";
import * as styles from "./Menu.module.scss";
type Props = {
menu: {
menu: Array<{
label: string;
path: string;
}[];
}>;
};
const Menu: React.FC<Props> = ({ menu }: Props) => (
<nav className={styles.menu}>
<ul className={styles.menu__list}>
<ul className={styles.list}>
{menu.map(item => (
<li className={styles["menu__list-item"]} key={item.path}>
<li className={styles.item} key={item.path}>
<Link
to={item.path}
className={styles["menu__list-item-link"]}
activeClassName={styles["menu__list-item-link--active"]}
className={styles.link}
activeClassName={styles.active}
>
{item.label}
</Link>

View File

@@ -1,37 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Menu renders correctly 1`] = `
<nav
className="menu"
>
<ul
className="menu__list"
>
<li
className="menu__list-item"
>
<nav>
<ul>
<li>
<a
className="menu__list-item-link"
href="/"
>
Articles
</a>
</li>
<li
className="menu__list-item"
>
<li>
<a
className="menu__list-item-link"
href="/pages/about"
>
About Me
</a>
</li>
<li
className="menu__list-item"
>
<li>
<a
className="menu__list-item-link"
href="/pages/contacts"
>
Contact Me

View File

@@ -3,8 +3,9 @@
.sidebar {
width: 100%;
&__inner {
padding: 25px 20px 0;
.inner {
@include padding(1, 0.75, 0);
position: relative;
}
}
@@ -12,8 +13,10 @@
@include breakpoint-sm {
.sidebar {
lost-column: 5/12;
&__inner {
padding: 30px 20px 0;
.inner {
@include padding(1.25, 0.75, 0);
&:after {
background: $color-gray-border;
background: linear-gradient(
@@ -37,8 +40,9 @@
@include breakpoint-md {
.sidebar {
lost-column: 1/3;
&__inner {
padding: 40px;
.inner {
@include padding-equal(1.5);
}
}
}

View File

@@ -17,11 +17,8 @@ describe("Sidebar", () => {
mockedUseStaticQuery.mockReturnValue(mocks.siteMetadata);
});
const props = {
isIndex: true,
};
it("renders correctly", () => {
const props = { isIndex: true };
const tree = renderer.create(<Sidebar {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});

View File

@@ -7,7 +7,7 @@ import { Contacts } from "./Contacts";
import { Copyright } from "./Copyright";
import { Menu } from "./Menu";
import styles from "./Sidebar.module.scss";
import * as styles from "./Sidebar.module.scss";
type Props = {
isIndex?: boolean;
@@ -18,7 +18,7 @@ const Sidebar = ({ isIndex }: Props) => {
return (
<div className={styles.sidebar}>
<div className={styles.sidebar__inner}>
<div className={styles.inner}>
<Author author={author} isIndex={isIndex} />
<Menu menu={menu} />
<Contacts contacts={author.contacts} />

View File

@@ -1,73 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Sidebar renders correctly 1`] = `
<div
className="sidebar"
>
<div
className="sidebar__inner"
>
<div
className="author"
>
<div>
<div>
<div>
<a
href="/"
>
<img
alt="John Doe"
className="author__photo"
height="75"
src="/static/photo.jpg"
width="75"
/>
</a>
<h1
className="author__title"
>
/>
<h1>
<a
className="author__title-link"
href="/"
>
John Doe
</a>
</h1>
<p
className="author__subtitle"
>
<p>
Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu.
</p>
</div>
<nav
className="menu"
>
<ul
className="menu__list"
>
<li
className="menu__list-item"
>
<nav>
<ul>
<li>
<a
className="menu__list-item-link"
href="/"
>
Articles
</a>
</li>
<li
className="menu__list-item"
>
<li>
<a
className="menu__list-item-link"
href="/pages/about"
>
About Me
</a>
</li>
<li
className="menu__list-item"
>
<li>
<a
className="menu__list-item-link"
href="/pages/contacts"
>
Contact Me
@@ -75,23 +43,15 @@ exports[`Sidebar renders correctly 1`] = `
</li>
</ul>
</nav>
<div
className="contacts"
>
<ul
className="contacts__list"
>
<li
className="contacts__list-item"
>
<div>
<ul>
<li>
<a
className="contacts__list-item-link"
href="#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 22 28"
>
<title>
@@ -103,17 +63,13 @@ exports[`Sidebar renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="mailto:#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 28 28"
>
<title>
@@ -125,17 +81,13 @@ exports[`Sidebar renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="https://github.com/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 26 28"
>
<title>
@@ -147,17 +99,13 @@ exports[`Sidebar renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="https://www.twitter.com/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 26 28"
>
<title>
@@ -169,17 +117,13 @@ exports[`Sidebar renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<li>
<a
className="contacts__list-item-link"
href="https://t.me/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 28 28"
>
<title>
@@ -191,33 +135,9 @@ exports[`Sidebar renders correctly 1`] = `
</svg>
</a>
</li>
<li
className="contacts__list-item"
>
<a
className="contacts__list-item-link"
href="https://vk.com/#"
rel="noopener noreferrer"
target="_blank"
>
<svg
className="icon"
viewBox="0 0 31 28"
>
<title>
vkontakte
</title>
<path
d="M29.953 8.125c0.234 0.641-0.5 2.141-2.344 4.594-3.031 4.031-3.359 3.656-0.859 5.984 2.406 2.234 2.906 3.313 2.984 3.453 0 0 1 1.75-1.109 1.766l-4 0.063c-0.859 0.172-2-0.609-2-0.609-1.5-1.031-2.906-3.703-4-3.359 0 0-1.125 0.359-1.094 2.766 0.016 0.516-0.234 0.797-0.234 0.797s-0.281 0.297-0.828 0.344h-1.797c-3.953 0.25-7.438-3.391-7.438-3.391s-3.813-3.938-7.156-11.797c-0.219-0.516 0.016-0.766 0.016-0.766s0.234-0.297 0.891-0.297l4.281-0.031c0.406 0.063 0.688 0.281 0.688 0.281s0.25 0.172 0.375 0.5c0.703 1.75 1.609 3.344 1.609 3.344 1.563 3.219 2.625 3.766 3.234 3.437 0 0 0.797-0.484 0.625-4.375-0.063-1.406-0.453-2.047-0.453-2.047-0.359-0.484-1.031-0.625-1.328-0.672-0.234-0.031 0.156-0.594 0.672-0.844 0.766-0.375 2.125-0.391 3.734-0.375 1.266 0.016 1.625 0.094 2.109 0.203 1.484 0.359 0.984 1.734 0.984 5.047 0 1.062-0.203 2.547 0.562 3.031 0.328 0.219 1.141 0.031 3.141-3.375 0 0 0.938-1.625 1.672-3.516 0.125-0.344 0.391-0.484 0.391-0.484s0.25-0.141 0.594-0.094l4.5-0.031c1.359-0.172 1.578 0.453 1.578 0.453z"
/>
</svg>
</a>
</li>
</ul>
</div>
<div
className="copyright"
>
<div>
All rights reserved.
</div>
</div>