-
-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/npm_and_yarn/types/react-18.2.45
- Loading branch information
Showing
12 changed files
with
87 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters