c4cui
Version:
Highly customizable elegant react components
1,061 lines • 54.8 kB
JavaScript
// src/Button/Index.tsx
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _array_without_holes(arr) {
if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _iterable_to_array(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _non_iterable_spread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _to_consumable_array(arr) {
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _ts_generator(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
import classNames from "classnames";
import { twMerge } from "tailwind-merge";
import React from "react";
var Button = function(param) {
var icon = param.icon, label = param.label, onClick = param.onClick, _param_disabled = param.disabled, disabled = _param_disabled === void 0 ? false : _param_disabled, _param_outline = param.outline, outline = _param_outline === void 0 ? false : _param_outline, _param_className = param.className, className = _param_className === void 0 ? "" : _param_className, type = param.type, active = param.active;
return /* @__PURE__ */ React.createElement("button", {
type: type === "submit" ? "submit" : type === "reset" ? "reset" : "button",
onClick: function(e) {
e.stopPropagation();
onClick && onClick();
},
className: twMerge(classNames("p-2 rounded-xl whitespace-nowrap flex items-center gap-2 transition-all justify-center hover:scale-95 bg-[var(--primary-color)] text-[var(--background-color)]", {
"px-3 md:p-3 md:px-4": label && icon || label,
"border border-[var(--primary-color)] bg-transparent text-[var(--primary-color)] hover:bg-[var(--primary-color)] hover:text-[var(--background-color)]": outline,
"bg-[var(--primary-color)] text-[var(--background-color)]": active,
"cursor-not-allowed opacity-70 hover:scale-100": disabled
}, className)),
disabled: disabled
}, icon, label);
};
// src/Input/Index.tsx
import React3, { useState as useState2 } from "react";
import { PiEye, PiEyeClosed, PiMagnifyingGlass } from "react-icons/pi";
import { BiCopy } from "react-icons/bi";
// src/utils.ts
var passwordGenerator = function(param) {
var _param_length = param.length, length = _param_length === void 0 ? 12 : _param_length, _param_includeNumbers = param.includeNumbers, includeNumbers = _param_includeNumbers === void 0 ? true : _param_includeNumbers, _param_includeSymbols = param.includeSymbols, includeSymbols = _param_includeSymbols === void 0 ? true : _param_includeSymbols, _param_excludeSimilarCharacters = param.excludeSimilarCharacters, excludeSimilarCharacters = _param_excludeSimilarCharacters === void 0 ? false : _param_excludeSimilarCharacters;
var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var numbers = "0123456789";
var symbols = "!@#$%^&*()_+-=[]{}|;:,.<>?";
var similarCharacters = "O0Il1";
var characters = letters;
if (includeNumbers) characters += numbers;
if (includeSymbols) characters += symbols;
if (excludeSimilarCharacters) {
characters = characters.split("").filter(function(char) {
return !similarCharacters.includes(char);
}).join("");
}
if (characters.length === 0) {
throw new Error("No valid characters available to generate password.");
}
var generatedPassword = "";
for(var i = 0; i < length; i++){
var randomIndex = Math.floor(Math.random() * characters.length);
generatedPassword += characters[randomIndex];
}
return generatedPassword;
};
// src/Input/Index.tsx
import classNames2 from "classnames";
import { twMerge as twMerge2 } from "tailwind-merge";
// src/Toast/Index.tsx
import React2, { useState, useEffect } from "react";
import { MdClose } from "react-icons/md";
import { PiCheckCircle, PiInfo, PiWarning, PiXCircle } from "react-icons/pi";
var addToastToContainer = null;
var toast = {
success: function(message) {
return addToastToContainer === null || addToastToContainer === void 0 ? void 0 : addToastToContainer({
id: generateId(),
message: message,
type: "success"
});
},
error: function(message) {
return addToastToContainer === null || addToastToContainer === void 0 ? void 0 : addToastToContainer({
id: generateId(),
message: message,
type: "error"
});
},
info: function(message) {
return addToastToContainer === null || addToastToContainer === void 0 ? void 0 : addToastToContainer({
id: generateId(),
message: message,
type: "info"
});
},
warning: function(message) {
return addToastToContainer === null || addToastToContainer === void 0 ? void 0 : addToastToContainer({
id: generateId(),
message: message,
type: "warning"
});
}
};
var generateId = function() {
return Math.random().toString(36).substring(7);
};
var ToastContainer = function() {
var _useState = _sliced_to_array(useState([]), 2), toasts = _useState[0], setToasts = _useState[1];
useEffect(function() {
addToastToContainer = function(newToast) {
setToasts(function(prev) {
return _to_consumable_array(prev).concat([
newToast
]);
});
};
}, []);
useEffect(function() {
if (toasts.length > 0) {
var timeout = setTimeout(function() {
setToasts(function(prev) {
return prev.slice(1);
});
}, 5e3);
return function() {
return clearTimeout(timeout);
};
}
}, [
toasts
]);
var removeToast = function(id) {
setToasts(function(prev) {
return prev.filter(function(toast2) {
return toast2.id !== id;
});
});
};
return /* @__PURE__ */ React2.createElement("div", {
className: "fixed z-40 right-2 top-2 flex flex-col w-auto gap-2"
}, toasts.map(function(toast2) {
return /* @__PURE__ */ React2.createElement("div", {
key: toast2.id,
className: "flex gap-2 w-auto items-center p-2 rounded-lg shadow-md transition-opacity duration-300 ".concat(toast2.type === "success" ? "text-green-500 bg-green-50" : toast2.type === "error" ? "text-red-500 bg-red-50" : toast2.type === "info" ? "text-blue-500 bg-blue-50" : toast2.type === "warning" ? "text-yellow-500 bg-yellow-50" : "")
}, toast2.type === "success" ? /* @__PURE__ */ React2.createElement(PiCheckCircle, {
size: 18
}) : toast2.type === "error" ? /* @__PURE__ */ React2.createElement(PiXCircle, {
size: 18
}) : toast2.type === "info" ? /* @__PURE__ */ React2.createElement(PiInfo, {
size: 18
}) : toast2.type === "warning" ? /* @__PURE__ */ React2.createElement(PiWarning, {
size: 18
}) : null, /* @__PURE__ */ React2.createElement("p", {
className: "flex w-fit"
}, toast2.message), /* @__PURE__ */ React2.createElement(Button, {
outline: true,
className: "border-none rounded-full p-2",
icon: /* @__PURE__ */ React2.createElement(MdClose, {
size: 18
}),
onClick: function() {
return removeToast(toast2.id);
}
}));
}));
};
// src/Input/Index.tsx
var InputComponent = function(param) {
var label = param.label, name = param.name, type = param.type, labelClasses = param.labelClasses, readOnly = param.readOnly, value = param.value, onChange = param.onChange, _param_inputClasses = param.inputClasses, inputClasses = _param_inputClasses === void 0 ? "" : _param_inputClasses, placeholder = param.placeholder, options = param.options, defaultValue = param.defaultValue, _param_required = param.required, required = _param_required === void 0 ? true : _param_required, maxLength = param.maxLength, minLength = param.minLength, maxNumber = param.maxNumber, minNumber = param.minNumber, copyPassword = param.copyPassword, generatePassword = param.generatePassword, rows = param.rows, suggestions = param.suggestions, onKeyDown = param.onKeyDown, multiple = param.multiple, step = param.step, onSearch = param.onSearch, error = param.error;
var _useState2 = _sliced_to_array(useState2(false), 2), passwordVisible = _useState2[0], setPasswordVisible = _useState2[1];
var _useState21 = _sliced_to_array(useState2(false), 2), isFocused = _useState21[0], setIsFocused = _useState21[1];
var _useState22 = _sliced_to_array(useState2(false), 2), isHoveringSuggestions = _useState22[0], setIsHoveringSuggestions = _useState22[1];
return /* @__PURE__ */ React3.createElement("div", {
className: "flex flex-col items-start w-full gap-4 relative"
}, label && /* @__PURE__ */ React3.createElement("label", {
className: classNames2(labelClasses)
}, label), type === "textarea" ? /* @__PURE__ */ React3.createElement("textarea", {
name: name,
value: value,
onChange: function(e) {
return onChange && onChange(e.target.value);
},
maxLength: maxLength,
minLength: minLength,
readOnly: readOnly,
placeholder: placeholder,
defaultValue: defaultValue,
required: required,
rows: rows || 4,
className: twMerge2(classNames2("w-full p-2 md:p-3 border border-[var(--border-color)] bg-transparent rounded-xl placeholder:text-[var(--placeholder-color)]", inputClasses))
}) : type === "select" ? /* @__PURE__ */ React3.createElement("select", {
onChange: function(e) {
return onChange && onChange(e.target.value);
},
className: twMerge2(classNames2("w-full p-2 md:p-3 border border-[var(--border-color)] bg-transparent rounded-xl placeholder:text-[var(--placeholder-color)]", inputClasses)),
name: name,
disabled: readOnly,
required: required,
"aria-placeholder": placeholder,
value: value || ""
}, /* @__PURE__ */ React3.createElement("option", {
disabled: true,
value: ""
}, "SELECT"), options === null || options === void 0 ? void 0 : options.map(function(option) {
return /* @__PURE__ */ React3.createElement("option", {
key: option.id,
value: option.id,
disabled: option.disabled
}, option.value || option.id);
})) : /* @__PURE__ */ React3.createElement("div", {
className: classNames2(type !== "checkbox" && "w-full", "flex flex-col md:flex-row items-center gap-2")
}, /* @__PURE__ */ React3.createElement("div", {
className: classNames2(type !== "checkbox" && "w-full", "flex items-center gap-2 relative")
}, type === "search" && /* @__PURE__ */ React3.createElement("div", {
className: "flex gap-2 items-center absolute left-2 top-0 bottom-0"
}, /* @__PURE__ */ React3.createElement(Button, {
onClick: onSearch,
className: "p-2 hover:opacity-70 border-none rounded-xl-full",
outline: true,
icon: /* @__PURE__ */ React3.createElement(PiMagnifyingGlass, {
size: 18
})
})), /* @__PURE__ */ React3.createElement("input", {
type: type === "number" || passwordVisible ? "text" : type,
multiple: multiple,
name: name,
value: value,
step: step,
min: minNumber,
max: maxNumber,
required: required,
maxLength: maxLength,
minLength: !minLength && type === "password" ? 5 : minLength,
onKeyDown: onKeyDown,
onChange: function(e) {
return onChange && onChange(e.target.value);
},
readOnly: readOnly,
placeholder: placeholder,
defaultValue: defaultValue,
onFocus: function() {
return setIsFocused(true);
},
onBlur: function() {
if (!isHoveringSuggestions) setIsFocused(false);
},
onKeyPress: function(e) {
if (type === "number") {
if (e.key !== "Backspace" && e.key !== "Delete" && (maxNumber && parseInt(e.key) > maxNumber || minNumber && parseInt(e.key) < minNumber || !/^[0-9]$/.test(e.key))) {
e.preventDefault();
}
} else if (type === "puretext") {
if (!/^[a-z]$/.test(e.key.toLowerCase())) {
e.preventDefault();
}
}
},
className: twMerge2(classNames2("w-full p-2 md:p-3 border border-[var(--border-color)] rounded-xl placeholder:text-[var(--placeholder-color)] bg-transparent", {
"p-2 pl-11 md:p-2 md:pl-11 rounded-full": type === "search"
}, inputClasses))
}), /* @__PURE__ */ React3.createElement("div", {
className: "flex gap-2 items-center absolute right-2 top-0 bottom-0"
}, copyPassword && value && value.length > 5 && /* @__PURE__ */ React3.createElement(Button, {
onClick: function() {
return navigator.clipboard.writeText(value).then(function() {
toast.info("Copied to clipboard.");
}).catch(function(err) {
toast.info(err.messge || "Failed to copy to clipboard.");
});
},
outline: true,
className: "p-2 hover:opacity-70 border-none",
icon: /* @__PURE__ */ React3.createElement(BiCopy, null)
}), type === "password" && /* @__PURE__ */ React3.createElement(Button, {
onClick: function() {
return setPasswordVisible(!passwordVisible);
},
className: "p-2 hover:opacity-70 border-none",
outline: true,
icon: passwordVisible ? /* @__PURE__ */ React3.createElement(PiEye, {
size: 18
}) : /* @__PURE__ */ React3.createElement(PiEyeClosed, {
size: 18
})
}))), generatePassword && /* @__PURE__ */ React3.createElement(Button, {
onClick: function() {
var newPassword = passwordGenerator({
length: 16,
includeNumbers: true,
includeSymbols: true,
excludeSimilarCharacters: true
});
onChange && onChange(newPassword);
},
className: "border-none",
label: "Generate Password",
outline: true
})), error && /* @__PURE__ */ React3.createElement("span", {
className: "text-red-500 text-xs"
}, error), (isFocused || isHoveringSuggestions) && suggestions && /* @__PURE__ */ React3.createElement("div", {
onMouseEnter: function() {
return setIsHoveringSuggestions(true);
},
onMouseLeave: function() {
return setIsHoveringSuggestions(false);
},
className: "absolute left-0 top-full mt-1 w-full bg-[var(--suggestion-tile-background-color)]\n text-[var(--suggestion-tile-text-color)] rounded-xl shadow-lg \n max-h-60 overflow-y-auto z-10 border border-gray-300"
}, suggestions));
};
// src/RichTextEditor/Index.tsx
import React4, { lazy, Suspense } from "react";
var ReactQuill = lazy(function() {
return import("react-quill-new");
});
var RichTextEditor = function(param) {
var value = param.value, onChange = param.onChange;
return /* @__PURE__ */ React4.createElement("div", {
className: "flex w-full h-auto relative overflow-hidden border border-black/20 rounded"
}, /* @__PURE__ */ React4.createElement(Suspense, {
fallback: /* @__PURE__ */ React4.createElement("div", null, "Loading editor...")
}, /* @__PURE__ */ React4.createElement(ReactQuill, {
value: value,
onChange: onChange,
modules: {
toolbar: [
[
{
header: "1"
},
{
header: "2"
},
{
font: []
}
],
[
{
list: "ordered"
},
{
list: "bullet"
}
],
[
"bold",
"italic",
"underline"
],
[
{
align: []
}
],
[
"link"
]
]
},
theme: "snow",
className: "w-full custom-quill-editor"
})));
};
// src/Nav/Index.tsx
import React6, { useState as useState4 } from "react";
import { PiMagnifyingGlass as PiMagnifyingGlass2, PiUser } from "react-icons/pi";
import classNames3 from "classnames";
import { twMerge as twMerge3 } from "tailwind-merge";
import { BiMenuAltLeft } from "react-icons/bi";
import { MdClose as MdClose2 } from "react-icons/md";
// src/Nav/NavContext.tsx
import React5, { createContext, useState as useState3, useContext } from "react";
var NavContext = createContext(void 0);
var NavProvider = function(param) {
var children = param.children;
var _useState3 = _sliced_to_array(useState3(""), 2), query = _useState3[0], setQuery = _useState3[1];
var _useState31 = _sliced_to_array(useState3(null), 2), searchSuggestions = _useState31[0], setSearchSuggestions = _useState31[1];
return /* @__PURE__ */ React5.createElement(NavContext.Provider, {
value: {
query: query,
setQuery: setQuery,
searchSuggestions: searchSuggestions,
setSearchSuggestions: setSearchSuggestions
}
}, children);
};
var useNav = function() {
var context = useContext(NavContext);
if (!context) {
throw new Error("useNav must be used within a NavProvider");
}
return context;
};
// src/Nav/Index.tsx
var Nav = function(param) {
var header = param.header, items = param.items, profile = param.profile, type = param.type, rightIcons = param.rightIcons, hideProfileIcon = param.hideProfileIcon, hideSearchIcon = param.hideSearchIcon, onSearch = param.onSearch;
var _useState4 = _sliced_to_array(useState4(false), 2), isNavOpen = _useState4[0], setIsNavOpen = _useState4[1];
var _useState41 = _sliced_to_array(useState4(false), 2), isSearchOpen = _useState41[0], setIsSearchOpen = _useState41[1];
var _useNav = useNav(), query = _useNav.query, setQuery = _useNav.setQuery, searchSuggestions = _useNav.searchSuggestions, setSearchSuggestions = _useNav.setSearchSuggestions;
return /* @__PURE__ */ React6.createElement("div", {
className: classNames3("flex md:flex-col md:h-screen gap-8 p-4 justify-between bg-[var(--nav-bg-color)] text-[var(--nav-text-color)] shrink-0 border-r border-[var(--border-color)]", {
"flex-row md:flex-row h-auto w-full": type === "xnav",
"flex-col md:flex-col h-full w-auto": type === "ynav"
})
}, /* @__PURE__ */ React6.createElement("div", {
className: classNames3("flex flex-col h-full gap-4")
}, header && /* @__PURE__ */ React6.createElement("div", {
className: twMerge3(classNames3("flex gap-2 items-center", header === null || header === void 0 ? void 0 : header.className))
}, /* @__PURE__ */ React6.createElement(Button, {
onClick: function() {
return setIsNavOpen(!isNavOpen);
},
icon: /* @__PURE__ */ React6.createElement(BiMenuAltLeft, {
size: 24
}),
outline: true,
className: "p-2 border-none md:hidden"
}), header.logo && /* @__PURE__ */ React6.createElement("img", {
src: header === null || header === void 0 ? void 0 : header.logo,
className: classNames3(header === null || header === void 0 ? void 0 : header.logoClassNames, "size-10")
}), header === null || header === void 0 ? void 0 : header.startIcon, /* @__PURE__ */ React6.createElement("h1", {
className: classNames3("font-semibold text-[var(--primary-color)]")
}, header === null || header === void 0 ? void 0 : header.title), header === null || header === void 0 ? void 0 : header.endIcon), /* @__PURE__ */ React6.createElement("div", {
className: classNames3("hidden md:flex flex-col gap-4 w-full grow pt-8")
}, /* @__PURE__ */ React6.createElement(Button, {
onClick: function() {
return setIsNavOpen(false);
},
icon: /* @__PURE__ */ React6.createElement(MdClose2, {
size: 24
}),
outline: true,
className: "p-2 border-none ml-auto md:hidden"
}), items === null || items === void 0 ? void 0 : items.map(function(item, index) {
return /* @__PURE__ */ React6.createElement(Button, {
key: index,
onClick: item.onClick,
icon: item.icon,
label: item.label,
outline: !item.active,
active: item.active,
className: "border-none justify-start w-full"
});
}), profile && /* @__PURE__ */ React6.createElement("div", {
className: "flex items-center shrink-0 gap-2 mt-auto"
}, profile.avatar ? /* @__PURE__ */ React6.createElement("img", {
onClick: profile.onAvatarClick,
src: profile.avatar,
className: classNames3("size-6", {
"cursor-pointer": profile.onAvatarClick
})
}) : /* @__PURE__ */ React6.createElement("p", {
onClick: profile.onAvatarClick,
className: classNames3("rounded-full p-2 bg-[var(--primary-color)] text-[var(--bg-color)]", {
"cursor-pointer": profile.onAvatarClick
})
}, /* @__PURE__ */ React6.createElement(PiUser, {
size: 24
})), /* @__PURE__ */ React6.createElement("p", {
className: classNames3({
"cursor-pointer": profile.onUsernameClick
}),
onClick: profile.onUsernameClick
}, profile.username))), isNavOpen && /* @__PURE__ */ React6.createElement("div", {
className: classNames3("left-0 top-0 bottom-0 h-screen w-screen absolute z-20 flex", {
"flex-col md:flex-col": type === "ynav",
"flex-row md:flex-row": type === "xnav"
})
}, /* @__PURE__ */ React6.createElement("div", {
className: classNames3("flex flex-col gap-4 w-auto bg-[var(--nav-bg-color)] backdrop-blur shrink-0 border-r border-black/10 p-4")
}, /* @__PURE__ */ React6.createElement(Button, {
onClick: function() {
return setIsNavOpen(false);
},
icon: /* @__PURE__ */ React6.createElement(MdClose2, {
size: 24
}),
outline: true,
className: "p-2 border-none ml-auto md:hidden"
}), items === null || items === void 0 ? void 0 : items.map(function(item, index) {
return /* @__PURE__ */ React6.createElement(Button, {
key: index,
onClick: item.onClick,
icon: item.icon,
label: item.label,
outline: !item.active,
active: item.active,
className: "border-none justify-start w-full"
});
}), profile && /* @__PURE__ */ React6.createElement("div", {
className: "flex items-center shrink-0 gap-2 mt-auto"
}, profile.avatar ? /* @__PURE__ */ React6.createElement("img", {
onClick: profile.onAvatarClick,
src: profile.avatar,
className: classNames3("size-6", {
"cursor-pointer": profile.onAvatarClick
})
}) : /* @__PURE__ */ React6.createElement("p", {
onClick: profile.onAvatarClick,
className: classNames3("rounded-full p-2 bg-[var(--primary-color)] text-[var(--bg-color)]", {
"cursor-pointer": profile.onAvatarClick
})
}, /* @__PURE__ */ React6.createElement(PiUser, {
size: 24
})), /* @__PURE__ */ React6.createElement("p", {
className: classNames3({
"cursor-pointer": profile.onUsernameClick
}),
onClick: profile.onUsernameClick
}, profile.username))), /* @__PURE__ */ React6.createElement("div", {
className: "flex flex-col w-full h-full items-center justify-center p-4 bg-black/50 text-white/50",
onClick: function() {
return setIsNavOpen(false);
}
}, /* @__PURE__ */ React6.createElement("p", null, "Close")))), profile || rightIcons ? /* @__PURE__ */ React6.createElement("div", {
className: "flex items-center shrink-0 gap-2 md:hidden"
}, rightIcons, !hideSearchIcon && /* @__PURE__ */ React6.createElement(Button, {
onClick: function() {
return setIsSearchOpen(!isSearchOpen);
},
icon: /* @__PURE__ */ React6.createElement(PiMagnifyingGlass2, {
size: 24
}),
outline: true,
className: "p-2 border-none rounded-full"
}), !hideProfileIcon && (profile === null || profile === void 0 ? void 0 : profile.avatar) ? /* @__PURE__ */ React6.createElement("img", {
className: classNames3("size-8 rounded-full", {
"cursor-pointer": profile.onAvatarClick
}),
onClick: profile.onAvatarClick,
src: profile.avatar
}) : /* @__PURE__ */ React6.createElement("p", {
onClick: profile === null || profile === void 0 ? void 0 : profile.onAvatarClick,
className: classNames3("rounded-full p-2 bg-[var(--primary-color)] text-[var(--background-color)]", {
"cursor-pointer": profile === null || profile === void 0 ? void 0 : profile.onAvatarClick
})
}, /* @__PURE__ */ React6.createElement(PiUser, {
size: 24
}))) : null, isSearchOpen && /* @__PURE__ */ React6.createElement("div", {
className: classNames3("left-0 top-0 bottom-0 right-0 h-screen w-screen absolute z-20 flex flex-col")
}, /* @__PURE__ */ React6.createElement("div", {
className: classNames3("flex w-full gap-4 bg-[var(--nav-bg-color)] backdrop-blur shrink-0 border-r border-black/10 p-4")
}, /* @__PURE__ */ React6.createElement(InputComponent, {
value: query,
onChange: setQuery,
type: "search"
}), /* @__PURE__ */ React6.createElement(Button, {
onClick: function() {
if (query && query.length > 0) {
setQuery("");
} else {
setIsSearchOpen(false);
}
},
icon: /* @__PURE__ */ React6.createElement(MdClose2, {
size: 24
}),
outline: true,
className: "p-2 border-none"
})), searchSuggestions && /* @__PURE__ */ React6.createElement("div", {
className: "flex flex-col gap-4 w-full p-4 pt-10 bg-[var(--nav-bg-color)]"
}, searchSuggestions), /* @__PURE__ */ React6.createElement("div", {
className: "flex flex-col w-full h-full items-center justify-center p-4 bg-black/50 text-white/50",
onClick: function() {
return setIsSearchOpen(false);
}
})));
};
// src/Header/Index.tsx
import React7 from "react";
import { GoChevronLeft } from "react-icons/go";
import classNames4 from "classnames";
import { twMerge as twMerge4 } from "tailwind-merge";
import { PiArrowArcRight, PiCopy, PiDotsThreeVertical, PiPencil, PiTrash } from "react-icons/pi";
import { BiChevronRight } from "react-icons/bi";
import { MdClose as MdClose3 } from "react-icons/md";
var Header = function(param) {
var title = param.title, back = param.back, children = param.children, type = param.type, className = param.className, query = param.query, refreshing = param.refreshing, refreshIcon = param.refreshIcon, onRefresh = param.onRefresh, setQuery = param.setQuery, deleteIcon = param.deleteIcon, onDelete = param.onDelete, editIcon = param.editIcon, onEdit = param.onEdit, copyIcon = param.copyIcon, onCopy = param.onCopy, optionsIcon = param.optionsIcon, onOptionsClicked = param.onOptionsClicked, steps = param.steps, closeIcon = param.closeIcon, onClose = param.onClose, actionIcon = param.actionIcon, actionLabel = param.actionLabel, onAction = param.onAction;
return /* @__PURE__ */ React7.createElement("div", {
className: twMerge4(classNames4("flex justify-between items-center p-4 rounded-xl w-full", {
"border border-[var(--border-color)]": type === "bordered",
"bg-[var(--header-background-color)] text-[var(--header-text-color)]": type !== "bordered"
}, className))
}, /* @__PURE__ */ React7.createElement("div", {
className: "flex gap-4 items-center line-clamp-1 text-ellipsis"
}, back && /* @__PURE__ */ React7.createElement(Button, {
outline: true,
onClick: back,
icon: /* @__PURE__ */ React7.createElement(GoChevronLeft, {
size: 18
}),
className: "p-2 border-none bg-transparent text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}), steps && steps.map(function(step) {
return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement("p", {
onClick: step.onClick,
className: "opacity-70 ".concat(step.onClick && "hover:scale-95 cursor-pointer")
}, step.name), /* @__PURE__ */ React7.createElement(BiChevronRight, {
size: 18,
className: "opacity-70"
}));
}), typeof title === "string" ? /* @__PURE__ */ React7.createElement("h1", {
className: "md:text-lg"
}, title) : title), /* @__PURE__ */ React7.createElement("div", {
className: "flex gap-4 items-center"
}, refreshing ? /* @__PURE__ */ React7.createElement(PiArrowArcRight, {
size: 18,
className: "animate-spin"
}) : onRefresh ? /* @__PURE__ */ React7.createElement(Button, {
outline: true,
onClick: onRefresh,
icon: refreshIcon || /* @__PURE__ */ React7.createElement(PiArrowArcRight, {
size: 18
}),
className: "p-2 border-none bg-transparent text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}) : null, setQuery && /* @__PURE__ */ React7.createElement(InputComponent, {
type: "search",
value: query,
onChange: setQuery
}), children, onEdit && /* @__PURE__ */ React7.createElement(Button, {
outline: true,
onClick: onEdit,
icon: editIcon || /* @__PURE__ */ React7.createElement(PiPencil, {
size: 18
}),
className: "p-2 border-none bg-transparent text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}), onCopy && /* @__PURE__ */ React7.createElement(Button, {
outline: true,
onClick: onCopy,
icon: copyIcon || /* @__PURE__ */ React7.createElement(PiCopy, {
size: 18
}),
className: "p-2 border-none text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}), onDelete && /* @__PURE__ */ React7.createElement(Button, {
outline: true,
onClick: onDelete,
icon: deleteIcon || /* @__PURE__ */ React7.createElement(PiTrash, {
size: 18
}),
className: "p-2 border-none bg-transparent text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}), onOptionsClicked && /* @__PURE__ */ React7.createElement(Button, {
outline: true,
onClick: onOptionsClicked,
icon: optionsIcon || /* @__PURE__ */ React7.createElement(PiDotsThreeVertical, {
size: 18
}),
className: "p-2 border-none bg-transparent text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}), onClose && /* @__PURE__ */ React7.createElement(Button, {
outline: true,
onClick: onClose,
icon: closeIcon || /* @__PURE__ */ React7.createElement(MdClose3, {
size: 18
}),
className: "p-2 border-none bg-transparent text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}), onAction ? actionIcon || actionLabel ? /* @__PURE__ */ React7.createElement(Button, {
onClick: onAction,
icon: actionIcon,
label: actionLabel,
className: "p-1 border-none text-sm bg-transparent text-[var(--header-text-color)] hover:bg-[var(--header-button-hover-background-color)] hover:text-[var(--header-button-hover-text-color)]"
}) : null : null));
};
// src/Modal/Index.tsx
import React8, { createContext as createContext2, useState as useState5, useContext as useContext2 } from "react";
var ModalContext = createContext2(void 0);
var useModal = function() {
var context = useContext2(ModalContext);
if (!context) {
throw new Error("useModal must be used within a ModalProvider");
}
return context;
};
var ModalProvider = function(param) {
var children = param.children;
var _useState5 = _sliced_to_array(useState5([]), 2), modalStack = _useState5[0], setModalStack = _useState5[1];
var openModal = function(content) {
setModalStack(function(prev) {
return _to_consumable_array(prev).concat([
content
]);
});
};
var closeModal = function(index) {
if (index !== void 0) {
setModalStack(function(prev) {
return prev.filter(function(_, i) {
return i !== index;
});
});
} else {
setModalStack(function(prev) {
return prev.slice(0, -1);
});
}
};
return /* @__PURE__ */ React8.createElement(ModalContext.Provider, {
value: {
openModal: openModal,
closeModal: closeModal,
modalStack: modalStack
}
}, children, modalStack.map(function(content, index) {
return /* @__PURE__ */ React8.createElement(Modal, {
key: index,
index: index
}, content);
}));
};
var Modal = React8.memo(function(param) {
var children = param.children, index = param.index;
var closeModal = useModal().closeModal;
return /* @__PURE__ */ React8.createElement("div", {
className: "fixed z-40 flex flex-col top-0 bottom-0 justify-center items-center gap-4 overflow-hidden w-screen h-screen bg-gray-950/80 backdrop-blur"
}, children);
});
Modal.displayName = "Modal";
// src/Cropper/Index.tsx
import React9, { useState as useState6 } from "react";
import { PiArrowArcLeft, PiArrowArcRight as PiArrowArcRight2, PiMinus, PiPen, PiPlus } from "react-icons/pi";
import EasyCropper from "react-easy-crop";
var Cropper = function(param) {
var title = param.title, image = param.image, setImage = param.setImage, handleClose = param.handleClose, onImageEdit = param.onImageEdit, _param_max_zoom = param.max_zoom, max_zoom = _param_max_zoom === void 0 ? 3 : _param_max_zoom, _param_min_zoom = param.min_zoom, min_zoom = _param_min_zoom === void 0 ? 1 : _param_min_zoom, _param_zoom_step = param.zoom_step, zoom_step = _param_zoom_step === void 0 ? 0.1 : _param_zoom_step, _param_max_rotation = param.max_rotation, max_rotation = _param_max_rotation === void 0 ? 360 : _param_max_rotation, _param_min_rotation = param.min_rotation, min_rotation = _param_min_rotation === void 0 ? 0 : _param_min_rotation, _param_rotation_step = param.rotation_step, rotation_step = _param_rotation_step === void 0 ? 5 : _param_rotation_step, _param_defaultCrop = param.defaultCrop, defaultCrop = _param_defaultCrop === void 0 ? {
x: 0,
y: 0
} : _param_defaultCrop, _param_defaultRotation = param.defaultRotation, defaultRotation = _param_defaultRotation === void 0 ? 0 : _param_defaultRotation, _param_defaultZoom = param.defaultZoom, defaultZoom = _param_defaultZoom === void 0 ? 1 : _param_defaultZoom, _param_cropShape = param.cropShape, cropShape = _param_cropShape === void 0 ? "rect" : _param_cropShape, _param_defaultCroppedAreaPixels = param.defaultCroppedAreaPixels, defaultCroppedAreaPixels = _param_defaultCroppedAreaPixels === void 0 ? null : _param_defaultCroppedAreaPixels;
var _useState6 = _sliced_to_array(useState6(defaultCrop), 2), crop = _useState6[0], setCrop = _useState6[1];
var _useState61 = _sliced_to_array(useState6(defaultRotation), 2), rotation = _useState61[0], setRotation = _useState61[1];
var _useState62 = _sliced_to_array(useState6({
horizontal: false,
vertical: false
}), 2), flip = _useState62[0], setFlip = _useState62[1];
var _useState63 = _sliced_to_array(useState6(defaultZoom), 2), zoom = _useState63[0], setZoom = _useState63[1];
var _useState64 = _sliced_to_array(useState6(defaultCroppedAreaPixels), 2), croppedAreaPixels = _useState64[0], setCroppedAreaPixels = _useState64[1];
var handleSave = /*#__PURE__*/ function() {
var _ref = _async_to_generator(function() {
var rotateCanvas, ctx, img;
return _ts_generator(this, function(_state) {
if (image && croppedAreaPixels) {
rotateCanvas = document.createElement("canvas");
ctx = rotateCanvas.getContext("2d");
if (ctx) {
img = new Image();
img.src = image;
img.onload = function() {
var rotRad = rotation * (Math.PI / 180);
var bBoxWidth = Math.abs(Math.cos(rotRad) * img.width) + Math.abs(Math.sin(rotRad) * img.height);
var bBoxHeight = Math.abs(Math.sin(rotRad) * img.width) + Math.abs(Math.cos(rotRad) * img.height);
rotateCanvas.width = bBoxWidth;
rotateCanvas.height = bBoxHeight;
ctx.translate(rotateCanvas.width / 2, rotateCanvas.height / 2);
ctx.rotate(rotRad);
ctx.scale(flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1);
ctx.drawImage(img, -img.width / 2, -img.height / 2);
var cropCanvas = document.createElement("canvas");
var cropCtx = cropCanvas.getContext("2d");
if (cropCtx) {
cropCanvas.width = croppedAreaPixels.width;
cropCanvas.height = croppedAreaPixels.height;
cropCtx.drawImage(rotateCanvas, croppedAreaPixels.x, croppedAreaPixels.y, croppedAreaPixels.width, croppedAreaPixels.height, 0, 0, croppedAreaPixels.width, croppedAreaPixels.height);
var imgUrl = cropCanvas.toDataURL("image/png");
if (imgUrl) {
setImage(imgUrl);
handleClose();
} else {
toast.error("Failed to create final image.");
}
}
};
}
}
return [
2
];
});
});
return function handleSave() {
return _ref.apply(this, arguments);
};
}();
var handleZoomIn = function() {
if (zoom < max_zoom) {
setZoom(zoom + zoom_step * 2);
}
};
var handleZoomOut = function() {
if (zoom > min_zoom) {
setZoom(zoom - zoom_step * 2);
}
};
var handleRotateCw = function() {
setRotation(rotation + rotation_step);
};
var handleRotateAntiCw = function() {
setRotation(rotation - rotation_step);
};
return /* @__PURE__ */ React9.createElement("div", {
className: "flex flex-col gap-4 items-center shrink-0 justify-center relative bg-[var(--background-color)] rounded p-4"
}, /* @__PURE__ */ React9.createElement("h2", {
className: "font-semibold text-xl text-[var(--text-color)]"
}, title), /* @__PURE__ */ React9.createElement("div", {
className: "relative flex size-[400px]"
}, onImageEdit && /* @__PURE__ */ React9.createElement(Button, {
onClick: onImageEdit,
className: "absolute top-2 right-2 z-10 p-2",
outline: true,
icon: /* @__PURE__ */ React9.createElement(PiPen, {
size: 18
})
}), /* @__PURE__ */ React9.createElement(EasyCropper, {
image: image,
aspect: 1,
crop: crop,
zoom: zoom,
onCropChange: setCrop,
onZoomChange: setZoom,
rotation: rotation,
cropShape: cropShape,
onCropComplete: function(croppedArea, croppedAreaPixels2) {
setCroppedAreaPixels(croppedAreaPixels2);
},
showGrid: true
})), /* @__PURE__ */ React9.createElement("div", {
className: "flex flex-col gap-2 w-full"
}, /* @__PURE__ */ React9.createElement("div", {
className: "flex w-full items-center justify-between gap-4"
}, /* @__PURE__ */ React9.createElement(Button, {
outline: true,
className: "p-2",
onClick: handleZoomOut,
icon: /* @__PURE__ */ React9.createElement(PiMinus, {
size: 18
})
}), /* @__PURE__ */ React9.createElement(InputComponent, {
type: "range",
name: "volju",
minNumber: min_zoom,
maxNumber: max_zoom,
step: zoom_step,
value: zoom.toString(),
onChange: function(e) {
return setZoom(Number(e));
}
}), /* @__PURE__ */ React9.createElement(Button, {
outline: true,
className: "p-2",
onClick: handleZoomIn,
icon: /* @__PURE__ */ React9.createElement(PiPlus, {
size: 18
})
})), /* @__PURE__ */ React9.createElement("div", {
className: "flex w-full items-center justify-between gap-4"
}, /* @__PURE__ */ React9.createElement(Button, {
outline: true,
className: "p-2",
onClick: handleRotateAntiCw,
icon: /* @__PURE__ */ React9.createElement(PiArrowArcLeft, {
size: 18
})
}), /* @__PURE__ */ React9.createElement(InputComponent, {
type: "range",
name: "volju",
minNumber: min_rotation,
maxNumber: max_rotation,
step: rotation_step,
value: rotation.toString(),
onChange: function(e) {
return setRotation(Number(e));
}
}), /* @__PURE__ */ React9.createElement(Button, {
outline: true,
className: "p-2",
onClick: handleRotateCw,
icon: /* @__PURE__ */ React9.createElement(PiArrowArcRight2, {
size: 18
})
}))), /* @__PURE__ */ React9.createElement("div", {
className: "flex flex-col md:flex-row w-full gap-4"
}, /* @__PURE__ */ React9.createElement(Button, {
className: "w-full",
outline: true,
onClick: handleClose,
label: "Cancel"
}), /* @__PURE__ */ React9.createElement(Button, {
className: "w-full",
label: "Done",
onClick: handleSave
})));
};
// src/ConfirmDialog/Index.tsx
import React10 from "react";
import { twMerge as twMerge5 } from "tailwind-merge";
import classNames5 from "classnames";
var ConfirmDialog = function(param) {
var message = param.message, confirmLabel = param.confirmLabel, cancelLabel = param.cancelLabel, neutralLabel = param.neutralLabel, confirmLabelClasses = param.confirmLabelClasses, cancelLabelClasses = param.cancelLabelClasses, neutralLabelClasses = param.neutralLabelClasses, onConfirm = param.onConfirm, onCancel = param.onCancel, onNeutral = param.onNeutral;
return /* @__PURE__ */ React10.createElement("div", {
className: "flex flex-col gap-