@platned/ui 0.10.3 → 0.10.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.cjs CHANGED
@@ -6370,13 +6370,21 @@ var Slider = (0, import_react40.forwardRef)(function Slider2({
6370
6370
  disabled = false,
6371
6371
  id,
6372
6372
  className,
6373
+ style,
6373
6374
  ...props
6374
6375
  }, ref) {
6375
6376
  const generatedId = (0, import_react40.useId)();
6376
6377
  const controlId = id ?? generatedId;
6377
6378
  const descriptionId = `${controlId}-description`;
6378
- const current = value ?? defaultValue ?? min;
6379
+ const [uncontrolled, setUncontrolled] = (0, import_react40.useState)(defaultValue ?? min);
6380
+ const current = value ?? uncontrolled;
6379
6381
  const display = formatValue ? formatValue(current) : String(current);
6382
+ const ratio = max > min ? Math.min(1, Math.max(0, (current - min) / (max - min))) : 0;
6383
+ const trackVars = {
6384
+ "--slider-fill": `calc(0.5rem + (100% - 1rem) * ${ratio})`,
6385
+ "--slider-fill-color": disabled ? "var(--color-background-disabled-default)" : "var(--color-background-brand-default)",
6386
+ "--slider-track-color": "var(--color-background-default-tertiary)"
6387
+ };
6380
6388
  return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: (0, import_clsx45.default)("flex w-full flex-col gap-1.5", className), children: [
6381
6389
  (label || showValue) && /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex items-baseline justify-between gap-2", children: [
6382
6390
  label && /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
@@ -6411,23 +6419,32 @@ var Slider = (0, import_react40.forwardRef)(function Slider2({
6411
6419
  disabled,
6412
6420
  "aria-describedby": description ? descriptionId : void 0,
6413
6421
  "aria-valuetext": formatValue ? display : void 0,
6414
- onChange: (event) => onValueChange?.(Number(event.target.value)),
6422
+ onChange: (event) => {
6423
+ const next = Number(event.target.value);
6424
+ if (value === void 0) setUncontrolled(next);
6425
+ onValueChange?.(next);
6426
+ },
6427
+ style: { ...trackVars, ...style },
6415
6428
  className: (0, import_clsx45.default)(
6416
6429
  "h-5 w-full cursor-pointer appearance-none bg-transparent",
6417
6430
  "focus-visible:outline-none",
6418
- disabled && "cursor-not-allowed opacity-50",
6419
- // Track
6420
- "[&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-default-tertiary",
6421
- "[&::-moz-range-track]:h-1.5 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-default-tertiary",
6422
- "[&::-moz-range-progress]:h-1.5 [&::-moz-range-progress]:rounded-full [&::-moz-range-progress]:bg-brand",
6423
- // Thumb. The negative margin centres it on the track, since the input box is
6424
- // taller than the track to keep a comfortable pointer target.
6425
- "[&::-webkit-slider-thumb]:-mt-[7px] [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-brand [&::-webkit-slider-thumb]:bg-default [&::-webkit-slider-thumb]:shadow-100",
6426
- "[&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-brand [&::-moz-range-thumb]:bg-default",
6431
+ disabled && "cursor-not-allowed",
6432
+ // Track: filled (brand) up to the thumb, unfilled (grey) after it, as in Figma.
6433
+ "[&::-webkit-slider-runnable-track]:h-1 [&::-webkit-slider-runnable-track]:rounded-full",
6434
+ "[&::-webkit-slider-runnable-track]:[background:linear-gradient(to_right,var(--slider-fill-color)_var(--slider-fill),var(--slider-track-color)_var(--slider-fill))]",
6435
+ "rtl:[&::-webkit-slider-runnable-track]:[background:linear-gradient(to_left,var(--slider-fill-color)_var(--slider-fill),var(--slider-track-color)_var(--slider-fill))]",
6436
+ "[&::-moz-range-track]:h-1 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:[background:var(--slider-track-color)]",
6437
+ "[&::-moz-range-progress]:h-1 [&::-moz-range-progress]:rounded-full [&::-moz-range-progress]:[background:var(--slider-fill-color)]",
6438
+ // Thumb: a solid knob in the fill colour (grey when disabled). The negative margin
6439
+ // centres it on the 4px track; the input box is taller to keep a comfortable target.
6440
+ "[&::-webkit-slider-thumb]:-mt-1.5 [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-0 [&::-webkit-slider-thumb]:[background:var(--slider-fill-color)] [&::-webkit-slider-thumb]:shadow-100",
6441
+ "[&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:[background:var(--slider-fill-color)]",
6427
6442
  // Focus ring on the thumb, not the whole 100%-wide input — a ring around the
6428
- // full track reads as the row being focused rather than the handle.
6429
- "focus-visible:[&::-webkit-slider-thumb]:ring-2 focus-visible:[&::-webkit-slider-thumb]:ring-brand focus-visible:[&::-webkit-slider-thumb]:ring-offset-1",
6430
- "focus-visible:[&::-moz-range-thumb]:ring-2 focus-visible:[&::-moz-range-thumb]:ring-brand"
6443
+ // full track reads as the row being focused rather than the handle. Written as
6444
+ // `:focus-visible::thumb`: the `focus-visible:` prefix would emit
6445
+ // `::thumb:focus-visible`, a pseudo-class after a pseudo-element, which browsers drop.
6446
+ "[&:focus-visible::-webkit-slider-thumb]:ring-2 [&:focus-visible::-webkit-slider-thumb]:ring-brand [&:focus-visible::-webkit-slider-thumb]:ring-offset-1",
6447
+ "[&:focus-visible::-moz-range-thumb]:ring-2 [&:focus-visible::-moz-range-thumb]:ring-brand"
6431
6448
  ),
6432
6449
  ...props
6433
6450
  }