diff --git a/.changeset/short-maps-beg.md b/.changeset/short-maps-beg.md new file mode 100644 index 0000000000..c645750bab --- /dev/null +++ b/.changeset/short-maps-beg.md @@ -0,0 +1,6 @@ +--- +"@rhds/elements": minor +--- +``: added new states: `info`, `neutral`, and `caution`, and deprecated +`note` (now an alias to `info`), `default` (now an alias to `neutral`), and +`error` (now an alias to `danger`). diff --git a/elements/rh-alert/demo/deprecated-states.html b/elements/rh-alert/demo/deprecated-states.html new file mode 100644 index 0000000000..fe7f03d278 --- /dev/null +++ b/elements/rh-alert/demo/deprecated-states.html @@ -0,0 +1,39 @@ +
+ +

Error - alias of Danger

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est + egestas, a sollicitudin mauris tincidunt.

+ Dismiss + Confirm +
+ + +

Default - alias of Neutral

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est + egestas, a sollicitudin mauris tincidunt.

+ Dismiss + Confirm +
+ + +

Note - alias of Info

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est + egestas, a sollicitudin mauris tincidunt.

+ Dismiss + Confirm +
+
+ + + + diff --git a/elements/rh-alert/demo/states.html b/elements/rh-alert/demo/states.html index 45f88b9813..f699858d77 100644 --- a/elements/rh-alert/demo/states.html +++ b/elements/rh-alert/demo/states.html @@ -1,46 +1,46 @@
- -

Default

+ +

Danger

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est egestas, a sollicitudin mauris tincidunt.

Dismiss Confirm
- -

Default

+ +

Warning

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est egestas, a sollicitudin mauris tincidunt.

Dismiss Confirm
- -

Info

+ +

Caution

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est egestas, a sollicitudin mauris tincidunt.

Dismiss Confirm
- -

Success

+ +

Neutral

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est egestas, a sollicitudin mauris tincidunt.

Dismiss Confirm
- -

Warning

+ +

Info

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est egestas, a sollicitudin mauris tincidunt.

Dismiss Confirm
- -

Danger

+ +

Success

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eleifend elit sed est egestas, a sollicitudin mauris tincidunt.

Dismiss diff --git a/elements/rh-alert/rh-alert.css b/elements/rh-alert/rh-alert.css index ed14f60075..3bde308959 100644 --- a/elements/rh-alert/rh-alert.css +++ b/elements/rh-alert/rh-alert.css @@ -81,31 +81,45 @@ footer ::slotted(rh-button[variant='link' i]) { font-family: var(--_font-family); } +#container.neutral { + --_border-color: var(--rh-color-status-neutral); + --_icon-color: var(--rh-color-icon-status-neutral); + --_header-color: var(--rh-color-text-primary); + --_background-color: var(--rh-color-surface-status-neutral); +} + #container.info { - --_border-color: var(--rh-color-status-note); + --_border-color: var(--rh-color-status-info); --_icon-color: var(--rh-color-icon-status-info); - --_header-color: var(--rh-color-status-note); + --_header-color: var(--rh-color-purple-70); --_background-color: var(--rh-color-surface-status-info); } #container.success { --_border-color: var(--rh-color-status-success); --_icon-color: var(--rh-color-icon-status-success); - --_header-color: var(--rh-color-status-success); + --_header-color: var(--rh-color-green-70); --_background-color: var(--rh-color-surface-status-success); } +#container.caution { + --_border-color: var(--rh-color-status-caution); + --_icon-color: var(--rh-color-icon-status-caution); + --_header-color: var(--rh-color-orange-70); + --_background-color: var(--rh-color-surface-status-caution); +} + #container.warning { --_border-color: var(--rh-color-status-warning); --_icon-color: var(--rh-color-icon-status-warning); - --_header-color: var(--rh-color-status-warning); + --_header-color: var(--rh-color-yellow-70); --_background-color: var(--rh-color-surface-status-warning); } #container.danger { --_border-color: var(--rh-color-status-danger); --_icon-color: var(--rh-color-icon-status-danger); - --_header-color: var(--rh-color-status-danger); + --_header-color: var(--rh-color-red-orange-70); --_background-color: var(--rh-color-surface-status-danger); } diff --git a/elements/rh-alert/rh-alert.ts b/elements/rh-alert/rh-alert.ts index d749d423da..41c28e4ec4 100644 --- a/elements/rh-alert/rh-alert.ts +++ b/elements/rh-alert/rh-alert.ts @@ -1,6 +1,6 @@ import { SlotController } from '@patternfly/pfe-core/controllers/slot-controller.js'; -import { type CSSResult, LitElement, html, render } from 'lit'; +import { type CSSResult, LitElement, html, isServer, render } from 'lit'; import { customElement } from 'lit/decorators/custom-element.js'; import { property } from 'lit/decorators/property.js'; import { repeat } from 'lit/directives/repeat.js'; @@ -23,12 +23,12 @@ interface ToastOptions { } const ICONS = new Map(Object.entries({ - default: 'notification-fill', - error: 'error-fill', + neutral: 'notification-fill', success: 'check-circle-fill', + caution: 'warning-fill', warning: 'warning-fill', danger: 'error-fill', - info: 'information-fill', + note: 'information-fill', })); export class AlertCloseEvent extends Event { @@ -129,20 +129,37 @@ export class RhAlert extends LitElement { } private get icon() { - return ICONS.get(this.state.toLowerCase()) ?? ''; + const state = this.state.toLowerCase() as this['state']; + switch (state) { + case 'info': return ICONS.get('note'); + case 'default': return ICONS.get('neutral'); + case 'error': return ICONS.get('danger'); + default: return ICONS.get(state); + } } /** * Communicates the urgency of a message and is denoted by various styling configurations. * - * - `default` - Indicates generic information or a message with no severity. + * - `neutral` - Indicates generic information or a message with no severity. + * - `danger` - Indicates a danger state, like an error that is blocking a user from completing a task. + * - `warning` - Indicates a warning state, like a non-blocking error that might need to be fixed. + * - `caution` - Indicates an action or notice which should immediately draw the attention * - `info` - Indicates helpful information or a message with very little to no severity. * - `success` - Indicates a success state, like if a process was completed without errors. - * - `warning` - Indicates a caution state, like a non-blocking error that might need to be fixed. - * - `danger` - Indicates a danger state, like an error that is blocking a user from completing a task. */ @property({ reflect: true }) - state: 'default' | 'error' | 'success' | 'warning' | 'danger' | 'info' = 'default'; + state: + | 'danger' + | 'warning' + | 'caution' + | 'neutral' + | 'info' + | 'success' + | 'note' // deprecated + | 'default' // deprecated + | 'error' = // deprecated + 'neutral'; /** * The alternate Inline alert style includes a border instead of a line which @@ -171,27 +188,56 @@ export class RhAlert extends LitElement { } } + #aliasState(state: string) { + switch (state.toLowerCase()) { + // the first three are deprecated pre-DPO status names + case 'note': return 'info'; + case 'default': return 'neutral'; + case 'error': return 'danger'; + // the following are DPO-approved status names + case 'danger': + case 'warning': + case 'caution': + case 'neutral': + case 'info': + case 'success': + return state as this['state']; + default: + return 'neutral'; + } + } + + override connectedCallback() { + super.connectedCallback(); + if (!isServer) { + this.requestUpdate(); + } + } + render() { - const hasActions = this.#slots.hasSlotted('actions'); - const hasBody = this.#slots.hasSlotted(SlotController.default as unknown as string); - const { state, variant = '' } = this; + const _isServer = isServer && !this.hasUpdated; + const hasActions = _isServer || this.#slots.hasSlotted('actions'); + const hasBody = + _isServer || this.#slots.hasSlotted(SlotController.default as unknown as string); + const { variant = '' } = this; + const state = this.#aliasState(this.state); return html` + class="${classMap({ + hasBody, + on: true, + light: true, + [state]: true, + [variant]: !!variant, + })}" + role="alert" + aria-hidden="false" + color-palette="lightest">
-
+
${!this.dismissable && this.variant !== 'toast' ? '' : html`