Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(background-image): pf-background-image element #2588

Merged
merged 26 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
51e5bd5
feat(background-image): pf-background-image element
zeroedin Aug 22, 2023
0f94f07
docs(background-image): impove property docs
zeroedin Aug 22, 2023
ed0a296
Merge branch 'main' into feat/pf-background-image
zeroedin Aug 22, 2023
e272f43
docs(background-image): update example demo text
zeroedin Aug 22, 2023
745ae41
fix(background-image): styleMap and remove content wrapper
zeroedin Aug 23, 2023
1d355f5
fix(background-image): add missing lg size private css prop
zeroedin Aug 23, 2023
f95e8f7
docs: htmlexample plugin support for class on parent container
zeroedin Aug 24, 2023
f5bc82c
fix(background-image): remove content and slot adjust demo styles
zeroedin Aug 24, 2023
18ca4af
docs(background-image): update docs to reflect removal of content slot
zeroedin Aug 24, 2023
752dfb3
docs(background-image): fix demo image paths
zeroedin Aug 24, 2023
c1b4896
docs(background-image): remove support for container use case
zeroedin Aug 24, 2023
2516a8f
docs(background-image): fix image paths
zeroedin Aug 24, 2023
4bcaff9
fix(background-image): align cssprop value with PFv4
zeroedin Aug 24, 2023
0668059
fix(background-image): align cssprop value with PFv4 missed one
zeroedin Aug 24, 2023
0ead12d
fix(background-image): correct css prop cascade
zeroedin Aug 24, 2023
0dc5e99
docs(background-image): add screenshot
zeroedin Aug 25, 2023
ed0a43b
chore(background-image): add changeset
zeroedin Aug 25, 2023
7d16831
test(background-image): add spec tests
zeroedin Aug 25, 2023
e384db1
Merge branch 'main' into feat/pf-background-image
zeroedin Sep 25, 2023
55d9558
docs(background-image): update readme
zeroedin Oct 5, 2023
c8fe072
docs(background-image): fix typo in readme
zeroedin Oct 5, 2023
0a932c1
docs: demos
bennypowers Oct 19, 2023
2d191cd
docs: changeset
bennypowers Oct 19, 2023
1783586
docs: demos
bennypowers Oct 19, 2023
257d4c6
docs: demos and readme
bennypowers Oct 19, 2023
ad5c33a
Merge branch 'main' into feat/pf-background-image
bennypowers Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/neat-toes-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@patternfly/elements": minor
---

✨ Added `<pf-background-image>`

```html
<pf-background-image
src="/path/to/image.jpg"
src-2x="/path/to/[email protected]"
src-sm="/path/to/image-768.jpg"
src-sm-2x="/path/to/[email protected]"
src-lg="/path/to/image-992.jpg"
></pf-background-image>
```
4 changes: 1 addition & 3 deletions docs/_plugins/html-example.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ module.exports = function(eleventyConfig) {
content = await renderFromFile.call(this, dedent(content), kwargs);
}
return /* html */`
<div class="example-preview">
${content}
</div>
<div class="example-preview ${kwargs?.class ?? ''}">${content.trim()}</div>
<details class="html-example ${kwargs?.class ?? ''}"${!kwargs?.style ? '' : ` style="${kwargs.style}"`}>
<summary>View HTML Source</summary>

Expand Down
32 changes: 31 additions & 1 deletion docs/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,36 @@ header.band h1 {
padding: var(--pf-global--spacer--md, 1rem);
background-color: var(--pf-global--BackgroundColor--100, #fff);
border-bottom: var(--pf-global--BorderWidth--sm, 1px) solid var(--pf-global--BorderColor--300, #f0f0f0);
transition: width .2s ease-in-out;
}

.example-preview.pf-background-image {
position: relative;
z-index: 0;
height: 350px;
overflow: hidden;
color: var(--pf-theme--color--white, #fff);
}

.example-preview.pf-background-image pf-background-image {
position: absolute;
z-index: -1;
top: 0;
left: 0;
}

.example-preview.pf-background-image pf-background-image::part(container) {
position: relative;
}

.example-preview.pf-background-image pf-background-image,
.example-preview.pf-background-image pf-background-image::part(container) {
height: 100%;
width: 100%;
}

.example-preview.pf-background-image pf-background-image::part(container)::after {
position: absolute;
background-size: cover;
}

section.api.band.api-properties dl {
Expand Down Expand Up @@ -731,6 +760,7 @@ code {
.html-example {
display: flex;
padding-block: 6px;
transition: width .2s ease-in-out;
}

.html-example:hover summary {
Expand Down
1 change: 1 addition & 0 deletions elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"./pf-accordion/pf-accordion.js": "./pf-accordion/pf-accordion.js",
"./pf-avatar/BaseAvatar.js": "./pf-avatar/BaseAvatar.js",
"./pf-avatar/pf-avatar.js": "./pf-avatar/pf-avatar.js",
"./pf-background-image/pf-background-image.js": "./pf-background-image/pf-background-image.js",
"./pf-badge/BaseBadge.js": "./pf-badge/BaseBadge.js",
"./pf-badge/pf-badge.js": "./pf-badge/pf-badge.js",
"./pf-banner/pf-banner.js": "./pf-banner/pf-banner.js",
Expand Down
37 changes: 37 additions & 0 deletions elements/pf-background-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Background Image

A **background image** allows you to place an image in the background of your page or area of a page.


## Installation
Load `<pf-background-image>` via CDN:

```html
<script src="https://jspm.dev/@patternfly/elements/pf-background-image/pf-background-image.js"></script>


Or, if you are using [NPM](https://npm.im), install it

```bash
npm install @patternfly/elements
```

Then once installed, import it to your application:

```js
import '@patternfly/elements/pf-background-image/pf-background-image.js';
```

## Usage

```html
<pf-background-image
src="image.jpg"
src-2x="image-576.jpg"
src-sm="image-768.jpg"
src-sm-2x="[email protected]"
src-lg="image-1200.jpg"
></pf-background-image>
```

[docs]: https://patternflyelements.org/components/background-image
23 changes: 23 additions & 0 deletions elements/pf-background-image/demo/filter-override.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<pf-background-image filter
src="/components/background-image/demo/pfbg.jpg"
src-2x="/components/background-image/demo/pfbg_576.jpg"
src-sm="/components/background-image/demo/pfbg_768.jpg"
src-sm-2x="/components/background-image/demo/[email protected]"
src-lg="/components/background-image/demo/pfbg_1200.jpg">
<svg slot="filter" xmlns="http://www.w3.org/2000/svg">
<filter id="image_overlay">
<feMorphology in="SourceGraphic" operator="dilate" radius="5"></feMorphology>
</filter>
</svg>
</pf-background-image>

<script type="module">
import '@patternfly/elements/pf-background-image/pf-background-image.js';
</script>

<style>
/* override demo chrome styles */
html, body {
background-color: transparent;
}
</style>
18 changes: 18 additions & 0 deletions elements/pf-background-image/demo/pf-background-image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<pf-background-image filter
src="pfbg.jpg"
src-2x="pfbg_576.jpg"
src-sm="pfbg_768.jpg"
src-sm-2x="[email protected]"
src-lg="pfbg_1200.jpg"
></pf-background-image>

<script type="module">
import '@patternfly/elements/pf-background-image/pf-background-image.js';
</script>

<style>
/* override demo chrome styles */
html, body {
background-color: transparent;
}
</style>
Binary file added elements/pf-background-image/demo/pfbg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added elements/pf-background-image/demo/pfbg_1200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added elements/pf-background-image/demo/pfbg_576.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added elements/pf-background-image/demo/pfbg_768.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions elements/pf-background-image/demo/sibling-content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script type="module" src="pf-background-image.js"></script>

<pf-background-image
src="/components/background-image/demo/pfbg.jpg"
src-2x="/components/background-image/demo/pfbg_576.jpg"
src-sm="/components/background-image/demo/pfbg_768.jpg"
src-sm-2x="/components/background-image/demo/[email protected]"
src-lg="/components/background-image/demo/pfbg_1200.jpg"
></pf-background-image>

<section>
<h1>Sibling Content</h1>
<pf-button>Button</pf-button>
</section>


<style>
/* override demo chrome styles */
html, body {
background-color: transparent;
}
section {
color: var(--pf-theme--color--ui-base--text, #fff);
padding: var(--pf-global--spacer--xl, 2rem);
}
</style>
65 changes: 65 additions & 0 deletions elements/pf-background-image/docs/pf-background-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{% renderOverview %}
{% htmlexample class="pf-background-image" %}
<pf-background-image filter
src="/components/background-image/demo/pfbg.jpg"
src-2x="/components/background-image/demo/pfbg_576.jpg"
src-sm="/components/background-image/demo/pfbg_768.jpg"
src-sm-2x="/components/background-image/demo/[email protected]"
src-lg="/components/background-image/demo/pfbg_1200.jpg"
></pf-background-image>
{% endhtmlexample %}

View the [full screen demo](/components/background-image/demo/).

{% endrenderOverview %}

{% band header="Usage" %}
### Sibling content w/ no filter
{% htmlexample class="pf-background-image" %}
<pf-background-image
src="/components/background-image/demo/pfbg.jpg"
src-2x="/components/background-image/demo/pfbg_576.jpg"
src-sm="/components/background-image/demo/pfbg_768.jpg"
src-sm-2x="/components/background-image/demo/[email protected]"
src-lg="/components/background-image/demo/pfbg_1200.jpg"
></pf-background-image>
<p>Sibling Content</p>
<pf-button>Button</pf-button>
{% endhtmlexample %}

View the [full screen demo](/components/background-image/demo/sibling-content/).

### Override SVG Filter

[MDN documentation for `<filter>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/filter)

{% htmlexample class="pf-background-image" %}
<pf-background-image filter
src="/components/background-image/demo/pfbg.jpg"
src-2x="/components/background-image/demo/pfbg_576.jpg"
src-sm="/components/background-image/demo/pfbg_768.jpg"
src-sm-2x="/components/background-image/demo/[email protected]"
src-lg="/components/background-image/demo/pfbg_1200.jpg" >
<svg slot="filter" xmlns="http://www.w3.org/2000/svg">
<filter id="image_overlay">
<feMorphology in="SourceGraphic" operator="dilate" radius="5"></feMorphology>
</filter>
</svg>
</pf-background-image>
{% endhtmlexample %}

View the [full screen demo](/components/background-image/demo/filter-override/).

{% endband %}

{% renderSlots %}{% endrenderSlots %}

{% renderAttributes %}{% endrenderAttributes %}

{% renderMethods %}{% endrenderMethods %}

{% renderEvents %}{% endrenderEvents %}

{% renderCssCustomProperties %}{% endrenderCssCustomProperties %}

{% renderCssParts %}{% endrenderCssParts %}
Binary file added elements/pf-background-image/docs/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions elements/pf-background-image/pf-background-image.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
:host {
display: flex;

--_background-image: var(--pf-c-background-image--BackgroundImage);
}

#outer-container {
display: contents;
}

#container {
padding: 0;
margin: 0;
background-color: transparent;
}

#container::after {
display: block;
position: fixed;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
content: "";
background-color: var(--pf-c-background-image--BackgroundColor, var(--pf-global--BackgroundColor--dark-100, #151515));
background-image: var(--_background-image);
filter: var(--pf-c-background-image--Filter, url("#image_overlay"));
background-repeat: no-repeat;
background-size: cover;
}

slot[name="filter"] {
display: none;
}

slot[part="content"] {
display: block;
position: relative;
z-index: 1;
color: white;
}

@media screen and (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
#container::after {
background-image: var(--pf-c-background-image--BackgroundImage-2x, var(--_background-image-2x, var(--_background-image)));
}
}

@media screen and (min-width: 576px) {
#container::after {
background-image: var(--pf-c-background-image--BackgroundImage--sm, var(--_background-image-sm, var(--_background-image)));
}
}

@media screen and (min-width: 576px) and (-webkit-min-device-pixel-ratio: 2), (min-width: 576px) and (min-resolution: 192dpi) {
#container::after {
background-image: var(--pf-c-background-image--BackgroundImage--sm-2x, var(--_background-image-sm-2x, var(--_background-image)));
}
}

@media screen and (min-width: 992px) {
#container::after {
background-image: var(--pf-c-background-image--BackgroundImage--lg, var(--_background-image-lg, var(--_background-image)));
}
}
Loading
Loading