Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4765 feat/base card #20

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/components/BaseCard/BaseCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { render, screen } from '@testing-library/react';
import { expect } from '@jest/globals';
import '@testing-library/jest-dom/extend-expect';

import BaseCard from './BaseCard';

describe('<BaseCard />', () => {
let container: HTMLElement;

beforeEach(() => {
container = render(
<BaseCard>
<div>Test</div>
</BaseCard>,
).container;
});

it('should be defined', () => {
expect(container).toBeDefined();
});

it('should render with: background-color: white as default', () => {
(expect as any)(container).toHaveStyle('background-color: + white');
});

it('should render with: padding: 2rem as default', () => {
(expect as any)(container).toHaveStyle('padding: + 2rem');
});

it('should render with: border: 1px solid var(--gray) as default', () => {
(expect as any)(container).toHaveStyle('border: + 1px solid var(--gray)');
});

it('should render children', () => {
const element = screen.getByText('Test');

expect(element).toBeDefined();
});

it('should render with: background-color: var(--purple) when prop is passed', () => {
container = render(
<BaseCard backgroundColor="purple">
<div>Test</div>
</BaseCard>,
).container;

(expect as any)(container).toHaveStyle('background-color: + var(--purple)');
});

it('should render with: padding: var(--font-size-small) when prop is passed', () => {
container = render(
<BaseCard padding="small">
<div>Test</div>
</BaseCard>,
).container;

(expect as any)(container).toHaveStyle('padding: + var(--font-size-small)');
});

it('should render with: border: 1px solid var(--purple) when prop is passed', () => {
container = render(
<BaseCard borderColor="purple">
<div>Test</div>
</BaseCard>,
).container;

(expect as any)(container).toHaveStyle('border: + 1px solid var(--purple)');
});
});
11 changes: 11 additions & 0 deletions src/components/BaseCard/BaseCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as S from './styles';

const BaseCard = ({ children, ...styleProps }: BaseCardProps) => {
return (
<S.BaseCard {...styleProps} className="base-card">
{children}
</S.BaseCard>
);
};

export default BaseCard;
1 change: 1 addition & 0 deletions src/components/BaseCard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './BaseCard';
15 changes: 15 additions & 0 deletions src/components/BaseCard/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import styled from 'styled-components';

export const BaseCard = styled.div<
Pick<BaseCardProps, 'padding' | 'borderColor' | 'backgroundColor'>
>`
display: flex;
border-radius: 1rem;
padding: ${({ padding }) =>
padding ? `var(--font-size-${padding})` : 'var(--font-size-large)'};
box-shadow: 0px 1rem 2rem rgba(207.7, 207.7, 207.7, 0.2);
border: ${({ borderColor }) =>
borderColor ? `1px solid var(--${borderColor})` : '1px solid var(--gray)'};
background-color: ${({ backgroundColor }) =>
backgroundColor ? `var(--${backgroundColor})` : 'var(--white)'};
`;
1 change: 1 addition & 0 deletions src/styles/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default createGlobalStyle`
--font-size-small: 0.875rem;
--font-size-xsmall: 0.75rem;
--font-size-medium: 1.125rem;
--font-size-xmedium: 1.5rem;
--font-size-large: 2rem;
--font-size-xlarge: 3rem;
}
Expand Down
6 changes: 6 additions & 0 deletions src/types/BaseCardProps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type BaseCardProps = {
padding?: 'large' | 'xmedium' | 'small';
borderColor?: 'purple';
backgroundColor?: 'purple' | 'white';
children: React.ReactNode;
};