Skip to content

Commit 2389ccd

Browse files
bennypowersheyMPzeroedin
committed
feat(card)!: migrate pfe-card to lit
**Features** - add parts to card - update docs (#1842) - transfer css props from docs to CEM - chore: fix href in demo - add {{version}} to element classes **Fixes** - make imgSrc optional **Tests** - adjust test for changes in slot controller - e2e tests with page object model **Breaking Changes** - remove public `has_` attrs **Docs** - inline docs - refactor docs page - add changeset - document CSS parts - fix a11y bugs in demo - use pfe-styles - simplify demo Co-Authored-By: Michael Potter <[email protected]> Co-Authored-By: Steven Spriggs <[email protected]>
1 parent a1f69e7 commit 2389ccd

34 files changed

+871
-1741
lines changed

.changeset/card.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"@patternfly/pfe-card": major
3+
---
4+
5+
## 🔥 Migrate to Lit
6+
7+
This release migrates `<pfe-card>` to LitElement.
8+
9+
### NEW: CSS Shadow Parts!
10+
- Adds `header`, `body`, and `footer` CSS parts to `<pfe-card>`
11+
12+
### Breaking Changes
13+
- Initial render is now [asynchronous](https://lit.dev/docs/components/lifecycle/#reactive-update-cycle)
14+
If your code assumes that shadow DOM is ready once the element is constructed, update it to `await element.updateComplete`
15+
- Deprecates `pfe-card--header` and `pfe-card--footer` slots. Use `header` and `footer` instead
16+
17+
18+
See [docs](https://patternflyelements.org/components/card/) for more info

elements/pfe-card/.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

elements/pfe-card/README.md

Lines changed: 25 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,36 @@
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)
24

3-
## Usage
5+
## Installation
6+
7+
Load `<pfe-card>` via CDN:
48

59
```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>
1311
```
1412

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
5814

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+
```
7618

77-
From the PFElements root directory, run:
19+
Then once installed, import it to your application:
7820

79-
npm start
21+
```js
22+
import '@patternfly/pfe-card';
23+
```
8024

81-
## Code style
25+
## Usage
8226

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+
```
8436

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
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { pfeCustomElementsManifestConfig } from '@patternfly/pfe-tools/custom-elements-manifest.js';
2+
3+
export default pfeCustomElementsManifestConfig({
4+
globs: ['pfe-*.ts'],
5+
});

elements/pfe-card/demo/demo.css

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
1-
/* For demo only */
2-
.demo-cards {
3-
display: flex;
4-
flex-wrap: wrap;
1+
:host,
2+
body {
3+
padding: 1em;
4+
display: grid;
5+
grid-template-columns: repeat(auto-fill, minmax(200px, calc(25% - 32px)));
6+
grid-auto-rows: max-content;
7+
gap: 32px;
58
}
69

7-
.demo-cards>* {
8-
margin: 0 16px 32px;
9-
min-width: 200px;
10-
width: calc(25% - 32px);
10+
.button-series::part(footer) {
11+
display: flex;
12+
gap: 15px;
1113
}
1214

13-
.button-series {
14-
display: inline-block;
15-
margin-bottom: -15px;
16-
margin-left: -15px;
15+
#first-image {
16+
grid-column: 1/2;
1717
}
1818

19-
.button-series>* {
20-
display: inline-block;
21-
margin-left: 15px;
22-
margin-bottom: 15px;
23-
}
24-
25-
h2[slot="pfe-card--header"] {
26-
font-size: 1.1em;
27-
font-weight: bolder;
19+
h2[slot="header"] {
20+
font-size: 1.1em;
21+
font-weight: bolder;
2822
}
2923

3024
.custom-border {
31-
--pfe-card--BorderColor: #eee;
32-
--pfe-card--BorderWeight: 1px;
25+
--pfe-card--BorderColor: #eee;
26+
--pfe-card--BorderWeight: 1px;
3327
}

elements/pfe-card/demo/index.html

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

0 commit comments

Comments
 (0)