Skip to content

Commit a3ea2ba

Browse files
authored
fix(card): add wrapper to image to resize it properly (#3642)
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
1 parent 68b1c59 commit a3ea2ba

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import { CardHeadMain } from './CardHeadMain';
3+
import { shallow } from 'enzyme';
4+
5+
test('renders with PatternFly Core styles', () => {
6+
const view = shallow(<CardHeadMain>text</CardHeadMain>);
7+
expect(view).toMatchSnapshot();
8+
});
9+
10+
test('className is added to the root element', () => {
11+
const view = shallow(<CardHeadMain className="extra-class">text</CardHeadMain>);
12+
expect(view.prop('className')).toMatchSnapshot();
13+
});
14+
15+
test('extra props are spread to the root element', () => {
16+
const testId = 'card-head-main';
17+
const view = shallow(<CardHeadMain data-testid={testId} />);
18+
expect(view.prop('data-testid')).toBe(testId);
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import { css } from '@patternfly/react-styles';
3+
4+
export interface CardHeadMainProps extends React.HTMLProps<HTMLDivElement> {
5+
/** Content rendered inside the Card Head Main */
6+
children?: React.ReactNode;
7+
/** Additional classes added to the Card Head Main */
8+
className?: string;
9+
}
10+
11+
export const CardHeadMain: React.FunctionComponent<CardHeadMainProps> = ({
12+
children = null,
13+
className = '',
14+
...props
15+
}: CardHeadMainProps) => (
16+
<div className={css('pf-c-card__head-main', className)} {...props}>
17+
{children}
18+
</div>
19+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`className is added to the root element 1`] = `"pf-c-card__head-main extra-class"`;
4+
5+
exports[`renders with PatternFly Core styles 1`] = `
6+
<div
7+
className="pf-c-card__head-main"
8+
>
9+
text
10+
</div>
11+
`;

packages/react-core/src/components/Card/examples/Card.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ title: 'Card'
33
section: components
44
cssPrefix: 'pf-c-card'
55
typescript: true
6-
propComponents: ['Card', 'CardHeader', 'CardBody', 'CardFooter']
6+
propComponents: ['Card', 'CardHeadMain', 'CardHeader', 'CardBody', 'CardFooter']
77
---
88

9-
import { Card, CardActions, CardHead, CardHeader, CardBody, CardFooter, Checkbox, DropdownActions } from '@patternfly/react-core';
9+
import { Brand, Card, CardActions, CardHead, CardHeadMain, CardHeader, CardBody, CardFooter, Checkbox, DropdownActions } from '@patternfly/react-core';
1010
import pfLogo from './pfLogo.svg';
1111

1212
## Examples
@@ -25,7 +25,7 @@ SimpleCard = () => (
2525

2626
```js title=With-image-and-actions
2727
import React from 'react';
28-
import { Card, CardHead, CardActions, CardHeader, CardBody, CardFooter, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition, DropdownDirection, KebabToggle, } from '@patternfly/react-core';
28+
import { Brand, Card, CardHead, CardHeadMain, CardActions, CardHeader, CardBody, CardFooter, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition, DropdownDirection, KebabToggle, } from '@patternfly/react-core';
2929
import pfLogo from './pfLogo.svg';
3030

3131
class KebabDropdown extends React.Component {
@@ -75,7 +75,9 @@ class KebabDropdown extends React.Component {
7575
return (
7676
<Card>
7777
<CardHead>
78-
<img src={pfLogo} alt="PatternFly logo" style={{ height: '50px' }}/>
78+
<CardHeadMain>
79+
<Brand src={pfLogo} alt="PatternFly logo" style={{ height: '50px' }}/>
80+
</CardHeadMain>
7981
<CardActions>
8082
<Dropdown
8183
onSelect={this.onSelect}
@@ -262,12 +264,14 @@ class KebabDropdown extends React.Component {
262264

263265
```js title=Only-image-in-the-card-head
264266
import React from 'react';
265-
import { Card, CardBody, CardFooter, CardHead, CardHeader } from '@patternfly/react-core';
267+
import { Brand, Card, CardBody, CardFooter, CardHead, CardHeadMain, CardHeader } from '@patternfly/react-core';
266268

267269
ImageCard = () => (
268270
<Card>
269271
<CardHead>
270-
<img src={pfLogo} alt="PatternFly Logo" style={{ height: '50px' }}/>
272+
<CardHeadMain>
273+
<Brand src={pfLogo} alt="PatternFly logo" style={{ height: '50px' }}/>
274+
</CardHeadMain>
271275
</CardHead>
272276
<CardHeader>Header</CardHeader>
273277
<CardBody>Body</CardBody>

packages/react-core/src/components/Card/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './CardBody';
44
export * from './CardFooter';
55
export * from './CardHeader';
66
export * from './CardHead';
7+
export * from './CardHeadMain';

0 commit comments

Comments
 (0)