Skip to content

Commit a9c71e2

Browse files
authored
feat: #241 init v5 new Tag component (#270)
* feat: init v5 tag component
1 parent a4e13fd commit a9c71e2

File tree

11 files changed

+158
-3
lines changed

11 files changed

+158
-3
lines changed

src/components/deprecated-tag/tag.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Meta, Story, Canvas, Controls } from '@storybook/blocks'
2-
import { Tag } from '.'
32
import { RenderHtmlMarkup } from '../../storybook/render-html-markup'
43
import * as TagStories from './tag.stories'
54

src/components/deprecated-tag/tag.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DeprecatedTag, DeprecatedTagGroup } from '.'
22

33
export default {
4-
title: 'Tag',
4+
title: 'DeprecatedTag',
55
component: DeprecatedTag,
66
}
77

src/components/status-indicator/__tests__/status-indicator.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { render } from '@testing-library/react'
2-
import { StatusIndicator } from '../status-indicator'
2+
import { StatusIndicator } from '..'
33

44
describe('StatusIndicator', () => {
55
it('should render as expected', () => {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Tag > should render standalone tag properly and match snapshot 1`] = `
4+
<DocumentFragment>
5+
<span
6+
class="mocked-styled-0 el-standalone-tag"
7+
>
8+
Tag
9+
</span>
10+
</DocumentFragment>
11+
`;
12+
13+
exports[`Tag > should render tag group properly and match snapshot 1`] = `
14+
<DocumentFragment>
15+
<ul
16+
class="mocked-styled-2 el-tag-group"
17+
>
18+
<li
19+
class="mocked-styled-1 el-tag"
20+
>
21+
Tag
22+
</li>
23+
</ul>
24+
</DocumentFragment>
25+
`;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { render } from '@testing-library/react'
2+
import { Tag, TagGroup } from '..'
3+
4+
describe('Tag', () => {
5+
it('should render tag group properly and match snapshot', () => {
6+
const { asFragment } = render(
7+
<TagGroup>
8+
<Tag>Tag</Tag>
9+
</TagGroup>,
10+
)
11+
expect(asFragment()).toMatchSnapshot()
12+
})
13+
it('should render standalone tag properly and match snapshot', () => {
14+
const { asFragment } = render(<Tag isStandalone>Tag</Tag>)
15+
expect(asFragment()).toMatchSnapshot()
16+
})
17+
})

src/components/tag/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './tag'
2+
export * from './styles'

src/components/tag/styles.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { styled } from '@linaria/react'
2+
3+
const baseTagStyle = `
4+
width: fit-content;
5+
padding: var(--spacing-half) var(--spacing-3);
6+
border-radius: var(--corner-xl);
7+
background: var(--fill-default-light);
8+
color: var(--text-tertiary);
9+
font-family: var(--font-family);
10+
font-size: var(--font-size-xs);
11+
font-weight: var(--font-weight-medium);
12+
line-height: var(--line-height-xs);
13+
letter-spacing: var(--letter-spacing-xs);
14+
15+
display: list-item;
16+
&::marker {
17+
content: '';
18+
}
19+
`
20+
21+
export const ElStandaloneTag = styled.span`
22+
${baseTagStyle}
23+
`
24+
export const ElTag = styled.li`
25+
${baseTagStyle}
26+
`
27+
28+
export const ElTagGroup = styled.ul`
29+
display: inline-flex;
30+
align-items: flex-start;
31+
gap: var(--spacing-1);
32+
`

src/components/tag/tag.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Meta, Canvas, Controls, Description } from '@storybook/blocks'
2+
import { RenderHtmlMarkup } from '../../storybook/render-html-markup'
3+
import * as TagStories from './tag.stories'
4+
5+
<Meta of={TagStories} />
6+
7+
# Tag / Tag Group
8+
9+
<Description of={TagStories.Default} />
10+
11+
<Controls />
12+
13+
## Default
14+
15+
<Canvas of={TagStories.Default} />
16+
17+
<RenderHtmlMarkup of={TagStories.Default} />
18+
19+
## Tag Group
20+
21+
<Description of={TagStories.TagGroup} />
22+
23+
<Canvas of={TagStories.TagGroup} />
24+
25+
<RenderHtmlMarkup of={TagStories.TagGroup} />

src/components/tag/tag.stories.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import { Tag, TagGroup as TagGroupComponent } from './tag'
3+
4+
export default {
5+
title: 'Components/Tag',
6+
component: Tag,
7+
args: {
8+
children: 'Tag',
9+
isStandalone: false,
10+
},
11+
argTypes: {
12+
isStandalone: {
13+
control: 'boolean',
14+
description: 'whether the component will be rendered as `span` or `li`',
15+
},
16+
},
17+
} as Meta<typeof Tag>
18+
19+
type Story = StoryObj<typeof Tag>
20+
21+
/**
22+
* The `Tag` component is used to label, categorise or organise items using keywords.
23+
*/
24+
export const Default: Story = {
25+
args: {
26+
isStandalone: true,
27+
},
28+
}
29+
30+
/**
31+
* The `TagGroup` Component is useful to render multiple `Tag`
32+
*/
33+
export const TagGroup: Story = {
34+
render: () => (
35+
<TagGroupComponent>
36+
<Tag>Tag</Tag>
37+
<Tag>Tag</Tag>
38+
<Tag>Tag</Tag>
39+
<Tag>Tag</Tag>
40+
<Tag>Tag</Tag>
41+
</TagGroupComponent>
42+
),
43+
}

src/components/tag/tag.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ElStandaloneTag, ElTag, ElTagGroup } from './styles'
2+
3+
export interface TagProps extends React.HTMLAttributes<HTMLLIElement | HTMLSpanElement> {
4+
isStandalone?: boolean
5+
}
6+
7+
export const Tag: React.FC<TagProps> = ({ children, isStandalone = false, ...props }) => {
8+
return isStandalone ? <ElStandaloneTag {...props}>{children}</ElStandaloneTag> : <ElTag {...props}>{children}</ElTag>
9+
}
10+
11+
export const TagGroup = ElTagGroup

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export * from './components/mobile-controls'
4747
export * from './components/drawer'
4848
export * from './components/accordion'
4949
export * from './components/deprecated-tag'
50+
export * from './components/tag'
5051
export * from './components/deprecated-badge'
5152
export * from './components/chip'
5253
export * from './components/tile'

0 commit comments

Comments
 (0)