diff --git a/package.json b/package.json index 019832f..c993cd3 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "meshkeetoast", - "version": "0.1.0", + "version": "0.1.1", "main": "dist/MeshkeeToast.umd.js", - "style": "dist/theme-bootstrap.css", + "style": "dist/theme-default.css", "module": "dist/MeshkeeToast.esm.js", "unpkg": "dist/MeshkeeToast.min.js", "browser": { diff --git a/src/api.js b/src/api.js index 5e4018c..523556d 100644 --- a/src/api.js +++ b/src/api.js @@ -1,92 +1,93 @@ -import MeshkeeToast from './MeshkeeToast.vue' -import { createComponent } from './helpers'; -import eventBus from './bus.js'; -import Positions from './positions.js'; - -let parentTop = document.querySelector('.v-toast.v-toast--top'); -let parentBottom = document.querySelector('.v-toast.v-toast--bottom'); - -const correctParent = (position) => { - switch (position) { - case Positions.TOP: - case Positions.TOP_RIGHT: - case Positions.TOP_LEFT: - return parentTop; - - case Positions.BOTTOM: - case Positions.BOTTOM_RIGHT: - case Positions.BOTTOM_LEFT: - return parentBottom; - } -}; -const setupContainer = () => { - // No need to create them, they already exists - if (parentTop && parentBottom) return; - - if (!parentTop) { - parentTop = document.createElement('div'); - parentTop.className = 'v-toast v-toast--top'; - } - - if (!parentBottom) { - parentBottom = document.createElement('div'); - parentBottom.className = 'v-toast v-toast--bottom' - } - - const container = document.body; - container.appendChild(parentTop); - container.appendChild(parentBottom); -}; -export const useToast = (globalProps = {}) => { - return { - open(options) { - let message = null; - if (typeof options === 'string') message = options; - - const defaultProps = { - message - }; - - const propsData = Object.assign({}, defaultProps, globalProps, options); - setupContainer(); - console.log(propsData.position, correctParent(propsData.position ? propsData.position : 'bottom')); - const instance = createComponent(MeshkeeToast, propsData, correctParent(propsData.position ? propsData.position : 'bottom')); - return { - dismiss: instance.dismiss - } - }, - clear() { - eventBus.emit('toast-clear') - }, - success(message, options = {}) { - return this.open(Object.assign({}, { - message, - type: 'success' - }, options)) - }, - error(message, options = {}) { - return this.open(Object.assign({}, { - message, - type: 'error' - }, options)) - }, - info(message, options = {}) { - return this.open(Object.assign({}, { - message, - type: 'info' - }, options)) - }, - warning(message, options = {}) { - return this.open(Object.assign({}, { - message, - type: 'warning' - }, options)) - }, - default(message, options = {}) { - return this.open(Object.assign({}, { - message, - type: 'default' - }, options)) - } - } -}; +import MeshkeeToast from './components/MeshkeeToast.vue' +import { createComponent } from './utils/helpers.js'; +import eventBus from './utils/bus.js'; +import Positions from './utils/positions.js'; + +let parentTop = document.querySelector('.me-toast.me-toast--top'); +let parentBottom = document.querySelector('.me-toast.me-toast--bottom'); + +const correctParent = (position) => { + switch (position) { + case Positions.TOP: + case Positions.TOP_RIGHT: + case Positions.TOP_LEFT: + return parentTop; + + case Positions.BOTTOM: + case Positions.BOTTOM_RIGHT: + case Positions.BOTTOM_LEFT: + return parentBottom; + } +}; +const setupContainer = () => { + // No need to create them, they already exists + if (parentTop && parentBottom) return; + + if (!parentTop) { + parentTop = document.createElement('div'); + parentTop.className = 'me-toast me-toast--top'; + } + + if (!parentBottom) { + parentBottom = document.createElement('div'); + parentBottom.className = 'me-toast me-toast--bottom' + } + + const container = document.body; + container.appendChild(parentTop); + container.appendChild(parentBottom); +}; +export const useToast = (globalProps = {}) => { + return { + open(options) { + let message = null; + if (typeof options === 'string') message = options; + + const defaultProps = { + message + }; + + const propsData = Object.assign({}, defaultProps, globalProps, options); + setupContainer(); + const instance = createComponent(MeshkeeToast, propsData, correctParent(propsData.position ? propsData.position : 'bottom')); + return { + dismiss: instance.dismiss + } + }, + clear() { + eventBus.emit('toast-clear') + }, + success(title, message, options = {}) { + return this.open(Object.assign({}, { + title, + message, + type: 'success', + borderColor: '#EDEDED' + }, options)) + }, + error(title, message, options = {}) { + return this.open(Object.assign({}, { + title, + message, + type: 'error', + borderColor: '#EDEDED' + }, options)) + }, + info(title, message, options = {}) { + return this.open(Object.assign({}, { + title, + message, + type: 'info' + }, options)) + }, + preset(title, message, options = {}) { + return this.open(Object.assign({}, { + title, + message, + titleColor: 'black', + messageColor: 'black', + type: 'default' + }, options)) + } + } +}; diff --git a/src/MeshkeeToast.vue b/src/components/MeshkeeToast.vue similarity index 53% rename from src/MeshkeeToast.vue rename to src/components/MeshkeeToast.vue index ae0d772..e2d7dc2 100644 --- a/src/MeshkeeToast.vue +++ b/src/components/MeshkeeToast.vue @@ -1,206 +1,254 @@ - - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/src/main.js b/src/main.js index e442c42..126011e 100644 --- a/src/main.js +++ b/src/main.js @@ -1,51 +1,12 @@ -// Import vue component -import Vue from 'vue'; -import MeshkeeToast from './MeshkeeToast.vue'; -import { useToast } from './api'; - -// Vue.prototype.$meshkeeToast = function () { -// console.log(324); -// return 321; -// } -// // Declare install function executed by Vue.use() -// export function install(Vue) { -// console.log(43); - -// if (install.installed) return; -// install.installed = true; -// Vue.prototype.$meshkeeToast = function () { -// console.log(324); -// return 321; -// } -// Vue.component('MeshkeeToast', MeshkeeToast); -// } - -// // Create module definition for Vue.use() -// const plugin = { -// install, -// }; - -// // Auto-install when vue is found (eg. in browser via