Skip to content

Commit 2df4228

Browse files
committed
Removed Card class test.
1 parent 125d8af commit 2df4228

File tree

3 files changed

+115
-5
lines changed

3 files changed

+115
-5
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ describe('CardSubtitle', () => {
77
expect(asFragment()).toMatchSnapshot();
88
});
99

10-
test('className is added to the root element', () => {
11-
render(<CardSubtitle className="extra-class">text</CardSubtitle>);
12-
expect(screen.getByText('text')).toHaveClass('extra-class');
13-
});
14-
1510
test('extra props are spread to the root element', () => {
1611
const testId = 'card-subtitle';
1712

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ A basic card that also has a subtitle
3737

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

40+
```
41+
### Card with subtitle and Actions
42+
This card demonstrates having an image, action, and subtitle in a single card.
43+
44+
```ts file='./CardSubtitleActions.tsx'
45+
4046
```
4147

4248
### Secondary cards
@@ -78,6 +84,8 @@ Select the "actions hasNoOffset" checkbox in the example below to illustrate thi
7884

7985
```
8086

87+
88+
8189
### Title inline with images and actions
8290

8391
Moving `<CardTitle>` within the `<CardHeader>` will style it inline with any images or actions.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { useState } from 'react';
2+
import {
3+
Brand,
4+
Card,
5+
CardHeader,
6+
CardTitle,
7+
CardBody,
8+
CardFooter,
9+
Checkbox,
10+
Dropdown,
11+
DropdownList,
12+
DropdownItem,
13+
MenuToggle,
14+
MenuToggleElement,
15+
Divider
16+
} from '@patternfly/react-core';
17+
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
18+
import pfLogo from '../../assets/PF-HorizontalLogo-Color.svg';
19+
20+
export const CardWithImageAndActions: React.FunctionComponent = () => {
21+
const [isOpen, setIsOpen] = useState<boolean>(false);
22+
const [isChecked, setIsChecked] = useState<boolean>(false);
23+
const [hasNoOffset, setHasNoOffset] = useState<boolean>(false);
24+
25+
const onSelect = () => {
26+
setIsOpen(!isOpen);
27+
};
28+
const onClick = (checked: boolean) => {
29+
setIsChecked(checked);
30+
};
31+
const toggleOffset = (checked: boolean) => {
32+
setHasNoOffset(checked);
33+
};
34+
35+
const dropdownItems = (
36+
<>
37+
<DropdownItem key="action">Action</DropdownItem>
38+
{/* Prevent default onClick functionality for example purposes */}
39+
<DropdownItem key="link" to="#" onClick={(event: any) => event.preventDefault()}>
40+
Link
41+
</DropdownItem>
42+
<DropdownItem key="disabled action" isDisabled>
43+
Disabled Action
44+
</DropdownItem>
45+
<DropdownItem key="disabled link" isDisabled to="#" onClick={(event: any) => event.preventDefault()}>
46+
Disabled Link
47+
</DropdownItem>
48+
<Divider component="li" key="separator" />
49+
<DropdownItem key="separated action">Separated Action</DropdownItem>
50+
<DropdownItem key="separated link" to="#" onClick={(event: any) => event.preventDefault()}>
51+
Separated Link
52+
</DropdownItem>
53+
</>
54+
);
55+
56+
const headerActions = (
57+
<>
58+
<Dropdown
59+
onSelect={onSelect}
60+
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
61+
<MenuToggle
62+
ref={toggleRef}
63+
isExpanded={isOpen}
64+
onClick={() => setIsOpen(!isOpen)}
65+
variant="plain"
66+
aria-label="Card header images and actions example kebab toggle"
67+
icon={<EllipsisVIcon />}
68+
/>
69+
)}
70+
isOpen={isOpen}
71+
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
72+
>
73+
<DropdownList>{dropdownItems}</DropdownList>
74+
</Dropdown>
75+
<Checkbox
76+
isChecked={isChecked}
77+
onChange={(_event, checked) => onClick(checked)}
78+
aria-label="card checkbox example"
79+
id="check-1"
80+
name="check1"
81+
/>
82+
</>
83+
);
84+
85+
return (
86+
<>
87+
<Checkbox
88+
label="actions hasNoOffset"
89+
isChecked={hasNoOffset}
90+
onChange={(_event, checked) => toggleOffset(checked)}
91+
aria-label="remove actions offset"
92+
id="toggle-actions-offset"
93+
name="toggle-actions-offset"
94+
/>
95+
<div style={{ marginTop: '15px' }}>
96+
<Card>
97+
<CardHeader actions={{ actions: headerActions, hasNoOffset }}>
98+
<Brand src={pfLogo} alt="PatternFly logo" style={{ width: '300px' }} />
99+
</CardHeader>
100+
<CardTitle subtitle="Subtitle">Title</CardTitle>
101+
<CardBody>Body</CardBody>
102+
<CardFooter>Footer</CardFooter>
103+
</Card>
104+
</div>
105+
</>
106+
);
107+
};

0 commit comments

Comments
 (0)