-
Notifications
You must be signed in to change notification settings - Fork 30
add ServiceCard component #200
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6f60bd3
add ServiceCard component
InsaneZein 4ce6b3a
fix props
InsaneZein a941a0d
remove comments and unused imports
InsaneZein 8e545e2
update footer prop
InsaneZein c9d1e10
fix styling
InsaneZein d183eb0
use right spacing var
InsaneZein 5f42d55
add Service Card with Gallery example
InsaneZein 2b74087
add service-card tests
InsaneZein e8d285f
fix icon issue
InsaneZein afac096
update snapshot
InsaneZein b8723cc
fix example
InsaneZein 9541df0
remove default button props
InsaneZein 6899a73
remove unused import
InsaneZein 8b0207c
update snapshot
InsaneZein 241e44f
update props description
InsaneZein 948231b
Update packages/module/patternfly-docs/content/extensions/component-g…
fhlavac eb895bb
Update packages/module/patternfly-docs/content/extensions/component-g…
fhlavac a6c3ae1
Update packages/module/patternfly-docs/content/extensions/component-g…
fhlavac c119f00
remove unused prop
InsaneZein 92ec3db
Merge branch 'add-servicecard' of github.com:patternfly/react-compone…
InsaneZein 49d6e4a
fix test
InsaneZein d972e5e
add ouia-ids
InsaneZein 6062897
update snapshot
InsaneZein c4bcc8b
add cypress tests
InsaneZein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| import React from 'react'; | ||
| import ServiceCard from '../../packages/module/dist/dynamic/ServiceCard'; | ||
| import { Button, ButtonVariant } from '@patternfly/react-core'; | ||
|
|
||
| describe('ServiceCard', () => { | ||
| it('renders ServiceCard', () => { | ||
| cy.mount( | ||
| <ServiceCard | ||
| title='Example' | ||
| subtitle='A basic example' | ||
| description='This is a basic ServiceCard Example' | ||
| icon={<img src="/" alt="content-header-icon" />} | ||
| helperText='Here is helper text' | ||
| ouiaId='Example' | ||
| />) | ||
| cy.get('[data-ouia-component-id="Example-card"]').should('exist'); | ||
| }); | ||
| it('renders custom footer', () => { | ||
| cy.mount( | ||
| <ServiceCard | ||
| title='Example' | ||
| subtitle='A basic example' | ||
| description='This is a basic ServiceCard Example' | ||
| icon={<img src="/" alt="content-header-icon" />} | ||
| helperText='Here is helper text' | ||
| ouiaId='Example' | ||
| footer={<> | ||
| <Button | ||
| variant={ButtonVariant.secondary} | ||
| isInline | ||
| className='pf-v5-u-pr-md' | ||
| component="a" | ||
| href='www.google.com'> | ||
| Launch | ||
| </Button> | ||
| <Button | ||
| variant={ButtonVariant.link} | ||
| component="a" | ||
| isInline | ||
| href='www.google.com' | ||
| > | ||
| Learn More | ||
| </Button></> | ||
| } | ||
| />) | ||
| cy.get('[data-ouia-component-id="Example-footer"]').should('exist'); | ||
| }) | ||
| }); |
33 changes: 33 additions & 0 deletions
33
...ly-docs/content/extensions/component-groups/examples/ServiceCard/ServiceCard.md
This file contains hidden or 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,33 @@ | ||
| --- | ||
| section: extensions | ||
| subsection: Component groups | ||
| id: Service card | ||
| source: react | ||
| propComponents: ['ServiceCard'] | ||
| sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/ServiceCard/ServiceCard.md | ||
| --- | ||
|
|
||
| import ServiceCard from "@patternfly/react-component-groups/dist/dynamic/ServiceCard"; | ||
| import { EllipsisVIcon } from '@patternfly/react-icons'; | ||
| import contentHeaderIcon from '../../assets/icons/content-header-icon.svg' | ||
|
|
||
| The **service card** component displays a card representing a service with an icon, title, description, and an optional customized footer | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Service Card | ||
|
|
||
| This shows a basic service card with an `icon`, `title`, `description`, and optional footer passed in. | ||
|
|
||
| ```js file="./ServiceCardExample.tsx" | ||
|
|
||
| ``` | ||
|
|
||
| ### Service Card with Gallery example | ||
|
|
||
| This shows how cards can look side by side in a [gallery layout](/layouts/gallery). | ||
|
|
||
| ```js file="./ServiceCardGalleryExample.tsx" | ||
|
|
||
| ``` | ||
|
|
33 changes: 33 additions & 0 deletions
33
...nfly-docs/content/extensions/component-groups/examples/ServiceCard/ServiceCardExample.tsx
This file contains hidden or 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,33 @@ | ||
| import React from 'react'; | ||
| import ServiceCard from "@patternfly/react-component-groups/dist/dynamic/ServiceCard"; | ||
| import contentHeaderIcon from '../../assets/icons/content-header-icon.svg'; | ||
| import { Button, ButtonVariant } from '@patternfly/react-core'; | ||
|
|
||
|
|
||
| export const BasicExample: React.FunctionComponent = () => ( | ||
| <ServiceCard | ||
| title='Example' | ||
| subtitle='A basic example' | ||
| description='This is a basic ServiceCard Example' | ||
| icon={<img src={contentHeaderIcon} alt="content-header-icon" />} | ||
| helperText='Here is helper text' | ||
| footer={<> | ||
| <Button | ||
| variant={ButtonVariant.secondary} | ||
| isInline | ||
| className='pf-v5-u-pr-md' | ||
| component="a" | ||
| href='www.google.com'> | ||
| Launch | ||
| </Button> | ||
| <Button | ||
| variant={ButtonVariant.link} | ||
| component="a" | ||
| isInline | ||
| href='www.google.com' | ||
| > | ||
| Learn More | ||
| </Button></> | ||
| } | ||
| /> | ||
| ); |
47 changes: 47 additions & 0 deletions
47
...cs/content/extensions/component-groups/examples/ServiceCard/ServiceCardGalleryExample.tsx
This file contains hidden or 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,47 @@ | ||
| import React from 'react'; | ||
| import ServiceCard from "@patternfly/react-component-groups/dist/dynamic/ServiceCard"; | ||
| import { Gallery } from '@patternfly/react-core/dist/dynamic/layouts/Gallery'; | ||
| import { GalleryItem } from '@patternfly/react-core/dist/dynamic/layouts/Gallery'; | ||
| import { Button, ButtonVariant } from '@patternfly/react-core'; | ||
| import contentHeaderIcon from '../../assets/icons/content-header-icon.svg'; | ||
|
|
||
| export const ServiceCardGalleryExample: React.FunctionComponent = () => ( | ||
| <Gallery hasGutter minWidths={{ default: '330px' }}> | ||
| <GalleryItem> | ||
| <ServiceCard | ||
| title='Example1' | ||
| subtitle='A basic example' | ||
| description='This is a basic ServiceCard Example' | ||
| icon={<img src={contentHeaderIcon} alt="content-header-icon" />} | ||
| helperText='' | ||
|
|
||
| /> | ||
| </GalleryItem> | ||
| <GalleryItem> | ||
| <ServiceCard | ||
| title='Example2' | ||
| subtitle='A second example' | ||
| description='This is another basic ServiceCard Example' | ||
| icon={<img src={contentHeaderIcon} alt="content-header-icon" />} | ||
| helperText='' | ||
| footer={<> | ||
| <Button | ||
| variant={ButtonVariant.secondary} | ||
| isInline | ||
| component="a" | ||
| href='www.google.com'> | ||
| Launch | ||
| </Button> | ||
| <Button | ||
| variant={ButtonVariant.link} | ||
| component="a" | ||
| isInline | ||
| href='www.google.com' | ||
| > | ||
| Learn More | ||
| </Button></> | ||
| } | ||
| /> | ||
| </GalleryItem> | ||
| </Gallery> | ||
| ) |
This file contains hidden or 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,15 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import ServiceCard from './ServiceCard'; | ||
|
|
||
| describe('LogSnippet component', () => { | ||
| it('should render LogSnippet component', () => { | ||
| expect(render(<ServiceCard | ||
| title='Example' | ||
| subtitle='A basic example' | ||
| description='This is a basic ServiceCard Example' | ||
| icon='/' | ||
| helperText='' | ||
| />)).toMatchSnapshot(); | ||
| }); | ||
| }); |
This file contains hidden or 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,71 @@ | ||
| import React from 'react'; | ||
| import { Card, CardBody, CardFooter, CardHeader, Text, TextContent, TextVariants } from '@patternfly/react-core'; | ||
| import { HelperText } from '@patternfly/react-core/dist/dynamic/components/HelperText'; | ||
| import { HelperTextItem } from '@patternfly/react-core/dist/dynamic/components/HelperText'; | ||
| import { createUseStyles } from 'react-jss'; | ||
|
|
||
| export interface ServiceCardProps { | ||
| /** Service card title */ | ||
| title: string; | ||
| /** Service card subtitle */ | ||
| subtitle: string; | ||
| /** Service card description */ | ||
| description: string; | ||
| /** Service card icon */ | ||
| icon: React.ReactNode; | ||
| /** Optional Service card helper text*/ | ||
| helperText?: string; | ||
| /** Optional footer */ | ||
| footer?: React.ReactElement | null; | ||
| /** Optional custom OUIA ID */ | ||
| ouiaId?: string | number; | ||
| } | ||
|
|
||
| const useStyles = createUseStyles({ | ||
| card: { | ||
| height: 'var(--pf-v5-u-h-100)' | ||
| }, | ||
| image: { | ||
| marginRight: 'var(--pf-v5-global--spacer--md)', | ||
| width: 48 | ||
| } | ||
| }); | ||
|
|
||
| const ServiceCard: React.FunctionComponent<ServiceCardProps> = ({ | ||
| title, | ||
| subtitle, | ||
| description, | ||
| icon, | ||
| helperText, | ||
| footer = null, | ||
| ouiaId='ServiceCard' | ||
| }: ServiceCardProps) => { | ||
| const classes = useStyles(); | ||
|
|
||
| return ( | ||
| <Card className={classes.card} ouiaId={`${ouiaId}-card`}> | ||
| <CardHeader> | ||
| <div className={classes.image}> | ||
| {icon} | ||
| </div> | ||
| <TextContent> | ||
| <Text component={TextVariants.h2} ouiaId={`${ouiaId}-title`}>{title}</Text> | ||
| {subtitle} | ||
| </TextContent> | ||
| </CardHeader> | ||
| <CardBody data-ouia-component-id={`${ouiaId}-description`}>{description}</CardBody> | ||
| <CardFooter data-ouia-component-id={`${ouiaId}-footer`}> | ||
| { helperText ? | ||
| ( <HelperText data-ouia-component-id={`${ouiaId}-helper-text`}> | ||
| <HelperTextItem variant="indeterminate" className="pf-v5-u-mb-lg"> | ||
| {helperText} | ||
| </HelperTextItem> | ||
| </HelperText>) : null | ||
| } | ||
| { footer } | ||
| </CardFooter> | ||
| </Card> | ||
| ) | ||
| } | ||
|
|
||
| export default ServiceCard; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.