From d28d5398027797fd779cf9fbd01ae3e26fcd3659 Mon Sep 17 00:00:00 2001 From: Innders <49156310+Innders@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:15:24 +0100 Subject: [PATCH] fix(Tags): improvements and fixes --- .../Dropdown/DefaultValueTemplate.tsx | 3 +-- src/Dropdowns/Dropdown/Dropdown.tsx | 4 +--- src/Dropdowns/EnumDropdown/EnumDropdown.tsx | 8 ++++++-- .../TagsSelect/TagsSelect.stories.tsx | 1 + .../TagsSelect/TagsSelectValueTemplate.tsx | 20 +++++++++++++++++-- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Dropdowns/Dropdown/DefaultValueTemplate.tsx b/src/Dropdowns/Dropdown/DefaultValueTemplate.tsx index 27c8a1c0..7b03a1ff 100644 --- a/src/Dropdowns/Dropdown/DefaultValueTemplate.tsx +++ b/src/Dropdowns/Dropdown/DefaultValueTemplate.tsx @@ -69,7 +69,6 @@ export interface DefaultValueTemplateProps | 'placeholder' | 'clearTooltip' | 'clearNullTooltip' - | 'editor' > { displayIcon?: string style?: React.CSSProperties @@ -110,7 +109,7 @@ export const DefaultValueTemplate: FC = ({ {noValue ? ( <> - + {value === null ? nullPlaceholder || '(no value)' : placeholder} diff --git a/src/Dropdowns/Dropdown/Dropdown.tsx b/src/Dropdowns/Dropdown/Dropdown.tsx index ccab8981..f70b5f4a 100644 --- a/src/Dropdowns/Dropdown/Dropdown.tsx +++ b/src/Dropdowns/Dropdown/Dropdown.tsx @@ -106,7 +106,6 @@ export interface DropdownProps extends Omit buttonProps?: Styled.ButtonType['defaultProps'] activateKeys?: string[] startContent?: (value: string[], selected: string[], isOpen: boolean) => React.ReactNode - editor?: boolean } export interface DropdownRef { @@ -182,7 +181,6 @@ export const Dropdown = forwardRef( buttonProps, activateKeys = ['Enter', 'Space', 'NumpadEnter', 'Tab'], startContent, - editor, ...props }, ref, @@ -826,7 +824,7 @@ export const Dropdown = forwardRef( const valueTemplateNode = useMemo(() => { if (typeof valueTemplate === 'function') return valueTemplate if (valueTemplate === 'tags') - return () => + return () => }, [ valueTemplate, value, diff --git a/src/Dropdowns/EnumDropdown/EnumDropdown.tsx b/src/Dropdowns/EnumDropdown/EnumDropdown.tsx index 490818b3..6d6dc662 100644 --- a/src/Dropdowns/EnumDropdown/EnumDropdown.tsx +++ b/src/Dropdowns/EnumDropdown/EnumDropdown.tsx @@ -40,7 +40,7 @@ export interface EnumDropdownProps } export const EnumDropdown = forwardRef( - ({ colorInverse, value, ...props }, ref) => { + ({ colorInverse, value, itemStyle, ...props }, ref) => { return ( ( ) }} itemTemplate={(option, isSelected) => ( - + )} value={value?.map((v) => String(v))} {...props} diff --git a/src/Dropdowns/TagsSelect/TagsSelect.stories.tsx b/src/Dropdowns/TagsSelect/TagsSelect.stories.tsx index 8d7b4d08..29c19a97 100644 --- a/src/Dropdowns/TagsSelect/TagsSelect.stories.tsx +++ b/src/Dropdowns/TagsSelect/TagsSelect.stories.tsx @@ -17,6 +17,7 @@ export const Default: Story = { args: { tags, tagsOrder, + editor: true, }, render: (args) => { const [value, setValue] = useState(initValue) diff --git a/src/Dropdowns/TagsSelect/TagsSelectValueTemplate.tsx b/src/Dropdowns/TagsSelect/TagsSelectValueTemplate.tsx index 546a5c69..69251ac3 100644 --- a/src/Dropdowns/TagsSelect/TagsSelectValueTemplate.tsx +++ b/src/Dropdowns/TagsSelect/TagsSelectValueTemplate.tsx @@ -3,6 +3,15 @@ import { DefaultValueTemplateProps } from '../Dropdown' import * as Styled from './TagsSelect.styled' import { type TagsType } from './tags' import clsx from 'clsx' +import styled from 'styled-components' +import { Icon } from '../../Icon' + +const PlaceholderTag = styled.div` + display: flex; + align-items: center; + gap: var(--base-gap-small); + padding: 0 6px; +` export interface TagsSelectValueTemplateProps extends Omit { tags: TagsType @@ -13,14 +22,20 @@ export const TagsSelectValueTemplate: FC = (props) const { value, tags = {}, editor = false } = props // if value empty return placeholder tag - if (!value?.length) value?.push('Add tags') + if (!value?.length && editor) + return ( + + + Select tags + + ) return ( {value?.map((v) => ( = (props) style={{ color: tags[v]?.color, }} + className="tag" > {v}