-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): add ActionCard component
- Loading branch information
Showing
8 changed files
with
271 additions
and
2 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/react/.storybook/static/assets/images/action-card-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/react/src/components/ActionCard/ActionCard.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" />} | ||
/> | ||
); | ||
}`} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
48 changes: 48 additions & 0 deletions
48
packages/react/src/components/ActionCard/__tests__/ActionCard.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/react/src/components/ActionCard/__tests__/__snapshots__/ActionCard.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |