Skip to content

Commit

Permalink
fix(core-components-tag): fix tag background (#151)
Browse files Browse the repository at this point in the history
* fix(core-components-tag): fix tag background

* feat(core-components-tag): add forward ref
  • Loading branch information
dmitrsavk committed Jun 11, 2020
1 parent 33e11eb commit 03b465b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
65 changes: 35 additions & 30 deletions packages/tag/src/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ButtonHTMLAttributes } from 'react';
import React, { ButtonHTMLAttributes, forwardRef } from 'react';
import cn from 'classnames';

import styles from './index.module.css';
Expand Down Expand Up @@ -43,34 +43,39 @@ export type TagProps = Omit<NativeProps, 'onClick'> & {
) => void;
};

export const Tag = ({
rightAddons,
leftAddons,
children,
size = 's',
checked,
className,
dataTestId,
name,
onClick,
...restProps
}: TagProps) => {
const tagProps = {
className: cn(styles.component, styles[size], { [styles.checked]: checked }, className),
'data-test-id': dataTestId,
};
export const Tag = forwardRef<HTMLButtonElement, TagProps>(
(
{
rightAddons,
leftAddons,
children,
size = 's',
checked,
className,
dataTestId,
name,
onClick,
...restProps
},
ref,
) => {
const tagProps = {
className: cn(styles.component, styles[size], { [styles.checked]: checked }, className),
'data-test-id': dataTestId,
};

const handleClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
if (onClick) {
onClick(event, { name, checked: !checked });
}
};
const handleClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
if (onClick) {
onClick(event, { name, checked: !checked });
}
};

return (
<button type='button' onClick={handleClick} {...tagProps} {...restProps}>
{leftAddons ? <span className={cn(styles.addons)}>{leftAddons}</span> : null}
<span>{children}</span>
{rightAddons ? <span className={cn(styles.addons)}>{rightAddons}</span> : null}
</button>
);
};
return (
<button ref={ref} type='button' onClick={handleClick} {...tagProps} {...restProps}>
{leftAddons ? <span className={cn(styles.addons)}>{leftAddons}</span> : null}
<span>{children}</span>
{rightAddons ? <span className={cn(styles.addons)}>{rightAddons}</span> : null}
</button>
);
},
);
2 changes: 2 additions & 0 deletions packages/tag/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
--tag-border-color-disabled: var(--color-dark-indigo-30-flat);

/* background-color */
--tag-background-color: transparent;
--tag-background-color-active: var(--color-dark-indigo-07);
--tag-background-color-checked: var(--color-dark-indigo);
--tag-background-color-checked-disabled: var(--color-dark-indigo-30-flat);
Expand All @@ -30,6 +31,7 @@
text-decoration: none;
border: var(--tag-border-width) var(--tag-border-style) var(--tag-border-color);
border-radius: var(--tag-border-radius);
background-color: var(--tag-background-color);
transition: background 0.2s ease, border 0.2s ease, color 0.2s ease;
box-sizing: border-box;
box-shadow: none;
Expand Down

0 comments on commit 03b465b

Please sign in to comment.