Debian Codegraph @

node/@patternfly/react-core/src/components/Card/examples/Card.md

raw
1 ---
2 id: Card
3 section: components
4 cssPrefix: pf-v6-c-card
5 propComponents:
6 [
7 'Card',
8 'CardHeader',
9 'CardHeaderActionsObject',
10 'CardHeaderSelectableActionsObject',
11 'CardTitle',
12 'CardBody',
13 'CardFooter',
14 'CardExpandableContent'
15 ]
16 ouia: true
17 ---
18
19 import { Fragment, useState } from 'react';
20 import pfLogo from '../../assets/PF-HorizontalLogo-Color.svg';
21 import pfLogoSmall from '../../assets/PF-IconLogo.svg';
22 import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon';
23 import PlusIcon from '@patternfly/react-icons/dist/esm/icons/plus-icon';
24
25 ## Examples
26
27 ### Basic cards
28
29 Basic cards typically have a `<CardTitle>`, `<CardBody>` and `<CardFooter>`. You may omit these components as needed, but it is recommended to at least include a `<CardBody>` to provide details about the card item.
30
31 ```ts file='./CardBasic.tsx'
32
33 ```
34 ### Card with subtitle
35
36 A basic card that also has a subtitle
37
38 ```ts file='./CardSubtitle.tsx' isBeta
39
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' isBeta
45
46 ```
47
48 ### Secondary cards
49
50 You can apply secondary background color styling to a card by setting the `variant` property to `secondary`.
51
52 ```ts file='./CardSecondary.tsx'
53
54 ```
55
56 ### Modifiers
57
58 You can further modify the styling of the card's content by using the properties outlined below. In this example, you can enable each modifier by selecting its respective checkbox.
59
60 Most modifiers can be used in combination with each other, except for `isCompact` and `isLarge`, since they are contradictory.
61
62 ```ts file='./CardWithModifiers.tsx'
63
64 ```
65
66 | Modifier | Description |
67 | ------------ | ------------------------------------------------------------------------------------ |
68 | isCompact | Modifies the card to include compact styling. Should not be used with isLarge. |
69 | isLarge | Modifies the card to be large. Should not be used with isCompact. |
70 | isFullHeight | Modifies the card so that it fills the total available height of its container. |
71 | isPlain | Modifies the card to include plain styling, which removes the border and background. |
72
73 ### Header images and actions
74
75 You can include header actions with the `actions` property of `<CardHeader>` . The following example includes an image using the [Brand](/components/brand) component, and also includes a kebab dropdown and a checkbox in `<CardHeader>` actions.
76
77 The `actions` property for `<CardHeader>` includes the `hasNoOffset` property, which is `false` by default. When `hasNoOffset` is `false`, a negative margin is applied to help align default-sized card titles with card actions.
78
79 You may use `hasNoOffset` to remove this negative margin, which better aligns card actions in implementations that use large card titles or tall header images, for example.
80
81 Select the "actions hasNoOffset" checkbox in the example below to illustrate this behavior.
82
83 ```ts file='./CardWithImageAndActions.tsx'
84
85 ```
86
87
88
89 ### Title inline with images and actions
90
91 Moving `<CardTitle>` within the `<CardHeader>` will style it inline with any images or actions.
92
93 ```ts file='./CardHeaderInCardHead.tsx'
94
95 ```
96
97 ### Card header without title
98
99 Card actions can be placed in the card header even without a `<CardTitle>`.
100
101 Images can also be placed in the card header without a `<CardTitle>`.
102
103 ```ts file='./CardOnlyActionsInCardHead.tsx'
104
105 ```
106
107 ### Card with header that wraps
108 ```ts file='./CardHeaderWraps.tsx'
109 ```
110
111 ### With HTML heading element
112
113 You may use the `component` property to place the card's title within an HTML heading element.
114
115 ```ts file='./CardWithHeadingElement.tsx'
116
117 ```
118
119 ### With multiple body sections
120
121 You may use multiple body sections to visually separate blocks of content.
122
123 ```ts file='./CardWithMultipleBodySections.tsx'
124
125 ```
126
127 ### With a primary body section that fills
128
129 `<CardBody>` sections will fill the available height of the card when `isFilled` equals `{true}`, which is the default value. Set `isFilled` to `{false}` to disable this behavior for one or more body sections. The remaining available height of the card will be split between any `<CardBody>` section that does not set `isFilled` to `{false}`.
130
131 A common use case of this is to set all but one body section to `isFilled={false}` so that a primary body section fills the available space of the card as seen in the example below. This example has 3 `<CardBody>` sections, two of which set `isFilled` to `{false}`. The third `<CardBody>` fills the remaining height of the card.
132
133 ```ts file='./CardWithBodySectionFills.tsx'
134
135 ```
136
137 ### Selectable
138
139 A selectable card can be selected by clicking anywhere within the card.
140
141 You must avoid rendering any other interactive content within the `<Card>` when it is meant to be selectable only. Refer to our [actionable and selectable example](#clickable-and-selectable-cards) if you need a card that is both selectable and has other interactive, actionable content.
142
143 ```ts file='./CardSelectable.tsx'
144
145 ```
146
147 ### Single selectable
148
149 When a group of single selectable cards are related, you must pass the same `name` property to each card's `selectableActions` property. For more guidance on selectable cards with hidden input, see our [cards as tiles examples](#cards-as-tiles).
150
151 ```ts file='./CardSingleSelectable.tsx'
152
153 ```
154
155 ### Actionable
156
157 An actionable card can perform an action or navigate to a link by clicking anywhere within the card. To open a link in a new tab or window, pass the `isExternalLink` property to `selectableActions`.
158
159 You can pass the `isClicked` property to `<Card>` to convey that a card is the currently clicked one, such as when clicking a card would open a [primary-detail view](/patterns/primary-detail). This must not be used simply for "selection" of a card, and you should instead use our [selectable card](#selectable) or [single selectable card](#single-selectable).
160
161 When a card is meant to be actionable only, you must avoid rendering any other interactive content within the `<Card>`, similar to selectable cards.
162
163 ```ts file='./CardClickable.tsx'
164
165 ```
166
167 ### Actionable and selectable
168
169 A card can be selectable and have additional interactive content by passing both the `isClickable` and `isSelectable` properties to `<Card>`. The following example shows how the actionable functionality can be rendered anywhere within a selectable card.
170
171 When passing interactive content to an actionable and selectable card that is disabled, you should also ensure the interactive content is disabled as well, if applicable.
172
173 ```ts file='./CardClickableSelectable.tsx'
174
175 ```
176
177 ### Expandable cards
178
179 A card can be made expandable using the `isExpanded` property. In the collapsed state, only the card header is shown, and the user can click the caret to view the rest of the card content.
180
181 Place any content that you want to be hidden within the `<CardExpandableContent>` component.
182
183 ```ts file='./CardExpandable.tsx'
184
185 ```
186
187 ### Expandable with icon
188
189 An image can be placed in the card header to show users an icon beside the expansion caret.
190
191 ```ts file='./CardExpandableWithIcon.tsx'
192
193 ```
194
195 ### Card with dividers
196
197 Dividers can be placed between sections of the card.
198
199 ```ts file='./CardWithDividers.tsx'
200
201 ```
202
203 ## Cards as tiles
204
205 Sets of selectable cards can be used as tiles, which are static options that users can select.
206
207 They can be either single selectable or multi selectable, by passing the `variant` property to the `selectableActions` object. You can also toggle the visibility of the radio or checkbox by passing the `isHidden` property to the `selectableActions` object.
208
209 ### Single selectable tiles
210
211 To prevent users from selecting more than 1 tile in a set, set `variant` to "single" within the `selectableActions` object of `<CardHeader>`.
212
213 ```ts file='./CardTile.tsx'
214
215 ```
216
217 ### Multi selectable tiles
218
219 To allow users to select more than 1 tile in a set, do not set `variant` within the `selectableActions` object of `<CardHeader>`.
220
221 ```ts file='./CardTileMulti.tsx'
222
223 ```