Skip to content

Commit 292d3e9

Browse files
feat(background-image): pf-background-image element (#2588)
* feat(background-image): pf-background-image element * docs(background-image): impove property docs * docs(background-image): update example demo text * fix(background-image): styleMap and remove content wrapper * fix(background-image): add missing lg size private css prop * docs: htmlexample plugin support for class on parent container * fix(background-image): remove content and slot adjust demo styles * docs(background-image): update docs to reflect removal of content slot * docs(background-image): fix demo image paths * docs(background-image): remove support for container use case * docs(background-image): fix image paths * fix(background-image): align cssprop value with PFv4 * fix(background-image): align cssprop value with PFv4 missed one * fix(background-image): correct css prop cascade * docs(background-image): add screenshot * chore(background-image): add changeset * test(background-image): add spec tests * docs(background-image): update readme * docs(background-image): fix typo in readme * docs: demos * docs: changeset * docs: demos * docs: demos and readme --------- Co-authored-by: Benny Powers <web@bennypowers.com>
1 parent 24d43bd commit 292d3e9

19 files changed

+521
-4
lines changed

.changeset/neat-toes-guess.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@patternfly/elements": minor
3+
---
4+
5+
✨ Added `<pf-background-image>`
6+
7+
```html
8+
<pf-background-image
9+
src="/path/to/image.jpg"
10+
src-2x="/path/to/image@2x.jpg"
11+
src-sm="/path/to/image-768.jpg"
12+
src-sm-2x="/path/to/image-768@2x.jpg"
13+
src-lg="/path/to/image-992.jpg"
14+
></pf-background-image>
15+
```

docs/_plugins/html-example.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ module.exports = function(eleventyConfig) {
2828
content = await renderFromFile.call(this, dedent(content), kwargs);
2929
}
3030
return /* html */`
31-
<div class="example-preview">
32-
${content}
33-
</div>
31+
<div class="example-preview ${kwargs?.class ?? ''}">${content.trim()}</div>
3432
<details class="html-example ${kwargs?.class ?? ''}"${!kwargs?.style ? '' : ` style="${kwargs.style}"`}>
3533
<summary>View HTML Source</summary>
3634

docs/main.css

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,36 @@ header.band h1 {
281281
padding: var(--pf-global--spacer--md, 1rem);
282282
background-color: var(--pf-global--BackgroundColor--100, #fff);
283283
border-bottom: var(--pf-global--BorderWidth--sm, 1px) solid var(--pf-global--BorderColor--300, #f0f0f0);
284-
transition: width .2s ease-in-out;
284+
}
285+
286+
.example-preview.pf-background-image {
287+
position: relative;
288+
z-index: 0;
289+
height: 350px;
290+
overflow: hidden;
291+
color: var(--pf-theme--color--white, #fff);
292+
}
293+
294+
.example-preview.pf-background-image pf-background-image {
295+
position: absolute;
296+
z-index: -1;
297+
top: 0;
298+
left: 0;
299+
}
300+
301+
.example-preview.pf-background-image pf-background-image::part(container) {
302+
position: relative;
303+
}
304+
305+
.example-preview.pf-background-image pf-background-image,
306+
.example-preview.pf-background-image pf-background-image::part(container) {
307+
height: 100%;
308+
width: 100%;
309+
}
310+
311+
.example-preview.pf-background-image pf-background-image::part(container)::after {
312+
position: absolute;
313+
background-size: cover;
285314
}
286315

287316
section.api.band.api-properties dl {
@@ -731,6 +760,7 @@ code {
731760
.html-example {
732761
display: flex;
733762
padding-block: 6px;
763+
transition: width .2s ease-in-out;
734764
}
735765

736766
.html-example:hover summary {

elements/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"./pf-accordion/pf-accordion.js": "./pf-accordion/pf-accordion.js",
1919
"./pf-avatar/BaseAvatar.js": "./pf-avatar/BaseAvatar.js",
2020
"./pf-avatar/pf-avatar.js": "./pf-avatar/pf-avatar.js",
21+
"./pf-background-image/pf-background-image.js": "./pf-background-image/pf-background-image.js",
2122
"./pf-badge/BaseBadge.js": "./pf-badge/BaseBadge.js",
2223
"./pf-badge/pf-badge.js": "./pf-badge/pf-badge.js",
2324
"./pf-banner/pf-banner.js": "./pf-banner/pf-banner.js",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Background Image
2+
3+
A **background image** allows you to place an image in the background of your page or area of a page.
4+
5+
6+
## Installation
7+
Load `<pf-background-image>` via CDN:
8+
9+
```html
10+
<script src="https://jspm.dev/@patternfly/elements/pf-background-image/pf-background-image.js"></script>
11+
12+
13+
Or, if you are using [NPM](https://npm.im), install it
14+
15+
```bash
16+
npm install @patternfly/elements
17+
```
18+
19+
Then once installed, import it to your application:
20+
21+
```js
22+
import '@patternfly/elements/pf-background-image/pf-background-image.js';
23+
```
24+
25+
## Usage
26+
27+
```html
28+
<pf-background-image
29+
src="image.jpg"
30+
src-2x="image-576.jpg"
31+
src-sm="image-768.jpg"
32+
src-sm-2x="image-768@2x.jpg"
33+
src-lg="image-1200.jpg"
34+
></pf-background-image>
35+
```
36+
37+
[docs]: https://patternflyelements.org/components/background-image
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<pf-background-image filter
2+
src="/components/background-image/demo/pfbg.jpg"
3+
src-2x="/components/background-image/demo/pfbg_576.jpg"
4+
src-sm="/components/background-image/demo/pfbg_768.jpg"
5+
src-sm-2x="/components/background-image/demo/pfbg_768@2x.jpg"
6+
src-lg="/components/background-image/demo/pfbg_1200.jpg">
7+
<svg slot="filter" xmlns="http://www.w3.org/2000/svg">
8+
<filter id="image_overlay">
9+
<feMorphology in="SourceGraphic" operator="dilate" radius="5"></feMorphology>
10+
</filter>
11+
</svg>
12+
</pf-background-image>
13+
14+
<script type="module">
15+
import '@patternfly/elements/pf-background-image/pf-background-image.js';
16+
</script>
17+
18+
<style>
19+
/* override demo chrome styles */
20+
html, body {
21+
background-color: transparent;
22+
}
23+
</style>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<pf-background-image filter
2+
src="pfbg.jpg"
3+
src-2x="pfbg_576.jpg"
4+
src-sm="pfbg_768.jpg"
5+
src-sm-2x="pfbg_768@2x.jpg"
6+
src-lg="pfbg_1200.jpg"
7+
></pf-background-image>
8+
9+
<script type="module">
10+
import '@patternfly/elements/pf-background-image/pf-background-image.js';
11+
</script>
12+
13+
<style>
14+
/* override demo chrome styles */
15+
html, body {
16+
background-color: transparent;
17+
}
18+
</style>
206 KB
Loading
271 KB
Loading
65.9 KB
Loading

0 commit comments

Comments
 (0)