From 1955f1318bbacab989b463ade559934fe5f9210e Mon Sep 17 00:00:00 2001 From: Tony Vi Date: Fri, 11 Aug 2023 21:42:18 +0300 Subject: [PATCH] refactor(Tag)!: move out clean button --- src/components/CleanButton.tsx | 2 +- src/components/FormMultiInput.tsx | 7 ++-- src/components/Tag.tsx | 54 ++++++------------------------- 3 files changed, 15 insertions(+), 48 deletions(-) diff --git a/src/components/CleanButton.tsx b/src/components/CleanButton.tsx index 099fdf9a..c0f8842a 100644 --- a/src/components/CleanButton.tsx +++ b/src/components/CleanButton.tsx @@ -2,7 +2,7 @@ import React from 'react'; import styled from 'styled-components'; import { gray10, gray7, gray8 } from '@taskany/colors'; -interface CleanButtonProps extends React.HTMLAttributes { +export interface CleanButtonProps extends React.HTMLAttributes { className?: string; onClick?: (e: React.MouseEvent) => void; diff --git a/src/components/FormMultiInput.tsx b/src/components/FormMultiInput.tsx index 82b65c52..6b4c008c 100644 --- a/src/components/FormMultiInput.tsx +++ b/src/components/FormMultiInput.tsx @@ -8,7 +8,7 @@ import { formContext } from '../context/form'; import { PlusIcon } from './Icon/PlusIcon'; import { Text } from './Text'; -import { Tag } from './Tag'; +import { Tag, TagCleanButton } from './Tag'; import { Input } from './Input'; import { MenuItem } from './MenuItem'; import { ComboBox } from './ComboBox'; @@ -111,7 +111,10 @@ export const FormMultiInput = React.forwardRef ( - + + + {item.title} + ))} { - title: string; + children: React.ReactNode; description?: string; size?: 's' | 'm'; className?: string; checked?: boolean; onClick?: MouseEventHandler; - onHide?: () => void; } -const StyledCleanButton = styled(CleanButton)``; +export const TagCleanButton = styled(CleanButton)``; // eslint-disable-next-line @typescript-eslint/no-unused-vars -const StyledTag = styled(({ onHide, ...props }: Partial & { children?: React.ReactNode }) => ( -
-))` +const StyledTag = styled(({ size, ...props }: TagProps) =>
)` display: inline-block; position: relative; padding: 4px 12px 5px; @@ -45,8 +40,7 @@ const StyledTag = styled(({ onHide, ...props }: Partial & { children?: margin-left: ${gapXs}; } - ${({ onHide, checked }) => - !onHide && + ${({ checked }) => !checked && ` &:hover { @@ -57,7 +51,7 @@ const StyledTag = styled(({ onHide, ...props }: Partial & { children?: `} &:hover { - ${StyledCleanButton} { + ${TagCleanButton} { visibility: visible; cursor: pointer; @@ -86,40 +80,10 @@ const StyledTag = styled(({ onHide, ...props }: Partial & { children?: `} `; -export const Tag: React.FC = ({ - title, - description, - size = 'm', - onClick, - onHide, - className, - checked, - ...attrs -}) => { - const onHideClick = useCallback( - (e: React.MouseEvent) => { - e.preventDefault(); - e.stopPropagation(); - - onHide?.(); - }, - [onHide], - ); - +export const Tag: React.FC = ({ children, description, size = 'm', ...props }) => { return ( - - {nullable(onHide, () => ( - - ))} - {title} + + {children} ); };