1
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
import * as React from 'react';
|
||||
import type { CopyConfig } from '../Base';
|
||||
declare const useCopyClick: ({ copyConfig, children, }: {
|
||||
copyConfig: CopyConfig;
|
||||
children?: React.ReactNode;
|
||||
}) => {
|
||||
copied: boolean;
|
||||
copyLoading: boolean;
|
||||
onClick: (e?: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
|
||||
};
|
||||
export default useCopyClick;
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
import * as React from 'react';
|
||||
import { useEvent } from '@rc-component/util';
|
||||
import copy from '../../_util/copy';
|
||||
import toList from '../../_util/toList';
|
||||
const useCopyClick = ({
|
||||
copyConfig,
|
||||
children
|
||||
}) => {
|
||||
const [copied, setCopied] = React.useState(false);
|
||||
const [copyLoading, setCopyLoading] = React.useState(false);
|
||||
const copyIdRef = React.useRef(null);
|
||||
const cleanCopyId = () => {
|
||||
if (copyIdRef.current) {
|
||||
clearTimeout(copyIdRef.current);
|
||||
}
|
||||
};
|
||||
const copyOptions = {};
|
||||
if (copyConfig.format) {
|
||||
copyOptions.format = copyConfig.format;
|
||||
}
|
||||
React.useEffect(() => cleanCopyId, []);
|
||||
// Keep copy action up to date
|
||||
const onClick = useEvent(async e => {
|
||||
e?.preventDefault();
|
||||
e?.stopPropagation();
|
||||
setCopyLoading(true);
|
||||
try {
|
||||
const text = typeof copyConfig.text === 'function' ? await copyConfig.text() : copyConfig.text;
|
||||
await copy(text || toList(children, {
|
||||
skipEmpty: true
|
||||
}).join('') || '', copyOptions);
|
||||
setCopyLoading(false);
|
||||
setCopied(true);
|
||||
// Trigger tips update
|
||||
cleanCopyId();
|
||||
copyIdRef.current = setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 3000);
|
||||
copyConfig.onCopy?.(e);
|
||||
} catch (error) {
|
||||
setCopyLoading(false);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
return {
|
||||
copied,
|
||||
copyLoading,
|
||||
onClick
|
||||
};
|
||||
};
|
||||
export default useCopyClick;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export default function useMergedConfig<Target>(propConfig: any, templateConfig?: Target): readonly [boolean, Target];
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import * as React from 'react';
|
||||
export default function useMergedConfig(propConfig, templateConfig) {
|
||||
return React.useMemo(() => {
|
||||
const support = !!propConfig;
|
||||
return [support, {
|
||||
...templateConfig,
|
||||
...(support && typeof propConfig === 'object' ? propConfig : null)
|
||||
}];
|
||||
}, [propConfig]);
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const usePrevious: <T>(value: T) => T | undefined;
|
||||
export default usePrevious;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
const usePrevious = value => {
|
||||
const ref = useRef(undefined);
|
||||
useEffect(() => {
|
||||
ref.current = value;
|
||||
});
|
||||
return ref.current;
|
||||
};
|
||||
export default usePrevious;
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
import type { TooltipProps } from '../../tooltip';
|
||||
declare const useTooltipProps: (tooltip: React.ReactNode | TooltipProps, editConfigText: React.ReactNode, children: React.ReactNode) => {
|
||||
[Symbol.iterator](): Iterator<import("react").ReactNode, any, any>;
|
||||
title: import("react").ReactNode;
|
||||
} | {
|
||||
then<TResult1 = string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined, TResult2 = never>(onfulfilled?: ((value: string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
||||
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<(string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined) | TResult>;
|
||||
finally(onfinally?: (() => void) | null | undefined): Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined>;
|
||||
[Symbol.toStringTag]: string;
|
||||
title: import("react").ReactNode;
|
||||
} | {
|
||||
title: string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("../../_util/getRenderPropValue").RenderFunction | null | undefined;
|
||||
overlay?: React.ReactNode | import("../../_util/getRenderPropValue").RenderFunction;
|
||||
classNames?: import("../../tooltip").TooltipClassNamesType;
|
||||
styles?: import("../../tooltip").TooltipStylesType;
|
||||
style?: React.CSSProperties;
|
||||
className?: string;
|
||||
rootClassName?: string;
|
||||
color?: import("../../_util/type").LiteralUnion<import("../../_util/colors").PresetColorType>;
|
||||
placement?: import("../../tooltip").TooltipPlacement;
|
||||
builtinPlacements?: typeof import("@rc-component/tooltip/lib/placements").placements;
|
||||
openClassName?: string;
|
||||
arrow?: boolean | {
|
||||
pointAtCenter?: boolean;
|
||||
};
|
||||
autoAdjustOverflow?: boolean | import("../../tooltip").AdjustOverflow;
|
||||
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
||||
children?: React.ReactNode;
|
||||
destroyOnHidden?: boolean;
|
||||
destroyTooltipOnHide?: boolean | {
|
||||
keepParent?: boolean;
|
||||
};
|
||||
overlayStyle?: React.CSSProperties;
|
||||
overlayInnerStyle?: React.CSSProperties;
|
||||
overlayClassName?: string;
|
||||
open?: import("@rc-component/tooltip/lib/Tooltip").TooltipProps["visible"];
|
||||
defaultOpen?: import("@rc-component/tooltip/lib/Tooltip").TooltipProps["defaultVisible"];
|
||||
onOpenChange?: import("@rc-component/tooltip/lib/Tooltip").TooltipProps["onVisibleChange"];
|
||||
afterOpenChange?: import("@rc-component/tooltip/lib/Tooltip").TooltipProps["afterVisibleChange"];
|
||||
align?: import("@rc-component/trigger").AlignType | undefined;
|
||||
motion?: import("@rc-component/motion").CSSMotionProps | undefined;
|
||||
prefixCls?: string | undefined;
|
||||
zIndex?: number | undefined;
|
||||
onPopupAlign?: ((element: HTMLElement, align: import("@rc-component/trigger").AlignType) => void) | undefined;
|
||||
fresh?: boolean | undefined;
|
||||
mouseLeaveDelay?: number | undefined;
|
||||
mouseEnterDelay?: number | undefined;
|
||||
forceRender?: boolean | undefined;
|
||||
popupVisible?: boolean | undefined;
|
||||
trigger?: (import("@rc-component/trigger").ActionType | import("@rc-component/trigger").ActionType[]) | undefined;
|
||||
getTooltipContainer?: ((node: HTMLElement) => HTMLElement) | undefined;
|
||||
showArrow?: (boolean | import("@rc-component/trigger").ArrowType) | undefined;
|
||||
arrowContent?: import("react").ReactNode;
|
||||
id?: string | undefined;
|
||||
unique?: boolean | undefined;
|
||||
};
|
||||
export default useTooltipProps;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { isValidElement, useMemo } from 'react';
|
||||
import { isPlainObject } from '../../_util/is';
|
||||
const useTooltipProps = (tooltip, editConfigText, children) => useMemo(() => {
|
||||
if (tooltip === true) {
|
||||
return {
|
||||
title: editConfigText ?? children
|
||||
};
|
||||
}
|
||||
if (/*#__PURE__*/isValidElement(tooltip)) {
|
||||
return {
|
||||
title: tooltip
|
||||
};
|
||||
}
|
||||
if (isPlainObject(tooltip)) {
|
||||
return {
|
||||
title: editConfigText ?? children,
|
||||
...tooltip
|
||||
};
|
||||
}
|
||||
return {
|
||||
title: tooltip
|
||||
};
|
||||
}, [tooltip, editConfigText, children]);
|
||||
export default useTooltipProps;
|
||||
Reference in New Issue
Block a user