@alacris/ui 0.6.2 → 0.8.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/README.md +3 -3
- package/package.json +1 -1
- package/src/components/ui-chip.js +7 -3
- package/src/components/ui-snackbar.js +15 -8
package/README.md
CHANGED
|
@@ -47,9 +47,9 @@ The published package is plain ESM. Point an import map at a pinned CDN build of
|
|
|
47
47
|
{
|
|
48
48
|
"imports": {
|
|
49
49
|
"@alacris/core": "https://cdn.jsdelivr.net/npm/@alacris/core@0.11.5/dist/alacris.js",
|
|
50
|
-
"@alacris/ui": "https://cdn.jsdelivr.net/npm/@alacris/ui@0.
|
|
51
|
-
"@alacris/ui/theme": "https://cdn.jsdelivr.net/npm/@alacris/ui@0.
|
|
52
|
-
"@alacris/ui/components/": "https://cdn.jsdelivr.net/npm/@alacris/ui@0.
|
|
50
|
+
"@alacris/ui": "https://cdn.jsdelivr.net/npm/@alacris/ui@0.8.0/src/index.js",
|
|
51
|
+
"@alacris/ui/theme": "https://cdn.jsdelivr.net/npm/@alacris/ui@0.8.0/src/theme/index.js",
|
|
52
|
+
"@alacris/ui/components/": "https://cdn.jsdelivr.net/npm/@alacris/ui@0.8.0/src/components/"
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
</script>
|
package/package.json
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
// removes itself.
|
|
12
12
|
//
|
|
13
13
|
// @prop {string} variant='assist' — assist | filter | input | suggestion
|
|
14
|
-
// @prop {boolean} selected=false — filter chips
|
|
14
|
+
// @prop {boolean} selected=false — filter chips (toggle, check icon) and input chips
|
|
15
|
+
// (MD3 selected input chip: filled, no check;
|
|
16
|
+
// the app owns the state and its ARIA)
|
|
15
17
|
// @prop {boolean} disabled=false
|
|
16
18
|
// @prop {string} icon='' — leading icon name (check replaces it while
|
|
17
19
|
// a filter chip is selected)
|
|
@@ -73,7 +75,7 @@ const styles = css`
|
|
|
73
75
|
border-color ${sys.duration.short2} ${sys.easing.standard},
|
|
74
76
|
padding-inline-start ${sys.duration.short4} ${sys.easing.emphasized};
|
|
75
77
|
}
|
|
76
|
-
.
|
|
78
|
+
.checked .control { padding-inline-start: ${sys.space(2)}; }
|
|
77
79
|
.lead {
|
|
78
80
|
display: inline-flex;
|
|
79
81
|
align-items: center;
|
|
@@ -159,9 +161,11 @@ define('ui-chip', {
|
|
|
159
161
|
});
|
|
160
162
|
|
|
161
163
|
const checkWhen = computed(() => variant() === 'filter' && selected());
|
|
164
|
+
const filled = computed(() => checkWhen() || (variant() === 'input' && selected()));
|
|
162
165
|
const rootCls = computed(() =>
|
|
163
166
|
[
|
|
164
|
-
|
|
167
|
+
filled() ? 'selected' : '',
|
|
168
|
+
checkWhen() ? 'checked' : '',
|
|
165
169
|
icon() ? 'with-lead' : '',
|
|
166
170
|
dismissible() ? 'with-dismiss' : '',
|
|
167
171
|
].filter(Boolean).join(' '));
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Imperative (fire and forget; FIFO — one visible at a time):
|
|
10
10
|
//
|
|
11
|
-
// const { close, closed } = showSnackbar('Message archived', { action: 'Undo' });
|
|
11
|
+
// const { close, closed } = showSnackbar('Message archived', { action: 'Undo', onAction: undo });
|
|
12
|
+
// const { reason } = await closed // 'action' | 'timeout' | 'close' | 'method'
|
|
12
13
|
//
|
|
13
14
|
// The component requests closing by emitting `close` with a reason — the
|
|
14
15
|
// PARENT flips `open`. `closed` fires after the exit animation finishes.
|
|
@@ -183,11 +184,15 @@ function serviceHost() {
|
|
|
183
184
|
if (!serviceEl || !serviceEl.isConnected) {
|
|
184
185
|
serviceEl = document.createElement('ui-snackbar');
|
|
185
186
|
// The service is the "parent": it owns the open state.
|
|
186
|
-
serviceEl.addEventListener('close', () => {
|
|
187
|
+
serviceEl.addEventListener('close', (e) => {
|
|
188
|
+
if (current && !current.reason) current.reason = e.detail?.reason ?? 'close';
|
|
189
|
+
serviceEl.open = false;
|
|
190
|
+
});
|
|
191
|
+
serviceEl.addEventListener('action', () => current?.onAction?.());
|
|
187
192
|
serviceEl.addEventListener('closed', () => {
|
|
188
193
|
const done = current;
|
|
189
194
|
current = null;
|
|
190
|
-
done?.resolve();
|
|
195
|
+
done?.resolve({ reason: done.reason ?? 'close' });
|
|
191
196
|
next();
|
|
192
197
|
});
|
|
193
198
|
document.body.append(serviceEl);
|
|
@@ -210,23 +215,25 @@ function next() {
|
|
|
210
215
|
* showSnackbar(message, { action, duration, closeButton })
|
|
211
216
|
*
|
|
212
217
|
* Returns { close, closed }: `close()` dismisses this snackbar (or removes it
|
|
213
|
-
* from the queue if it has not shown yet); `closed` resolves
|
|
214
|
-
*
|
|
218
|
+
* from the queue if it has not shown yet); `closed` resolves with
|
|
219
|
+
* `{ reason }` ('action' | 'timeout' | 'close' | 'method') once it has fully
|
|
220
|
+
* left the screen. `onAction` runs when the action button is pressed.
|
|
215
221
|
*/
|
|
216
|
-
export function showSnackbar(message, { action = '', duration = 4000, closeButton = false } = {}) {
|
|
222
|
+
export function showSnackbar(message, { action = '', duration = 4000, closeButton = false, onAction } = {}) {
|
|
217
223
|
let resolve;
|
|
218
224
|
const closed = new Promise((r) => { resolve = r; });
|
|
219
|
-
const entry = { message, action, duration, closeButton, resolve };
|
|
225
|
+
const entry = { message, action, duration, closeButton, resolve, onAction, reason: null };
|
|
220
226
|
queue.push(entry);
|
|
221
227
|
next();
|
|
222
228
|
return {
|
|
223
229
|
closed,
|
|
224
230
|
close() {
|
|
225
231
|
if (current === entry) {
|
|
232
|
+
entry.reason ??= 'method';
|
|
226
233
|
serviceEl.open = false; // exit animation → 'closed' → resolve + next
|
|
227
234
|
} else {
|
|
228
235
|
const i = queue.indexOf(entry);
|
|
229
|
-
if (i > -1) { queue.splice(i, 1); entry.resolve(); }
|
|
236
|
+
if (i > -1) { queue.splice(i, 1); entry.resolve({ reason: 'method' }); }
|
|
230
237
|
}
|
|
231
238
|
},
|
|
232
239
|
};
|