Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom template #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/components/Snotify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
<div>
<div class="snotify-backdrop" v-if="backdrop >= 0" :style="{opacity: backdrop}"></div>
<div v-for="(position, index) in notifications" class="snotify" :class="'snotify-' + index">
<slot name="toast"
v-for="toast in notifications[index].slice(blockSize_a, blockSize_b)"
:snotify="{stateChanged: stateChanged, toast:toast}">
<toast :toastData="toast" :key="toast.id" @stateChanged="stateChanged" />
</slot>
<toast v-for="toast in notifications[index].slice(blockSize_a, blockSize_b)"
:toastData="toast"
:key="toast.id"
@stateChanged="stateChanged" />
</div>
</div>
</template>
Expand Down
53 changes: 24 additions & 29 deletions src/components/SnotifyToast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,41 @@
@mouseleave="onMouseLeave"
@animationend="onExitTransitionEnd">

<slot name="progressBar" v-if="toast.config.showProgressBar && toast.config.timeout > 0" :state="state">
<div class="snotifyToast__progressBar">
<span class="snotifyToast__progressBar__percentage" :style="{'width': (state.progress * 100) + '%'}"></span>
</div>
</slot>
<div v-if="toast.config.showProgressBar && toast.config.timeout > 0"
class="snotifyToast__progressBar">
<span class="snotifyToast__progressBar__percentage" :style="{'width': (state.progress * 100) + '%'}" />
</div>

<div class="snotifyToast__inner" v-if="!toast.config.html">
<slot name="inner" :toast="toast">
<slot name="title" :toast="toast" v-if="toast.title">
<div class="snotifyToast__title">{{toast.title | truncate(toast.config.titleMaxLength)}}</div>
</slot>
<slot name="body" :toast="toast" v-if="toast.body">
<div class="snotifyToast__body">{{toast.body | truncate(toast.config.bodyMaxLength)}}</div>
</slot>
<slot name="prompt" :toast="toast" v-if="toast.config.type === state.promptType">
<snotify-prompt :toast="toast">
</snotify-prompt>
</slot>
<slot name="icon" :toast="toast">
<div v-if="!toast.config.icon" :class="['snotify-icon', 'snotify-icon--' + toast.config.type]"></div>
<div v-else>
<img class="snotify-icon" :src='toast.config.icon'/>
<div v-if="!toast.config.html"
class="snotifyToast__inner"
:class="{'snotifyToast__noIcon': toast.config.icon === false}">
<div class="snotifyToast__inner-row">
<div v-if="typeof toast.config.icon === 'undefined'"
:class="['snotify-icon', 'snotify-icon--' + toast.config.type]" />
<div v-else-if="toast.config.icon !== false" class="snotifyToast__icon">
<svg><use :xlink:href="toast.config.icon" /></svg>
</div>
<div>
<div v-if="toast.title" class="snotifyToast__title">
{{toast.title | truncate(toast.config.titleMaxLength)}}
</div>
<div v-if="toast.body" class="snotifyToast__body">
{{toast.body | truncate(toast.config.bodyMaxLength)}}
</div>
</slot>
</slot>
<snotify-prompt v-if="toast.config.type === state.promptType" :toast="toast"/>
</div>
</div>
<snotify-button v-if="toast.config.buttons" :toast="toast" />
</div>
<div class="snotifyToast__inner" v-html="toast.config.html" v-else></div>

<slot name="buttons" :toast="toast" v-if="toast.config.buttons">
<snotify-button v-if="toast.config.buttons" :toast="toast"></snotify-button>
</slot>
</div>

</template>

<script lang="ts">
import Vue from 'vue';
import SnotifyPrompt from './SnotifyPrompt.vue';
import SnotifyButton from './SnotifyButton.vue';
import {SnotifyStyle} from '../enums';
import { isBoolean } from 'util';

export default Vue.extend({
props: ['toastData'],
Expand Down