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

Likhith/74169/ts migration scrollbar container #50

2 changes: 1 addition & 1 deletion packages/account/src/Components/form-body/form-body.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ScrollbarsContainer } from 'Components/scrollbars-container/scrollbars-container';
import { Div100vhContainer, DesktopWrapper, MobileWrapper } from '@deriv/components';
import { ScrollbarsContainer } from 'Components/scrollbars-container/scrollbars-container.jsx';

type TFormBody = {
scroll_offset?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,43 @@ jest.mock('@deriv/shared/src/utils/screen/responsive', () => ({

describe('<ScrollbarsContainer />', () => {
it('should render children with ScrollbarsContainer component for desktop without scroll_offset for desktop ', () => {
const { container } = render(
render(
<ScrollbarsContainer>
<div>Test children</div>
</ScrollbarsContainer>
);

expect(container.firstChild).not.toHaveClass('account__scrollbars_container');
expect(container.firstChild.style.maxHeight).toBe('100%');
const el_child_div = screen.getByText('Test children');

const child_div_el = screen.getByText('Test children');
expect(child_div_el).toBeInTheDocument();
expect(child_div_el.parentElement).toHaveClass('account__scrollbars_container');
expect(el_child_div).toBeInTheDocument();
expect(screen.getByTestId('dt_themed_scrollbars')).toHaveStyle('max-height: 100%');
});

it('should render children with ScrollbarsContainer component for desktop with scroll_offset and extra className for desktop ', () => {
const { container } = render(
render(
<ScrollbarsContainer scroll_offset='33%' className='test__class-name'>
<div>Test children</div>
</ScrollbarsContainer>
);

expect(container.firstChild.style.maxHeight).toBe('calc(100% - 33%)');
const el_child_div = screen.getByText('Test children');

const child_div_el = screen.getByText('Test children');
expect(child_div_el).toBeInTheDocument();
expect(child_div_el.parentElement).toHaveClass('account__scrollbars_container test__class-name');
expect(el_child_div).toBeInTheDocument();
expect(screen.getByTestId('dt_themed_scrollbars')).toHaveStyle('max-height: calc(100% - 33%)');
});

it('should render children with ScrollbarsContainer component with scroll_offset and extra className for mobile', () => {
isMobile.mockReturnValue(true);
(isMobile as jest.Mock).mockReturnValue(true);

const { container } = render(
render(
<ScrollbarsContainer scroll_offset='33%' className='test__class-name'>
<div>Test children</div>
</ScrollbarsContainer>
);
expect(container.firstChild).toHaveClass('account__scrollbars_container');
expect(container.firstChild.style.maxHeight).not.toBe('calc(100% - 33%)');

const child_div_el = screen.getByText('Test children');
expect(child_div_el).toBeInTheDocument();
expect(child_div_el.parentElement).toHaveClass('account__scrollbars_container test__class-name');
const el_child_div = screen.getByText('Test children');

expect(el_child_div).toBeInTheDocument();
expect(screen.queryByTestId('dt_themed_scrollbars')).not.toBeInTheDocument();
});
});
3 changes: 0 additions & 3 deletions packages/account/src/Components/scrollbars-container/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/account/src/Components/scrollbars-container/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ScrollbarsContainer } from './scrollbars-container';

export default ScrollbarsContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import React from 'react';
import { ThemedScrollbars } from '@deriv/components';
import { isMobile } from '@deriv/shared';

export const ScrollbarsContainer = ({ children, className, scroll_offset }) => (
type TScrollbarsContainer = {
className?: string;
scroll_offset?: string;
};

export const ScrollbarsContainer = ({
children,
className,
scroll_offset,
}: React.PropsWithChildren<TScrollbarsContainer>) => (
<ThemedScrollbars is_bypassed={isMobile()} height={scroll_offset ? `calc(100% - ${scroll_offset})` : '100%'}>
<div
className={classNames('account__scrollbars_container', className)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Div100vh from 'react-div-100vh';
type TDiv100vhContainer = {
id: string;
height_offset: string;
is_bypassed: boolean;
is_disabled: boolean;
is_bypassed?: boolean;
is_disabled?: boolean;
max_height_offset: string;
className: string;
max_autoheight_offset: string;
Expand Down