Skip to content

Commit 79dc769

Browse files
feat(ui): add DataTag (#7797)
* feat(ui): add CircularIcon * tw in story * Apply suggestions from code review Co-authored-by: Caner Akdas <[email protected]> Signed-off-by: Aviv Keller <[email protected]> * fixup! * rename * code review * code review --------- Signed-off-by: Aviv Keller <[email protected]> Co-authored-by: Caner Akdas <[email protected]>
1 parent 73ed14d commit 79dc769

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@reference "../../styles/index.css";
2+
3+
.dataTag {
4+
@apply flex
5+
items-center
6+
justify-center
7+
rounded-full
8+
font-semibold
9+
text-white;
10+
11+
&.lg {
12+
@apply size-12
13+
text-2xl;
14+
}
15+
16+
&.md {
17+
@apply size-10
18+
text-xl;
19+
}
20+
21+
&.sm {
22+
@apply size-8;
23+
}
24+
25+
&.event {
26+
@apply bg-accent1-600;
27+
}
28+
29+
&.method {
30+
@apply bg-info-600;
31+
}
32+
33+
&.property {
34+
@apply bg-green-600;
35+
}
36+
37+
&.class {
38+
@apply bg-warning-600;
39+
}
40+
41+
&.module {
42+
@apply bg-red-600;
43+
}
44+
45+
&.classMethod {
46+
@apply bg-blue-600;
47+
}
48+
49+
&.ctor {
50+
@apply bg-accent2-600;
51+
}
52+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2+
3+
import DataTag, { type DataTagProps } from '#ui/Common/DataTag';
4+
5+
type Story = StoryObj<typeof DataTag>;
6+
type Meta = MetaObj<typeof DataTag>;
7+
8+
export const DataTags: Story = {
9+
render: () => (
10+
<div className="grid grid-cols-3 gap-6 p-6">
11+
{['event', 'method', 'property', 'class', 'module', 'classMethod', 'ctor']
12+
.map(kind =>
13+
['sm', 'md', 'lg'].map(size => (
14+
<div
15+
key={`${kind}-${size}`}
16+
className="flex justify-center"
17+
title={kind}
18+
>
19+
<DataTag
20+
kind={kind as DataTagProps['kind']}
21+
size={size as DataTagProps['size']}
22+
/>
23+
</div>
24+
))
25+
)
26+
.flat()}
27+
</div>
28+
),
29+
};
30+
31+
export default { component: DataTag } as Meta;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import classNames from 'classnames';
2+
import type { FC } from 'react';
3+
4+
import styles from './index.module.css';
5+
6+
export type DataTagProps = {
7+
kind:
8+
| 'event'
9+
| 'method'
10+
| 'property'
11+
| 'class'
12+
| 'module'
13+
| 'classMethod'
14+
| 'ctor';
15+
size?: 'lg' | 'md' | 'sm';
16+
};
17+
18+
// These symbols match up with the types used in
19+
// node core, and the ones defined at
20+
// https://github.com/nodejs/api-docs-tooling/blob/main/src/types.d.ts#L22 (`HeadingMetadataEntry['type']`)
21+
const symbolMap = {
22+
event: 'E',
23+
method: 'M',
24+
property: 'P',
25+
class: 'C',
26+
module: 'M',
27+
classMethod: 'S',
28+
ctor: 'C',
29+
} as const;
30+
31+
const DataTag: FC<DataTagProps> = ({ kind, size = 'md' }) => (
32+
<div className={classNames(styles.dataTag, styles[size], styles[kind])}>
33+
<span>{symbolMap[kind]}</span>
34+
</div>
35+
);
36+
37+
export default DataTag;

0 commit comments

Comments
 (0)