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] <rh-alert> add ability for instances to toast themselves #2152

Open
KamiQuasi opened this issue Jan 31, 2025 · 2 comments
Open

[feat] <rh-alert> add ability for instances to toast themselves #2152

KamiQuasi opened this issue Jan 31, 2025 · 2 comments
Labels
feature New feature or request

Comments

@KamiQuasi
Copy link

Description

Problem: The RhAlert class is not always readily available, or able to be (re)imported, which restricts access to the .toast() function.

Suggested solution

  • Add the ability for <rh-alert> component instances to .toast() themselves.
  • Update documentation for the toast functionality to explain more details
const newAlert = document.createElement('rh-alert');
newAlert.toast();

In the instance toast() function, the component would call

const message = this.shadowRoot.querySelector('slot:not([name])').textContent;
const heading = this.shadowRoot.querySelector('slot[name="header"]').textContent;
RhAlert.toast({
  message: message,
  heading: heading,
  state: this.state
});

Screenshots

No response

Example API

Additional context

No response

@bennypowers
Copy link
Member

toast needs to be static because it creates and destroys instances of alert.

Users who for one reason or another are unwilling or unable to import from a bare specifier can use whenDefined:

const RhAlert = await customElements.whenDefined('rh-alert')
RhAlert.toast(...)

@bennypowers
Copy link
Member

discussed in chat, we might want to let toast() accept any lit renderable (template result, dom node, string, etc)

const message = document.createElement('a');
message.href = './confirm';
message.textContent = 'Confirm';

RhAlert.toast({
  heading: html`<strong>Rich</strong> <em>text</em>`,
  message
});

or whatever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants