|
1 | | -# PFElements Card Element |
| 1 | +# PatternFly Elements Card |
| 2 | + |
| 3 | +Read more about Card in the [PatternFly Elements Card documentation](https://patternflyelements.org/components/card) |
2 | 4 |
|
3 | | -## Usage |
| 5 | +## Installation |
| 6 | + |
| 7 | +Load `<pfe-card>` via CDN: |
4 | 8 |
|
5 | 9 | ```html |
6 | | -<pfe-card> |
7 | | - <h2 slot="pfe-card--header">Card header</h2> |
8 | | - <p>This is the pfe-card body.</p> |
9 | | - <pfe-cta slot="pfe-card--footer"> |
10 | | - <a href="#">Footer link</a> |
11 | | - </pfe-cta> |
12 | | -</pfe-card> |
| 10 | +<script src="https://unpkg.com/@patternfly/pfe-card?module"></script> |
13 | 11 | ``` |
14 | 12 |
|
15 | | -## Slots |
16 | | -All slots are optional. If the slot is not defined, the content will be added to the `body` region of the card. |
17 | | - |
18 | | -### Header |
19 | | -If this slot is used, we expect a heading level tag (h1, h2, h3, h4, h5, h6). An icon, svg, or use of the icon component are also valid in this region. |
20 | | - |
21 | | -### Default slot (body) |
22 | | -Any content that is not designated for the `header` or `footer` slot, will go to this slot. |
23 | | - |
24 | | -### Footer |
25 | | -Use this slot for anything that you want to be stuck to the base of the card. This region is bottom-aligned. |
26 | | - |
27 | | -## Attributes |
28 | | - |
29 | | -<style> |
30 | | - .color-preview { |
31 | | - display: inline-block; |
32 | | - width: 1em; |
33 | | - height: 1em; |
34 | | - vertical-align: middle; |
35 | | - background-color: var(--bg, #ffffff); |
36 | | - border: 1px solid #444444; |
37 | | - } |
38 | | -</style> |
39 | | - |
40 | | -There are several attributes available for customizing the visual treatment of this container. |
41 | | - |
42 | | -- `color`: Options include darkest, darker, accent, complement, lighter, lightest. The card has a default value of `#dfdfdf`. Your context will influence these colors so check there first if you are seeing inconsistencies. |
43 | | - |
44 | | - | color | hex | |
45 | | - |-------|-----| |
46 | | - | lightest | <span class="color-preview" style="--bg:#ffffff"></span> #ffffff | |
47 | | - | lighter | <span class="color-preview" style="--bg:#ececec"></span> #ececec | |
48 | | - | default | <span class="color-preview" style="--bg:#dfdfdf"></span> #dfdfdf | |
49 | | - | darker | <span class="color-preview" style="--bg:#464646"></span> #464646 | |
50 | | - | darkest | <span class="color-preview" style="--bg:#131313"></span> #131313 | |
51 | | - | accent | <span class="color-preview" style="--bg:#ee0000"></span> #ee0000 | |
52 | | - | complement | <span class="color-preview" style="--bg:#0477a4"></span> #0477a4 | |
53 | | - |
54 | | -- `img-src`: Optional background image applied to the entire card container. Alignment of this image can be managed using the `--pfe-card--BackgroundPosition` variable which is set to `center center` by default. |
55 | | -- `size`: Optionally adjusts the padding on the container. Accepts: `small`. |
56 | | -- `overflow`: Optionally allows an image or element to overflow the padding on the container. This property should be added to the direct child of the slotm such as on an image tag; should be added to the element that you want to overflow the container. Accepts: `top`, `right`, `bottom`, `left`. |
57 | | -- `border`: Optionally apply a border color and weight to the entire card container. The default color and weight is `#d2d2d2` and `1px`, respectively. |
| 13 | +Or, if you are using [NPM](https://npm.im), install it |
58 | 14 |
|
59 | | -## Variables |
60 | | -There are several powerful variables available to hook into and override default styles. |
61 | | - |
62 | | -- **Background color**: Though using the `pfe-color` attribute is strongly recommended when setting the background color for the band, you can also use completely custom colors by updating the `--pfe-band--BackgroundColor` variable. If you update this value manually, you should also update the `--context` context variable to invoke the right context on it and it's child elements. Supported contexts include: `light`, `dark`, and `saturated`. |
63 | | -- **Background position**: This is designed for use with the `pfe-img-src` attribute to allow you to align your background image. Default value is `center center`. **Variable name:** `--pfe-card--BackgroundPosition`. |
64 | | -- **Border**: This allows the customization of a border around the entire container. There is a variable for the entire border shorthand (transparent by default) or you can hook into the individual properties. **Variable name:** `--pfe-card--BorderRadius` and `--pfe-card--Border` or `--pfe-card--BorderWeight`, `--pfe-card--BorderStyle`, `--pfe-card--BorderColor`. |
65 | | -- **Padding**: You can customize the padding around the outside of the card container by connecting to either the shortcut padding variable or just one or more of the individual padding regions. **Variable names:** `--pfe-card--Padding` or `--pfe-card--PaddingTop`, `--pfe-card--PaddingRight`, `--pfe-card--PaddingBottom`, `--pfe-card--PaddingLeft`. |
66 | | - |
67 | | -## Test |
68 | | - |
69 | | - npm run test |
70 | | - |
71 | | -## Build |
72 | | - |
73 | | - npm run build |
74 | | - |
75 | | -## Demo |
| 15 | +```bash |
| 16 | +npm install @patternfly/pfe-card |
| 17 | +``` |
76 | 18 |
|
77 | | -From the PFElements root directory, run: |
| 19 | +Then once installed, import it to your application: |
78 | 20 |
|
79 | | - npm start |
| 21 | +```js |
| 22 | +import '@patternfly/pfe-card'; |
| 23 | +``` |
80 | 24 |
|
81 | | -## Code style |
| 25 | +## Usage |
82 | 26 |
|
83 | | -Card (and all PFElements) use [Prettier][prettier] to auto-format JS and JSON. The style rules get applied when you commit a change. If you choose to, you can [integrate your editor][prettier-ed] with Prettier to have the style rules applied on every save. |
| 27 | +```html |
| 28 | +<pfe-card> |
| 29 | + <h2 slot="header">Card header</h2> |
| 30 | + <p>This is the pfe-card body.</p> |
| 31 | + <pfe-cta slot="footer"> |
| 32 | + <a href="#">Footer link</a> |
| 33 | + </pfe-cta> |
| 34 | +</pfe-card> |
| 35 | +``` |
84 | 36 |
|
85 | | -[prettier]: https://github.com/prettier/prettier/ |
86 | | -[prettier-ed]: https://prettier.io/docs/en/editors.html |
87 | | -[web-component-tester]: https://github.com/Polymer/web-component-tester |
0 commit comments