Skip to content

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 ​

PropTypeDefaultDescription
valueBooleantruev-model control
titleString''Toast title
subtitleString''Toast subtitle
primaryTextString''Primary button text
secondaryTextString''Secondary link text
positionStringbottom-rightToast position
effectStringnoneAnimation effect
storageKeyString''localStorage key
stackGapNumber12Gap between stacked toasts

πŸ“£ Events ​

EventWhen
@primaryPrimary button clicked
@dont-show-againSecondary clicked
@closeClose button clicked
@inputv-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"
/>