Skip to content

Commit

Permalink
Merge pull request #23 from savindi7/feat-add-list-item-avatar
Browse files Browse the repository at this point in the history
feat(react): add `ListItemAvatar` component
  • Loading branch information
savindi7 authored Feb 14, 2023
2 parents 8e5d523 + 412c4a4 commit 175c1de
Show file tree
Hide file tree
Showing 7 changed files with 199 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 @@ -48,6 +48,7 @@ export type Stories =
| 'Link'
| 'List'
| 'ListItem'
| 'ListItemAvatar'
| 'ListItemButton'
| 'ListItemIcon'
| 'ListItemText'
Expand Down Expand Up @@ -145,6 +146,9 @@ const StoryConfig: StorybookConfig = {
ListItem: {
hierarchy: `${StorybookCategories.DataDisplay}/List Item`,
},
ListItemAvatar: {
hierarchy: `${StorybookCategories.DataDisplay}/List Item Avatar`,
},
ListItemButton: {
hierarchy: `${StorybookCategories.DataDisplay}/List Item Button`,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 ListItemAvatar from './ListItemAvatar.tsx';
import Avatar from '../Avatar';

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

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

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

# List Item Avatar

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

## Overview

`ListItemAvatar` is a wrapper to apply List styles to an Avatar.

<Canvas>
<Story name="Overview" args={{children: <Avatar>U</Avatar>}}>
{Template.bind({})}
</Story>
</Canvas>

## Props

<ArgsTable story="Overview" />

## Usage

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

<Source
language="jsx"
dark
format
code={dedent`
import ListItemAvatar from '@oxygen-ui/react/ListItemAvatar';\n
function Demo() {
return (
<ListItemAvatar>
{/* List Item Avatar Content */}
</ListItemAvatar>
);
}`}
/>
42 changes: 42 additions & 0 deletions packages/react/src/components/ListItemAvatar/ListItemAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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 MuiListItemAvatar, {ListItemAvatarProps as MuiListItemAvatarProps} from '@mui/material/ListItemAvatar';
import clsx from 'clsx';
import {FC, ReactElement} from 'react';
import {WithWrapperProps} from '../../models';
import {composeComponentDisplayName} from '../../utils';
import './list-item-avatar.scss';

export type ListItemAvatarProps = MuiListItemAvatarProps;

const COMPONENT_NAME: string = 'ListItemAvatar';

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

const classes: string = clsx('oxygen-list-item-avatar', className);

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

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

export default ListItemAvatar;
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 {render} from '@unit-testing';
import Avatar from '../../Avatar';
import ListItemAvatar from '../ListItemAvatar';

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

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

exports[`ListItemAvatar should match the snapshot 1`] = `
<body>
<div>
<div
class="MuiListItemAvatar-root oxygen-list-item-avatar css-1e9lk82-MuiListItemAvatar-root"
>
<div
class="MuiAvatar-root MuiAvatar-circular MuiAvatar-colorDefault oxygen-ui-avatar css-woe6xp-MuiAvatar-root"
>
U
</div>
</div>
</div>
</body>
`;
20 changes: 20 additions & 0 deletions packages/react/src/components/ListItemAvatar/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 './ListItemAvatar';
export type {ListItemAvatarProps} from './ListItemAvatar';
21 changes: 21 additions & 0 deletions packages/react/src/components/ListItemAvatar/list-item-avatar.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-list-item-avatar {
/* Add Styles */
}

0 comments on commit 175c1de

Please sign in to comment.