Skip to content
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
52 changes: 52 additions & 0 deletions packages/ui-components/Common/DataTag/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@reference "../../styles/index.css";

.dataTag {
@apply flex
items-center
justify-center
rounded-full
font-semibold
text-white;

&.lg {
@apply size-12
text-2xl;
}

&.md {
@apply size-10
text-xl;
}

&.sm {
@apply size-8;
}

&.event {
@apply bg-accent1-600;
}

&.method {
@apply bg-info-600;
}

&.property {
@apply bg-green-600;
}

&.class {
@apply bg-warning-600;
}

&.module {
@apply bg-red-600;
}

&.classMethod {
@apply bg-blue-600;
}

&.ctor {
@apply bg-accent2-600;
}
}
31 changes: 31 additions & 0 deletions packages/ui-components/Common/DataTag/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import DataTag, { type DataTagProps } from '#ui/Common/DataTag';

type Story = StoryObj<typeof DataTag>;
type Meta = MetaObj<typeof DataTag>;

export const DataTags: Story = {
render: () => (
<div className="grid grid-cols-3 gap-6 p-6">
{['event', 'method', 'property', 'class', 'module', 'classMethod', 'ctor']
.map(kind =>
['sm', 'md', 'lg'].map(size => (
<div
key={`${kind}-${size}`}
className="flex justify-center"
title={kind}
>
<DataTag
kind={kind as DataTagProps['kind']}
size={size as DataTagProps['size']}
/>
</div>
))
)
.flat()}
</div>
),
};

export default { component: DataTag } as Meta;
37 changes: 37 additions & 0 deletions packages/ui-components/Common/DataTag/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import classNames from 'classnames';
import type { FC } from 'react';

import styles from './index.module.css';

export type DataTagProps = {
kind:
| 'event'
| 'method'
| 'property'
| 'class'
| 'module'
| 'classMethod'
| 'ctor';
size?: 'lg' | 'md' | 'sm';
};

// These symbols match up with the types used in
// node core, and the ones defined at
// https://github.com/nodejs/api-docs-tooling/blob/main/src/types.d.ts#L22 (`HeadingMetadataEntry['type']`)
const symbolMap = {
event: 'E',
method: 'M',
property: 'P',
class: 'C',
module: 'M',
classMethod: 'S',
ctor: 'C',
} as const;

const DataTag: FC<DataTagProps> = ({ kind, size = 'md' }) => (
<div className={classNames(styles.dataTag, styles[size], styles[kind])}>
<span>{symbolMap[kind]}</span>
</div>
);

export default DataTag;
Loading