vue-nt-toast 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/toast.css ADDED
@@ -0,0 +1 @@
1
+ button{border:0 none;background-color:transparent;cursor:pointer}.toast.success,.toast .success{background-color:#528e64!important;color:#fff!important;border-color:#3f6e4d!important}.toast.success:hover,.toast .success:hover{background-color:#3f6e4d}.toast.success-text,.toast .success-text{color:#528e64!important}.toast.success-bg,.toast .success-bg{background-color:#528e64!important}.toast.success-border,.toast .success-border{border-color:#3f6e4d!important}.toast.success.light,.toast .success.light{background-color:#cbe1d2!important;color:#528e64!important;border-color:#3f6e4d!important}.toast.info,.toast .info{background-color:#62b0bc!important;color:#fff!important;border-color:#4698a5!important}.toast.info:hover,.toast .info:hover{background-color:#4698a5}.toast.info-text,.toast .info-text{color:#62b0bc!important}.toast.info-bg,.toast .info-bg{background-color:#62b0bc!important}.toast.info-border,.toast .info-border{border-color:#4698a5!important}.toast.info.light,.toast .info.light{background-color:#d4e9ed!important;color:#62b0bc!important;border-color:#4698a5!important}.toast.danger,.toast .danger{background-color:#d53012!important;color:#fff!important;border-color:#a6250e!important}.toast.danger:hover,.toast .danger:hover{background-color:#a6250e}.toast.danger-text,.toast .danger-text{color:#d53012!important}.toast.danger-bg,.toast .danger-bg{background-color:#d53012!important}.toast.danger-border,.toast .danger-border{border-color:#a6250e!important}.toast.danger.light,.toast .danger.light{background-color:#fbe0da!important;color:#d53012!important;border-color:#a6250e!important}.toast.attention,.toast .attention{background-color:#ec6e00!important;color:#fff!important;border-color:#b95600!important}.toast.attention:hover,.toast .attention:hover{background-color:#b95600}.toast.attention-text,.toast .attention-text{color:#ec6e00!important}.toast.attention-bg,.toast .attention-bg{background-color:#ec6e00!important}.toast.attention-border,.toast .attention-border{border-color:#b95600!important}.toast.attention.light,.toast .attention.light{background-color:#ffe9d6!important;color:#ec6e00!important;border-color:#b95600!important}.toast.importance,.toast .importance{background-color:#fdc036!important;color:#fff!important;border-color:#fcb004!important}.toast.importance:hover,.toast .importance:hover{background-color:#fcb004}.toast.importance-text,.toast .importance-text{color:#fdc036!important}.toast.importance-bg,.toast .importance-bg{background-color:#fdc036!important}.toast.importance-border,.toast .importance-border{border-color:#fcb004!important}.toast.importance.light,.toast .importance.light{background-color:#fff3d7!important;color:#fdc036!important;border-color:#fcb004!important}.toast.red,.toast .red{background-color:#d93b3b!important;color:#fff!important;border-color:#bc2525!important}.toast.red:hover,.toast .red:hover{background-color:#bc2525}.toast.red-text,.toast .red-text{color:#d93b3b!important}.toast.red-bg,.toast .red-bg{background-color:#d93b3b!important}.toast.red-border,.toast .red-border{border-color:#d93b3b!important}.toast.red.light,.toast .red.light{background-color:#f6d1d1!important;color:#d93b3b!important;border-color:#bc2525!important}.toast.sunset,.toast .sunset{background-color:#d44d32!important;color:#fff!important;border-color:#ae3c25!important}.toast.sunset:hover,.toast .sunset:hover{background-color:#ae3c25}.toast.sunset-text,.toast .sunset-text{color:#d44d32!important}.toast.sunset-bg,.toast .sunset-bg{background-color:#d44d32!important}.toast.sunset-border,.toast .sunset-border{border-color:#d44d32!important}.toast.sunset.light,.toast .sunset.light{background-color:#f3cdc6!important;color:#d44d32!important;border-color:#ae3c25!important}.toast.orange,.toast .orange{background-color:#d95b2c!important;color:#fff!important;border-color:#b24820!important}.toast.orange:hover,.toast .orange:hover{background-color:#b24820}.toast.orange-text,.toast .orange-text{color:#d95b2c!important}.toast.orange-bg,.toast .orange-bg{background-color:#d95b2c!important}.toast.orange-border,.toast .orange-border{border-color:#d95b2c!important}.toast.orange.light,.toast .orange.light{background-color:#f4d1c3!important;color:#d95b2c!important;border-color:#b24820!important}.toast.amber,.toast .amber{background-color:#d3873f!important;color:#fff!important;border-color:#b56e2a!important}.toast.amber:hover,.toast .amber:hover{background-color:#b56e2a}.toast.amber-text,.toast .amber-text{color:#d3873f!important}.toast.amber-bg,.toast .amber-bg{background-color:#d3873f!important}.toast.amber-border,.toast .amber-border{border-color:#d3873f!important}.toast.amber.light,.toast .amber.light{background-color:#f4e2d0!important;color:#d3873f!important;border-color:#b56e2a!important}.toast.yellow,.toast .yellow{background-color:#f5b54d!important;color:#fff!important;border-color:#f2a11d!important}.toast.yellow:hover,.toast .yellow:hover{background-color:#f2a11d}.toast.yellow-text,.toast .yellow-text{color:#f5b54d!important}.toast.yellow-bg,.toast .yellow-bg{background-color:#f5b54d!important}.toast.yellow-border,.toast .yellow-border{border-color:#f5b54d!important}.toast.yellow.light,.toast .yellow.light{background-color:#fefbf6!important;color:#f5b54d!important;border-color:#f2a11d!important}.toast.citron,.toast .citron{background-color:#cac747!important;color:#fff!important;border-color:#acaa32!important}.toast.citron:hover,.toast .citron:hover{background-color:#acaa32}.toast.citron-text,.toast .citron-text{color:#cac747!important}.toast.citron-bg,.toast .citron-bg{background-color:#cac747!important}.toast.citron-border,.toast .citron-border{border-color:#cac747!important}.toast.citron.light,.toast .citron.light{background-color:#f2f1d2!important;color:#cac747!important;border-color:#acaa32!important}.toast.lime,.toast .lime{background-color:#85ab39!important;color:#fff!important;border-color:#67852c!important}.toast.lime:hover,.toast .lime:hover{background-color:#67852c}.toast.lime-text,.toast .lime-text{color:#85ab39!important}.toast.lime-bg,.toast .lime-bg{background-color:#85ab39!important}.toast.lime-border,.toast .lime-border{border-color:#85ab39!important}.toast.lime.light,.toast .lime.light{background-color:#d4e5b1!important;color:#85ab39!important;border-color:#67852c!important}.toast.green,.toast .green{background-color:#48992f!important;color:#fff!important;border-color:#367223!important}.toast.green:hover,.toast .green:hover{background-color:#367223}.toast.green-text,.toast .green-text{color:#48992f!important}.toast.green-bg,.toast .green-bg{background-color:#48992f!important}.toast.green-border,.toast .green-border{border-color:#48992f!important}.toast.green.light,.toast .green.light{background-color:#abe09a!important;color:#48992f!important;border-color:#367223!important}.toast.mint,.toast .mint{background-color:#3a874f!important;color:#fff!important;border-color:#2b633a!important}.toast.mint:hover,.toast .mint:hover{background-color:#2b633a}.toast.mint-text,.toast .mint-text{color:#3a874f!important}.toast.mint-bg,.toast .mint-bg{background-color:#3a874f!important}.toast.mint-border,.toast .mint-border{border-color:#3a874f!important}.toast.mint.light,.toast .mint.light{background-color:#9ed5ad!important;color:#3a874f!important;border-color:#2b633a!important}.toast.teal,.toast .teal{background-color:#449698!important;color:#fff!important;border-color:#347375!important}.toast.teal:hover,.toast .teal:hover{background-color:#347375}.toast.teal-text,.toast .teal-text{color:#449698!important}.toast.teal-bg,.toast .teal-bg{background-color:#449698!important}.toast.teal-border,.toast .teal-border{border-color:#449698!important}.toast.teal.light,.toast .teal.light{background-color:#b2dcdd!important;color:#449698!important;border-color:#347375!important}.toast.cyan,.toast .cyan{background-color:#4d9bcc!important;color:#fff!important;border-color:#3382b3!important}.toast.cyan:hover,.toast .cyan:hover{background-color:#3382b3}.toast.cyan-text,.toast .cyan-text{color:#4d9bcc!important}.toast.cyan-bg,.toast .cyan-bg{background-color:#4d9bcc!important}.toast.cyan-border,.toast .cyan-border{border-color:#4d9bcc!important}.toast.cyan.light,.toast .cyan.light{background-color:#d8e9f4!important;color:#4d9bcc!important;border-color:#3382b3!important}.toast.blue,.toast .blue{background-color:#4e7af8!important;color:#fff!important;border-color:#1d55f6!important}.toast.blue:hover,.toast .blue:hover{background-color:#1d55f6}.toast.blue-text,.toast .blue-text{color:#4e7af8!important}.toast.blue-bg,.toast .blue-bg{background-color:#4e7af8!important}.toast.blue-border,.toast .blue-border{border-color:#4e7af8!important}.toast.blue.light,.toast .blue.light{background-color:#fafbff!important;color:#4e7af8!important;border-color:#1d55f6!important}.toast.indigo,.toast .indigo{background-color:#5642ed!important;color:#fff!important;border-color:#2e16e6!important}.toast.indigo:hover,.toast .indigo:hover{background-color:#2e16e6}.toast.indigo-text,.toast .indigo-text{color:#5642ed!important}.toast.indigo-bg,.toast .indigo-bg{background-color:#5642ed!important}.toast.indigo-border,.toast .indigo-border{border-color:#5642ed!important}.toast.indigo.light,.toast .indigo.light{background-color:#e8e5fd!important;color:#5642ed!important;border-color:#2e16e6!important}.toast.purple,.toast .purple{background-color:#8756f3!important;color:#fff!important;border-color:#6526f0!important}.toast.purple:hover,.toast .purple:hover{background-color:#6526f0}.toast.purple-text,.toast .purple-text{color:#8756f3!important}.toast.purple-bg,.toast .purple-bg{background-color:#8756f3!important}.toast.purple-border,.toast .purple-border{border-color:#8756f3!important}.toast.purple.light,.toast .purple.light{background-color:#fdfdff!important;color:#8756f3!important;border-color:#6526f0!important}.toast.pink,.toast .pink{background-color:#bf3da0!important;color:#fff!important;border-color:#983180!important}.toast.pink:hover,.toast .pink:hover{background-color:#983180}.toast.pink-text,.toast .pink-text{color:#bf3da0!important}.toast.pink-bg,.toast .pink-bg{background-color:#bf3da0!important}.toast.pink-border,.toast .pink-border{border-color:#bf3da0!important}.toast.pink.light,.toast .pink.light{background-color:#ecc3e2!important;color:#bf3da0!important;border-color:#983180!important}.toast.rose,.toast .rose{background-color:#bb3a62!important;color:#fff!important;border-color:#942e4e!important}.toast.rose:hover,.toast .rose:hover{background-color:#942e4e}.toast.rose-text,.toast .rose-text{color:#bb3a62!important}.toast.rose-bg,.toast .rose-bg{background-color:#bb3a62!important}.toast.rose-border,.toast .rose-border{border-color:#bb3a62!important}.toast.rose.light,.toast .rose.light{background-color:#ebbdcb!important;color:#bb3a62!important;border-color:#942e4e!important}.toast-board{position:fixed;display:flex;flex-direction:column;z-index:9999;top:0}.toast-board.on-top{flex-direction:column-reverse}.toast-board.top-left{top:0;left:0}.toast-board.top-center{top:0;left:50%;transform:translate(-50%)}.toast-board.top-right{top:0;right:0}.toast-board.top-full-width{top:0;left:50%;transform:translate(-50%);width:80%}.toast-board.top-full-width .toast{width:100%}.toast-board.bottom-left{bottom:0;left:0}.toast-board.bottom-center{bottom:0;left:50%;transform:translate(-50%)}.toast-board.bottom-right{bottom:0;right:0}.toast-board.bottom-full-width{bottom:0;left:50%;transform:translate(-50%);width:80%}.toast-board.bottom-full-width .toast{width:100%}.toast-board .toast{position:relative;display:flex;justify-content:flex-start;width:400px;margin:5px;color:#333;border-radius:4px;box-shadow:2px 5px 5px #00000029;background-color:#fff;transition-property:opacity,transform;transition-duration:.5s,1s;line-height:1em;vertical-align:baseline;opacity:0;font-size:1.2em;overflow:hidden;animation:swing-off .5s ease}.toast-board .toast.fade{opacity:.95;transform:translate(0)}.toast-board .toast.swing{animation:swing .5s ease;opacity:.95}.toast-board .toast.round{border-radius:2em}.toast-board .toast .toast-contents{flex-grow:1;padding:10px 25px 10px 10px;max-width:calc(100% - 50px);font-size:.8em;overflow-wrap:break-word}.toast-board .toast .toast-contents h5{font-weight:700;font-size:1.2em;margin-bottom:10px}.toast-board .toast .toast-close{flex-shrink:1;cursor:pointer;padding:20px;line-height:1em;position:absolute;top:50%;right:0;transform:translateY(-50%);font-size:1em;color:inherit}.toast-board .toast .toast-icon{flex-shrink:1;padding:10px}.toast-board .toast.line-left .toast-contents{border-left:5px solid}.toast-board .toast.line-top .toast-contents{border-top:5px solid}@keyframes swing{0%{transform:translate(300px);opacity:0}25%{transform:translate(20px)}75%{transform:translate(-10px);opacity:.95}to{transform:translate(0)}}@keyframes swing-off{0%{transform:translate(0)}25%{transform:translate(-10px)}75%{transform:translate(20px)}to{transform:translate(300px)}}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "vue-nt-toast",
3
+ "version": "0.1.0",
4
+ "description": "Toast system plugin with vue3",
5
+ "author": "Minyoung Tommy Kim",
6
+ "private": false,
7
+ "scripts": {
8
+ "dev": "MODE=demo vite",
9
+ "build": "npm run build:code",
10
+ "build:code": "MODE=lib vite build",
11
+ "build:demo": "MODE=demo vite build",
12
+ "preview": "vite preview",
13
+ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",
14
+ "format": "prettier --write src/"
15
+ },
16
+ "main": "./dist/nt-toast.umd.js",
17
+ "module": "./dist/nt-toast.es.js",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/nt-toast.es.js",
21
+ "require": "./dist/nt-toast.umd.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "src"
27
+ ],
28
+ "bugs": {
29
+ "url": "https://github.com/noistommy/vue-nt-toast/issues"
30
+ },
31
+ "homepage": "https://github.com/noistommy/vue-nt-toast#readme",
32
+ "keywords": [
33
+ "vue",
34
+ "notification",
35
+ "toast"
36
+ ],
37
+ "style": "./dist/toast.css",
38
+ "peerDependencies": {
39
+ "@fortawesome/fontawesome-free": "^6.4.2",
40
+ "vue": "^3.3.4"
41
+ },
42
+ "devDependencies": {
43
+ "@rushstack/eslint-patch": "^1.3.2",
44
+ "@vitejs/plugin-vue": "^4.3.1",
45
+ "@vue/eslint-config-prettier": "^8.0.0",
46
+ "eslint": "^8.46.0",
47
+ "eslint-plugin-vue": "^9.16.1",
48
+ "font-awesome": "^4.7.0",
49
+ "prettier": "^3.0.0",
50
+ "sass": "^1.66.1",
51
+ "vite": "^4.4.9"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/noistommy/vue-nt-toast.git"
56
+ }
57
+ }
package/src/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import ToastBoard from './toastBoard'
2
+ import './toast.scss'
3
+ import '@fortawesome/fontawesome-free/js/all.js'
4
+
5
+ const defaultOptions = {
6
+ useTitle: true,
7
+ useIcon: true,
8
+ closeButton: true,
9
+ round: false,
10
+ theme: '',
11
+ timeout: 5000,
12
+ clickToClose: true,
13
+ displayOnTop: false,
14
+ snackbar: false,
15
+ freeze: true
16
+ }
17
+
18
+ let extendOptions = {}
19
+ const setOption = option => {
20
+ return { ...defaultOptions, ...option }
21
+ }
22
+
23
+ export default {
24
+ install(app, options = {}) {
25
+ extendOptions = setOption(options)
26
+ app.config.globalProperties.$gaToast = new ToastBoard(extendOptions)
27
+ }
28
+ }
package/src/toast.js ADDED
@@ -0,0 +1,85 @@
1
+ const statusIcon = {
2
+ success: 'check-circle',
3
+ info: 'info-circle',
4
+ danger: 'exclamation-circle',
5
+ attention: 'exclamation-triangle',
6
+ importance: 'star'
7
+ }
8
+
9
+ class Toast {
10
+ constructor(type, msg, options) {
11
+ this.type = type
12
+ this.msg = msg
13
+ this.options = options
14
+ this.interval = null
15
+ this.toast = null
16
+ this.icon = null
17
+ this.closeButton = null
18
+ this.notify()
19
+ }
20
+
21
+ notify() {
22
+ this.toast = document.createElement('div')
23
+ this.toast.classList.add('toast', 'swing')
24
+ // const contents = document.createElement('div')
25
+ const contents = this.setContents()
26
+ this.setIcon()
27
+ if (this.options.round) {
28
+ this.toast.classList.add('round')
29
+ }
30
+ if (this.options.theme === 'light') {
31
+ this.toast.classList.add(`${this.type}`, `light`)
32
+ } else if (this.options.theme === 'icon') {
33
+ this.icon.classList.add(`${this.type}-text`)
34
+ } else if (this.options.theme === 'icon-bg') {
35
+ this.icon.classList.add(`${this.type}`)
36
+ } else if (this.options.theme === 'line') {
37
+ this.toast.classList.add(`line-left`)
38
+ contents.classList.add(`${this.type}-border`)
39
+ } else {
40
+ this.toast.classList.add(`${this.type}`)
41
+ }
42
+
43
+ contents.classList.add('toast-contents')
44
+ this.toast.appendChild(contents)
45
+ // this.interval = setTimeout(() => this.hide(), this.options.timeout)
46
+ return this.toast
47
+ }
48
+ // hide() {
49
+ // this.toast.classList.remove('swing')
50
+ // this.toast.addEventListener('transitionend', () => {
51
+ // this.toast.remove()
52
+ // clearTimeout(this.interval)
53
+ // })
54
+ // }
55
+ setIcon() {
56
+ if (!this.options.useIcon || this.options.theme === 'line') return
57
+ this.icon = document.createElement('div')
58
+ this.icon.classList.add('toast-icon')
59
+ const iconClass = statusIcon[this.type] || 'hexagon-exclamation'
60
+ this.icon.innerHTML = `<i class="fa fa-${iconClass}" />`
61
+ // this.icon.innerHTML = `<img src="./icons/success.svg" />`
62
+ // this.toast.appendChild(this.icon)
63
+ this.toast.appendChild(this.icon)
64
+ }
65
+ setContents() {
66
+ const contents = document.createElement('div')
67
+ const title = document.createElement('h5')
68
+ title.classList.add('title', 'ellipsis')
69
+ const description = document.createElement('div')
70
+ if (typeof this.msg === 'string') {
71
+ description.innerHTML = this.msg
72
+ contents.appendChild(description)
73
+ } else {
74
+ if (this.options.useTitle) {
75
+ title.innerHTML = this.msg.title
76
+ contents.appendChild(title)
77
+ }
78
+ description.innerHTML = this.msg.description
79
+ contents.appendChild(description)
80
+ }
81
+ return contents
82
+ }
83
+ }
84
+
85
+ export default Toast
package/src/toast.scss ADDED
@@ -0,0 +1,277 @@
1
+ button {border:0 none;background-color:transparent;cursor:pointer}
2
+
3
+ $success: #528E64;
4
+ $info: #62B0BC;
5
+ $danger: #D53012;
6
+ $attention: #EC6E00;
7
+ $importance: #FDC036;
8
+
9
+ $lightSuccess: #CBE1D2;
10
+ $lightInfo: #D4E9ED;
11
+ $lightDanger: #FBE0DA;
12
+ $lightAttention: #FFE9D6;
13
+ $lightImportance: #FFF3D7;
14
+
15
+ $white: #FFFFFF;
16
+
17
+ $stateColors: (
18
+ 'success': ($success, darken($success, 10), $white, $lightSuccess),
19
+ 'info': ($info, darken($info, 10), $white, $lightInfo),
20
+ 'danger': ($danger, darken($danger, 10), $white, $lightDanger),
21
+ 'attention': ($attention, darken($attention, 10), $white, $lightAttention),
22
+ 'importance': ($importance, darken($importance, 10), $white, $lightImportance),
23
+ );
24
+
25
+ $colors: (
26
+ 'red': #D93B3B,
27
+ 'sunset': #D44D32,
28
+ 'orange': #D95B2C,
29
+ 'amber': #D3873F,
30
+ 'yellow': #F5B54D,
31
+ 'citron': #CAC747,
32
+ 'lime': #85AB39,
33
+ 'green': #48992F,
34
+ 'mint': #3A874F,
35
+ 'teal': #449698,
36
+ 'cyan': #4D9BCC,
37
+ 'blue': #4E7AF8,
38
+ 'indigo': #5642ED,
39
+ 'purple': #8756F3,
40
+ 'pink': #BF3DA0,
41
+ 'rose': #BB3A62,
42
+ );
43
+
44
+ @each $color, $value in $stateColors {
45
+ .toast {
46
+ &.#{$color}, .#{$color} {
47
+ background-color: nth($value, 1) !important;
48
+ color: $white !important;
49
+ border-color: nth($value, 2) !important;
50
+ &:hover {
51
+ background-color: nth($value, 2);
52
+ }
53
+ &-text {
54
+ color: nth($value, 1) !important;
55
+ }
56
+ &-bg {
57
+ background-color: nth($value, 1) !important;
58
+ }
59
+ &-border {
60
+ border-color: nth($value, 2) !important;
61
+ }
62
+ &.light {
63
+ background-color: nth($value, 4) !important;
64
+ color: nth($value, 1) !important;
65
+ border-color: nth($value, 2) !important;
66
+ }
67
+ }
68
+ }
69
+ }
70
+ @each $color, $value in $colors {
71
+ .toast {
72
+ &.#{$color}, .#{$color} {
73
+ background-color: $value !important;
74
+ color: $white !important;
75
+ border-color: darken($value, 10) !important;
76
+ &:hover {
77
+ background-color: darken($value, 10);
78
+ }
79
+ &-text {
80
+ color: $value !important;
81
+ }
82
+ &-bg {
83
+ background-color: $value !important;
84
+ }
85
+ &-border {
86
+ border-color: $value !important;
87
+ }
88
+ &.light {
89
+ background-color: lighten($value, 35) !important;
90
+ color: $value !important;
91
+ border-color: darken($value, 10) !important;
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+
98
+ .toast-board {
99
+ position: fixed;
100
+ display: flex;
101
+ flex-direction: column;
102
+ z-index: 9999;
103
+ top: 0;
104
+ &.on-top {
105
+ flex-direction: column-reverse;
106
+ }
107
+ &.top {
108
+ &-left {
109
+ top: 0;
110
+ left: 0;
111
+ }
112
+ &-center {
113
+ top: 0;
114
+ left: 50%;
115
+ transform: translateX(-50%);
116
+ }
117
+ &-right {
118
+ top: 0;
119
+ right: 0;
120
+ }
121
+ &-full-width {
122
+ top: 0;
123
+ left: 50%;
124
+ transform: translateX(-50%);
125
+ width: 80%;
126
+ .toast {
127
+ width: 100%;
128
+ }
129
+ }
130
+ }
131
+ &.bottom {
132
+ &-left {
133
+ bottom: 0;
134
+ left: 0;
135
+ }
136
+
137
+ &-center {
138
+ bottom: 0;
139
+ left: 50%;
140
+ transform: translateX(-50%);
141
+ }
142
+
143
+ &-right {
144
+ bottom: 0;
145
+ right: 0;
146
+ }
147
+
148
+ &-full-width {
149
+ bottom: 0;
150
+ left: 50%;
151
+ transform: translateX(-50%);
152
+ width: 80%;
153
+
154
+ .toast {
155
+ width: 100%;
156
+ }
157
+ }
158
+ }
159
+ .toast {
160
+ position: relative;
161
+ display: flex;
162
+ justify-content: flex-start;
163
+ width: 400px;
164
+ margin: 5px;
165
+ //opacity: .95;
166
+ color: #333;
167
+ border-radius: 4px;
168
+ box-shadow: 2px 5px 5px rgba(0, 0, 0, 0.16);
169
+ background-color: #fff;
170
+ //transition: all 500ms;
171
+ transition-property: opacity, transform;
172
+ transition-duration: 500ms, 1000ms;
173
+ line-height: 1em;
174
+ vertical-align: baseline;
175
+ // border: 1px solid #d6d6d6;
176
+ opacity: 0;
177
+ //transform: translateX(20px);
178
+ font-size: 1.2em;
179
+ overflow: hidden;
180
+ animation: swing-off 500ms ease;
181
+ &.fade {
182
+ opacity: .95;
183
+ transform: translateX(0px);
184
+ }
185
+ &.swing {
186
+ animation: swing 500ms ease;
187
+ opacity: .95;
188
+ }
189
+ &.round {
190
+ border-radius: 2em;
191
+ }
192
+ .toast-contents {
193
+ flex-grow: 1;
194
+ padding: 10px;
195
+ padding-right: 25px;
196
+ max-width: calc(100% - 50px);
197
+ font-size: .8em;
198
+ overflow-wrap: break-word;
199
+ h5 {
200
+ font-weight: bold;
201
+ font-size: 1.2em;
202
+ margin-bottom: 10px;
203
+ }
204
+ }
205
+ .toast-close {
206
+ flex-shrink: 1;
207
+ cursor: pointer;
208
+ padding: 20px;
209
+ line-height: 1em;
210
+ position: absolute;
211
+ top: 50%;
212
+ right: 0;
213
+ transform: translateY(-50%);
214
+ font-size: 1em;
215
+ color: inherit;
216
+ }
217
+ .toast-icon {
218
+ flex-shrink: 1;
219
+ padding: 10px;
220
+ }
221
+ &.line-left {
222
+ .toast-contents {
223
+ border-left: 5px solid;
224
+ }
225
+ }
226
+ &.line-top {
227
+ .toast-contents {
228
+ border-top: 5px solid;
229
+ }
230
+ }
231
+ }
232
+ // .ga-primary {
233
+ // background-color: $primary;
234
+ // color: $white;
235
+ // &-text {
236
+ // color: $primary;
237
+ // }
238
+ // }
239
+ // .ga-secondary {
240
+ // background-color: $secondary;
241
+ // color: $white;
242
+ // }
243
+ }
244
+ @keyframes swing {
245
+ 0% {
246
+ transform: translateX(300px);
247
+ opacity: 0;
248
+ }
249
+ 25% {
250
+ transform: translateX(20px);
251
+ }
252
+ 75% {
253
+ transform: translateX(-10px);
254
+ opacity: .95;
255
+ }
256
+ 100% {
257
+ transform: translateX(0px);
258
+ }
259
+
260
+ }
261
+ @keyframes swing-off {
262
+ 0% {
263
+ transform: translateX(0px);
264
+ }
265
+ 25% {
266
+ transform: translateX(-10px);
267
+ //opacity: 0.95;
268
+ }
269
+ 75% {
270
+ transform: translateX(20px);
271
+ }
272
+ 100% {
273
+ transform: translateX(300px);
274
+ //opacity: 0;
275
+ }
276
+
277
+ }
@@ -0,0 +1,86 @@
1
+ import Toast from './toast'
2
+
3
+ class ToastBoard {
4
+ constructor(options) {
5
+ this.toastId = 0
6
+ this.options = options
7
+ this.board = null
8
+ }
9
+ show(type, contents, options) {
10
+ const extendOption = { ...this.options, ...options }
11
+ if (extendOption.snackbar) {
12
+ this.clear()
13
+ }
14
+ let closeEl = null
15
+ this.toastId++
16
+ this.board = this.getBoard(extendOption)
17
+
18
+ const toastEl = new Toast(type, contents, extendOption).toast
19
+ if (extendOption.closeButton) {
20
+ closeEl = this.setClose()
21
+ toastEl.appendChild(closeEl)
22
+ }
23
+ this.board.appendChild(toastEl)
24
+ const interval = extendOption.freeze
25
+ ? null
26
+ : setTimeout(() => this.hideToast(toastEl, interval), extendOption.timeout)
27
+ if (extendOption.clickToClose) {
28
+ toastEl.onclick = () => {
29
+ this.hideToast(toastEl, interval)
30
+ }
31
+ }
32
+ if (extendOption.closeButton) {
33
+ closeEl.onClick = () => {
34
+ this.hideToast(toastEl, interval)
35
+ }
36
+ }
37
+ }
38
+ getBoard(options) {
39
+ let board = document.querySelector('.toast-board')
40
+ if (board) {
41
+ return board
42
+ }
43
+ board = document.createElement('div')
44
+ board.classList.add('toast-board')
45
+ board.classList.add(options.position)
46
+ if (options.displayOnTop) {
47
+ board.classList.add('on-top')
48
+ }
49
+ document.body.appendChild(board)
50
+ return board
51
+ }
52
+ setClose() {
53
+ const closeButton = document.createElement('button')
54
+ closeButton.classList.add('toast-close')
55
+ closeButton.innerHTML = '<span>&times;</span>'
56
+ return closeButton
57
+ }
58
+ hideToast(toast, interval) {
59
+ this.toastId--
60
+ toast.classList.remove('swing')
61
+ toast.addEventListener('transitionend', () => {
62
+ this.removeToast(toast)
63
+ clearTimeout(interval)
64
+ })
65
+ }
66
+ removeToast(toast) {
67
+ toast.remove()
68
+ if (!this.toastId) {
69
+ this.clear()
70
+ }
71
+ }
72
+ clearToast() {
73
+ if (!this.board) return
74
+ const toasts = this.board.querySelectorAll('.toast')
75
+ toasts.forEach(t => {
76
+ this.hideToast(t, null)
77
+ })
78
+ }
79
+ clear() {
80
+ if (this.board) {
81
+ this.board.remove()
82
+ }
83
+ }
84
+ }
85
+
86
+ export default ToastBoard