react-snackbar-glass 1.0.0 → 1.2.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 +33 -0
- package/README.md +63 -3
- package/dist/index.cjs +136 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +112 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +90 -3
- package/dist/index.d.ts +90 -3
- package/dist/index.js +134 -19
- package/dist/index.js.map +1 -1
- package/dist/styles.css +112 -0
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var DEFAULT_CONFIG = {
|
|
|
9
9
|
duration: 5e3,
|
|
10
10
|
dismissible: true,
|
|
11
11
|
progress: true,
|
|
12
|
+
compact: false,
|
|
12
13
|
tone: "glass",
|
|
13
14
|
size: "md",
|
|
14
15
|
maxVisible: 3
|
|
@@ -48,6 +49,7 @@ function createSnackbarStore(initialConfig = {}) {
|
|
|
48
49
|
} : null,
|
|
49
50
|
...initialConfig.dismissible !== void 0 ? { dismissible: initialConfig.dismissible } : null,
|
|
50
51
|
...initialConfig.progress !== void 0 ? { progress: initialConfig.progress } : null,
|
|
52
|
+
...initialConfig.compact !== void 0 ? { compact: initialConfig.compact } : null,
|
|
51
53
|
...initialConfig.tone !== void 0 ? { tone: initialConfig.tone } : null,
|
|
52
54
|
...initialConfig.size !== void 0 ? { size: initialConfig.size } : null,
|
|
53
55
|
...initialConfig.maxVisible !== void 0 ? { maxVisible: Math.max(1, Math.floor(initialConfig.maxVisible)) } : null
|
|
@@ -58,6 +60,7 @@ function createSnackbarStore(initialConfig = {}) {
|
|
|
58
60
|
const shown = /* @__PURE__ */ new Set();
|
|
59
61
|
const pauseReasons = /* @__PURE__ */ new Map();
|
|
60
62
|
let pageHidden = false;
|
|
63
|
+
let minimized = false;
|
|
61
64
|
const emit = () => {
|
|
62
65
|
for (const listener of listeners) listener();
|
|
63
66
|
};
|
|
@@ -231,6 +234,7 @@ function createSnackbarStore(initialConfig = {}) {
|
|
|
231
234
|
action: options.action ?? null,
|
|
232
235
|
dismissible: options.dismissible ?? config.dismissible,
|
|
233
236
|
progress: options.progress ?? config.progress,
|
|
237
|
+
compact: options.compact ?? config.compact,
|
|
234
238
|
className: options.className,
|
|
235
239
|
style: options.style,
|
|
236
240
|
createdAt: Date.now(),
|
|
@@ -259,6 +263,7 @@ function createSnackbarStore(initialConfig = {}) {
|
|
|
259
263
|
...options.action !== void 0 ? { action: options.action } : null,
|
|
260
264
|
...options.dismissible !== void 0 ? { dismissible: options.dismissible } : null,
|
|
261
265
|
...options.progress !== void 0 ? { progress: options.progress } : null,
|
|
266
|
+
...options.compact !== void 0 ? { compact: options.compact } : null,
|
|
262
267
|
...options.className !== void 0 ? { className: options.className } : null,
|
|
263
268
|
...options.style !== void 0 ? { style: options.style } : null,
|
|
264
269
|
...options.onOpen !== void 0 ? { onOpen: options.onOpen } : null,
|
|
@@ -316,6 +321,7 @@ function createSnackbarStore(initialConfig = {}) {
|
|
|
316
321
|
} : null,
|
|
317
322
|
...patch.dismissible !== void 0 ? { dismissible: patch.dismissible } : null,
|
|
318
323
|
...patch.progress !== void 0 ? { progress: patch.progress } : null,
|
|
324
|
+
...patch.compact !== void 0 ? { compact: patch.compact } : null,
|
|
319
325
|
...patch.tone !== void 0 ? { tone: patch.tone } : null,
|
|
320
326
|
...patch.size !== void 0 ? { size: patch.size } : null,
|
|
321
327
|
...patch.maxVisible !== void 0 ? { maxVisible: Math.max(1, Math.floor(patch.maxVisible)) } : null
|
|
@@ -370,9 +376,26 @@ function createSnackbarStore(initialConfig = {}) {
|
|
|
370
376
|
resume,
|
|
371
377
|
notifyShown,
|
|
372
378
|
notifyExited,
|
|
373
|
-
setPageHidden
|
|
379
|
+
setPageHidden,
|
|
380
|
+
getMinimized: () => minimized,
|
|
381
|
+
getServerMinimized: () => false,
|
|
382
|
+
setMinimized(next) {
|
|
383
|
+
if (minimized === next) return;
|
|
384
|
+
minimized = next;
|
|
385
|
+
emit();
|
|
386
|
+
}
|
|
374
387
|
};
|
|
375
388
|
}
|
|
389
|
+
|
|
390
|
+
// src/core/defaultStore.ts
|
|
391
|
+
var defaultStore = null;
|
|
392
|
+
function getDefaultStore() {
|
|
393
|
+
if (!defaultStore) defaultStore = createSnackbarStore();
|
|
394
|
+
return defaultStore;
|
|
395
|
+
}
|
|
396
|
+
function setDefaultStore(store) {
|
|
397
|
+
defaultStore = store;
|
|
398
|
+
}
|
|
376
399
|
var strokeProps = {
|
|
377
400
|
fill: "none",
|
|
378
401
|
stroke: "currentColor",
|
|
@@ -605,7 +628,7 @@ function SnackbarItem({
|
|
|
605
628
|
};
|
|
606
629
|
const resolvedIcon = record.icon === void 0 ? icons?.[variant] ?? defaultIcons[variant] : record.icon;
|
|
607
630
|
const showIcon = record.icon !== false;
|
|
608
|
-
const showProgress = record.progress && Number.isFinite(duration) && duration > 0;
|
|
631
|
+
const showProgress = !record.compact && record.progress && Number.isFinite(duration) && duration > 0;
|
|
609
632
|
const style = {
|
|
610
633
|
...record.style,
|
|
611
634
|
"--prs-drag-x": `${dragX}px`,
|
|
@@ -625,6 +648,7 @@ function SnackbarItem({
|
|
|
625
648
|
"data-dragging": dragging ? "true" : "false",
|
|
626
649
|
"data-has-icon": showIcon ? "true" : "false",
|
|
627
650
|
"data-dismissible": record.dismissible ? "true" : "false",
|
|
651
|
+
"data-compact": record.compact ? "true" : "false",
|
|
628
652
|
"data-prs-id": record.id,
|
|
629
653
|
"data-position": record.position,
|
|
630
654
|
style,
|
|
@@ -724,6 +748,9 @@ var POSITIONS = [
|
|
|
724
748
|
"bottom-center",
|
|
725
749
|
"bottom-right"
|
|
726
750
|
];
|
|
751
|
+
function defaultMinimizedLabel(count) {
|
|
752
|
+
return `${count} notification${count === 1 ? "" : "s"}`;
|
|
753
|
+
}
|
|
727
754
|
function SnackbarHost({
|
|
728
755
|
store,
|
|
729
756
|
maxVisible = 3,
|
|
@@ -741,6 +768,7 @@ function SnackbarHost({
|
|
|
741
768
|
closeIcon,
|
|
742
769
|
closeLabel = "Dismiss notification",
|
|
743
770
|
regionLabel = "Notifications",
|
|
771
|
+
minimizedLabel = defaultMinimizedLabel,
|
|
744
772
|
className,
|
|
745
773
|
style,
|
|
746
774
|
zIndex = 2147483e3,
|
|
@@ -751,6 +779,11 @@ function SnackbarHost({
|
|
|
751
779
|
store.getSnapshot,
|
|
752
780
|
store.getServerSnapshot
|
|
753
781
|
);
|
|
782
|
+
const minimized = useSyncExternalStore(
|
|
783
|
+
store.subscribe,
|
|
784
|
+
store.getMinimized,
|
|
785
|
+
store.getServerMinimized
|
|
786
|
+
);
|
|
754
787
|
const [portalNode, setPortalNode] = useState(null);
|
|
755
788
|
const regionRefs = useRef(/* @__PURE__ */ new Map());
|
|
756
789
|
const topsRef = useRef(/* @__PURE__ */ new Map());
|
|
@@ -814,6 +847,7 @@ function SnackbarHost({
|
|
|
814
847
|
else byPosition.set(record.position, [record]);
|
|
815
848
|
}
|
|
816
849
|
const limit = Math.max(1, Math.floor(maxVisible));
|
|
850
|
+
const minimizedPosition = records[0]?.position ?? null;
|
|
817
851
|
const rootStyle = {
|
|
818
852
|
"--prs-width": `${width}px`,
|
|
819
853
|
"--prs-offset": `${offset}px`,
|
|
@@ -832,6 +866,32 @@ function SnackbarHost({
|
|
|
832
866
|
children: POSITIONS.map((position) => {
|
|
833
867
|
const items = byPosition.get(position);
|
|
834
868
|
if (!items || items.length === 0) return null;
|
|
869
|
+
if (minimized) {
|
|
870
|
+
if (position !== minimizedPosition) return null;
|
|
871
|
+
return /* @__PURE__ */ jsx(
|
|
872
|
+
"section",
|
|
873
|
+
{
|
|
874
|
+
className: "prs-region prs-region--minimized",
|
|
875
|
+
"data-position": position,
|
|
876
|
+
"aria-label": regionLabel,
|
|
877
|
+
children: /* @__PURE__ */ jsxs(
|
|
878
|
+
"button",
|
|
879
|
+
{
|
|
880
|
+
type: "button",
|
|
881
|
+
className: "prs-minimized",
|
|
882
|
+
"data-count": items.length,
|
|
883
|
+
onClick: () => store.setMinimized(false),
|
|
884
|
+
title: "Expand notifications",
|
|
885
|
+
children: [
|
|
886
|
+
/* @__PURE__ */ jsx("span", { className: "prs-minimized__dot", "aria-hidden": "true" }),
|
|
887
|
+
/* @__PURE__ */ jsx("span", { className: "prs-minimized__count", children: minimizedLabel(items.length) })
|
|
888
|
+
]
|
|
889
|
+
}
|
|
890
|
+
)
|
|
891
|
+
},
|
|
892
|
+
position
|
|
893
|
+
);
|
|
894
|
+
}
|
|
835
895
|
const visible = items.slice(0, limit);
|
|
836
896
|
return /* @__PURE__ */ jsx(
|
|
837
897
|
"section",
|
|
@@ -875,20 +935,18 @@ function SnackbarProvider({
|
|
|
875
935
|
duration,
|
|
876
936
|
dismissible,
|
|
877
937
|
progress,
|
|
938
|
+
compact,
|
|
878
939
|
tone,
|
|
879
940
|
size,
|
|
880
941
|
maxVisible,
|
|
881
942
|
...hostProps
|
|
882
943
|
}) {
|
|
883
944
|
const store = useMemo(
|
|
884
|
-
() =>
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
tone,
|
|
890
|
-
size
|
|
891
|
-
}),
|
|
945
|
+
() => (
|
|
946
|
+
// Falling back to the shared default store is what makes the
|
|
947
|
+
// module-level `toast` API render without extra wiring.
|
|
948
|
+
providedStore ?? getDefaultStore()
|
|
949
|
+
),
|
|
892
950
|
// The store is intentionally created once per provider instance.
|
|
893
951
|
// Subsequent config changes are pushed below.
|
|
894
952
|
[providedStore]
|
|
@@ -899,31 +957,45 @@ function SnackbarProvider({
|
|
|
899
957
|
duration,
|
|
900
958
|
dismissible,
|
|
901
959
|
progress,
|
|
960
|
+
compact,
|
|
902
961
|
tone,
|
|
903
962
|
size,
|
|
904
963
|
maxVisible
|
|
905
964
|
});
|
|
906
|
-
}, [
|
|
965
|
+
}, [
|
|
966
|
+
store,
|
|
967
|
+
position,
|
|
968
|
+
duration,
|
|
969
|
+
dismissible,
|
|
970
|
+
progress,
|
|
971
|
+
compact,
|
|
972
|
+
tone,
|
|
973
|
+
size,
|
|
974
|
+
maxVisible
|
|
975
|
+
]);
|
|
907
976
|
const api = useMemo(() => {
|
|
908
|
-
const
|
|
977
|
+
const preset2 = (variant) => (message, options = {}) => store.show({ ...options, message, variant });
|
|
909
978
|
return {
|
|
910
979
|
show: store.show,
|
|
911
980
|
update: store.update,
|
|
912
981
|
dismiss: store.dismiss,
|
|
913
982
|
dismissAll: store.dismissAll,
|
|
914
983
|
promise: store.promise,
|
|
915
|
-
success:
|
|
916
|
-
error:
|
|
917
|
-
warning:
|
|
918
|
-
info:
|
|
919
|
-
neutral:
|
|
920
|
-
custom:
|
|
984
|
+
success: preset2("success"),
|
|
985
|
+
error: preset2("error"),
|
|
986
|
+
warning: preset2("warning"),
|
|
987
|
+
info: preset2("info"),
|
|
988
|
+
neutral: preset2("neutral"),
|
|
989
|
+
custom: preset2("custom"),
|
|
921
990
|
loading: (message, options = {}) => store.show({
|
|
922
991
|
...options,
|
|
923
992
|
message,
|
|
924
993
|
variant: "loading",
|
|
925
994
|
duration: options.duration !== void 0 ? options.duration : null
|
|
926
995
|
}),
|
|
996
|
+
minimize: () => store.setMinimized(true),
|
|
997
|
+
expand: () => store.setMinimized(false),
|
|
998
|
+
isMinimized: () => store.getMinimized(),
|
|
927
999
|
store
|
|
928
1000
|
};
|
|
929
1001
|
}, [store]);
|
|
@@ -955,7 +1027,50 @@ function useSnackbar() {
|
|
|
955
1027
|
function useSnackbarStore() {
|
|
956
1028
|
return useSnackbarContext().store;
|
|
957
1029
|
}
|
|
1030
|
+
function isOptionsObject(value) {
|
|
1031
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !isValidElement(value) && !("$$typeof" in value);
|
|
1032
|
+
}
|
|
1033
|
+
function preset(variant) {
|
|
1034
|
+
return (message, options = {}) => getDefaultStore().show({ ...options, message, variant });
|
|
1035
|
+
}
|
|
1036
|
+
function createToast() {
|
|
1037
|
+
const toast2 = ((content, options) => {
|
|
1038
|
+
if (options === void 0 && isOptionsObject(content)) {
|
|
1039
|
+
return getDefaultStore().show(content);
|
|
1040
|
+
}
|
|
1041
|
+
return getDefaultStore().show({
|
|
1042
|
+
...options,
|
|
1043
|
+
message: content
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
1046
|
+
toast2.show = (options) => getDefaultStore().show(options);
|
|
1047
|
+
toast2.update = (id, options) => getDefaultStore().update(id, options);
|
|
1048
|
+
toast2.dismiss = (id, reason) => getDefaultStore().dismiss(id, reason);
|
|
1049
|
+
toast2.dismissAll = (reason) => getDefaultStore().dismissAll(reason);
|
|
1050
|
+
toast2.success = preset("success");
|
|
1051
|
+
toast2.error = preset("error");
|
|
1052
|
+
toast2.warning = preset("warning");
|
|
1053
|
+
toast2.info = preset("info");
|
|
1054
|
+
toast2.neutral = preset("neutral");
|
|
1055
|
+
toast2.custom = preset("custom");
|
|
1056
|
+
toast2.loading = (message, options = {}) => getDefaultStore().show({
|
|
1057
|
+
...options,
|
|
1058
|
+
message,
|
|
1059
|
+
variant: "loading",
|
|
1060
|
+
duration: options.duration !== void 0 ? options.duration : null
|
|
1061
|
+
});
|
|
1062
|
+
toast2.promise = (input, messages, options) => getDefaultStore().promise(input, messages, options);
|
|
1063
|
+
toast2.minimize = () => getDefaultStore().setMinimized(true);
|
|
1064
|
+
toast2.expand = () => getDefaultStore().setMinimized(false);
|
|
1065
|
+
toast2.isMinimized = () => getDefaultStore().getMinimized();
|
|
1066
|
+
Object.defineProperty(toast2, "store", {
|
|
1067
|
+
get: getDefaultStore,
|
|
1068
|
+
enumerable: true
|
|
1069
|
+
});
|
|
1070
|
+
return toast2;
|
|
1071
|
+
}
|
|
1072
|
+
var toast = createToast();
|
|
958
1073
|
|
|
959
|
-
export { SnackbarHost, SnackbarProvider, createSnackbarStore, useSnackbar, useSnackbarStore };
|
|
1074
|
+
export { SnackbarHost, SnackbarProvider, createSnackbarStore, getDefaultStore, setDefaultStore, toast, useSnackbar, useSnackbarStore };
|
|
960
1075
|
//# sourceMappingURL=index.js.map
|
|
961
1076
|
//# sourceMappingURL=index.js.map
|