forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-core-card): added PatternFly 4 Card Component (patternfly#458
) affects: @patternfly/react-core, @patternfly/react-docs Added the Card Component from here: https://pf-next.com/components/Card/examples/ ISSUES CLOSED: patternfly#386
- Loading branch information
1 parent
67ceb0e
commit a9af02d
Showing
21 changed files
with
383 additions
and
0 deletions.
There are no files selected for viewing
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,9 @@ | ||
import { SFC, HTMLProps, ReactType } from 'react'; | ||
|
||
export interface CardProps extends HTMLProps<HTMLDivElement> { | ||
component?: ReactType<CardProps>; | ||
} | ||
|
||
declare const Card: SFC<CardProps>; | ||
|
||
export default 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,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/patternfly-next/components/Card/styles.css'; | ||
import { componentShape } from '../../internal/componentShape'; | ||
|
||
const propTypes = { | ||
children: PropTypes.any, | ||
className: PropTypes.string, | ||
component: componentShape | ||
}; | ||
|
||
const defaultProps = { | ||
children: null, | ||
className: '', | ||
component: 'article' | ||
}; | ||
|
||
const Card = ({ children, className, component: Component, ...props }) => ( | ||
<Component className={css(styles.card, className)} {...props}> | ||
{children} | ||
</Component> | ||
); | ||
|
||
Card.propTypes = propTypes; | ||
Card.defaultProps = defaultProps; | ||
|
||
export default 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,31 @@ | ||
import React from 'react'; | ||
import Card from './Card'; | ||
import { shallow } from 'enzyme'; | ||
|
||
test('renders with PatternFly Core styles', () => { | ||
const view = shallow(<Card />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('className is added to the root element', () => { | ||
const view = shallow(<Card className="extra-class" />); | ||
expect(view.prop('className')).toMatchSnapshot(); | ||
}); | ||
|
||
test('extra props are spread to the root element', () => { | ||
const testId = 'card'; | ||
const view = shallow(<Card data-testid={testId} />); | ||
expect(view.prop('data-testid')).toBe(testId); | ||
}); | ||
|
||
test('allows passing in a string as the component', () => { | ||
const component = 'section'; | ||
const view = shallow(<Card component={component} />); | ||
expect(view.type()).toBe(component); | ||
}); | ||
|
||
test('allows passing in a React Component as the component', () => { | ||
const Component = () => null; | ||
const view = shallow(<Card component={Component} />); | ||
expect(view.type()).toBe(Component); | ||
}); |
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,9 @@ | ||
import { SFC, HTMLProps, ReactType } from 'react'; | ||
|
||
export interface CardBodyProps extends HTMLProps<HTMLDivElement> { | ||
component?: ReactType<CardBodyProps>; | ||
} | ||
|
||
declare const CardBody: SFC<CardBodyProps>; | ||
|
||
export default CardBody; |
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,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/patternfly-next/components/Card/styles.css'; | ||
import { componentShape } from '../../internal/componentShape'; | ||
|
||
const propTypes = { | ||
children: PropTypes.any, | ||
className: PropTypes.string, | ||
component: componentShape | ||
}; | ||
|
||
const defaultProps = { | ||
children: null, | ||
className: '', | ||
component: 'div' | ||
}; | ||
|
||
const CardBody = ({ children, className, component: Component, ...props }) => ( | ||
<Component className={css(styles.cardBody, className)} {...props}> | ||
{children} | ||
</Component> | ||
); | ||
|
||
CardBody.propTypes = propTypes; | ||
CardBody.defaultProps = defaultProps; | ||
|
||
export default CardBody; |
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,31 @@ | ||
import React from 'react'; | ||
import CardBody from './CardBody'; | ||
import { shallow } from 'enzyme'; | ||
|
||
test('renders with PatternFly Core styles', () => { | ||
const view = shallow(<CardBody />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('className is added to the root element', () => { | ||
const view = shallow(<CardBody className="extra-class" />); | ||
expect(view.prop('className')).toMatchSnapshot(); | ||
}); | ||
|
||
test('extra props are spread to the root element', () => { | ||
const testId = 'card-body'; | ||
const view = shallow(<CardBody data-testid={testId} />); | ||
expect(view.prop('data-testid')).toBe(testId); | ||
}); | ||
|
||
test('allows passing in a string as the component', () => { | ||
const component = 'section'; | ||
const view = shallow(<CardBody component={component} />); | ||
expect(view.type()).toBe(component); | ||
}); | ||
|
||
test('allows passing in a React Component as the component', () => { | ||
const Component = () => null; | ||
const view = shallow(<CardBody component={Component} />); | ||
expect(view.type()).toBe(Component); | ||
}); |
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,9 @@ | ||
import { SFC, HTMLProps, ReactType } from 'react'; | ||
|
||
export interface CardFooterProps extends HTMLProps<HTMLDivElement> { | ||
component?: ReactType<CardFooterProps>; | ||
} | ||
|
||
declare const CardFooter: SFC<CardFooterProps>; | ||
|
||
export default CardFooter; |
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,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/patternfly-next/components/Card/styles.css'; | ||
import { componentShape } from '../../internal/componentShape'; | ||
|
||
const propTypes = { | ||
children: PropTypes.any, | ||
className: PropTypes.string, | ||
component: componentShape | ||
}; | ||
|
||
const defaultProps = { | ||
children: null, | ||
className: '', | ||
component: 'div' | ||
}; | ||
|
||
const CardFooter = ({ | ||
children, | ||
className, | ||
component: Component, | ||
...props | ||
}) => ( | ||
<Component className={css(styles.cardFooter, className)} {...props}> | ||
{children} | ||
</Component> | ||
); | ||
|
||
CardFooter.propTypes = propTypes; | ||
CardFooter.defaultProps = defaultProps; | ||
|
||
export default CardFooter; |
31 changes: 31 additions & 0 deletions
31
packages/react-core/src/components/Card/CardFooter.test.js
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,31 @@ | ||
import React from 'react'; | ||
import CardFooter from './CardFooter'; | ||
import { shallow } from 'enzyme'; | ||
|
||
test('renders with PatternFly Core styles', () => { | ||
const view = shallow(<CardFooter />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('className is added to the root element', () => { | ||
const view = shallow(<CardFooter className="extra-class" />); | ||
expect(view.prop('className')).toMatchSnapshot(); | ||
}); | ||
|
||
test('extra props are spread to the root element', () => { | ||
const testId = 'card-footer'; | ||
const view = shallow(<CardFooter data-testid={testId} />); | ||
expect(view.prop('data-testid')).toBe(testId); | ||
}); | ||
|
||
test('allows passing in a string as the component', () => { | ||
const component = 'div'; | ||
const view = shallow(<CardFooter component={component} />); | ||
expect(view.type()).toBe(component); | ||
}); | ||
|
||
test('allows passing in a React Component as the component', () => { | ||
const Component = () => null; | ||
const view = shallow(<CardFooter component={Component} />); | ||
expect(view.type()).toBe(Component); | ||
}); |
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,9 @@ | ||
import { SFC, HTMLProps, ReactType } from 'react'; | ||
|
||
export interface CardHeaderProps extends HTMLProps<HTMLDivElement> { | ||
component?: ReactType<CardHeaderProps>; | ||
} | ||
|
||
declare const CardHeader: SFC<CardHeaderProps>; | ||
|
||
export default CardHeader; |
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,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/patternfly-next/components/Card/styles.css'; | ||
import { componentShape } from '../../internal/componentShape'; | ||
|
||
const propTypes = { | ||
children: PropTypes.any, | ||
className: PropTypes.string, | ||
component: componentShape | ||
}; | ||
|
||
const defaultProps = { | ||
children: null, | ||
className: '', | ||
component: 'div' | ||
}; | ||
|
||
const CardHeader = ({ | ||
children, | ||
className, | ||
component: Component, | ||
...props | ||
}) => ( | ||
<Component className={css(styles.cardHeader, className)} {...props}> | ||
{children} | ||
</Component> | ||
); | ||
|
||
CardHeader.propTypes = propTypes; | ||
CardHeader.defaultProps = defaultProps; | ||
|
||
export default CardHeader; |
31 changes: 31 additions & 0 deletions
31
packages/react-core/src/components/Card/CardHeader.test.js
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,31 @@ | ||
import React from 'react'; | ||
import CardHeader from './CardHeader'; | ||
import { shallow } from 'enzyme'; | ||
|
||
test('renders with PatternFly Core styles', () => { | ||
const view = shallow(<CardHeader />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('className is added to the root element', () => { | ||
const view = shallow(<CardHeader className="extra-class" />); | ||
expect(view.prop('className')).toMatchSnapshot(); | ||
}); | ||
|
||
test('extra props are spread to the root element', () => { | ||
const testId = 'card-footer'; | ||
const view = shallow(<CardHeader data-testid={testId} />); | ||
expect(view.prop('data-testid')).toBe(testId); | ||
}); | ||
|
||
test('allows passing in a string as the component', () => { | ||
const component = 'div'; | ||
const view = shallow(<CardHeader component={component} />); | ||
expect(view.type()).toBe(component); | ||
}); | ||
|
||
test('allows passing in a React Component as the component', () => { | ||
const Component = () => null; | ||
const view = shallow(<CardHeader component={Component} />); | ||
expect(view.type()).toBe(Component); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/react-core/src/components/Card/__snapshots__/Card.test.js.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,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`className is added to the root element 1`] = `"pf-c-card extra-class"`; | ||
|
||
exports[`renders with PatternFly Core styles 1`] = ` | ||
.pf-c-card { | ||
display: flex; | ||
flex-direction: column; | ||
background-color: #ffffff; | ||
box-shadow: 0 0.0625rem 0.125rem 0 rgba(3, 3, 3, 0.2); | ||
} | ||
<article | ||
className="pf-c-card" | ||
/> | ||
`; |
14 changes: 14 additions & 0 deletions
14
packages/react-core/src/components/Card/__snapshots__/CardBody.test.js.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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`className is added to the root element 1`] = `"pf-c-card__body extra-class"`; | ||
|
||
exports[`renders with PatternFly Core styles 1`] = ` | ||
.pf-c-card__body { | ||
display: block; | ||
padding: 2rem 2rem 2rem 2rem; | ||
} | ||
<div | ||
className="pf-c-card__body" | ||
/> | ||
`; |
14 changes: 14 additions & 0 deletions
14
packages/react-core/src/components/Card/__snapshots__/CardFooter.test.js.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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`className is added to the root element 1`] = `"pf-c-card__footer extra-class"`; | ||
|
||
exports[`renders with PatternFly Core styles 1`] = ` | ||
.pf-c-card__footer { | ||
display: block; | ||
padding: 2rem 2rem 2rem 2rem; | ||
} | ||
<div | ||
className="pf-c-card__footer" | ||
/> | ||
`; |
14 changes: 14 additions & 0 deletions
14
packages/react-core/src/components/Card/__snapshots__/CardHeader.test.js.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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`className is added to the root element 1`] = `"pf-c-card__header extra-class"`; | ||
|
||
exports[`renders with PatternFly Core styles 1`] = ` | ||
.pf-c-card__header { | ||
display: block; | ||
padding: 2rem 2rem 2rem 2rem; | ||
} | ||
<div | ||
className="pf-c-card__header" | ||
/> | ||
`; |
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,4 @@ | ||
export { default as Card, CardProps } from './Card'; | ||
export { default as CardBody, CardBodyProps } from './CardBody'; | ||
export { default as CardFooter, CardFooterProps } from './CardFooter'; | ||
export { default as CardHeader, CardHeaderProps } from './CardHeader'; |
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,4 @@ | ||
export { default as Card } from './Card'; | ||
export { default as CardBody } from './CardBody'; | ||
export { default as CardFooter } from './CardFooter'; | ||
export { default as CardHeader } from './CardHeader'; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './Badge'; | ||
export * from './Button'; | ||
export * from './Card'; | ||
export * from './Title'; | ||
export * from './Alert'; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './Badge'; | ||
export * from './Button'; | ||
export * from './Card'; | ||
export * from './Title'; | ||
export * from './Alert'; |
Oops, something went wrong.