Skip to content

feat: create article data tag component #5280

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

Merged
merged 1 commit into from
Apr 18, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Data Tag component renders with blue background color when tag is 'M' 1`] = `
<div>
<span
class="dataTag"
data-tag="M"
>
M
</span>
</div>
`;

exports[`Data Tag component renders with red background color when tag is 'E' 1`] = `
<div>
<span
class="dataTag"
data-tag="E"
>
E
</span>
</div>
`;

exports[`Data Tag component renders with yellow background color when tag is 'C' 1`] = `
<div>
<span
class="dataTag"
data-tag="C"
>
C
</span>
</div>
`;
27 changes: 27 additions & 0 deletions components/Article/DataTag/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { render } from '@testing-library/react';
import React from 'react';

import DataTag from '..';

describe('Data Tag component', () => {
it(`renders with red background color when tag is 'E'`, () => {
const { container } = render(<DataTag tag="E" />);

expect(container).toHaveStyle('background-color: var(--danger6)');
expect(container).toMatchSnapshot();
});

it(`renders with yellow background color when tag is 'C'`, () => {
const { container } = render(<DataTag tag="C" />);

expect(container).toHaveStyle('background-color: var(--warning4)');
expect(container).toMatchSnapshot();
});

it(`renders with blue background color when tag is 'M'`, () => {
const { container } = render(<DataTag tag="M" />);

expect(container).toHaveStyle('background-color: var(--info6)');
expect(container).toMatchSnapshot();
});
});
26 changes: 26 additions & 0 deletions components/Article/DataTag/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.dataTag {
border-radius: 50%;
color: #fff;
display: inline-block;
font-family: var(--sans);
font-size: 1.4rem;
font-weight: var(--font-weight-light);
height: 2.4rem;
line-height: 2.4rem;
margin-right: 0.8rem;
min-width: 2.4rem;
text-align: center;
width: 2.4rem;

&[data-tag='C'] {
background-color: var(--warning4);
}

&[data-tag='E'] {
background-color: var(--danger6);
}

&[data-tag='M'] {
background-color: var(--info6);
}
}
24 changes: 24 additions & 0 deletions components/Article/DataTag/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { StoryObj } from '@storybook/react';
import DataTag from '.';

export default { component: DataTag };

type Story = StoryObj<typeof DataTag>;

export const Red: Story = {
args: {
tag: 'E',
},
};

export const Yellow: Story = {
args: {
tag: 'C',
},
};

export const Blue: Story = {
args: {
tag: 'M',
},
};
14 changes: 14 additions & 0 deletions components/Article/DataTag/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import styles from './index.module.scss';

interface Props {
tag: 'E' | 'C' | 'M';
}

const DataTag = ({ tag }: Props) => (
<span className={styles.dataTag} data-tag={tag}>
{tag}
</span>
);

export default DataTag;