@webdevarif/dashui 0.3.3 → 0.3.4
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/dist/index.js +90 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -57
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3309,8 +3309,8 @@ function PostSidebarSection({
|
|
|
3309
3309
|
|
|
3310
3310
|
// src/components/ui/hsl-color-input.tsx
|
|
3311
3311
|
var import_react = require("react");
|
|
3312
|
+
var import_react_dom = require("react-dom");
|
|
3312
3313
|
var import_react_colorful = require("react-colorful");
|
|
3313
|
-
var Popover2 = __toESM(require("@radix-ui/react-popover"));
|
|
3314
3314
|
var import_jsx_runtime49 = require("react/jsx-runtime");
|
|
3315
3315
|
function parseHsl(value) {
|
|
3316
3316
|
if (!value) return { h: 0, s: 0, l: 0 };
|
|
@@ -3321,83 +3321,117 @@ function parseHsl(value) {
|
|
|
3321
3321
|
l: parseFloat(parts[2]) || 0
|
|
3322
3322
|
};
|
|
3323
3323
|
}
|
|
3324
|
-
function formatHsl(
|
|
3325
|
-
return `${Math.round(
|
|
3324
|
+
function formatHsl(c) {
|
|
3325
|
+
return `${Math.round(c.h)} ${Math.round(c.s)}% ${Math.round(c.l)}%`;
|
|
3326
3326
|
}
|
|
3327
3327
|
function HslColorInput({ value, onChange, className, inputClassName, disabled }) {
|
|
3328
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
3329
|
+
const [pos, setPos] = (0, import_react.useState)({ top: 0, left: 0 });
|
|
3328
3330
|
const [inputVal, setInputVal] = (0, import_react.useState)(value);
|
|
3331
|
+
const [mounted, setMounted] = (0, import_react.useState)(false);
|
|
3332
|
+
const triggerRef = (0, import_react.useRef)(null);
|
|
3333
|
+
const pickerRef = (0, import_react.useRef)(null);
|
|
3334
|
+
(0, import_react.useEffect)(() => {
|
|
3335
|
+
setMounted(true);
|
|
3336
|
+
}, []);
|
|
3329
3337
|
(0, import_react.useEffect)(() => {
|
|
3330
3338
|
setInputVal(value);
|
|
3331
3339
|
}, [value]);
|
|
3332
|
-
const
|
|
3340
|
+
const openPicker = (0, import_react.useCallback)(() => {
|
|
3341
|
+
const rect = triggerRef.current?.getBoundingClientRect();
|
|
3342
|
+
if (!rect) return;
|
|
3343
|
+
const pickerW = 228;
|
|
3344
|
+
let left = rect.left;
|
|
3345
|
+
if (left + pickerW > window.innerWidth - 8) left = window.innerWidth - pickerW - 8;
|
|
3346
|
+
setPos({ top: rect.bottom + 6, left: Math.max(8, left) });
|
|
3347
|
+
setOpen(true);
|
|
3348
|
+
}, []);
|
|
3349
|
+
(0, import_react.useEffect)(() => {
|
|
3350
|
+
if (!open) return;
|
|
3351
|
+
const handler = (e) => {
|
|
3352
|
+
const target = e.target;
|
|
3353
|
+
if (pickerRef.current?.contains(target)) return;
|
|
3354
|
+
if (triggerRef.current?.contains(target)) return;
|
|
3355
|
+
setOpen(false);
|
|
3356
|
+
};
|
|
3357
|
+
document.addEventListener("pointerdown", handler, true);
|
|
3358
|
+
return () => document.removeEventListener("pointerdown", handler, true);
|
|
3359
|
+
}, [open]);
|
|
3333
3360
|
const cssColor = value ? `hsl(${value})` : "transparent";
|
|
3334
|
-
const
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3361
|
+
const picker = /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
|
|
3362
|
+
"div",
|
|
3363
|
+
{
|
|
3364
|
+
ref: pickerRef,
|
|
3365
|
+
style: { position: "fixed", top: pos.top, left: pos.left, zIndex: 9999 },
|
|
3366
|
+
className: "bg-[#1a1c2e] border border-white/10 rounded-xl shadow-2xl p-3 flex flex-col gap-3",
|
|
3367
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
3368
|
+
children: [
|
|
3369
|
+
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
|
|
3370
|
+
import_react_colorful.HslColorPicker,
|
|
3371
|
+
{
|
|
3372
|
+
color: parseHsl(value),
|
|
3373
|
+
onChange: (c) => {
|
|
3374
|
+
const formatted = formatHsl(c);
|
|
3375
|
+
setInputVal(formatted);
|
|
3376
|
+
onChange(formatted);
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
),
|
|
3380
|
+
/* @__PURE__ */ (0, import_jsx_runtime49.jsxs)("div", { className: "flex items-center gap-2 px-1", children: [
|
|
3381
|
+
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "w-5 h-5 rounded border border-white/10 shrink-0", style: { background: cssColor } }),
|
|
3382
|
+
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)("span", { className: "text-xs font-mono text-white/40 flex-1 truncate", children: value || "none" }),
|
|
3383
|
+
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
|
|
3384
|
+
"button",
|
|
3385
|
+
{
|
|
3386
|
+
onClick: () => setOpen(false),
|
|
3387
|
+
className: "text-white/30 hover:text-white/70 text-xs px-1.5 py-0.5 rounded hover:bg-white/5 transition-colors",
|
|
3388
|
+
children: "Done"
|
|
3389
|
+
}
|
|
3390
|
+
)
|
|
3391
|
+
] })
|
|
3392
|
+
]
|
|
3344
3393
|
}
|
|
3345
|
-
|
|
3394
|
+
);
|
|
3346
3395
|
return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)("div", { className: cn("flex items-center gap-1.5", className), children: [
|
|
3347
|
-
/* @__PURE__ */ (0, import_jsx_runtime49.
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
}
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
{
|
|
3364
|
-
sideOffset: 8,
|
|
3365
|
-
align: "start",
|
|
3366
|
-
className: cn(
|
|
3367
|
-
"z-[9999] rounded-xl shadow-2xl p-3",
|
|
3368
|
-
"bg-[#1a1c2e] border border-white/10",
|
|
3369
|
-
"flex flex-col gap-3",
|
|
3370
|
-
"animate-in fade-in-0 zoom-in-95"
|
|
3371
|
-
),
|
|
3372
|
-
children: [
|
|
3373
|
-
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_react_colorful.HslColorPicker, { color: hslColor, onChange: handlePickerChange }),
|
|
3374
|
-
/* @__PURE__ */ (0, import_jsx_runtime49.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
3375
|
-
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "w-6 h-6 rounded border border-white/10 shrink-0", style: { background: cssColor } }),
|
|
3376
|
-
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)("span", { className: "text-xs font-mono text-white/50 truncate", children: value || "none" })
|
|
3377
|
-
] }),
|
|
3378
|
-
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Popover2.Arrow, { className: "fill-white/10" })
|
|
3379
|
-
]
|
|
3380
|
-
}
|
|
3381
|
-
) })
|
|
3382
|
-
] }),
|
|
3396
|
+
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
|
|
3397
|
+
"button",
|
|
3398
|
+
{
|
|
3399
|
+
ref: triggerRef,
|
|
3400
|
+
type: "button",
|
|
3401
|
+
disabled,
|
|
3402
|
+
onClick: () => open ? setOpen(false) : openPicker(),
|
|
3403
|
+
className: cn(
|
|
3404
|
+
"w-5 h-5 rounded border border-white/10 shrink-0 transition-all",
|
|
3405
|
+
"hover:scale-110 hover:border-white/30 focus:outline-none",
|
|
3406
|
+
disabled && "opacity-50 cursor-not-allowed"
|
|
3407
|
+
),
|
|
3408
|
+
style: { background: cssColor },
|
|
3409
|
+
"aria-label": "Pick color"
|
|
3410
|
+
}
|
|
3411
|
+
),
|
|
3383
3412
|
/* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
|
|
3384
3413
|
"input",
|
|
3385
3414
|
{
|
|
3386
3415
|
type: "text",
|
|
3387
3416
|
value: inputVal,
|
|
3388
|
-
onChange:
|
|
3417
|
+
onChange: (e) => {
|
|
3418
|
+
setInputVal(e.target.value);
|
|
3419
|
+
if (/^\d+(\.\d+)?\s+\d+(\.\d+)?%\s+\d+(\.\d+)?%$/.test(e.target.value.trim())) {
|
|
3420
|
+
onChange(e.target.value.trim());
|
|
3421
|
+
}
|
|
3422
|
+
},
|
|
3389
3423
|
onBlur: () => setInputVal(value),
|
|
3390
3424
|
disabled,
|
|
3391
3425
|
placeholder: "H S% L%",
|
|
3392
3426
|
className: cn(
|
|
3393
3427
|
"w-28 bg-white/5 border border-white/10 rounded px-1.5 py-0.5",
|
|
3394
|
-
"text-xs text-white/70 font-mono outline-none",
|
|
3395
|
-
"
|
|
3396
|
-
"disabled:opacity-50 disabled:cursor-not-allowed",
|
|
3428
|
+
"text-xs text-white/70 font-mono outline-none focus:border-white/30",
|
|
3429
|
+
"placeholder:text-white/20 disabled:opacity-50",
|
|
3397
3430
|
inputClassName
|
|
3398
3431
|
)
|
|
3399
3432
|
}
|
|
3400
|
-
)
|
|
3433
|
+
),
|
|
3434
|
+
mounted && open && (0, import_react_dom.createPortal)(picker, document.body)
|
|
3401
3435
|
] });
|
|
3402
3436
|
}
|
|
3403
3437
|
|