@fab1o978/react-ui 0.2.1 → 0.2.2

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.
@@ -9,7 +9,9 @@ var jsxRuntime = require('react/jsx-runtime');
9
9
  var ColorWheel_module_default = {
10
10
  root: "ColorWheel_module_root2",
11
11
  recents: "ColorWheel_module_recents2",
12
+ recentsEmpty: "ColorWheel_module_recentsEmpty2",
12
13
  chipWrap: "ColorWheel_module_chipWrap2",
14
+ chipWrapRemoving: "ColorWheel_module_chipWrapRemoving2",
13
15
  chip: "ColorWheel_module_chip2",
14
16
  chipRemove: "ColorWheel_module_chipRemove2",
15
17
  picker: "ColorWheel_module_picker2",
@@ -268,6 +270,11 @@ var ARC_A1 = 150;
268
270
  var ARC_HANDLE_R_FRAC = 152 / 380;
269
271
  var PICKER_HEIGHT_WITH_ARC = 265;
270
272
  var PICKER_HEIGHT_NO_ARC = 224;
273
+ var CHIP_SIZE = 26;
274
+ var CHIP_GAP = 7;
275
+ function recentsContentWidth(chipCount) {
276
+ return chipCount > 0 ? chipCount * CHIP_SIZE + (chipCount - 1) * CHIP_GAP : 0;
277
+ }
271
278
  var MODES_HSV = ["h", "s", "v"];
272
279
  var MODES_HSVA = ["h", "s", "v", "a"];
273
280
  function ringGradient(mode, hsv) {
@@ -313,6 +320,15 @@ function ColorWheel({
313
320
  const [editing, setEditing] = react.useState(false);
314
321
  const [editValue, setEditValue] = react.useState("");
315
322
  const [eyedropperSupported, setEyedropperSupported] = react.useState(false);
323
+ const [removingHexes, setRemovingHexes] = react.useState(/* @__PURE__ */ new Set());
324
+ const [recentsGrown, setRecentsGrown] = react.useState(false);
325
+ const recentsGrowRaf = react.useRef(0);
326
+ react.useEffect(() => {
327
+ recentsGrowRaf.current = requestAnimationFrame(() => {
328
+ recentsGrowRaf.current = requestAnimationFrame(() => setRecentsGrown(true));
329
+ });
330
+ return () => cancelAnimationFrame(recentsGrowRaf.current);
331
+ }, []);
316
332
  const accentVars = accent ? accentToCssVars(deriveAccent(accent), "colorwheel") : {};
317
333
  const lastEmitted = react.useRef(value);
318
334
  react.useEffect(() => {
@@ -508,6 +524,15 @@ function ColorWheel({
508
524
  if (next) commit(next.hsv, next.a);
509
525
  }
510
526
  function removeFavorite(hex) {
527
+ setRemovingHexes((prev) => new Set(prev).add(hex));
528
+ }
529
+ function handleChipRemoveEnd(hex) {
530
+ setRemovingHexes((prev) => {
531
+ if (!prev.has(hex)) return prev;
532
+ const next = new Set(prev);
533
+ next.delete(hex);
534
+ return next;
535
+ });
511
536
  onFavoritesChange?.(favorites.filter((h) => h !== hex));
512
537
  }
513
538
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -521,32 +546,56 @@ function ColorWheel({
521
546
  ...size !== 1 ? { transform: `scale(${size})`, transformOrigin: "top center" } : void 0
522
547
  },
523
548
  children: [
524
- favorites.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: ColorWheel_module_default.recents, children: favorites.map((hex, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ColorWheel_module_default.chipWrap, style: { animationDelay: `${i * 0.02}s` }, children: [
525
- /* @__PURE__ */ jsxRuntime.jsx(
526
- "button",
527
- {
528
- type: "button",
529
- className: ColorWheel_module_default.chip,
530
- style: { background: hex.length > 7 ? hex.slice(0, 7) : hex },
531
- title: hex,
532
- "aria-label": `Apply color ${hex}`,
533
- onClick: () => applyFavorite(hex)
534
- }
535
- ),
536
- /* @__PURE__ */ jsxRuntime.jsx(
537
- "button",
538
- {
539
- type: "button",
540
- className: ColorWheel_module_default.chipRemove,
541
- "aria-label": `Remove ${hex} from favorites`,
542
- onClick: (e) => {
543
- e.stopPropagation();
544
- removeFavorite(hex);
545
- },
546
- children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 6l12 12M18 6L6 18" }) })
547
- }
548
- )
549
- ] }, hex + i)) }),
549
+ (favorites.length > 0 || onFavoritesChange) && /* @__PURE__ */ jsxRuntime.jsx(
550
+ "div",
551
+ {
552
+ className: [ColorWheel_module_default.recents, favorites.length === 0 ? ColorWheel_module_default.recentsEmpty : ""].join(" "),
553
+ style: { width: recentsGrown ? recentsContentWidth(favorites.length) : 0 },
554
+ children: favorites.map((hex, i) => (
555
+ // keyed by hex alone (not index) so an add/remove -- which
556
+ // shifts every other item's index -- doesn't remount and replay
557
+ // the entrance animation on chips that were already there; only
558
+ // a genuinely new hex mounts fresh and animates in
559
+ /* @__PURE__ */ jsxRuntime.jsxs(
560
+ "div",
561
+ {
562
+ className: [ColorWheel_module_default.chipWrap, removingHexes.has(hex) ? ColorWheel_module_default.chipWrapRemoving : ""].join(" "),
563
+ style: { animationDelay: removingHexes.has(hex) ? void 0 : `${i * 0.05}s` },
564
+ onAnimationEnd: (e) => {
565
+ if (e.target === e.currentTarget && e.animationName.includes("chipOut")) handleChipRemoveEnd(hex);
566
+ },
567
+ children: [
568
+ /* @__PURE__ */ jsxRuntime.jsx(
569
+ "button",
570
+ {
571
+ type: "button",
572
+ className: ColorWheel_module_default.chip,
573
+ style: { background: hex.length > 7 ? hex.slice(0, 7) : hex },
574
+ title: hex,
575
+ "aria-label": `Apply color ${hex}`,
576
+ onClick: () => applyFavorite(hex)
577
+ }
578
+ ),
579
+ /* @__PURE__ */ jsxRuntime.jsx(
580
+ "button",
581
+ {
582
+ type: "button",
583
+ className: ColorWheel_module_default.chipRemove,
584
+ "aria-label": `Remove ${hex} from favorites`,
585
+ onClick: (e) => {
586
+ e.stopPropagation();
587
+ removeFavorite(hex);
588
+ },
589
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 6l12 12M18 6L6 18" }) })
590
+ }
591
+ )
592
+ ]
593
+ },
594
+ hex
595
+ )
596
+ ))
597
+ }
598
+ ),
550
599
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ColorWheel_module_default.picker, style: { height: arcVisible ? PICKER_HEIGHT_WITH_ARC : PICKER_HEIGHT_NO_ARC }, children: [
551
600
  /* @__PURE__ */ jsxRuntime.jsx(
552
601
  "div",