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

feat: added step 4 for onboarding in dtrader v2 #82

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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { TooltipRenderProps } from 'react-joyride';
import GuideTooltip from '../guide-tooltip';
import GuideTooltip, { GuideTooltipProps } from '../guide-tooltip';

jest.mock('react-joyride', () => jest.fn(() => <div>Joyride</div>));

Expand All @@ -17,8 +16,9 @@ const mock_props = {
title: 'Title',
content: 'Step content',
},
setStepIndex: jest.fn(),
tooltipProps: {},
} as unknown as TooltipRenderProps;
} as unknown as GuideTooltipProps;

describe('GuideTooltip', () => {
it('should render correct content for tooltip if isLastStep === false', () => {
Expand All @@ -38,4 +38,10 @@ describe('GuideTooltip', () => {
expect(screen.getByText('Done')).toBeInTheDocument();
expect(screen.queryByText('Next')).not.toBeInTheDocument();
});

it('should render scroll icon if title of the step is scroll-icon', () => {
mock_props.step.title = 'scroll-icon';
render(<GuideTooltip {...mock_props} isLastStep={true} />);
expect(screen.getByText('Swipe up to see the chart')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type TGuideContainerProps = {
};

const GuideContainer = ({ should_run, onFinishGuide }: TGuideContainerProps) => {
const [step_index, setStepIndex] = React.useState(0);
const steps = [
{
content: <Localize i18n_default_text='Scroll left or right to explore trade types.' />,
Expand All @@ -35,13 +36,37 @@ const GuideContainer = ({ should_run, onFinishGuide }: TGuideContainerProps) =>
target: '.trade-params',
title: <Localize i18n_default_text='Open your trade (3/6)' />,
},
{
content: '',
disableBeacon: false,
offset: 0,
spotlightPadding: 0,
styles: {
spotlight: {
display: 'none',
},
arrow: {
display: 'none',
},
},
target: '.purchase-button__wrapper',
title: 'scroll-icon',
},
{
content: <Localize i18n_default_text='Track market trends with our interactive charts.' />,
disableBeacon: true,
spotlightPadding: 8,
offset: 4,
target: '.trade__chart-tooltip',
title: <Localize i18n_default_text='Analyse with charts (4/6)' />,
placement: 'bottom' as Step['placement'],
},
{
content: <Localize i18n_default_text='Scroll left or right to adjust your trade parameters.' />,
disableBeacon: true,
// TODO: remove disableScrolling after 4 step wil be added
disableScrolling: false,
offset: -4,
target: '.trade__bottom',
target: '.trade__parameter',
title: <Localize i18n_default_text='Make quick adjustments (5/6)' />,
},
{
Expand Down Expand Up @@ -73,11 +98,12 @@ const GuideContainer = ({ should_run, onFinishGuide }: TGuideContainerProps) =>
arrow: {
length: 4,
spread: 8,
display: step_index === 3 ? 'none' : 'inline-flex',
},
},
}}
run={should_run}
showSkipButton
tooltipComponent={GuideTooltip}
steps={steps}
spotlightPadding={0}
scrollToFirstStep
Expand All @@ -90,7 +116,8 @@ const GuideContainer = ({ should_run, onFinishGuide }: TGuideContainerProps) =>
borderRadius: 'unset',
},
}}
run={should_run}
stepIndex={step_index}
tooltipComponent={props => <GuideTooltip {...props} setStepIndex={setStepIndex} />}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

/>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,75 @@
import React from 'react';
import { Button, CaptionText, IconButton } from '@deriv-com/quill-ui';
import { LabelPairedXmarkSmBoldIcon } from '@deriv/quill-icons';
import { Button, CaptionText, IconButton, Text } from '@deriv-com/quill-ui';
import { LabelPairedChevronsUpXlBoldIcon, LabelPairedXmarkSmBoldIcon } from '@deriv/quill-icons';
import { Localize } from '@deriv/translations';
import { TooltipRenderProps } from 'react-joyride';
import { useSwipeable } from 'react-swipeable';
import { setTime } from '@deriv/shared';

const GuideTooltip = ({ isLastStep, primaryProps, skipProps, step, tooltipProps }: TooltipRenderProps) => (
<div {...tooltipProps} className='guide-tooltip__wrapper'>
<div>
{step.title && (
<div className='guide-tooltip__header'>
<CaptionText bold color='var(--component-textIcon-inverse-prominent)'>
{step.title}
export interface GuideTooltipProps extends TooltipRenderProps {
vinu-deriv marked this conversation as resolved.
Show resolved Hide resolved
setStepIndex: React.Dispatch<React.SetStateAction<number>>;
}

const GuideTooltip = ({ isLastStep, primaryProps, skipProps, step, tooltipProps, setStepIndex }: GuideTooltipProps) => {
const swipe_handlers = useSwipeable({
onSwipedUp: () => {
document.querySelector('.trade__chart')?.scrollIntoView();
setStepIndex((prev: number) => prev + 1);
},
preventDefaultTouchmoveEvent: true,
trackTouch: true,
trackMouse: true,
});

if (step.title === 'scroll-icon') {
return (
<div {...swipe_handlers} className='guide-tooltip__wrapper-scroll'>
<LabelPairedChevronsUpXlBoldIcon className='guide-tooltip--bounce' />
<Text size='sm' bold className='guide-tooltip__wrapper-scroll-text'>
<Localize i18n_default_text='Swipe up to see the chart' />
</Text>
</div>
);
}

return (
<div {...tooltipProps} className='guide-tooltip__wrapper'>
<div>
{step.title && (
<div className='guide-tooltip__header'>
<CaptionText bold color='var(--component-textIcon-inverse-prominent)'>
{step.title}
</CaptionText>
<IconButton
{...skipProps}
icon={<LabelPairedXmarkSmBoldIcon fill='var(--component-textIcon-inverse-prominent)' />}
className='guide-tooltip__close'
size='sm'
color='white-black'
variant='tertiary'
/>
</div>
)}
{step.content && (
<CaptionText color='var(--component-textIcon-inverse-prominent)' className='guide-tooltip__content'>
{step.content}
</CaptionText>
<IconButton
{...skipProps}
icon={<LabelPairedXmarkSmBoldIcon fill='var(--component-textIcon-inverse-prominent)' />}
className='guide-tooltip__close'
size='sm'
color='white-black'
variant='tertiary'
/>
</div>
)}
{step.content && (
<CaptionText color='var(--component-textIcon-inverse-prominent)' className='guide-tooltip__content'>
{step.content}
</CaptionText>
)}
)}
</div>
<Button
{...primaryProps}
onClick={e => {
setStepIndex((prev: number) => prev + 1);
primaryProps.onClick(e);
}}
color='white-black'
className='guide-tooltip__button'
variant='secondary'
size='sm'
label={isLastStep ? <Localize i18n_default_text='Done' /> : <Localize i18n_default_text='Next' />}
/>
</div>
<Button
{...primaryProps}
color='white-black'
className='guide-tooltip__button'
variant='secondary'
size='sm'
label={isLastStep ? <Localize i18n_default_text='Done' /> : <Localize i18n_default_text='Next' />}
/>
</div>
);
);
};

export default GuideTooltip;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
align-items: flex-start;
min-width: var(--core-size-4300);
color: var(--component-textIcon-inverse-prominent);

&-scroll {
display: flex;
flex-direction: column;
align-items: center;

&-text {
color: var(--core-color-solid-slate-50);
}
}
}

&__button {
Expand All @@ -29,6 +39,23 @@
inset-inline-start: var(--core-spacing-500);
inset-block-end: var(--core-spacing-500);
}

@keyframes bounce {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-10px);
}
}

&--bounce {
height: var(--core-spacing-3200);
width: var(--core-spacing-2400);
fill: var(--core-color-solid-slate-50);
animation: bounce var(--core-motion-duration-400) ease-in-out var(--core-motion-duration-100) infinite;
}
}

//TODO: remove after video for position page guide will be ready
Expand Down
3 changes: 3 additions & 0 deletions packages/trader/src/AppV2/Containers/Trade/trade.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@
position: relative;
}
}
&__parameter {
display: inline;
}
}
10 changes: 6 additions & 4 deletions packages/trader/src/AppV2/Containers/Trade/trade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ const Trade = observer(() => {
<TradeParametersContainer>
<TradeParameters />
</TradeParametersContainer>
<section className='trade__chart' style={{ height: dynamic_chart_height }} ref={chart_ref}>
<TradeChart />
</section>
<div className='trade__chart-tooltip'>
<section className='trade__chart' style={{ height: dynamic_chart_height }} ref={chart_ref}>
<TradeChart />
</section>
</div>
{isAccumulatorContract(contract_type) && <AccumulatorStats />}
</div>
<div className='trade__bottom'>
<div className='trade__parameter'>
<TradeParametersContainer is_minimized_visible={is_minimized_params_visible} is_minimized>
<TradeParameters is_minimized />
</TradeParametersContainer>
Expand Down
Loading