Skip to content

Commit 1ec4b3c

Browse files
committed
pf-alert-new
1 parent 09aa71a commit 1ec4b3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+198
-3213
lines changed

elements/pf-alert/README.md

Lines changed: 2 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,11 @@
11
# Alert
2-
An Alert is a banner used to notify a user about a change in status or communicate other information. It can be generated with or without a user triggering an action first.
2+
Add a description of the component here.
33

44
## Usage
5-
An alert is used by wrapping html elements with an `rh-alert` element as slots in order to format the data in the desired manner.
6-
7-
An alert consists of the following slots:
8-
9-
`Header`
10-
- Header text for the alert, appears at the top of the alert.
11-
12-
`Actions`
13-
- Buttons that can be used to perform an action from the alert, such as closing or accepting the alert.
14-
15-
`Anonymous Slot`
16-
- This is the text that is inserted into the state to be displayed in the main content body.
17-
18-
An alert consists of the following attributes:
19-
20-
`dismissable`
21-
- The `dismissable` attribute adds a close button to the top right of the alert allowing the user to dismiss the alert. Clicking the close button dispatches a `close` event, then removes the alert from the page.
22-
23-
An alert has the following events:
24-
25-
`close`
26-
- This is fired when the user clicks the close button enabled by the `dismissable` attribute. Cancelling the event prevents the alert from closing.
27-
28-
## Installation
29-
30-
If using npm/bundlers:
31-
```bash
32-
npm install @rhds/elements
33-
```
34-
35-
Then once installed, import it to your application:
36-
37-
```js
38-
import '@patternfly/elements/pf-alert/pf-alert.js';
39-
```
40-
## Usage
41-
42-
### Basic Alert
5+
Describe how best to use this web component along with best practices.
436

447
```html
458
<pf-alert>
46-
<h3 slot="header">Default</h3>
47-
<p>Example Alert</p>
48-
<pf-button variant="secondary" slot="actions" data-action="dismiss">Dismiss</pf-button>
49-
<pf-button variant="link" slot="actions" data-action="confirm">Confirm</pf-button>
50-
</pf-alert>
51-
```
529

53-
### Info Alert (also available `success`, `warning`, `danger`, and `error`)
54-
55-
```html
56-
<pf-alert state="info">
57-
<h3 slot="header">Info</h3>
58-
<p>Example Alert</p>
59-
<pf-button variant="secondary" slot="actions" data-action="dismiss">Dismiss</pf-button>
60-
<pf-button variant="link" slot="actions" data-action="confirm">Confirm</pf-button>
6110
</pf-alert>
6211
```
63-
64-
### Inline Alert
65-
```html
66-
<pf-alert variant="inline">
67-
<h3 slot="header">Default</h3>
68-
<p>Example Alert</p>
69-
<pf-button variant="secondary" slot="actions" data-action="dismiss">Dismiss</pf-button>
70-
<pf-button variant="link" slot="actions" data-action="confirm">Confirm</pf-button>
71-
</pf-alert>
72-
```
73-
74-
### Toast Alert
75-
76-
Alerts may be toasted using the `toast()` function. A toasted alert has a
77-
unique style, a drop shadow, and either disappears after eight seconds, or can persist until the user dismisses it.
78-
79-
```js
80-
import { PfAlert } from '@patternfly/elements/pf-alert/pf-alert.js';
81-
82-
await PfAlert.toast({
83-
heading: 'Toast alert',
84-
message: 'Example toasted alert',
85-
actions: [
86-
{ variant: 'secondary', action: 'confirm', text: 'Confirm' },
87-
{ action: 'dismiss', text: 'Dismiss' }
88-
],
89-
});
90-
91-
```
92-
93-
You can respond to the various actions by listening for the `close` event
94-
95-
```js
96-
document.addEventListener('close', function(event) {
97-
if (event.target instanceof PfAlert) {
98-
switch (event.reason) {
99-
case 'close': // handle alert close ("X" button)
100-
case 'dismiss': // handle alert dismiss (data-action="dismiss")
101-
case 'confirm': // handle alert confirm (data-action="confirm")
102-
}
103-
}
104-
});
105-
106-
```
107-
108-
### Adding an Event Listener to a Basic Alert
109-
110-
If you would like to add custom logic when the alert is closed, you can do so with JavaScript.
111-
```js
112-
// Query for the alert element
113-
const alert = document.querySelector('pf-alert');
114-
alert.addEventListener('close', () => {
115-
// Add code to be executed when the alert element is closed.
116-
});
117-
```
118-
119-
### Preventing the default close behavior in a Basic Alert
120-
```js
121-
// Query for the alert element
122-
const alert = document.querySelector('pf-alert');
123-
alert.addEventListener('close', async function (event) {
124-
// Prevent the alert from closing
125-
event.preventDefault();
126-
// Perform some async task
127-
await alertClosed();
128-
// Close the alert when finished
129-
this.remove();
130-
});
131-
```
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<section id="alert-variant-alternate">
2-
<pf-alert variant="alternate">
1+
<section id="alert-variant-alternate">
2+
<pf-alert variant="alternate">
33
<h3 slot="header">Neutral</h3>
44
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
55
egestas, a sollicitudin mauris tincidunt.</p>
@@ -25,15 +25,15 @@ <h3 slot="header">Success</h3>
2525

2626
<pf-alert state="warning" variant="alternate">
2727
<h3 slot="header">Warning</h3>
28-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
28+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
2929
egestas, a sollicitudin mauris tincidunt.</p>
3030
<pf-button slot="actions" variant="secondary" data-action="confirm">Confirm</pf-button>
3131
<pf-button slot="actions" variant="link" data-action="dismiss">Cancel</pf-button>
3232
</pf-alert>
3333

3434
<pf-alert state="danger" variant="alternate">
3535
<h3 slot="header">Danger</h3>
36-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
36+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
3737
egestas, a sollicitudin mauris tincidunt.</p>
3838
<pf-button slot="actions" variant="secondary" data-action="confirm">Confirm</pf-button>
3939
<pf-button slot="actions" variant="link" data-action="dismiss">Cancel</pf-button>
@@ -47,18 +47,31 @@ <h3 slot="header">Caution</h3>
4747
<pf-button slot="actions" variant="link" data-action="dismiss">Cancel</pf-button>
4848
</pf-alert>
4949
</section>
50+
<button id="prev-btn">Prev</button>
51+
<button id="next-btn">Next</button>
5052

5153
<style>
5254
#alert-variant-alternate {
5355
display: grid;
5456
grid-template-columns: repeat(auto-fit, minmax(300px, max(40vh, 40%)));
5557
grid-auto-rows: min-content;
56-
gap: var(--pf-global--spacer--lg, 16px); /* שימוש בטוקן של PF */
58+
gap: var(--rh-space-lg, 16px);
5759
}
5860
</style>
5961

6062
<script type="module">
61-
import '@patternfly/elements/pf-alert/pf-alert.js';
62-
import '@patternfly/elements/pf-button/pf-button.js';
63+
import '@patternfly/elements/pf-alert/pf-alert.js';
64+
import '@patternfly/elements/pf-button/pf-button.js';
65+
66+
// customElements.whenDefined('pf-alert').then(() => {
67+
// const alerts = document.querySelectorAll('pf-alert');
68+
// alerts.forEach(alert => {
69+
// // trigger internal styling properly
70+
// alert.variant = alert.variant;
71+
// if (alert.state) {
72+
// alert.state = alert.state;
73+
// }
74+
// });
75+
// });
76+
6377
</script>
64-
//hi
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
<pf-context-demo>
2-
<pf-alert>
1+
<pf-alert dismissable>
32
<h3 slot="header">Default</h3>
43
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
54
egestas, a sollicitudin mauris tincidunt.</p>
65
<pf-button slot="actions" variant="secondary" data-action="confirm">Confirm</pf-button>
76
<pf-button slot="actions" variant="link" data-action="dismiss">Cancel</pf-button>
87
</pf-alert>
9-
</pf-context-demo>
10-
118
<script type="module">
12-
import '@patternfly/elements/lib/elements/pf-context-demo/pf-context-demo.js';
13-
import '@patternfly/elements/pf-alert/pf-alert.js';
9+
import { AlertCloseEvent } from '@patternfly/elements/pf-alert/pf-alert.js';
1410
import '@patternfly/elements/pf-button/pf-button.js';
15-
</script>
11+
12+
document.body.addEventListener('close', event => {
13+
if (event instanceof AlertCloseEvent) {
14+
console.log('Alert closed:', event.target);
15+
}
16+
});
17+
18+
</script>

elements/pf-alert/demo/deprecated-states.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ <h3 slot="header">Note - alias of Info</h3>
3636
<script type="module">
3737
import '@patternfly/elements/pf-alert/pf-alert.js';
3838
import '@patternfly/elements/pf-button/pf-button.js';
39-
</script>
39+
</script>

elements/pf-alert/demo/dismissable.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ <h3 slot="header">Dismissable With Prevent Default</h3>
5656
grid-auto-rows: min-content;
5757
gap: var(--pf-global--spacer--lg, 16px); /* שימוש בטוקן PF */
5858
}
59-
</style>
59+
</style>

elements/pf-alert/demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<pf-alert>
1+
<pf-alert dismissable>
22
<h3 slot="header">Default</h3>
33
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
44
egestas, a sollicitudin mauris tincidunt.</p>
@@ -9,4 +9,4 @@ <h3 slot="header">Default</h3>
99
<script type="module">
1010
import '@patternfly/elements/pf-alert/pf-alert.js';
1111
import '@patternfly/elements/pf-button/pf-button.js';
12-
</script>
12+
</script>

elements/pf-alert/demo/inline.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ <h3 slot="header">Danger</h3>
5252
<script type="module">
5353
import '@patternfly/elements/pf-alert/pf-alert.js';
5454
import '@patternfly/elements/pf-button/pf-button.js';
55-
</script>
55+
</script>
56+

elements/pf-alert/demo/states.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<section id="alert-states">
2-
<pf-alert state="danger">
2+
<pf-alert dismissable state="danger">
33
<h3 slot="header">Danger</h3>
44
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est
55
egestas, a sollicitudin mauris tincidunt.</p>
@@ -56,8 +56,7 @@ <h3 slot="header">Success</h3>
5656
gap: var(--pf-space-lg, 16px);
5757
}
5858
</style>
59-
6059
<script type="module">
6160
import '@patternfly/elements/pf-alert/pf-alert.js';
6261
import '@patternfly/elements/pf-button/pf-button.js';
63-
</script>
62+
</script>

elements/pf-alert/demo/toast.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
] : undefined,
5757
});
5858
});
59-
</script>
59+
</script>

elements/pf-alert/docs/00-overview.md

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

0 commit comments

Comments
 (0)