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 Box component #13

Merged
merged 5 commits into from
Feb 13, 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 @@ -32,6 +32,7 @@ enum StorybookCategories {

export type Stories =
| 'AppBar'
| 'Box'
| 'Button'
| 'ColorModeToggle'
| 'Colors'
Expand Down Expand Up @@ -79,6 +80,9 @@ const StoryConfig: StorybookConfig = {
},
hierarchy: `${StorybookCategories.Surfaces}/AppBar`,
},
Box: {
hierarchy: `${StorybookCategories.Layout}/Box`,
},
Button: {
hierarchy: `${StorybookCategories.Inputs}/Button`,
},
Expand Down
73 changes: 73 additions & 0 deletions packages/react/src/components/Box/Box.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';
import Box from './Box.tsx';

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

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

export const Template = args => <Box {...args} />;

# Box

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

## Overview

The `Box` component serves as a wrapper component for most of the CSS utility needs.

<Canvas>
<Story
name="Overview"
args={{
sx: {
width: 300,
height: 300,
backgroundColor: 'primary.dark',
'&:hover': {
backgroundColor: 'primary.main',
opacity: [0.9, 0.8, 0.7],
},
},
}}
>
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

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

<Source
language="jsx"
dark
format
code={dedent`
import Box from '@oxygen-ui/react/Box';\n
function Demo() {
return (
<Box
sx={{
width: 300,
height: 300,
backgroundColor: 'primary.dark',
'&:hover': {
backgroundColor: 'primary.main',
opacity: [0.9, 0.8, 0.7],
},
}}
/>
);
}`}
/>
41 changes: 41 additions & 0 deletions packages/react/src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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 MuiBox, {BoxProps as MuiBoxProps} from '@mui/material/Box';
import clsx from 'clsx';
import {FC, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';

export type BoxProps = MuiBoxProps;

const COMPONENT_NAME: string = 'Box';

const Box: FC<BoxProps> & WithWrapperProps = (props: BoxProps): ReactElement => {
const {className, ...rest} = props;

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

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

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

export default Box;
32 changes: 32 additions & 0 deletions packages/react/src/components/Box/__tests__/Box.test.tsx
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 Box from '../Box';

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

it('should match the snapshot', () => {
const {baseElement} = render(<Box />);
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[`Box should match the snapshot 1`] = `
<body>
<div>
<div
class="oxygen-box MuiBox-root css-0"
/>
</div>
</body>
`;
19 changes: 19 additions & 0 deletions packages/react/src/components/Box/box.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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-box {}
20 changes: 20 additions & 0 deletions packages/react/src/components/Box/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 './Box';
export type {BoxProps} from './Box';
2 changes: 1 addition & 1 deletion packages/react/src/components/ListItemIcon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
*/

export {default} from './ListItemIcon';
export type {ListItemButtonProps} from './ListItemIcon';
export type {ListItemIconProps} from './ListItemIcon';
18 changes: 18 additions & 0 deletions packages/react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
export {default as AppBar} from './AppBar';
export * from './AppBar';

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

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

Expand All @@ -31,6 +34,21 @@ export * from './Grid';
export {default as Link} from './Link';
export * from './Link';

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

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

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

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

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

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

Expand Down
1 change: 0 additions & 1 deletion packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export {
ToggleButton,
ToggleButtonGroup,
IconButton,
Box,
Dialog,
DialogTitle,
DialogContent,
Expand Down