CommonNotifications.story.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!-- Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { ref } from 'vue'
  4. import CommonNotifications from './CommonNotifications.vue'
  5. import useNotifications from './composable'
  6. import type { NewNotification } from './types'
  7. import { NotificationTypes } from './types'
  8. const types = [
  9. NotificationTypes.Error,
  10. NotificationTypes.Warn,
  11. NotificationTypes.Success,
  12. NotificationTypes.Info,
  13. ]
  14. const selectedType = ref(NotificationTypes.Success)
  15. const { notify } = useNotifications()
  16. const showNotification = (options: Partial<NewNotification> = {}) => {
  17. notify({
  18. message: 'This is a notification message',
  19. persistent: false,
  20. type: selectedType.value,
  21. durationMS: 5000,
  22. ...options,
  23. })
  24. }
  25. // eslint-disable-next-line no-alert
  26. const alert = (msg: string) => window.alert(msg)
  27. </script>
  28. <template>
  29. <Story>
  30. <Variant title="Default">
  31. <template #controls>
  32. <HstSelect
  33. v-model="selectedType"
  34. title="Notification Type"
  35. :options="types"
  36. />
  37. </template>
  38. <div>
  39. <button @click="showNotification()">Show Notification</button>
  40. </div>
  41. <button
  42. @click="
  43. showNotification({
  44. persistent: true,
  45. callback: () => {
  46. alert('Callback executed.')
  47. },
  48. })
  49. "
  50. >
  51. Notification with callback
  52. </button>
  53. <CommonNotifications />
  54. </Variant>
  55. </Story>
  56. </template>