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