-
Notifications
You must be signed in to change notification settings - Fork 134
Thulasizwe/en/dropdown tag #3395
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
Changes from 6 commits
979940c
1513949
33824bc
13f94a4
df3de7f
7aed7f3
ccc8664
94fb8d1
f0fd227
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { IncomeValueFunc, ISelectOption, OutcomeValueFunc } from '@/components/r | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ReferenceListItemDto } from '@/apis/referenceList'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useStyles } from './style'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getTagStyle } from '@/utils/style'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ReflistTag from '../refListDropDown/reflistTag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const Dropdown: FC<IDropdownProps> = ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -37,7 +38,7 @@ export const Dropdown: FC<IDropdownProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| tagStyle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { styles } = useStyles({ style, tagStyle }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { styles } = useStyles({ style }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const selectedMode = mode === 'multiple' || mode === 'tags' ? mode : undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -79,6 +80,7 @@ export const Dropdown: FC<IDropdownProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| color: item?.color, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon: item?.icon, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: item?.data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: item?.description, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [incomeValueFunc]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -104,6 +106,7 @@ export const Dropdown: FC<IDropdownProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: outcomeValueFunc(fetchedItem, args), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color: fetchedItem?.color, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon: fetchedItem?.icon, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: fetchedItem?.description, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [labelCustomJs, outcomeValueFunc, incomeValueFunc]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -176,23 +179,29 @@ export const Dropdown: FC<IDropdownProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (displayStyle === 'tags' && mode !== 'multiple') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <Select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...commonSelectProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className={styles.dropdown} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showSearch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={{ ...style, width: 'max-content' }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| popupMatchSelectWidth={false} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={{ width: 'max-content' }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| placeholder={<Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={{ ...getTagStyle(tagStyle, true), background: '#d9d9d9' }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {placeholder ?? <span style={{ whiteSpace: 'pre' }}>{' '}</span>} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Tag>} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| labelRender={(props) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const option = options.find((o) => o.value === props.value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <ReflistTag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={props.value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color={option?.color} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon={((option?.icon && showIcon)) && <Icon type={option?.icon} />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={getTagStyle(tagStyle, !!option?.color && solidColor)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {showItemName && option?.label} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Tag>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tagStyle={tagStyle} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showIcon={showIcon} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| solidColor={solidColor} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showItemName={showItemName} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label={option?.label} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value={props.value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tooltip={"Single"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| />; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -214,12 +223,18 @@ export const Dropdown: FC<IDropdownProps> = ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...(displayStyle === 'tags' ? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| labelRender: (props) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const option = options.find((o) => o.value === props.value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <ReflistTag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showIcon={showIcon} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showItemName={showItemName} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tagStyle={tagStyle} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| solidColor={solidColor} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label={option?.label} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value={props.value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={props.value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tooltip={"multiple"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color={option?.color} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon={option?.icon && showIcon && <Icon type={option?.icon} />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={getTagStyle(tagStyle, !!option?.color && solidColor)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| >{showItemName && option?.label}</Tag>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ></ReflistTag>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+226
to
+237
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix hardcoded tooltip and inconsistent Icon handling. Two issues:
return <ReflistTag
showIcon={showIcon}
showItemName={showItemName}
tagStyle={tagStyle}
solidColor={solidColor}
label={option?.label}
value={props.value}
key={props.value}
- tooltip={"multiple"}
+ tooltip={option?.description}
color={option?.color}
- icon={option?.icon && showIcon && <Icon type={option?.icon} />}
+ icon={option?.icon}
></ReflistTag>;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } : {})} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,14 +1,13 @@ | ||||||||||||||||||||||
| import { createStyles } from '@/styles'; | ||||||||||||||||||||||
| import { CSSProperties } from 'react'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export const useStyles = createStyles(({ css, cx, token }, { style, tagStyle }: { style: CSSProperties; tagStyle: CSSProperties }) => { | ||||||||||||||||||||||
| export const useStyles = createStyles(({ css, cx, token }, { style }: { style: CSSProperties }) => { | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mismatch between CSS variable names – font weight will not apply You set Later, - --ant-font-weight-strong: ${style.fontWeight} !important;
+ --ant-font-weight: ${style.fontWeight} !important;Apply the same rename (or update the consumer) to restore the intended styling. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const dropdown = cx("sha-dropdown", css` | ||||||||||||||||||||||
| --ant-color-text: ${style.color} !important; | ||||||||||||||||||||||
| --ant-font-size: ${style.fontSize} !important; | ||||||||||||||||||||||
| --ant-font-weight-strong: ${style.fontWeight} !important; | ||||||||||||||||||||||
| --ant-select-multiple-item-bg: transparent !important; | ||||||||||||||||||||||
| --ant-select-multiple-item-height: ${tagStyle.height} !important; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| .ant-select-selector{ | ||||||||||||||||||||||
| overflow: auto; | ||||||||||||||||||||||
|
|
@@ -31,16 +30,14 @@ export const useStyles = createStyles(({ css, cx, token }, { style, tagStyle }: | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| :hover { | ||||||||||||||||||||||
| border: none !important; | ||||||||||||||||||||||
| .ant-tag { | ||||||||||||||||||||||
| .ant-tag { | ||||||||||||||||||||||
| align-content: center; | ||||||||||||||||||||||
| cursor: default !important; | ||||||||||||||||||||||
| pointer-events: none !important; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+33
to
38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Hover disables pointer events on all nested tags – may break close icon
Consider: .ant-tag[disabled] { pointer-events:none; }🤖 Prompt for AI Agents |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| &.ant-select-open, &:hover { | ||||||||||||||||||||||
| border-color: ${token.colorPrimary} !important; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getTagStyle } from '@/utils/style'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import convertCssColorNameToHex from 'convert-css-color-name-to-hex'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Tag, Tooltip, TooltipProps } from 'antd'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Icon } from '../readOnlyDisplayFormItem'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function ReflistTag({ value, tooltip, color, icon, showIcon, tagStyle, solidColor, showItemName, label, placement = 'right' }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const memoizedColor = solidColor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? convertCssColorNameToHex(color ?? '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : color?.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Tooltip title={tooltip} placement={placement as TooltipProps['placement']} style={{ cursor: 'pointer' }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color={memoizedColor} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon={(icon && showIcon) && <Icon type={icon} />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={getTagStyle(tagStyle, !!color)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| >{showItemName && label}</Tag> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Tooltip> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default ReflistTag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add TypeScript interface for component props to improve type safety. The component lacks TypeScript typing, which reduces type safety and IDE support. As this is a reusable component used across multiple files, proper typing is essential. Add TypeScript interface and type the component: import { getTagStyle } from '@/utils/style';
import convertCssColorNameToHex from 'convert-css-color-name-to-hex';
import { Tag, Tooltip, TooltipProps } from 'antd';
-import React from 'react';
+import React, { FC, ReactNode } from 'react';
import { Icon } from '../readOnlyDisplayFormItem';
+
+interface IReflistTagProps {
+ value: string | number;
+ tooltip?: string;
+ color?: string;
+ icon?: string;
+ showIcon?: boolean;
+ tagStyle?: React.CSSProperties;
+ solidColor?: boolean;
+ showItemName?: boolean;
+ label?: ReactNode;
+ placement?: TooltipProps['placement'];
+}
+
-function ReflistTag({ value, tooltip, color, icon, showIcon, tagStyle, solidColor, showItemName, label, placement = 'right' }) {
+const ReflistTag: FC<IReflistTagProps> = ({
+ value,
+ tooltip,
+ color,
+ icon,
+ showIcon,
+ tagStyle,
+ solidColor,
+ showItemName,
+ label,
+ placement = 'right'
+}) => {
const memoizedColor = solidColor
? convertCssColorNameToHex(color ?? '')
: color?.toLowerCase();
return (
<Tooltip title={tooltip} placement={placement as TooltipProps['placement']} style={{ cursor: 'pointer' }}>
<Tag
key={value}
color={memoizedColor}
icon={(icon && showIcon) && <Icon type={icon} />}
style={getTagStyle(tagStyle, !!color)}
>{showItemName && label}</Tag>
</Tooltip>
);
};
export default ReflistTag;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.