@manufosela/slide-notification 2.0.1 → 2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 manufosela
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -130,6 +130,14 @@ showSlideNotification({
130
130
  | `--slide-notification-z-index` | `10000` | Z-index |
131
131
  | `--slide-notification-min-height` | `80px` | Minimum height |
132
132
 
133
+ ## Accessibility
134
+
135
+ - Uses `role="alert"` with `aria-live="assertive"` for error/warning types
136
+ - Uses `role="status"` with `aria-live="polite"` for info/success types
137
+ - Icons are hidden from screen readers (`aria-hidden="true"`)
138
+ - Click-to-close for persistent notifications is accessible
139
+ - Respects `prefers-reduced-motion` by disabling slide animation
140
+
133
141
  ## slide-notification vs toast-notification
134
142
 
135
143
  This library includes two notification components. Choose based on your needs:
package/package.json CHANGED
@@ -1,18 +1,26 @@
1
1
  {
2
2
  "name": "@manufosela/slide-notification",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Slide-in notification web component from the right edge",
5
- "main": "src/slide-notification.js",
6
- "module": "src/slide-notification.js",
5
+ "license": "MIT",
6
+ "author": "manufosela",
7
7
  "type": "module",
8
+ "main": "./src/slide-notification.js",
9
+ "module": "./src/slide-notification.js",
10
+ "types": "./src/slide-notification.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./src/slide-notification.d.ts",
14
+ "import": "./src/slide-notification.js"
15
+ }
16
+ },
8
17
  "files": [
9
18
  "src"
10
19
  ],
11
- "scripts": {
12
- "start": "web-dev-server --node-resolve --open demo/ --watch",
13
- "test": "web-test-runner",
14
- "test:watch": "web-test-runner --watch",
15
- "test:coverage": "web-test-runner --coverage"
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/manufosela/ui-components",
23
+ "directory": "packages/slide-notification"
16
24
  },
17
25
  "keywords": [
18
26
  "web-components",
@@ -22,13 +30,6 @@
22
30
  "toast",
23
31
  "alert"
24
32
  ],
25
- "author": "manufosela",
26
- "license": "MIT",
27
- "repository": {
28
- "type": "git",
29
- "url": "https://github.com/manufosela/ui-components",
30
- "directory": "packages/slide-notification"
31
- },
32
33
  "homepage": "https://github.com/manufosela/ui-components/tree/main/packages/slide-notification#readme",
33
34
  "bugs": {
34
35
  "url": "https://github.com/manufosela/ui-components/issues"
@@ -36,9 +37,12 @@
36
37
  "dependencies": {
37
38
  "lit": "^3.2.1"
38
39
  },
39
- "devDependencies": {
40
- "@open-wc/testing": "^4.0.0",
41
- "@web/dev-server": "^0.4.6",
42
- "@web/test-runner": "^0.19.0"
40
+ "customElements": "custom-elements.json",
41
+ "scripts": {
42
+ "start": "web-dev-server --node-resolve --open demo/ --watch",
43
+ "test": "web-test-runner",
44
+ "test:watch": "web-test-runner --watch",
45
+ "test:coverage": "web-test-runner --coverage",
46
+ "build:types": "tsc --declaration --declarationMap --emitDeclarationOnly --allowJs --checkJs --outDir ./src ./src/slide-notification.js"
43
47
  }
44
- }
48
+ }
@@ -2,22 +2,16 @@ import { LitElement, html } from 'lit';
2
2
  import { unsafeHTML } from 'lit/directives/unsafe-html.js';
3
3
  import { slideNotificationStyles } from './slide-notification.styles.js';
4
4
 
5
- const DEFAULT_COLORS = {
6
- error: '#dc3545',
7
- success: '#22c55e',
8
- warning: '#ffc107',
9
- info: '#17a2b8'
10
- };
11
-
12
5
  const ICONS = {
13
6
  error: '❌',
14
7
  success: '✅',
15
8
  warning: '⚠️',
16
- info: 'ℹ️'
9
+ info: 'ℹ️',
17
10
  };
18
11
 
19
12
  /**
20
13
  * A slide-in notification component from the right edge.
14
+ * Fully themeable via CSS custom properties with design system token fallbacks.
21
15
  *
22
16
  * @element slide-notification
23
17
  * @fires slide-notification-shown - Fired when notification appears
@@ -27,14 +21,38 @@ const ICONS = {
27
21
  * @attr {String} message - Notification message (supports HTML)
28
22
  * @attr {Number} timetohide - Time in ms before auto-hide (default: 3000, 0 = persistent)
29
23
  * @attr {String} type - Type: 'info', 'success', 'warning', 'error'
30
- * @attr {String} background-color - Custom background color
24
+ * @attr {String} background-color - Custom background color (overrides type color)
31
25
  * @attr {Boolean} persistent - If true, notification stays until clicked (same as timetohide=0)
32
26
  *
33
- * @cssprop --slide-notification-width - Width (default: 300px)
34
- * @cssprop --slide-notification-bg - Background color (default: #17a2b8)
35
- * @cssprop --slide-notification-color - Text color (default: white)
36
- * @cssprop --slide-notification-radius - Border radius (default: 8px)
37
- * @cssprop --slide-notification-z-index - Z-index (default: 10000)
27
+ * @csspart container - The notification container wrapper
28
+ * @csspart title - The notification title element
29
+ * @csspart content - The notification content wrapper (icon + message)
30
+ * @csspart icon - The notification icon
31
+ * @csspart message - The notification message element
32
+ *
33
+ * @cssprop [--notification-bg] - Background color (falls back to type-specific token)
34
+ * @cssprop [--notification-text] - Text color (falls back to --text-inverse or #ffffff)
35
+ * @cssprop [--notification-border-radius] - Border radius (falls back to --radius-md or 6px)
36
+ * @cssprop [--notification-shadow] - Box shadow (falls back to --shadow-lg)
37
+ * @cssprop [--notification-padding] - Padding (falls back to --spacing-md or 1rem)
38
+ * @cssprop [--notification-min-width=300px] - Minimum width
39
+ * @cssprop [--notification-max-width=400px] - Maximum width
40
+ * @cssprop [--notification-min-height=80px] - Minimum height
41
+ * @cssprop [--notification-bottom=20px] - Distance from bottom
42
+ * @cssprop [--notification-z-index=10000] - Z-index
43
+ *
44
+ * @cssprop [--notification-title-size] - Title font size (falls back to --font-size-lg or 1.1rem)
45
+ * @cssprop [--notification-title-weight=600] - Title font weight
46
+ * @cssprop [--notification-message-size] - Message font size (falls back to --font-size-base or 1rem)
47
+ * @cssprop [--notification-icon-size=1.2em] - Icon size
48
+ *
49
+ * @cssprop [--notification-animation-duration=0.5s] - Animation duration
50
+ * @cssprop [--notification-slide-distance=100%] - Slide distance
51
+ *
52
+ * @cssprop [--notification-success-bg=#22c55e] - Success type background
53
+ * @cssprop [--notification-error-bg=#dc3545] - Error type background
54
+ * @cssprop [--notification-warning-bg=#ffc107] - Warning type background
55
+ * @cssprop [--notification-info-bg=#17a2b8] - Info type background
38
56
  */
39
57
  export class SlideNotification extends LitElement {
40
58
  static styles = slideNotificationStyles;
@@ -83,10 +101,12 @@ export class SlideNotification extends LitElement {
83
101
  this.classList.remove('hiding');
84
102
  this.classList.add('visible');
85
103
 
86
- this.dispatchEvent(new CustomEvent('slide-notification-shown', {
87
- bubbles: true,
88
- composed: true
89
- }));
104
+ this.dispatchEvent(
105
+ new CustomEvent('slide-notification-shown', {
106
+ bubbles: true,
107
+ composed: true,
108
+ })
109
+ );
90
110
  });
91
111
 
92
112
  // Auto-hide after timeout (unless persistent)
@@ -103,7 +123,7 @@ export class SlideNotification extends LitElement {
103
123
  if (this.persistent || this.timetohide === 0) {
104
124
  this.hide();
105
125
  }
106
- }
126
+ };
107
127
 
108
128
  disconnectedCallback() {
109
129
  super.disconnectedCallback();
@@ -126,10 +146,12 @@ export class SlideNotification extends LitElement {
126
146
  this.classList.remove('visible');
127
147
  this.classList.add('hiding');
128
148
 
129
- this.dispatchEvent(new CustomEvent('slide-notification-hidden', {
130
- bubbles: true,
131
- composed: true
132
- }));
149
+ this.dispatchEvent(
150
+ new CustomEvent('slide-notification-hidden', {
151
+ bubbles: true,
152
+ composed: true,
153
+ })
154
+ );
133
155
 
134
156
  // Remove from DOM if created programmatically
135
157
  if (this._removeOnHide) {
@@ -141,36 +163,30 @@ export class SlideNotification extends LitElement {
141
163
  this._showNotification();
142
164
  }
143
165
 
144
- _getBackgroundColor() {
145
- if (this.backgroundColor) return this.backgroundColor;
146
- return DEFAULT_COLORS[this.type] || DEFAULT_COLORS.info;
166
+ _getRole() {
167
+ // Use alert for error/warning (more urgent), status for info/success
168
+ return this.type === 'error' || this.type === 'warning' ? 'alert' : 'status';
147
169
  }
148
170
 
149
- _getTextColor() {
150
- return this.type === 'warning' ? '#212529' : 'white';
151
- }
152
-
153
- _getTextShadow() {
154
- return this.type === 'warning'
155
- ? '1px 1px 2px rgba(0, 0, 0, 0.3)'
156
- : '1px 1px 2px rgba(0, 0, 0, 0.5)';
171
+ _getAriaLive() {
172
+ return this.type === 'error' || this.type === 'warning' ? 'assertive' : 'polite';
157
173
  }
158
174
 
159
175
  render() {
160
176
  const icon = ICONS[this.type] || ICONS.info;
161
- const bgColor = this._getBackgroundColor();
162
- const textColor = this._getTextColor();
163
- const textShadow = this._getTextShadow();
164
177
 
165
- this.style.setProperty('--_bg', bgColor);
166
- this.style.setProperty('--_color', textColor);
167
- this.style.setProperty('--_text-shadow', textShadow);
178
+ // Allow backgroundColor attribute to override CSS token
179
+ if (this.backgroundColor) {
180
+ this.style.setProperty('--notification-bg', this.backgroundColor);
181
+ }
168
182
 
169
183
  return html`
170
- ${this.title ? html`<div class="title">${this.title}</div>` : ''}
171
- <div class="notification-content">
172
- <span class="icon">${icon}</span>
173
- <div class="message">${unsafeHTML(this.message)}</div>
184
+ <div part="container" role="${this._getRole()}" aria-live="${this._getAriaLive()}">
185
+ ${this.title ? html`<div class="title" part="title">${this.title}</div>` : ''}
186
+ <div class="notification-content" part="content">
187
+ <span class="icon" part="icon" aria-hidden="true">${icon}</span>
188
+ <div class="message" part="message">${unsafeHTML(this.message)}</div>
189
+ </div>
174
190
  </div>
175
191
  `;
176
192
  }
@@ -185,7 +201,7 @@ customElements.define('slide-notification', SlideNotification);
185
201
  * @param {string} options.message - Notification message (supports HTML)
186
202
  * @param {number} options.timetohide - Time in ms before auto-hide (default: 3000, 0 = persistent)
187
203
  * @param {string} options.type - Type: 'info' | 'success' | 'warning' | 'error'
188
- * @param {string} options.backgroundColor - Custom background color
204
+ * @param {string} options.backgroundColor - Custom background color (overrides type)
189
205
  * @param {boolean} options.persistent - If true, stays until clicked
190
206
  * @returns {SlideNotification} The created notification element
191
207
  */
@@ -2,41 +2,85 @@ import { css } from 'lit';
2
2
 
3
3
  export const slideNotificationStyles = css`
4
4
  :host {
5
- --_width: var(--slide-notification-width, 300px);
6
- --_bg: var(--slide-notification-bg, #17a2b8);
7
- --_color: var(--slide-notification-color, white);
8
- --_text-shadow: var(--slide-notification-text-shadow, 1px 1px 2px rgba(0, 0, 0, 0.5));
5
+ /* ========================================
6
+ Design System Tokens
7
+ ======================================== */
9
8
 
9
+ /* Base tokens */
10
+ --notification-bg: var(--notification-info-bg, #17a2b8);
11
+ --notification-text: var(--text-inverse, #ffffff);
12
+ --notification-border-radius: var(--radius-md, 6px);
13
+ --notification-shadow: var(--shadow-lg, 0 4px 8px rgba(0, 0, 0, 0.15));
14
+ --notification-padding: var(--spacing-md, 1rem);
15
+ --notification-min-width: 300px;
16
+ --notification-max-width: 400px;
17
+
18
+ /* Title */
19
+ --notification-title-size: var(--font-size-lg, 1.1rem);
20
+ --notification-title-weight: 600;
21
+
22
+ /* Message */
23
+ --notification-message-size: var(--font-size-base, 1rem);
24
+
25
+ /* Icon */
26
+ --notification-icon-size: 1.2em;
27
+
28
+ /* Animation */
29
+ --notification-animation-duration: 0.5s;
30
+ --notification-slide-distance: 100%;
31
+
32
+ /* Layout */
10
33
  position: fixed;
11
- bottom: var(--slide-notification-bottom, 20px);
12
- right: calc(-20px - var(--_width));
13
- width: var(--_width);
14
- min-height: var(--slide-notification-min-height, 80px);
15
- background: var(--_bg);
16
- color: var(--_color);
17
- border-radius: var(--slide-notification-radius, 8px);
34
+ bottom: var(--notification-bottom, 20px);
35
+ right: calc(-20px - var(--notification-max-width));
36
+ width: var(--notification-max-width);
37
+ min-width: var(--notification-min-width);
38
+ min-height: var(--notification-min-height, 80px);
39
+ background: var(--notification-bg);
40
+ color: var(--notification-text);
41
+ border-radius: var(--notification-border-radius);
18
42
  border-left: 4px solid rgba(255, 255, 255, 0.3);
19
- padding: var(--slide-notification-padding, 1.5rem);
20
- box-shadow: var(--slide-notification-shadow, 0 2px 8px rgba(0, 0, 0, 0.2));
21
- font-size: 1rem;
43
+ padding: var(--notification-padding);
44
+ box-shadow: var(--notification-shadow);
45
+ font-size: var(--notification-message-size);
22
46
  font-weight: 500;
23
47
  opacity: 0;
24
- transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
48
+ transition:
49
+ transform var(--notification-animation-duration) ease-in-out,
50
+ opacity var(--notification-animation-duration) ease-in-out;
25
51
  transform: translateX(0);
26
- z-index: var(--slide-notification-z-index, 10000);
52
+ z-index: var(--notification-z-index, 10000);
27
53
  display: flex;
28
54
  flex-direction: column;
29
55
  justify-content: center;
30
56
  align-items: center;
31
57
  }
32
58
 
59
+ /* Type variants using attribute selectors */
60
+ :host([type='success']) {
61
+ --notification-bg: var(--notification-success-bg, #22c55e);
62
+ }
63
+
64
+ :host([type='error']) {
65
+ --notification-bg: var(--notification-error-bg, #dc3545);
66
+ }
67
+
68
+ :host([type='warning']) {
69
+ --notification-bg: var(--notification-warning-bg, #ffc107);
70
+ --notification-text: var(--text-primary, #333333);
71
+ }
72
+
73
+ :host([type='info']) {
74
+ --notification-bg: var(--notification-info-bg, #17a2b8);
75
+ }
76
+
33
77
  :host(.visible) {
34
78
  opacity: 1;
35
- transform: translateX(calc(-1 * var(--_width) - 40px));
79
+ transform: translateX(calc(-1 * var(--notification-max-width) - 40px));
36
80
  }
37
81
 
38
82
  :host(.hiding) {
39
- transform: translateX(calc(var(--_width) + 40px));
83
+ transform: translateX(calc(var(--notification-max-width) + 40px));
40
84
  }
41
85
 
42
86
  :host([persistent]) {
@@ -44,9 +88,10 @@ export const slideNotificationStyles = css`
44
88
  }
45
89
 
46
90
  .title {
47
- font-weight: 600;
91
+ font-size: var(--notification-title-size);
92
+ font-weight: var(--notification-title-weight);
48
93
  margin-bottom: 0.25rem;
49
- text-shadow: var(--_text-shadow);
94
+ text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
50
95
  }
51
96
 
52
97
  .notification-content {
@@ -56,12 +101,19 @@ export const slideNotificationStyles = css`
56
101
  }
57
102
 
58
103
  .message {
104
+ font-size: var(--notification-message-size);
59
105
  font-weight: 500;
60
- text-shadow: var(--_text-shadow);
106
+ text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
61
107
  }
62
108
 
63
109
  .icon {
64
- font-size: 1.2em;
110
+ font-size: var(--notification-icon-size);
65
111
  flex-shrink: 0;
66
112
  }
113
+
114
+ @media (prefers-reduced-motion: reduce) {
115
+ :host {
116
+ transition: none;
117
+ }
118
+ }
67
119
  `;