@webdevarif/dashui 0.3.7 → 0.3.9

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.d.mts CHANGED
@@ -572,7 +572,7 @@ declare const ColorPickerHexOutput: ({ className, ...props }: HTMLAttributes<HTM
572
572
  declare const ColorPickerEyeDropper: ({ className, ...props }: HTMLAttributes<HTMLButtonElement>) => react_jsx_runtime.JSX.Element;
573
573
  type ColorPickerOutputProps = HTMLAttributes<HTMLDivElement>;
574
574
  declare const ColorPickerOutput: ({ className, ...props }: ColorPickerOutputProps) => react_jsx_runtime.JSX.Element;
575
- type ColorPickerFormatProps = HTMLAttributes<HTMLDivElement>;
575
+ type ColorPickerFormatProps = HTMLAttributes<HTMLInputElement>;
576
576
  declare const ColorPickerFormat: ({ className, ...props }: ColorPickerFormatProps) => react_jsx_runtime.JSX.Element;
577
577
 
578
578
  declare function useDisclosure(initial?: boolean): {
package/dist/index.d.ts CHANGED
@@ -572,7 +572,7 @@ declare const ColorPickerHexOutput: ({ className, ...props }: HTMLAttributes<HTM
572
572
  declare const ColorPickerEyeDropper: ({ className, ...props }: HTMLAttributes<HTMLButtonElement>) => react_jsx_runtime.JSX.Element;
573
573
  type ColorPickerOutputProps = HTMLAttributes<HTMLDivElement>;
574
574
  declare const ColorPickerOutput: ({ className, ...props }: ColorPickerOutputProps) => react_jsx_runtime.JSX.Element;
575
- type ColorPickerFormatProps = HTMLAttributes<HTMLDivElement>;
575
+ type ColorPickerFormatProps = HTMLAttributes<HTMLInputElement>;
576
576
  declare const ColorPickerFormat: ({ className, ...props }: ColorPickerFormatProps) => react_jsx_runtime.JSX.Element;
577
577
 
578
578
  declare function useDisclosure(initial?: boolean): {
package/dist/index.js CHANGED
@@ -3529,42 +3529,79 @@ var ColorPickerEyeDropper = ({ className, ...props }) => {
3529
3529
  };
3530
3530
  var ColorPickerOutput = ({ className, ...props }) => {
3531
3531
  const { mode, setMode } = useColorPicker();
3532
- return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
3533
- "select",
3534
- {
3535
- value: mode,
3536
- onChange: (e) => setMode(e.target.value),
3537
- className: cn(
3538
- "h-7 bg-white/5 border border-white/10 rounded-md text-xs text-white/60 px-1.5 outline-none",
3539
- "hover:border-white/20 focus:border-white/30 cursor-pointer shrink-0",
3540
- className
3541
- ),
3542
- children: ["HEX", "HSL", "RGB"].map((f) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("option", { value: f, className: "bg-[#1a1c2e]", children: f }, f))
3543
- }
3544
- );
3532
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(Select, { value: mode, onValueChange: setMode, children: [
3533
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(SelectTrigger, { className: cn("h-7 w-[4.5rem] shrink-0 text-xs px-2 border-white/10 bg-white/5 rounded-md", className), children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(SelectValue, {}) }),
3534
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(SelectContent, { children: ["HEX", "HSL", "RGB"].map((f) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(SelectItem, { value: f, className: "text-xs", children: f }, f)) })
3535
+ ] });
3545
3536
  };
3546
3537
  var ColorPickerFormat = ({ className, ...props }) => {
3547
- const { hue, saturation, lightness, alpha, mode } = useColorPicker();
3548
- let displayValue = "";
3549
- try {
3550
- const c = import_color.default.hsl(hue, saturation, lightness).alpha(alpha / 100);
3551
- if (mode === "HEX") displayValue = c.hex();
3552
- else if (mode === "HSL") displayValue = `${Math.round(hue)} ${Math.round(saturation)}% ${Math.round(lightness)}%`;
3553
- else if (mode === "RGB") {
3554
- const rgb = c.rgb().array().map(Math.round);
3555
- displayValue = `${rgb[0]}, ${rgb[1]}, ${rgb[2]}`;
3538
+ const { hue, saturation, lightness, alpha, mode, setHue, setSaturation, setLightness, setAlpha } = useColorPicker();
3539
+ const [focused, setFocused] = (0, import_react.useState)(false);
3540
+ const [localVal, setLocalVal] = (0, import_react.useState)("");
3541
+ const computedVal = (() => {
3542
+ try {
3543
+ const c = import_color.default.hsl(hue, saturation, lightness).alpha(alpha / 100);
3544
+ if (mode === "HEX") return c.hex().toUpperCase();
3545
+ if (mode === "HSL") return `${Math.round(hue)} ${Math.round(saturation)}% ${Math.round(lightness)}%`;
3546
+ if (mode === "RGB") {
3547
+ const [r, g, b] = c.rgb().array().map(Math.round);
3548
+ return `${r}, ${g}, ${b}`;
3549
+ }
3550
+ } catch {
3556
3551
  }
3557
- } catch {
3558
- displayValue = "";
3559
- }
3552
+ return "";
3553
+ })();
3554
+ (0, import_react.useEffect)(() => {
3555
+ if (!focused) setLocalVal(computedVal);
3556
+ }, [computedVal, focused]);
3557
+ const tryApply = (raw) => {
3558
+ try {
3559
+ if (mode === "HEX") {
3560
+ const hex = raw.startsWith("#") ? raw : `#${raw}`;
3561
+ const c = (0, import_color.default)(hex);
3562
+ setHue(c.hue());
3563
+ setSaturation(c.saturationl());
3564
+ setLightness(c.lightness());
3565
+ setAlpha(c.alpha() * 100);
3566
+ } else if (mode === "HSL") {
3567
+ const parts = raw.split(/[\s,%]+/).filter(Boolean);
3568
+ if (parts.length >= 3) {
3569
+ setHue(+parts[0]);
3570
+ setSaturation(+parts[1]);
3571
+ setLightness(+parts[2]);
3572
+ }
3573
+ } else if (mode === "RGB") {
3574
+ const parts = raw.split(/[\s,]+/).filter(Boolean);
3575
+ if (parts.length >= 3) {
3576
+ const c = import_color.default.rgb(+parts[0], +parts[1], +parts[2]);
3577
+ setHue(c.hue());
3578
+ setSaturation(c.saturationl());
3579
+ setLightness(c.lightness());
3580
+ }
3581
+ }
3582
+ } catch {
3583
+ }
3584
+ };
3560
3585
  return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
3561
3586
  "input",
3562
3587
  {
3563
- readOnly: true,
3564
3588
  type: "text",
3565
- value: displayValue,
3589
+ value: focused ? localVal : computedVal,
3590
+ onChange: (e) => {
3591
+ setLocalVal(e.target.value);
3592
+ tryApply(e.target.value);
3593
+ },
3594
+ onFocus: () => {
3595
+ setFocused(true);
3596
+ setLocalVal(computedVal);
3597
+ },
3598
+ onBlur: () => {
3599
+ tryApply(localVal);
3600
+ setFocused(false);
3601
+ },
3566
3602
  className: cn(
3567
- "flex-1 h-7 bg-white/5 border border-white/10 rounded-md px-2 text-xs text-white/50 font-mono outline-none",
3603
+ "flex-1 min-w-0 h-7 bg-white/5 border border-white/10 rounded-md px-2",
3604
+ "text-xs text-white/70 font-mono outline-none focus:border-white/30",
3568
3605
  className
3569
3606
  ),
3570
3607
  ...props
@@ -3662,7 +3699,7 @@ function HslColorInput({ value, onChange, className, inputClassName, disabled })
3662
3699
  sideOffset: 6,
3663
3700
  align: "start",
3664
3701
  className: cn(
3665
- "z-[9999] rounded-xl shadow-2xl p-3 w-[14rem]",
3702
+ "z-[9999] rounded-xl shadow-2xl p-3 w-[220px]",
3666
3703
  "bg-[#0f1117] border border-white/10",
3667
3704
  "focus:outline-none"
3668
3705
  ),
@@ -3677,9 +3714,9 @@ function HslColorInput({ value, onChange, className, inputClassName, disabled })
3677
3714
  /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(ColorPickerAlpha, {})
3678
3715
  ] })
3679
3716
  ] }),
3680
- /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)("div", { className: "flex items-center gap-1.5", children: [
3717
+ /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)("div", { className: "flex items-center gap-1.5 min-w-0", children: [
3681
3718
  /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(ColorPickerOutput, {}),
3682
- /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(ColorPickerFormat, {})
3719
+ /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(ColorPickerFormat, { className: "min-w-0" })
3683
3720
  ] })
3684
3721
  ] }, hexValue)
3685
3722
  }