Skip to content

Commit

Permalink
refactor(anni): extract label as generic component
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Jun 20, 2022
1 parent b594e42 commit 1d5d687
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
20 changes: 20 additions & 0 deletions annotation-interface/components/Label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createElement, ElementType } from 'react';

interface Props<T> extends React.HTMLAttributes<T> {
as?: ElementType;
title: string;
}

function Label<T>({ as: parent, title, ...additionalProps }: Props<T>) {
return createElement(
parent ?? 'span',
{
className:
'border border-black border-opacity-20 text-xs px-2 rounded-full whitespace-nowrap font-semibold align-text-top mr-2',
...additionalProps,
},
title,
);
}

export default Label;
10 changes: 5 additions & 5 deletions annotation-interface/pages/bricks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Link from 'next/link';

import { displayCategories } from '../../common/constants';
import FilterTabs, { DisplayFilterProps } from '../../components/FilterTabs';
import Label from '../../components/Label';
import PageHeading from '../../components/PageHeading';
import dbConnect from '../../database/connect';
import TextBrick from '../../database/models/TextBrick';
Expand Down Expand Up @@ -69,18 +70,17 @@ const AllTextBricks = ({
)}
</a>
</Link>
<button
className="border border-black border-opacity-20 text-xs px-2 rounded-full whitespace-nowrap font-semibold align-text-top mr-2"
<Label
as="button"
title={brick.usage}
onClick={() =>
display.setCategoryIndex(
displayCategories.indexOf(
brick.usage,
),
)
}
>
{brick.usage}
</button>
/>
</p>
))}
</div>
Expand Down

0 comments on commit 1d5d687

Please sign in to comment.