Skip to content

Commit e121b83

Browse files
feat: create article data tag component (#5280)
1 parent 390c2da commit e121b83

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Data Tag component renders with blue background color when tag is 'M' 1`] = `
4+
<div>
5+
<span
6+
class="dataTag"
7+
data-tag="M"
8+
>
9+
M
10+
</span>
11+
</div>
12+
`;
13+
14+
exports[`Data Tag component renders with red background color when tag is 'E' 1`] = `
15+
<div>
16+
<span
17+
class="dataTag"
18+
data-tag="E"
19+
>
20+
E
21+
</span>
22+
</div>
23+
`;
24+
25+
exports[`Data Tag component renders with yellow background color when tag is 'C' 1`] = `
26+
<div>
27+
<span
28+
class="dataTag"
29+
data-tag="C"
30+
>
31+
C
32+
</span>
33+
</div>
34+
`;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { render } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import DataTag from '..';
5+
6+
describe('Data Tag component', () => {
7+
it(`renders with red background color when tag is 'E'`, () => {
8+
const { container } = render(<DataTag tag="E" />);
9+
10+
expect(container).toHaveStyle('background-color: var(--danger6)');
11+
expect(container).toMatchSnapshot();
12+
});
13+
14+
it(`renders with yellow background color when tag is 'C'`, () => {
15+
const { container } = render(<DataTag tag="C" />);
16+
17+
expect(container).toHaveStyle('background-color: var(--warning4)');
18+
expect(container).toMatchSnapshot();
19+
});
20+
21+
it(`renders with blue background color when tag is 'M'`, () => {
22+
const { container } = render(<DataTag tag="M" />);
23+
24+
expect(container).toHaveStyle('background-color: var(--info6)');
25+
expect(container).toMatchSnapshot();
26+
});
27+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.dataTag {
2+
border-radius: 50%;
3+
color: #fff;
4+
display: inline-block;
5+
font-family: var(--sans);
6+
font-size: 1.4rem;
7+
font-weight: var(--font-weight-light);
8+
height: 2.4rem;
9+
line-height: 2.4rem;
10+
margin-right: 0.8rem;
11+
min-width: 2.4rem;
12+
text-align: center;
13+
width: 2.4rem;
14+
15+
&[data-tag='C'] {
16+
background-color: var(--warning4);
17+
}
18+
19+
&[data-tag='E'] {
20+
background-color: var(--danger6);
21+
}
22+
23+
&[data-tag='M'] {
24+
background-color: var(--info6);
25+
}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { StoryObj } from '@storybook/react';
2+
import DataTag from '.';
3+
4+
export default { component: DataTag };
5+
6+
type Story = StoryObj<typeof DataTag>;
7+
8+
export const Red: Story = {
9+
args: {
10+
tag: 'E',
11+
},
12+
};
13+
14+
export const Yellow: Story = {
15+
args: {
16+
tag: 'C',
17+
},
18+
};
19+
20+
export const Blue: Story = {
21+
args: {
22+
tag: 'M',
23+
},
24+
};

components/Article/DataTag/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import styles from './index.module.scss';
3+
4+
interface Props {
5+
tag: 'E' | 'C' | 'M';
6+
}
7+
8+
const DataTag = ({ tag }: Props) => (
9+
<span className={styles.dataTag} data-tag={tag}>
10+
{tag}
11+
</span>
12+
);
13+
14+
export default DataTag;

0 commit comments

Comments
 (0)