@ataraui/ataraui-react 0.4.0 → 0.5.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.
- package/README.md +201 -96
- package/dist/index.d.mts +67 -1
- package/dist/index.d.ts +67 -1
- package/dist/index.js +294 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +283 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1110,7 +1110,289 @@ var Popover = ({
|
|
|
1110
1110
|
] });
|
|
1111
1111
|
};
|
|
1112
1112
|
Popover.displayName = "Popover";
|
|
1113
|
+
var ToastContext = React13.createContext(null);
|
|
1114
|
+
var counter = 0;
|
|
1115
|
+
var genId = () => `toast-${++counter}`;
|
|
1116
|
+
var ToastProvider = ({ children }) => {
|
|
1117
|
+
const [toasts, setToasts] = React13.useState([]);
|
|
1118
|
+
const toast = React13.useCallback((input) => {
|
|
1119
|
+
const id = genId();
|
|
1120
|
+
setToasts((prev) => [...prev, { ...input, id }]);
|
|
1121
|
+
return id;
|
|
1122
|
+
}, []);
|
|
1123
|
+
const dismiss = React13.useCallback((id) => {
|
|
1124
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
1125
|
+
}, []);
|
|
1126
|
+
const dismissAll = React13.useCallback(() => {
|
|
1127
|
+
setToasts([]);
|
|
1128
|
+
}, []);
|
|
1129
|
+
return /* @__PURE__ */ jsx(ToastContext.Provider, { value: { toasts, toast, dismiss, dismissAll }, children });
|
|
1130
|
+
};
|
|
1131
|
+
var useToast = () => {
|
|
1132
|
+
const ctx = React13.useContext(ToastContext);
|
|
1133
|
+
if (!ctx) throw new Error("useToast must be used within a ToastProvider");
|
|
1134
|
+
return ctx;
|
|
1135
|
+
};
|
|
1136
|
+
var toastVariants = cva(
|
|
1137
|
+
"pointer-events-auto relative flex w-80 max-w-[calc(100vw-2rem)] items-start gap-3 overflow-hidden rounded-(--radius-lg) border p-4 pr-8 shadow-lg",
|
|
1138
|
+
{
|
|
1139
|
+
variants: {
|
|
1140
|
+
variant: {
|
|
1141
|
+
default: "border-(--color-neutral-200) bg-white text-(--color-neutral-800)",
|
|
1142
|
+
success: "border-green-200 bg-green-50 text-green-900",
|
|
1143
|
+
warning: "border-yellow-200 bg-yellow-50 text-yellow-900",
|
|
1144
|
+
destructive: "border-red-200 bg-red-50 text-red-900"
|
|
1145
|
+
}
|
|
1146
|
+
},
|
|
1147
|
+
defaultVariants: { variant: "default" }
|
|
1148
|
+
}
|
|
1149
|
+
);
|
|
1150
|
+
var positionClasses = {
|
|
1151
|
+
"top-left": "top-4 left-4 items-start",
|
|
1152
|
+
"top-center": "top-4 left-1/2 -translate-x-1/2 items-center",
|
|
1153
|
+
"top-right": "top-4 right-4 items-end",
|
|
1154
|
+
"bottom-left": "bottom-4 left-4 items-start",
|
|
1155
|
+
"bottom-center": "bottom-4 left-1/2 -translate-x-1/2 items-center",
|
|
1156
|
+
"bottom-right": "bottom-4 right-4 items-end"
|
|
1157
|
+
};
|
|
1158
|
+
var SingleToast = ({ toast, onDismiss, defaultDuration }) => {
|
|
1159
|
+
var _a, _b;
|
|
1160
|
+
const duration = (_a = toast.duration) != null ? _a : defaultDuration;
|
|
1161
|
+
React13.useEffect(() => {
|
|
1162
|
+
if (duration <= 0) return;
|
|
1163
|
+
const timer = setTimeout(() => onDismiss(toast.id), duration);
|
|
1164
|
+
return () => clearTimeout(timer);
|
|
1165
|
+
}, [duration, onDismiss, toast.id]);
|
|
1166
|
+
return /* @__PURE__ */ jsxs(
|
|
1167
|
+
"div",
|
|
1168
|
+
{
|
|
1169
|
+
role: "status",
|
|
1170
|
+
"aria-live": "polite",
|
|
1171
|
+
className: toastVariants({ variant: (_b = toast.variant) != null ? _b : "default" }),
|
|
1172
|
+
children: [
|
|
1173
|
+
toast.icon && /* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0 [&>svg]:size-4", children: toast.icon }),
|
|
1174
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-1", children: [
|
|
1175
|
+
toast.title && /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold leading-none", children: toast.title }),
|
|
1176
|
+
toast.description && /* @__PURE__ */ jsx("p", { className: "text-xs opacity-80", children: toast.description }),
|
|
1177
|
+
toast.action && /* @__PURE__ */ jsx(
|
|
1178
|
+
"button",
|
|
1179
|
+
{
|
|
1180
|
+
type: "button",
|
|
1181
|
+
onClick: () => {
|
|
1182
|
+
toast.action.onClick();
|
|
1183
|
+
onDismiss(toast.id);
|
|
1184
|
+
},
|
|
1185
|
+
className: "mt-1.5 text-xs font-medium underline underline-offset-2 hover:no-underline focus:outline-none",
|
|
1186
|
+
children: toast.action.label
|
|
1187
|
+
}
|
|
1188
|
+
)
|
|
1189
|
+
] }),
|
|
1190
|
+
/* @__PURE__ */ jsx(
|
|
1191
|
+
"button",
|
|
1192
|
+
{
|
|
1193
|
+
type: "button",
|
|
1194
|
+
"aria-label": "Dismiss",
|
|
1195
|
+
onClick: () => onDismiss(toast.id),
|
|
1196
|
+
className: "absolute right-2 top-2 rounded opacity-50 transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-(--color-primary-500)",
|
|
1197
|
+
children: /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
1198
|
+
/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }),
|
|
1199
|
+
/* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })
|
|
1200
|
+
] })
|
|
1201
|
+
}
|
|
1202
|
+
)
|
|
1203
|
+
]
|
|
1204
|
+
}
|
|
1205
|
+
);
|
|
1206
|
+
};
|
|
1207
|
+
var Toaster = ({
|
|
1208
|
+
position = "bottom-right",
|
|
1209
|
+
defaultDuration = 4e3,
|
|
1210
|
+
className
|
|
1211
|
+
}) => {
|
|
1212
|
+
const { toasts, dismiss } = useToast();
|
|
1213
|
+
const [mounted, setMounted] = React13.useState(false);
|
|
1214
|
+
React13.useEffect(() => {
|
|
1215
|
+
setMounted(true);
|
|
1216
|
+
}, []);
|
|
1217
|
+
if (!mounted) return null;
|
|
1218
|
+
return createPortal(
|
|
1219
|
+
/* @__PURE__ */ jsx(
|
|
1220
|
+
"div",
|
|
1221
|
+
{
|
|
1222
|
+
"aria-label": "Notifications",
|
|
1223
|
+
className: cn(
|
|
1224
|
+
"fixed z-[100] flex flex-col gap-2 pointer-events-none",
|
|
1225
|
+
positionClasses[position],
|
|
1226
|
+
className
|
|
1227
|
+
),
|
|
1228
|
+
children: toasts.map((t) => /* @__PURE__ */ jsx(
|
|
1229
|
+
SingleToast,
|
|
1230
|
+
{
|
|
1231
|
+
toast: t,
|
|
1232
|
+
onDismiss: dismiss,
|
|
1233
|
+
defaultDuration
|
|
1234
|
+
},
|
|
1235
|
+
t.id
|
|
1236
|
+
))
|
|
1237
|
+
}
|
|
1238
|
+
),
|
|
1239
|
+
document.body
|
|
1240
|
+
);
|
|
1241
|
+
};
|
|
1242
|
+
Toaster.displayName = "Toaster";
|
|
1243
|
+
ToastProvider.displayName = "ToastProvider";
|
|
1244
|
+
var alertVariants = cva(
|
|
1245
|
+
"relative flex w-full gap-3 rounded-(--radius-lg) border p-4 text-sm",
|
|
1246
|
+
{
|
|
1247
|
+
variants: {
|
|
1248
|
+
variant: {
|
|
1249
|
+
default: "border-(--color-neutral-200) bg-(--color-neutral-50) text-(--color-neutral-700)",
|
|
1250
|
+
success: "border-green-200 bg-green-50 text-green-800",
|
|
1251
|
+
warning: "border-yellow-200 bg-yellow-50 text-yellow-800",
|
|
1252
|
+
destructive: "border-red-200 bg-red-50 text-red-800"
|
|
1253
|
+
}
|
|
1254
|
+
},
|
|
1255
|
+
defaultVariants: { variant: "default" }
|
|
1256
|
+
}
|
|
1257
|
+
);
|
|
1258
|
+
var Alert = ({
|
|
1259
|
+
variant,
|
|
1260
|
+
icon,
|
|
1261
|
+
onClose,
|
|
1262
|
+
className,
|
|
1263
|
+
children,
|
|
1264
|
+
...props
|
|
1265
|
+
}) => {
|
|
1266
|
+
return /* @__PURE__ */ jsxs(
|
|
1267
|
+
"div",
|
|
1268
|
+
{
|
|
1269
|
+
role: "alert",
|
|
1270
|
+
className: cn(alertVariants({ variant }), className),
|
|
1271
|
+
...props,
|
|
1272
|
+
children: [
|
|
1273
|
+
icon && /* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0 [&>svg]:size-4", children: icon }),
|
|
1274
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1", children }),
|
|
1275
|
+
onClose && /* @__PURE__ */ jsx(
|
|
1276
|
+
"button",
|
|
1277
|
+
{
|
|
1278
|
+
type: "button",
|
|
1279
|
+
"aria-label": "Dismiss",
|
|
1280
|
+
onClick: onClose,
|
|
1281
|
+
className: "ml-auto shrink-0 self-start rounded opacity-60 transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-(--color-primary-500)",
|
|
1282
|
+
children: /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
1283
|
+
/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }),
|
|
1284
|
+
/* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })
|
|
1285
|
+
] })
|
|
1286
|
+
}
|
|
1287
|
+
)
|
|
1288
|
+
]
|
|
1289
|
+
}
|
|
1290
|
+
);
|
|
1291
|
+
};
|
|
1292
|
+
Alert.displayName = "Alert";
|
|
1293
|
+
var AlertTitle = ({
|
|
1294
|
+
className,
|
|
1295
|
+
children,
|
|
1296
|
+
...props
|
|
1297
|
+
}) => /* @__PURE__ */ jsx("p", { className: cn("font-semibold leading-none tracking-tight", className), ...props, children });
|
|
1298
|
+
AlertTitle.displayName = "AlertTitle";
|
|
1299
|
+
var AlertDescription = ({
|
|
1300
|
+
className,
|
|
1301
|
+
children,
|
|
1302
|
+
...props
|
|
1303
|
+
}) => /* @__PURE__ */ jsx("p", { className: cn("mt-1 text-[0.8rem] opacity-80", className), ...props, children });
|
|
1304
|
+
AlertDescription.displayName = "AlertDescription";
|
|
1305
|
+
var progressVariants = cva(
|
|
1306
|
+
"w-full overflow-hidden rounded-full bg-(--color-neutral-200)",
|
|
1307
|
+
{
|
|
1308
|
+
variants: {
|
|
1309
|
+
size: {
|
|
1310
|
+
sm: "h-1",
|
|
1311
|
+
md: "h-2",
|
|
1312
|
+
lg: "h-3"
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
defaultVariants: { size: "md" }
|
|
1316
|
+
}
|
|
1317
|
+
);
|
|
1318
|
+
var Progress = ({
|
|
1319
|
+
value,
|
|
1320
|
+
size,
|
|
1321
|
+
label,
|
|
1322
|
+
showLabel = false,
|
|
1323
|
+
className,
|
|
1324
|
+
...props
|
|
1325
|
+
}) => {
|
|
1326
|
+
const isIndeterminate = value === void 0 || value === null;
|
|
1327
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full", children: [
|
|
1328
|
+
(label || showLabel) && /* @__PURE__ */ jsxs("div", { className: "mb-1.5 flex items-center justify-between text-xs text-(--color-neutral-600)", children: [
|
|
1329
|
+
label && /* @__PURE__ */ jsx("span", { children: label }),
|
|
1330
|
+
showLabel && !isIndeterminate && /* @__PURE__ */ jsxs("span", { className: "ml-auto font-medium", children: [
|
|
1331
|
+
Math.round(value),
|
|
1332
|
+
"%"
|
|
1333
|
+
] })
|
|
1334
|
+
] }),
|
|
1335
|
+
/* @__PURE__ */ jsx(
|
|
1336
|
+
"div",
|
|
1337
|
+
{
|
|
1338
|
+
role: "progressbar",
|
|
1339
|
+
"aria-valuemin": 0,
|
|
1340
|
+
"aria-valuemax": 100,
|
|
1341
|
+
"aria-valuenow": isIndeterminate ? void 0 : value,
|
|
1342
|
+
className: cn(progressVariants({ size }), className),
|
|
1343
|
+
...props,
|
|
1344
|
+
children: /* @__PURE__ */ jsx(
|
|
1345
|
+
"div",
|
|
1346
|
+
{
|
|
1347
|
+
className: cn(
|
|
1348
|
+
"h-full rounded-full bg-(--color-primary-500) transition-all duration-300 ease-in-out",
|
|
1349
|
+
isIndeterminate && "w-1/3 animate-[indeterminate_1.5s_ease-in-out_infinite]"
|
|
1350
|
+
),
|
|
1351
|
+
style: isIndeterminate ? void 0 : { width: `${Math.min(100, Math.max(0, value))}%` }
|
|
1352
|
+
}
|
|
1353
|
+
)
|
|
1354
|
+
}
|
|
1355
|
+
)
|
|
1356
|
+
] });
|
|
1357
|
+
};
|
|
1358
|
+
Progress.displayName = "Progress";
|
|
1359
|
+
var skeletonVariants = cva(
|
|
1360
|
+
"animate-pulse bg-(--color-neutral-200)",
|
|
1361
|
+
{
|
|
1362
|
+
variants: {
|
|
1363
|
+
variant: {
|
|
1364
|
+
text: "h-4 w-full rounded",
|
|
1365
|
+
circle: "rounded-full",
|
|
1366
|
+
rect: "rounded-(--radius-md)"
|
|
1367
|
+
}
|
|
1368
|
+
},
|
|
1369
|
+
defaultVariants: { variant: "rect" }
|
|
1370
|
+
}
|
|
1371
|
+
);
|
|
1372
|
+
var Skeleton = ({
|
|
1373
|
+
variant,
|
|
1374
|
+
width,
|
|
1375
|
+
height,
|
|
1376
|
+
className,
|
|
1377
|
+
style,
|
|
1378
|
+
...props
|
|
1379
|
+
}) => {
|
|
1380
|
+
return /* @__PURE__ */ jsx(
|
|
1381
|
+
"div",
|
|
1382
|
+
{
|
|
1383
|
+
"aria-hidden": "true",
|
|
1384
|
+
className: cn(skeletonVariants({ variant }), className),
|
|
1385
|
+
style: {
|
|
1386
|
+
width: typeof width === "number" ? `${width}px` : width,
|
|
1387
|
+
height: typeof height === "number" ? `${height}px` : height,
|
|
1388
|
+
...style
|
|
1389
|
+
},
|
|
1390
|
+
...props
|
|
1391
|
+
}
|
|
1392
|
+
);
|
|
1393
|
+
};
|
|
1394
|
+
Skeleton.displayName = "Skeleton";
|
|
1113
1395
|
|
|
1114
|
-
export { Avatar, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Drawer, DrawerBody, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, Input, Modal, ModalBody, ModalDescription, ModalFooter, ModalHeader, ModalTitle, Popover, RadioGroup, Select, Separator, Spinner, Switch, Tooltip, avatarVariants, badgeVariants, buttonVariants, cardVariants, cn, colors, drawerVariants, fontSize, inputVariants, modalVariants, radius, selectVariants, separatorVariants, spinnerVariants };
|
|
1396
|
+
export { Alert, AlertDescription, AlertTitle, Avatar, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Drawer, DrawerBody, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, Input, Modal, ModalBody, ModalDescription, ModalFooter, ModalHeader, ModalTitle, Popover, Progress, RadioGroup, Select, Separator, Skeleton, Spinner, Switch, ToastProvider, Toaster, Tooltip, alertVariants, avatarVariants, badgeVariants, buttonVariants, cardVariants, cn, colors, drawerVariants, fontSize, inputVariants, modalVariants, progressVariants, radius, selectVariants, separatorVariants, skeletonVariants, spinnerVariants, toastVariants, useToast };
|
|
1115
1397
|
//# sourceMappingURL=index.mjs.map
|
|
1116
1398
|
//# sourceMappingURL=index.mjs.map
|