refactor: extract Tag to its own component

This commit is contained in:
Antonella Sgarlatta
2021-05-25 15:57:51 -03:00
parent 2b734415e4
commit cdf8f60655
2 changed files with 18 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
import { AppState } from '@/ui_models/app_state';
import { observer } from 'mobx-react-lite';
import { toDirective } from './utils';
import { Icon } from './Icon';
import { Tag } from './Tag';
import { AutocompleteTagInput } from './AutocompleteTagInput';
import { WebApplication } from '@/ui_models/application';
@@ -14,10 +14,7 @@ const NoteTags = observer(({ application, appState }: Props) => {
return (
<div className="flex flex-wrap">
{appState.notes.activeNoteTags.map((tag) => (
<span key={tag.uuid} className="bg-contrast rounded text-xs color-text p-1 flex items-center mt-2 mr-2">
<Icon type="hashtag" className="small color-neutral mr-1" />
{tag.title}
</span>
<Tag key={tag.uuid} title={tag.title} className="mt-2 mr-2" />
))}
<AutocompleteTagInput application={application} appState={appState} />
</div>

View File

@@ -0,0 +1,16 @@
import { FunctionalComponent } from 'preact';
import { Icon } from './Icon';
type TagProps = {
title: string;
className?: string;
};
export const Tag: FunctionalComponent<TagProps> = ({ title, className }) => (
<span
className={`bg-contrast rounded text-xs color-text p-1 flex items-center ${className ?? ''}`}
>
<Icon type="hashtag" className="small color-neutral mr-1" />
{title}
</span>
);