Skip to content

Commit 96ba083

Browse files
bennypowersheyMPzeroedin
committed
feat(toast)!: migrate pfe-toast to lit
**Features** - add CSS parts - add static `toast(text)` method - allows users to create an ephemeral toast via JS **Fixes** - compose UI events - rename `pfeEvent` to `deprecatedCustomEvent` - add {{version}} to element classes **Docs** - 2.0 [pfe-toast] update docs (#1826) - pfe-toast update docs - add .no-header-styles opt-out class for headers - rearrange docs urls - inline docs - refactor docs page - add changeset - use pfe-styles **Tests** - e2e tests with page object model - build demo with optional shadowroot Co-Authored-By: Michael Potter <[email protected]> Co-Authored-By: Steven Spriggs <[email protected]>
1 parent 3adf7b9 commit 96ba083

33 files changed

+558
-1044
lines changed

.changeset/toast.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"@patternfly/pfe-toast": major
3+
---
4+
5+
## 🔥 Migrate to Lit
6+
7+
This release migrates `<pfe-toast>` to LitElement.
8+
9+
### NEW: CSS Shadow Parts!
10+
- Adds `container`, `content`, `close-button` CSS parts
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-toast:open` event. Use `open`
16+
- Deprecates `pfe-toast:close` event. Use `close`
17+
18+
See [docs](https://patternflyelements.org/components/toast/) for more info

docs/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ p.subtitle {
5757
pfe-band.header h1 {
5858
margin: 0;
5959
}
60-
pfe-band h2[id] {
60+
pfe-band h2[id]:not(.no-header-styles) {
6161
font-size: 1.5rem;
6262
line-height: 1.9375rem;
6363
font-weight: bold;
@@ -632,7 +632,7 @@ blockquote {
632632
}
633633

634634
@media (min-width: 1200px) {
635-
pfe-band h2[id] {
635+
pfe-band h2[id]:not(.no-header-styles) {
636636
font-size: 2rem;
637637
line-height: 2.3125rem;
638638
}

elements/pfe-toast/.babelrc

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

elements/pfe-toast/.editorconfig

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

elements/pfe-toast/.npmignore

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

elements/pfe-toast/README.md

Lines changed: 18 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,34 @@
1-
# PFElements Toast Element
1+
# PatternFly Elements Toast
2+
3+
`pfe-toast` is a self-contained alert that is hidden on page load and slides in/out of the view when programmatically opened/closed.
24

3-
## Overview
5+
Read more about Toast in the [PatternFly Elements Toast documentation](https://patternflyelements.org/components/toast)
46

5-
`pfe-toast` is a self-contained alert that is hidden on page load and slides in/out of the view when programmatically opened/closed.
7+
## Installation
68

7-
## Usage
9+
Load `<pfe-toast>` via CDN:
810

911
```html
10-
<pfe-toast>
11-
<p>You've been successfully toasted!</p>
12-
</pfe-toast>
12+
<script src="https://unpkg.com/@patternfly/pfe-toast?module"></script>
1313
```
1414

15-
## Slots
16-
17-
### Default slot
18-
The default slot can contain any type of content.
19-
20-
## Attributes
21-
22-
- `auto-dismiss`: This is an optional attribute string that you can provide to automatically dismiss the alert. The auto-dismiss delay value can be provided in seconds or in milliseconds. For example, `auto-dismiss="3s"` and `auto-dismiss="3000ms"` will dismiss the toast alert after three seconds. If no delay value is provided, it will default to eight seconds.
23-
- `close-label`: This is an optional attribute string that you can provide that sets the aria-label on the close button in the shadow DOM. The aria-label attribute will default to "Close".
24-
25-
## Variables
15+
Or, if you are using [NPM](https://npm.im), install it
2616

27-
- Max width: Allows you to specify the maximum width of the component. **Variable name:** `--pfe-toast--MaxWidth`.
28-
- Min width: Allows you to specify the minimum width of the component. **Variable name:** `--pfe-toast--MinWidth`.
29-
- Top: Allows you to customize the distance between the component and the top of its container. **Variable name:** `--pfe-toast--Top`.
30-
- Right: Allows you to customize the distance between the component and the right of its container. **Variable name:** ` --pfe-toast--Right`.
31-
32-
## API
33-
34-
### open
35-
36-
Manually opens a toast. Return the toast that has been opened.
37-
38-
```
39-
document.querySelector("pfe-toast").open();
17+
```bash
18+
npm install @patternfly/pfe-toast
4019
```
4120

42-
### close
21+
Then once installed, import it to your application:
4322

44-
Manually closes a toast. Returns the toast that has been closed.
45-
46-
```
47-
document.querySelector("pfe-toast").close();
23+
```js
24+
import '@patternfly/pfe-toast';
4825
```
4926

50-
### toggle
51-
52-
Manually toggles a toast. Returns the toast that has been toggled.
27+
## Usage
5328

29+
```html
30+
<pfe-toast>
31+
<p>You've been successfully toasted!</p>
32+
</pfe-toast>
5433
```
55-
document.querySelector("pfe-toast").toggle();
56-
```
57-
58-
## Events
59-
60-
### pfe-toast:open
61-
Fires when a toast is manually openned.
62-
63-
64-
### pfe-toast:close
65-
Fires when a toast is manually closed.
66-
67-
## Test
68-
69-
npm run test
70-
71-
## Build
72-
73-
npm run build
74-
75-
## Demo
76-
77-
From the PFElements root directory, run:
78-
79-
npm start
80-
81-
## Code style
82-
83-
Toast (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.
8434

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-toast/demo/index.html

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<link rel="stylesheet" href="/core/pfe-styles/red-hat-font.min.css">
2+
<link rel="stylesheet" href="/core/pfe-styles/pfe-base.css">
3+
<link rel="stylesheet" href="/core/pfe-styles/pfe-context.css">
4+
<link rel="stylesheet" href="/core/pfe-styles/pfe-layouts.css">
5+
<link rel="stylesheet" href="/core/pfe-styles/pfe.css">
6+
7+
<pfe-band color="lightest" size="small">
8+
<pfe-cta priority="secondary"><button data-toast="toast1">Toggle example one</button></pfe-cta>
9+
<pfe-cta priority="secondary"><button data-toast="toast2">Toggle example two</button></pfe-cta>
10+
<pfe-cta priority="secondary"><button data-toast="toast3">Toggle example three</button></pfe-cta>
11+
</pfe-band>
12+
13+
<pfe-band color="lightest" size="small">
14+
<h2 slot="header">Toast using JS</h2>
15+
<label for="content">Toast Content</label>
16+
<input id="content" value="Toast this message"/>
17+
<pfe-cta priority="secondary"><button id="js-toast">Toast It</button></pfe-cta>
18+
</pfe-band>
19+
20+
<pfe-toast auto-dismiss="3s" id="toast1">
21+
<p>Lorem ipsum dolor sit amet.</p>
22+
</pfe-toast>
23+
24+
<pfe-toast id="toast2">
25+
<p>Lorem ipsum dolor sit amet.</p>
26+
<pfe-cta priority="secondary"><button>Button 1</button></pfe-cta>
27+
<pfe-cta priority="secondary"><button>Button 2</button></pfe-cta>
28+
</pfe-toast>
29+
30+
<pfe-toast id="toast3" aria-label="Custom alert dialog" close-label="Cerrar">
31+
<h2>Lorem ipsum dolor sit amet</h2>
32+
<p>Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
33+
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
34+
clita
35+
kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
36+
sadipscing elitr.</p>
37+
<pfe-cta priority="secondary"><button>Button 1</button></pfe-cta>
38+
<pfe-cta priority="secondary"><button>Button 2</button></pfe-cta>
39+
</pfe-toast>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import '@patternfly/pfe-band';
2+
import '@patternfly/pfe-cta';
3+
import { PfeToast } from '@patternfly/pfe-toast';
4+
5+
const root = document.querySelector('[data-demo="pfe-toast"]')?.shadowRoot ?? document;
6+
const jsToastButton = root.getElementById('js-toast');
7+
const contentInput = root.getElementById('content');
8+
9+
for (const button of root.querySelectorAll('[data-toast]')) {
10+
button.addEventListener('click', function(event) {
11+
root.getElementById(event.target.dataset.toast).toggle();
12+
});
13+
}
14+
15+
jsToastButton.addEventListener('click', () => {
16+
PfeToast.toast(contentInput.value);
17+
});

0 commit comments

Comments
 (0)