File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import React , { useCallback , useEffect } from 'react' ;
22import { useEvent } from '@rc-component/util' ;
3+ import { isFunction } from 'antd/lib/_util/is' ;
34
45const ANT_SYNC_STORAGE_EVENT_KEY = 'ANT_SYNC_STORAGE_EVENT_KEY' ;
56
6- const isFunction = ( val : any ) : val is ( ...args : any [ ] ) => any => {
7- return typeof val === 'function' ;
8- } ;
9-
107interface Options < T > {
118 defaultValue ?: T ;
129 serializer ?: ( value : T ) => string ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import useState from '@rc-component/util/lib/hooks/useState';
44import Button from '../button/Button' ;
55import type { ButtonProps , LegacyButtonType } from '../button/Button' ;
66import { convertLegacyProps } from '../button/buttonHelpers' ;
7+ import { isThenable } from './is' ;
78
89export interface ActionButtonProps {
910 type ?: LegacyButtonType ;
@@ -22,10 +23,6 @@ export interface ActionButtonProps {
2223 isSilent ?: ( ) => boolean ;
2324}
2425
25- const isThenable = < T , > ( thing ?: PromiseLike < T > ) : thing is PromiseLike < T > => {
26- return typeof thing ?. then === 'function' ;
27- } ;
28-
2926const ActionButton : React . FC < ActionButtonProps > = ( props ) => {
3027 const {
3128 type,
Original file line number Diff line number Diff line change 1- // \b([A-Za-z_$][\w$]*)\s*!==\s*(?:undefined\s*&&\s*\1\s*!==\s*null|null\s*&&\s*\1\s*!==\s*undefined)\b
2- // \b([A-Za-z_$][\w$\.]*)\s*===\s*(?:undefined|null)\s*\|\|\s*\1\s*===\s*(?:undefined|null)\b
31export const isNonNullable = < T > ( val : T ) : val is NonNullable < T > => {
42 return val !== undefined && val !== null ;
53} ;
@@ -8,6 +6,18 @@ export const isNumber = (val: any): val is number => {
86 return typeof val === 'number' && ! Number . isNaN ( val ) ;
97} ;
108
9+ export const isString = ( val : any ) : val is string => {
10+ return typeof val === 'string' ;
11+ } ;
12+
1113export const isPrimitive = ( value : any ) => {
1214 return ( typeof value !== 'object' && typeof value !== 'function' ) || value === null ;
1315} ;
16+
17+ export const isFunction = ( val : any ) : val is ( ...args : any [ ] ) => any => {
18+ return typeof val === 'function' ;
19+ } ;
20+
21+ export const isThenable = < T > ( val ?: PromiseLike < T > ) : val is PromiseLike < T > => {
22+ return isNonNullable ( val ) && isFunction ( val . then ) ;
23+ } ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22
3+ import { isFunction } from './is' ;
34import type { AnyObject } from './type' ;
45
56export function isFragment ( child : any ) : boolean {
@@ -16,10 +17,7 @@ export const replaceElement = <P>(
1617 if ( ! React . isValidElement < P > ( element ) ) {
1718 return replacement ;
1819 }
19- return React . cloneElement < P > (
20- element ,
21- typeof props === 'function' ? props ( element . props || { } ) : props ,
22- ) ;
20+ return React . cloneElement < P > ( element , isFunction ( props ) ? props ( element . props || { } ) : props ) ;
2321} ;
2422
2523export function cloneElement < P > ( element : React . ReactNode , props ?: RenderProps ) {
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { clsx } from 'clsx' ;
33
4- import { isNonNullable } from '../_util/is' ;
4+ import { isNonNullable , isString } from '../_util/is' ;
55import { cloneElement , isFragment } from '../_util/reactNode' ;
66import { PresetColors } from '../theme/interface' ;
77import type { BaseButtonProps , LegacyButtonType } from './Button' ;
@@ -19,10 +19,6 @@ export function convertLegacyProps(
1919 return { type } ;
2020}
2121
22- export function isString ( str : unknown ) : str is string {
23- return typeof str === 'string' ;
24- }
25-
2622export function isUnBorderedButtonVariant ( type ?: ButtonVariantType ) {
2723 return type === 'text' || type === 'link' ;
2824}
Original file line number Diff line number Diff line change @@ -224,10 +224,7 @@ const Dropdown: CompoundedComponent = (props) => {
224224
225225 const child = React . Children . only (
226226 isPrimitive ( children ) ? < span > { children } </ span > : children ,
227- ) as React . ReactElement < {
228- className ?: string ;
229- disabled ?: boolean ;
230- } > ;
227+ ) as React . ReactElement < { className ?: string ; disabled ?: boolean } > ;
231228
232229 const popupTrigger = cloneElement ( child , {
233230 className : clsx (
You can’t perform that action at this time.
0 commit comments