> Markdown version of [Notification](https://vaadin.com/docs/latest/it/components/notification). Section index: [llms.txt](https://vaadin.com/docs/latest/it/components/llms.txt)

# <a id="notification"></a>Notification

Notification viene utilizzato per fornire feedback all’utente su attività, processi, ed eventi nell’applicazione.

**Lit** — `notification-basic.ts`

```typescript
const notification = Notification.show('Financial report generated', {
  position: 'middle',
  duration: 0,
});
```

**Flow** — `NotificationBasic.java`

```java
// When creating a notification using the `show` static method,
// the duration is 5-sec by default.
Notification notification = Notification
        .show("Financial report generated");
```

**React** — `notification-basic.tsx`

```typescript
const notification = Notification.show('Financial report generated', {
  position: 'middle',
  duration: 0,
});
```

## <a id="durata"></a>Durata

Per impostazione predefinita, le notifiche rimangono sullo schermo per cinque secondi. La durata può essere impostata — in millisecondi — e dovrebbe essere definita in base al contenuto e alla sua importanza:

- Utilizzare durate brevi per le notifiche che contengono testo breve, sono di minore importanza (ad esempio, operazioni terminate senza errori), e non hanno elementi interattivi.

- Utilizzare durate più lunghe per le notifiche che contengono testo più lungo, sono di maggiore importanza (ad esempio, errori), e hanno elementi interattivi (ad esempio, link o azioni "undo").

Si consiglia una durata di almeno cinque secondi (cioè, `5000` millisecondi) — ecco perché è il valore predefinito — per garantire che l’utente abbia la possibilità di leggere e comprendere la notifica.

### <a id="notifiche-persistenti"></a>Notifiche Persistenti

Impostare la durata a `0` millisecondi disabilita la chiusura automatica. Mantiene la notifica visibile finché non viene esplicitamente chiusa dall’utente. Questo dovrebbe essere utilizzato per le notifiche che forniscono informazioni vitali all’utente, come gli errori.

Le notifiche persistenti dovrebbero contenere un Button che chiude la notifica, o consente all’utente di intraprendere l’azione appropriata. Le notifiche meno importanti non dovrebbero essere persistenti, e invece scomparire automaticamente dopo un ritardo appropriato.

## <a id="posizione"></a>Posizione

Le notifiche possono essere posizionate nel viewport in sette posizioni non estese, o estese lungo la parte superiore o inferiore:

Utilizzare l’attributo `position` nei template HTML (ad esempio, `<vaadin-notification position="top-end"></vaadin-notification>`).

**Lit** — `notification-position.ts`

```typescript
protected override render() {
  return html`
    <vaadin-button @click="${this.show}">top-stretch</vaadin-button>
    <vaadin-button @click="${this.show}">top-start</vaadin-button>
    <vaadin-button @click="${this.show}">top-center</vaadin-button>
    <vaadin-button @click="${this.show}">top-end</vaadin-button>
    <vaadin-button @click="${this.show}">middle</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-start</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-center</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-end</vaadin-button>
    <vaadin-button @click="${this.show}">bottom-stretch</vaadin-button>
  `;
}

show(event: MouseEvent) {
  // Use the button label as the location
  const position = (event.target as HTMLElement).textContent as NotificationPosition;

  Notification.show(position, { position });
}
```

**Flow** — `NotificationPosition.java`

```java
add(createButton(Position.TOP_STRETCH),
        createButton(Position.TOP_START),
        createButton(Position.TOP_CENTER),
        createButton(Position.TOP_END), createButton(Position.MIDDLE),
        createButton(Position.BOTTOM_START),
        createButton(Position.BOTTOM_CENTER),
        createButton(Position.BOTTOM_END),
        createButton(Position.BOTTOM_STRETCH));

...

private Button createButton(Notification.Position position) {
    Button button = new Button(position.getClientName());
    button.addClickListener(event -> show(position));
    return button;
}

...

private void show(Notification.Position position) {
    Notification.show(position.getClientName(), 5000, position);
}
```

`notification-position-example.css`

```css
```

**React** — `notification-position.tsx`

```tsx
<Button onClick={() => show('top-stretch')}>top-stretch</Button>
<Button onClick={() => show('top-start')}>top-start</Button>
<Button onClick={() => show('top-center')}>top-center</Button>
<Button onClick={() => show('top-end')}>top-end</Button>
<Button onClick={() => show('middle')}>middle</Button>
<Button onClick={() => show('bottom-start')}>bottom-start</Button>
<Button onClick={() => show('bottom-center')}>bottom-center</Button>
<Button onClick={() => show('bottom-end')}>bottom-end</Button>
<Button onClick={() => show('bottom-stretch')}>bottom-stretch</Button>
```

**Top End** o **Bottom Start** sono consigliati per la maggior parte delle notifiche. Sono poco invasive, ma comunque visibili. **Middle** è la posizione più dirompente, e dovrebbe essere utilizzata solo per notifiche importanti, come gli errori. **Bottom End** è la posizione meno invasiva, ma può passare inosservata. Le notifiche **Stretch**, che si estendono per l’intera larghezza del viewport, sono dirompenti, e dovrebbero essere riservate alle notifiche importanti il cui contenuto richiede più spazio.

Le applicazioni con un pulsante di notifica, o un menu a tendina nell’header o nel footer, dovrebbero posizionare le notifiche in modo che appaiano nella stessa parte dello schermo. Per un’esperienza utente coerente, utilizzare una o due posizioni in tutta l’applicazione. Evitare di utilizzare posizioni che potrebbero ostruire parti importanti della UI, come la navigazione.

## <a id="impilamento"></a>Impilamento

Più notifiche visualizzate simultaneamente vengono impilate verticalmente. L’ordine, tuttavia, dipende dal loro posizionamento.

Quando si utilizza la metà inferiore dello schermo come posizione, una nuova notifica appare sotto le notifiche più vecchie. Con la posizione impostata sulla metà superiore, una nuova notifica appare sopra le notifiche esistenti.

## <a id="dimensione"></a>Dimensione

Con il tema Aura e gli stili di base, le notifiche utilizzano una larghezza fissa. La larghezza non supera mai la larghezza del viewport del browser. È possibile modificare la larghezza utilizzando la proprietà personalizzata CSS `--vaadin-notification-width`.

Con il tema Lumo, le notifiche sono dimensionate in base al loro contenuto. Nei viewport grandi, la larghezza massima della card è un terzo del viewport. Nei viewport piccoli (sotto i 450px), la card occupa sempre l’intera larghezza del viewport.

## <a id="elementi-interattivi"></a>Elementi Interattivi

Le notifiche possono contenere contenuto interattivo (ad esempio, Buttons o link) che consente all’utente di eseguire azioni correlate.

Ad esempio, se un’operazione fallisce, la notifica di errore potrebbe offrire all’utente l’opportunità di riprovare. Oppure potrebbe contenere un link a una view che consente all’utente di risolvere il problema.

**Lit** — `notification-retry.ts`

```html
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
  theme="error"
  duration="0"
  position="middle"
  .opened="${this.notificationOpened}"
  @closed="${() => {
    this.notificationOpened = false;
  }}"
  ${notificationRenderer(this.renderer, [])}
></vaadin-notification>

<!-- ... -->

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout theme="spacing" style="align-items: center; min-width: 350px;">
    <div>Failed to generate report</div>
    <vaadin-button slot="end" @click="${this.close}">Retry</vaadin-button>
    <vaadin-button slot="end" theme="icon" @click="${this.close}" aria-label="Close">
      <vaadin-icon icon="lumo:cross"></vaadin-icon>
    </vaadin-button>
  </vaadin-horizontal-layout>
`;
```

**Flow** — `NotificationRetry.java`

```java
Notification notification = new Notification();
notification.addThemeVariants(NotificationVariant.ERROR);

// this is the default, 0 or negative means the Notification
// is not closed automatically
notification.setDuration(0);

// Now we can compose the content from components
Button retryButton = new RetryButton();
Button closeButton = new CloseButton();

HorizontalLayout layout = new HorizontalLayout(
        new Text("Failed to generate report"));
layout.addToEnd(retryButton, closeButton);
layout.setAlignItems(FlexComponent.Alignment.CENTER);
layout.setMinWidth("350px");
notification.add(layout);

notification.open();
```

**React** — `notification-retry.tsx`

```tsx
{/* The duration is set to 0-sec to prevent the notification from auto-close. */}
<Notification
  theme="error"
  duration={0}
  position="middle"
  opened={notificationOpened.value}
  onClosed={() => {
    notificationOpened.value = false;
  }}
>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <div>Failed to generate report</div>
    <Button slot="end" onClick={close}>
      Retry
    </Button>

    <Button slot="end" theme="icon" aria-label="Close" onClick={close}>
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

In situazioni in cui l’utente potrebbe voler annullare un’azione, visualizzare un pulsante "Undo".

**Lit** — `notification-undo.ts`

```html
<vaadin-notification
  duration="10000"
  position="middle"
  .opened="${this.notificationOpened}"
  @closed="${() => {
    this.notificationOpened = false;
  }}"
  ${notificationRenderer(this.renderer, [])}
></vaadin-notification>

<!-- ... -->

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout theme="spacing" style="align-items: center; min-width: 300px">
    <div>5 tasks deleted</div>
    <vaadin-button slot="end" @click="${this.close}">Undo</vaadin-button>
    <vaadin-button slot="end" theme="icon" aria-label="Close" @click="${this.close}">
      <vaadin-icon icon="lumo:cross"></vaadin-icon>
    </vaadin-button>
  </vaadin-horizontal-layout>
`;
```

**Flow** — `NotificationUndo.java`

```java
Notification notification = new Notification();
notification.setDuration(10000);

Button undoButton = new UndoButton();
undoButton.addClickListener(event -> {
    // In this example we just close the Notification
    notification.close();
});

HorizontalLayout layout = new HorizontalLayout(
        new Text("5 tasks deleted"));
layout.addToEnd(undoButton, new CloseButton());
layout.setAlignItems(Alignment.CENTER);
layout.setMinWidth("300px");
notification.add(layout);

notification.open();
```

**React** — `notification-undo.tsx`

```tsx
<Notification
  duration={10000}
  position="middle"
  opened={notificationOpened.value}
  onClosed={() => {
    notificationOpened.value = false;
  }}
>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '300px' }}>
    <div>5 tasks deleted</div>
    <Button slot="end" onClick={close}>
      Undo
    </Button>

    <Button slot="end" theme="icon" aria-label="Close" onClick={close}>
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

Le notifiche possono anche contenere link a informazioni pertinenti.

**Lit** — `notification-link.ts`

```html
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
  duration="0"
  position="middle"
  .opened="${this.notificationOpened}"
  @closed="${() => {
    this.notificationOpened = false;
  }}"
  ${notificationRenderer(this.renderer, [])}
></vaadin-notification>

<!-- ... -->

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
    <div>Jason Bailey mentioned you in <a href="#">Project Q4</a></div>
    <vaadin-button slot="end" theme="tertiary" aria-label="Close" @click="${this.close}">
      <vaadin-icon icon="lumo:cross"></vaadin-icon>
    </vaadin-button>
  </vaadin-horizontal-layout>
`;
```

**Flow** — `NotificationLink.java`

```java
// When creating a notification using the constructor,
// the duration is 0-sec by default which means that
// the notification does not close automatically.
Notification notification = new Notification();

Div text = new Div(new Text("Jason Bailey mentioned you in "),
        new Anchor("#", "Project Q4"));

Button closeButton = new Button(new Icon("lumo", "cross"));
closeButton.addThemeVariants(ButtonVariant.TERTIARY);
closeButton.setAriaLabel("Close");
closeButton.addClickListener(event -> {
    notification.close();
});

HorizontalLayout layout = new HorizontalLayout(text);
layout.addToEnd(closeButton);
layout.setAlignItems(Alignment.CENTER);

notification.add(layout);
notification.open();
```

**React** — `notification-link.tsx`

```tsx
{/* The duration is set to 0-sec to prevent the notification from auto-close. */}
<Notification
  duration={0}
  position="middle"
  opened={notificationOpened.value}
  onClosed={() => {
    notificationOpened.value = false;
  }}
>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center' }}>
    <div>
      Jason Bailey mentioned you in <a href="#">Project Q4</a>
    </div>

    <Button slot="end" theme="tertiary" aria-label="Close" onClick={close}>
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

### <a id="accessibile-da-tastiera"></a>Accessibile da Tastiera

Assicurarsi che gli utenti che utilizzano solo la tastiera possano accedere agli elementi interattivi nelle notifiche.

Rendere la notifica persistente per evitare che scompaia prima che l’utente abbia avuto la possibilità di reagire. Fornire una scorciatoia da tastiera — sia per attivare l’azione stessa sia per spostare il focus sulla card della notifica — nei casi in cui siano presenti più elementi interattivi. Infine, rendere la scorciatoia individuabile, ad esempio, mostrandola come parte del contenuto della notifica.

**Lit** — `notification-keyboard-a11y.ts`

```typescript
protected override render() {
  return html`
    <vaadin-notification
      duration="10000"
      position="middle"
      .opened="${this.notificationOpened}"
      @closed="${() => {
        this.notificationOpened = false;
      }}"
      ${notificationRenderer(this.renderer, [])}
    ></vaadin-notification>
  `;
}

renderer: NotificationLitRenderer = () => html`
  <vaadin-horizontal-layout style="align-items: center; min-width: 300px;">
    <div>5 tasks deleted</div>
    <vaadin-button slot="end" @click="${this.close}">
      Undo
      <!-- Ideally, this should be hidden if the
               device does not have a physical keyboard -->
      ${this.isMac ? '⌘' : 'Ctrl-'}Z
    </vaadin-button>
  </vaadin-horizontal-layout>
`;

connectedCallback() {
  super.connectedCallback();

  document.addEventListener('keydown', this.onKeyDown);
}

disconnectedCallback() {
  super.disconnectedCallback();

  document.removeEventListener('keydown', this.onKeyDown);
}

onKeyDown = (event: KeyboardEvent) => {
  if (this.notificationOpened && (event.metaKey || event.ctrlKey) && event.key === 'z') {
    // Handle your custom undo logic here
    // Avoid triggering the native undo action
    event.preventDefault();
    this.close();
  }
};
```

**Flow** — `NotificationKeyboardA11y.java`

```java
public Notification show() {
    Notification notification = new Notification();
    notification.setDuration(10000);

    Div statusText = new Div(new Text("5 tasks deleted"));

    HorizontalLayout layout = new HorizontalLayout(statusText);
    layout.addToEnd(new CloseButtonWithShortcutHint());
    layout.setMinWidth("300px");
    layout.setAlignItems(Alignment.CENTER);

    notification.add(layout);
    notification.open();

    return notification;
}

// ...

public void setupUndoShortcut(Notification notification) {
    Shortcuts.addShortcutListener(notification, notification::close,
            Key.of("z"), KeyModifier.META);
    Shortcuts.addShortcutListener(notification, notification::close,
            Key.of("z"), KeyModifier.CONTROL);
}
```

**React** — `notification-keyboard-a11y.tsx`

```tsx
useEffect(() => {
  const onKeyDown = (event: KeyboardEvent) => {
    if (notificationOpened.value && (event.metaKey || event.ctrlKey) && event.key === 'z') {
      event.preventDefault();
      close();
    }
  };

  document.addEventListener('keydown', onKeyDown);

  return () => {
    document.removeEventListener('keydown', onKeyDown);
  };
}, [notificationOpened.value]);

return (
  <>
    <Button disabled={notificationOpened.value} onClick={open}>
      Show notification
    </Button>

    <Notification
      duration={10000}
      position="middle"
      opened={notificationOpened.value}
      onClosed={() => {
        notificationOpened.value = false;
      }}
    >
      <HorizontalLayout style={{ alignItems: 'center', minWidth: '300px' }}>
        <div>5 tasks deleted</div>
        <Button slot="end" onClick={close}>
          Undo
          {isMac ? '⌘' : 'Ctrl-'}Z
        </Button>
      </HorizontalLayout>
    </Notification>
  </>
);
```

## <a id="icone-altra-formattazione-ricca"></a>Icone & Altra Formattazione Ricca

Le icone e altre formattazioni del contenuto possono essere utilizzate per fornire informazioni e utili indizi visivi. Ad esempio, si potrebbe fare questo per rendere più facili da distinguere le notifiche di errore e di successo per gli utenti con daltonismo.

**Lit** — `notification-rich.ts`

```html
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
  duration="0"
  ${notificationRenderer(
    () => html`
      <vaadin-horizontal-layout
        theme="spacing"
        style="align-items: center; min-width: 350px;"
      >
        <vaadin-icon icon="vaadin:check-circle"></vaadin-icon>
        <div>Application submitted!</div>
        <vaadin-button slot="end">View</vaadin-button>
        <vaadin-button slot="end" theme="icon" aria-label="Close">
          <vaadin-icon icon="lumo:cross"></vaadin-icon>
        </vaadin-button>
      </vaadin-horizontal-layout>
    `,
    []
  )}
  theme="success"
  position="middle"
></vaadin-notification>

<vaadin-notification
  duration="0"
  ${notificationRenderer(
    () => html`
      <vaadin-horizontal-layout
        theme="spacing"
        style="align-items: center; min-width: 350px;"
      >
        <vaadin-icon icon="vaadin:warning"></vaadin-icon>
        <div>Failed to generate report</div>
        <vaadin-button slot="end">Retry</vaadin-button>
        <vaadin-button slot="end" theme="icon" aria-label="Close">
          <vaadin-icon icon="lumo:cross"></vaadin-icon>
        </vaadin-button>
      </vaadin-horizontal-layout>
    `,
    []
  )}
  theme="error"
  position="middle"
></vaadin-notification>

<vaadin-notification
  duration="0"
  ${notificationRenderer(
    () => html`
      <vaadin-horizontal-layout
        theme="spacing"
        style="align-items: center; min-width: 350px;"
      >
        <vaadin-avatar name="Jason Bailey"></vaadin-avatar>
        <div><b>Jason Bailey</b> mentioned you in <a href="#">Project Q4</a></div>
        <vaadin-button slot="end" theme="icon" aria-label="Close">
          <vaadin-icon icon="lumo:cross"></vaadin-icon>
        </vaadin-button>
      </vaadin-horizontal-layout>
    `,
    []
  )}
  position="middle"
></vaadin-notification>
```

**Flow** — `NotificationRich.java`

```java
public Notification createSubmitSuccess() {
    Notification notification = new Notification();
    notification.addThemeVariants(NotificationVariant.SUCCESS);

    Icon icon = VaadinIcon.CHECK_CIRCLE.create();

    Button viewBtn = new Button("View");

    HorizontalLayout layout = new HorizontalLayout(icon,
            new Text("Application submitted!"));
    layout.addToEnd(viewBtn, createCloseBtn());
    layout.setAlignItems(FlexComponent.Alignment.CENTER);
    layout.setMinWidth("350px");

    notification.add(layout);

    return notification;
}

public Notification createReportError() {
    Notification notification = new Notification();
    notification.addThemeVariants(NotificationVariant.ERROR);

    Icon icon = VaadinIcon.WARNING.create();
    Button retryBtn = new Button("Retry");

    HorizontalLayout layout = new HorizontalLayout(icon,
            new Text("Failed to generate report!"));
    layout.addToEnd(retryBtn, createCloseBtn());
    layout.setAlignItems(FlexComponent.Alignment.CENTER);
    layout.setMinWidth("350px");

    notification.add(layout);

    return notification;
}

public Notification createMentionNotification() {
    Notification notification = new Notification();

    Avatar avatar = new Avatar("Jason Bailey");

    Span name = new Span("Jason Bailey");
    name.getStyle().set("font-weight", "500");

    Div info = new Div(name, new Text(" mentioned you in "),
            new Anchor("#", "Project Q4"));

    HorizontalLayout layout = new HorizontalLayout(avatar, info);
    layout.addToEnd(createCloseBtn());
    layout.setAlignItems(FlexComponent.Alignment.CENTER);
    layout.setMinWidth("350px");

    notification.add(layout);

    return notification;
}

public static Button createCloseBtn() {
    Button closeBtn = new Button(VaadinIcon.CLOSE_SMALL.create());

    return closeBtn;
}
```

**React** — `notification-rich.tsx`

```tsx
{/* The duration is set to 0-sec to prevent the notification from auto-close. */}
<Notification duration={0} theme="success" position="middle" opened>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <Icon icon="vaadin:check-circle" />
    <div>Application submitted!</div>
    <Button slot="end">View</Button>
    <Button slot="end" theme="icon" aria-label="Close">
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>

<Notification duration={0} theme="error" position="middle" opened>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <Icon icon="vaadin:warning" />
    <div>Failed to generate report</div>
    <Button slot="end">Retry</Button>
    <Button slot="end" theme="icon" aria-label="Close">
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>

<Notification duration={0} position="middle" opened>
  <HorizontalLayout theme="spacing" style={{ alignItems: 'center', minWidth: '350px' }}>
    <Avatar name="Jason Bailey" />
    <div>
      <b>Jason Bailey</b> mentioned you in <a href="#">Project Q4</a>
    </div>
    <Button slot="end" theme="icon" aria-label="Close">
      <Icon icon="lumo:cross" />
    </Button>
  </HorizontalLayout>
</Notification>
```

## <a id="helper-statico"></a>Helper Statico

Per notifiche semplici, una tantum, è comodo utilizzare il metodo helper statico `show()`. L’helper gestisce il ciclo di vita della notifica, e la aggiunge e rimuove dal DOM, automaticamente.

**Flow**

```java
// Mostra una semplice notifica basata su testo
Notification notification = Notification.show("Financial report generated");
notification.setPosition(Notification.Position.MIDDLE);
```

**React**

```tsx
import { Notification } from '@vaadin/react-components';

// Mostra una semplice notifica basata su testo
Notification.show('Financial report generated', {
  position: 'middle',
});
```

**Lit**

```typescript
import { html } from 'lit';
import { Notification } from '@vaadin/notification';

// Mostra una semplice notifica basata su testo
Notification.show('Financial report generated', {
  position: 'middle',
});

// Mostra una notifica con markup usando un template Lit
Notification.show(
  html`
    <b>@John:</b>
    &nbsp;
    <span>
      Che ne dice di pranzo alle
      <i>12:30pm</i>?
    </span>
  `,
  { position: 'middle' }
);
```

## <a id="best-practices"></a>Best Practices

### <a id="usare-con-parsimonia"></a>Usare con Parsimonia

Le notifiche sono dirompenti per progettazione e dovrebbero essere utilizzate con parsimonia. Utilizzare meno notifiche riservandole a informazioni più importanti che altrimenti potrebbero passare inosservate all’utente.

Le notifiche meno urgenti possono essere fornite tramite un link o un menu a tendina nell’header o nel footer dell’applicazione, invece che tramite notifiche immediate.

**Lit** — `notification-popup.ts`

```typescript
protected override render() {
  return html`
    <vaadin-button id="target" aria-label="notifications" theme="tertiary icon">
      <vaadin-icon icon="lumo:bell"></vaadin-icon>
      <vaadin-badge number="4" theme="error filled"></vaadin-badge>
    </vaadin-button>
    <vaadin-popover for="target">
      <div>Show notifications here</div>
    </vaadin-popover>
  `;
}
```

**Flow** — `NotificationPopup.java`

```java
var bellBtn = new MessagesButton();
bellBtn.setUnreadMessages(4);
bellBtn.setAriaLabel("notifications");

Popover popover = new Popover();
popover.setTarget(bellBtn);
Div content = new Div("Show notifications here");
popover.add(content);
```

**React** — `notification-popup.tsx`

```tsx
<>
  <Button id="target" aria-label="notifications" theme="tertiary icon">
    <Icon icon="lumo:bell" />
    <Badge
      number={4}
      theme="error filled"
      style={{ position: 'absolute', transform: 'translate(-40%, -30%)' }}
    />
  </Button>
  <Popover for="target">
    <div>Show notifications here</div>
  </Popover>
</>
```

### <a id="limitare-la-lunghezza-del-contenuto"></a>Limitare la Lunghezza del Contenuto

Le notifiche dovrebbero essere brevi e andare dritte al punto. Cercare di limitare il contenuto a una o due righe. Ulteriori informazioni possono essere fornite tramite un link incorporato o un Button.

Mostrare un’anteprima di contenuti più lunghi, e collegare ai dettagli completi.

`notification-content-length-do.ts`

```typescript
import '@vaadin/button';
import '@vaadin/horizontal-layout';
import '@vaadin/icon';
import '@vaadin/notification';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import { html, LitElement } from 'lit';
import { applyTheme } from 'Frontend/demo/theme';

export class Example extends LitElement {
  protected override createRenderRoot() {
    const root = super.createRenderRoot();
    applyTheme(root);
    return root;
  }

  protected override render() {
    return html`
      <vaadin-notification-card slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>
            <div>Aria Bailey</div>
            <div style="font-size: 0.875rem; color: var(--vaadin-text-color-secondary);">
              Yeah, I know. But could you help me with...
            </div>
          </div>
          <vaadin-button slot="end">View</vaadin-button>
          <vaadin-button slot="end" theme="icon">
            <vaadin-icon icon="lumo:cross"></vaadin-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
```

Non mostrare tutti i dettagli nella notifica.

`notification-content-length-dont.ts`

```typescript
import '@vaadin/button';
import '@vaadin/horizontal-layout';
import '@vaadin/icon';
import '@vaadin/notification';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import { html, LitElement } from 'lit';
import { applyTheme } from 'Frontend/demo/theme';

export class Example extends LitElement {
  protected override createRenderRoot() {
    const root = super.createRenderRoot();
    applyTheme(root);
    return root;
  }

  protected override render() {
    return html`
      <vaadin-notification-card slot="middle">
        <vaadin-horizontal-layout theme="spacing" style="align-items: center;">
          <div>
            <div>New message from Aria Bailey</div>
            <div style="font-size: 0.875rem; color: var(--vaadin-text-color-secondary);">
              Yeah, I know. But could you help me with this. I’m not sure where the bug is in my
              CSS? The checkmark doesn’t get the right color. I’m trying to use the CSS custom
              properties from our design system, but for some reason it’s not working.
            </div>
          </div>
          <vaadin-button slot="end" theme="icon">
            <vaadin-icon icon="lumo:cross"></vaadin-icon>
          </vaadin-button>
        </vaadin-horizontal-layout>
      </vaadin-notification-card>
    `;
  }
}
```

## <a id="componenti-correlati"></a>Componenti Correlati

| Component                                                        | Raccomandazione d’Uso                                                                                                       |
| ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| [Dialog](https://vaadin.com/docs/latest/it/components/dialog.md) | Dialog dovrebbe essere utilizzato al posto di Notification per qualsiasi cosa che richieda un’azione immediata dell’utente. |

`77E15AD0-F634-4D81-8C4D-FAC7A21D889B`
