Raccourci clavier : Ctrl + K
Commencer

Barre de confirmation

La confirmation d'une action qui vient d'être faite, avec un bouton pour revenir dessus. Seule la dernière vaut la peine d'être proposée : une nouvelle barre remplace donc celle affichée au lieu de s'empiler sous elle.

Utilisation

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'

function remove() {
  snackbar({ message: 'Message deleted.', actionText: 'Undo', action: () => {} })
}
</script>

<template>
  <!-- Mount <VSnackbar /> once, at the root of your application. This site does it in its layout,
       which is why the example does not: a second one would render the same bar twice. -->
  <VButton variant="outline" tone="neutral" @click="remove">Delete</VButton>
</template>

Exemples

Tonalités

tone propose deux valeurs et pas plus : une confirmation dit soit que cela a marché, soit que non. Les deux sont peintes en solid.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <!-- Raised into the <VSnackbar /> mounted once at the root of the application. -->
  <div class="demo">
    <!-- Two tones and deliberately no more: a confirmation says either "done" or "that
         did not work". Success, warning and the accent are states, which is what a
         notification reports. -->
    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Conversation archived.', action: () => {} })"
    >
      Archive
    </VButton>

    <VButton
      variant="outline"
      tone="danger"
      @click="
        snackbar({
          tone: 'danger',
          message: 'Could not save your changes.',
          actionText: 'Retry',
          action: () => {},
        })
      "
    >
      Failing action
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

Sans action

Sans action, la barre ne porte aucun bouton. Quand il y en a un, l'exécuter retire toujours la barre.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <!-- Raised into the <VSnackbar /> mounted once at the root of the application. -->
  <!-- No `action`, no button at all. The bar is then a plain statement of what just
       happened, and it takes itself away on its own. -->
  <VButton variant="outline" tone="neutral" @click="snackbar({ message: 'Settings saved.' })">
    Save
  </VButton>
</template>

Avec une icône

icon est optionnelle, et aucune n'est déduite du ton.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
import { cloud_upload as cloudUpload } from 'vectis-ui/icons'
</script>

<template>
  <!-- Raised into the <VSnackbar /> mounted once at the root of the application. -->
  <!-- An icon is opt-in, and none is deduced from the tone: a confirmation is read,
       not scanned, so the words carry it and the icon only ever adds to them. -->
  <VButton
    variant="outline"
    tone="neutral"
    @click="snackbar({ message: 'File uploaded.', icon: cloudUpload, action: () => {} })"
  >
    Upload
  </VButton>
</template>

Placements

placement pose la barre le long du bord inférieur, au début, au centre ou à la fin. Posé sur le VSnackbar, il est la valeur par défaut de toutes les barres ; passé au moment d'en lever une, il n'appartient qu'à elle.

vue
<script setup lang="ts">
import { VButton, snackbar, type SnackbarPlacement } from 'vectis-ui'

const placements: SnackbarPlacement[] = ['bottom-left', 'bottom-center', 'bottom-right']
</script>

<template>
  <!-- Raised into the <VSnackbar /> mounted once at the root of the application. -->
  <div class="demo">
    <!-- Along the bottom edge and nowhere else: a confirmation belongs where it is out
         of the content's way and close to what the reader was doing. Set on the
         VSnackbar it is the default for every bar; passed here it is this bar's own. -->
    <VButton
      v-for="placement in placements"
      :key="placement"
      variant="outline"
      tone="neutral"
      @click="snackbar({ placement, message: `Raised at ${placement}.`, action: () => {} })"
    >
      {{ placement }}
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

Une seule à la fois

Il n'y a au plus qu'une barre : en lever une seconde remplace la première sur-le-champ, compte à rebours relancé.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <!-- Raised into the <VSnackbar /> mounted once at the root of the application. -->
  <div class="demo">
    <!-- There is at most one bar. Raising a second replaces the first on the spot and
         restarts the countdown from the top, which is what separates a confirmation
         from a notification: two states can be true at once, but only the last action
         a reader took is worth offering to undo. -->
    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Message deleted.', duration: 0, action: () => {} })"
    >
      Delete
    </VButton>

    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Conversation archived.', duration: 0, action: () => {} })"
    >
      Archive
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

Combien de temps elle reste

duration est la durée d'affichage de la barre, quatre secondes par défaut. Le compte à rebours se suspend tant que le pointeur est sur la barre et tant que le clavier y est, et ne repart que lorsque les deux sont partis.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <!-- Raised into the <VSnackbar /> mounted once at the root of the application. -->
  <div class="demo">
    <!-- Four seconds by default, shorter than a notification's: the reader already
         knows what the bar says, having just done it. The countdown holds while the
         pointer rests on the bar and while the keyboard is inside it, so an action
         being reached for is never taken away mid-reach. -->
    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Gone in 1.5 seconds.', duration: 1500, action: () => {} })"
    >
      1.5 seconds
    </VButton>

    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Gone in 8 seconds.', duration: 8000, action: () => {} })"
    >
      8 seconds
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

La garder jusqu'à ce qu'on la retire

Une duration de 0 désarme le compte à rebours : la barre reste jusqu'à ce que quelque chose la remplace ou la retire. snackbar rend un identifiant, et dismissSnackbar retire cette barre.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VButton, dismissSnackbar, snackbar } from 'vectis-ui'

const id = ref<number | null>(null)

function raise() {
  // `snackbar` hands back an id, which is what lets this bar be taken away later and
  // only this one: a stale id is ignored rather than closing whatever replaced it.
  id.value = snackbar({ message: 'Stays until you take it away.', duration: 0 })
}
</script>

<template>
  <!-- Raised into the <VSnackbar /> mounted once at the root of the application. -->
  <div class="demo">
    <!-- A duration of 0 disarms the countdown: the bar then stays until something
         replaces it or takes it away. Reserve it for a confirmation the reader has to
         act on, and give it a way out. -->
    <VButton variant="outline" tone="neutral" @click="raise">Raise</VButton>

    <VButton variant="outline" tone="neutral" @click="dismissSnackbar(id ?? undefined)">
      Dismiss
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

API

Props

PropTypeDéfaut
placementSnackbarPlacement'bottom-left' | 'bottom-center' | 'bottom-right''bottom-center'
À quelle extrémité du bord inférieur les confirmations apparaissent, sauf si l'une d'elles en demande une autre.
durationnumber4000
Combien de temps une confirmation reste, en millisecondes, sauf si elle demande autre chose. Une confirmation à qui l'on donne 0 reste jusqu'à ce qu'elle soit remplacée ou retirée à la main.
actionTextstringaucune
Le mot affiché sur l'unique action, quand la confirmation n'en donne pas. C'est aussi le nom accessible du bouton, et il retombe sur le dictionnaire du design system.
labelstringaucune
Ce que les lecteurs d'écran annoncent pour la zone de confirmation elle-même, qui est un point de repère de la page. Il retombe sur le dictionnaire du design system.

Variables CSS

TokenValeur
--vectis-control-size-snackbar-min18rem
--vectis-control-size-snackbar-max36rem