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(react): add Container component #32

Merged
merged 1 commit into from
Feb 15, 2023
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
4 changes: 4 additions & 0 deletions packages/react/.storybook/story-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type Stories =
| 'Button'
| 'ColorModeToggle'
| 'Colors'
| 'Container'
| 'Divider'
| 'Drawer'
| 'Grid'
Expand Down Expand Up @@ -118,6 +119,9 @@ const StoryConfig: StorybookConfig = {
Colors: {
hierarchy: `${StorybookCategories.Foundations}/Colors`,
},
Container: {
hierarchy: `${StorybookCategories.Layout}/Container`,
},
Divider: {
hierarchy: `${StorybookCategories.DataDisplay}/Divider`,
},
Expand Down
57 changes: 57 additions & 0 deletions packages/react/src/components/Container/Container.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';
import Container from './Container.tsx';
import Box from '../Box/Box.tsx';

export const meta = {
component: Container,
title: StoryConfig.Container.hierarchy,
};

<Meta title={meta.title} component={meta.component} />

export const Template = args => (
<Container {...args}>
<Box sx={{bgcolor: '#cfe8fc', height: '100vh'}} />
</Container>
);

# Container

- [Overview](#overview)
- [Props](#props)
- [Usage](#usage)

## Overview

The container centers your content horizontally. It's the most basic layout element.

<Canvas>
<Story name="Overview" args={{maxWidth: 'sm'}}>
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

Import and use the `Container` component in your components as follows.

<Source
language="jsx"
dark
format
code={dedent`
import Container from '@oxygen-ui/react/Container';\n
function Demo() {
return (
<Container>
{/* Content */}
</Container>
);
}`}
/>
46 changes: 46 additions & 0 deletions packages/react/src/components/Container/Container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import MuiContainer, {ContainerProps as MuiContainerProps} from '@mui/material/Container';
import clsx from 'clsx';
import {ElementType, FC, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';
import './container.scss';

export type ContainerProps<C extends ElementType = ElementType> = {
component?: C;
} & Omit<MuiContainerProps<C>, 'component'>;

const COMPONENT_NAME: string = 'Container';

const Container: FC<ContainerProps> & WithWrapperProps = <C extends ElementType>(
props: ContainerProps<C>,
): ReactElement => {
const {className, ...rest} = props;

const classes: string = clsx('oxygen-container', className);

return <MuiContainer className={classes} {...rest} />;
};

Container.displayName = composeComponentDisplayName(COMPONENT_NAME);
Container.muiName = COMPONENT_NAME;
Container.defaultProps = {};

export default Container;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {render} from '@unit-testing';
import Container from '../Container';

describe('Container', () => {
it('should render successfully', () => {
const {baseElement} = render(<Container />);
expect(baseElement).toBeTruthy();
});

it('should match the snapshot', () => {
const {baseElement} = render(<Container />);
expect(baseElement).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Container should match the snapshot 1`] = `
<body>
<div>
<div
class="MuiContainer-root MuiContainer-maxWidthLg oxygen-container css-1oqqzyl-MuiContainer-root"
/>
</div>
</body>
`;
21 changes: 21 additions & 0 deletions packages/react/src/components/Container/container.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

.oxygen-container {
/* Add Styles */
}
20 changes: 20 additions & 0 deletions packages/react/src/components/Container/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export {default} from './Container';
export type {ContainerProps} from './Container';
3 changes: 3 additions & 0 deletions packages/react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export * from './Button';
export {default as ColorModeToggle} from './ColorModeToggle';
export * from './ColorModeToggle';

export {default as Container} from './Container';
export * from './Container';

export {default as Divider} from './Divider';
export * from './Divider';

Expand Down