@andreagiugni/tailwind-dashboard-ui 1.0.4 → 1.0.5

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.cts CHANGED
@@ -519,8 +519,8 @@ interface RadioSmProps {
519
519
  }
520
520
  declare const RadioSm: React.FC<RadioSmProps>;
521
521
 
522
- interface SwitchProps {
523
- label: string;
522
+ interface SwitchProps extends Omit<React.LabelHTMLAttributes<HTMLLabelElement>, "onChange" | "color"> {
523
+ label?: React.ReactNode;
524
524
  checked?: boolean;
525
525
  defaultChecked?: boolean;
526
526
  disabled?: boolean;
package/dist/index.d.ts CHANGED
@@ -519,8 +519,8 @@ interface RadioSmProps {
519
519
  }
520
520
  declare const RadioSm: React.FC<RadioSmProps>;
521
521
 
522
- interface SwitchProps {
523
- label: string;
522
+ interface SwitchProps extends Omit<React.LabelHTMLAttributes<HTMLLabelElement>, "onChange" | "color"> {
523
+ label?: React.ReactNode;
524
524
  checked?: boolean;
525
525
  defaultChecked?: boolean;
526
526
  disabled?: boolean;
package/dist/index.js CHANGED
@@ -626,6 +626,8 @@ var Input = ({
626
626
  style,
627
627
  ...rest
628
628
  }) => {
629
+ const placeholder = typeof rest.placeholder === "string" ? rest.placeholder.trim() : "";
630
+ const placeholderMinWidth = placeholder ? `${Math.min(Math.max(placeholder.length + 6, 18), 40)}ch` : void 0;
629
631
  const stateClass = disabled ? "text-gray-500 border-gray-300 cursor-not-allowed dark:bg-gray-800 dark:text-gray-400 dark:border-gray-700" : error ? "text-error-800 border-error-500 focus:ring-3 focus:ring-error-500/10 dark:text-error-400 dark:border-error-500" : success ? "text-success-500 border-success-400 focus:ring-success-500/10 focus:border-success-300 dark:text-success-400 dark:border-success-500" : "text-gray-800 border-gray-300 focus:border-brand-300 focus:ring-3 focus:ring-brand-500/10 dark:border-gray-700 dark:text-white/90 dark:focus:border-brand-800";
630
632
  return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
631
633
  /* @__PURE__ */ jsx(
@@ -637,7 +639,11 @@ var Input = ({
637
639
  stateClass,
638
640
  className
639
641
  ),
640
- style: { ...styleOverride({ bgColor, textColor, borderColor }), ...style },
642
+ style: {
643
+ minWidth: placeholderMinWidth,
644
+ ...styleOverride({ bgColor, textColor, borderColor }),
645
+ ...style
646
+ },
641
647
  ...rest
642
648
  }
643
649
  ),
@@ -801,7 +807,7 @@ function DataDrivenTable({
801
807
  setSearch(e.target.value);
802
808
  setPage(1);
803
809
  },
804
- className: "max-w-[220px]"
810
+ className: "sm:w-auto"
805
811
  }
806
812
  )
807
813
  ] }),
@@ -2214,7 +2220,12 @@ var Switch = ({
2214
2220
  defaultChecked = false,
2215
2221
  disabled = false,
2216
2222
  onChange,
2217
- color = "blue"
2223
+ color = "blue",
2224
+ className,
2225
+ onClick,
2226
+ onKeyDown,
2227
+ "aria-label": ariaLabel,
2228
+ ...rest
2218
2229
  }) => {
2219
2230
  const isControlled = checked !== void 0;
2220
2231
  const [internalChecked, setInternalChecked] = useState(defaultChecked);
@@ -2229,6 +2240,20 @@ var Switch = ({
2229
2240
  onChange(newCheckedState);
2230
2241
  }
2231
2242
  };
2243
+ const handleClick = (event) => {
2244
+ onClick?.(event);
2245
+ if (!event.defaultPrevented) {
2246
+ handleToggle();
2247
+ }
2248
+ };
2249
+ const handleKeyDown = (event) => {
2250
+ onKeyDown?.(event);
2251
+ if (event.defaultPrevented) return;
2252
+ if (event.key === " " || event.key === "Enter") {
2253
+ event.preventDefault();
2254
+ handleToggle();
2255
+ }
2256
+ };
2232
2257
  const offTrack = "bg-gray-200 ring-1 ring-inset ring-gray-300 dark:bg-white/10 dark:ring-gray-700";
2233
2258
  const switchColors = color === "blue" ? {
2234
2259
  background: isChecked ? "bg-brand-500 " : offTrack,
@@ -2239,14 +2264,23 @@ var Switch = ({
2239
2264
  // Gray version
2240
2265
  knob: isChecked ? "translate-x-full bg-white" : "translate-x-0 bg-white"
2241
2266
  };
2267
+ const hasLabel = label !== void 0 && label !== null && label !== "";
2242
2268
  return /* @__PURE__ */ jsxs(
2243
2269
  "label",
2244
2270
  {
2271
+ role: "switch",
2272
+ "aria-checked": isChecked,
2273
+ "aria-disabled": disabled || void 0,
2274
+ "aria-label": ariaLabel ?? (!hasLabel ? "Toggle switch" : void 0),
2275
+ tabIndex: disabled ? -1 : 0,
2245
2276
  className: cn(
2246
2277
  "flex cursor-pointer select-none items-center gap-3 text-sm font-medium",
2247
- disabled ? "text-gray-400" : "text-gray-700 dark:text-gray-400"
2278
+ disabled ? "text-gray-400" : "text-gray-700 dark:text-gray-400",
2279
+ className
2248
2280
  ),
2249
- onClick: handleToggle,
2281
+ onClick: handleClick,
2282
+ onKeyDown: handleKeyDown,
2283
+ ...rest,
2250
2284
  children: [
2251
2285
  /* @__PURE__ */ jsxs("div", { className: "relative", children: [
2252
2286
  /* @__PURE__ */ jsx(
@@ -2268,7 +2302,7 @@ var Switch = ({
2268
2302
  }
2269
2303
  )
2270
2304
  ] }),
2271
- label
2305
+ hasLabel && /* @__PURE__ */ jsx("span", { children: label })
2272
2306
  ]
2273
2307
  }
2274
2308
  );