@openameba/spindle-ui 0.45.0 → 0.46.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/DropdownMenu/DropdownMenu.css +1 -0
  3. package/DropdownMenu/DropdownMenu.d.ts +27 -0
  4. package/DropdownMenu/DropdownMenu.d.ts.map +1 -0
  5. package/DropdownMenu/DropdownMenu.js +119 -0
  6. package/DropdownMenu/DropdownMenu.js.map +1 -0
  7. package/DropdownMenu/DropdownMenu.mjs +82 -0
  8. package/DropdownMenu/index.d.ts +2 -0
  9. package/DropdownMenu/index.d.ts.map +1 -0
  10. package/DropdownMenu/index.js +6 -0
  11. package/DropdownMenu/index.js.map +1 -0
  12. package/DropdownMenu/index.mjs +1 -0
  13. package/HeroCarousel/HeroCarousel.js +3 -3
  14. package/HeroCarousel/HeroCarousel.js.map +1 -1
  15. package/HeroCarousel/HeroCarousel.mjs +3 -3
  16. package/SnackBar/SnackBar.css +1 -1
  17. package/SnackBar/SnackBar.d.ts +6 -11
  18. package/SnackBar/SnackBar.d.ts.map +1 -1
  19. package/SnackBar/SnackBar.js +43 -20
  20. package/SnackBar/SnackBar.js.map +1 -1
  21. package/SnackBar/SnackBar.mjs +40 -18
  22. package/StackNotificationManager/StackNotificationManager.d.ts +34 -0
  23. package/StackNotificationManager/StackNotificationManager.d.ts.map +1 -0
  24. package/StackNotificationManager/StackNotificationManager.js +50 -0
  25. package/StackNotificationManager/StackNotificationManager.js.map +1 -0
  26. package/StackNotificationManager/StackNotificationManager.mjs +20 -0
  27. package/StackNotificationManager/hooks.d.ts +44 -0
  28. package/StackNotificationManager/hooks.d.ts.map +1 -0
  29. package/StackNotificationManager/hooks.js +247 -0
  30. package/StackNotificationManager/hooks.js.map +1 -0
  31. package/StackNotificationManager/hooks.mjs +220 -0
  32. package/StackNotificationManager/index.d.ts +3 -0
  33. package/StackNotificationManager/index.d.ts.map +1 -0
  34. package/StackNotificationManager/index.js +10 -0
  35. package/StackNotificationManager/index.js.map +1 -0
  36. package/StackNotificationManager/index.mjs +2 -0
  37. package/Toast/Toast.css +1 -1
  38. package/Toast/Toast.d.ts +7 -5
  39. package/Toast/Toast.d.ts.map +1 -1
  40. package/Toast/Toast.js +34 -11
  41. package/Toast/Toast.js.map +1 -1
  42. package/Toast/Toast.mjs +31 -9
  43. package/index.css +1 -1
  44. package/index.d.ts +2 -1
  45. package/index.d.ts.map +1 -1
  46. package/index.js +3 -1
  47. package/index.js.map +1 -1
  48. package/index.mjs +2 -1
  49. package/package.json +2 -2
@@ -0,0 +1,220 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useStackNotificationManagerContext, } from './StackNotificationManager';
3
+ const MAX_STACK_SIZE_DESKTOP = 4;
4
+ const MAX_STACK_SIZE_MOBILE = 3;
5
+ /**
6
+ * Fallback for `MediaQueryList.onchange`
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/matches
8
+ */
9
+ function addMQListener(mq, callback) {
10
+ if (mq.addEventListener) {
11
+ mq.addEventListener('change', callback);
12
+ }
13
+ else {
14
+ mq.addListener(callback);
15
+ }
16
+ }
17
+ /**
18
+ * Fallback for `MediaQueryList.onchange`
19
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/matches
20
+ */
21
+ function removeMQListener(mq, callback) {
22
+ if (mq.removeEventListener) {
23
+ mq.removeEventListener('change', callback);
24
+ }
25
+ else {
26
+ mq.removeListener(callback);
27
+ }
28
+ }
29
+ const useBreakpoint = (breakpoint) => {
30
+ const mql = useRef(typeof window !== 'undefined' && window.matchMedia
31
+ ? window.matchMedia(breakpoint)
32
+ : undefined);
33
+ const [matches, setMatches] = useState(() => mql.current ? mql.current.matches : false);
34
+ const handleSetMatches = useCallback((e) => setMatches(e.matches), []);
35
+ useEffect(() => {
36
+ const current = mql.current;
37
+ if (current) {
38
+ addMQListener(current, handleSetMatches);
39
+ }
40
+ return () => {
41
+ if (current) {
42
+ removeMQListener(current, handleSetMatches);
43
+ }
44
+ };
45
+ }, []);
46
+ return matches;
47
+ };
48
+ const useMaxStackSize = () => {
49
+ const isMobile = useBreakpoint('(max-width: 464px)');
50
+ return isMobile ? MAX_STACK_SIZE_MOBILE : MAX_STACK_SIZE_DESKTOP;
51
+ };
52
+ export const useStackInteraction = () => {
53
+ const { setStack, setOffset: _setOffset } = useStackNotificationManagerContext();
54
+ const maxStackSize = useMaxStackSize();
55
+ const setActive = useCallback(({ id, active, position, }) => {
56
+ setStack((prev) => {
57
+ const _stack = prev[position] || [];
58
+ const stack = [..._stack];
59
+ let specifiedItem = stack.find((item) => item.id === id);
60
+ if (!specifiedItem) {
61
+ specifiedItem = {
62
+ id,
63
+ active: false,
64
+ order: 0,
65
+ isPreservingInternalActive: false,
66
+ contentHeight: 0,
67
+ };
68
+ stack.push(specifiedItem);
69
+ }
70
+ const shouldUpdate = specifiedItem?.active !== active ||
71
+ specifiedItem?.isPreservingInternalActive;
72
+ if (!shouldUpdate) {
73
+ return prev;
74
+ }
75
+ const totalActiveItems = stack.reduce((res, v) => v.active || v.isPreservingInternalActive ? res + 1 : res, 0);
76
+ const isOverMaxStackSize = totalActiveItems >= maxStackSize;
77
+ if (active && isOverMaxStackSize) {
78
+ stack
79
+ .sort((a, b) => (a.order > b.order ? 1 : -1))
80
+ .find((item) => {
81
+ if (item.active && !item.isPreservingInternalActive) {
82
+ item.active = false;
83
+ item.isPreservingInternalActive = true;
84
+ return true;
85
+ }
86
+ return false;
87
+ });
88
+ }
89
+ return {
90
+ ...prev,
91
+ [position]: stack.map((s) => {
92
+ const next = { ...s };
93
+ if (next.id === id) {
94
+ next.active = active;
95
+ next.isPreservingInternalActive = false;
96
+ }
97
+ if (next.id !== id &&
98
+ !active &&
99
+ (specifiedItem?.order || 0) <= next.order) {
100
+ next.order = Math.max(next.order - 1, 0);
101
+ }
102
+ if (next.id === id && active) {
103
+ next.order = totalActiveItems;
104
+ }
105
+ return next;
106
+ }),
107
+ };
108
+ });
109
+ }, []);
110
+ const setOffset = ({ offset, position, }) => {
111
+ _setOffset((prev) => ({ ...prev, [position]: offset }));
112
+ };
113
+ const setContentHeight = ({ id, height, position, }) => {
114
+ setStack((prev) => {
115
+ const _stack = prev[position] || [];
116
+ const stack = [..._stack];
117
+ const specifiedItem = stack.find((item) => item.id === id);
118
+ if (!specifiedItem) {
119
+ return prev;
120
+ }
121
+ const next = { ...specifiedItem };
122
+ next.contentHeight = height;
123
+ return {
124
+ ...prev,
125
+ [position]: stack.map((s) => (s.id === id ? next : s)),
126
+ };
127
+ });
128
+ };
129
+ return {
130
+ setActive,
131
+ setOffset,
132
+ setContentHeight,
133
+ };
134
+ };
135
+ export const useStackNotificationManager = ({ id, position, }) => {
136
+ const { stackRef, setStack, offset } = useStackNotificationManagerContext();
137
+ const stack = stackRef.current;
138
+ const { setActive: _setActive, setOffset: _setOffset, setContentHeight: _setContentHeight, } = useStackInteraction();
139
+ const setActive = useCallback((active) => {
140
+ _setActive({ id, active, position });
141
+ }, [id, position]);
142
+ const setOffset = useCallback((offset) => {
143
+ _setOffset({ position, offset });
144
+ }, [position]);
145
+ const setContentHeight = useCallback((height) => {
146
+ _setContentHeight({ id, position, height });
147
+ }, [position]);
148
+ useEffect(() => {
149
+ setStack((prev) => {
150
+ const stack = prev[position] || [];
151
+ const item = stack?.find((s) => s.id === id);
152
+ if (item) {
153
+ return prev;
154
+ }
155
+ // If stack item does not find, create stack item.
156
+ return {
157
+ ...prev,
158
+ [position]: [
159
+ ...stack,
160
+ {
161
+ id,
162
+ active: false,
163
+ order: 0,
164
+ contentHeight: 0,
165
+ },
166
+ ],
167
+ };
168
+ });
169
+ return () => {
170
+ setStack((prev) => {
171
+ return {
172
+ ...prev,
173
+ [position]: [...(prev[position]?.filter((s) => s.id !== id) || [])],
174
+ };
175
+ });
176
+ };
177
+ }, []);
178
+ const item = useMemo(() => stack[position]?.find((s) => s.id === id), [stack, id, position]);
179
+ const stackPosition = useMemo(() => {
180
+ const _stackItem = stack[position] || [];
181
+ const stackItem = [..._stackItem];
182
+ return stackItem
183
+ .sort((a, b) => (a.order > b.order ? 1 : -1))
184
+ .reduce((res, v) => (v.active || v.isPreservingInternalActive) &&
185
+ v.order < (item?.order || 0)
186
+ ? res + v.contentHeight
187
+ : res, 0);
188
+ }, [stack]);
189
+ return {
190
+ stackProps: {
191
+ ...(item || {}),
192
+ position,
193
+ offset: offset[position],
194
+ stackPosition,
195
+ setContentHeight,
196
+ },
197
+ setActive,
198
+ setOffset,
199
+ };
200
+ };
201
+ export const useRepeatedStackItem = ({ id, position, }) => {
202
+ const [idList, setIdList] = useState([]);
203
+ const lastIndex = useRef(0);
204
+ const { setActive } = useStackInteraction();
205
+ const append = useCallback(() => {
206
+ const nextId = `${id}-${lastIndex.current}`;
207
+ lastIndex.current += 1;
208
+ setActive({ id: nextId, position, active: true });
209
+ setIdList((prev) => [...prev, nextId]);
210
+ }, [id, position, idList]);
211
+ const onHide = useCallback((id) => {
212
+ setActive({ id, position, active: false });
213
+ setIdList((prev) => prev.filter((item) => item !== id));
214
+ }, [position]);
215
+ return {
216
+ idList,
217
+ append,
218
+ onHide,
219
+ };
220
+ };
@@ -0,0 +1,3 @@
1
+ export { StackNotificationManagerProvider, StackPosition, StackOffset, StackPositionOffset, ManagedStack, } from './StackNotificationManager';
2
+ export { useStackNotificationManager, useStackInteraction, useRepeatedStackItem, } from './hooks';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/StackNotificationManager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,YAAY,GACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRepeatedStackItem = exports.useStackInteraction = exports.useStackNotificationManager = exports.StackNotificationManagerProvider = void 0;
4
+ var StackNotificationManager_1 = require("./StackNotificationManager");
5
+ Object.defineProperty(exports, "StackNotificationManagerProvider", { enumerable: true, get: function () { return StackNotificationManager_1.StackNotificationManagerProvider; } });
6
+ var hooks_1 = require("./hooks");
7
+ Object.defineProperty(exports, "useStackNotificationManager", { enumerable: true, get: function () { return hooks_1.useStackNotificationManager; } });
8
+ Object.defineProperty(exports, "useStackInteraction", { enumerable: true, get: function () { return hooks_1.useStackInteraction; } });
9
+ Object.defineProperty(exports, "useRepeatedStackItem", { enumerable: true, get: function () { return hooks_1.useRepeatedStackItem; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/StackNotificationManager/index.ts"],"names":[],"mappings":";;;AAAA,uEAMoC;AALlC,4IAAA,gCAAgC,OAAA;AAMlC,iCAIiB;AAHf,oHAAA,2BAA2B,OAAA;AAC3B,4GAAA,mBAAmB,OAAA;AACnB,6GAAA,oBAAoB,OAAA"}
@@ -0,0 +1,2 @@
1
+ export { StackNotificationManagerProvider, } from './StackNotificationManager';
2
+ export { useStackNotificationManager, useStackInteraction, useRepeatedStackItem, } from './hooks';
package/Toast/Toast.css CHANGED
@@ -1 +1 @@
1
- :root{--IconButton-tapHighlightColor:var(--gray-5-alpha);--IconButton-onFocus-outlineColor:var(--color-focus-clarity);--IconButton--contained-backgroundColor:var(--color-surface-accent-primary);--IconButton--contained-color:var(--color-object-high-emphasis-inverse);--IconButton--contained-onActive-backgroundColor:var(--primary-green-100);--IconButton--contained-onHover-backgroundColor:var(--primary-green-100);--IconButton--outlined-borderColor:var(--color-border-accent-primary);--IconButton--outlined-color:var(--color-object-accent-primary);--IconButton--outlined-onActive-backgroundColor:var(--primary-green-5);--IconButton--outlined-onHover-backgroundColor:var(--primary-green-5);--IconButton--lighted-backgroundColor:var(--color-surface-accent-primary-light);--IconButton--lighted-color:var(--color-object-accent-primary);--IconButton--lighted-onActive-backgroundColor:var(--primary-green-10);--IconButton--lighted-onHover-backgroundColor:var(--primary-green-10);--IconButton--neutral-backgroundColor:var(--color-surface-tertiary);--IconButton--neutral-color:var(--color-object-medium-emphasis);--IconButton--neutral-onActive-backgroundColor:var(--gray-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--gray-20-alpha);--IconButton--danger-borderColor:var(--color-border-caution);--IconButton--danger-color:var(--color-object-caution);--IconButton--danger-onActive-backgroundColor:var(--caution-red-5-alpha);--IconButton--danger-onHover-backgroundColor:var(--caution-red-5-alpha)}.spui-IconButton{align-items:center;border-radius:100%;box-sizing:border-box;display:inline-flex;justify-content:center;margin:0;padding:0;-webkit-tap-highlight-color:var(--IconButton-tapHighlightColor);text-align:center;transition:background-color .3s}.spui-IconButton:disabled{opacity:.3}.spui-IconButton:focus{outline:2px solid var(--IconButton-onFocus-outlineColor);outline-offset:1px}.spui-IconButton:focus:not(:focus-visible){outline:none}.spui-IconButton--large{font-size:1.375em;height:48px;width:48px}.spui-IconButton--medium{font-size:1.25em;height:40px;width:40px}.spui-IconButton--small{font-size:1em;height:32px;width:32px}.spui-IconButton--exSmall{font-size:1em;height:24px;width:24px}.spui-IconButton--contained{background-color:var(--IconButton--contained-backgroundColor);border:none;color:var(--IconButton--contained-color)}.spui-IconButton--contained:active{background-color:var(--IconButton--contained-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--contained:not([disabled]):hover{background-color:var(--IconButton--contained-onHover-backgroundColor)}}.spui-IconButton--outlined{background-color:transparent;border:2px solid var(--IconButton--outlined-borderColor);color:var(--IconButton--outlined-color)}.spui-IconButton--outlined:active{background-color:var(--IconButton--outlined-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--outlined:not([disabled]):hover{background-color:var(--IconButton--outlined-onHover-backgroundColor)}}.spui-IconButton--lighted{background-color:var(--IconButton--lighted-backgroundColor);border:none;color:var(--IconButton--lighted-color);padding-bottom:8px;padding-top:8px}.spui-IconButton--lighted:active{background-color:var(--IconButton--lighted-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--lighted:not([disabled]):hover{background-color:var(--IconButton--lighted-onHover-backgroundColor)}}.spui-IconButton--neutral{background-color:var(--IconButton--neutral-backgroundColor);border:none;color:var(--IconButton--neutral-color)}.spui-IconButton--neutral:active{background-color:var(--IconButton--neutral-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--neutral:not([disabled]):hover{background-color:var(--IconButton--neutral-onHover-backgroundColor)}}.spui-IconButton--danger{background-color:transparent;border:2px solid var(--IconButton--danger-borderColor);color:var(--IconButton--danger-color)}.spui-IconButton--danger:active{background-color:var(--IconButton--danger-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--danger:hover{background-color:var(--IconButton--danger-onHover-backgroundColor)}}:root{--Toast-z-index:1}.spui-Toast{box-sizing:border-box;left:0;padding:0 12px;position:fixed;right:0;text-align:center;z-index:var(--Toast-z-index)}.spui-Toast-content{align-items:center;border-radius:52px;box-shadow:0 11px 28px rgba(8,18,26,.24);box-sizing:border-box;display:inline-flex;margin:0;max-width:360px;min-height:48px;padding:0 16px 0 20px}.spui-Toast-contentInfo{flex-shrink:0;font-size:1.375rem;line-height:0;margin-right:8px}.spui-Toast-contentText{font-family:inherit;font-size:.875rem;font-weight:700;line-height:1.6;overflow:hidden;white-space:nowrap}.spui-Toast--top{top:0;transform:translateY(calc(var(--Toast--initial-height) - var(--Toast--offset-top)))}.spui-Toast--bottom{bottom:0;transform:translateY(calc(var(--Toast--initial-height)*-1 - var(--Toast--offset-bottom)*-1))}.spui-Toast--slide{opacity:0;transition:transform .3s ease,opacity .3s ease}.spui-Toast--hidden{visibility:hidden}.spui-Toast-slide--in{opacity:1;transition:transform .5s ease,opacity .5s ease}.spui-Toast-slide--in.spui-Toast--top{transform:translateY(var(--Toast--order-offset-top))}.spui-Toast-slide--in.spui-Toast--bottom{transform:translateY(var(--Toast--order-offset-bottom))}.spui-Toast-iconButton{--IconButton--neutral-backgroundColor:transparent;margin-left:12px}.spui-Toast-contentInfo--information{color:var(--color-object-high-emphasis-inverse)}.spui-Toast-content--information{background-color:var(--gray-80);color:var(--color-text-high-emphasis-inverse)}.spui-Toast-iconButton--information{--IconButton--neutral-onActive-backgroundColor:var(--white-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--white-20-alpha);--IconButton--neutral-color:var(--color-object-high-emphasis-inverse)}.spui-Toast-contentInfo--confirmation{color:var(--color-object-accent-primary)}.spui-Toast-content--confirmation{background-color:var(--color-surface-primary);border:2px solid var(--color-border-low-emphasis);color:var(--color-text-accent-primary)}.spui-Toast-iconButton--confirmation{--IconButton--neutral-onActive-backgroundColor:var(--gray-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--gray-20-alpha);--IconButton--neutral-color:var(--color-object-low-emphasis)}.spui-Toast-contentInfo--error{color:var(--color-object-high-emphasis-inverse)}.spui-Toast-content--error{background-color:var(--color-surface-caution);color:var(--color-text-high-emphasis-inverse)}.spui-Toast-iconButton--error{--IconButton--neutral-onActive-backgroundColor:var(--white-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--white-20-alpha);--IconButton--neutral-color:var(--color-object-high-emphasis-inverse)}@media (prefers-reduced-motion:reduce){.spui-Toast--slide,.spui-Toast-slide--in{transition-duration:.1ms}}@media (max-width:384px){.spui-Toast-content{max-width:100%}}
1
+ :root{--IconButton-tapHighlightColor:var(--gray-5-alpha);--IconButton-onFocus-outlineColor:var(--color-focus-clarity);--IconButton--contained-backgroundColor:var(--color-surface-accent-primary);--IconButton--contained-color:var(--color-object-high-emphasis-inverse);--IconButton--contained-onActive-backgroundColor:var(--primary-green-100);--IconButton--contained-onHover-backgroundColor:var(--primary-green-100);--IconButton--outlined-borderColor:var(--color-border-accent-primary);--IconButton--outlined-color:var(--color-object-accent-primary);--IconButton--outlined-onActive-backgroundColor:var(--primary-green-5);--IconButton--outlined-onHover-backgroundColor:var(--primary-green-5);--IconButton--lighted-backgroundColor:var(--color-surface-accent-primary-light);--IconButton--lighted-color:var(--color-object-accent-primary);--IconButton--lighted-onActive-backgroundColor:var(--primary-green-10);--IconButton--lighted-onHover-backgroundColor:var(--primary-green-10);--IconButton--neutral-backgroundColor:var(--color-surface-tertiary);--IconButton--neutral-color:var(--color-object-medium-emphasis);--IconButton--neutral-onActive-backgroundColor:var(--gray-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--gray-20-alpha);--IconButton--danger-borderColor:var(--color-border-caution);--IconButton--danger-color:var(--color-object-caution);--IconButton--danger-onActive-backgroundColor:var(--caution-red-5-alpha);--IconButton--danger-onHover-backgroundColor:var(--caution-red-5-alpha)}.spui-IconButton{align-items:center;border-radius:100%;box-sizing:border-box;display:inline-flex;justify-content:center;margin:0;padding:0;-webkit-tap-highlight-color:var(--IconButton-tapHighlightColor);text-align:center;transition:background-color .3s}.spui-IconButton:disabled{opacity:.3}.spui-IconButton:focus{outline:2px solid var(--IconButton-onFocus-outlineColor);outline-offset:1px}.spui-IconButton:focus:not(:focus-visible){outline:none}.spui-IconButton--large{font-size:1.375em;height:48px;width:48px}.spui-IconButton--medium{font-size:1.25em;height:40px;width:40px}.spui-IconButton--small{font-size:1em;height:32px;width:32px}.spui-IconButton--exSmall{font-size:1em;height:24px;width:24px}.spui-IconButton--contained{background-color:var(--IconButton--contained-backgroundColor);border:none;color:var(--IconButton--contained-color)}.spui-IconButton--contained:active{background-color:var(--IconButton--contained-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--contained:not([disabled]):hover{background-color:var(--IconButton--contained-onHover-backgroundColor)}}.spui-IconButton--outlined{background-color:transparent;border:2px solid var(--IconButton--outlined-borderColor);color:var(--IconButton--outlined-color)}.spui-IconButton--outlined:active{background-color:var(--IconButton--outlined-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--outlined:not([disabled]):hover{background-color:var(--IconButton--outlined-onHover-backgroundColor)}}.spui-IconButton--lighted{background-color:var(--IconButton--lighted-backgroundColor);border:none;color:var(--IconButton--lighted-color);padding-bottom:8px;padding-top:8px}.spui-IconButton--lighted:active{background-color:var(--IconButton--lighted-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--lighted:not([disabled]):hover{background-color:var(--IconButton--lighted-onHover-backgroundColor)}}.spui-IconButton--neutral{background-color:var(--IconButton--neutral-backgroundColor);border:none;color:var(--IconButton--neutral-color)}.spui-IconButton--neutral:active{background-color:var(--IconButton--neutral-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--neutral:not([disabled]):hover{background-color:var(--IconButton--neutral-onHover-backgroundColor)}}.spui-IconButton--danger{background-color:transparent;border:2px solid var(--IconButton--danger-borderColor);color:var(--IconButton--danger-color)}.spui-IconButton--danger:active{background-color:var(--IconButton--danger-onActive-backgroundColor)}@media (hover:hover){.spui-IconButton--danger:hover{background-color:var(--IconButton--danger-onHover-backgroundColor)}}:root{--Toast-z-index:1}.spui-Toast{box-sizing:border-box;left:0;opacity:0;padding:0 12px;pointer-events:none;position:fixed;right:0;text-align:center;z-index:var(--Toast-z-index)}.spui-Toast-content{align-items:center;border-radius:52px;box-shadow:0 11px 28px rgba(8,18,26,.24);box-sizing:border-box;display:inline-flex;margin:0;max-width:360px;min-height:48px;padding:0 16px 0 20px;pointer-events:auto}.spui-Toast-contentInfo{flex-shrink:0;font-size:1.375rem;line-height:0;margin-right:8px}.spui-Toast-contentText{font-family:inherit;font-size:.875rem;font-weight:700;line-height:1.6;overflow:hidden;white-space:nowrap}.spui-Toast--top{top:0;transform:translateY(calc(var(--Toast--initial-height) - var(--Toast--offset-top)))}.spui-Toast--bottom{bottom:0;transform:translateY(calc(var(--Toast--initial-height)*-1 - var(--Toast--offset-bottom)*-1))}.spui-Toast--slide{transition:transform .3s ease,opacity .3s ease}.spui-Toast--hidden{visibility:hidden}.spui-Toast-slide--in{opacity:1;transition:transform .5s ease,opacity .5s ease}.spui-Toast-slide--in.spui-Toast--top{transform:translateY(var(--Toast--order-offset-top))}.spui-Toast-slide--in.spui-Toast--bottom{transform:translateY(var(--Toast--order-offset-bottom))}.spui-Toast-iconButton{--IconButton--neutral-backgroundColor:transparent;margin-left:12px}.spui-Toast-contentInfo--information{color:var(--color-object-high-emphasis-inverse)}.spui-Toast-content--information{background-color:var(--gray-80);color:var(--color-text-high-emphasis-inverse)}.spui-Toast-iconButton--information{--IconButton--neutral-onActive-backgroundColor:var(--white-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--white-20-alpha);--IconButton--neutral-color:var(--color-object-high-emphasis-inverse)}.spui-Toast-contentInfo--confirmation{color:var(--color-object-accent-primary)}.spui-Toast-content--confirmation{background-color:var(--color-surface-primary);border:2px solid var(--color-border-low-emphasis);color:var(--color-text-accent-primary)}.spui-Toast-iconButton--confirmation{--IconButton--neutral-onActive-backgroundColor:var(--gray-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--gray-20-alpha);--IconButton--neutral-color:var(--color-object-low-emphasis)}.spui-Toast-contentInfo--error{color:var(--color-object-high-emphasis-inverse)}.spui-Toast-content--error{background-color:var(--color-surface-caution);color:var(--color-text-high-emphasis-inverse)}.spui-Toast-iconButton--error{--IconButton--neutral-onActive-backgroundColor:var(--white-20-alpha);--IconButton--neutral-onHover-backgroundColor:var(--white-20-alpha);--IconButton--neutral-color:var(--color-object-high-emphasis-inverse)}@media (prefers-reduced-motion:reduce){.spui-Toast--slide,.spui-Toast-slide--in{transition-duration:.1ms}}@media (max-width:384px){.spui-Toast-content{max-width:100%}}
package/Toast/Toast.d.ts CHANGED
@@ -1,22 +1,24 @@
1
- import React from 'react';
2
- declare type Position = 'top' | 'bottom';
1
+ import React, { FC } from 'react';
2
+ import { ManagedStack, StackPositionOffset } from '../StackNotificationManager';
3
+ declare type Position = keyof Pick<ManagedStack, 'topCenter' | 'bottomCenter'>;
3
4
  declare type PositionOffset = {
4
- [K in Position]?: number;
5
+ [K in keyof StackPositionOffset<'top' | 'bottom'>]?: StackPositionOffset[K];
5
6
  };
6
7
  declare type Variant = 'information' | 'confirmation' | 'error';
7
8
  declare type Props = {
8
9
  children?: React.ReactNode;
9
10
  active?: boolean;
10
- order?: number;
11
11
  offset?: PositionOffset;
12
12
  duration?: number;
13
13
  onHide?: () => void;
14
14
  position?: Position;
15
15
  icon?: React.ReactNode;
16
16
  variant?: Variant;
17
+ setContentHeight?: (height: number) => void;
18
+ stackPosition?: number;
17
19
  };
18
20
  export declare const BLOCK_NAME = "spui-Toast";
19
21
  export declare const ANIMATION_DURATION = 300;
20
- export declare const Toast: ({ children, active, position, order, offset: _offset, onHide, icon, variant, }: Props) => React.ReactElement;
22
+ export declare const Toast: FC<Props>;
21
23
  export {};
22
24
  //# sourceMappingURL=Toast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../src/Toast/Toast.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAIxE,aAAK,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;AACjC,aAAK,cAAc,GAAG;KACnB,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,MAAM;CACzB,CAAC;AAEF,aAAK,OAAO,GAAG,aAAa,GAAG,cAAc,GAAG,OAAO,CAAC;AAExD,aAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,cAAc,CAAC;IAExB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,UAAU,eAAe,CAAC;AAGvC,eAAO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17 @@ var VERTICAL_GAP = 20;
35
35
  var TOTAL_ANIMATION_DURATION = MAX_DURATION - exports.ANIMATION_DURATION;
36
36
  var Toast = function (_a) {
37
37
  var _b;
38
- var children = _a.children, _c = _a.active, active = _c === void 0 ? false : _c, _d = _a.position, position = _d === void 0 ? 'top' : _d, _e = _a.order, order = _e === void 0 ? 0 : _e, _f = _a.offset, _offset = _f === void 0 ? {} : _f, onHide = _a.onHide, icon = _a.icon, _g = _a.variant, variant = _g === void 0 ? 'information' : _g;
39
- var _h = (0, react_1.useState)(false), isShow = _h[0], setIsShow = _h[1];
38
+ var _c, _d;
39
+ var children = _a.children, _active = _a.active, _e = _a.position, position = _e === void 0 ? 'topCenter' : _e, _f = _a.offset, _offset = _f === void 0 ? {} : _f, onHide = _a.onHide, icon = _a.icon, _g = _a.variant, variant = _g === void 0 ? 'information' : _g, _h = _a.stackPosition, stackPosition = _h === void 0 ? 0 : _h, setContentHeight = _a.setContentHeight;
40
+ var _j = (0, react_1.useState)(false), isShow = _j[0], setIsShow = _j[1];
40
41
  var offset = {
41
- top: _offset.top || 24,
42
- bottom: _offset.bottom || 24,
42
+ top: (_c = _offset.top) !== null && _c !== void 0 ? _c : 24,
43
+ bottom: (_d = _offset.bottom) !== null && _d !== void 0 ? _d : 24,
43
44
  };
44
45
  var timeoutID = (0, react_1.useRef)(null);
45
- var _j = (0, react_1.useState)(0), clientHeight = _j[0], setClientHeight = _j[1];
46
+ var _k = (0, react_1.useState)(0), clientHeight = _k[0], setClientHeight = _k[1];
47
+ var _l = (0, react_1.useState)(false), shouldAnimation = _l[0], setShouldAnimation = _l[1];
48
+ var _m = (0, react_1.useState)(false), active = _m[0], setActive = _m[1];
46
49
  var setIsShowWithTimeout = (0, react_1.useCallback)(function () {
47
50
  // Out animation is executed after `TOTAL_ANIMATION_DURATION` seconds.
48
51
  if (timeoutID.current === null && isShow) {
@@ -60,6 +63,7 @@ var Toast = function (_a) {
60
63
  var handleTransitionEnd = (0, react_1.useCallback)(function () {
61
64
  if (onHide && !isShow) {
62
65
  onHide();
66
+ setActive(false);
63
67
  timeoutID.current = null;
64
68
  }
65
69
  }, [isShow, setIsShow, onHide]);
@@ -72,23 +76,42 @@ var Toast = function (_a) {
72
76
  setIsShow(true);
73
77
  }
74
78
  }, [active]);
79
+ (0, react_1.useEffect)(function () {
80
+ if (isShow) {
81
+ setShouldAnimation(true);
82
+ }
83
+ if (!active) {
84
+ setShouldAnimation(false);
85
+ }
86
+ }, [active, isShow]);
75
87
  (0, react_1.useEffect)(function () {
76
88
  setIsShowWithTimeout();
77
89
  return resetTimeout;
78
90
  }, [setIsShowWithTimeout, resetTimeout]);
79
- var contentHeight = clientHeight;
80
- var offsetPosition = offset[position] || 0;
81
- var orderOffset = order * (contentHeight + VERTICAL_GAP) + offsetPosition;
91
+ (0, react_1.useEffect)(function () {
92
+ if (_active) {
93
+ setActive(true);
94
+ }
95
+ if (!_active && isShow) {
96
+ setIsShow(false);
97
+ }
98
+ }, [_active, isShow]);
99
+ (0, react_1.useEffect)(function () {
100
+ setContentHeight === null || setContentHeight === void 0 ? void 0 : setContentHeight(clientHeight + VERTICAL_GAP);
101
+ }, [clientHeight]);
102
+ var positionPrefix = position.startsWith('top') ? 'top' : 'bottom';
103
+ var offsetPosition = offset[positionPrefix] || 0;
104
+ var orderOffset = stackPosition + offsetPosition;
82
105
  return (react_1.default.createElement("div", { style: (_b = {},
83
- _b['--Toast--initial-height'] = "".concat(orderOffset - contentHeight + offsetPosition, "px"),
106
+ _b['--Toast--initial-height'] = "".concat(orderOffset - clientHeight + offsetPosition, "px"),
84
107
  _b['--Toast--order-offset-top'] = "".concat(orderOffset, "px"),
85
108
  _b['--Toast--order-offset-bottom'] = "".concat(-orderOffset, "px"),
86
109
  _b['--Toast--offset-top'] = "".concat(offset.top, "px"),
87
110
  _b['--Toast--offset-bottom'] = "".concat(offset.bottom, "px"),
88
111
  _b), className: [
89
112
  exports.BLOCK_NAME,
90
- "".concat(exports.BLOCK_NAME, "--").concat(position),
91
- "".concat(exports.BLOCK_NAME, "--slide"),
113
+ "".concat(exports.BLOCK_NAME, "--").concat(positionPrefix),
114
+ shouldAnimation && "".concat(exports.BLOCK_NAME, "--slide"),
92
115
  isShow && "".concat(exports.BLOCK_NAME, "-slide--in"),
93
116
  !active && "".concat(exports.BLOCK_NAME, "--hidden"),
94
117
  ]
@@ -1 +1 @@
1
- {"version":3,"file":"Toast.js","sourceRoot":"","sources":["../../src/Toast/Toast.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwE;AACxE,gCAAoC;AACpC,4CAA2C;AAsB9B,QAAA,UAAU,GAAG,YAAY,CAAC;AAEvC,8BAA8B;AACjB,QAAA,kBAAkB,GAAG,GAAG,CAAC;AAEtC,IAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,IAAM,YAAY,GAAG,EAAE,CAAC;AACxB,IAAM,wBAAwB,GAAG,YAAY,GAAG,0BAAkB,CAAC;AAE5D,IAAM,KAAK,GAAG,UAAC,EASd;;QARN,QAAQ,cAAA,EACR,cAAc,EAAd,MAAM,mBAAG,KAAK,KAAA,EACd,gBAAgB,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAChB,aAAS,EAAT,KAAK,mBAAG,CAAC,KAAA,EACT,cAAoB,EAAZ,OAAO,mBAAG,EAAE,KAAA,EACpB,MAAM,YAAA,EACN,IAAI,UAAA,EACJ,eAAuB,EAAvB,OAAO,mBAAG,aAAa,KAAA;IAEjB,IAAA,KAAsB,IAAA,gBAAQ,EAAU,KAAK,CAAC,EAA7C,MAAM,QAAA,EAAE,SAAS,QAA4B,CAAC;IACrD,IAAM,MAAM,GAAmB;QAC7B,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;KAC7B,CAAC;IACF,IAAM,SAAS,GAAG,IAAA,cAAM,EAAgB,IAAI,CAAC,CAAC;IACxC,IAAA,KAAkC,IAA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C/D,uCACE,SAAS,EAAE,UAAG,kBAAU,yBAAe,kBAAU,0BAAgB,OAAO,CAAE,EAC1E,eAAe,EAAE,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,eAAe,EAAE,EAAnB,CAAmB;gBAE3C,8BAAC,uBAAU,IACT,IAAI,EAAC,SAAS,EACd,OAAO,EAAC,SAAS,EACjB,OAAO,EAAE,wBAAwB;oBAEjC,8BAAC,gBAAS,kBAAY,oBAAK,GAAG,CACnB,CACT,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AAvIW,QAAA,KAAK,SAuIhB"}
package/Toast/Toast.mjs CHANGED
@@ -7,14 +7,16 @@ export const ANIMATION_DURATION = 300;
7
7
  const MAX_DURATION = 4000;
8
8
  const VERTICAL_GAP = 20;
9
9
  const TOTAL_ANIMATION_DURATION = MAX_DURATION - ANIMATION_DURATION;
10
- export const Toast = ({ children, active = false, position = 'top', order = 0, offset: _offset = {}, onHide, icon, variant = 'information', }) => {
10
+ export const Toast = ({ children, active: _active, position = 'topCenter', offset: _offset = {}, onHide, icon, variant = 'information', stackPosition = 0, setContentHeight, }) => {
11
11
  const [isShow, setIsShow] = useState(false);
12
12
  const offset = {
13
- top: _offset.top || 24,
14
- bottom: _offset.bottom || 24,
13
+ top: _offset.top ?? 24,
14
+ bottom: _offset.bottom ?? 24,
15
15
  };
16
16
  const timeoutID = useRef(null);
17
17
  const [clientHeight, setClientHeight] = useState(0);
18
+ const [shouldAnimation, setShouldAnimation] = useState(false);
19
+ const [active, setActive] = useState(false);
18
20
  const setIsShowWithTimeout = useCallback(() => {
19
21
  // Out animation is executed after `TOTAL_ANIMATION_DURATION` seconds.
20
22
  if (timeoutID.current === null && isShow) {
@@ -32,6 +34,7 @@ export const Toast = ({ children, active = false, position = 'top', order = 0, o
32
34
  const handleTransitionEnd = useCallback(() => {
33
35
  if (onHide && !isShow) {
34
36
  onHide();
37
+ setActive(false);
35
38
  timeoutID.current = null;
36
39
  }
37
40
  }, [isShow, setIsShow, onHide]);
@@ -44,23 +47,42 @@ export const Toast = ({ children, active = false, position = 'top', order = 0, o
44
47
  setIsShow(true);
45
48
  }
46
49
  }, [active]);
50
+ useEffect(() => {
51
+ if (isShow) {
52
+ setShouldAnimation(true);
53
+ }
54
+ if (!active) {
55
+ setShouldAnimation(false);
56
+ }
57
+ }, [active, isShow]);
47
58
  useEffect(() => {
48
59
  setIsShowWithTimeout();
49
60
  return resetTimeout;
50
61
  }, [setIsShowWithTimeout, resetTimeout]);
51
- const contentHeight = clientHeight;
52
- const offsetPosition = offset[position] || 0;
53
- const orderOffset = order * (contentHeight + VERTICAL_GAP) + offsetPosition;
62
+ useEffect(() => {
63
+ if (_active) {
64
+ setActive(true);
65
+ }
66
+ if (!_active && isShow) {
67
+ setIsShow(false);
68
+ }
69
+ }, [_active, isShow]);
70
+ useEffect(() => {
71
+ setContentHeight?.(clientHeight + VERTICAL_GAP);
72
+ }, [clientHeight]);
73
+ const positionPrefix = position.startsWith('top') ? 'top' : 'bottom';
74
+ const offsetPosition = offset[positionPrefix] || 0;
75
+ const orderOffset = stackPosition + offsetPosition;
54
76
  return (React.createElement("div", { style: {
55
- ['--Toast--initial-height']: `${orderOffset - contentHeight + offsetPosition}px`,
77
+ ['--Toast--initial-height']: `${orderOffset - clientHeight + offsetPosition}px`,
56
78
  ['--Toast--order-offset-top']: `${orderOffset}px`,
57
79
  ['--Toast--order-offset-bottom']: `${-orderOffset}px`,
58
80
  ['--Toast--offset-top']: `${offset.top}px`,
59
81
  ['--Toast--offset-bottom']: `${offset.bottom}px`,
60
82
  }, className: [
61
83
  BLOCK_NAME,
62
- `${BLOCK_NAME}--${position}`,
63
- `${BLOCK_NAME}--slide`,
84
+ `${BLOCK_NAME}--${positionPrefix}`,
85
+ shouldAnimation && `${BLOCK_NAME}--slide`,
64
86
  isShow && `${BLOCK_NAME}-slide--in`,
65
87
  !active && `${BLOCK_NAME}--hidden`,
66
88
  ]