Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
"@types/react-transition-group": "^4.4.4",
"@types/rimraf": "^4.0.5",
"@types/tinycolor2": "^1.4.6",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.6.0",
"@typescript-eslint/eslint-plugin": "^8.33.0",
"@typescript-eslint/parser": "^8.33.0",
"@vitejs/plugin-react": "^4.4.1",
"@vitest/coverage-istanbul": "^3.2.4",
"@vitest/coverage-v8": "^3.2.4",
Expand Down
2 changes: 1 addition & 1 deletion src/_util/forwardRefWithStatics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { RefAttributes, forwardRef } from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';

export default function forwardRefWithStatics<P, T = any, S = {}>(
export default function forwardRefWithStatics<P, T = any, S = object>(
component: React.ForwardRefRenderFunction<T, P>,
statics?: S,
): React.FunctionComponent<P & RefAttributes<T>> & S {
Expand Down
2 changes: 1 addition & 1 deletion src/_util/parseTNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function parseContentTNode<T>(tnode: TNode<T>, props: T) {
if (!tnode || ['string', 'number', 'boolean'].includes(typeof tnode)) return tnode as ReactNode;
try {
return React.cloneElement(tnode as ReactElement, { ...props });
} catch (e) {
} catch {
log.warn('parseContentTNode', `${tnode} is not a valid ReactNode`);
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_util/react-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ try {
} else if (mainVersion >= 19) {
createRoot = createRootClient;
}
} catch (e) {
} catch {
// Do nothing;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_util/supportsPassive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (canUseDocument) {
},
});
window.addEventListener('test-passive', null as any, opts);
} catch (e) {
} catch {
//
}
}
4 changes: 3 additions & 1 deletion src/action-sheet/ActionSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const ActionSheet: React.FC<ActionSheetProps> = (props) => {
const actionSheetClass = usePrefixClass('action-sheet');

const [visible, setVisible] = useControlled(props, 'visible', (visible, context) => {
!visible && onClose?.(context);
if (!visible) {
onClose?.(context);
}
});

const handleCancel = (ev) => {
Expand Down
2 changes: 1 addition & 1 deletion src/back-top/Backtop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const BackTop: React.FC<BackTopProps> = (props) => {

const name = `${classPrefix}-back-top`;

const getContainer = (container: Function) => {
const getContainer = (container: TdBackTopProps['container']) => {
if (typeof container === 'function') {
return container();
}
Expand Down
2 changes: 1 addition & 1 deletion src/cell/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Cell: React.FC<CellProps> = (originProps) => {

const handleClick = useCallback(
(e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
onClick && onClick({ e });
onClick?.({ e });
},
[onClick],
);
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const Dialog: React.FC<DialogProps> = (props) => {
} else if (isValidElement(btn)) {
result = btn;
} else if (isObject(btn)) {
result = <Button {...defaultProps} {...(btn as {})} />;
result = <Button {...defaultProps} {...(btn as ButtonProps)} />;
} else if (isFunction(btn)) {
result = btn();
}
Expand Down
2 changes: 1 addition & 1 deletion src/fab/Fab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const Fab: React.FC<FabProps> = (originProps) => {

useEffect(() => {
const fab = fabRef.current;
fab && fab.addEventListener('touchmove', onTouchMove, { passive: false });
fab?.addEventListener('touchmove', onTouchMove, { passive: false });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
19 changes: 0 additions & 19 deletions src/form/const.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { InjectionKey } from 'vue';
import { FormItemValidateResult } from './FormItem';
import {
AllValidateResult,
Data,
FormItemValidateMessage,
FormRule,
TdFormItemProps,
TdFormProps,
ValidateResultType,
ValidateTriggerType,
} from './type';
Expand Down Expand Up @@ -56,20 +54,3 @@ export interface FormItemContext {
onBlur?: (value: any, ...args) => void;
value?: any;
}

export const FormInjectionKey: InjectionKey<{
showErrorMessage: TdFormProps['showErrorMessage'];
labelWidth: TdFormProps['labelWidth'];
labelAlign: TdFormProps['labelAlign'];
contentAlign: TdFormProps['contentAlign'];
colon: TdFormProps['colon'];
requiredMark: TdFormProps['requiredMark'];
rules: TdFormProps['rules'];
errorMessage: TdFormProps['errorMessage'];
resetType: TdFormProps['resetType'];
children: FormItemContext[];
}> = Symbol('FormProvide');

export const FormItemInjectionKey: InjectionKey<{
handleBlur: () => Promise<void>;
}> = Symbol('FormItemProvide');
8 changes: 6 additions & 2 deletions src/guide/Guide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ const Guide: FC<GuideProps> = (originProps) => {
setHighlightLayerPosition(popoverWrapperRef.current, true);
setHighlightLayerPosition(referenceLayerRef.current, true);
scrollToElm(currentHighlightLayerElm.current);
isPopoverCenter && setReferenceFullW([referenceLayerRef.current, popoverWrapperRef.current]);
if (isPopoverCenter) {
setReferenceFullW([referenceLayerRef.current, popoverWrapperRef.current]);
}
popoverRef.current?.updatePopper?.();
});
};
Expand Down Expand Up @@ -272,7 +274,9 @@ const Guide: FC<GuideProps> = (originProps) => {

useEffect(() => {
if (innerCurrent >= 0 && innerCurrent < stepsTotal) {
isPopover && setPopoverVisible(false);
if (isPopover) {
setPopoverVisible(false);
}
initGuide();
} else {
setActived(false);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useControlled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const useControlled: <P extends any[], R extends object, K extends keyof R>(
onChange: ChangeHandler<R[K], P>,
defaultOptions?:
| {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[key in DefaultOptions<ToString<K>>]: R[K];
}
| object,
Expand Down
2 changes: 1 addition & 1 deletion src/image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Image: React.FC<ImageProps> = (props) => {
const handleUnObserve = (element) => {
const observer = observe(element, null, handleLoadImage, 0);
return () => {
observer && observer.unobserve(element);
observer?.unobserve(element);
};
};

Expand Down
12 changes: 7 additions & 5 deletions src/indexes/Indexes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ const Indexes: React.FC<IndexesProps> = (props) => {
};

const relation = (ele: HTMLElement, anchor: string | number) => {
ele && childNodes.current.push({ ele, anchor });
if (ele) {
childNodes.current.push({ ele, anchor });
}
};

useEffect(() => {
const clearSidebarTip = (): void => {
if (showSidebarTip && activeSidebar !== null) {
tipTimer.current && clearTimeout(tipTimer.current);
clearTimeout(tipTimer.current);
tipTimer.current = window.setTimeout(() => {
setShowSidebarTip(false);
}, 1000);
Expand Down Expand Up @@ -194,11 +196,11 @@ const Indexes: React.FC<IndexesProps> = (props) => {
// https://github.com/facebook/react/pull/19654
// react 中 onTouchMove 等事件默认使用 passive: true,导致无法在listener 中使用 preventDefault()
const sideBar = sidebarRef.current;
sideBar && sideBar.addEventListener('touchmove', handleSidebarTouchmove, { passive: false });
sideBar?.addEventListener('touchmove', handleSidebarTouchmove, { passive: false });

return () => {
tipTimer.current && clearTimeout(tipTimer.current);
sideBar && sideBar.removeEventListener('touchmove', handleSidebarTouchmove);
clearTimeout(tipTimer.current);
sideBar?.removeEventListener('touchmove', handleSidebarTouchmove);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
2 changes: 1 addition & 1 deletion src/list/_example/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function ListDemo() {
stateRef.current = newListData;
setIsLoading(false);
}, 0);
} catch (err) {
} catch {
stateRef.current = [];
}
};
Expand Down
19 changes: 12 additions & 7 deletions src/locale/LocalReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ export interface Placement {
[propName: string]: string | number;
}

export type TransformPattern = string | Function | Array<string>;
export type TransformPattern = string | ((placement?: Placement) => string | Array<string>) | Array<string>;

export function useLocaleReceiver<T extends keyof Locale>(componentName: T, defaultLocale?: Locale[T] | Function) {
type TransformLocaleFn = (pattern: TransformPattern, placement?: Placement) => string | Array<string>;

export function useLocaleReceiver<T extends keyof Locale>(
componentName: T,
defaultLocale?: Locale[T] | (() => Locale[T]),
) {
const { globalConfig } = React.useContext(ConfigContext);

function transformLocale(pattern: TransformPattern, placement?: Placement): string | Array<string> {
const transformLocale: TransformLocaleFn = (pattern: TransformPattern, placement?: Placement) => {
const REGEXP = /\{\s*([\w-]+)\s*\}/g;
if (typeof pattern === 'string') {
if (!placement || !REGEXP.test(pattern)) return pattern;
Expand All @@ -33,20 +38,20 @@ export function useLocaleReceiver<T extends keyof Locale>(componentName: T, defa
return pattern(placement);
}
return '';
}
};

/** @TypeA => 确保此参数是属于 globalConfig[componentName] 下的子属性 */
const componentLocale = React.useMemo<Locale[T] | Function>(() => {
const componentLocale = React.useMemo<Locale[T] | (() => Locale[T])>(() => {
const locale = defaultLocale || {};
const connectLocaleByName = globalConfig[componentName];

const localeFromContext = componentName && globalConfig ? connectLocaleByName : {};

return {
...(typeof locale === 'function' ? (locale as Function)() : locale),
...(typeof locale === 'function' ? locale() : locale),
...(localeFromContext || {}),
};
}, [componentName, defaultLocale, globalConfig]);

return [componentLocale, transformLocale] as [Locale[T], Function];
return [componentLocale, transformLocale] as [Locale[T], TransformLocaleFn];
}
2 changes: 1 addition & 1 deletion src/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Message: React.FC<MessageProps> = (originProps) => {
/**
* 获取visibleChange函数引用
*/
const scrollingHandler = useRef<Function>(null);
const scrollingHandler = useRef<null | (() => void)>(null);

/**
* duration为0时,取消倒计时
Expand Down
2 changes: 1 addition & 1 deletion src/message/hooks/useMessageCssTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { unmount } from '../../_util/react-render';

interface UseMessageCssTransitionParams {
contentRef: React.MutableRefObject<HTMLDivElement>;
classPrefix: String;
classPrefix: string;
container: HTMLElement;
}

Expand Down
4 changes: 2 additions & 2 deletions src/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const Navbar: React.FC<NavbarProps> = (originProps) => {
if (isStringTitle && !isNaN(titleMaxLength)) {
if (titleMaxLength <= 0) {
console.warn('titleMaxLength must be greater than 0');
} else if ((titleNode as String).length > titleMaxLength) {
titleNode = `${(titleNode as String).slice(0, titleMaxLength)}...`;
} else if ((titleNode as string).length > titleMaxLength) {
titleNode = `${(titleNode as string).slice(0, titleMaxLength)}...`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/notice-bar/NoticeBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { noticeBarDefaultProps } from './defaultProps';
import noop from '../_util/noop';

export interface NoticeBarProps extends TdNoticeBarProps, StyledProps {
touchable?: Boolean;
touchable?: boolean;
}

type IconType = ReturnType<typeof InfoCircleFilledIcon>;
Expand Down
7 changes: 5 additions & 2 deletions src/picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ const Picker: FC<PickerProps> = (props) => {

const [pickerValue = [], setPickerValue] = useDefault(value, defaultValue, onChange);
const confirmButtonText = useMemo(
() => getDefaultText(confirmBtn, t(locale.confirm)),
() => getDefaultText(confirmBtn, t(locale.confirm) as string),
[confirmBtn, t, locale.confirm],
);
const cancelButtonText = useMemo(() => getDefaultText(cancelBtn, t(locale.cancel)), [cancelBtn, t, locale.cancel]);
const cancelButtonText = useMemo(
() => getDefaultText(cancelBtn, t(locale.cancel) as string),
[cancelBtn, t, locale.cancel],
);
const [curValueArray, setCurValueArray] = useState(value?.map((item) => item) ?? []);
const pickerItemInstanceArray = useRef<PickerItemExposeRef[]>([]);

Expand Down
4 changes: 3 additions & 1 deletion src/picker/picker.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ class Picker {
this.list.style.transitionDuration = `${realOptions.duration}ms`;
this.list.style.transitionTimingFunction = 'ease-out';
}
realOptions.isChange && this.onChange(index);
if (realOptions.isChange) {
this.onChange(index);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Popover = forwardRef<PopoverExposeRef, PopoverProps>((props, ref) => {
x: number;
y: number;
};
placement: String;
placement: string;
}) => {
const horizontal = ['top', 'bottom'];
const vertical = ['left', 'right'];
Expand Down
2 changes: 1 addition & 1 deletion src/pull-down-refresh/PullDownRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
}
};

const statusText = getStatusText(status, loadingTexts.length ? loadingTexts : t(locale.loadingTexts));
const statusText = getStatusText(status, loadingTexts.length ? loadingTexts : (t(locale.loadingTexts) as string[]));
let statusNode: React.ReactNode = <div className={`${name}__text`}>{statusText}</div>;
if (status === PullStatusEnum.loading) {
statusNode = <Loading text={statusText} size="24px" {...loadingProps} />;
Expand Down
8 changes: 6 additions & 2 deletions src/radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,17 @@ const Radio = forwardRef((_props: RadioProps, ref: Ref<HTMLDivElement>) => {
}
if (icon === 'dot') {
let dotIconClassName = `${radioClass}__icon-${icon}`;
disabled && (dotIconClassName += ` ${radioClass}__icon-${icon}--disabled`);
if (disabled) {
dotIconClassName += ` ${radioClass}__icon-${icon}--disabled`;
}
return <div className={dotIconClassName} />;
}
} else {
if (icon === 'circle' || icon === 'dot') {
let circleIconClassName = `${radioClass}__icon-circle`;
disabled && (circleIconClassName += ` ${radioClass}__icon-circle--disabled`);
if (disabled) {
circleIconClassName += ` ${radioClass}__icon-circle--disabled`;
}
return <div className={circleIconClassName} />;
}
if (icon === 'line') {
Expand Down
20 changes: 10 additions & 10 deletions src/side-bar/SideBarContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import React, { createContext, MutableRefObject, useMemo } from 'react';
import { ChangeHandler } from '../_util/useDefault';
import { TdSideBarProps } from './type';

interface BaseSidebarContext {
defaultIndex: MutableRefObject<number>;
activeValue: number | string | (number | string)[];
updateChild: ChangeHandler<number | string | (number | string)[], any[]>;
relation: (child: any) => void;
removeRelation: (child: any) => void;
onClickItem: (cur: any, label: any) => void;
}

/**
* SideBarContext is a React context that stores the state and actions related to the SideBar component.
*/
export const SideBarContext = createContext<
{
defaultIndex: MutableRefObject<number>;
activeValue: number | string | (number | string)[];
updateChild: ChangeHandler<number | string | (number | string)[], any[]>;
relation: (child: any) => void;
removeRelation: (child: any) => void;
onClickItem: (cur: any, label: any) => void;
} & Pick<TdSideBarProps, 'onChange' | 'onClick'>
>(null);
export const SideBarContext = createContext<BaseSidebarContext & Pick<TdSideBarProps, 'onChange' | 'onClick'>>(null);

export function SideBarProvider({ children, value }) {
const memoValue = useMemo(() => value, [value]);
Expand Down
2 changes: 1 addition & 1 deletion src/skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Skeleton: React.FC<SkeletonProps> = (props) => {
skeletonDefaultProps,
);

const renderCols = (_cols: Number | SkeletonRowColObj | Array<SkeletonRowColObj>) => {
const renderCols = (_cols: number | SkeletonRowColObj | Array<SkeletonRowColObj>) => {
let cols: Array<SkeletonRowColObj> = [];
if (isArray(_cols)) {
cols = _cols;
Expand Down
Loading