Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmony: fix Tag selector #787

Merged
merged 1 commit into from
Feb 2, 2024
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
2 changes: 1 addition & 1 deletion src/harmony/Tag/Tag.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
transition: color 200ms ease-in;
}

.Tag:not(:has(.Button)) {
.Tag_interactive {
padding-right: var(--gap-sm);
}

Expand Down
17 changes: 11 additions & 6 deletions src/harmony/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,30 @@ export const TagsList = () => {
</div>
<div style={{ display: 'flex', gap: 4 }}>
{tags.map((tag) => (
<Tag key={tag}>
<Tag key={tag} action={<TagCleanButton />}>
{tag}
<TagCleanButton />
</Tag>
))}
</div>
<div style={{ display: 'flex', gap: 4 }}>
{tags.map((tag) => (
<Tag key={tag} onClick={tag.length <= 5 ? () => {} : undefined}>
<Tag
key={tag}
onClick={tag.length <= 5 ? () => {} : undefined}
action={tag.length <= 5 && <TagCleanButton />}
>
{tag}
{tag.length <= 5 && <TagCleanButton />}
</Tag>
))}
</div>
<div style={{ display: 'flex', gap: 4, maxWidth: 200, flexWrap: 'wrap' }}>
{tags.map((tag) => (
<Tag key={tag} onClick={tag.length <= 5 ? () => {} : undefined}>
<Tag
key={tag}
onClick={tag.length <= 5 ? () => {} : undefined}
action={tag.length <= 5 && <TagCleanButton />}
>
{tag}
{tag.length <= 5 && <TagCleanButton />}
</Tag>
))}
</div>
Expand Down
14 changes: 10 additions & 4 deletions src/harmony/Tag/Tag.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ComponentProps, HTMLAttributes, MouseEvent, useCallback } from 'react';
import React, { ComponentProps, HTMLAttributes, MouseEvent, ReactNode, useCallback } from 'react';
import cn from 'classnames';
import { IconXSmallOutline } from '@taskany/icons';

Expand Down Expand Up @@ -33,12 +33,18 @@ export const TagCleanButton = ({
);
};

interface TagProps extends HTMLAttributes<HTMLDivElement> {}
interface TagProps extends HTMLAttributes<HTMLDivElement> {
action?: ReactNode;
}

export const Tag = ({ className, children, ...props }: TagProps) => {
export const Tag = ({ className, children, action, ...props }: TagProps) => {
return (
<div className={cn(s.Tag, { [s.Tag_hovered]: Boolean(props.onClick) }, className)} {...props}>
<div
className={cn(s.Tag, { [s.Tag_hovered]: !!props.onClick, [s.Tag_interactive]: !action }, className)}
{...props}
>
{children}
{action}
</div>
);
};
Loading