@orbitkit/components 0.2.0-beta.1 → 0.3.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.
Files changed (62) hide show
  1. package/dist/astro/accordion/Accordion.astro +34 -34
  2. package/dist/astro/accordion/AccordionItem.astro +19 -16
  3. package/dist/astro/accordion/AccordionTrigger.astro +33 -33
  4. package/dist/astro/accordion/AcordionContent.astro +23 -26
  5. package/dist/astro/accordion/accordion.ts +151 -125
  6. package/dist/astro/accordion/index.ts +6 -6
  7. package/dist/astro/collapsible/Collapsible.astro +34 -34
  8. package/dist/astro/collapsible/CollapsibleContent.astro +20 -20
  9. package/dist/astro/collapsible/collapsible.ts +81 -81
  10. package/dist/astro/collapsible/index.ts +4 -4
  11. package/dist/astro/drawer/DrawerContent.astro +74 -74
  12. package/dist/astro/drawer/drawer.ts +104 -104
  13. package/dist/astro/drawer/index.ts +2 -0
  14. package/dist/astro/dropdown/DropdownMenu.astro +19 -19
  15. package/dist/astro/dropdown/DropdownMenuContent.astro +42 -42
  16. package/dist/astro/dropdown/DropdownMenuGroup.astro +3 -3
  17. package/dist/astro/dropdown/DropdownMenuItem.astro +27 -27
  18. package/dist/astro/dropdown/DropdownMenuLabel.astro +3 -3
  19. package/dist/astro/dropdown/DropdownMenuSeparator.astro +6 -6
  20. package/dist/astro/dropdown/dropdown.ts +157 -157
  21. package/dist/astro/dropdown/dropdownVariants.ts +134 -134
  22. package/dist/astro/dropdown/index.ts +23 -15
  23. package/dist/astro/marquee/Marquee.astro +53 -0
  24. package/dist/astro/marquee/index.ts +3 -0
  25. package/dist/astro/modal/Modal.astro +19 -19
  26. package/dist/astro/modal/ModalContent.astro +2 -2
  27. package/dist/astro/modal/ModalDescription.astro +12 -12
  28. package/dist/astro/modal/ModalFooter.astro +15 -15
  29. package/dist/astro/modal/ModalHeader.astro +12 -12
  30. package/dist/astro/modal/ModalTitle.astro +18 -18
  31. package/dist/astro/modal/index.ts +15 -15
  32. package/dist/astro/modal/modal.ts +101 -101
  33. package/dist/astro/pagination/index.ts +2 -0
  34. package/dist/astro/popover/Popover.astro +17 -17
  35. package/dist/astro/popover/PopoverContent.astro +39 -39
  36. package/dist/astro/popover/index.ts +5 -4
  37. package/dist/astro/popover/popover.ts +113 -113
  38. package/dist/astro/popover/popoverVariants.ts +115 -115
  39. package/dist/astro/scroll-progress/ScrollProgress.astro +41 -0
  40. package/dist/astro/scroll-progress/ScrollProgressBar.astro +19 -0
  41. package/dist/astro/scroll-progress/index.ts +4 -0
  42. package/dist/astro/stat/Stat.astro +12 -12
  43. package/dist/astro/stat/StatDescription.astro +12 -12
  44. package/dist/astro/stat/StatTitle.astro +18 -18
  45. package/dist/astro/stat/StatValue.astro +12 -12
  46. package/dist/astro/stat/index.ts +6 -6
  47. package/dist/astro/tab/TabList.astro +19 -19
  48. package/dist/astro/toast/Toast.astro +36 -0
  49. package/dist/astro/toast/ToastDescription.astro +10 -0
  50. package/dist/astro/toast/ToastTitle.astro +18 -0
  51. package/dist/astro/toast/Toaster.astro +78 -0
  52. package/dist/astro/toast/assets.ts +6 -0
  53. package/dist/astro/toast/index.ts +30 -0
  54. package/dist/astro/toast/toast.ts +277 -0
  55. package/dist/astro/tooltip/Tooltip.astro +40 -40
  56. package/dist/astro/tooltip/TooltipContent.astro +39 -39
  57. package/dist/astro/tooltip/index.ts +5 -6
  58. package/dist/astro/tooltip/tooltip.ts +137 -137
  59. package/dist/astro/tooltip/tooltipVariants.ts +115 -115
  60. package/dist/index.js +18 -5
  61. package/dist/index.js.map +1 -1
  62. package/package.json +1 -1
@@ -1,19 +1,19 @@
1
- ---
2
- import { cn } from "@/utils/cn";
3
- import type { HTMLAttributes } from "astro/types";
4
-
5
- interface Props extends HTMLAttributes<"div"> {}
6
-
7
- const { class: className } = Astro.props;
8
- ---
9
-
10
- <div
11
- role="tablist"
12
- data-tab-list
13
- class={cn(
14
- "flex flex-row justify-between flex-wrap bg-surface border border-border p-1 rounded-lg w-fit",
15
- className,
16
- )}
17
- >
18
- <slot />
19
- </div>
1
+ ---
2
+ import { cn } from "@/utils/cn";
3
+ import type { HTMLAttributes } from "astro/types";
4
+
5
+ interface Props extends HTMLAttributes<"div"> {}
6
+
7
+ const { class: className } = Astro.props;
8
+ ---
9
+
10
+ <div
11
+ role="tablist"
12
+ data-tab-list
13
+ class={cn(
14
+ "flex flex-row justify-between flex-wrap bg-surface border border-border p-1 rounded-lg w-fit",
15
+ className,
16
+ )}
17
+ >
18
+ <slot />
19
+ </div>
@@ -0,0 +1,36 @@
1
+ ---
2
+ import { cn } from "@/utils/cn";
3
+ import type { HTMLAttributes } from "astro/types";
4
+
5
+ interface Props extends HTMLAttributes<"div"> {}
6
+
7
+ const { class: className, ...attrs } = Astro.props;
8
+ ---
9
+
10
+ <div
11
+ data-toast
12
+ class={cn(
13
+ "fixed z-[1000] p-4 bg-background text-foreground border border-border rounded-lg shadow-lg flex flex-row items-start gap-2 overflow-hidden opacity-0 duration-500 transition-all ease-in-out min-w-xs max-w-md data-[state=showing]:opacity-100 data-[state=hide]:pointer-events-none ",
14
+ className,
15
+ )}
16
+ {...attrs}
17
+ >
18
+ <slot />
19
+ </div>
20
+
21
+ <style>
22
+ @reference "@/styles/global.css";
23
+
24
+ [data-toast][data-toast-type="success"] {
25
+ @apply border-green-500 bg-green-50 text-green-800;
26
+ }
27
+ [data-toast][data-toast-type="error"] {
28
+ @apply border-red-500 bg-red-50 text-red-800;
29
+ }
30
+ [data-toast][data-toast-type="warning"] {
31
+ @apply border-orange-400 bg-orange-50 text-orange-800;
32
+ }
33
+ [data-toast][data-toast-type="info"] {
34
+ @apply border-blue-500 bg-blue-50 text-blue-800;
35
+ }
36
+ </style>
@@ -0,0 +1,10 @@
1
+ ---
2
+ import { cn } from "@/utils/cn";
3
+ import { type HTMLAttributes } from "astro/types";
4
+
5
+ interface Props extends HTMLAttributes<"p"> {}
6
+
7
+ const { class: className, ...attrs } = Astro.props;
8
+ ---
9
+
10
+ <p data-toast-description class={cn("text-sm", className)} {...attrs}></p>
@@ -0,0 +1,18 @@
1
+ ---
2
+ import { cn } from "@/utils/cn";
3
+ import type { HTMLAttributes } from "astro/types";
4
+
5
+ interface Props extends HTMLAttributes<"h5"> {}
6
+
7
+ const { class: className, ...attrs } = Astro.props;
8
+ ---
9
+
10
+ <h5
11
+ data-toast-title
12
+ class={cn(
13
+ "font-medium flex items-center justify-start gap-2 text-sm",
14
+ className,
15
+ )}
16
+ {...attrs}
17
+ >
18
+ </h5>
@@ -0,0 +1,78 @@
1
+ ---
2
+ import Toast from "./Toast.astro";
3
+ import ToastDescription from "./ToastDescription.astro";
4
+ import ToastTitle from "./ToastTitle.astro";
5
+
6
+ interface Props {
7
+ offset?: number;
8
+ gap?: number;
9
+ position?:
10
+ | "top-right"
11
+ | "top-center"
12
+ | "top-left"
13
+ | "bottom-right"
14
+ | "bottom-center"
15
+ | "bottom-left";
16
+ visibleToasts?: number;
17
+ dismissible?: boolean;
18
+ autoClose?: boolean;
19
+ }
20
+
21
+ const {
22
+ offset = 24,
23
+ gap = 16,
24
+ position = "bottom-right",
25
+ visibleToasts = 3,
26
+ dismissible = true,
27
+ autoClose = true,
28
+ } = Astro.props;
29
+ ---
30
+
31
+ <section
32
+ tabindex="-1"
33
+ data-toaster
34
+ data-position={position}
35
+ data-visible-toasts={visibleToasts}
36
+ data-offset={offset}
37
+ data-dismissible={dismissible}
38
+ data-position={position}
39
+ data-gap={gap}
40
+ data-auto-close={autoClose}
41
+ >
42
+ <template id="toast-template">
43
+ <slot>
44
+ <Toast>
45
+ <div data-toast-icon></div>
46
+
47
+ <div>
48
+ <ToastTitle />
49
+ <ToastDescription />
50
+ </div>
51
+
52
+ <button
53
+ class="absolute right-1 top-1 cursor-pointer rounded-lg p-1 transition-colors duration-150"
54
+ aria-label="close toast"
55
+ data-close
56
+ data-dismissible-button
57
+ >
58
+ <svg
59
+ xmlns="http://www.w3.org/2000/svg"
60
+ viewBox="0 0 24 24"
61
+ fill="none"
62
+ stroke="currentColor"
63
+ stroke-width="2"
64
+ stroke-linecap="round"
65
+ stroke-linejoin="round"
66
+ class="size-4"
67
+ >
68
+ <>
69
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
70
+ <path d="M18 6l-12 12"></path>
71
+ <path d="M6 6l12 12"></path>
72
+ </>
73
+ </svg>
74
+ </button>
75
+ </Toast>
76
+ </slot>
77
+ </template>
78
+ </section>
@@ -0,0 +1,6 @@
1
+ export const toastIcons: Record<string, string> = {
2
+ success: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-1.293 5.953a1 1 0 0 0 -1.32 -.083l-.094 .083l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.403 1.403l.083 .094l2 2l.094 .083a1 1 0 0 0 1.226 0l.094 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z" /></svg>`,
3
+ error: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-alert-circle"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm.01 13l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -8a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z" /></svg>`,
4
+ warning: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 1.67c.955 0 1.845 .467 2.39 1.247l.105 .16l8.114 13.548a2.914 2.914 0 0 1 -2.307 4.363l-.195 .008h-16.225a2.914 2.914 0 0 1 -2.582 -4.2l.099 -.185l8.11 -13.538a2.914 2.914 0 0 1 2.491 -1.403zm.01 13.33l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -7a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z" /></svg>`,
5
+ info: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm0 9h-1l-.117 .007a1 1 0 0 0 0 1.986l.117 .007v3l.007 .117a1 1 0 0 0 .876 .876l.117 .007h1l.117 -.007a1 1 0 0 0 .876 -.876l.007 -.117l-.007 -.117a1 1 0 0 0 -.764 -.857l-.112 -.02l-.117 -.006v-3l-.007 -.117a1 1 0 0 0 -.876 -.876l-.117 -.007zm.01 -3l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007z" /></svg>`,
6
+ };
@@ -0,0 +1,30 @@
1
+ import { toastIcons } from "./assets";
2
+ import type {
3
+ ToastDomElements,
4
+ ToastOptions,
5
+ ToastPosition,
6
+ ToastType,
7
+ } from "./toast";
8
+ import { Toast as ToastHandler } from "./toast";
9
+ import Toast from "./Toast.astro";
10
+ import ToastDescription from "./ToastDescription.astro";
11
+ import ToastTitle from "./ToastTitle.astro";
12
+
13
+ export { Toast, ToastDescription, ToastHandler, toastIcons, ToastTitle };
14
+ export type { ToastDomElements, ToastOptions, ToastPosition, ToastType };
15
+
16
+ export const toast = Object.assign(
17
+ (opts: ToastOptions) => new ToastHandler(opts),
18
+ {
19
+ success: (opts: Omit<ToastOptions, "type">) =>
20
+ new ToastHandler({ ...opts, type: "success" }),
21
+ error: (opts: Omit<ToastOptions, "type">) =>
22
+ new ToastHandler({ ...opts, type: "error" }),
23
+ warning: (opts: Omit<ToastOptions, "type">) =>
24
+ new ToastHandler({ ...opts, type: "warning" }),
25
+ info: (opts: Omit<ToastOptions, "type">) =>
26
+ new ToastHandler({ ...opts, type: "info" }),
27
+ default: (opts: Omit<ToastOptions, "type">) =>
28
+ new ToastHandler({ ...opts, type: "default" }),
29
+ },
30
+ );
@@ -0,0 +1,277 @@
1
+ import { toastIcons } from "./assets";
2
+
3
+ export interface ToastDomElements {
4
+ title: HTMLElement | null;
5
+ description: HTMLElement | null;
6
+ dismissibleButton: HTMLElement | null;
7
+ iconContainer: HTMLElement | null;
8
+ closeButtons: NodeListOf<HTMLElement>;
9
+ }
10
+
11
+ export type ToastPosition =
12
+ | "top-right"
13
+ | "top-center"
14
+ | "top-left"
15
+ | "bottom-right"
16
+ | "bottom-center"
17
+ | "bottom-left";
18
+
19
+ export type ToastType = "default" | "success" | "error" | "warning" | "info";
20
+
21
+ export interface ToastOptions {
22
+ title: string;
23
+ description?: string;
24
+ duration?: number;
25
+ dismissible?: boolean;
26
+ autoClose?: boolean;
27
+ type?: ToastType;
28
+ onClose?: () => void;
29
+ }
30
+
31
+ const DEFAULT_DURATION = 3000;
32
+ const DEFAULT_MAX_VISIBLE_TOASTS = 3;
33
+ const DEFAULT_OFFSET = 24;
34
+ const DEFAULT_GAP = 16;
35
+ const DEFAULT_POSITION: ToastPosition = "bottom-right";
36
+ const DEFAULT_TOAST_TYPE: ToastType = "default";
37
+
38
+ export class Toast {
39
+ private static instances: HTMLElement[] = [];
40
+
41
+ private opts: ToastOptions;
42
+ private toaster: HTMLElement | null;
43
+ private toast: HTMLElement | null;
44
+ private elements: ToastDomElements;
45
+
46
+ private duration: number;
47
+ private startTime: number = 0;
48
+ private remainingTime: number = 0;
49
+ private timeoutId: number | null = null;
50
+ private position: ToastPosition;
51
+ private dismissible: boolean;
52
+ private autoClose: boolean;
53
+
54
+ private maxVisibleToasts: number;
55
+ private offset: number;
56
+ private gap: number;
57
+
58
+ constructor(opts: ToastOptions) {
59
+ this.opts = opts;
60
+
61
+ this.toaster = document.querySelector("[data-toaster]");
62
+ if (!this.toaster) {
63
+ throw new Error(
64
+ "Toaster container with 'data-toaster' attribute not found in the document.",
65
+ );
66
+ }
67
+
68
+ this.toast = this.getTemplate().querySelector(
69
+ "[data-toast]",
70
+ ) as HTMLElement;
71
+ if (!this.toast) {
72
+ throw new Error("Toast element with 'data-toast' not found in template.");
73
+ }
74
+
75
+ this.elements = {
76
+ title: this.toast.querySelector("[data-toast-title]"),
77
+ description: this.toast.querySelector("[data-toast-description]"),
78
+ iconContainer: this.toast.querySelector("[data-toast-icon]"),
79
+ closeButtons: this.toast.querySelectorAll("[data-close]") ?? [],
80
+ dismissibleButton: this.toast.querySelector("[data-dismissible-button]"),
81
+ };
82
+
83
+ this.gap = parseInt(this.toaster.dataset.gap ?? `${DEFAULT_GAP}`, 10);
84
+ this.maxVisibleToasts = parseInt(
85
+ this.toaster.dataset.visibleToasts ?? `${DEFAULT_MAX_VISIBLE_TOASTS}`,
86
+ 10,
87
+ );
88
+ this.offset = parseInt(
89
+ this.toaster.dataset.offset ?? `${DEFAULT_OFFSET}`,
90
+ 10,
91
+ );
92
+ this.position =
93
+ (this.toaster?.dataset.position as typeof this.position) ??
94
+ DEFAULT_POSITION;
95
+ this.duration =
96
+ this.opts.duration ??
97
+ parseInt(this.toaster.dataset.duration ?? `${DEFAULT_DURATION}`);
98
+ this.dismissible =
99
+ this.opts.dismissible ?? this.toaster.dataset.dismissible === "true";
100
+ this.autoClose =
101
+ this.opts.autoClose ?? this.toaster.dataset.autoClose === "true";
102
+
103
+ this.init();
104
+ }
105
+
106
+ private init() {
107
+ this.initializeToastContent();
108
+ this.calculateInitialPosition();
109
+ this.setupAccessibility();
110
+ this.setupEventListeners();
111
+ this.showToast();
112
+ }
113
+
114
+ private setupAccessibility() {
115
+ if (this.toast) {
116
+ this.toast.setAttribute("role", "alert");
117
+ this.toast.setAttribute("aria-live", "assertive");
118
+ this.toast.setAttribute("aria-atomic", "true");
119
+ }
120
+ }
121
+
122
+ private initializeToastContent() {
123
+ this.toast!.setAttribute(
124
+ "data-toast-type",
125
+ this.opts.type ?? DEFAULT_TOAST_TYPE,
126
+ );
127
+
128
+ if (this.elements.iconContainer) {
129
+ const iconType = toastIcons[this.opts.type ?? DEFAULT_TOAST_TYPE];
130
+ if (iconType) {
131
+ this.elements.iconContainer.innerHTML = iconType;
132
+ } else {
133
+ this.elements.iconContainer.remove();
134
+ this.elements.iconContainer = null;
135
+ }
136
+ }
137
+
138
+ if (this.elements.title) {
139
+ this.elements.title.textContent = this.opts.title;
140
+ } else {
141
+ console.warn(
142
+ "Toast title element not found. Title might not be displayed.",
143
+ );
144
+ }
145
+
146
+ if (this.opts.description && this.elements.description) {
147
+ this.elements.description.textContent = this.opts.description;
148
+ } else if (this.elements.description) {
149
+ this.elements.description.remove();
150
+ this.elements.description = null;
151
+ }
152
+
153
+ if (!this.dismissible && this.elements.dismissibleButton) {
154
+ this.elements.dismissibleButton.remove();
155
+ this.elements.dismissibleButton = null;
156
+ }
157
+ }
158
+
159
+ private setupEventListeners() {
160
+ this.elements.closeButtons.forEach((trigger) => {
161
+ trigger.addEventListener("click", () => this.removeToast());
162
+ });
163
+ this.toaster!.addEventListener("mouseenter", () => this.handleMouseEnter());
164
+ this.toaster!.addEventListener("mouseleave", () => this.handleMouseLeave());
165
+ }
166
+
167
+ private showToast() {
168
+ this.toaster?.insertAdjacentElement("afterbegin", this.toast!);
169
+ Toast.instances.unshift(this.toast!);
170
+ this.adjustToastPositions();
171
+ this.setState(this.toast!, "showing");
172
+
173
+ if (this.autoClose) {
174
+ this.startTime = Date.now();
175
+ this.remainingTime = this.duration;
176
+ this.timeoutId = window.setInterval(() => {
177
+ this.removeToast();
178
+ this.opts.onClose?.();
179
+ }, this.duration);
180
+ }
181
+ }
182
+
183
+ private removeToast() {
184
+ this.setState(this.toast!, "hide");
185
+ const index = Toast.instances.indexOf(this.toast!);
186
+ if (index !== -1) {
187
+ Toast.instances.splice(index, 1);
188
+ }
189
+ this.adjustToastPositions();
190
+
191
+ setTimeout(() => {
192
+ this.toast?.remove();
193
+ this.opts.onClose?.();
194
+ }, 500);
195
+ }
196
+
197
+ private adjustToastPositions() {
198
+ const isButtom = this.position.startsWith("bottom");
199
+ let accumulatedHeight = this.offset;
200
+
201
+ Toast.instances.forEach((currentToast, index) => {
202
+ accumulatedHeight += currentToast.offsetHeight;
203
+ const verticalOffset = accumulatedHeight + index * this.gap;
204
+
205
+ const sign = isButtom ? -1 : 1;
206
+ const translateYValue =
207
+ sign * (verticalOffset - currentToast.offsetHeight);
208
+
209
+ let translateXValue = "";
210
+ if (this.position.endsWith("center")) {
211
+ translateXValue = "translateX(-50%)";
212
+ }
213
+
214
+ currentToast.style.transform = `${translateXValue} translateY(${translateYValue}px)`;
215
+
216
+ this.setState(
217
+ currentToast,
218
+ index < this.maxVisibleToasts ? "showing" : "hide",
219
+ );
220
+ });
221
+ }
222
+
223
+ private handleMouseEnter() {
224
+ if (!this.autoClose) return;
225
+ if (this.timeoutId) {
226
+ clearTimeout(this.timeoutId);
227
+ const elapsedTime = Date.now() - this.startTime;
228
+ this.remainingTime = Math.max(0, this.remainingTime - elapsedTime);
229
+ this.timeoutId = null;
230
+ }
231
+ }
232
+
233
+ private handleMouseLeave() {
234
+ if (!this.autoClose) return;
235
+ if (this.remainingTime > 0) {
236
+ this.startTime = Date.now();
237
+ this.timeoutId = window.setTimeout(
238
+ () => this.removeToast(),
239
+ this.remainingTime,
240
+ );
241
+ } else {
242
+ this.removeToast();
243
+ }
244
+ }
245
+
246
+ private calculateInitialPosition() {
247
+ const [y, x] = this.position.split("-");
248
+
249
+ if (y === "top") {
250
+ this.toast!.style.top = `0px`;
251
+ } else {
252
+ this.toast!.style.bottom = `0px`;
253
+ }
254
+
255
+ if (x === "left") {
256
+ this.toast!.style.left = `${this.offset}px`;
257
+ } else if (x === "center") {
258
+ this.toast!.style.left = "50%";
259
+ this.toast!.style.transform = "translateX(-50%)";
260
+ } else {
261
+ this.toast!.style.right = `${this.offset}px`;
262
+ }
263
+ }
264
+
265
+ private setState(toast: HTMLElement, state: "showing" | "hide") {
266
+ toast.setAttribute("data-state", state);
267
+ }
268
+
269
+ private getTemplate() {
270
+ const toastTemplate =
271
+ this.toaster?.querySelector<HTMLTemplateElement>("#toast-template");
272
+ if (!toastTemplate) {
273
+ throw new Error("Toast template not found in the document.");
274
+ }
275
+ return toastTemplate.content.cloneNode(true) as DocumentFragment;
276
+ }
277
+ }
@@ -1,40 +1,40 @@
1
- ---
2
- interface Props {
3
- disableHoverableContent?: boolean;
4
- openDelay?: number;
5
- closeDelay?: number;
6
- duration?: number;
7
- }
8
-
9
- const {
10
- openDelay = 150,
11
- closeDelay = 150,
12
- duration = 200,
13
- disableHoverableContent = false,
14
- } = Astro.props;
15
- ---
16
-
17
- <div
18
- class="relative inline-flex"
19
- data-tooltip
20
- data-open-delay={openDelay}
21
- data-close-delay={closeDelay}
22
- data-duration={duration}
23
- data-disable-hoverable-content={disableHoverableContent}
24
- >
25
- <slot />
26
- </div>
27
-
28
- <script>
29
- import { Tooltip } from "./tooltip";
30
-
31
- function init() {
32
- const tooltips = document.querySelectorAll<HTMLElement>("[data-tooltip]");
33
- tooltips.forEach((tooltip) => {
34
- new Tooltip(tooltip);
35
- });
36
- }
37
-
38
- init();
39
- document.addEventListener("astro:page-load", () => init());
40
- </script>
1
+ ---
2
+ interface Props {
3
+ disableHoverableContent?: boolean;
4
+ openDelay?: number;
5
+ closeDelay?: number;
6
+ duration?: number;
7
+ }
8
+
9
+ const {
10
+ openDelay = 150,
11
+ closeDelay = 150,
12
+ duration = 200,
13
+ disableHoverableContent = false,
14
+ } = Astro.props;
15
+ ---
16
+
17
+ <div
18
+ class="relative inline-flex"
19
+ data-tooltip
20
+ data-open-delay={openDelay}
21
+ data-close-delay={closeDelay}
22
+ data-duration={duration}
23
+ data-disable-hoverable-content={disableHoverableContent}
24
+ >
25
+ <slot />
26
+ </div>
27
+
28
+ <script>
29
+ import { Tooltip } from "./tooltip";
30
+
31
+ function init() {
32
+ const tooltips = document.querySelectorAll<HTMLElement>("[data-tooltip]");
33
+ tooltips.forEach((tooltip) => {
34
+ new Tooltip(tooltip);
35
+ });
36
+ }
37
+
38
+ init();
39
+ document.addEventListener("astro:page-load", () => init());
40
+ </script>
@@ -1,39 +1,39 @@
1
- ---
2
- import { cn } from "@/utils/cn";
3
- import type { HTMLAttributes } from "astro/types";
4
- import type { VariantProps } from "class-variance-authority";
5
- import { tooltipArrowVariants, tooltipVariants } from "./tooltipVariants";
6
-
7
- interface Props
8
- extends HTMLAttributes<"div">,
9
- VariantProps<typeof tooltipVariants> {
10
- sideOffset?: number;
11
- arrow?: boolean;
12
- }
13
-
14
- const {
15
- class: className,
16
- side,
17
- alignment,
18
- sideOffset = 2,
19
- arrow = true,
20
- ...attrs
21
- } = Astro.props;
22
- ---
23
-
24
- <div
25
- {...attrs}
26
- role="tooltip"
27
- data-tooltip-content
28
- aria-hidden="false"
29
- data-state="closed"
30
- data-side={sideOffset}
31
- data-alignment={alignment}
32
- class={cn(tooltipVariants({ side, alignment, className }))}
33
- style={{
34
- "--tooltip-offset": `calc(var(--spacing) * ${sideOffset})`,
35
- }}
36
- >
37
- <slot />
38
- {arrow && <span class={cn(tooltipArrowVariants({ side, alignment }))} />}
39
- </div>
1
+ ---
2
+ import { cn } from "@/utils/cn";
3
+ import type { HTMLAttributes } from "astro/types";
4
+ import type { VariantProps } from "class-variance-authority";
5
+ import { tooltipArrowVariants, tooltipVariants } from "./tooltipVariants";
6
+
7
+ interface Props
8
+ extends HTMLAttributes<"div">,
9
+ VariantProps<typeof tooltipVariants> {
10
+ sideOffset?: number;
11
+ arrow?: boolean;
12
+ }
13
+
14
+ const {
15
+ class: className,
16
+ side,
17
+ alignment,
18
+ sideOffset = 2,
19
+ arrow = true,
20
+ ...attrs
21
+ } = Astro.props;
22
+ ---
23
+
24
+ <div
25
+ {...attrs}
26
+ role="tooltip"
27
+ data-tooltip-content
28
+ aria-hidden="false"
29
+ data-state="closed"
30
+ data-side={sideOffset}
31
+ data-alignment={alignment}
32
+ class={cn(tooltipVariants({ side, alignment, className }))}
33
+ style={{
34
+ "--tooltip-offset": `calc(var(--spacing) * ${sideOffset})`,
35
+ }}
36
+ >
37
+ <slot />
38
+ {arrow && <span class={cn(tooltipArrowVariants({ side, alignment }))} />}
39
+ </div>
@@ -1,6 +1,5 @@
1
- import Tooltip from "./Tooltip.astro";
2
- import TooltipContent from "./TooltipContent.astro";
3
- import TooltipTrigger from "./TooltipTrigger.astro";
4
- import { tooltipVariants } from "./tooltipVariants";
5
-
6
- export { Tooltip, TooltipContent, TooltipTrigger, tooltipVariants };
1
+ import Tooltip from "./Tooltip.astro";
2
+ import TooltipContent from "./TooltipContent.astro";
3
+ import { tooltipArrowVariants, tooltipVariants } from "./tooltipVariants";
4
+
5
+ export { Tooltip, tooltipArrowVariants, TooltipContent, tooltipVariants };