Skip to content

Commit

Permalink
fix: add new class instead has selector
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVorop committed Feb 2, 2024
1 parent ea3bea3 commit b5e8579
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
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>
);
};

0 comments on commit b5e8579

Please sign in to comment.