CocToast β
CocToast is a reusable, stackable, glass-effect toast / notification component for Vue 2.
This component provides:
- Automatic stacking (no overlap)
- Multiple position support
- Glass / brand background styling
- Optional primary and secondary actions
- βDonβt show againβ handling using localStorage
- Flash-free behavior on page reload
π¦ Import β
js
const COCToast = () =>
import(
/* webpackChunkName: "coc-common" */ 'school@/components/common/COCToast.vue'
)
export default {
components: { CocToast },
}π§© Basic Usage β
js
<CocToast
v-model="showToast"
title="Plan expiring soon"
subtitle="Renew within 1 day(s) to keep access uninterrupted."
/>π― Positions β
Supported positions:
- top-left
- top-right
- bottom-left
- bottom-right
js
<CocToast v-model="showToast" position="top-right" title="Top right toast" />π Actions (Optional) β
Primary Action (Button)
js
<CocToast
v-model="showToast"
title="Plan expiring soon"
primary-text="Renew"
@primary="goToRenew"
/>Secondary Action (Link)
js
<CocToast
v-model="showToast"
title="Reminder"
secondary-text="Donβt show again"
storage-key="renewal_toast_hide"
/>βΉοΈ Secondary action behavior:
- Toast closes immediately
- Value is stored in localStorage (if storageKey is provided)
- Toast will not appear again after page reload
π¨ Effects β
Supported effects:
- none (default)
- pulse
- shake
- glow
js
<CocToast v-model="showToast" title="Attention required" effect="glow" />π¨ Icon Slot (Optional) β
js
<CocToast
v-model="showToast"
title="New update"
>
<template #icon>
π
</template>
</CocToast>π§ Auto Stacking (Built-in) β
When multiple CocToast components are shown in the same position:
js
<CocToast v-model="toast1" title="Toast one" />
<CocToast v-model="toast2" title="Toast two" />β Toasts stack automatically β Spacing adjusts dynamically based on content height β No index or counter is required
πΎ Remember Dismiss ("Donβt show again") β
js
<CocToast
v-model="showToast"
title="Plan expiring"
secondary-text="Donβt show again"
storage-key="plan_expiry_dismissed"
/>β Toast will not reappear after reload β No flicker or flash on page load
π Props β
| Prop | Type | Default | Description |
|---|---|---|---|
value | Boolean | true | v-model control |
title | String | '' | Toast title |
subtitle | String | '' | Toast subtitle |
primaryText | String | '' | Primary button text |
secondaryText | String | '' | Secondary link text |
position | String | bottom-right | Toast position |
effect | String | none | Animation effect |
storageKey | String | '' | localStorage key |
stackGap | Number | 12 | Gap between stacked toasts |
π£ Events β
| Event | When |
|---|---|
@primary | Primary button clicked |
@dont-show-again | Secondary clicked |
@close | Close button clicked |
@input | v-model update |
π― Example: Renewal Toast β
js
<CocToast
v-model="showRenewal"
title="Plan expiring soon"
subtitle="Renew within 1 day(s) to keep access uninterrupted."
primary-text="Renew"
secondary-text="Donβt show again"
position="top-right"
effect="pulse"
storage-key="renewal_dismissed"
@primary="goToBilling"
/>
Campus On Click