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

fix: Fix tour step type #39382

Merged
merged 25 commits into from Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1c2bc1a
feat: fix-step-type
heiyu4585 Dec 7, 2022
6b02942
feat: fix-step-type
heiyu4585 Dec 7, 2022
cf525cc
feat: add test
heiyu4585 Dec 12, 2022
62287b9
feat: update test
heiyu4585 Dec 12, 2022
afad578
feat: update test snapshots
heiyu4585 Dec 12, 2022
0a2f4cf
feat: update test snapshots
heiyu4585 Dec 12, 2022
9b16e0e
feat: update test snapshots
heiyu4585 Dec 12, 2022
dd57d6b
fix: PurePanel style
zombieJ Dec 15, 2022
e542cf4
test: update snapshot
zombieJ Dec 15, 2022
e1fe78e
feat: update package
heiyu4585 Dec 15, 2022
424759b
Merge branch 'master' of https://github.com/ant-design/ant-design int…
heiyu4585 Dec 16, 2022
5fa89de
Merge branch 'fix-step-type' of https://github.com/heiyu4585/ant-desi…
heiyu4585 Dec 16, 2022
2c6b470
Merge branch 'master' of https://github.com/ant-design/ant-design int…
heiyu4585 Dec 16, 2022
e7fd63d
feat: fix-step-type
heiyu4585 Dec 7, 2022
cfe139d
feat: fix-step-type
heiyu4585 Dec 7, 2022
180d1a4
feat: add test
heiyu4585 Dec 12, 2022
0a082df
feat: update test
heiyu4585 Dec 12, 2022
089b11a
feat: update test snapshots
heiyu4585 Dec 12, 2022
dc632cb
feat: update test snapshots
heiyu4585 Dec 12, 2022
8ddde5e
feat: update test snapshots
heiyu4585 Dec 12, 2022
e9a9c40
feat: update package
heiyu4585 Dec 15, 2022
9bb8d79
fix: PurePanel style
zombieJ Dec 15, 2022
76ed3d1
test: update snapshot
zombieJ Dec 15, 2022
8ca1f33
Merge branch 'fix-step-type' of https://github.com/heiyu4585/ant-desi…
heiyu4585 Dec 19, 2022
036c8aa
feat: update for checks
heiyu4585 Dec 19, 2022
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
446 changes: 235 additions & 211 deletions components/tour/__tests__/__snapshots__/demo-extend.test.ts.snap

Large diffs are not rendered by default.

446 changes: 235 additions & 211 deletions components/tour/__tests__/__snapshots__/demo.test.ts.snap

Large diffs are not rendered by default.

672 changes: 629 additions & 43 deletions components/tour/__tests__/__snapshots__/index.test.tsx.snap

Large diffs are not rendered by default.

70 changes: 54 additions & 16 deletions components/tour/__tests__/index.test.tsx
Expand Up @@ -29,10 +29,10 @@ describe('Tour', () => {
</>
);
};
const { getByText, container } = render(<App />);
const { getByText, baseElement } = render(<App />);
expect(getByText('cover title')).toBeTruthy();
expect(getByText('cover description.')).toBeTruthy();
expect(container.firstChild).toMatchSnapshot();
expect(baseElement).toMatchSnapshot();
});

it('steps is empty', () => {
Expand All @@ -48,8 +48,8 @@ describe('Tour', () => {
</>
);
};
const { container } = render(<App />);
expect(container.firstChild).toMatchSnapshot();
const { baseElement } = render(<App />);
expect(baseElement).toMatchSnapshot();
});

it('steps props stepRender', () => {
Expand Down Expand Up @@ -95,14 +95,14 @@ describe('Tour', () => {
</>
);
};
const { container } = render(<App />);
const { baseElement } = render(<App />);
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
fireEvent.click(screen.getByRole('button', { name: 'Previous' }));
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
fireEvent.click(screen.getByRole('button', { name: 'Finish' }));
expect(onClickMock).toHaveBeenCalledTimes(5);
expect(container.firstChild).toMatchSnapshot();
expect(baseElement).toMatchSnapshot();
});

it('button props onClick', () => {
Expand Down Expand Up @@ -141,15 +141,16 @@ describe('Tour', () => {
</>
);
};
const { container } = render(<App />);
expect(container.querySelector('#btnName')).toHaveTextContent('defaultBtn');
const { baseElement } = render(<App />);
expect(baseElement.querySelector('#btnName')).toHaveTextContent('defaultBtn');
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
expect(container.querySelector('#btnName')).toHaveTextContent('nextButton');
expect(baseElement.querySelector('#btnName')).toHaveTextContent('nextButton');
fireEvent.click(screen.getByRole('button', { name: 'Previous' }));
expect(container.querySelector('#btnName')).toHaveTextContent('prevButton');
expect(baseElement.querySelector('#btnName')).toHaveTextContent('prevButton');
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
fireEvent.click(screen.getByRole('button', { name: 'Finish' }));
expect(container.querySelector('#btnName')).toHaveTextContent('finishButton');
expect(baseElement.querySelector('#btnName')).toHaveTextContent('finishButton');
expect(baseElement).toMatchSnapshot();
});

it('Primary', () => {
Expand All @@ -174,10 +175,47 @@ describe('Tour', () => {
</>
);
};
const { getByText, container } = render(<App />);
const { getByText, baseElement } = render(<App />);
expect(getByText('primary description.')).toBeTruthy();
expect(container.querySelector('.ant-tour')).toHaveClass('ant-tour-primary');
expect(container.firstChild).toMatchSnapshot();
expect(baseElement.querySelector('.ant-tour-content')).toHaveClass('ant-tour-primary');
expect(baseElement).toMatchSnapshot();
});

it('step support Primary', () => {
const App: React.FC = () => {
const coverBtnRef = useRef<HTMLButtonElement>(null);
return (
<>
<button disabled ref={coverBtnRef} type="button">
Cover
</button>

<Tour
type="default"
steps={[
{
title: 'cover title',
description: 'cover description.',
target: () => coverBtnRef.current!,
},
{
title: 'primary title',
description: 'primary description.',
target: () => coverBtnRef.current!,
type: 'primary',
},
]}
/>
</>
);
};
const { getByText, container, baseElement } = render(<App />);
expect(getByText('cover description.')).toBeTruthy();
expect(container.querySelector('.ant-tour-content.ant-tour-primary')).toBeFalsy();
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
expect(getByText('primary description.')).toBeTruthy();
expect(container.querySelector('.ant-tour-content.ant-tour-primary')).toBeTruthy();
expect(baseElement).toMatchSnapshot();
});

it('basic', () => {
Expand Down Expand Up @@ -243,7 +281,7 @@ describe('Tour', () => {
</>
);
};
const { getByText, container } = render(<App />);
const { getByText, container, baseElement } = render(<App />);
fireEvent.click(screen.getByRole('button', { name: 'Show' }));
expect(getByText('Show in Center')).toBeTruthy();
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
Expand All @@ -252,7 +290,7 @@ describe('Tour', () => {
expect(getByText('Adjust Placement')).toBeTruthy();
fireEvent.click(screen.getByRole('button', { name: 'Finish' }));
expect(container.querySelector('.ant-tour')).toBeFalsy();
expect(container.firstChild).toMatchSnapshot();
expect(baseElement).toMatchSnapshot();
});
it('panelRender should correct render when total is undefined', () => {
expect(() => {
Expand Down
3 changes: 0 additions & 3 deletions components/tour/index.tsx
Expand Up @@ -27,9 +27,6 @@ const Tour: React.ForwardRefRenderFunction<HTMLDivElement, TourProps> & {
{
[`${prefixCls}-rtl`]: direction === 'rtl',
},
{
[`${prefixCls}-primary`]: type === 'primary',
},
hashId,
rootClassName,
);
Expand Down
69 changes: 41 additions & 28 deletions components/tour/panelRender.tsx
Expand Up @@ -26,8 +26,12 @@ const panelRender = (
nextButtonProps,
prevButtonProps,
stepRender,
type: stepType,
arrow,
className,
} = props;

const mergedType = typeof stepType !== 'undefined' ? stepType : type;
const isLastStep = current === total - 1;

const prevBtnClick = () => {
Expand Down Expand Up @@ -80,47 +84,56 @@ const panelRender = (
));
const slickNode: ReactNode = total > 1 ? mergedSlickNode : null;

const mainBtnType = type === 'primary' ? 'default' : 'primary';
const mainBtnType = mergedType === 'primary' ? 'default' : 'primary';
const secondaryBtnProps: ButtonProps = {
type: 'default',
ghost: type === 'primary',
ghost: mergedType === 'primary',
};

return (
<LocaleReceiver componentName="Tour" defaultLocale={defaultLocale.Tour}>
{(contextLocale) => (
<>
<CloseOutlined className={`${prefixCls}-close`} onClick={onClose} />
{coverNode}
{headerNode}
{descriptionNode}
<div className={`${prefixCls}-footer`}>
<div className={`${prefixCls}-sliders`}>{slickNode}</div>
<div className={`${prefixCls}-buttons`}>
{current !== 0 ? (
<div
className={classNames(
mergedType === 'primary' ? `${prefixCls}-primary` : '',
className,
`${prefixCls}-content`,
)}
>
{arrow && <div className={`${prefixCls}-arrow`} key="arrow" />}
<div className={`${prefixCls}-inner`}>
<CloseOutlined className={`${prefixCls}-close`} onClick={onClose} />
{coverNode}
{headerNode}
{descriptionNode}
<div className={`${prefixCls}-footer`}>
<div className={`${prefixCls}-sliders`}>{slickNode}</div>
<div className={`${prefixCls}-buttons`}>
{current !== 0 ? (
<Button
{...secondaryBtnProps}
{...prevButtonProps}
onClick={prevBtnClick}
size="small"
className={`${prefixCls}-prev-btn`}
>
{prevButtonProps?.children ?? contextLocale.Previous}
</Button>
) : null}
<Button
{...secondaryBtnProps}
{...prevButtonProps}
onClick={prevBtnClick}
type={mainBtnType}
{...nextButtonProps}
onClick={nextBtnClick}
size="small"
className={`${prefixCls}-prev-btn`}
className={`${prefixCls}-next-btn`}
>
{prevButtonProps?.children ?? contextLocale.Previous}
{nextButtonProps?.children ??
(isLastStep ? contextLocale.Finish : contextLocale.Next)}
</Button>
) : null}
<Button
type={mainBtnType}
{...nextButtonProps}
onClick={nextBtnClick}
size="small"
className={`${prefixCls}-next-btn`}
>
{nextButtonProps?.children ??
(isLastStep ? contextLocale.Finish : contextLocale.Next)}
</Button>
</div>
</div>
</div>
</>
</div>
)}
</LocaleReceiver>
);
Expand Down
11 changes: 8 additions & 3 deletions components/tour/style/index.tsx
Expand Up @@ -66,7 +66,7 @@ const genBaseStyle: GenerateStyle<TourToken> = (token) => {
display: 'none',
},

// ============================= panel content ===========================
// ============================= panel content ============================
[`${componentCls}-content`]: {
position: 'relative',
},
Expand Down Expand Up @@ -152,9 +152,13 @@ const genBaseStyle: GenerateStyle<TourToken> = (token) => {
},
},

// ============================= primary type ===========================
[`&${componentCls}-primary`]: {
// ============================= primary type ===========================
li-jia-nan marked this conversation as resolved.
Show resolved Hide resolved
// `$` for panel, `&$` for pure panel
[`${componentCls}-primary, &${componentCls}-primary`]: {
'--antd-arrow-background-color': colorPrimary,
},

[`${componentCls}-primary`]: {
[`${componentCls}-inner`]: {
color: colorTextLightSolid,
textAlign: 'start',
Expand All @@ -180,6 +184,7 @@ const genBaseStyle: GenerateStyle<TourToken> = (token) => {
[`${componentCls}-prev-btn`]: {
color: colorTextLightSolid,
borderColor: new TinyColor(colorTextLightSolid).setAlpha(0.15).toRgbString(),
backgroundColor: colorPrimary,

'&:hover': {
backgroundColor: new TinyColor(colorTextLightSolid).setAlpha(0.15).toRgbString(),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -115,7 +115,7 @@
"@ant-design/react-slick": "~0.29.1",
"@babel/runtime": "^7.18.3",
"@ctrl/tinycolor": "^3.4.0",
"@rc-component/tour": "~1.0.1-2",
"@rc-component/tour": "~1.1.0",
"classnames": "^2.2.6",
"copy-to-clipboard": "^3.2.0",
"dayjs": "^1.11.1",
Expand Down