1.1.1 • Published 1 year ago

vue-flare v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Vue Flare - notifications for Vue 3 and Nuxt 3

The goal was to create simple, easy to set up notifications for Vue 3 in a beautiful design that no app or website would be ashamed of.

Check out the demo vue-flare.web.app

Alt text

Installation

# npm
npm install --save vue-flare

# yarn
yarn add vue-flare

Setup with Vue 3

// main.ts

import "vue-flare/dist/style.css"
import VueFlare from "vue-flare"

createApp(App).use(VueFlare, {
  position: 'top-right',
  animation: 'fade-in',
  borderRadius: false,
  backdropFilterBlur: false,
  duration: 5000,
  maxWidth: '400px',
  displayFromTop: true,
  duplicationEnabled: true,
}).mount('#app')

Setup with Nuxt 3

// plugins/vue-flare.ts

import VueFlare from "vue-flare"

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueFlare)
})
// nuxt.config.ts

export default defineNuxtConfig({
  css: ["~/node_modules/vue-flare/dist/style.css"]
})

Usage

<!-- App.vue -->

<template>
    <div>
        {{ activeFlares }}
        {{ activeSettings }}
        <Flares />
        <div>
            <button @click='show'>show</button>
            <button @click='hide'>hide</button>
            <button @click='setNewSettings'>set new settings</button>
        </div>
    </div>
</template>
// App.vue

import { computed, inject } from "vue";
import { Flares, FlareInterface } from "vue-flare"

// Access to the plugin
const flare = inject('flare') as FlareInterface

const activeFlares = computed(() => flare.flares.value)
const activeSettings = computed(() => flare.settings.value)

function show () {
    // Examples
    flare.success({ title: "Success" })
    flare.info({ title: "Info", message: "Message" })
    flare.warning({ title: "Info", message: "Message", duration: 10000 })
    flare.error({ id: '78dd0a2b', title: "Info", message: "Message" })

    // All the settings
    flare.info({
        id: '78dd0a2c',  
        title: "Info", 
        message: "Message",
        duration: 20000,
        hasIcon: false,
        hasLoading: false,
        closable: false
    })
}

function hide () {
    flare.hide('78dd0a2b')
}

function setNewSettings () {
    flare.setSettings({
        position: 'bottom-right',
        animation: 'fade-right',
        borderRadius: true,
        backdropFilterBlur: true,
        duration: 3000,
        maxWidth: '600px',
        displayFromTop: false,
        duplicationEnabled: false
    })
}

You can even use global property $flare

<button @click='$flare.success({
    id: "78dd0a2b",
    title: "Info",
    message: "Message"
  })'>
show
</button>

Customization

You can use custom component for notifications inside the <Flares /> component

<!-- App.vue -->

<template>
  <div>
    <Flares>
      <Flare
          v-for="{ id, type, title, message, duration, hasIcon, hasLoading, closable } of flare.flares.value"
          :key="`flare-${id}`"
          :type="type"
          :title="title"
          :message="message"
          :duration="duration"
          :has-icon="hasIcon"
          :has-loading="hasLoading"
          :closable="closable"
          animation="fade-in"
          border-radius
          backdrop-filter-blur
          @close="flare.hide(id)"
      />
    </Flares>
  </div>
</template>

Custom styles

// main.scss

.flares {
  &-top-left {}
  &-top-right {}
  &-top-center {}
  &-bottom-left {}
  &-bottom-right {}
  &-bottom-center {}
}

.flare {
  &-border-radius {}
  &-backdrop-filter-blur {}
  &-has-icon {}
  
  &-animation-fade-in {}
  &-animation-fade-top {}
  &-animation-fade-right {}
  &-animation-fade-bottom {}
  &-animation-fade-left {}
  
  &-loading {}
  &-icon {}
  &-title {}
  &-message {}
  &-close {
    &:hover {}
    svg {}
  }
  
  &-success {
    // light - #1fa55a
    // dark - #0e5f38
    &.flare-backdrop-filter-blur {}
    .flare-icon, .flare-close {}
    .flare-loading {}
  }
  
  &-info {
    // light - #1f6fe0
    // dark - #10488a
    &.flare-backdrop-filter-blur {}
    .flare-icon, .flare-close {}
    .flare-loading {}
  }
  
  &-warning {
    // light - #ee8d31
    // dark - #c34916
    &.flare-backdrop-filter-blur {}
    .flare-icon, .flare-close {}
    .flare-loading {}
  }
  
  &-error {
    // light - #dc3055
    // dark - #851d41
    &.flare-backdrop-filter-blur {}
    .flare-icon, .flare-close {}
    .flare-loading {}
  }
}

Props

<Flare />

<Flare
    type="success"
    title="Title"
    message="Message"
    animation="fade-in"
    border-radius="false"
    backdrop-filter-blur="false"
    has-icon
    has-loading
    closable
    :duration="5000"
/>
NameDescriptionTypeValuesDefault
type*TypeStringsuccess info warning error
title*TitleString
animationAnimationStringfade-in fade-top fade-right fade-bottom fade-leftfade-in
messageMessageString''
duration*Duration of the flareNumber
borderRadiusBorder radius on the flareBooleanfalse
backdropFilterBlurBlurred background on the flareBooleanfalse
hasIconVisible iconBooleantrue
hasLoadingVisible loading barBooleantrue
closableVisible close iconBooleantrue

flare.setSettings({ ...options })

flare.setSettings({
    position: 'top-right',
    animation: 'fade-in',
    borderRadius: false,
    backdropFilterBlur: false,
    duration: 5000,
    maxWidth: '400px',
    displayFromTop: true,
    duplicationEnabled: true
})
NameDescriptionTypeValuesDefault
positionPosition of the flaresStringtop-left top-right top-center bottom-left bottom-right bottom-centertop-right
animationAnimationStringfade-in fade-top fade-right fade-bottom fade-leftfade-in
borderRadiusBorder radius on the flareBooleanfalse
backdropFilterBlurBlurred background on the flareBooleanfalse
durationDuration of the flares in milisecondsNumber5000
maxWidthMax width of flares in px or %String400px
displayFromTopAdds new notifications from the top, otherwise from the bottomBooleantrue
duplicationEnabledAllows you to have multiple notifications of the same type in the stackBooleantrue

Development

Make sure to install the dependencies and then run:

# yarn
yarn dev

# npm
npm run dev
1.1.1

1 year ago

1.1.0

1 year ago

0.9.0

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago