Skip to content

Commit

Permalink
chore: support more toast positions
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Sep 22, 2023
1 parent 7a85c15 commit 2e4d84a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/tiny-toast/src/preact/ui.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransitionManager } from "@hiogawa/tiny-transition";
import { includesGuard } from "@hiogawa/utils";
import { groupBy, includesGuard } from "@hiogawa/utils";
import type * as CSS from "csstype";
import { h } from "preact";
import { useEffect, useReducer, useState } from "preact/hooks";
Expand All @@ -14,7 +14,8 @@ import type { PreactToastItem, PreactToastManager } from "./api";
export function ToastContainer({ toast }: { toast: PreactToastManager }) {
useSubscribe(toast.subscribe);

// TODO: handle ToastPosition
const itemsByPosition = groupBy(toast.items, (item) => item.data.position);

return h(
"div",
{
Expand All @@ -32,6 +33,21 @@ export function ToastContainer({ toast }: { toast: PreactToastManager }) {
},
},
[
h(
"div",
{
style: istyle({
position: "absolute",
bottom: "0.5rem",
left: "0.75rem",
display: "flex",
flexDirection: "column",
}),
},
itemsByPosition
.get("bottom-left")
?.map((item) => h(ToastAnimation, { key: item.id, toast, item }))
),
h(
"div",
{
Expand All @@ -44,9 +60,9 @@ export function ToastContainer({ toast }: { toast: PreactToastManager }) {
alignItems: "center",
}),
},
toast.items.map((item) =>
h(ToastAnimation, { key: item.id, toast, item })
)
itemsByPosition
.get("top-center")
?.map((item) => h(ToastAnimation, { key: item.id, toast, item }))
),
]
);
Expand Down

0 comments on commit 2e4d84a

Please sign in to comment.