Skip to content

Commit

Permalink
Merge pull request #11 from nickovchinnikov/nick/tile
Browse files Browse the repository at this point in the history
Add tile component
  • Loading branch information
nickovchinnikov authored Mar 18, 2022
2 parents 2b0d2f2 + 898f38b commit e56dcf8
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

[pull request](https://github.com/nickovchinnikov/coursesbox/pull/4)


## React and Typescript Review

### JSX at Glance
Expand Down Expand Up @@ -51,3 +52,10 @@
### Visual testing and Chromatic

[pull request](https://github.com/nickovchinnikov/coursesbox/pull/10)


## Storybook and Components Library

### Tile component

[pull request](https://github.com/nickovchinnikov/coursesbox/pull/11)
1 change: 0 additions & 1 deletion components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import { ComponentStoryObj, ComponentMeta } from "@storybook/react";
import { expect } from "@storybook/jest";
import { screen, userEvent } from "@storybook/testing-library";
Expand Down
4 changes: 2 additions & 2 deletions components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from "@emotion/styled";
import { css, SerializedStyles } from "@emotion/react";

import { AppTheme } from "@/styles/themes";
import { boxShadow, transition } from "@/components/styles";
import { boxShadow, transition, borderRadius } from "@/components/styles";

export type Color = "primary" | "secondary" | "danger" | "warning";

Expand Down Expand Up @@ -46,7 +46,7 @@ export const Button = styled.button<Props>`
font-size: 1.6rem;
width: 15rem;
height: 4rem;
border-radius: 1rem;
${borderRadius};
${({ theme, color }) => getColors(theme, color)};
&:hover {
opacity: 0.9;
Expand Down
2 changes: 1 addition & 1 deletion components/Button/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Button test cases Render check 1`] = `
<DocumentFragment>
<button
class="css-1s99dgh"
class="css-1rttvxo"
color="primary"
>
Button
Expand Down
47 changes: 47 additions & 0 deletions components/Tile/Tile.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect } from "@storybook/jest";
import { screen } from "@storybook/testing-library";
import { ComponentStoryObj, ComponentMeta } from "@storybook/react";

import { Tile } from "./Tile";

export default {
title: "Content/Tile",
component: Tile,
} as ComponentMeta<typeof Tile>;

export const BasicTile: ComponentStoryObj<typeof Tile> = {
play: async () => {
await expect(screen.getByRole("heading")).toBeInTheDocument();
},
args: {
header: "Lorem ipsum dolor sit amet",
children: `Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.`,
},
};
19 changes: 19 additions & 0 deletions components/Tile/Tile.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";

import { render } from "@/test-utils";

import { Tile } from "./Tile";

describe("Tile test cases", () => {
it("Tile render check", () => {
const { asFragment } = render(
<Tile header="Lorem ipsum dolor sit amet">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris
</Tile>
);

expect(asFragment()).toMatchSnapshot();
});
});
24 changes: 24 additions & 0 deletions components/Tile/Tile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { FC } from "react";
import styled from "@emotion/styled";

import { boxShadow, borderRadius } from "@/components/styles";

const Section = styled.section`
${borderRadius};
padding: 1vmin 4vmin 4vmin;
background: ${({ theme }) => theme.background};
color: ${({ theme }) => theme.font.regular};
${({ theme }) =>
boxShadow(theme.components.shadow1, theme.components.shadow2)}
`;

type Props = {
header: string;
};

export const Tile: FC<Props> = ({ header, children }) => (
<Section>
<h2>{header}</h2>
{children}
</Section>
);
14 changes: 14 additions & 0 deletions components/Tile/__snapshots__/Tile.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tile test cases Tile render check 1`] = `
<DocumentFragment>
<section
class="css-brv202"
>
<h2>
Lorem ipsum dolor sit amet
</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
</section>
</DocumentFragment>
`;
4 changes: 4 additions & 0 deletions components/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const boxShadow = (
`;
};

export const borderRadius = css`
border-radius: 1rem;
`;

export const transition = () =>
css`
transition: all 0.4s ease;
Expand Down
4 changes: 2 additions & 2 deletions styles/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const light: AppTheme = {
warning: "#ffca2ce6;",
},
font: {
regular: "#5e5c64e6",
regular: "#504e55e6",
button: "#E4EBF5e6",
warning: "#5e5c64e6",
warning: "#504e55e6",
valid: "#198754e6",
invalid: "#dc3545e6",
},
Expand Down

0 comments on commit e56dcf8

Please sign in to comment.