No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.


  

ChAlert

Компонент для отображения алертов

Usage

<template>
  <ChAlert
    ref="alertRef"
    duration="5000"
    persistent
  >
    <template #default="{ content }">
      <p>{{ content }}</p>
    </template>
    <template #icon>
      <ChAlertIcon>Icon</ChAlertIcon>
    </template>
    <template #footer>
      <ChAlertButton>Button</ChAlertButton>
    </template>
  </ChAlert>
</template>

<script>
  import { ref } from 'vue'
  import { ChAlert, ChAlertIcon, ChAlertButton } from 'choco-ui'

  const alertRef = ref()

  alertRef.show('Alert content') // Shows alert with content == 'Alert content'
  alertRef.hide() // Hides alert
</script>

Props

НазваниеТипDefault valueОписание
durationNumber5000Время, после которого алерт должен автоматически закрываться. В миллисекундах
persistentBooleanfalseЕсли true, то алерт не исчезнет по истечению duration. В этом случае закрыть его можно только вызвав метод hide

Methods

ChAlert предоставляет public методы show, hide и переменную isVisible для отображения/скрытия алерта.

Для того, чтобы использовать эти public api нужно добавить ref на ChAlert

<template>
  <ChAlert ref="alertRef">
    <template #default="{ content }">
      <p>{{ content.main }}</p>
    </template>
    <template #footer="{ content }">
      <p>{{ content.footer }}</p>
    </template>
  </ChAlert>
</template>

<script>
  import { ref } from 'vue'
  import { ChAlert } from 'choco-ui'

  const alertRef = ref()

  alertRef.show({ main: 'Content may be of any type', footer: 'This is footer content' }) // Shows alert
  alertRef.hide() // Hides alert
</script>
НазваниеТипОписание
showFunctionМетод для отображения алерта. Может быть вызван с параметрами, которые будут записаны в поле content
hideFunctionМетод для закрытия алерта
isVisibleReadonly<Boolean>Возвращает открыт ли алерт или нет

Slots

НазваниеОписание
defaultГлавный контент алерта
iconСлот для иконки алерта. Для иконки лучше использовать ChAlertIcon компонент
footerСлот для контента в footer алерта. Для иконки лучше использовать ChAlertButton компонент