@cruxkit/toast 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Maysara Elshewehy (https://github.com/maysara-elshewehy)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ <!-- ╔══════════════════════════════ BEG ══════════════════════════════╗ -->
2
+
3
+ <br>
4
+ <div align="center">
5
+ <p>
6
+ <img src="./assets/img/logo.png" alt="logo" style="" height="60" />
7
+ </p>
8
+ </div>
9
+
10
+ <div align="center">
11
+ <img src="https://img.shields.io/badge/v-0.0.1-black"/>
12
+ <a href="https://github.com/cruxkit-org"><img src="https://img.shields.io/badge/🔥-@cruxkit-black"/></a>
13
+ <br>
14
+ <img src="https://img.shields.io/badge/coverage-100%25-brightgreen" alt="Test Coverage" />
15
+ <img src="https://img.shields.io/github/issues/cruxkit-orgz/toast?style=flat" alt="Github Repo Issues" />
16
+ <img src="https://img.shields.io/github/stars/cruxkit-orgz/toast?style=social" alt="GitHub Repo stars" />
17
+ </div>
18
+ <br>
19
+
20
+ <!-- ╚═════════════════════════════════════════════════════════════════╝ -->
21
+
22
+
23
+
24
+ <!-- ╔══════════════════════════════ DOC ══════════════════════════════╗ -->
25
+
26
+ - ## Overview 👀
27
+
28
+ - #### Why ?
29
+ > A lightweight, reactive toast kit, built for [`@cruxjs`](https://github.com/cruxjs-org) ecosystem, especially for [`@cruxext/toast`](https://github.com/cruxext-org/toast) extension.
30
+
31
+ - #### When ?
32
+ > When you need to display brief, non-blocking feedback or notifications to your users.
33
+
34
+ <br>
35
+ <br>
36
+
37
+ - ## Quick Start 🔥
38
+
39
+ > install [`hmm`](https://github.com/minejs-org/hmm) first.
40
+
41
+ ```bash
42
+ # in your terminal
43
+ hmm i @cruxkit/toast
44
+ ```
45
+
46
+ ```ts
47
+ // in your ts files
48
+ import { Toast, ToastContainer } from `@cruxkit/toast`;
49
+ ```
50
+
51
+ <div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> </div>
52
+ <br>
53
+
54
+ - ### Example
55
+
56
+ > See [`@cruxext/toast`](https://github.com/cruxext-org/toast) for more details.
57
+
58
+ <br>
59
+ <br>
60
+
61
+ - ## Documentation 📑
62
+
63
+
64
+ - ### API ⛓️
65
+
66
+ - #### Functions
67
+
68
+ ```typescript
69
+ export function Toast(props: ToastProps): JSXElement
70
+
71
+ export function ToastContainer(props: ToastContainerProps): JSXElement
72
+ ```
73
+
74
+ - #### Types
75
+
76
+ ```typescript
77
+ export type ToastType = 'success' | 'error' | 'warning' | 'info';
78
+
79
+ export interface ToastOptions {
80
+ type? : ToastType;
81
+ duration? : number; // in ms
82
+ onClose? : () => void;
83
+ }
84
+
85
+ export interface ToastInstance extends ToastOptions {
86
+ id : string;
87
+ message : string;
88
+ type : ToastType;
89
+ duration : number;
90
+ closing? : boolean;
91
+ }
92
+
93
+ export interface ToastProps {
94
+ key? : string;
95
+ toast : ToastInstance;
96
+ onDismiss : (id: string) => void;
97
+ }
98
+
99
+ export interface ToastContainerProps {
100
+ position? : 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
101
+ className? : string;
102
+ toasts : Signal<ToastInstance[]> | ToastInstance[];
103
+ onDismiss : (id: string) => void;
104
+ }
105
+ ```
106
+
107
+ <div align="center"> <img src="./assets/img/line.png" alt="line" style="display: block; margin-top:20px;margin-bottom:20px;width:500px;"/> </div>
108
+ <br>
109
+
110
+ - ### Related 🔗
111
+
112
+ - ##### [@minejs/jsx](https://github.com/minejs-org/jsx)
113
+ - ##### [@minejs/signals](https://github.com/minejs-org/signals)
114
+
115
+ - ##### [@cruxkit/overlay](https://github.com/cruxkit-org/overlay)
116
+ - ##### [@cruxkit/text](https://github.com/cruxkit-org/text)
117
+ - ##### [@cruxkit/icon](https://github.com/cruxkit-org/icon)
118
+
119
+ - ##### [@cruxext/toast](https://github.com/cruxext-org/toast)
120
+
121
+ - ##### [@cruxjs/client](https://github.com/cruxjs-org/client)
122
+ - ##### [@cruxjs/app](https://github.com/cruxjs-org/app)
123
+
124
+ ...
125
+
126
+ <!-- ╚═════════════════════════════════════════════════════════════════╝ -->
127
+
128
+
129
+
130
+ <!-- ╔══════════════════════════════ END ══════════════════════════════╗ -->
131
+
132
+ <br>
133
+ <br>
134
+
135
+ ---
136
+
137
+ <div align="center">
138
+ <a href="https://github.com/maysara-elshewehy"><img src="https://img.shields.io/badge/by-Maysara-black"/></a>
139
+ </div>
140
+
141
+ <!-- ╚═════════════════════════════════════════════════════════════════╝ -->
package/dist/index.cjs ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';var jsx=require('@minejs/jsx'),overlay=require('@cruxkit/overlay'),icon=require('@cruxkit/icon'),text=require('@cruxkit/text'),jsxRuntime=require('@minejs/jsx/jsx-runtime');var b=o=>{switch(o){case "success":return "circle-check";case "error":return "circle-xmark";case "warning":return "triangle-exclamation";case "info":return "circle-info";default:return "circle-info"}},x=o=>{switch(o){case "success":return "text-success bg-success-subtle border-success";case "error":return "text-error bg-error-subtle border-error";case "warning":return "text-warning bg-warning-subtle border-warning";default:return "text-2 bg-surface border-c2"}};function y(o){let{toast:t,onDismiss:r}=o;return jsxRuntime.jsxs("div",{className:`
2
+ pointer-events-auto
3
+ flex items-center gap-3 p-4 rounded-lg border shadow-lg
4
+ w-full transform transition-all duration-300
5
+ bg-surface
6
+ ${t.closing?"opacity-0 scale-95":"animate-in fade-in zoom-in-95 opacity-100 scale-100"}
7
+ ${x(t.type)}
8
+ `,children:[jsxRuntime.jsx(icon.Icon,{name:b(t.type),size:20}),jsxRuntime.jsx(text.Text,{size:"sm",className:"flex-1 font-medium text-1",children:t.message}),jsxRuntime.jsx("button",{onClick:()=>r(t.id),className:"p-1 hover:opacity-75 rounded transition-colors",children:jsxRuntime.jsx(icon.Icon,{name:"x",size:16})})]})}function k(o){let{position:t,className:r="",toasts:i,onDismiss:a}=o;t||(t=typeof document<"u"&&document.documentElement.dir==="rtl"?"bottom-left":"bottom-right");let c={"top-right":"top-right","top-left":"top-left","bottom-right":"bottom-right","bottom-left":"bottom-left","top-center":"top","bottom-center":"bottom"}[t]||"bottom-right",l=t.includes("top"),m=t.includes("right"),p=l?"flex-col-reverse":"flex-col",u=t.includes("center")?"items-center":m?"items-end":"items-start";return jsxRuntime.jsx(overlay.Overlay,{position:c,backdrop:false,zIndex:60,className:`pointer-events-none p-4 ${r}`,children:jsxRuntime.jsx("div",{className:`flex ${p} ${u} gap-3 w-full max-w-sm pointer-events-none`,children:jsxRuntime.jsx(jsx.For,{each:i,children:s=>jsxRuntime.jsx(y,{toast:s,onDismiss:a},s.id)})})})}exports.Toast=y;exports.ToastContainer=k;//# sourceMappingURL=index.cjs.map
9
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/kit/toast.tsx"],"names":["getIconForType","type","getColorForType","Toast","props","toast","onDismiss","jsxs","jsx","Icon","Text","ToastContainer","position","className","toasts","overlayPosition","isTop","isRight","stackClass","alignClass","Overlay","For"],"mappings":"0LAqBI,IAAMA,EAAkBC,CAAAA,EAAoB,CACxC,OAAQA,CAAAA,EACJ,KAAK,SAAA,CAAW,OAAO,eACvB,KAAK,OAAA,CAAW,OAAO,cAAA,CACvB,KAAK,UAAW,OAAO,sBAAA,CACvB,KAAK,MAAA,CAAW,OAAO,aAAA,CACvB,QAAgB,OAAO,aAC3B,CACJ,EAEMC,CAAAA,CAAmBD,CAAAA,EAAoB,CACzC,OAAQA,CAAAA,EACJ,KAAK,SAAA,CAAW,OAAO,+CAAA,CACvB,KAAK,QAAW,OAAO,yCAAA,CACvB,KAAK,SAAA,CAAW,OAAO,+CAAA,CAEvB,QAAgB,OAAO,6BAC3B,CACJ,EAEO,SAASE,CAAAA,CAAMC,EAA+B,CACjD,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,UAAAC,CAAU,CAAA,CAAIF,EAC7B,OACIG,eAAAA,CAAC,OACG,SAAA,CAAW;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAA,EAKLF,CAAAA,CAAM,OAAA,CAAU,oBAAA,CAAuB,qDAAqD;AAAA,oBAAA,EAC5FH,CAAAA,CAAgBG,CAAAA,CAAM,IAAI,CAAC;AAAA,gBAAA,CAAA,CAGjC,UAAAG,cAAAA,CAACC,SAAAA,CAAA,CAAK,IAAA,CAAMT,EAAeK,CAAAA,CAAM,IAAI,CAAA,CAAe,IAAA,CAAM,GAAI,CAAA,CAC9DG,cAAAA,CAACE,SAAAA,CAAA,CAAK,KAAK,IAAA,CAAK,SAAA,CAAU,2BAAA,CACrB,QAAA,CAAAL,EAAM,OAAA,CACX,CAAA,CACAG,cAAAA,CAAC,QAAA,CAAA,CACG,QAAS,IAAMF,CAAAA,CAAUD,CAAAA,CAAM,EAAE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,IAAA,CAAMP,CAAAA,CACN,QAAA,CAACT,CAAAA,EACEG,eAACL,CAAAA,CAAA,CAAqB,KAAA,CAAOE,CAAAA,CAAO,UAAWC,CAAAA,CAAAA,CAAnCD,CAAAA,CAAM,EAAwC,CAAA,CAElE,CAAA,CACJ,EACJ,CAER","file":"index.cjs","sourcesContent":["// src/kit/toast.tsx\r\n//\r\n// Made with ❤️ by Maysara.\r\n\r\n\r\n\r\n// ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗\r\n\r\n import type { JSXElement } from '@minejs/jsx';\r\n import { For } from '@minejs/jsx';\r\n import { Overlay } from '@cruxkit/overlay';\r\n import { Icon, IconName } from '@cruxkit/icon';\r\n import { Text } from '@cruxkit/text';\r\n import { ToastContainerProps, ToastInstance, ToastProps, ToastType } from '../types';\r\n\r\n// ╚══════════════════════════════════════════════════════════════════════════════════════╝\r\n\r\n\r\n\r\n// ╔════════════════════════════════════════ CORE ════════════════════════════════════════╗\r\n\r\n const getIconForType = (type: ToastType) => {\r\n switch (type) {\r\n case 'success': return 'circle-check';\r\n case 'error': return 'circle-xmark';\r\n case 'warning': return 'triangle-exclamation';\r\n case 'info': return 'circle-info';\r\n default: return 'circle-info';\r\n }\r\n };\r\n\r\n const getColorForType = (type: ToastType) => {\r\n switch (type) {\r\n case 'success': return 'text-success bg-success-subtle border-success';\r\n case 'error': return 'text-error bg-error-subtle border-error';\r\n case 'warning': return 'text-warning bg-warning-subtle border-warning';\r\n // case 'info': return 'text-info bg-info-subtle border-brand';\r\n default: return 'text-2 bg-surface border-c2';\r\n }\r\n };\r\n\r\n export function Toast(props: ToastProps): JSXElement {\r\n const { toast, onDismiss } = props;\r\n return (\r\n <div\r\n className={`\r\n pointer-events-auto\r\n flex items-center gap-3 p-4 rounded-lg border shadow-lg\r\n w-full transform transition-all duration-300\r\n bg-surface\r\n ${toast.closing ? 'opacity-0 scale-95' : 'animate-in fade-in zoom-in-95 opacity-100 scale-100'}\r\n ${getColorForType(toast.type)}\r\n `}\r\n >\r\n <Icon name={getIconForType(toast.type) as IconName} size={20} />\r\n <Text size=\"sm\" className=\"flex-1 font-medium text-1\">\r\n {toast.message}\r\n </Text>\r\n <button\r\n onClick={() => onDismiss(toast.id)}\r\n className=\"p-1 hover:opacity-75 rounded transition-colors\"\r\n >\r\n <Icon name=\"x\" size={16} />\r\n </button>\r\n </div>\r\n );\r\n }\r\n\r\n export function ToastContainer(props: ToastContainerProps): JSXElement {\r\n let { position, className = '', toasts, onDismiss } = props;\r\n\r\n // Handle default position with RTL awareness\r\n if (!position) {\r\n const isRTL = typeof document !== 'undefined' && document.documentElement.dir === 'rtl';\r\n position = isRTL ? 'bottom-left' : 'bottom-right';\r\n }\r\n\r\n // Map position to Overlay position\r\n const overlayPositionMap: Record<string, any> = {\r\n 'top-right': 'top-right',\r\n 'top-left': 'top-left',\r\n 'bottom-right': 'bottom-right',\r\n 'bottom-left': 'bottom-left',\r\n 'top-center': 'top',\r\n 'bottom-center': 'bottom',\r\n };\r\n\r\n const overlayPosition = overlayPositionMap[position] || 'bottom-right';\r\n const isTop = position.includes('top');\r\n const isRight = position.includes('right');\r\n\r\n // Stack direction:\r\n // Top: Newest at top (reverse column) -> [Old, New] -> Reverse -> New, Old\r\n // Bottom: Newest at bottom (column) -> [Old, New] -> Old, New\r\n const stackClass = isTop ? 'flex-col-reverse' : 'flex-col';\r\n\r\n // Alignment\r\n const alignClass = position.includes('center') ? 'items-center' : (isRight ? 'items-end' : 'items-start');\r\n\r\n return (\r\n <Overlay\r\n position={overlayPosition}\r\n backdrop={false}\r\n zIndex={60} // Higher than default overlay\r\n className={`pointer-events-none p-4 ${className}`}\r\n >\r\n <div className={`flex ${stackClass} ${alignClass} gap-3 w-full max-w-sm pointer-events-none`}>\r\n <For each={toasts}>\r\n {(toast) => (\r\n <Toast key={toast.id} toast={toast} onDismiss={onDismiss} />\r\n )}\r\n </For>\r\n </div>\r\n </Overlay>\r\n );\r\n }\r\n\r\n// ╚══════════════════════════════════════════════════════════════════════════════════════╝\r\n"]}
@@ -0,0 +1,32 @@
1
+ import { Signal } from '@minejs/signals';
2
+ import { JSXElement } from '@minejs/jsx';
3
+
4
+ type ToastType = 'success' | 'error' | 'warning' | 'info';
5
+ interface ToastOptions {
6
+ type?: ToastType;
7
+ duration?: number;
8
+ onClose?: () => void;
9
+ }
10
+ interface ToastInstance extends ToastOptions {
11
+ id: string;
12
+ message: string;
13
+ type: ToastType;
14
+ duration: number;
15
+ closing?: boolean;
16
+ }
17
+ interface ToastProps {
18
+ key?: string;
19
+ toast: ToastInstance;
20
+ onDismiss: (id: string) => void;
21
+ }
22
+ interface ToastContainerProps {
23
+ position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
24
+ className?: string;
25
+ toasts: Signal<ToastInstance[]> | ToastInstance[];
26
+ onDismiss: (id: string) => void;
27
+ }
28
+
29
+ declare function Toast(props: ToastProps): JSXElement;
30
+ declare function ToastContainer(props: ToastContainerProps): JSXElement;
31
+
32
+ export { Toast, ToastContainer, type ToastContainerProps, type ToastInstance, type ToastOptions, type ToastProps, type ToastType };
@@ -0,0 +1,32 @@
1
+ import { Signal } from '@minejs/signals';
2
+ import { JSXElement } from '@minejs/jsx';
3
+
4
+ type ToastType = 'success' | 'error' | 'warning' | 'info';
5
+ interface ToastOptions {
6
+ type?: ToastType;
7
+ duration?: number;
8
+ onClose?: () => void;
9
+ }
10
+ interface ToastInstance extends ToastOptions {
11
+ id: string;
12
+ message: string;
13
+ type: ToastType;
14
+ duration: number;
15
+ closing?: boolean;
16
+ }
17
+ interface ToastProps {
18
+ key?: string;
19
+ toast: ToastInstance;
20
+ onDismiss: (id: string) => void;
21
+ }
22
+ interface ToastContainerProps {
23
+ position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
24
+ className?: string;
25
+ toasts: Signal<ToastInstance[]> | ToastInstance[];
26
+ onDismiss: (id: string) => void;
27
+ }
28
+
29
+ declare function Toast(props: ToastProps): JSXElement;
30
+ declare function ToastContainer(props: ToastContainerProps): JSXElement;
31
+
32
+ export { Toast, ToastContainer, type ToastContainerProps, type ToastInstance, type ToastOptions, type ToastProps, type ToastType };
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import {For}from'@minejs/jsx';import {Overlay}from'@cruxkit/overlay';import {Icon}from'@cruxkit/icon';import {Text}from'@cruxkit/text';import {jsxs,jsx}from'@minejs/jsx/jsx-runtime';var b=o=>{switch(o){case "success":return "circle-check";case "error":return "circle-xmark";case "warning":return "triangle-exclamation";case "info":return "circle-info";default:return "circle-info"}},x=o=>{switch(o){case "success":return "text-success bg-success-subtle border-success";case "error":return "text-error bg-error-subtle border-error";case "warning":return "text-warning bg-warning-subtle border-warning";default:return "text-2 bg-surface border-c2"}};function y(o){let{toast:t,onDismiss:r}=o;return jsxs("div",{className:`
2
+ pointer-events-auto
3
+ flex items-center gap-3 p-4 rounded-lg border shadow-lg
4
+ w-full transform transition-all duration-300
5
+ bg-surface
6
+ ${t.closing?"opacity-0 scale-95":"animate-in fade-in zoom-in-95 opacity-100 scale-100"}
7
+ ${x(t.type)}
8
+ `,children:[jsx(Icon,{name:b(t.type),size:20}),jsx(Text,{size:"sm",className:"flex-1 font-medium text-1",children:t.message}),jsx("button",{onClick:()=>r(t.id),className:"p-1 hover:opacity-75 rounded transition-colors",children:jsx(Icon,{name:"x",size:16})})]})}function k(o){let{position:t,className:r="",toasts:i,onDismiss:a}=o;t||(t=typeof document<"u"&&document.documentElement.dir==="rtl"?"bottom-left":"bottom-right");let c={"top-right":"top-right","top-left":"top-left","bottom-right":"bottom-right","bottom-left":"bottom-left","top-center":"top","bottom-center":"bottom"}[t]||"bottom-right",l=t.includes("top"),m=t.includes("right"),p=l?"flex-col-reverse":"flex-col",u=t.includes("center")?"items-center":m?"items-end":"items-start";return jsx(Overlay,{position:c,backdrop:false,zIndex:60,className:`pointer-events-none p-4 ${r}`,children:jsx("div",{className:`flex ${p} ${u} gap-3 w-full max-w-sm pointer-events-none`,children:jsx(For,{each:i,children:s=>jsx(y,{toast:s,onDismiss:a},s.id)})})})}export{y as Toast,k as ToastContainer};//# sourceMappingURL=index.js.map
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/kit/toast.tsx"],"names":["getIconForType","type","getColorForType","Toast","props","toast","onDismiss","jsxs","jsx","Icon","Text","ToastContainer","position","className","toasts","overlayPosition","isTop","isRight","stackClass","alignClass","Overlay","For"],"mappings":"sLAqBI,IAAMA,EAAkBC,CAAAA,EAAoB,CACxC,OAAQA,CAAAA,EACJ,KAAK,SAAA,CAAW,OAAO,eACvB,KAAK,OAAA,CAAW,OAAO,cAAA,CACvB,KAAK,UAAW,OAAO,sBAAA,CACvB,KAAK,MAAA,CAAW,OAAO,aAAA,CACvB,QAAgB,OAAO,aAC3B,CACJ,EAEMC,CAAAA,CAAmBD,CAAAA,EAAoB,CACzC,OAAQA,CAAAA,EACJ,KAAK,SAAA,CAAW,OAAO,+CAAA,CACvB,KAAK,QAAW,OAAO,yCAAA,CACvB,KAAK,SAAA,CAAW,OAAO,+CAAA,CAEvB,QAAgB,OAAO,6BAC3B,CACJ,EAEO,SAASE,CAAAA,CAAMC,EAA+B,CACjD,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,UAAAC,CAAU,CAAA,CAAIF,EAC7B,OACIG,IAAAA,CAAC,OACG,SAAA,CAAW;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAA,EAKLF,CAAAA,CAAM,OAAA,CAAU,oBAAA,CAAuB,qDAAqD;AAAA,oBAAA,EAC5FH,CAAAA,CAAgBG,CAAAA,CAAM,IAAI,CAAC;AAAA,gBAAA,CAAA,CAGjC,UAAAG,GAAAA,CAACC,IAAAA,CAAA,CAAK,IAAA,CAAMT,EAAeK,CAAAA,CAAM,IAAI,CAAA,CAAe,IAAA,CAAM,GAAI,CAAA,CAC9DG,GAAAA,CAACE,IAAAA,CAAA,CAAK,K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CAAAL,GAAAA,CAAC,OAAI,SAAA,CAAW,CAAA,KAAA,EAAQU,CAAU,CAAA,CAAA,EAAIC,CAAU,CAAA,0CAAA,CAAA,CAC5C,QAAA,CAAAX,GAAAA,CAACa,GAAAA,CAAA,CAAI,IAAA,CAAMP,CAAAA,CACN,QAAA,CAACT,CAAAA,EACEG,IAACL,CAAAA,CAAA,CAAqB,KAAA,CAAOE,CAAAA,CAAO,UAAWC,CAAAA,CAAAA,CAAnCD,CAAAA,CAAM,EAAwC,CAAA,CAElE,CAAA,CACJ,EACJ,CAER","file":"index.js","sourcesContent":["// src/kit/toast.tsx\r\n//\r\n// Made with ❤️ by Maysara.\r\n\r\n\r\n\r\n// ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗\r\n\r\n import type { JSXElement } from '@minejs/jsx';\r\n import { For } from '@minejs/jsx';\r\n import { Overlay } from '@cruxkit/overlay';\r\n import { Icon, IconName } from '@cruxkit/icon';\r\n import { Text } from '@cruxkit/text';\r\n import { ToastContainerProps, ToastInstance, ToastProps, ToastType } from '../types';\r\n\r\n// ╚══════════════════════════════════════════════════════════════════════════════════════╝\r\n\r\n\r\n\r\n// ╔════════════════════════════════════════ CORE ════════════════════════════════════════╗\r\n\r\n const getIconForType = (type: ToastType) => {\r\n switch (type) {\r\n case 'success': return 'circle-check';\r\n case 'error': return 'circle-xmark';\r\n case 'warning': return 'triangle-exclamation';\r\n case 'info': return 'circle-info';\r\n default: return 'circle-info';\r\n }\r\n };\r\n\r\n const getColorForType = (type: ToastType) => {\r\n switch (type) {\r\n case 'success': return 'text-success bg-success-subtle border-success';\r\n case 'error': return 'text-error bg-error-subtle border-error';\r\n case 'warning': return 'text-warning bg-warning-subtle border-warning';\r\n // case 'info': return 'text-info bg-info-subtle border-brand';\r\n default: return 'text-2 bg-surface border-c2';\r\n }\r\n };\r\n\r\n export function Toast(props: ToastProps): JSXElement {\r\n const { toast, onDismiss } = props;\r\n return (\r\n <div\r\n className={`\r\n pointer-events-auto\r\n flex items-center gap-3 p-4 rounded-lg border shadow-lg\r\n w-full transform transition-all duration-300\r\n bg-surface\r\n ${toast.closing ? 'opacity-0 scale-95' : 'animate-in fade-in zoom-in-95 opacity-100 scale-100'}\r\n ${getColorForType(toast.type)}\r\n `}\r\n >\r\n <Icon name={getIconForType(toast.type) as IconName} size={20} />\r\n <Text size=\"sm\" className=\"flex-1 font-medium text-1\">\r\n {toast.message}\r\n </Text>\r\n <button\r\n onClick={() => onDismiss(toast.id)}\r\n className=\"p-1 hover:opacity-75 rounded transition-colors\"\r\n >\r\n <Icon name=\"x\" size={16} />\r\n </button>\r\n </div>\r\n );\r\n }\r\n\r\n export function ToastContainer(props: ToastContainerProps): JSXElement {\r\n let { position, className = '', toasts, onDismiss } = props;\r\n\r\n // Handle default position with RTL awareness\r\n if (!position) {\r\n const isRTL = typeof document !== 'undefined' && document.documentElement.dir === 'rtl';\r\n position = isRTL ? 'bottom-left' : 'bottom-right';\r\n }\r\n\r\n // Map position to Overlay position\r\n const overlayPositionMap: Record<string, any> = {\r\n 'top-right': 'top-right',\r\n 'top-left': 'top-left',\r\n 'bottom-right': 'bottom-right',\r\n 'bottom-left': 'bottom-left',\r\n 'top-center': 'top',\r\n 'bottom-center': 'bottom',\r\n };\r\n\r\n const overlayPosition = overlayPositionMap[position] || 'bottom-right';\r\n const isTop = position.includes('top');\r\n const isRight = position.includes('right');\r\n\r\n // Stack direction:\r\n // Top: Newest at top (reverse column) -> [Old, New] -> Reverse -> New, Old\r\n // Bottom: Newest at bottom (column) -> [Old, New] -> Old, New\r\n const stackClass = isTop ? 'flex-col-reverse' : 'flex-col';\r\n\r\n // Alignment\r\n const alignClass = position.includes('center') ? 'items-center' : (isRight ? 'items-end' : 'items-start');\r\n\r\n return (\r\n <Overlay\r\n position={overlayPosition}\r\n backdrop={false}\r\n zIndex={60} // Higher than default overlay\r\n className={`pointer-events-none p-4 ${className}`}\r\n >\r\n <div className={`flex ${stackClass} ${alignClass} gap-3 w-full max-w-sm pointer-events-none`}>\r\n <For each={toasts}>\r\n {(toast) => (\r\n <Toast key={toast.id} toast={toast} onDismiss={onDismiss} />\r\n )}\r\n </For>\r\n </div>\r\n </Overlay>\r\n );\r\n }\r\n\r\n// ╚══════════════════════════════════════════════════════════════════════════════════════╝\r\n"]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@cruxkit/toast",
3
+ "version": "0.0.1",
4
+ "description": "A lightweight, reactive toast kit, built for @cruxjs ecosystem.",
5
+ "keywords": ["crux", "kit", "toast"],
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/cruxkit-org/toast#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/cruxkit-org/toast/issues"
10
+ },
11
+ "author": {
12
+ "name": "Maysara",
13
+ "email": "maysara.elshewehy@gmail.com",
14
+ "url": "https://github.com/maysara-elshewehy"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/cruxkit-org/toast.git"
19
+ },
20
+ "type": "module",
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "files": ["dist"],
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.js"
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "tsup",
33
+ "lint": "eslint src --ext .ts",
34
+ "test": "bun test"
35
+ },
36
+ "engines": {
37
+ "bun": ">=1.3.3"
38
+ },
39
+ "peerDependencies": {
40
+ "bun": "^1.3.3"
41
+ },
42
+ "dependencies": {
43
+ "@cruxkit/icon": "^0.1.1",
44
+ "@cruxkit/overlay": "^0.0.9",
45
+ "@cruxkit/text": "^0.0.2",
46
+ "@minejs/jsx": "^0.1.8",
47
+ "@minejs/signals": "^0.0.6"
48
+ },
49
+ "devDependencies": {
50
+ "@eslint/js": "^9.39.2",
51
+ "@stylistic/eslint-plugin": "^5.7.1",
52
+ "@types/bun": "^1.3.6",
53
+ "@types/jsdom": "^27.0.0",
54
+ "@types/node": "^20.19.30",
55
+ "@types/react": "^19.2.9",
56
+ "bun-plugin-dts": "^0.3.0",
57
+ "bun-types": "^1.3.6",
58
+ "jsdom": "^27.4.0",
59
+ "ts-node": "^10.9.2",
60
+ "tsup": "^8.5.1",
61
+ "typescript": "^5.9.3",
62
+ "typescript-eslint": "^8.53.1"
63
+ }
64
+ }