@apliteni/apliteni-ui 0.139.0 → 0.141.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/package.json +1 -1
- package/react/README.md +3 -0
- package/react/dist/index.css +68 -1
- package/react/dist/index.d.ts +2 -1
- package/react/dist/index.js +146 -3
package/package.json
CHANGED
package/react/README.md
CHANGED
|
@@ -634,6 +634,9 @@ notice with an action and no close button has no other dismissal affordance.
|
|
|
634
634
|
Pass `timer: 12` to dismiss a notice after that many seconds. Pass `timer: false` or `timer: 0`
|
|
635
635
|
to keep a notice until it is dismissed.
|
|
636
636
|
|
|
637
|
+
Pass `collapse` to `Toast` to rest the notices as a pile with the newest in front. The pile fans out
|
|
638
|
+
when the reader hovers it or tabs into it. On a device without hover it stays a plain column.
|
|
639
|
+
|
|
637
640
|
```tsx
|
|
638
641
|
function SaveButton() {
|
|
639
642
|
const push = useToast();
|
package/react/dist/index.css
CHANGED
|
@@ -886,7 +886,7 @@
|
|
|
886
886
|
}
|
|
887
887
|
|
|
888
888
|
/* src/Toast.css */
|
|
889
|
-
.rx-toast-stack {
|
|
889
|
+
.ui-toast-stack.rx-toast-stack {
|
|
890
890
|
position: fixed;
|
|
891
891
|
right: var(--space-4);
|
|
892
892
|
bottom: var(--space-4);
|
|
@@ -894,9 +894,76 @@
|
|
|
894
894
|
z-index: var(--z-toast);
|
|
895
895
|
pointer-events: none;
|
|
896
896
|
}
|
|
897
|
+
.ui-toast-stack.rx-toast-stack.ui-toast-stack--collapsed {
|
|
898
|
+
pointer-events: auto;
|
|
899
|
+
}
|
|
897
900
|
.rx-toast-stack > .ui-toast {
|
|
898
901
|
pointer-events: auto;
|
|
899
902
|
}
|
|
903
|
+
.ui-toast-stack--collapsed {
|
|
904
|
+
position: relative;
|
|
905
|
+
display: block;
|
|
906
|
+
height: var(--toast-pile-height, auto);
|
|
907
|
+
transition: height var(--dur-med) var(--ease);
|
|
908
|
+
}
|
|
909
|
+
.ui-toast-stack--collapsed:focus-visible {
|
|
910
|
+
outline: var(--ring);
|
|
911
|
+
outline-offset: var(--ring-offset);
|
|
912
|
+
}
|
|
913
|
+
.ui-toast-stack--collapsed > .ui-toast {
|
|
914
|
+
position: absolute;
|
|
915
|
+
right: 0;
|
|
916
|
+
bottom: 0;
|
|
917
|
+
z-index: var(--toast-card-depth, auto);
|
|
918
|
+
transform-origin: bottom center;
|
|
919
|
+
translate: 0 var(--toast-card-lift, 0px);
|
|
920
|
+
scale: var(--toast-card-scale, 1);
|
|
921
|
+
max-height: var(--toast-card-box, none);
|
|
922
|
+
clip-path: inset(-100vmax var(--toast-card-clip, -100vmax) var(--toast-card-clip, -100vmax));
|
|
923
|
+
transition: translate var(--dur-med) var(--ease), scale var(--dur-med) var(--ease);
|
|
924
|
+
}
|
|
925
|
+
.ui-toast-stack--collapsed > .ui-toast > .ui-toast__icon,
|
|
926
|
+
.ui-toast-stack--collapsed > .ui-toast > .ui-toast__body,
|
|
927
|
+
.ui-toast-stack--collapsed > .ui-toast > .ui-toast__action {
|
|
928
|
+
margin-block: auto;
|
|
929
|
+
}
|
|
930
|
+
.ui-toast-stack--collapsed:hover > .ui-toast > *,
|
|
931
|
+
.ui-toast-stack--collapsed:focus-within > .ui-toast > * {
|
|
932
|
+
margin-block: 0;
|
|
933
|
+
}
|
|
934
|
+
.ui-toast-stack--collapsed:hover,
|
|
935
|
+
.ui-toast-stack--collapsed:focus-within {
|
|
936
|
+
height: var(--toast-fan-height, auto);
|
|
937
|
+
}
|
|
938
|
+
.ui-toast-stack--collapsed:hover > .ui-toast,
|
|
939
|
+
.ui-toast-stack--collapsed:focus-within > .ui-toast {
|
|
940
|
+
translate: 0 var(--toast-card-fan, 0px);
|
|
941
|
+
scale: 1;
|
|
942
|
+
max-height: var(--toast-card-natural, none);
|
|
943
|
+
clip-path: inset(-100vmax -100vmax var(--toast-card-fan-clip, -100vmax));
|
|
944
|
+
transition: translate var(--dur-med) var(--ease), scale var(--dur-med) var(--ease);
|
|
945
|
+
}
|
|
946
|
+
@media (hover: none) {
|
|
947
|
+
.ui-toast-stack--collapsed,
|
|
948
|
+
.ui-toast-stack--collapsed:hover,
|
|
949
|
+
.ui-toast-stack--collapsed:focus-within {
|
|
950
|
+
display: flex;
|
|
951
|
+
height: auto;
|
|
952
|
+
}
|
|
953
|
+
.ui-toast-stack--collapsed > .ui-toast,
|
|
954
|
+
.ui-toast-stack--collapsed:hover > .ui-toast,
|
|
955
|
+
.ui-toast-stack--collapsed:focus-within > .ui-toast {
|
|
956
|
+
position: static;
|
|
957
|
+
translate: none;
|
|
958
|
+
scale: 1;
|
|
959
|
+
max-height: none;
|
|
960
|
+
clip-path: none;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
.ui-toast-stack--collapsed:hover > .ui-toast > .ui-toast__timer.is-running,
|
|
964
|
+
.ui-toast-stack--collapsed:focus-within > .ui-toast > .ui-toast__timer.is-running {
|
|
965
|
+
animation-play-state: paused;
|
|
966
|
+
}
|
|
900
967
|
|
|
901
968
|
/* src/ThemeToggle.css */
|
|
902
969
|
.ui-theme-toggle {
|
package/react/dist/index.d.ts
CHANGED
|
@@ -883,9 +883,10 @@ type ToastNotice = {
|
|
|
883
883
|
};
|
|
884
884
|
type ToastProps = {
|
|
885
885
|
children: ReactNode;
|
|
886
|
+
collapse?: boolean;
|
|
886
887
|
};
|
|
887
888
|
declare function useToast(): (notice: ToastNotice) => void;
|
|
888
|
-
declare function Toast({ children }: ToastProps): react.JSX.Element;
|
|
889
|
+
declare function Toast({ children, collapse }: ToastProps): react.JSX.Element;
|
|
889
890
|
|
|
890
891
|
type AppShellSection = {
|
|
891
892
|
href: string;
|
package/react/dist/index.js
CHANGED
|
@@ -3821,8 +3821,117 @@ var SearchField = forwardRef7(function SearchField2({ ariaLabel, className, ...p
|
|
|
3821
3821
|
// src/Toast.tsx
|
|
3822
3822
|
import { createContext as createContext3, useCallback as useCallback6, useContext as useContext3, useEffect as useEffect13, useLayoutEffect as useLayoutEffect4, useRef as useRef19, useState as useState14 } from "react";
|
|
3823
3823
|
import { createPortal as createPortal5 } from "react-dom";
|
|
3824
|
+
|
|
3825
|
+
// src/lib/toast-stack.ts
|
|
3826
|
+
var TOAST_PEEK = 8;
|
|
3827
|
+
var TOAST_SCALE_STEP = 0.04;
|
|
3828
|
+
var TOAST_TIERS = 2;
|
|
3829
|
+
var TOAST_PILE_MIN = 2;
|
|
3830
|
+
var TOAST_GAP = 12;
|
|
3831
|
+
function toastPileGeometry(heights, gap = TOAST_GAP) {
|
|
3832
|
+
const count = heights.length;
|
|
3833
|
+
if (!count) return { cards: [], collapsedHeight: 0, fannedHeight: 0 };
|
|
3834
|
+
const front = heights[count - 1];
|
|
3835
|
+
const cards = heights.map((height, index) => {
|
|
3836
|
+
const depth = count - 1 - index;
|
|
3837
|
+
const tier = Math.min(depth, TOAST_TIERS);
|
|
3838
|
+
const scale = 1 - tier * TOAST_SCALE_STEP;
|
|
3839
|
+
const reach = (front + tier * TOAST_PEEK) / scale;
|
|
3840
|
+
const box = depth > 0 ? Math.min(height, reach) : height;
|
|
3841
|
+
const lift = box * scale - front - tier * TOAST_PEEK;
|
|
3842
|
+
let fan = 0;
|
|
3843
|
+
for (let after = index + 1; after < count; after += 1) fan -= heights[after] + gap;
|
|
3844
|
+
return { depth, tier, scale, lift, fan, box, natural: height };
|
|
3845
|
+
});
|
|
3846
|
+
return {
|
|
3847
|
+
cards,
|
|
3848
|
+
collapsedHeight: front + Math.min(count - 1, TOAST_TIERS) * TOAST_PEEK,
|
|
3849
|
+
fannedHeight: heights.reduce((sum, height) => sum + height, 0) + (count - 1) * gap
|
|
3850
|
+
};
|
|
3851
|
+
}
|
|
3852
|
+
var pileCards = (stack2) => [...stack2.children].filter((el) => el.classList.contains("ui-toast"));
|
|
3853
|
+
var naturalHeight = (card) => {
|
|
3854
|
+
const style = card.ownerDocument.defaultView.getComputedStyle(card);
|
|
3855
|
+
const frame = (parseFloat(style.paddingBottom) || 0) + (parseFloat(style.borderTopWidth) || 0) + (parseFloat(style.borderBottomWidth) || 0);
|
|
3856
|
+
const content = [...card.children].filter((el) => !el.classList.contains("ui-toast__timer")).reduce((end, el) => Math.max(end, el.offsetTop + el.offsetHeight), 0);
|
|
3857
|
+
return Math.max(card.offsetHeight, content + frame);
|
|
3858
|
+
};
|
|
3859
|
+
function applyToastPile(stack2) {
|
|
3860
|
+
if (!stack2) return null;
|
|
3861
|
+
const cards = pileCards(stack2);
|
|
3862
|
+
const geometry = toastPileGeometry(cards.map(naturalHeight));
|
|
3863
|
+
stack2.style.setProperty("--toast-pile-height", `${geometry.collapsedHeight}px`);
|
|
3864
|
+
stack2.style.setProperty("--toast-fan-height", `${geometry.fannedHeight}px`);
|
|
3865
|
+
cards.forEach((card, index) => {
|
|
3866
|
+
const { lift, scale, fan, depth, box, natural } = geometry.cards[index];
|
|
3867
|
+
card.style.setProperty("--toast-card-lift", `${lift}px`);
|
|
3868
|
+
card.style.setProperty("--toast-card-scale", String(scale));
|
|
3869
|
+
card.style.setProperty("--toast-card-fan", `${fan}px`);
|
|
3870
|
+
card.style.setProperty("--toast-card-depth", String(cards.length - depth));
|
|
3871
|
+
if (depth > 0) {
|
|
3872
|
+
card.style.setProperty("--toast-card-clip", "0px");
|
|
3873
|
+
card.style.setProperty("--toast-card-fan-clip", `${fan}px`);
|
|
3874
|
+
} else {
|
|
3875
|
+
card.style.removeProperty("--toast-card-clip");
|
|
3876
|
+
card.style.removeProperty("--toast-card-fan-clip");
|
|
3877
|
+
}
|
|
3878
|
+
if (box < natural) {
|
|
3879
|
+
card.style.setProperty("--toast-card-box", `${box}px`);
|
|
3880
|
+
card.style.setProperty("--toast-card-natural", `${natural}px`);
|
|
3881
|
+
} else {
|
|
3882
|
+
card.style.removeProperty("--toast-card-box");
|
|
3883
|
+
card.style.removeProperty("--toast-card-natural");
|
|
3884
|
+
}
|
|
3885
|
+
});
|
|
3886
|
+
return geometry;
|
|
3887
|
+
}
|
|
3888
|
+
var PILE_PROPERTIES = ["--toast-pile-height", "--toast-fan-height"];
|
|
3889
|
+
var CARD_PROPERTIES = [
|
|
3890
|
+
"--toast-card-lift",
|
|
3891
|
+
"--toast-card-scale",
|
|
3892
|
+
"--toast-card-fan",
|
|
3893
|
+
"--toast-card-depth",
|
|
3894
|
+
"--toast-card-clip",
|
|
3895
|
+
"--toast-card-fan-clip",
|
|
3896
|
+
"--toast-card-box",
|
|
3897
|
+
"--toast-card-natural"
|
|
3898
|
+
];
|
|
3899
|
+
function clearToastPile(stack2) {
|
|
3900
|
+
if (!stack2) return;
|
|
3901
|
+
for (const name of PILE_PROPERTIES) stack2.style.removeProperty(name);
|
|
3902
|
+
for (const card of pileCards(stack2)) for (const name of CARD_PROPERTIES) card.style.removeProperty(name);
|
|
3903
|
+
}
|
|
3904
|
+
function watchToastPile(stack2) {
|
|
3905
|
+
if (!stack2) return () => {
|
|
3906
|
+
};
|
|
3907
|
+
const view = stack2.ownerDocument.defaultView;
|
|
3908
|
+
const watched = /* @__PURE__ */ new WeakSet();
|
|
3909
|
+
let observer = null;
|
|
3910
|
+
const sync2 = () => {
|
|
3911
|
+
applyToastPile(stack2);
|
|
3912
|
+
for (const card of pileCards(stack2)) {
|
|
3913
|
+
for (const el of [card, ...card.children]) {
|
|
3914
|
+
if (watched.has(el)) continue;
|
|
3915
|
+
watched.add(el);
|
|
3916
|
+
observer?.observe(el);
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
};
|
|
3920
|
+
observer = typeof view?.ResizeObserver === "function" ? new view.ResizeObserver(sync2) : null;
|
|
3921
|
+
const mutations = typeof view?.MutationObserver === "function" ? new view.MutationObserver(sync2) : null;
|
|
3922
|
+
mutations?.observe(stack2, { childList: true });
|
|
3923
|
+
sync2();
|
|
3924
|
+
return () => {
|
|
3925
|
+
observer?.disconnect();
|
|
3926
|
+
mutations?.disconnect();
|
|
3927
|
+
clearToastPile(stack2);
|
|
3928
|
+
};
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3931
|
+
// src/Toast.tsx
|
|
3824
3932
|
import { jsx as jsx35, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
3825
3933
|
var Context = createContext3(null);
|
|
3934
|
+
var PileHoldContext = createContext3(false);
|
|
3826
3935
|
var glyphs = { success: "circleCheck", danger: "circleX", warn: "circleAlert", info: "info", neutral: "bolt" };
|
|
3827
3936
|
function useToast() {
|
|
3828
3937
|
const push = useContext3(Context);
|
|
@@ -3835,7 +3944,8 @@ function Notice({ notice, remove }) {
|
|
|
3835
3944
|
const dismissed = useRef19(false);
|
|
3836
3945
|
const [hovered, setHovered] = useState14(false);
|
|
3837
3946
|
const [focused, setFocused] = useState14(false);
|
|
3838
|
-
const
|
|
3947
|
+
const pileHeld = useContext3(PileHoldContext);
|
|
3948
|
+
const paused = hovered || focused || pileHeld;
|
|
3839
3949
|
const tone = notice.tone ?? "success";
|
|
3840
3950
|
const timed = !notice.action && notice.timer !== false && notice.timer !== 0;
|
|
3841
3951
|
const duration = typeof notice.timer === "number" ? notice.timer * 1e3 : 5e3;
|
|
@@ -3936,8 +4046,21 @@ function usePublishedReach(stack2, count) {
|
|
|
3936
4046
|
};
|
|
3937
4047
|
}, [stack2, count]);
|
|
3938
4048
|
}
|
|
3939
|
-
function
|
|
4049
|
+
function usePile(stack2, piled, count) {
|
|
4050
|
+
useLayoutEffect4(() => {
|
|
4051
|
+
const element = stack2.current;
|
|
4052
|
+
if (!element) return;
|
|
4053
|
+
if (!piled) {
|
|
4054
|
+
clearToastPile(element);
|
|
4055
|
+
return;
|
|
4056
|
+
}
|
|
4057
|
+
return watchToastPile(element);
|
|
4058
|
+
}, [stack2, piled, count]);
|
|
4059
|
+
}
|
|
4060
|
+
function Toast({ children, collapse = false }) {
|
|
3940
4061
|
const [entries, setEntries] = useState14([]);
|
|
4062
|
+
const [pileHovered, setPileHovered] = useState14(false);
|
|
4063
|
+
const [pileFocused, setPileFocused] = useState14(false);
|
|
3941
4064
|
const nextId = useRef19(0);
|
|
3942
4065
|
const stack2 = useRef19(null);
|
|
3943
4066
|
const push = useCallback6((notice) => {
|
|
@@ -3945,11 +4068,31 @@ function Toast({ children }) {
|
|
|
3945
4068
|
const remove = () => setEntries((current) => current.filter((entry) => entry.id !== id));
|
|
3946
4069
|
setEntries((current) => [...current, { id, notice, remove }]);
|
|
3947
4070
|
}, []);
|
|
4071
|
+
const piled = collapse && entries.length >= TOAST_PILE_MIN;
|
|
4072
|
+
const pileHeld = piled && (pileHovered || pileFocused);
|
|
3948
4073
|
usePublishedReach(stack2, entries.length);
|
|
4074
|
+
usePile(stack2, piled, entries.length);
|
|
4075
|
+
const leavePileFocus = (event) => {
|
|
4076
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setPileFocused(false);
|
|
4077
|
+
};
|
|
3949
4078
|
return /* @__PURE__ */ jsxs30(Context.Provider, { value: push, children: [
|
|
3950
4079
|
children,
|
|
3951
4080
|
typeof document !== "undefined" && createPortal5(
|
|
3952
|
-
/* @__PURE__ */ jsx35(
|
|
4081
|
+
/* @__PURE__ */ jsx35(
|
|
4082
|
+
"div",
|
|
4083
|
+
{
|
|
4084
|
+
className: `ui-toast-stack rx-toast-stack${piled ? " ui-toast-stack--collapsed" : ""}`,
|
|
4085
|
+
ref: stack2,
|
|
4086
|
+
tabIndex: piled ? 0 : void 0,
|
|
4087
|
+
role: piled ? "region" : void 0,
|
|
4088
|
+
"aria-label": piled ? "Notifications" : void 0,
|
|
4089
|
+
onMouseEnter: () => setPileHovered(true),
|
|
4090
|
+
onMouseLeave: () => setPileHovered(false),
|
|
4091
|
+
onFocus: () => setPileFocused(true),
|
|
4092
|
+
onBlur: leavePileFocus,
|
|
4093
|
+
children: /* @__PURE__ */ jsx35(PileHoldContext.Provider, { value: pileHeld, children: entries.map((entry) => /* @__PURE__ */ jsx35(Notice, { notice: entry.notice, remove: entry.remove }, entry.id)) })
|
|
4094
|
+
}
|
|
4095
|
+
),
|
|
3953
4096
|
document.body
|
|
3954
4097
|
)
|
|
3955
4098
|
] });
|