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 Chip component #33

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 @@ -38,6 +38,7 @@ export type Stories =
| 'Header'
| 'Box'
| 'Button'
| 'Chip'
| 'ColorModeToggle'
| 'Colors'
| 'Divider'
Expand Down Expand Up @@ -112,6 +113,9 @@ const StoryConfig: StorybookConfig = {
UserDropdownMenu: {
hierarchy: `${StorybookCategories.Navigation}/User Dropdown Menu`,
},
Chip: {
hierarchy: `${StorybookCategories.DataDisplay}/Chip`,
},
ColorModeToggle: {
hierarchy: `${StorybookCategories.Theme}/Color Mode Toggle`,
},
Expand Down
52 changes: 52 additions & 0 deletions packages/react/src/components/Chip/Chip.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';
import Chip from './Chip.tsx';

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

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

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

# Chip

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

## Overview

Chips allow users to enter information, make selections, filter content, or trigger actions.

While included here as a standalone component, the most common use will be in some form of input, so some of the behavior demonstrated here is not shown in context.

<Canvas>
<Story name="Overview" args={{label: 'Chip Filled'}}>
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

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

<Source
language="jsx"
dark
format
code={dedent`
import Chip from '@oxygen-ui/react/Chip';\n
function Demo() {
return (
<Chip label="Chip Filled" />
);
}`}
/>
44 changes: 44 additions & 0 deletions packages/react/src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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 MuiChip, {ChipProps as MuiChipProps} from '@mui/material/Chip';
import clsx from 'clsx';
import {ElementType, FC, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';
import './chip.scss';

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

const COMPONENT_NAME: string = 'Chip';

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

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

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

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

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

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

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

exports[`Chip should match the snapshot 1`] = `
<body>
<div>
<div
class="MuiChip-root MuiChip-filled MuiChip-sizeMedium MuiChip-colorDefault MuiChip-filledDefault oxygen-chip css-1cbo6kg-MuiChip-root"
>
<span
class="MuiChip-label MuiChip-labelMedium css-6od3lo-MuiChip-label"
/>
</div>
</div>
</body>
`;
21 changes: 21 additions & 0 deletions packages/react/src/components/Chip/chip.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-chip {
/* Add Styles */
}
20 changes: 20 additions & 0 deletions packages/react/src/components/Chip/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 './Chip';
export type {ChipProps} from './Chip';
3 changes: 3 additions & 0 deletions packages/react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export * from './Box';
export {default as Button} from './Button';
export * from './Button';

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

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

Expand Down