Skip to content

Commit a43a44a

Browse files
authored
fix: pfe-card header and footer slot issues (#861)
1 parent 4b2eae1 commit a43a44a

File tree

6 files changed

+70
-42
lines changed

6 files changed

+70
-42
lines changed

CHANGELOG-prerelease.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
## Prerelease 46 ( 2020-05-12 )
77

8+
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: pfe-card header and footer slot issues
89
- [27fee5f](https://github.com/patternfly/patternfly-elements/commit/27fee5f5c5eb021ac126f3767dd0299f5cda8231) fix: pfe-tabs check for tagName on addedNode mutation before continuing
910
- [2c950b0](https://github.com/patternfly/patternfly-elements/commit/2c950b08f7638787df50aa5ee6738f1205ea3a9d) fix: Add clearfix within tab and accordion panels
1011
- [96f0a1b](https://github.com/patternfly/patternfly-elements/commit/96f0a1bdf9c758650e02b20a63ee3fb2fcf11bc9) feat: Add border to the card component

elements/pfe-card/demo/pfe-card.story.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ stories.add(PfeCard.tag, () => {
129129
const ctaPriorityValue = storybookBridge.select(
130130
"Priority",
131131
{
132-
null: "default",
132+
default: null,
133133
primary: "primary",
134134
secondary: "secondary"
135135
},
@@ -154,19 +154,28 @@ stories.add(PfeCard.tag, () => {
154154
// Trigger the auto generation of the knobs for slots
155155
config.has = tools.autoContentKnobs(slots, storybookBridge);
156156

157-
// prettier-ignore
158-
config.slots = [{
159-
slot: "pfe-card--header",
160-
content: tools.customTag({
161-
tag: "h3",
162-
content: config.has.header
163-
})
164-
}, {
165-
content: (region !== "footer") ? image + config.has.body : config.has.body
166-
}, {
167-
slot: "pfe-card--footer",
168-
content: (region === "footer") ? image : config.has.footer
169-
}];
157+
config.slots = [];
158+
159+
if (config.has.header.length > 0) {
160+
config.slots.push({
161+
slot: "pfe-card--header",
162+
content: tools.customTag({
163+
tag: "h3",
164+
content: config.has.header
165+
})
166+
});
167+
}
168+
169+
config.slots.push({
170+
content: region !== "footer" ? image + config.has.body : config.has.body
171+
});
172+
173+
if (config.has.footer.length > 0) {
174+
config.slots.push({
175+
slot: "pfe-card--footer",
176+
content: region === "footer" ? image : config.has.footer
177+
});
178+
}
170179

171180
// Some attribute values don't need to be included in the markup
172181
if (config.prop.color === "base") {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!-- pfe-card -->
2-
${ this.has_slot("pfe-card--header") ? `<div class="pfe-card__header">
2+
<div class="pfe-card__header">
33
<slot name="pfe-card--header"></slot>
4-
</div>` : ``}
4+
</div>
55
<div class="pfe-card__body">
66
<slot></slot>
77
</div>
8-
${ this.has_slot("pfe-card--footer") ? `<div class="pfe-card__footer">
8+
<div class="pfe-card__footer">
99
<slot name="pfe-card--footer"></slot>
10-
</div>` : ``}
10+
</div>

elements/pfe-card/src/pfe-card.scss

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $variables: (
4242

4343
:host {
4444
@include pfe-print-variables($variables);
45-
45+
4646
// Broadcasted values set to match background color
4747
@include pfe-set-broadcast-theme(light);
4848
--theme: light;
@@ -187,6 +187,10 @@ $variables: (
187187
--pfe-card__overflow--MarginTop: calc(#{pfe-local(PaddingTop)} * -1);
188188
}
189189

190+
:host(:not([has_header])) & {
191+
display: none;
192+
}
193+
190194
:host([has_body],[has_footer]) & ::slotted([pfe-overflow~="bottom"]) {
191195
--pfe-card__overflow--MarginBottom: calc(#{pfe-local(spacing--vertical)} * -1);
192196
}
@@ -218,6 +222,10 @@ $variables: (
218222
:host([has_footer]) & ::slotted([pfe-overflow~="bottom"]) {
219223
--pfe-card__overflow--MarginBottom: calc(#{pfe-local(spacing--vertical)} * -1);
220224
}
225+
226+
:host(:not([has_footer])) & {
227+
margin-bottom: 0;
228+
}
221229
}
222230
&__footer {
223231
margin-top: auto; // This allows the footer to move to the very bottom
@@ -231,12 +239,14 @@ $variables: (
231239
::slotted([pfe-overflow~="bottom"]) {
232240
--pfe-card__overflow--MarginBottom: calc(#{pfe-local(PaddingBottom)} * -1);
233241
}
242+
243+
:host(:not([has_footer])) & {
244+
display: none;
245+
}
234246
}
235247
&__header,
236248
&__body {
237-
&:not(:last-child) {
238-
margin-bottom: #{pfe-local(spacing--vertical)};
239-
}
249+
margin-bottom: #{pfe-local(spacing--vertical)};
240250

241251
//-- Slotted styles for typography
242252
// Remove margins from typography inside the slots

elements/pfe-card/test/pfe-card_test.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ <h2 slot="pfe-card--header">Card 4</h2>
4040
<p>This is pfe-card.</p>
4141
<div slot="pfe-card--footer">Text in footer</div>
4242
</pfe-card>
43+
44+
<pfe-card id="dynamicHeaderFooter">
45+
This is the card
46+
</pfe-card>
4347
</div>
4448

4549
<script>
@@ -176,6 +180,30 @@ <h2 slot="pfe-card--header">Card 4</h2>
176180
})
177181
});
178182

183+
test("it should render a header and footer when content for those slots are added dynamically", done => {
184+
const card = document.querySelector("#dynamicHeaderFooter");
185+
186+
const header = document.createElement("h2");
187+
header.setAttribute("slot", "pfe-card--header");
188+
header.textContent = "Card Header";
189+
190+
const footer = document.createElement("div");
191+
footer.setAttribute("slot", "pfe-card--footer");
192+
footer.textContent = "This is the footer";
193+
194+
card.prepend(header);
195+
card.appendChild(footer);
196+
197+
flush(() => {
198+
const cardHeaderSlot = card.shadowRoot.querySelector(`slot[name="pfe-card--header"]`);
199+
const cardFooterSlot = card.shadowRoot.querySelector(`slot[name="pfe-card--footer"]`);
200+
201+
assert.equal(cardHeaderSlot.assignedNodes().length, 1);
202+
assert.equal(cardFooterSlot.assignedNodes().length, 1);
203+
done();
204+
});
205+
});
206+
179207
// Iterate over the colors object to test expected background color results
180208
Object.entries(colors).forEach(set => {
181209
test(`it should have a background color of ${set[1]} when pfe-color is ${set[0]}`, () => {

package-lock.json

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)