@cicciosgamino/snack-bar 1.1.0 → 1.4.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/CHANGELOG.md CHANGED
@@ -6,10 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.4.0] - 02-01-2025
10
+ ### Added
11
+ - New method `show(msg, time=2700, bkColor='#333', txtColor='#f5f5f5')` to show the snackbar with custom message, time, background-color and text-color
12
+
13
+ ## [1.3.0] - 06-06-2023
14
+
15
+ ### Changed
16
+ - Minor fix
17
+ - Click to close the component
18
+
9
19
  ## [1.1.0] - 29-07-2021
20
+
10
21
  ### Changed
11
22
  - Change module part in package.json, link to source snack-bar.js
12
23
 
13
24
  ## [1.0.0] - 07-07-2021
25
+
14
26
  ### Added
15
27
  - Init the Element [@cicciosgamino](https://github.com/CICCIOSGAMINO).
package/LICENSE CHANGED
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
652
652
  If the program does terminal interaction, make it output a short
653
653
  notice like this when it starts in an interactive mode:
654
654
 
655
- web-socket Copyright (C) 2021 @cicciosgamino
655
+ snack-bar Copyright (C) 2026 @cicciosgamino
656
656
  This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
657
  This is free software, and you are welcome to redistribute it
658
658
  under certain conditions; type `show c' for details.
package/README.md CHANGED
@@ -56,12 +56,14 @@ npm install --save @cicciosgamino/snack-bar
56
56
  | timing | Number | `3000` | Snackbar active timing
57
57
  | title | String | `🌰 ... SnackBar Title` | Snackbar title
58
58
  | active | Boolean | `` | Snackbar active attribute (present/NOT)
59
+ | closebtn| Boolean | `` | Show the close button when attribute is present
59
60
 
60
61
 
61
62
  ### Methods
62
63
 
63
64
  | Name | Description
64
65
  | -------- | -------------
66
+ | `show(msg, time=2700, bkColor='#333', txtColor='#f5f5f5') => void` | Show the snackbar with custom message, time, background-color and text-color
65
67
  | `closeSnackbar() => void` | Close the snackbar
66
68
 
67
69
 
package/index.html CHANGED
@@ -16,7 +16,7 @@
16
16
  <meta name="author" content="@cicciosgamino">
17
17
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
18
18
 
19
- <title>🍣 Sushi</title>
19
+ <title>🍣 SnackBar</title>
20
20
 
21
21
  <style>
22
22
  :root {
@@ -49,7 +49,7 @@
49
49
  }
50
50
 
51
51
  snack-bar {
52
- --snack-bottom: 10rem;
52
+ /* --snack-bottom: 10rem; absolute position from bottom */
53
53
  }
54
54
  </style>
55
55
 
@@ -67,8 +67,14 @@
67
67
  </section>
68
68
  </main>
69
69
 
70
- <!-- Use the snackbar -->
71
- <snack-bar timing="5000" title="@Cicciosgamino"></snack-bar>
70
+ <!-- (default)
71
+ <snack-bar></snack-bar> -->
72
+
73
+ <!-- (default) with close button -->
74
+ <snack-bar closebtn></snack-bar>
75
+
76
+ <!-- Use the snackbar custom timing / title with close button
77
+ <snack-bar timing="5000" title="@Cicciosgamino" closebtn></snack-bar> -->
72
78
 
73
79
  <noscript>
74
80
  Please enable JavaScript to view this website.
@@ -80,14 +86,21 @@
80
86
  <script>
81
87
  window.addEventListener('DOMContentLoaded', () => {
82
88
  const snack = document.querySelector('snack-bar')
89
+
83
90
  setTimeout(() => {
84
91
  // active the snack
85
92
  snack.setAttribute('active', '')
86
- }, 5000)
93
+ }, 1000)
94
+
87
95
  setTimeout(() => {
88
96
  // close the snack (before timing ended)
89
97
  snack.closeSnackbar()
90
- }, 8000)
98
+ }, 2800)
99
+
100
+ setTimeout(() => {
101
+ // re-active the snack
102
+ snack.show('Reactivated SnackBar!', 3000, '#ff0000', '#fff')
103
+ }, 3200)
91
104
  })
92
105
  </script>
93
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cicciosgamino/snack-bar",
3
- "version": "1.1.0",
3
+ "version": "1.4.0",
4
4
  "description": "Simple snackbar Lit Element",
5
5
  "main": "snack-bar.js",
6
6
  "module": "snack-bar.js",
@@ -30,9 +30,6 @@
30
30
  "lit": "*"
31
31
  },
32
32
  "devDependencies": {
33
- "vite": "^2.4.3"
34
- },
35
- "directories": {
36
- "example": "examples/index.html"
33
+ "vite": "^7.3.0"
37
34
  }
38
35
  }
package/snack-bar.js CHANGED
@@ -18,18 +18,21 @@ class SnackBar extends LitElement {
18
18
  padding: 0;
19
19
  box-sizing: border-box;
20
20
  }
21
+
21
22
  :host {
22
23
  display: none;
23
24
  animation-name: fadeOut;
24
25
  animation-duration: 0.5s;
25
26
  animation-fill-mode: forwards;
26
27
  }
28
+
27
29
  :host-context([active]) {
28
30
  /* Handle CSS when host active */
29
31
  animation-name: fadeIn;
30
32
  animation-duration: 0.5s;
31
33
  animation-fill-mode: forwards;
32
34
  }
35
+
33
36
  #snackbar {
34
37
  border-radius: var(--snack-radius, 1px);
35
38
  min-width: 100%;
@@ -43,18 +46,18 @@ class SnackBar extends LitElement {
43
46
  transform: translate(-50%, 0);
44
47
  bottom: var(--snack-bottom, 0);
45
48
  }
49
+
46
50
  #container {
47
51
  margin: calc(var(--snack-font-size, 2.1rem) * 1.1);
48
- display: grid;
49
- grid-template-columns: 5fr 1fr;
50
- grid-template-rows: 1fr;
51
52
  }
53
+
52
54
  p {
53
55
  font-size: var(--snack-font-size, 2.1rem);
54
56
  font-weight: 400;
55
57
  line-height: var(--snack-font-size, 2.1rem);
56
58
  }
57
- button {
59
+
60
+ #snackBtn {
58
61
  width: var(--snack-font-size, 2.1rem);
59
62
  height: var(--snack-font-size, 2.1rem);
60
63
 
@@ -62,8 +65,11 @@ class SnackBar extends LitElement {
62
65
  border: none;
63
66
  cursor: pointer;
64
67
 
65
- position: relative;
68
+ position: absolute;
69
+ top: calc(var(--snack-font-size, 2.1rem) * 1.3);
70
+ right: 3rem;
66
71
  }
72
+
67
73
  button::after {
68
74
  content: '';
69
75
  position: absolute;
@@ -79,14 +85,17 @@ class SnackBar extends LitElement {
79
85
  transform: scale(0);
80
86
  transition: 0.3s cubic-bezier(.95, .32, .37, 1.21);
81
87
  }
88
+
82
89
  button:hover::after {
83
90
  transform: scale(1);
84
91
  }
92
+
85
93
  button svg {
86
94
  width: var(--snack-font-size, 2.1rem);
87
95
  height: var(--snack-font-size, 2.1rem);
88
96
  fill: var(--snack-txt-color, #f5f5f5);
89
97
  }
98
+
90
99
  button:hover svg {
91
100
  transform: scale(0.95);
92
101
  }
@@ -117,18 +126,25 @@ class SnackBar extends LitElement {
117
126
  reflect: true
118
127
  },
119
128
  active: Boolean,
120
- timing: Number
129
+ timing: Number,
130
+ closebtn: {
131
+ type: Boolean,
132
+ reflect: true
133
+ }
121
134
  }
122
135
  }
123
136
 
124
137
  constructor () {
125
138
  super()
126
139
  this.title = '🌰 ... SnackBar Title' || ''
127
- this.timing = 3000
140
+ this.timing = 5000
128
141
  }
129
142
 
130
143
  connectedCallback () {
131
144
  super.connectedCallback()
145
+ this.addEventListener('click', this.#deactivate)
146
+
147
+ console.log('@CLOSE-BTN >> ', this.closebtn)
132
148
  }
133
149
 
134
150
  disconnectedCallback () {
@@ -136,6 +152,20 @@ class SnackBar extends LitElement {
136
152
  super.disconnectedCallback()
137
153
  }
138
154
 
155
+ /**
156
+ * Direct method to show the snackbar
157
+ * @returns {void}
158
+ */
159
+ show (msg, time=2700, bkColor='#333', txtColor='#f5f5f5') {
160
+
161
+ this.title = msg
162
+ this.timing = time
163
+
164
+ this.style.setProperty('--snack-bk-color', bkColor)
165
+ this.style.setProperty('--snack-txt-color', txtColor)
166
+ this.setAttribute('active', '')
167
+ }
168
+
139
169
  updated (changed) {
140
170
  if (changed.has('active')) {
141
171
  if (this.hasAttribute('active')) {
@@ -179,12 +209,18 @@ class SnackBar extends LitElement {
179
209
  ${this.title}
180
210
  </p>
181
211
 
182
- <button @click=${this.closeSnackbar}>
183
- <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
184
- <path d="M0 0h24v24H0V0z" fill="none"/>
185
- <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/>
186
- </svg>
187
- </button>
212
+ ${this.closebtn ?
213
+ html`
214
+ <!-- deprecated -->
215
+ <button
216
+ id="snackBtn"
217
+ @click=${this.closeSnackbar}>
218
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
219
+ <path d="M0 0h24v24H0V0z" fill="none"/>
220
+ <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/>
221
+ </svg>
222
+ </button>` : null
223
+ }
188
224
 
189
225
  </div>
190
226
  </div>
package/vite.config.js CHANGED
@@ -3,15 +3,20 @@ import { resolve } from 'path'
3
3
 
4
4
  // https://vitejs.dev/config/
5
5
  export default defineConfig({
6
- build: {
7
- lib: {
8
- entry: 'snack-bar.js',
9
- formats: ['es']
10
- },
11
- rollupOptions: {
12
- input: {
13
- main: resolve(__dirname, 'index.html')
14
- }
15
- }
16
- }
17
- })
6
+ build: {
7
+ lib: {
8
+ entry: 'src/app-lite.js',
9
+ formats: ['es']
10
+ },
11
+ rollupOptions: {
12
+ input: {
13
+ main: resolve(__dirname, 'index.html')
14
+ }
15
+ }
16
+ },
17
+ esbuild: {
18
+ supported: {
19
+ 'top-level-await': true // top-level-await feature
20
+ }
21
+ }
22
+ })