mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
detecting tag features
This commit is contained in:
parent
453f13f3db
commit
15f2bb3d96
2 changed files with 19 additions and 36 deletions
|
@ -4,9 +4,14 @@ import { ITag } from '~/redux/types';
|
||||||
|
|
||||||
import classNames = require('classnames');
|
import classNames = require('classnames');
|
||||||
|
|
||||||
|
const getTagFeature = (tag: ITag) => {
|
||||||
|
if (tag.title.substr(0, 1) === '/') return 'green';
|
||||||
|
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
title: ITag['title'];
|
tag: ITag;
|
||||||
feature?: ITag['feature'];
|
|
||||||
|
|
||||||
is_hoverable?: boolean;
|
is_hoverable?: boolean;
|
||||||
onInput?: ChangeEventHandler<HTMLInputElement>;
|
onInput?: ChangeEventHandler<HTMLInputElement>;
|
||||||
|
@ -14,23 +19,15 @@ interface IProps {
|
||||||
onBlur?: FocusEventHandler<HTMLInputElement>;
|
onBlur?: FocusEventHandler<HTMLInputElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Tag: FC<IProps> = ({
|
const Tag: FC<IProps> = ({ tag, is_hoverable, onInput, onKeyUp, onBlur }) => (
|
||||||
title,
|
<div className={classNames(styles.tag, getTagFeature(tag), { is_hoverable, input: !!onInput })}>
|
||||||
feature,
|
|
||||||
|
|
||||||
is_hoverable,
|
|
||||||
onInput,
|
|
||||||
onKeyUp,
|
|
||||||
onBlur,
|
|
||||||
}) => (
|
|
||||||
<div className={classNames(styles.tag, feature, { is_hoverable, input: !!onInput })}>
|
|
||||||
<div className={styles.hole} />
|
<div className={styles.hole} />
|
||||||
<div className={styles.title}>{title}</div>
|
<div className={styles.title}>{tag.title}</div>
|
||||||
|
|
||||||
{onInput && (
|
{onInput && (
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={title}
|
value={tag.title}
|
||||||
size={1}
|
size={1}
|
||||||
placeholder="Добавить"
|
placeholder="Добавить"
|
||||||
maxLength={24}
|
maxLength={24}
|
||||||
|
@ -43,5 +40,3 @@ const Tag: FC<IProps> = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
export { Tag };
|
export { Tag };
|
||||||
|
|
||||||
// </div>
|
|
||||||
|
|
|
@ -68,21 +68,6 @@ export const Tags: FC<IProps> = ({ tags, is_editable, onTagsChange, ...props })
|
||||||
onTagsChange(uniq([...tags, ...data]).map(tag => tag.title));
|
onTagsChange(uniq([...tags, ...data]).map(tag => tag.title));
|
||||||
}, [tags, data, onTagsChange]);
|
}, [tags, data, onTagsChange]);
|
||||||
|
|
||||||
// const onBlur = useCallback(() => {
|
|
||||||
// clearTimeout(timer.current);
|
|
||||||
// onSubmit();
|
|
||||||
// }, [onSubmit, timer]);
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// timer.current = setTimeout(() => {
|
|
||||||
// onSubmit();
|
|
||||||
// }, 3000);
|
|
||||||
|
|
||||||
// return () => {
|
|
||||||
// clearTimeout(timer.current);
|
|
||||||
// };
|
|
||||||
// }, [data]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setData(data.filter(({ title }) => !tags.some(tag => tag.title.trim() === title.trim())));
|
setData(data.filter(({ title }) => !tags.some(tag => tag.title.trim() === title.trim())));
|
||||||
}, [tags]);
|
}, [tags]);
|
||||||
|
@ -90,13 +75,16 @@ export const Tags: FC<IProps> = ({ tags, is_editable, onTagsChange, ...props })
|
||||||
return (
|
return (
|
||||||
<TagField {...props}>
|
<TagField {...props}>
|
||||||
{tags.map(tag => (
|
{tags.map(tag => (
|
||||||
<Tag key={tag.title} title={tag.title} feature={tag.feature} />
|
<Tag key={tag.title} tag={tag} />
|
||||||
))}
|
|
||||||
{data.map(tag => (
|
|
||||||
<Tag key={tag.title} title={tag.title} feature={tag.feature} />
|
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{is_editable && <Tag title={input} onInput={onInput} onKeyUp={onKeyUp} onBlur={onSubmit} />}
|
{data.map(tag => (
|
||||||
|
<Tag key={tag.title} tag={tag} />
|
||||||
|
))}
|
||||||
|
|
||||||
|
{is_editable && (
|
||||||
|
<Tag tag={{ title: input }} onInput={onInput} onKeyUp={onKeyUp} onBlur={onSubmit} />
|
||||||
|
)}
|
||||||
</TagField>
|
</TagField>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue