Toast siwo wotsɔna ɖaa nu
Tsɔ toast, si nye nuxlɔ̃ame gbedasi si ƒe kpekpeme le bɔbɔe eye woate ŋu atrɔ asi le eŋu bɔbɔe la ƒo nyatakakawo na wò amedzrowo.
Toasts nye nyatakaka siwo le bɔbɔe siwo wowɔ be woasrɔ̃ push notifications siwo asitelefon kple kɔmpiuta dɔwɔɖoɖowo va xɔ ŋkɔ la. Wotu wo kple flexbox, eyata wole bɔbɔe be woaɖo wo ɖe ɖoɖo nu ahaɖo wo ɖe teƒe ɖeka.
Kpɔɖeŋunyagbɔgblɔ
Nusiwo wòle be nànya ne èle toast plugin la zãm:
- Toasts nyea tiatiawɔwɔ le dɔwɔwɔ ƒe susuwo ta, eyata ele be wò ŋutɔ nàdze wo gɔme .
- Toasts aɣla le eɖokui si ne mègblɔe o
autohide: false
.
prefers-reduced-motion
nyadzɔdzɔgblɔmɔnuwo ƒe nyabiasea dzi. Kpɔ
míaƒe mɔnukpɔkpɔwo ŋuti nuŋlɔɖiwo ƒe akpa si woɖe dzi kpɔtɔ .
Kpɔɖeŋuwo
Gɔmedzenu
Be míade toast siwo woate ŋu akeke ɖe enu eye woate ŋu agblɔe ɖi ƒe dzi ƒo la, míeɖo aɖaŋu be woatsɔ ta kple ŋutilã awɔ dɔe. Toast headers use display: flex
, si ɖea mɔ be woaɖo nyatakakawo ɖe ɖoɖo nu bɔbɔe akpe ɖe míaƒe margin kple flexbox utilities ta.
Toastwo te ŋu trɔna ɖe nɔnɔmewo ŋu abe alesi nèhiã ene eye dzesidenu ʋɛ aɖewo koe wobia tso wo si. Ne mede ɖeke o la, míebiaa nu ɖeka aɖe si me wò “toasted” me nyawo nanɔ eye míedea dzi ƒo na wò vevie be nàɖe asi le eŋu.
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
.hide
klass la kpena ɖe eŋu le mɔ si trɔna nu be woaɣla toast aɖe keŋkeŋ (kple
display:none
, ke menye kple ko o
opacity:0
). Esia megahiã fifia o. Ke hã, le megbenyawo ƒe sɔsɔ ta la, míaƒe nuŋɔŋlɔa ayi edzi atrɔ asi le klass la ŋu (togbɔ be mehiã ŋutɔŋutɔ o hã) vaseɖe esime woawɔ tɔtrɔ gã si kplɔe ɖo.
Kpɔɖeŋu si le agbe
Zi dzesi si le ete dzi be nàkpɔ toast (si woɖo ɖe teƒe si míaƒe dɔwɔnuwo le le ɖusime le ete) si woɣla le gɔmedzedzea me.
<button type="button" class="btn btn-primary" id="liveToastBtn">Show live toast</button>
<div class="toast-container position-fixed bottom-0 end-0 p-3">
<div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
Míezãa JavaScript si gbɔna tsɔ dzea míaƒe live toast demo la gɔme:
const toastTrigger = document.getElementById('liveToastBtn')
const toastLiveExample = document.getElementById('liveToast')
if (toastTrigger) {
toastTrigger.addEventListener('click', () => {
const toast = new bootstrap.Toast(toastLiveExample)
toast.show()
})
}
Nusi me kɔ nyuie
Toastwo me kɔ vie be woatsaka kple nusiwo le wo te.
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
Nuƒoƒoƒu ɖe wo nɔewo dzi
Àte ŋu aƒo toastwo nu ƒu to wo babla ɖe toast nugoe me, si ana dometsotso aɖewo nanɔ wo nɔewo ŋu le tsitrenu.
<div class="toast-container position-static">
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">just now</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
See? Just like this.
</div>
</div>
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">2 seconds ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Heads up, toasts will stack automatically
</div>
</div>
</div>
Nyatakaka siwo wowɔ ɖe ɖoɖo nu
Trɔ asi le wò toasts ŋu to akpa suewo ɖeɖeɖa me, asitɔtrɔ le wo ŋu kple utilities , alo to wò ŋutɔ wò dzesidenu tsɔtsɔ kpee me. Le afisia la, míewɔ toast si le bɔbɔe wu to default la ɖeɖeɖa me .toast-header
, tsɔ ɣla dzesi si wowɔ ɖe ɖoɖo nu kpe ɖe Bootstrap Icons ŋu , eye míezã flexbox dɔwɔnu aɖewo tsɔ trɔ asi le ɖoɖoa ŋu.
<div class="toast align-items-center" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
Hello, world! This is a toast message.
</div>
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
Alo àte ŋu atsɔ nu bubu siwo dzi woaɖu kple nusiwo le eme hã akpe ɖe toastwo ŋu.
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body">
Hello, world! This is a toast message.
<div class="mt-2 pt-2 border-top">
<button type="button" class="btn btn-primary btn-sm">Take action</button>
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="toast">Close</button>
</div>
</div>
</div>
Amadedewo ƒe ɖoɖowo
Ne ètu kpɔɖeŋu si le etame la, àte ŋu awɔ toast ƒe amadede vovovowo kple míaƒe amadede kple megbe dɔwɔnuwo. Afisiae míetsɔ kpe .text-bg-primary
ɖe .toast
, eye emegbe míetsɔ kpe .btn-close-white
ɖe míaƒe nutrenu ƒe dzesi ŋu. Ne èdi be yeakpɔ nugbɔ si le ʋuʋu ɖi la, míeɖea liƒo si woɖo ɖi la ɖa kple .border-0
.
<div class="toast align-items-center text-bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
Hello, world! This is a toast message.
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
Amewo ɖoɖo ɖe teƒe aɖe
De toasts kple CSS si wowɔ ɖe ɖoɖo nu la ɖe teƒe si nèhiã wo. Zi geɖe la, wozãa ɖusime si le etame hena nyatakakawo nana, abe alesi wozãa titina si le etame ene. Ne toast ɖeka koe nàɖe afia gbeɖeka le ɣeyiɣi ɖeka me la, ke da alesi woɖoa nu ɖe teƒea ƒe atsyãwo ɖe .toast
.
<form>
<div class="mb-3">
<label for="selectToastPlacement">Toast placement</label>
<select class="form-select mt-2" id="selectToastPlacement">
<option value="" selected>Select a position...</option>
<option value="top-0 start-0">Top left</option>
<option value="top-0 start-50 translate-middle-x">Top center</option>
<option value="top-0 end-0">Top right</option>
<option value="top-50 start-0 translate-middle-y">Middle left</option>
<option value="top-50 start-50 translate-middle">Middle center</option>
<option value="top-50 end-0 translate-middle-y">Middle right</option>
<option value="bottom-0 start-0">Bottom left</option>
<option value="bottom-0 start-50 translate-middle-x">Bottom center</option>
<option value="bottom-0 end-0">Bottom right</option>
</select>
</div>
</form>
<div aria-live="polite" aria-atomic="true" class="bg-dark position-relative bd-example-toasts">
<div class="toast-container p-3" id="toastPlacement">
<div class="toast">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
</div>
Le ɖoɖo siwo wɔa nyatakaka geɖe wu gome la, bu nusi wotsɔ blaa nu zazã ŋu ale be woate ŋu aƒo wo nu ƒu bɔbɔe.
<div aria-live="polite" aria-atomic="true" class="position-relative">
<!-- Position it: -->
<!-- - `.toast-container` for spacing between toasts -->
<!-- - `top-0` & `end-0` to position the toasts in the upper right corner -->
<!-- - `.p-3` to prevent the toasts from sticking to the edge of the container -->
<div class="toast-container top-0 end-0 p-3">
<!-- Then put toasts within -->
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">just now</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
See? Just like this.
</div>
</div>
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">2 seconds ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Heads up, toasts will stack automatically
</div>
</div>
</div>
</div>
Àte ŋu akpɔ fancy hã kple flexbox utilities be nàɖo toasts ɖe ɖoɖo nu le tsia dzi kple/alo le tsia dzi.
<!-- Flexbox container for aligning the toasts -->
<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center w-100">
<!-- Then put toasts within -->
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
Mɔnukpɔkpɔwo ƒe Mɔnukpɔkpɔ
Woɖoe be toasts nanye nu suesuesue siwo axe mɔ na wò amedzrowo alo ezãlawo, eyata be nàkpe ɖe amesiwo si screen reader le kple mɔ̃ɖaŋununya mawo tɔgbe siwo kpena ɖe ame ŋu le ŋu la, ele be nàxatsa wò toasts ɖe aria-live
nuto aɖe me . Tɔtrɔ siwo wowɔ le nuto siwo me wole me (abe toast ƒe akpa aɖe dodo/wɔ yeyee ene) la, screen readers ɖea gbeƒãe le wo ɖokui si evɔ mehiã be woaʋuʋu ezãla ƒe susu alo atso nya me le ezãla ŋu le mɔ bubu aɖeke nu o. Tsɔ kpe ɖe eŋu la, de eme aria-atomic="true"
be nàkpɔ egbɔ be woɖe gbeƒã toast bliboa ɣesiaɣi be enye nu ɖeka (atomik) ɖeka, tsɔ wu be nàɖe gbeƒã nusi wotrɔ ko (si ate ŋu ahe kuxiwo vɛ ne èwɔ toast la me nyawo ƒe akpa aɖe ko yeyee, alo ne èle toast la me nyawo ƒe akpa ma ke ɖem fia le ɣeyiɣi aɖe megbe). Ne nyatakaka siwo hiã la le vevie na dɔa, le kpɔɖeŋu me, na vodadawo ƒe xexlẽdzesi le agbalẽvi aɖe me la, ekema zã nuxlɔ̃ame ƒe akpaaɖe toast teƒe.
De dzesii be ele be nuto si le agbe la nanɔ dzesidenu la me hafi woawɔ toast la alo awɔ yeyee. Ne èwɔ evea siaa le ɣeyiɣi ɖeka me le mɔ si trɔna nu eye nèdo wo ɖe axaa dzi la, zi geɖe la, mɔ̃ɖaŋununya siwo kpena ɖe ame ŋu maɖe gbeƒã wo o.
Ele be nàtrɔ asi le role
kple aria-live
dzidzenu hã ŋu le emenyawo nu. Ne enye gbedasi vevi aɖe abe vodada ene la, zã role="alert" aria-live="assertive"
, ne menye nenema o la, zã role="status" aria-live="polite"
nɔnɔmewo.
Ne nyatakaka siwo nèle ɖem fia la le tɔtrɔm la, kpɔ egbɔ be yewɔ ɣeyiɣia ƒe delay
ɣeyiɣia yeyee ale be ɣeyiɣi si sɔ nasu ezãlawo si be woaxlẽ toast la.
<div class="toast" role="alert" aria-live="polite" aria-atomic="true" data-bs-delay="10000">
<div role="alert" aria-live="assertive" aria-atomic="true">...</div>
</div>
Ne èle , zãm autohide: false
la, ele be nàtsɔ nutrenu aɖe akpe ɖe eŋu be wòana ezãlawo naɖe asi le toast la ŋu.
<div role="alert" aria-live="assertive" aria-atomic="true" class="toast" data-bs-autohide="false">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
Togbɔ be le mɔ̃ɖaŋununya gome la, anya wɔ be nàtsɔ nusiwo dzi woate ŋu aɖo ŋkui/awɔ dɔ le (abe abɔta alo kadodo bubuwo ene) akpe ɖe wò toast ŋu hã la, ele be nàƒo asa na esia wɔwɔ na autohiding toasts. Even if you give the toast a long delay
timeout , keyboard kple kpekpeɖeŋu mɔ̃ɖaŋununya zãlawo ate ŋu asesẽ be woaɖo toast la gbɔ le ɣeyiɣi nyuitɔ dzi be woawɔ nane (esi toasts mexɔa susu ne woɖe wo fia o ta). Ne ele be nàgakpɔ ŋusẽ ɖe nu bubuwo dzi keŋkeŋ la, míele aɖaŋu ɖom be nàzã toast si me autohide: false
.
CSS ƒe ƒuƒoƒo
Nusiwo trɔna
Wotsɔe kpe ɖe eŋu le v5.2.0 meAbe Bootstrap ƒe CSS tɔtrɔwo ƒe mɔnu si le tɔtrɔm ƒe akpa aɖe ene la, toasts zãa teƒea ƒe CSS tɔtrɔwo le fifia .toast
hena ɣeyiɣi ŋutɔŋutɔ ƒe tɔtrɔwɔwɔ si nyo ɖe edzi. Woɖo asixɔxɔwo na CSS ƒe tɔtrɔwo to Sass dzi, eyata Sass ƒe tɔtrɔwɔwɔ gakpɔtɔ doa alɔ, hã.
--#{$prefix}toast-zindex: #{$zindex-toast};
--#{$prefix}toast-padding-x: #{$toast-padding-x};
--#{$prefix}toast-padding-y: #{$toast-padding-y};
--#{$prefix}toast-spacing: #{$toast-spacing};
--#{$prefix}toast-max-width: #{$toast-max-width};
@include rfs($toast-font-size, --#{$prefix}toast-font-size);
--#{$prefix}toast-color: #{$toast-color};
--#{$prefix}toast-bg: #{$toast-background-color};
--#{$prefix}toast-border-width: #{$toast-border-width};
--#{$prefix}toast-border-color: #{$toast-border-color};
--#{$prefix}toast-border-radius: #{$toast-border-radius};
--#{$prefix}toast-box-shadow: #{$toast-box-shadow};
--#{$prefix}toast-header-color: #{$toast-header-color};
--#{$prefix}toast-header-bg: #{$toast-header-background-color};
--#{$prefix}toast-header-border-color: #{$toast-header-border-color};
Sass ƒe tɔtrɔwo
$toast-max-width: 350px;
$toast-padding-x: .75rem;
$toast-padding-y: .5rem;
$toast-font-size: .875rem;
$toast-color: null;
$toast-background-color: rgba($white, .85);
$toast-border-width: $border-width;
$toast-border-color: var(--#{$prefix}border-color-translucent);
$toast-border-radius: $border-radius;
$toast-box-shadow: $box-shadow;
$toast-spacing: $container-padding-x;
$toast-header-color: $gray-600;
$toast-header-background-color: rgba($white, .85);
$toast-header-border-color: rgba($black, .05);
Zãzã
Dze toastwo gɔme to JavaScript dzi:
const toastElList = document.querySelectorAll('.toast')
const toastList = [...toastElList].map(toastEl => new bootstrap.Toast(toastEl, option))
Nusiwo ʋãa ame
Woateŋu awɔ asiɖeɖe le dɔ ŋu kple data
nɔnɔme si le abɔta aɖe dzi le toast la me abe alesi woɖee fia le ete ene:
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
alo le abɔta aɖe si le toast la godo dzi to data-bs-target
alesi woɖee fia le ete la zazã me:
<button type="button" class="btn-close" data-bs-dismiss="toast" data-bs-target="#my-toast" aria-label="Close"></button>
Tiatiawɔblɔɖewo
Esi woateŋu atsɔ tiatiawɔnuwo ato nyatakaka nɔnɔmewo alo JavaScript dzi ta la, àteŋu atsɔ tiatia ŋkɔ akpe ɖe data-bs-
, abe alesi wòle le data-bs-animation="{value}"
. Kpɔ egbɔ be yetrɔ tiatia ŋkɔa ƒe case type tso “ camelCase ” yi “ kebab-case ” ne èle tiatiaawo tom to data attributes dzi. Le kpɔɖeŋu me, zãe data-bs-custom-class="beautifier"
ɖe data-bs-customClass="beautifier"
.
Tso Bootstrap 5.2.0 dzi la, akpaawo katã doa alɔ dodokpɔ ƒe nyatakaka si wodzra ɖo ƒe nɔnɔme data-bs-config
si ateŋu axɔ akpa ƒe ɖoɖo bɔbɔe abe JSON ka ene. Ne element aɖe si data-bs-config='{"delay":0, "title":123}'
kple data-bs-title="456"
nɔnɔmewo le la, asixɔxɔ mamlɛtɔ title
anye 456
eye nyatakaka nɔnɔme vovovoawo axɔ asixɔxɔ siwo wona le data-bs-config
. Tsɔ kpe ɖe eŋu la, nyatakaka ƒe nɔnɔme siwo li fifia te ŋu tsɔa JSON ƒe asixɔxɔwo abe data-bs-delay='{"show":0,"hide":150}'
.
Ŋkɔ | Ƒomevi | Gᴐmedzeƒe | Nuɖᴐɖᴐ |
---|---|---|---|
animation |
boolean ƒe ƒuƒoƒo | true |
Zã CSS fade ƒe tɔtrɔ ɖe toast la ŋu. |
autohide |
boolean ƒe ƒuƒoƒo | true |
Ɣla toast la le ɖokuiwò si le megbededea megbe. |
delay |
xexlẽdzesi | 5000 |
He ɖe megbe le milisekɛnd me hafi nàɣla toast la. |
Mɔnuwo
Mɔnu siwo mewɔ ɖeka kple ɣeyiɣi aɖeke o kple tɔtrɔwo
API mɔnuwo katã nye asynchronous eye wodzea tɔtrɔ gɔme . Wotrɔna yia ame si le ka ƒom na la gbɔ ne wonya dze tɔtrɔa gɔme ko gake hafi wòwu enu . Tsɔ kpe ɖe eŋu la, woaŋe aɖaba aƒu mɔnu ƒe yɔyɔ aɖe dzi le akpa si le tɔtrɔm dzi .
Nuwɔmɔnu | Nuɖᴐɖᴐ |
---|---|
dispose |
Eɣlaa element aɖe ƒe toast. Wò toast la anɔ DOM la dzi gake magaɖee afia o. |
getInstance |
Static mɔnu si ɖea mɔ na wò be nàxɔ toast ƒe kpɔɖeŋu si do ƒome kple DOM element aɖe. Le kpɔɖeŋu me: const myToastEl = document.getElementById('myToastEl') const myToast = bootstrap.Toast.getInstance(myToastEl) Trɔ Bootstrap toast ƒe kpɔɖeŋu aɖe. |
getOrCreateInstance |
Static mɔnu si ɖea mɔ na wò be nàxɔ toast ƒe kpɔɖeŋu si do ƒome kple DOM element, alo awɔ yeye, nenye be womedze egɔme o. const myToastEl = document.getElementById('myToastEl') const myToast = bootstrap.Toast.getOrCreateInstance(myToastEl) Trɔ Bootstrap toast ƒe kpɔɖeŋu aɖe. |
hide |
Eɣlaa element aɖe ƒe toast. Trɔna yia ame si yɔe gbɔ hafi woɣla toast la ŋutɔŋutɔ (si nye hafi hidden.bs.toast nudzɔdzɔa nadzɔ). Ele be nàtsɔ asi ayɔ mɔnu sia ne èwɔe autohide be false . |
isShown |
Trɔ boolean le toast ƒe nukpɔkpɔ ƒe nɔnɔme nu. |
show |
Eɖea element aɖe ƒe toast fiana. Trɔna yia ame si yɔe gbɔ hafi woɖe toast la fia ŋutɔŋutɔ (si nye hafi shown.bs.toast nudzɔdzɔa nadzɔ). Ele be nàtsɔ asi ayɔ mɔnu sia, ke boŋ wò toast la maɖee afia o. |
Nudzɔdzɔwo
Nudzᴐdzᴐ | Nuɖᴐɖᴐ |
---|---|
hide.bs.toast |
Woɖea nudzɔdzɔ sia ɖa enumake ne woyɔ hide instance mɔnu la. |
hidden.bs.toast |
Wodoa nudzɔdzɔ sia ne toast la ɣla ɖe ezãla vɔ. |
show.bs.toast |
Nudzɔdzɔ sia doa dzo enumake ne woyɔ show kpɔɖeŋu mɔnu la. |
shown.bs.toast |
Wodoa wɔna sia ne wowɔ toast la wòdze na ezãla. |
const myToastEl = document.getElementById('myToast')
myToastEl.addEventListener('hidden.bs.toast', () => {
// do something...
})