Skip to content

Commit 387da19

Browse files
tlabajTitanimcoker
authored
feat(Card): Refactor card header (#8759)
* feat(Card): Refactor card header * update snapshots * Updates from review comments * rebase * remove unused example * add width to brand * Update packages/react-core/src/components/Card/CardHeader.tsx Co-authored-by: Michael Coker <35148959+mcoker@users.noreply.github.com> --------- Co-authored-by: Titani <tlabaj@redaht.com> Co-authored-by: Michael Coker <35148959+mcoker@users.noreply.github.com>
1 parent 613d25f commit 387da19

36 files changed

+438
-461
lines changed

packages/react-core/src/components/Card/Card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export const CardContext = React.createContext<Partial<CardContextProps>>({
6464
});
6565

6666
export const Card: React.FunctionComponent<CardProps> = ({
67-
children = null,
67+
children,
6868
id = '',
69-
className = '',
69+
className,
7070
component = 'div',
7171
isCompact = false,
7272
isSelectable = false,

packages/react-core/src/components/Card/CardActions.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { css } from '@patternfly/react-styles';
33
import styles from '@patternfly/react-styles/css/components/Card/card';
44

55
export interface CardActionsProps extends React.HTMLProps<HTMLDivElement> {
6-
/** Content rendered inside the Card Action */
6+
/** Content rendered inside the card action */
77
children?: React.ReactNode;
8-
/** Additional classes added to the Action */
8+
/** Additional classes added to the action */
99
className?: string;
1010
/** Flag indicating that the actions have no offset */
1111
hasNoOffset?: boolean;
1212
}
1313

1414
export const CardActions: React.FunctionComponent<CardActionsProps> = ({
15-
children = null,
16-
className = '',
15+
children,
16+
className,
1717
hasNoOffset = false,
1818
...props
1919
}: CardActionsProps) => (

packages/react-core/src/components/Card/CardBody.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export interface CardBodyProps extends React.HTMLProps<HTMLDivElement> {
1414
}
1515

1616
export const CardBody: React.FunctionComponent<CardBodyProps> = ({
17-
children = null,
18-
className = '',
17+
children,
18+
className,
1919
component = 'div',
2020
isFilled = true,
2121
...props

packages/react-core/src/components/Card/CardExpandableContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export interface CardExpandableContentProps extends React.HTMLProps<HTMLDivEleme
1111
}
1212

1313
export const CardExpandableContent: React.FunctionComponent<CardExpandableContentProps> = ({
14-
children = null,
15-
className = '',
14+
children,
15+
className,
1616
...props
1717
}: CardExpandableContentProps) => (
1818
<CardContext.Consumer>

packages/react-core/src/components/Card/CardFooter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export interface CardFooterProps extends React.HTMLProps<HTMLDivElement> {
1212
}
1313

1414
export const CardFooter: React.FunctionComponent<CardFooterProps> = ({
15-
children = null,
16-
className = '',
15+
children,
16+
className,
1717
component = 'div',
1818
...props
1919
}: CardFooterProps) => {

packages/react-core/src/components/Card/CardHeadMain.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/react-core/src/components/Card/CardHeader.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ import * as React from 'react';
22
import { css } from '@patternfly/react-styles';
33
import styles from '@patternfly/react-styles/css/components/Card/card';
44
import { CardContext } from './Card';
5+
import { CardHeaderMain } from './CardHeaderMain';
6+
import { CardActions } from './CardActions';
57
import { Button } from '../Button';
68
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
79

10+
export interface CardHeaderActionsObject {
11+
/** Actions of the card header */
12+
actions: React.ReactNode;
13+
/** Flag indicating that the actions have no offset */
14+
hasNoOffset?: boolean;
15+
/** Additional classes added to the actions wrapper */
16+
className?: string;
17+
}
18+
819
export interface CardHeaderProps extends React.HTMLProps<HTMLDivElement> {
9-
/** Content rendered inside the CardHeader */
20+
/** Content rendered inside the card header */
1021
children?: React.ReactNode;
11-
/** Additional classes added to the CardHeader */
22+
/** Additional classes added to the card header */
1223
className?: string;
24+
/** Actions of the card header */
25+
actions?: CardHeaderActionsObject;
1326
/** ID of the card header. */
1427
id?: string;
1528
/** Callback expandable card */
@@ -21,8 +34,9 @@ export interface CardHeaderProps extends React.HTMLProps<HTMLDivElement> {
2134
}
2235

2336
export const CardHeader: React.FunctionComponent<CardHeaderProps> = ({
24-
children = null,
25-
className = '',
37+
children,
38+
className,
39+
actions,
2640
id,
2741
onExpand,
2842
toggleButtonProps,
@@ -36,7 +50,7 @@ export const CardHeader: React.FunctionComponent<CardHeaderProps> = ({
3650
<Button
3751
variant="plain"
3852
type="button"
39-
onClick={evt => {
53+
onClick={(evt) => {
4054
onExpand(evt, cardId);
4155
}}
4256
{...toggleButtonProps}
@@ -55,7 +69,8 @@ export const CardHeader: React.FunctionComponent<CardHeaderProps> = ({
5569
{...props}
5670
>
5771
{onExpand && !isToggleRightAligned && cardHeaderToggle}
58-
{children}
72+
{actions && <CardActions className={actions?.className} hasNoOffset={actions?.hasNoOffset}> {actions.actions} </CardActions>}
73+
{children && <CardHeaderMain>{children}</CardHeaderMain>}
5974
{onExpand && isToggleRightAligned && cardHeaderToggle}
6075
</div>
6176
);

packages/react-core/src/components/Card/CardHeaderMain.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as React from 'react';
2+
import { css } from '@patternfly/react-styles';
3+
import styles from '@patternfly/react-styles/css/components/Card/card';
24

35
export interface CardHeaderMainProps extends React.HTMLProps<HTMLDivElement> {
46
/** Content rendered inside the Card Head Main */
@@ -8,11 +10,11 @@ export interface CardHeaderMainProps extends React.HTMLProps<HTMLDivElement> {
810
}
911

1012
export const CardHeaderMain: React.FunctionComponent<CardHeaderMainProps> = ({
11-
children = null,
12-
className = '',
13+
children,
14+
className,
1315
...props
1416
}: CardHeaderMainProps) => (
15-
<div className={className} {...props}>
17+
<div className={css(styles.cardHeaderMain ,className)} {...props}>
1618
{children}
1719
</div>
1820
);

packages/react-core/src/components/Card/CardTitle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export interface CardTitleProps extends React.HTMLProps<HTMLDivElement> {
1313
}
1414

1515
export const CardTitle: React.FunctionComponent<CardTitleProps> = ({
16-
children = null,
17-
className = '',
16+
children,
17+
className,
1818
component = 'div',
1919
...props
2020
}: CardTitleProps) => {

packages/react-core/src/components/Card/__tests__/CardHeadMain.test.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)