@webdevarif/dashui 0.3.7 → 0.3.8

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.mjs CHANGED
@@ -3386,42 +3386,88 @@ var ColorPickerEyeDropper = ({ className, ...props }) => {
3386
3386
  };
3387
3387
  var ColorPickerOutput = ({ className, ...props }) => {
3388
3388
  const { mode, setMode } = useColorPicker();
3389
- return /* @__PURE__ */ jsx49(
3390
- "select",
3391
- {
3392
- value: mode,
3393
- onChange: (e) => setMode(e.target.value),
3394
- className: cn(
3395
- "h-7 bg-white/5 border border-white/10 rounded-md text-xs text-white/60 px-1.5 outline-none",
3396
- "hover:border-white/20 focus:border-white/30 cursor-pointer shrink-0",
3397
- className
3398
- ),
3399
- children: ["HEX", "HSL", "RGB"].map((f) => /* @__PURE__ */ jsx49("option", { value: f, className: "bg-[#1a1c2e]", children: f }, f))
3400
- }
3401
- );
3389
+ return /* @__PURE__ */ jsxs33("div", { className: cn("relative shrink-0", className), children: [
3390
+ /* @__PURE__ */ jsx49(
3391
+ "select",
3392
+ {
3393
+ value: mode,
3394
+ onChange: (e) => setMode(e.target.value),
3395
+ className: "appearance-none h-7 bg-white/8 border border-white/10 rounded-md text-xs text-white/70 pl-2 pr-6 outline-none hover:border-white/20 cursor-pointer",
3396
+ style: { backgroundColor: "rgba(255,255,255,0.05)" },
3397
+ children: ["HEX", "HSL", "RGB"].map((f) => /* @__PURE__ */ jsx49("option", { value: f, style: { background: "#1a1c2e" }, children: f }, f))
3398
+ }
3399
+ ),
3400
+ /* @__PURE__ */ jsx49("svg", { className: "pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 w-3 h-3 text-white/40", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", children: /* @__PURE__ */ jsx49("path", { d: "m6 9 6 6 6-6" }) })
3401
+ ] });
3402
3402
  };
3403
3403
  var ColorPickerFormat = ({ className, ...props }) => {
3404
- const { hue, saturation, lightness, alpha, mode } = useColorPicker();
3405
- let displayValue = "";
3406
- try {
3407
- const c = Color.hsl(hue, saturation, lightness).alpha(alpha / 100);
3408
- if (mode === "HEX") displayValue = c.hex();
3409
- else if (mode === "HSL") displayValue = `${Math.round(hue)} ${Math.round(saturation)}% ${Math.round(lightness)}%`;
3410
- else if (mode === "RGB") {
3411
- const rgb = c.rgb().array().map(Math.round);
3412
- displayValue = `${rgb[0]}, ${rgb[1]}, ${rgb[2]}`;
3404
+ const { hue, saturation, lightness, alpha, mode, setHue, setSaturation, setLightness, setAlpha } = useColorPicker();
3405
+ const [focused, setFocused] = useState7(false);
3406
+ const [localVal, setLocalVal] = useState7("");
3407
+ const computedVal = (() => {
3408
+ try {
3409
+ const c = Color.hsl(hue, saturation, lightness).alpha(alpha / 100);
3410
+ if (mode === "HEX") return c.hex().toUpperCase();
3411
+ if (mode === "HSL") return `${Math.round(hue)} ${Math.round(saturation)}% ${Math.round(lightness)}%`;
3412
+ if (mode === "RGB") {
3413
+ const [r, g, b] = c.rgb().array().map(Math.round);
3414
+ return `${r}, ${g}, ${b}`;
3415
+ }
3416
+ } catch {
3413
3417
  }
3414
- } catch {
3415
- displayValue = "";
3416
- }
3418
+ return "";
3419
+ })();
3420
+ useEffect5(() => {
3421
+ if (!focused) setLocalVal(computedVal);
3422
+ }, [computedVal, focused]);
3423
+ const tryApply = (raw) => {
3424
+ try {
3425
+ if (mode === "HEX") {
3426
+ const hex = raw.startsWith("#") ? raw : `#${raw}`;
3427
+ const c = Color(hex);
3428
+ setHue(c.hue());
3429
+ setSaturation(c.saturationl());
3430
+ setLightness(c.lightness());
3431
+ setAlpha(c.alpha() * 100);
3432
+ } else if (mode === "HSL") {
3433
+ const parts = raw.split(/[\s,%]+/).filter(Boolean);
3434
+ if (parts.length >= 3) {
3435
+ setHue(+parts[0]);
3436
+ setSaturation(+parts[1]);
3437
+ setLightness(+parts[2]);
3438
+ }
3439
+ } else if (mode === "RGB") {
3440
+ const parts = raw.split(/[\s,]+/).filter(Boolean);
3441
+ if (parts.length >= 3) {
3442
+ const c = Color.rgb(+parts[0], +parts[1], +parts[2]);
3443
+ setHue(c.hue());
3444
+ setSaturation(c.saturationl());
3445
+ setLightness(c.lightness());
3446
+ }
3447
+ }
3448
+ } catch {
3449
+ }
3450
+ };
3417
3451
  return /* @__PURE__ */ jsx49(
3418
3452
  "input",
3419
3453
  {
3420
- readOnly: true,
3421
3454
  type: "text",
3422
- value: displayValue,
3455
+ value: focused ? localVal : computedVal,
3456
+ onChange: (e) => {
3457
+ setLocalVal(e.target.value);
3458
+ tryApply(e.target.value);
3459
+ },
3460
+ onFocus: () => {
3461
+ setFocused(true);
3462
+ setLocalVal(computedVal);
3463
+ },
3464
+ onBlur: () => {
3465
+ tryApply(localVal);
3466
+ setFocused(false);
3467
+ },
3423
3468
  className: cn(
3424
- "flex-1 h-7 bg-white/5 border border-white/10 rounded-md px-2 text-xs text-white/50 font-mono outline-none",
3469
+ "flex-1 min-w-0 h-7 bg-white/5 border border-white/10 rounded-md px-2",
3470
+ "text-xs text-white/70 font-mono outline-none focus:border-white/30",
3425
3471
  className
3426
3472
  ),
3427
3473
  ...props
@@ -3519,7 +3565,7 @@ function HslColorInput({ value, onChange, className, inputClassName, disabled })
3519
3565
  sideOffset: 6,
3520
3566
  align: "start",
3521
3567
  className: cn(
3522
- "z-[9999] rounded-xl shadow-2xl p-3 w-[14rem]",
3568
+ "z-[9999] rounded-xl shadow-2xl p-3 w-[220px]",
3523
3569
  "bg-[#0f1117] border border-white/10",
3524
3570
  "focus:outline-none"
3525
3571
  ),
@@ -3534,9 +3580,9 @@ function HslColorInput({ value, onChange, className, inputClassName, disabled })
3534
3580
  /* @__PURE__ */ jsx50(ColorPickerAlpha, {})
3535
3581
  ] })
3536
3582
  ] }),
3537
- /* @__PURE__ */ jsxs34("div", { className: "flex items-center gap-1.5", children: [
3583
+ /* @__PURE__ */ jsxs34("div", { className: "flex items-center gap-1.5 min-w-0", children: [
3538
3584
  /* @__PURE__ */ jsx50(ColorPickerOutput, {}),
3539
- /* @__PURE__ */ jsx50(ColorPickerFormat, {})
3585
+ /* @__PURE__ */ jsx50(ColorPickerFormat, { className: "min-w-0" })
3540
3586
  ] })
3541
3587
  ] }, hexValue)
3542
3588
  }