Skip to content

Instantly share code, notes, and snippets.

@PCreations
Created September 16, 2024 19:26
Show Gist options
  • Save PCreations/f55913593b640cfb8c8620f1eb95d79e to your computer and use it in GitHub Desktop.
Save PCreations/f55913593b640cfb8c8620f1eb95d79e to your computer and use it in GitHub Desktop.
d0a9964a4d9d.diff
-0,0 +1,64 @@
+import * as elements from 'typed-html';
+
+export const Toast = ({
+ title,
+ message,
+ type,
+}: {
+ title: string;
+ message: string;
+ type: 'error' | 'success';
+}) => {
+ return (
+ <div
+ id="toast-container"
+ hx-swap-oob="true"
+ x-data="{ open: true }"
+ x-init="setTimeout(() => open = false, 1500)"
+ class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5"
+ x-show="open"
+ >
+ <div class="p-4">
+ <div class="flex items-start">
+ <div class="flex-shrink-0">
+ {`<svg
+ class="h-6 w-6 text-${type === 'success' ? 'green' : 'red'}-400"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
+ />
+ </svg>`}
+ </div>
+ <div class="ml-3 w-0 flex-1 pt-0.5">
+ <p class="text-sm font-medium text-gray-900">{title}</p>
+ <p class="mt-1 text-sm text-gray-500">{message}</p>
+ </div>
+ <div class="ml-4 flex flex-shrink-0">
+ <button
+ type="button"
+ x-on:click="open = false"
+ class="inline-flex rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
+ >
+ <span class="sr-only">Close</span>
+ {`<svg
+ class="h-5 w-5"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
+ </svg>`}
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
diff --git a/src/stories/Button.stories.ts b/src/stories/Button.stories.ts
index f06485b..be61f2c 100644
--- a/src/stories/Button.stories.ts
+++ b/src/stories/Button.stories.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment