@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/README.md CHANGED
@@ -203,7 +203,7 @@ Legend: **(+native)** = also extends the element's native HTML attributes.
203
203
  | `MultiSelect` | `options`, `selected` / `defaultSelected`, `onChange`, `placeholder`, `disabled` |
204
204
  | `Checkbox` | `label`, `checked`, `onChange(checked)`, `disabled`, `checkedColor?` |
205
205
  | `Radio` / `RadioSm` | `id`, `name`, `value`, `checked`, `label`, `onChange(value)`, `disabled` |
206
- | `Switch` | `label`, `checked` / `defaultChecked`, `onChange(checked)`, `color` (blue/gray), `disabled` |
206
+ | `Switch` | `label?`, `checked` / `defaultChecked`, `onChange(checked)`, `color` (blue/gray), `disabled` |
207
207
  | `TextArea` | `value`, `onChange`, `rows`, `success`, `error`, `hint`, `disabled` |
208
208
  | `FileInput` | `onChange`, `accept`, `multiple`, (+native input) |
209
209
  | `PasswordInput` | password field with a show/hide eye toggle, (+native input attrs) |
package/dist/index.cjs CHANGED
@@ -632,6 +632,8 @@ var Input = ({
632
632
  style,
633
633
  ...rest
634
634
  }) => {
635
+ const placeholder = typeof rest.placeholder === "string" ? rest.placeholder.trim() : "";
636
+ const placeholderMinWidth = placeholder ? `${Math.min(Math.max(placeholder.length + 6, 18), 40)}ch` : void 0;
635
637
  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";
636
638
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
637
639
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -643,7 +645,11 @@ var Input = ({
643
645
  stateClass,
644
646
  className
645
647
  ),
646
- style: { ...styleOverride({ bgColor, textColor, borderColor }), ...style },
648
+ style: {
649
+ minWidth: placeholderMinWidth,
650
+ ...styleOverride({ bgColor, textColor, borderColor }),
651
+ ...style
652
+ },
647
653
  ...rest
648
654
  }
649
655
  ),
@@ -807,7 +813,7 @@ function DataDrivenTable({
807
813
  setSearch(e.target.value);
808
814
  setPage(1);
809
815
  },
810
- className: "max-w-[220px]"
816
+ className: "sm:w-auto"
811
817
  }
812
818
  )
813
819
  ] }),
@@ -2220,7 +2226,12 @@ var Switch = ({
2220
2226
  defaultChecked = false,
2221
2227
  disabled = false,
2222
2228
  onChange,
2223
- color = "blue"
2229
+ color = "blue",
2230
+ className,
2231
+ onClick,
2232
+ onKeyDown,
2233
+ "aria-label": ariaLabel,
2234
+ ...rest
2224
2235
  }) => {
2225
2236
  const isControlled = checked !== void 0;
2226
2237
  const [internalChecked, setInternalChecked] = React5.useState(defaultChecked);
@@ -2235,6 +2246,20 @@ var Switch = ({
2235
2246
  onChange(newCheckedState);
2236
2247
  }
2237
2248
  };
2249
+ const handleClick = (event) => {
2250
+ onClick?.(event);
2251
+ if (!event.defaultPrevented) {
2252
+ handleToggle();
2253
+ }
2254
+ };
2255
+ const handleKeyDown = (event) => {
2256
+ onKeyDown?.(event);
2257
+ if (event.defaultPrevented) return;
2258
+ if (event.key === " " || event.key === "Enter") {
2259
+ event.preventDefault();
2260
+ handleToggle();
2261
+ }
2262
+ };
2238
2263
  const offTrack = "bg-gray-200 ring-1 ring-inset ring-gray-300 dark:bg-white/10 dark:ring-gray-700";
2239
2264
  const switchColors = color === "blue" ? {
2240
2265
  background: isChecked ? "bg-brand-500 " : offTrack,
@@ -2245,14 +2270,23 @@ var Switch = ({
2245
2270
  // Gray version
2246
2271
  knob: isChecked ? "translate-x-full bg-white" : "translate-x-0 bg-white"
2247
2272
  };
2273
+ const hasLabel = label !== void 0 && label !== null && label !== "";
2248
2274
  return /* @__PURE__ */ jsxRuntime.jsxs(
2249
2275
  "label",
2250
2276
  {
2277
+ role: "switch",
2278
+ "aria-checked": isChecked,
2279
+ "aria-disabled": disabled || void 0,
2280
+ "aria-label": ariaLabel ?? (!hasLabel ? "Toggle switch" : void 0),
2281
+ tabIndex: disabled ? -1 : 0,
2251
2282
  className: chunkYERNSNT4_cjs.cn(
2252
2283
  "flex cursor-pointer select-none items-center gap-3 text-sm font-medium",
2253
- disabled ? "text-gray-400" : "text-gray-700 dark:text-gray-400"
2284
+ disabled ? "text-gray-400" : "text-gray-700 dark:text-gray-400",
2285
+ className
2254
2286
  ),
2255
- onClick: handleToggle,
2287
+ onClick: handleClick,
2288
+ onKeyDown: handleKeyDown,
2289
+ ...rest,
2256
2290
  children: [
2257
2291
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
2258
2292
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -2274,7 +2308,7 @@ var Switch = ({
2274
2308
  }
2275
2309
  )
2276
2310
  ] }),
2277
- label
2311
+ hasLabel && /* @__PURE__ */ jsxRuntime.jsx("span", { children: label })
2278
2312
  ]
2279
2313
  }
2280
2314
  );