@cicciosgamino/snack-bar 1.1.0 → 1.3.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,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.0] - 06-06-2023
10
+
11
+ ### Changed
12
+ - Minor fix
13
+ - Click to close the component
14
+
9
15
  ## [1.1.0] - 29-07-2021
16
+
10
17
  ### Changed
11
18
  - Change module part in package.json, link to source snack-bar.js
12
19
 
13
20
  ## [1.0.0] - 07-07-2021
21
+
14
22
  ### Added
15
23
  - 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) 2023 @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,6 +56,7 @@ 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
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.
@@ -83,11 +89,11 @@
83
89
  setTimeout(() => {
84
90
  // active the snack
85
91
  snack.setAttribute('active', '')
86
- }, 5000)
92
+ }, 1000)
87
93
  setTimeout(() => {
88
94
  // close the snack (before timing ended)
89
95
  snack.closeSnackbar()
90
- }, 8000)
96
+ }, 28000)
91
97
  })
92
98
  </script>
93
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cicciosgamino/snack-bar",
3
- "version": "1.1.0",
3
+ "version": "1.3.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": "^4.3.9"
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 () {
@@ -179,12 +195,18 @@ class SnackBar extends LitElement {
179
195
  ${this.title}
180
196
  </p>
181
197
 
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>
198
+ ${this.closebtn ?
199
+ html`
200
+ <!-- deprecated -->
201
+ <button
202
+ id="snackBtn"
203
+ @click=${this.closeSnackbar}>
204
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
205
+ <path d="M0 0h24v24H0V0z" fill="none"/>
206
+ <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"/>
207
+ </svg>
208
+ </button>` : null
209
+ }
188
210
 
189
211
  </div>
190
212
  </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
+ })