feat(client): add bootstrap grid component as container component (#49829)

This commit is contained in:
Muhammed Mustafa
2023-07-10 16:49:33 +03:00
committed by GitHub
parent f256211032
commit 1d257e950e
5 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import React from 'react';
import { Story } from '@storybook/react';
import { Container, ContainerProps } from '.';
const story = {
title: 'Example/Container',
component: Container
};
const Template: Story<ContainerProps> = args => {
return (
<Container {...args}>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
<p>Random text to test the element width</p>
</Container>
);
};
export const Default = Template.bind({});
Default.args = {};
export const Fluid = Template.bind({});
Fluid.args = {
fluid: true
};
export default story;

View File

@@ -0,0 +1,27 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Container } from '.';
describe('<Container />', () => {
it('remove width when the container is fluid', () => {
render(
<Container fluid={true}>Random text to test the element width</Container>
);
expect(
screen.getByText('Random text to test the element width')
).toHaveClass('mx-auto px-[15px] ');
});
it('should add className to it', () => {
render(
<Container className='certificate-outer-wrapper'>
Random text to test the element width
</Container>
);
expect(
screen.getByText('Random text to test the element width')
).toHaveClass(
'mx-auto px-[15px] my-0 md:w-[750px] min-[992px]:w-[970px] min-[1200px]:w-[1170px] certificate-outer-wrapper'
);
});
});

View File

@@ -0,0 +1,23 @@
import React from 'react';
import type { ContainerProps } from './types';
export const Container = ({
children,
className,
fluid
}: ContainerProps): JSX.Element => {
let elementClasses = '';
if (!fluid) {
elementClasses = `my-0 md:w-[750px] min-[992px]:w-[970px] min-[1200px]:w-[1170px]`;
}
if (!className) {
className = '';
}
return (
<div className={`mx-auto px-[15px] ${elementClasses} ${className}`}>
{children}
</div>
);
};

View File

@@ -0,0 +1,2 @@
export { Container } from './container';
export type { ContainerProps } from './types';

View File

@@ -0,0 +1,5 @@
export type ContainerProps = {
children?: React.ReactNode;
className?: string;
fluid?: boolean;
};