Skip to content

Commit

Permalink
lint-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Dec 27, 2023
1 parent c01fe37 commit f804d17
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 74 deletions.
1 change: 0 additions & 1 deletion src/BaseSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
allowClear,
clearIcon,
disabled,

mergedSearchValue,
mode,
);
Expand Down
7 changes: 3 additions & 4 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const Select = React.forwardRef(
} else {
rawKey = val.key;
rawLabel = val.label;
rawValue = val.value ?? rawKey;
rawValue = val.value ?? (rawKey as RawValueType);
}

const option = valueOptions.get(rawValue);
Expand Down Expand Up @@ -680,9 +680,8 @@ const TypedSelect = Select as unknown as (<
ValueType = any,
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
>(
props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> & {
ref?: React.Ref<BaseSelectRef>;
},
props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> &
React.RefAttributes<BaseSelectRef>,
) => React.ReactElement) & {
Option: typeof Option;
OptGroup: typeof OptGroup;
Expand Down
11 changes: 8 additions & 3 deletions src/Selector/MultipleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
const selectionPrefixCls = `${prefixCls}-selection`;

// ===================== Search ======================
const inputValue = open || (mode === "multiple" && autoClearSearchValue === false) || mode === 'tags' ? searchValue : '';
const inputEditable: boolean = mode === 'tags' || (mode === "multiple" && autoClearSearchValue === false) || (showSearch && (open || focused));
const inputValue =
open || (mode === 'multiple' && autoClearSearchValue === false) || mode === 'tags'
? searchValue
: '';
const inputEditable: boolean =
mode === 'tags' ||
(mode === 'multiple' && autoClearSearchValue === false) ||
(showSearch && (open || focused));

// We measure width and set to the input immediately
useLayoutEffect(() => {
Expand Down Expand Up @@ -236,7 +242,6 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
return (
<>
{selectionNode}

{!values.length && !inputValue && (
<span className={`${selectionPrefixCls}-placeholder`}>{placeholder}</span>
)}
Expand Down
27 changes: 6 additions & 21 deletions src/TransBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,20 @@ export interface TransBtnProps {
children?: React.ReactNode;
}

const TransBtn: React.FC<TransBtnProps> = ({
className,
customizeIcon,
customizeIconProps,
onMouseDown,
onClick,
children,
}) => {
let icon: React.ReactNode;
const TransBtn: React.FC<TransBtnProps> = (props) => {
const { className, customizeIcon, customizeIconProps, children, onMouseDown, onClick } = props;

if (typeof customizeIcon === 'function') {
icon = customizeIcon(customizeIconProps);
} else {
icon = customizeIcon;
}
const icon =
typeof customizeIcon === 'function' ? customizeIcon(customizeIconProps) : customizeIcon;

return (
<span
className={className}
onMouseDown={(event) => {
event.preventDefault();
if (onMouseDown) {
onMouseDown(event);
}
}}
style={{
userSelect: 'none',
WebkitUserSelect: 'none',
onMouseDown?.(event);
}}
style={{ userSelect: 'none', WebkitUserSelect: 'none' }}
unselectable="on"
onClick={onClick}
aria-hidden
Expand Down
86 changes: 43 additions & 43 deletions src/hooks/useAllowClear.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import TransBtn from '../TransBtn';
import type { DisplayValueType, Mode } from '../interface';
import type { ReactNode } from 'react';
import type { DisplayValueType, Mode, RenderNode } from '../interface';
import React from 'react';

export function useAllowClear(
prefixCls,
onClearMouseDown,
displayValues: DisplayValueType[],
allowClear?: boolean | { clearIcon?: ReactNode },
clearIcon?: ReactNode,
disabled = false,
mergedSearchValue?: string,
mode?: Mode
) {
const mergedClearIcon = React.useMemo(() => {
if (typeof allowClear === "object") {
return allowClear.clearIcon;
}
if (!!clearIcon) return clearIcon;
}, [allowClear, clearIcon]);
export const useAllowClear = (
prefixCls: string,
onClearMouseDown: React.MouseEventHandler<HTMLSpanElement>,
displayValues: DisplayValueType[],
allowClear?: boolean | { clearIcon?: RenderNode },
clearIcon?: RenderNode,
disabled: boolean = false,
mergedSearchValue?: string,
mode?: Mode,
) => {
const mergedClearIcon = React.useMemo(() => {
if (typeof allowClear === 'object') {
return allowClear.clearIcon;
}
if (clearIcon) {
return clearIcon;
}
}, [allowClear, clearIcon]);

const mergedAllowClear = React.useMemo<boolean>(() => {
if (
!disabled &&
!!allowClear &&
(displayValues.length || mergedSearchValue) &&
!(mode === 'combobox' && mergedSearchValue === '')
) {
return true;
}
return false;
}, [allowClear, disabled, displayValues.length, mergedSearchValue, mode]);

const mergedAllowClear = React.useMemo(() => {
if (
!disabled &&
!!allowClear &&
(displayValues.length || mergedSearchValue) &&
!(mode === 'combobox' && mergedSearchValue === '')
) {
return true;
}
return false;
}, [allowClear, disabled, displayValues.length, mergedSearchValue, mode]);

return {
allowClear: mergedAllowClear,
clearIcon: (
<TransBtn
className={`${prefixCls}-clear`}
onMouseDown={onClearMouseDown}
customizeIcon={mergedClearIcon}
>
×
</TransBtn>
)
};
}
return {
allowClear: mergedAllowClear,
clearIcon: (
<TransBtn
className={`${prefixCls}-clear`}
onMouseDown={onClearMouseDown}
customizeIcon={mergedClearIcon}
>
×
</TransBtn>
),
};
};
3 changes: 1 addition & 2 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface DisplayValueType {
key?: React.Key;
value?: RawValueType;
label?: React.ReactNode;
title?: string | number;
title?: React.ReactNode;
disabled?: boolean;
}

Expand All @@ -27,4 +27,3 @@ export type Mode = 'multiple' | 'tags' | 'combobox';
export type Placement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';

export type DisplayInfoType = 'add' | 'remove' | 'clear';

0 comments on commit f804d17

Please sign in to comment.