Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump trigger to move click to mouseDown #47775

Merged
merged 7 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 31 additions & 3 deletions components/tour/PurePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import classNames from 'classnames';
import * as React from 'react';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';

import useClosable from '../_util/hooks/useClosable';
import { withPureRenderTheme } from '../_util/PurePanel';
import { cloneElement } from '../_util/reactNode';
import { ConfigContext } from '../config-provider';
import { RawPurePanel as PopoverRawPurePanel } from '../popover/PurePanel';
import type { TourStepProps } from './interface';
import TourPanel from './panelRender';
import useStyle from './style';
import { withPureRenderTheme } from '../_util/PurePanel';

export interface PurePanelProps extends TourStepProps {}

Expand All @@ -17,6 +21,8 @@ const PurePanel: React.FC<PurePanelProps> = (props) => {
className,
style,
type,
closable,
closeIcon,
...restProps
} = props;

Expand All @@ -25,6 +31,19 @@ const PurePanel: React.FC<PurePanelProps> = (props) => {

const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);

const [mergedClosable, mergedCloseIcon] = useClosable({
closable,
closeIcon,
customCloseIconRender: (icon) =>
React.isValidElement(icon)
? cloneElement(icon, {
className: classNames(icon.props.className, `${prefixCls}-close-icon`),
})
: icon,
defaultCloseIcon: <CloseOutlined />,
defaultClosable: true,
});

return wrapCSSVar(
<PopoverRawPurePanel
prefixCls={prefixCls}
Expand All @@ -37,7 +56,16 @@ const PurePanel: React.FC<PurePanelProps> = (props) => {
)}
style={style}
>
<TourPanel stepProps={{ ...restProps, prefixCls, total }} current={current} type={type} />
<TourPanel
stepProps={{
...restProps,
prefixCls,
total,
closable: mergedClosable ? { closeIcon: mergedCloseIcon } : undefined,
}}
current={current}
type={type}
/>
</PopoverRawPurePanel>,
);
};
Expand Down
9 changes: 4 additions & 5 deletions components/tour/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext } from 'react';
import RCTour from '@rc-component/tour';
import RCTour, { type TourProps as RcTourProps } from '@rc-component/tour';
import classNames from 'classnames';

import { useZIndex } from '../_util/hooks/useZIndex';
Expand All @@ -8,7 +8,7 @@ import zIndexContext from '../_util/zindexContext';
import type { ConfigConsumerProps } from '../config-provider';
import { ConfigContext } from '../config-provider';
import { useToken } from '../theme/internal';
import type { TourProps, TourStepProps } from './interface';
import type { TourProps } from './interface';
import TourPanel from './panelRender';
import PurePanel from './PurePanel';
import useStyle from './style';
Expand All @@ -24,7 +24,7 @@ const Tour: React.FC<TourProps> & { _InternalPanelDoNotUseOrYouWillBeFired: type
steps,
...restProps
} = props;
const { getPrefixCls, direction, tour } = useContext<ConfigConsumerProps>(ConfigContext);
const { getPrefixCls, direction } = useContext<ConfigConsumerProps>(ConfigContext);
const prefixCls = getPrefixCls('tour', customizePrefixCls);
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
const [, token] = useToken();
Expand Down Expand Up @@ -58,12 +58,11 @@ const Tour: React.FC<TourProps> & { _InternalPanelDoNotUseOrYouWillBeFired: type
rootClassName,
);

const mergedRenderPanel = (stepProps: TourStepProps, stepCurrent: number): React.ReactNode => (
const mergedRenderPanel: RcTourProps['renderPanel'] = (stepProps, stepCurrent) => (
<TourPanel
type={type}
stepProps={stepProps}
current={stepCurrent}
closeIcon={tour?.closeIcon}
indicatorsRender={indicatorsRender}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion components/tour/interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ReactNode } from 'react';
import type {
TourProps as RCTourProps,
TourStepProps as RCTourStepProps,
} from '@rc-component/tour';
import type { ReactNode } from 'react';

export interface TourProps extends Omit<RCTourProps, 'renderPanel'> {
steps?: TourStepProps[];
Expand Down
33 changes: 15 additions & 18 deletions components/tour/panelRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';

import useClosable from '../_util/hooks/useClosable';
import type { ButtonProps } from '../button';
import Button from '../button';
import { useLocale } from '../locale';
Expand All @@ -15,17 +14,18 @@ function isValidNode(node: ReactNode): boolean {
}

interface TourPanelProps {
stepProps: TourStepProps;
stepProps: Omit<TourStepProps, 'closable'> & {
closable?: Exclude<TourStepProps['closable'], boolean>;
};
current: number;
type: TourStepProps['type'];
indicatorsRender?: TourStepProps['indicatorsRender'];
closeIcon?: ReactNode;
}

// Due to the independent design of Panel, it will be too coupled to put in rc-tour,
// so a set of Panel logic is implemented separately in antd.
const TourPanel: React.FC<TourPanelProps> = (props) => {
const { stepProps, current, type, closeIcon, indicatorsRender } = props;
const { stepProps, current, type, indicatorsRender } = props;
const {
prefixCls,
total = 1,
Expand All @@ -39,27 +39,24 @@ const TourPanel: React.FC<TourPanelProps> = (props) => {
nextButtonProps,
prevButtonProps,
type: stepType,
closeIcon: stepCloseIcon,
closable,
} = stepProps;

const mergedType = stepType ?? type;

const mergedCloseIcon = stepCloseIcon ?? closeIcon;
const mergedCloseIcon = React.useMemo(() => {
let defaultCloseIcon: React.ReactNode = <CloseOutlined className={`${prefixCls}-close-icon`} />;

const mergedClosable = mergedCloseIcon !== false && mergedCloseIcon !== null;
if (closable && closable.closeIcon) {
defaultCloseIcon = closable.closeIcon;
}

const [closable, mergedDisplayCloseIcon] = useClosable({
closable: mergedClosable,
closeIcon: mergedCloseIcon,
// eslint-disable-next-line react/no-unstable-nested-components
customCloseIconRender: (icon) => (
return (
<span onClick={onClose} aria-label="Close" className={`${prefixCls}-close`}>
{icon}
{defaultCloseIcon}
</span>
),
defaultCloseIcon: <CloseOutlined className={`${prefixCls}-close-icon`} />,
defaultClosable: true,
});
);
}, [closable]);

const isLastStep = current === total - 1;

Expand Down Expand Up @@ -119,7 +116,7 @@ const TourPanel: React.FC<TourPanelProps> = (props) => {
return (
<div className={`${prefixCls}-content`}>
<div className={`${prefixCls}-inner`}>
{closable && mergedDisplayCloseIcon}
{closable && mergedCloseIcon}
{coverNode}
{headerNode}
{descriptionNode}
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,42 +123,42 @@
"@ctrl/tinycolor": "^3.6.1",
"@rc-component/color-picker": "~1.5.2",
"@rc-component/mutate-observer": "^1.1.0",
"@rc-component/tour": "~1.12.3",
"@rc-component/trigger": "^1.18.3",
"@rc-component/tour": "~1.14.2",
"@rc-component/trigger": "^2.0.0",
"classnames": "^2.5.1",
"copy-to-clipboard": "^3.3.3",
"dayjs": "^1.11.10",
"qrcode.react": "^3.1.0",
"rc-cascader": "~3.22.0",
"rc-cascader": "~3.24.0",
"rc-checkbox": "~3.2.0",
"rc-collapse": "~3.7.2",
"rc-dialog": "~9.4.0",
"rc-drawer": "~7.1.0",
"rc-dropdown": "~4.1.0",
"rc-dropdown": "~4.2.0",
"rc-field-form": "~1.42.1",
"rc-image": "~7.6.0",
"rc-input": "~1.4.3",
"rc-input-number": "~9.0.0",
"rc-mentions": "~2.10.1",
"rc-menu": "~9.12.4",
"rc-mentions": "~2.11.1",
"rc-menu": "~9.13.0",
"rc-motion": "^2.9.0",
"rc-notification": "~5.3.0",
"rc-pagination": "~4.0.4",
"rc-picker": "~4.2.1",
"rc-picker": "~4.3.0",
"rc-progress": "~3.5.1",
"rc-rate": "~2.12.0",
"rc-resize-observer": "^1.4.0",
"rc-segmented": "~2.3.0",
"rc-select": "~14.12.1",
"rc-select": "~14.13.0",
"rc-slider": "~10.5.0",
"rc-steps": "~6.0.1",
"rc-switch": "~4.1.0",
"rc-table": "~7.42.0",
"rc-tabs": "~14.0.0",
"rc-tabs": "~14.1.1",
"rc-textarea": "~1.6.3",
"rc-tooltip": "~6.1.3",
"rc-tooltip": "~6.2.0",
"rc-tree": "~5.8.5",
"rc-tree-select": "~5.18.0",
"rc-tree-select": "~5.19.0",
"rc-upload": "~4.5.2",
"rc-util": "^5.39.1",
"scroll-into-view-if-needed": "^3.1.0",
Expand Down