Skip to content

Commit

Permalink
Merge pull request #32 from brionmario/feat-container
Browse files Browse the repository at this point in the history
feat(react): add `Container` component
  • Loading branch information
brionmario authored Feb 15, 2023
2 parents c447a09 + 516db1e commit edbae1a
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react/.storybook/story-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type Stories =
| 'Chip'
| 'ColorModeToggle'
| 'Colors'
| 'Container'
| 'Divider'
| 'Drawer'
| 'Grid'
Expand Down Expand Up @@ -122,6 +123,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 @@ -34,6 +34,9 @@ export * from './Chip';
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

0 comments on commit edbae1a

Please sign in to comment.