Skip to content
Merged
2 changes: 1 addition & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"tslib": "^2.8.1"
},
"devDependencies": {
"@patternfly/patternfly": "6.5.0-prerelease.12",
"@patternfly/patternfly": "6.5.0-prerelease.14",
"case-anything": "^3.1.2",
"css": "^3.0.0",
"fs-extra": "^11.3.0"
Expand Down
20 changes: 20 additions & 0 deletions packages/react-core/src/components/Card/CardSubtitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Card/card';

export interface CardSubtitleProps {
/** Content rendered inside the description. */
children?: React.ReactNode;
/** Id of the description. */
id?: string;
}

export const CardSubtitle: React.FunctionComponent<CardSubtitleProps> = ({
children = null,
id = '',
...props
}: CardSubtitleProps) => (
<div {...props} id={id} className={css(styles.cardSubtitle)}>
{children}
</div>
);
CardSubtitle.displayName = 'CardSubtitle';
6 changes: 6 additions & 0 deletions packages/react-core/src/components/Card/CardTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useContext } from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Card/card';
import { CardContext } from './Card';
import { CardSubtitle } from './CardSubtitle';

export interface CardTitleProps extends React.HTMLProps<HTMLDivElement> {
/** Content rendered inside the CardTitle */
Expand All @@ -10,23 +11,28 @@ export interface CardTitleProps extends React.HTMLProps<HTMLDivElement> {
className?: string;
/** Sets the base component to render. defaults to div */
component?: keyof React.JSX.IntrinsicElements;
/** @beta Subtitle of the card title */
subtitle?: React.ReactNode;
}

export const CardTitle: React.FunctionComponent<CardTitleProps> = ({
children,
className,
component = 'div',
subtitle,
...props
}: CardTitleProps) => {
const { cardId } = useContext(CardContext);
const Component = component as any;
const titleId = cardId ? `${cardId}-title` : '';
const subtitleId = cardId ? `${cardId}-subtitle` : '';

return (
<div className={css(styles.cardTitle)}>
<Component className={css(styles.cardTitleText, className)} id={titleId || undefined} {...props}>
{children}
</Component>
{subtitle && <CardSubtitle id={subtitleId}>{subtitle}</CardSubtitle>}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { render, screen } from '@testing-library/react';
import { CardSubtitle } from '../CardSubtitle';

describe('CardSubtitle', () => {
test('renders with PatternFly Core styles', () => {
const { asFragment } = render(<CardSubtitle>text</CardSubtitle>);
expect(asFragment()).toMatchSnapshot();
});

test('className is added to the root element', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CardSubtitle doesn't pass className anymore, and is only used internally so this test can be removed to fix the build.

render(<CardSubtitle className="extra-class">text</CardSubtitle>);
expect(screen.getByText('text')).toHaveClass('extra-class');
});

test('extra props are spread to the root element', () => {
const testId = 'card-subtitle';

render(<CardSubtitle data-testid={testId} />);
expect(screen.getByTestId(testId)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CardSubtitle renders with PatternFly Core styles 1`] = `
<DocumentFragment>
<div
class="pf-v6-c-card__subtitle"
id=""
>
text
</div>
</DocumentFragment>
`;
7 changes: 7 additions & 0 deletions packages/react-core/src/components/Card/examples/Card.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Basic cards typically have a `<CardTitle>`, `<CardBody>` and `<CardFooter>`. You

```ts file='./CardBasic.tsx'

```
### Card with subtitle

A basic card that also has a subtitle

```ts file='./CardSubtitle.tsx'

```

### Secondary cards
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';

export const CardSubtitle: React.FunctionComponent = () => (
<Card ouiaId="CardSubtitle">
<CardTitle subtitle="Subtitle">Title</CardTitle>
<CardBody>Body</CardBody>
<CardFooter>Footer</CardFooter>
</Card>
);
2 changes: 1 addition & 1 deletion packages/react-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test:a11y": "patternfly-a11y --config patternfly-a11y.config"
},
"dependencies": {
"@patternfly/patternfly": "6.5.0-prerelease.12",
"@patternfly/patternfly": "6.5.0-prerelease.14",
"@patternfly/react-charts": "workspace:^",
"@patternfly/react-code-editor": "workspace:^",
"@patternfly/react-core": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-regular-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@patternfly/patternfly": "6.5.0-prerelease.12",
"@patternfly/patternfly": "6.5.0-prerelease.14",
"fs-extra": "^11.3.0",
"tslib": "^2.8.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"clean": "rimraf dist css"
},
"devDependencies": {
"@patternfly/patternfly": "6.5.0-prerelease.12",
"@patternfly/patternfly": "6.5.0-prerelease.14",
"change-case": "^5.4.4",
"fs-extra": "^11.3.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"devDependencies": {
"@adobe/css-tools": "^4.4.4",
"@patternfly/patternfly": "6.5.0-prerelease.12",
"@patternfly/patternfly": "6.5.0-prerelease.14",
"fs-extra": "^11.3.0"
}
}
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4516,10 +4516,10 @@ __metadata:
languageName: node
linkType: hard

"@patternfly/patternfly@npm:6.5.0-prerelease.12":
version: 6.5.0-prerelease.12
resolution: "@patternfly/patternfly@npm:6.5.0-prerelease.12"
checksum: 10c0/a07d7ccbde0bdcdfa03877678ee73c741f1dc6774c0fe96db24e308f637e68035684bf3758e6acf3e2c51c46f27d320eff2189e85bfdeb0c9104dd18d33ae771
"@patternfly/patternfly@npm:6.5.0-prerelease.14":
version: 6.5.0-prerelease.14
resolution: "@patternfly/patternfly@npm:6.5.0-prerelease.14"
checksum: 10c0/d2bca43a2b4c98767b81dc5569eb5960866c9e7b757276b69aa8eacc06414723e3a58b434c7f1b46e416fe02474dbc333707e6c6a82ca05201900458d74ca548
languageName: node
linkType: hard

Expand Down Expand Up @@ -4617,7 +4617,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@patternfly/react-core@workspace:packages/react-core"
dependencies:
"@patternfly/patternfly": "npm:6.5.0-prerelease.12"
"@patternfly/patternfly": "npm:6.5.0-prerelease.14"
"@patternfly/react-icons": "workspace:^"
"@patternfly/react-styles": "workspace:^"
"@patternfly/react-tokens": "workspace:^"
Expand All @@ -4638,7 +4638,7 @@ __metadata:
resolution: "@patternfly/react-docs@workspace:packages/react-docs"
dependencies:
"@patternfly/documentation-framework": "npm:^6.28.9"
"@patternfly/patternfly": "npm:6.5.0-prerelease.12"
"@patternfly/patternfly": "npm:6.5.0-prerelease.14"
"@patternfly/patternfly-a11y": "npm:5.1.0"
"@patternfly/react-charts": "workspace:^"
"@patternfly/react-code-editor": "workspace:^"
Expand Down Expand Up @@ -4678,7 +4678,7 @@ __metadata:
"@fortawesome/free-brands-svg-icons": "npm:^5.15.4"
"@fortawesome/free-regular-svg-icons": "npm:^5.15.4"
"@fortawesome/free-solid-svg-icons": "npm:^5.15.4"
"@patternfly/patternfly": "npm:6.5.0-prerelease.12"
"@patternfly/patternfly": "npm:6.5.0-prerelease.14"
fs-extra: "npm:^11.3.0"
tslib: "npm:^2.8.1"
peerDependencies:
Expand Down Expand Up @@ -4763,7 +4763,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@patternfly/react-styles@workspace:packages/react-styles"
dependencies:
"@patternfly/patternfly": "npm:6.5.0-prerelease.12"
"@patternfly/patternfly": "npm:6.5.0-prerelease.14"
change-case: "npm:^5.4.4"
fs-extra: "npm:^11.3.0"
languageName: unknown
Expand Down Expand Up @@ -4805,7 +4805,7 @@ __metadata:
resolution: "@patternfly/react-tokens@workspace:packages/react-tokens"
dependencies:
"@adobe/css-tools": "npm:^4.4.4"
"@patternfly/patternfly": "npm:6.5.0-prerelease.12"
"@patternfly/patternfly": "npm:6.5.0-prerelease.14"
fs-extra: "npm:^11.3.0"
languageName: unknown
linkType: soft
Expand Down
Loading