@sikka/hawa
Version:
Modern UI Kit made with Tailwind
129 lines (125 loc) • 3.36 kB
JavaScript
"use client";
// elements/avatar/Avatar.tsx
import React2 from "react";
// util/index.ts
import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";
function cn(...inputs) {
return twMerge(clsx(inputs));
}
// elements/fileUploader/FileUploader.tsx
import React, { useRef } from "react";
var FileUploader = ({ handleFile, className }) => {
const hiddenFileInput = useRef(null);
const handleClick = () => {
var _a;
(_a = hiddenFileInput.current) == null ? void 0 : _a.click();
};
const handleChange = (event) => {
const fileUploaded = event.target.files[0];
handleFile(fileUploaded);
};
return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement("div", { className: "hawa-h-full hawa-w-full", onClick: handleClick }), /* @__PURE__ */ React.createElement(
"input",
{
type: "file",
onChange: handleChange,
ref: hiddenFileInput,
style: { display: "none" }
}
));
};
// elements/avatar/Avatar.tsx
var Avatar = ({
isUploadable,
hideIcon,
src,
alt,
size = "default",
radius = "inherit",
icon,
className,
...props
}) => {
let sizeStyles = {
"2xs": "hawa-h-4 hawa-w-4",
xs: "hawa-h-6 hawa-w-6",
sm: "hawa-h-8 hawa-w-8",
default: "hawa-h-10 hawa-w-10",
lg: "hawa-h-12 hawa-w-12",
xl: "hawa-h-14 hawa-w-14",
"2xl": "hawa-h-16 hawa-w-16",
"3xl": "hawa-h-[72px] hawa-w-[72px]",
"4xl": "hawa-h-20 hawa-w-20",
"5xl": "hawa-h-[88px] hawa-w-[88px]",
"6xl": "hawa-h-24 hawa-w-24"
};
let radiusStyles = {
full: "hawa-rounded-full",
inherit: "hawa-rounded",
none: "hawa-rounded-none"
};
return /* @__PURE__ */ React2.createElement(
"div",
{
className: cn(
"hawa-relative hawa-bg-card hawa-p-0",
sizeStyles[size],
radiusStyles[radius],
className
)
},
/* @__PURE__ */ React2.createElement(
FileUploader,
{
className: cn(
"hawa-absolute hawa-left-0 hawa-top-0 hawa-w-full hawa-cursor-pointer hawa-bg-red-400 hawa-opacity-0",
sizeStyles[size],
radiusStyles[radius],
(!isUploadable || !!src) && "hawa-hidden"
)
}
),
/* @__PURE__ */ React2.createElement(
"img",
{
className: cn(
"hawa-blue-400 hawa-object-cover",
sizeStyles[size],
radiusStyles[radius],
!src && "hawa-hidden"
),
src,
alt
}
),
!src && !hideIcon && /* @__PURE__ */ React2.createElement(
"div",
{
className: cn(
sizeStyles[size],
"hawa-flex hawa-flex-col hawa-items-center hawa-justify-center"
)
},
icon ? icon : /* @__PURE__ */ React2.createElement(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
style: { width: "50%", opacity: 0.35 },
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round"
},
/* @__PURE__ */ React2.createElement("circle", { cx: "12", cy: "8", r: "5" }),
/* @__PURE__ */ React2.createElement("path", { d: "M20 21a8 8 0 1 0-16 0" })
)
)
);
};
export {
Avatar
};
//# sourceMappingURL=index.mjs.map