@caratlogic/design-system 0.1.8 → 0.1.10

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/ui.esm.js CHANGED
@@ -3334,33 +3334,39 @@ const Toaster = ({ theme = 'system', ...props }) => (jsx(Toaster$1, { theme: the
3334
3334
  },
3335
3335
  }, ...props }));
3336
3336
 
3337
- const SIZE_MAP = {
3338
- sm: {
3339
- track: { width: 28, height: 16 },
3340
- thumb: 12,
3341
- on: 14,
3342
- off: 2,
3343
- },
3344
- md: {
3345
- track: { width: 44, height: 24 },
3346
- thumb: 20,
3347
- on: 22,
3348
- off: 2,
3349
- },
3350
- lg: {
3351
- track: { width: 52, height: 28 },
3352
- thumb: 24,
3353
- on: 26,
3354
- off: 2,
3355
- },
3337
+ /** 1px border on the track, and the gap between thumb and track. */
3338
+ const TRACK_BORDER = 1;
3339
+ const THUMB_INSET = 2;
3340
+ const TRACK_SIZE = {
3341
+ sm: { width: 28, height: 16 },
3342
+ md: { width: 44, height: 24 },
3343
+ lg: { width: 52, height: 28 },
3356
3344
  };
3345
+ /**
3346
+ * Thumb size and travel are derived from the track rather than listed per size:
3347
+ * hardcoding them left the thumb 1px from the top and bottom but flush against
3348
+ * the inner right edge when on, so it bulged past the track's rounded end.
3349
+ * Deriving keeps the inset equal on all four sides at every size.
3350
+ */
3351
+ function switchGeometry(size) {
3352
+ const track = TRACK_SIZE[size];
3353
+ const innerWidth = track.width - TRACK_BORDER * 2;
3354
+ const innerHeight = track.height - TRACK_BORDER * 2;
3355
+ const thumb = innerHeight - THUMB_INSET * 2;
3356
+ return {
3357
+ track,
3358
+ thumb,
3359
+ off: THUMB_INSET,
3360
+ on: innerWidth - thumb - THUMB_INSET,
3361
+ };
3362
+ }
3357
3363
  const Switch = t.forwardRef(({ checked = false, onCheckedChange, disabled = false, id, name, className, size = 'md', 'aria-label': ariaLabel, }, ref) => {
3358
3364
  const handleClick = () => {
3359
3365
  if (!disabled && onCheckedChange) {
3360
3366
  onCheckedChange(!checked);
3361
3367
  }
3362
3368
  };
3363
- const dims = SIZE_MAP[size];
3369
+ const dims = switchGeometry(size);
3364
3370
  return (jsx("button", { type: "button", role: "switch", "aria-checked": checked, "aria-label": ariaLabel, "data-state": checked ? 'checked' : 'unchecked', disabled: disabled, onClick: handleClick, ref: ref, id: id, name: name, style: {
3365
3371
  width: dims.track.width,
3366
3372
  height: dims.track.height,