Skip to content

Commit

Permalink
feat(project): add card component and first test
Browse files Browse the repository at this point in the history
  • Loading branch information
demmyhonore committed Apr 28, 2021
1 parent 31fc7ff commit e82f950
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom'
43 changes: 43 additions & 0 deletions src/components/Card/Card.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.root {
position: relative;
overflow: hidden;
width: 100%;
}

.oneOne {
padding-bottom: 100%;
}

.twoOne {
padding-bottom: 50%;
}

.twoThree {
padding-bottom: (3 / 2) * 100%;
}

.fiveThree {
padding-bottom: 60%;
}

.fourThree {
padding-bottom: 75%;
}

.sixteenNine {
padding-bottom: (9 / 16) * 100%;
}

.container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: var(--card-slider-loading-card-bg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
border-radius: 4px;
}

12 changes: 12 additions & 0 deletions src/components/Card/Card.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { render } from '@testing-library/react';

import Card from './Card';

describe('<Card>', () => {
it('renders card', () => {
const { getByText } = render(<Card title="aa" duration={120} />);
const card = getByText(/card/i);
expect(card).toBeTruthy();
});
});
30 changes: 30 additions & 0 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import classNames from 'classnames';

import { ASPECT_RATIO } from '../../enum/Card.js'

import styles from './Card.module.scss';

type CardProps = {
title: string;
duration: number;
imageSource?: string;
aspectRatio?: string;
};

function Card({
title,
duration,
imageSource,
aspectRatio = ASPECT_RATIO[16_9],
}: CardProps): JSX.Element {
return (
<div className={classNames(styles.root, styles[aspectRatio])}>
<div className={styles.container} style={{ backgroundImage: `url(${imageSource})` }}>
<span>Card</span>
</div>
</div >
);
}

export default Card;
2 changes: 1 addition & 1 deletion src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

:root {
--primary-color: #{theme.$primary-color};

--body-background-color: #{theme.$body-bg-color};
--card-slider-loading-card-bg: #{theme.$card-slider-loading-card-bg};
}

body {
Expand Down

0 comments on commit e82f950

Please sign in to comment.