Skip to content

Commit

Permalink
feat(react): add ActionCard component
Browse files Browse the repository at this point in the history
  • Loading branch information
thivi committed Feb 13, 2023
1 parent e34dc02 commit 5201042
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions packages/react/.storybook/story-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum StorybookCategories {
}

export type Stories =
| 'ActionCard'
| 'AppBar'
| 'Avatar'
| 'ButtonDropdownMenu'
Expand Down Expand Up @@ -89,12 +90,15 @@ const StoryConfig: StorybookConfig = {
},
hierarchy: `${StorybookCategories.Navigation}/Header`,
},
ActionCard: {
hierarchy: `${StorybookCategories.Surfaces}/Action Card`,
},
AppBar: {
hierarchy: `${StorybookCategories.Surfaces}/App Bar`,
},
},
Avatar: {
hierarchy: `${StorybookCategories.DataDisplay}/Avatar`,
},
},
Box: {
hierarchy: `${StorybookCategories.Layout}/Box`,
},
Expand Down
61 changes: 61 additions & 0 deletions packages/react/src/components/ActionCard/ActionCard.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {ArgsTable, Source, Story, Canvas, Meta} from '@storybook/addon-docs';
import ActionCard from './ActionCard.tsx';
import dedent from 'ts-dedent';
import StoryConfig from '../../../.storybook/story-config.ts';

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

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

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

# ActionCard

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

## Overview

Action cards can be used in overview pages or dashboards.

<Canvas>
<Story name="Overview" args={{
title: "Secure your account by adding an extra layer of security",
description: "Configure additional authentications to sign in easily or to add an extra layer of security to your account.",
actionText: "Setup MFA",
onActionClick:() => {alert("Action clicked")},
image: <img src="/assets/images/action-card-image.svg" alt="action card" />
}}>
{Template.bind({})}
</Story>
</Canvas>

## Props
<ArgsTable story="Overview" />

## Usage

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

<Source
language="jsx"
dark
format
code={dedent`
import ActionCard from '@oxygen-ui/react/ActionCard';\n
function Demo() {
return (
<ActionCard
title="Secure your account by adding an extra layer of security"
description="Configure additional authentications to sign in easily or to add an extra layer of security to your account."
actionText="Setup MFA"
onActionClick={() => {alert("Action clicked")}}
image={<img src="/assets/images/action-card-image.svg" alt="action card" />}
/>
);
}`}
/>
67 changes: 67 additions & 0 deletions packages/react/src/components/ActionCard/ActionCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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 Card from '@mui/material/Card';
import CardActions from '@mui/material/CardActions';
import CardContent from '@mui/material/CardContent';
import {FC, ReactElement, ReactNode} from 'react';
import Button from '../Button';
import Typography from '../Typography';
import {WithWrapperProps} from '../../models';

export interface ActionCardProps {
actionText: string;
description: string;
image: ReactNode;
onActionClick: () => void;
title: string;
}

const COMPONENT_NAME: string = 'ActionCard';

const ActionCard: FC<ActionCardProps> & WithWrapperProps = (props: ActionCardProps): ReactElement => {
const {image, title, description, actionText, onActionClick} = props;

return (
<Card
sx={{
borderRadius: 'borderRadius.lg',
boxShadow: 'dropShadow.default',
}}
>
<CardContent>
{image}
<Typography variant="subtitle2">{title}</Typography>
<Typography variant="body1" color="secondary.main">
{description}
</Typography>
</CardContent>
<CardActions>
<Button onClick={onActionClick} variant="contained">
{actionText}
</Button>
</CardActions>
</Card>
);
};

ActionCard.displayName = COMPONENT_NAME;
ActionCard.muiName = COMPONENT_NAME;
ActionCard.defaultProps = {};

export default ActionCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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 {ReactElement} from 'react';
import ActionCard from '../ActionCard';

const onActionClick: jest.Mock<any, any> = jest.fn();

const actionCard: ReactElement = (
<ActionCard
title="Secure your account by adding an extra layer of security"
description={
'Configure additional authentications to sign in easily or to ' +
'add an extra layer of security to your account.'
}
actionText="Setup MFA"
onActionClick={onActionClick}
image={<img src="/assets/images/action-card-image.svg" alt="action card" />}
/>
);

describe('ActionCard', () => {
it('should render successfully', () => {
const {baseElement} = render(actionCard);
expect(baseElement).toBeTruthy();
});

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

exports[`ActionCard should match the snapshot 1`] = `
<body>
<div>
<div
class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation1 MuiCard-root css-1ico3yg-MuiPaper-root-MuiCard-root"
>
<div
class="MuiCardContent-root css-46bh2p-MuiCardContent-root"
>
<img
alt="action card"
src="/assets/images/action-card-image.svg"
/>
<h6
class="MuiTypography-root MuiTypography-subtitle2 oxygen-typography css-n98czh-MuiTypography-root"
>
Secure your account by adding an extra layer of security
</h6>
<p
class="MuiTypography-root MuiTypography-body1 oxygen-typography css-167a66v-MuiTypography-root"
>
Configure additional authentications to sign in easily or to add an extra layer of security to your account.
</p>
</div>
<div
class="MuiCardActions-root MuiCardActions-spacing css-1t6e9jv-MuiCardActions-root"
>
<button
class="MuiButtonBase-root MuiButton-root MuiLoadingButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-root MuiLoadingButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium oxygen-button css-1e4ccqm-MuiButtonBase-root-MuiButton-root-MuiLoadingButton-root"
id=":r1:"
tabindex="0"
type="button"
>
Setup MFA
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
</div>
</div>
</div>
</body>
`;
19 changes: 19 additions & 0 deletions packages/react/src/components/ActionCard/action-card.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-action-card {}
20 changes: 20 additions & 0 deletions packages/react/src/components/ActionCard/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 './ActionCard';
export type {ActionCardProps} from './ActionCard';

0 comments on commit 5201042

Please sign in to comment.