Skip to content

Commit

Permalink
Merge pull request #36 from savindi7/feat-badge
Browse files Browse the repository at this point in the history
feat(react): add `Badge` component
  • Loading branch information
savindi7 authored Feb 16, 2023
2 parents 9747324 + 2594f64 commit ba3f05e
Show file tree
Hide file tree
Showing 7 changed files with 178 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 @@ -34,6 +34,7 @@ export type Stories =
| 'ActionCard'
| 'AppBar'
| 'Avatar'
| 'Badge'
| 'Box'
| 'Button'
| 'Card'
Expand Down Expand Up @@ -99,6 +100,9 @@ const StoryConfig: StorybookConfig = {
Avatar: {
hierarchy: `${StorybookCategories.DataDisplay}/Avatar`,
},
Badge: {
hierarchy: `${StorybookCategories.DataDisplay}/Badge`,
},
Box: {
hierarchy: `${StorybookCategories.Layout}/Box`,
},
Expand Down
45 changes: 45 additions & 0 deletions packages/react/src/components/Badge/Badge.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';
import {withDesign} from '../../../.storybook/utils.ts';
import Badge from './Badge.tsx';

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

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

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

# Badge

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

## Overview

Generate a badge for elements.

<Canvas>
<Story name="Overview" args={{badgeContent:1, color:"primary", children: 'Element'}}>
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

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

<Source
language="jsx"
dark
format
code={dedent`import Badge from '@oxygen-ui/react/Badge';\n`}
/>
41 changes: 41 additions & 0 deletions packages/react/src/components/Badge/Badge.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 MuiBadge, {BadgeProps as MuiBadgeProps} from '@mui/material/Badge';
import clsx from 'clsx';
import {FC, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';
import './badge.scss';

export type BadgeProps = MuiBadgeProps;

const COMPONENT_NAME: string = 'Badge';

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

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

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

Badge.displayName = composeComponentDisplayName(COMPONENT_NAME);
Badge.muiName = COMPONENT_NAME;

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

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

it('should match the snapshot', () => {
const {baseElement} = render(<Badge />);
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[`Badge should match the snapshot 1`] = `
<body>
<div>
<span
class="MuiBadge-root oxygen-badge MuiBadge-root css-1c32n2y-MuiBadge-root"
>
<span
class="MuiBadge-badge MuiBadge-standard MuiBadge-invisible MuiBadge-anchorOriginTopRight MuiBadge-anchorOriginTopRightRectangular MuiBadge-overlapRectangular MuiBadge-badge css-uh1ep6-MuiBadge-badge"
/>
</span>
</div>
</body>
`;
21 changes: 21 additions & 0 deletions packages/react/src/components/Badge/badge.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-badge {
/** Add Styles */
}
20 changes: 20 additions & 0 deletions packages/react/src/components/Badge/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 './Badge';
export type {BadgeProps} from './Badge';

0 comments on commit ba3f05e

Please sign in to comment.