Last active
June 2, 2023 16:16
-
-
Save diegohaz/341ed774ebac3b4dd820ae48d8bc822c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Notifications, push } from "./notifications.jsx"; | |
function Example() { | |
return ( | |
<> | |
<button | |
onClick={() => { | |
push("Hello"); | |
push("Hello", { role: "status" }); | |
push("Hello", { onUndo: () => {}, timeout: 10000 }); | |
push("Hello", { visuallyHidden: true }); | |
}} | |
> | |
Push notification | |
</button> | |
</> | |
); | |
} | |
export default function App() { | |
return ( | |
<> | |
<Example /> | |
<Notifications /> | |
</> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { | |
NotificationStoreItem | |
} from "@ariakit/react/notification"; | |
import { | |
createNotificationStore, | |
Notification, | |
NotificationContainer, | |
NotificationDismiss, | |
} from "@ariakit/react/notification"; | |
interface Item extends NotificationStoreItem { | |
onUndo?: () => void; | |
} | |
const notification = createNotificationStore<Item>(); | |
export const push = notification.push; | |
export function Notifications() { | |
const items = notification.useState("items"); | |
return ( | |
<NotificationContainer className="notification-container"> | |
{items.map(({ onUndo, ...props }) => ( | |
<Notification {...props} key={props.id} className="notification"> | |
{props.children} | |
<NotificationDismiss /> | |
{onUndo && <button onClick={onUndo}>Undo</button>} | |
</Notification> | |
))} | |
</NotificationContainer> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment