@adam-milo/ui 1.0.23 → 1.0.24

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.
Files changed (154) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +18 -9
  3. package/dist/index10.cjs +1 -1
  4. package/dist/index10.js +53 -59
  5. package/dist/index11.cjs +1 -1
  6. package/dist/index11.js +50 -104
  7. package/dist/index12.cjs +1 -1
  8. package/dist/index12.js +108 -76
  9. package/dist/index13.cjs +1 -1
  10. package/dist/index13.js +77 -26
  11. package/dist/index14.cjs +1 -1
  12. package/dist/index14.js +22 -462
  13. package/dist/index15.cjs +1 -1
  14. package/dist/index15.js +466 -109
  15. package/dist/index16.cjs +1 -1
  16. package/dist/index16.js +111 -30
  17. package/dist/index17.cjs +1 -1
  18. package/dist/index17.js +42 -12
  19. package/dist/index18.cjs +1 -0
  20. package/dist/index18.js +14 -0
  21. package/dist/index2.cjs +1 -1
  22. package/dist/index2.js +1 -1
  23. package/dist/index20.cjs +1 -1
  24. package/dist/index20.js +20 -299
  25. package/dist/index21.cjs +1 -1
  26. package/dist/index21.js +298 -13
  27. package/dist/index22.cjs +1 -0
  28. package/dist/index22.js +16 -0
  29. package/dist/index25.cjs +1 -0
  30. package/dist/index25.js +1193 -0
  31. package/dist/index3.cjs +1 -1
  32. package/dist/index3.js +2 -2
  33. package/dist/index33.cjs +1 -1
  34. package/dist/index33.js +7 -19
  35. package/dist/index36.cjs +1 -0
  36. package/dist/index36.js +21 -0
  37. package/dist/index38.cjs +1 -0
  38. package/dist/index38.js +6 -0
  39. package/dist/index39.cjs +1 -0
  40. package/dist/index39.js +11 -0
  41. package/dist/index4.cjs +1 -1
  42. package/dist/index4.js +1 -1
  43. package/dist/index40.cjs +1 -0
  44. package/dist/index40.js +70 -0
  45. package/dist/index41.cjs +1 -0
  46. package/dist/index41.js +39 -0
  47. package/dist/index42.cjs +1 -0
  48. package/dist/index42.js +64 -0
  49. package/dist/index43.cjs +1 -0
  50. package/dist/index43.js +10 -0
  51. package/dist/index44.cjs +1 -0
  52. package/dist/index44.js +212 -0
  53. package/dist/index45.cjs +1 -0
  54. package/dist/index45.js +29 -0
  55. package/dist/index46.cjs +1 -0
  56. package/dist/index46.js +208 -0
  57. package/dist/index47.cjs +1 -0
  58. package/dist/index47.js +14 -0
  59. package/dist/index48.cjs +1 -0
  60. package/dist/index48.js +293 -0
  61. package/dist/index49.cjs +1 -0
  62. package/dist/index49.js +18 -0
  63. package/dist/index5.cjs +1 -1
  64. package/dist/index5.js +1 -1
  65. package/dist/index50.cjs +1 -0
  66. package/dist/index50.js +43 -0
  67. package/dist/index51.cjs +1 -0
  68. package/dist/index51.js +89 -0
  69. package/dist/index52.cjs +1 -0
  70. package/dist/index52.js +14 -0
  71. package/dist/index53.cjs +1 -0
  72. package/dist/index53.js +71 -0
  73. package/dist/index54.cjs +1 -0
  74. package/dist/index54.js +6 -0
  75. package/dist/index55.cjs +1 -0
  76. package/dist/index55.js +14 -0
  77. package/dist/index56.cjs +1 -0
  78. package/dist/index56.js +34 -0
  79. package/dist/index57.cjs +1 -0
  80. package/dist/index57.js +122 -0
  81. package/dist/index58.cjs +1 -0
  82. package/dist/index58.js +11 -0
  83. package/dist/index59.cjs +1 -0
  84. package/dist/index59.js +17 -0
  85. package/dist/index6.cjs +1 -1
  86. package/dist/index6.js +2 -2
  87. package/dist/index60.cjs +1 -0
  88. package/dist/index60.js +297 -0
  89. package/dist/index61.cjs +1 -0
  90. package/dist/index61.js +25 -0
  91. package/dist/index62.cjs +1 -0
  92. package/dist/index62.js +39 -0
  93. package/dist/index63.cjs +1 -0
  94. package/dist/index63.js +625 -0
  95. package/dist/index64.cjs +1 -0
  96. package/dist/index64.js +39 -0
  97. package/dist/index65.cjs +1 -0
  98. package/dist/index65.js +38 -0
  99. package/dist/index66.cjs +1 -0
  100. package/dist/index66.js +7 -0
  101. package/dist/index67.cjs +1 -0
  102. package/dist/index67.js +10 -0
  103. package/dist/index68.cjs +1 -0
  104. package/dist/index68.js +5 -0
  105. package/dist/index69.cjs +1 -0
  106. package/dist/index69.js +35 -0
  107. package/dist/index7.cjs +1 -1
  108. package/dist/index7.js +1 -1
  109. package/dist/index70.cjs +1 -0
  110. package/dist/index70.js +180 -0
  111. package/dist/index71.cjs +1 -0
  112. package/dist/index71.js +21 -0
  113. package/dist/index72.cjs +1 -0
  114. package/dist/index72.js +721 -0
  115. package/dist/index73.cjs +1 -0
  116. package/dist/index73.js +154 -0
  117. package/dist/index74.cjs +1 -0
  118. package/dist/index74.js +173 -0
  119. package/dist/index75.cjs +1 -0
  120. package/dist/index75.js +88 -0
  121. package/dist/index76.cjs +1 -0
  122. package/dist/index76.js +47 -0
  123. package/dist/index77.cjs +1 -0
  124. package/dist/index77.js +13 -0
  125. package/dist/index78.cjs +1 -0
  126. package/dist/index78.js +19 -0
  127. package/dist/index79.cjs +1 -0
  128. package/dist/index79.js +102 -0
  129. package/dist/index8.cjs +1 -1
  130. package/dist/index8.js +1 -1
  131. package/dist/index80.cjs +1 -0
  132. package/dist/index80.js +11 -0
  133. package/dist/index81.cjs +1 -0
  134. package/dist/index81.js +29 -0
  135. package/dist/index82.cjs +1 -0
  136. package/dist/index82.js +16 -0
  137. package/dist/index83.cjs +1 -0
  138. package/dist/index83.js +48 -0
  139. package/dist/index84.cjs +1 -0
  140. package/dist/index84.js +9 -0
  141. package/dist/index85.cjs +1 -0
  142. package/dist/index85.js +37 -0
  143. package/dist/index9.cjs +1 -1
  144. package/dist/index9.js +224 -35
  145. package/dist/src/components/forms/select/Select.component.d.ts +100 -0
  146. package/dist/src/components/forms/select/Select.component.d.ts.map +1 -0
  147. package/dist/src/index.d.ts +2 -0
  148. package/dist/src/index.d.ts.map +1 -1
  149. package/dist/style.css +1 -1
  150. package/package.json +2 -1
  151. package/dist/index19.cjs +0 -1
  152. package/dist/index19.js +0 -22
  153. package/dist/index30.cjs +0 -1
  154. package/dist/index30.js +0 -9
package/dist/index15.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),t=require("@radix-ui/react-dialog"),o=require("./index17.cjs");function i(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const t in e)if("default"!==t){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(a,t,o.get?o:{enumerable:!0,get:()=>e[t]})}return a.default=e,Object.freeze(a)};/* empty css */const r=i(t),s=r.Root,d=r.Trigger,l=r.Portal,c=r.Close,n=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-overlay",c=i||"dialog-overlay";return e.jsx(r.Overlay,{ref:d,className:o.cn("dialog-overlay",a),"data-cy":l,"data-testid":c,...s})});n.displayName=r.Overlay.displayName;const g=a.forwardRef(({className:a,children:t,"data-cy":i,"data-testid":s,...d},c)=>{const g=i||"dialog-content",y=s||"dialog-content";return e.jsxs(l,{children:[e.jsx(n,{}),e.jsx(r.Content,{ref:c,className:o.cn("dialog-content",a),"data-cy":g,"data-testid":y,...d,children:t})]})});g.displayName=r.Content.displayName;const y=({className:a,"data-cy":t,"data-testid":i,...r})=>{const s=t||"dialog-header",d=i||"dialog-header";return e.jsx("div",{className:o.cn("dialog-header",a),"data-cy":s,"data-testid":d,...r})};y.displayName="DialogHeader";const p=({className:a,"data-cy":t,"data-testid":i,...r})=>{const s=t||"dialog-footer",d=i||"dialog-footer";return e.jsx("div",{className:o.cn("dialog-footer",a),"data-cy":s,"data-testid":d,...r})};p.displayName="DialogFooter";const m=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-title",c=i||"dialog-title";return e.jsx(r.Title,{ref:d,className:o.cn("dialog-title",a),"data-cy":l,"data-testid":c,...s})});m.displayName=r.Title.displayName;const f=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-description",c=i||"dialog-description";return e.jsx(r.Description,{ref:d,className:o.cn("dialog-description",a),"data-cy":l,"data-testid":c,...s})});f.displayName=r.Description.displayName,exports.Dialog=s,exports.DialogClose=c,exports.DialogContent=g,exports.DialogDescription=f,exports.DialogFooter=p,exports.DialogHeader=y,exports.DialogOverlay=n,exports.DialogPortal=l,exports.DialogTitle=m,exports.DialogTrigger=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),r=require("./index18.cjs"),a=require("./index14.cjs");;/* empty css */const i=require("./index33.cjs"),n=require("@adam-milo/icons"),l=(e,r,a,i,n)=>{const[l,o]=t.useState(e.length),u=t.useCallback(()=>{if(void 0!==n)return void o(Math.min(n,e.length));const t=r.current;if(!t)return;const l=t.clientWidth,u=parseFloat(getComputedStyle(document.documentElement).fontSize)||16,s=window.getComputedStyle(t),c=((e,t,r)=>{if(!e)return.5*t;const a=e.match(/^([\d.]+)(px|rem|em)?/);if(!a)return.5*t;const i=parseFloat(a[1]);switch(a[2]||"px"){case"px":return i;case"rem":return i*t;case"em":return i*r;default:return.5*t}})(s.gap,u,parseFloat(s.fontSize)||16),d=3.75*u;for(let r=0;r<e.length;r++){const t=e[r],n=a.current[r];n&&i.current.set(t.value,n.offsetWidth)}const p=((e,t,r,a,i)=>{let n=0,l=0;for(let o=0;o<e.length;o++){const u=e[o],s=t.get(u.value)||0;if(0===s){l++;break}const c=n+(o>0?a:0)+s;if(o<e.length-1){if(c+a+i>r&&l>0)break}else if(c>r&&l>0)break;n=c,l++}return Math.max(1,l)})(e,i.current,l,c,d);o(p)},[e,n,r,a,i]),s=((e,r)=>{const a=t.useRef();return t.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]),t.useCallback((...t)=>{a.current&&clearTimeout(a.current),a.current=setTimeout(()=>e(...t),r)},[e,r])})(u,100);t.useEffect(()=>{a.current.length>e.length&&(a.current=a.current.slice(0,e.length));const t=new Set(e.map(e=>e.value));if(i.current.forEach((e,r)=>{t.has(r)||i.current.delete(r)}),void 0===n){e.some(e=>!i.current.has(e.value))?o(e.length):setTimeout(u,0)}},[e,n,u,a,i]),t.useEffect(()=>{const e=r.current;if(!e)return;const t=new ResizeObserver(()=>{s()});return t.observe(e),setTimeout(u,0),()=>{t.disconnect()}},[u,s,r]);const c=e.slice(0,l),d=e.slice(l);return{visibleCount:l,visibleItems:c,hiddenItems:d,hasOverflow:d.length>0}},o=t.forwardRef(({items:o,selectedValue:u,onSelectionChange:s,removable:c=!1,onRemove:d,variant:p="primary",disabled:h=!1,maxVisible:v,className:m,"data-testid":f,"data-cy":g,...b},y)=>{const w=(o&&Array.isArray(o)?o:[]).filter(e=>null!=e&&"object"==typeof e),x=t.useRef(null),k=t.useRef([]),_=t.useRef(new Map),C=t.useRef(null),[E,j]=t.useState(!1),[N,$]=t.useState(!1),D=t.useRef([]),{visibleItems:S,hiddenItems:R,hasOverflow:I}=l(w,x,k,_,v),q=t.useCallback((e,t,r)=>{if(!h&&!t&&s){s(u===e?null:e,r)}},[h,u,s]),A=t.useCallback((e,t)=>{e.stopPropagation(),h||d&&d(t,e)},[h,d]),M=t.useCallback((e,t,r)=>{h||r||"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),q(t,r,e))},[h,q]),P=t.useCallback(e=>{e.stopPropagation(),$(e=>!e),j(!1)},[]),T=t.useCallback((e,t)=>{var r,a,i,n;switch(e.key){case"ArrowDown":e.preventDefault(),t<R.length-1&&(null==(r=D.current[t+1])||r.focus());break;case"ArrowUp":e.preventDefault(),t>0&&(null==(a=D.current[t-1])||a.focus());break;case"Home":e.preventDefault(),null==(i=D.current[0])||i.focus();break;case"End":e.preventDefault(),null==(n=D.current[R.length-1])||n.focus()}},[R.length]),z=t.useRef(),L=t.useRef();return t.useEffect(()=>{z.current=e=>{C.current&&!C.current.contains(e.target)&&$(!1)},L.current=e=>{"Escape"===e.key&&$(!1)}}),t.useEffect(()=>{if(!N)return;const e=e=>{var t;return null==(t=z.current)?void 0:t.call(z,e)},t=e=>{var t;return null==(t=L.current)?void 0:t.call(L,e)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[N]),t.useEffect(()=>{if("development"===process.env.NODE_ENV&&w.length>0){const e=w.map(e=>e.value),t=new Set(e);e.length!==t.size&&i.devWarn("[ChipGroup] Duplicate values detected in items array. Each item should have a unique value.")}},[w]),t.useEffect(()=>{D.current.length>R.length&&(D.current=D.current.slice(0,R.length))},[R]),o&&Array.isArray(o)?e.jsxs("div",{ref:y,className:r.cn("chip-group",h&&"chip-group--disabled",m),role:"group","aria-label":"Chip group","data-testid":f||"chip-group","data-cy":g||"chip-group",...b,children:[I&&e.jsxs("div",{className:"sr-only",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"chip-group-live-region","data-cy":"chip-group-live-region",children:[R.length," additional ",1===R.length?"chip":"chips"," hidden"]}),e.jsxs("div",{ref:x,className:"chip-group__container",children:[S.map(t=>{const r=u===t.value,i=t.variant||p,l=h||t.disabled||!1,o=w.findIndex(e=>e.value===t.value);return e.jsx("div",{ref:e=>{k.current[o]=e||null},className:"chip-group__item-wrapper","data-cy":`chip-group-item-wrapper-${t.value}`,"data-testid":`chip-group-item-wrapper-${t.value}`,children:e.jsxs("div",{className:"chip-group__item",onClick:e=>q(t.value,l,e),onKeyDown:e=>M(e,t.value,l),tabIndex:l?-1:0,role:"button","aria-pressed":r?"true":"false","aria-disabled":l?"true":"false","data-cy":`chip-group-item-${t.value}`,"data-testid":`chip-group-item-${t.value}`,children:[e.jsx(a.Chip,{variant:i,selected:r,disabled:l,"data-cy":`chip-${t.value}`,"data-testid":`chip-${t.value}`,children:t.label}),c&&!h&&!l&&e.jsx("button",{className:"chip-group__remove",onClick:e=>A(e,t.value),"aria-label":`Remove ${t.label}`,"data-cy":`chip-remove-${t.value}`,"data-testid":`chip-remove-${t.value}`,type:"button",children:e.jsx(n.Icon,{name:"Cross2Icon",size:"sm",decorative:!0})})]})},t.value)}),I&&e.jsxs("div",{ref:C,className:"chip-group__overflow",role:"button",tabIndex:0,"aria-expanded":N?"true":"false","aria-haspopup":"menu","aria-label":`Show ${R.length} more ${1===R.length?"chip":"chips"}`,onMouseEnter:()=>!N&&j(!0),onMouseLeave:()=>j(!1),onClick:P,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),e.stopPropagation(),$(!N),j(!1))},"data-cy":"chip-group-overflow","data-testid":"chip-group-overflow",children:[e.jsxs(a.Chip,{variant:p,"data-cy":"chip-overflow","data-testid":"chip-overflow",children:["+",R.length]}),E&&!N&&e.jsx("div",{className:"chip-group__tooltip chip-group__tooltip--hover",role:"tooltip","data-cy":"chip-group-tooltip","data-testid":"chip-group-tooltip",children:R.map(t=>e.jsx("div",{className:"chip-group__tooltip-item","data-cy":`chip-group-tooltip-item-${t.value}`,"data-testid":`chip-group-tooltip-item-${t.value}`,children:t.label},t.value))}),N&&e.jsx("div",{className:"chip-group__dropdown",role:"menu","data-cy":"chip-group-dropdown","data-testid":"chip-group-dropdown",children:R.map((t,a)=>e.jsx("div",{ref:e=>{D.current[a]=e||null},className:r.cn("chip-group__dropdown-item",t.disabled&&"chip-group__dropdown-item--disabled"),role:"menuitem",tabIndex:t.disabled?-1:0,"aria-disabled":t.disabled?"true":"false",onClick:e=>{e.stopPropagation(),t.disabled||(q(t.value,!1,e),$(!1))},onKeyDown:e=>{T(e,a),"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),e.stopPropagation(),t.disabled||(q(t.value,!1,e),$(!1)))},"data-cy":`chip-group-dropdown-item-${t.value}`,"data-testid":`chip-group-dropdown-item-${t.value}`,children:t.label},t.value))})]})]})]}):null});o.displayName="ChipGroup",exports.ChipGroup=o;
package/dist/index15.js CHANGED
@@ -1,125 +1,482 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import * as DialogPrimitive from "@radix-ui/react-dialog";
4
- import { cn } from "./index17.js";
2
+ import { forwardRef, useRef, useState, useCallback, useEffect } from "react";
3
+ import { cn } from "./index18.js";
4
+ import { Chip } from "./index14.js";
5
5
  /* empty css */
6
- const Dialog = DialogPrimitive.Root;
7
- const DialogTrigger = DialogPrimitive.Trigger;
8
- const DialogPortal = DialogPrimitive.Portal;
9
- const DialogClose = DialogPrimitive.Close;
10
- const DialogOverlay = forwardRef(({ className, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
11
- const finalDataCy = dataCy || "dialog-overlay";
12
- const finalTestId = dataTestId || "dialog-overlay";
13
- return /* @__PURE__ */ jsx(
14
- DialogPrimitive.Overlay,
15
- {
16
- ref,
17
- className: cn("dialog-overlay", className),
18
- "data-cy": finalDataCy,
19
- "data-testid": finalTestId,
20
- ...props
6
+ import { devWarn } from "./index33.js";
7
+ import { Icon } from "@adam-milo/icons";
8
+ const parseGapValue = (gapString, rootFontSize, containerFontSize) => {
9
+ if (!gapString) return 0.5 * rootFontSize;
10
+ const match = gapString.match(/^([\d.]+)(px|rem|em)?/);
11
+ if (!match) return 0.5 * rootFontSize;
12
+ const value = parseFloat(match[1]);
13
+ const unit = match[2] || "px";
14
+ switch (unit) {
15
+ case "px":
16
+ return value;
17
+ case "rem":
18
+ return value * rootFontSize;
19
+ case "em":
20
+ return value * containerFontSize;
21
+ default:
22
+ return 0.5 * rootFontSize;
23
+ }
24
+ };
25
+ const calculateFittingChips = (items, chipWidths, containerWidth, gap, overflowChipWidth) => {
26
+ let totalWidth = 0;
27
+ let count = 0;
28
+ for (let i = 0; i < items.length; i++) {
29
+ const item = items[i];
30
+ const chipWidth = chipWidths.get(item.value) || 0;
31
+ if (chipWidth === 0) {
32
+ count++;
33
+ break;
21
34
  }
22
- );
23
- });
24
- DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
25
- const DialogContent = forwardRef(({ className, children, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
26
- const finalDataCy = dataCy || "dialog-content";
27
- const finalTestId = dataTestId || "dialog-content";
28
- return /* @__PURE__ */ jsxs(DialogPortal, { children: [
29
- /* @__PURE__ */ jsx(DialogOverlay, {}),
30
- /* @__PURE__ */ jsx(
31
- DialogPrimitive.Content,
32
- {
33
- ref,
34
- className: cn("dialog-content", className),
35
- "data-cy": finalDataCy,
36
- "data-testid": finalTestId,
37
- ...props,
38
- children
39
- }
40
- )
41
- ] });
42
- });
43
- DialogContent.displayName = DialogPrimitive.Content.displayName;
44
- const DialogHeader = ({
45
- className,
46
- "data-cy": dataCy,
47
- "data-testid": dataTestId,
48
- ...props
49
- }) => {
50
- const finalDataCy = dataCy || "dialog-header";
51
- const finalTestId = dataTestId || "dialog-header";
52
- return /* @__PURE__ */ jsx(
53
- "div",
54
- {
55
- className: cn("dialog-header", className),
56
- "data-cy": finalDataCy,
57
- "data-testid": finalTestId,
58
- ...props
35
+ const gapBeforeThisChip = i > 0 ? gap : 0;
36
+ const widthWithThisChip = totalWidth + gapBeforeThisChip + chipWidth;
37
+ const hasMoreItems = i < items.length - 1;
38
+ if (hasMoreItems) {
39
+ const widthWithOverflow = widthWithThisChip + gap + overflowChipWidth;
40
+ if (widthWithOverflow > containerWidth && count > 0) break;
41
+ } else {
42
+ if (widthWithThisChip > containerWidth && count > 0) break;
59
43
  }
44
+ totalWidth = widthWithThisChip;
45
+ count++;
46
+ }
47
+ return Math.max(1, count);
48
+ };
49
+ const useDebounce = (callback, delay) => {
50
+ const timeoutRef = useRef();
51
+ useEffect(() => {
52
+ return () => {
53
+ if (timeoutRef.current) {
54
+ clearTimeout(timeoutRef.current);
55
+ }
56
+ };
57
+ }, []);
58
+ const debouncedFn = useCallback(
59
+ (...args) => {
60
+ if (timeoutRef.current) clearTimeout(timeoutRef.current);
61
+ timeoutRef.current = setTimeout(() => callback(...args), delay);
62
+ },
63
+ [callback, delay]
60
64
  );
65
+ return debouncedFn;
61
66
  };
62
- DialogHeader.displayName = "DialogHeader";
63
- const DialogFooter = ({
64
- className,
65
- "data-cy": dataCy,
66
- "data-testid": dataTestId,
67
- ...props
68
- }) => {
69
- const finalDataCy = dataCy || "dialog-footer";
70
- const finalTestId = dataTestId || "dialog-footer";
71
- return /* @__PURE__ */ jsx(
72
- "div",
73
- {
74
- className: cn("dialog-footer", className),
75
- "data-cy": finalDataCy,
76
- "data-testid": finalTestId,
77
- ...props
67
+ const useChipOverflow = (items, containerRef, chipRefs, chipWidths, maxVisible) => {
68
+ const [visibleCount, setVisibleCount] = useState(items.length);
69
+ const calculateVisibleChips = useCallback(() => {
70
+ if (maxVisible !== void 0) {
71
+ setVisibleCount(Math.min(maxVisible, items.length));
72
+ return;
78
73
  }
79
- );
74
+ const container = containerRef.current;
75
+ if (!container) return;
76
+ const containerWidth = container.clientWidth;
77
+ const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
78
+ const computedStyle = window.getComputedStyle(container);
79
+ const gapString = computedStyle.gap;
80
+ const containerFontSize = parseFloat(computedStyle.fontSize) || 16;
81
+ const gap = parseGapValue(gapString, rootFontSize, containerFontSize);
82
+ const OVERFLOW_CHIP_WIDTH_REM = 3.75;
83
+ const overflowChipWidth = OVERFLOW_CHIP_WIDTH_REM * rootFontSize;
84
+ for (let i = 0; i < items.length; i++) {
85
+ const item = items[i];
86
+ const chip = chipRefs.current[i];
87
+ if (chip) {
88
+ chipWidths.current.set(item.value, chip.offsetWidth);
89
+ }
90
+ }
91
+ const count = calculateFittingChips(
92
+ items,
93
+ chipWidths.current,
94
+ containerWidth,
95
+ gap,
96
+ overflowChipWidth
97
+ );
98
+ setVisibleCount(count);
99
+ }, [items, maxVisible, containerRef, chipRefs, chipWidths]);
100
+ const debouncedCalculate = useDebounce(calculateVisibleChips, 100);
101
+ useEffect(() => {
102
+ if (chipRefs.current.length > items.length) {
103
+ chipRefs.current = chipRefs.current.slice(0, items.length);
104
+ }
105
+ const currentValues = new Set(items.map((item) => item.value));
106
+ chipWidths.current.forEach((_, value) => {
107
+ if (!currentValues.has(value)) {
108
+ chipWidths.current.delete(value);
109
+ }
110
+ });
111
+ if (maxVisible === void 0) {
112
+ const hasUnmeasuredItems = items.some((item) => !chipWidths.current.has(item.value));
113
+ if (hasUnmeasuredItems) {
114
+ setVisibleCount(items.length);
115
+ } else {
116
+ setTimeout(calculateVisibleChips, 0);
117
+ }
118
+ }
119
+ }, [items, maxVisible, calculateVisibleChips, chipRefs, chipWidths]);
120
+ useEffect(() => {
121
+ const container = containerRef.current;
122
+ if (!container) return;
123
+ const resizeObserver = new ResizeObserver(() => {
124
+ debouncedCalculate();
125
+ });
126
+ resizeObserver.observe(container);
127
+ setTimeout(calculateVisibleChips, 0);
128
+ return () => {
129
+ resizeObserver.disconnect();
130
+ };
131
+ }, [calculateVisibleChips, debouncedCalculate, containerRef]);
132
+ const visibleItems = items.slice(0, visibleCount);
133
+ const hiddenItems = items.slice(visibleCount);
134
+ const hasOverflow = hiddenItems.length > 0;
135
+ return { visibleCount, visibleItems, hiddenItems, hasOverflow };
80
136
  };
81
- DialogFooter.displayName = "DialogFooter";
82
- const DialogTitle = forwardRef(
83
- ({ className, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
84
- const finalDataCy = dataCy || "dialog-title";
85
- const finalTestId = dataTestId || "dialog-title";
86
- return /* @__PURE__ */ jsx(
87
- DialogPrimitive.Title,
137
+ const ChipGroup = forwardRef(
138
+ ({
139
+ items,
140
+ selectedValue,
141
+ onSelectionChange,
142
+ removable = false,
143
+ onRemove,
144
+ variant = "primary",
145
+ disabled = false,
146
+ maxVisible,
147
+ className,
148
+ "data-testid": dataTestId,
149
+ "data-cy": dataCy,
150
+ ...props
151
+ }, ref) => {
152
+ const normalizedItems = items && Array.isArray(items) ? items : [];
153
+ const validItems = normalizedItems.filter((item) => {
154
+ return item !== null && item !== void 0 && typeof item === "object";
155
+ });
156
+ const containerRef = useRef(null);
157
+ const chipRefs = useRef([]);
158
+ const chipWidths = useRef(/* @__PURE__ */ new Map());
159
+ const dropdownRef = useRef(null);
160
+ const [showTooltip, setShowTooltip] = useState(false);
161
+ const [showDropdown, setShowDropdown] = useState(false);
162
+ const dropdownItemRefs = useRef([]);
163
+ const { visibleItems, hiddenItems, hasOverflow } = useChipOverflow(
164
+ validItems,
165
+ containerRef,
166
+ chipRefs,
167
+ chipWidths,
168
+ maxVisible
169
+ );
170
+ const handleChipClick = useCallback(
171
+ (value, itemDisabled, event) => {
172
+ if (disabled || itemDisabled) return;
173
+ if (onSelectionChange) {
174
+ const newValue = selectedValue === value ? null : value;
175
+ onSelectionChange(newValue, event);
176
+ }
177
+ },
178
+ [disabled, selectedValue, onSelectionChange]
179
+ );
180
+ const handleRemove = useCallback(
181
+ (e, value) => {
182
+ e.stopPropagation();
183
+ if (disabled) return;
184
+ if (onRemove) {
185
+ onRemove(value, e);
186
+ }
187
+ },
188
+ [disabled, onRemove]
189
+ );
190
+ const handleKeyDown = useCallback(
191
+ (e, value, itemDisabled) => {
192
+ if (disabled || itemDisabled) return;
193
+ if (e.key === "Enter" || e.key === " ") {
194
+ e.preventDefault();
195
+ handleChipClick(value, itemDisabled, e);
196
+ }
197
+ },
198
+ [disabled, handleChipClick]
199
+ );
200
+ const handleOverflowClick = useCallback((e) => {
201
+ e.stopPropagation();
202
+ setShowDropdown((prev) => !prev);
203
+ setShowTooltip(false);
204
+ }, []);
205
+ const handleDropdownKeyDown = useCallback(
206
+ (e, index) => {
207
+ var _a, _b, _c, _d;
208
+ switch (e.key) {
209
+ case "ArrowDown":
210
+ e.preventDefault();
211
+ if (index < hiddenItems.length - 1) {
212
+ (_a = dropdownItemRefs.current[index + 1]) == null ? void 0 : _a.focus();
213
+ }
214
+ break;
215
+ case "ArrowUp":
216
+ e.preventDefault();
217
+ if (index > 0) {
218
+ (_b = dropdownItemRefs.current[index - 1]) == null ? void 0 : _b.focus();
219
+ }
220
+ break;
221
+ case "Home":
222
+ e.preventDefault();
223
+ (_c = dropdownItemRefs.current[0]) == null ? void 0 : _c.focus();
224
+ break;
225
+ case "End":
226
+ e.preventDefault();
227
+ (_d = dropdownItemRefs.current[hiddenItems.length - 1]) == null ? void 0 : _d.focus();
228
+ break;
229
+ }
230
+ },
231
+ [hiddenItems.length]
232
+ );
233
+ const handleClickOutsideRef = useRef();
234
+ const handleEscapeRef = useRef();
235
+ useEffect(() => {
236
+ handleClickOutsideRef.current = (event) => {
237
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
238
+ setShowDropdown(false);
239
+ }
240
+ };
241
+ handleEscapeRef.current = (event) => {
242
+ if (event.key === "Escape") {
243
+ setShowDropdown(false);
244
+ }
245
+ };
246
+ });
247
+ useEffect(() => {
248
+ if (!showDropdown) return;
249
+ const handleClickOutside = (e) => {
250
+ var _a;
251
+ return (_a = handleClickOutsideRef.current) == null ? void 0 : _a.call(handleClickOutsideRef, e);
252
+ };
253
+ const handleEscape = (e) => {
254
+ var _a;
255
+ return (_a = handleEscapeRef.current) == null ? void 0 : _a.call(handleEscapeRef, e);
256
+ };
257
+ document.addEventListener("mousedown", handleClickOutside);
258
+ document.addEventListener("keydown", handleEscape);
259
+ return () => {
260
+ document.removeEventListener("mousedown", handleClickOutside);
261
+ document.removeEventListener("keydown", handleEscape);
262
+ };
263
+ }, [showDropdown]);
264
+ useEffect(() => {
265
+ if (process.env.NODE_ENV === "development" && validItems.length > 0) {
266
+ const values = validItems.map((item) => item.value);
267
+ const uniqueValues = new Set(values);
268
+ if (values.length !== uniqueValues.size) {
269
+ devWarn(
270
+ "[ChipGroup] Duplicate values detected in items array. Each item should have a unique value."
271
+ );
272
+ }
273
+ }
274
+ }, [validItems]);
275
+ useEffect(() => {
276
+ if (dropdownItemRefs.current.length > hiddenItems.length) {
277
+ dropdownItemRefs.current = dropdownItemRefs.current.slice(0, hiddenItems.length);
278
+ }
279
+ }, [hiddenItems]);
280
+ if (!items || !Array.isArray(items)) {
281
+ return null;
282
+ }
283
+ return /* @__PURE__ */ jsxs(
284
+ "div",
88
285
  {
89
286
  ref,
90
- className: cn("dialog-title", className),
91
- "data-cy": finalDataCy,
92
- "data-testid": finalTestId,
93
- ...props
287
+ className: cn("chip-group", disabled && "chip-group--disabled", className),
288
+ role: "group",
289
+ "aria-label": "Chip group",
290
+ "data-testid": dataTestId || "chip-group",
291
+ "data-cy": dataCy || "chip-group",
292
+ ...props,
293
+ children: [
294
+ hasOverflow && /* @__PURE__ */ jsxs(
295
+ "div",
296
+ {
297
+ className: "sr-only",
298
+ role: "status",
299
+ "aria-live": "polite",
300
+ "aria-atomic": "true",
301
+ "data-testid": "chip-group-live-region",
302
+ "data-cy": "chip-group-live-region",
303
+ children: [
304
+ hiddenItems.length,
305
+ " additional ",
306
+ hiddenItems.length === 1 ? "chip" : "chips",
307
+ " hidden"
308
+ ]
309
+ }
310
+ ),
311
+ /* @__PURE__ */ jsxs("div", { ref: containerRef, className: "chip-group__container", children: [
312
+ visibleItems.map((item) => {
313
+ const isSelected = selectedValue === item.value;
314
+ const itemVariant = item.variant || variant;
315
+ const itemDisabled = disabled || item.disabled || false;
316
+ const itemIndexInFullArray = validItems.findIndex((i) => i.value === item.value);
317
+ return /* @__PURE__ */ jsx(
318
+ "div",
319
+ {
320
+ ref: (el) => {
321
+ if (el) {
322
+ chipRefs.current[itemIndexInFullArray] = el;
323
+ } else {
324
+ chipRefs.current[itemIndexInFullArray] = null;
325
+ }
326
+ },
327
+ className: "chip-group__item-wrapper",
328
+ "data-cy": `chip-group-item-wrapper-${item.value}`,
329
+ "data-testid": `chip-group-item-wrapper-${item.value}`,
330
+ children: /* @__PURE__ */ jsxs(
331
+ "div",
332
+ {
333
+ className: "chip-group__item",
334
+ onClick: (e) => handleChipClick(item.value, itemDisabled, e),
335
+ onKeyDown: (e) => handleKeyDown(e, item.value, itemDisabled),
336
+ tabIndex: itemDisabled ? -1 : 0,
337
+ role: "button",
338
+ "aria-pressed": isSelected ? "true" : "false",
339
+ "aria-disabled": itemDisabled ? "true" : "false",
340
+ "data-cy": `chip-group-item-${item.value}`,
341
+ "data-testid": `chip-group-item-${item.value}`,
342
+ children: [
343
+ /* @__PURE__ */ jsx(
344
+ Chip,
345
+ {
346
+ variant: itemVariant,
347
+ selected: isSelected,
348
+ disabled: itemDisabled,
349
+ "data-cy": `chip-${item.value}`,
350
+ "data-testid": `chip-${item.value}`,
351
+ children: item.label
352
+ }
353
+ ),
354
+ removable && !disabled && !itemDisabled && /* @__PURE__ */ jsx(
355
+ "button",
356
+ {
357
+ className: "chip-group__remove",
358
+ onClick: (e) => handleRemove(e, item.value),
359
+ "aria-label": `Remove ${item.label}`,
360
+ "data-cy": `chip-remove-${item.value}`,
361
+ "data-testid": `chip-remove-${item.value}`,
362
+ type: "button",
363
+ children: /* @__PURE__ */ jsx(Icon, { name: "Cross2Icon", size: "sm", decorative: true })
364
+ }
365
+ )
366
+ ]
367
+ }
368
+ )
369
+ },
370
+ item.value
371
+ );
372
+ }),
373
+ hasOverflow && /* @__PURE__ */ jsxs(
374
+ "div",
375
+ {
376
+ ref: dropdownRef,
377
+ className: "chip-group__overflow",
378
+ role: "button",
379
+ tabIndex: 0,
380
+ "aria-expanded": showDropdown ? "true" : "false",
381
+ "aria-haspopup": "menu",
382
+ "aria-label": `Show ${hiddenItems.length} more ${hiddenItems.length === 1 ? "chip" : "chips"}`,
383
+ onMouseEnter: () => !showDropdown && setShowTooltip(true),
384
+ onMouseLeave: () => setShowTooltip(false),
385
+ onClick: handleOverflowClick,
386
+ onKeyDown: (e) => {
387
+ if (e.key === "Enter" || e.key === " ") {
388
+ e.preventDefault();
389
+ e.stopPropagation();
390
+ setShowDropdown(!showDropdown);
391
+ setShowTooltip(false);
392
+ }
393
+ },
394
+ "data-cy": "chip-group-overflow",
395
+ "data-testid": "chip-group-overflow",
396
+ children: [
397
+ /* @__PURE__ */ jsxs(Chip, { variant, "data-cy": "chip-overflow", "data-testid": "chip-overflow", children: [
398
+ "+",
399
+ hiddenItems.length
400
+ ] }),
401
+ showTooltip && !showDropdown && /* @__PURE__ */ jsx(
402
+ "div",
403
+ {
404
+ className: "chip-group__tooltip chip-group__tooltip--hover",
405
+ role: "tooltip",
406
+ "data-cy": "chip-group-tooltip",
407
+ "data-testid": "chip-group-tooltip",
408
+ children: hiddenItems.map((item) => /* @__PURE__ */ jsx(
409
+ "div",
410
+ {
411
+ className: "chip-group__tooltip-item",
412
+ "data-cy": `chip-group-tooltip-item-${item.value}`,
413
+ "data-testid": `chip-group-tooltip-item-${item.value}`,
414
+ children: item.label
415
+ },
416
+ item.value
417
+ ))
418
+ }
419
+ ),
420
+ showDropdown && /* @__PURE__ */ jsx(
421
+ "div",
422
+ {
423
+ className: "chip-group__dropdown",
424
+ role: "menu",
425
+ "data-cy": "chip-group-dropdown",
426
+ "data-testid": "chip-group-dropdown",
427
+ children: hiddenItems.map((item, index) => /* @__PURE__ */ jsx(
428
+ "div",
429
+ {
430
+ ref: (el) => {
431
+ if (el) {
432
+ dropdownItemRefs.current[index] = el;
433
+ } else {
434
+ dropdownItemRefs.current[index] = null;
435
+ }
436
+ },
437
+ className: cn(
438
+ "chip-group__dropdown-item",
439
+ item.disabled && "chip-group__dropdown-item--disabled"
440
+ ),
441
+ role: "menuitem",
442
+ tabIndex: item.disabled ? -1 : 0,
443
+ "aria-disabled": item.disabled ? "true" : "false",
444
+ onClick: (e) => {
445
+ e.stopPropagation();
446
+ if (!item.disabled) {
447
+ handleChipClick(item.value, false, e);
448
+ setShowDropdown(false);
449
+ }
450
+ },
451
+ onKeyDown: (e) => {
452
+ handleDropdownKeyDown(e, index);
453
+ if (e.key === "Enter" || e.key === " ") {
454
+ e.preventDefault();
455
+ e.stopPropagation();
456
+ if (!item.disabled) {
457
+ handleChipClick(item.value, false, e);
458
+ setShowDropdown(false);
459
+ }
460
+ }
461
+ },
462
+ "data-cy": `chip-group-dropdown-item-${item.value}`,
463
+ "data-testid": `chip-group-dropdown-item-${item.value}`,
464
+ children: item.label
465
+ },
466
+ item.value
467
+ ))
468
+ }
469
+ )
470
+ ]
471
+ }
472
+ )
473
+ ] })
474
+ ]
94
475
  }
95
476
  );
96
477
  }
97
478
  );
98
- DialogTitle.displayName = DialogPrimitive.Title.displayName;
99
- const DialogDescription = forwardRef(({ className, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
100
- const finalDataCy = dataCy || "dialog-description";
101
- const finalTestId = dataTestId || "dialog-description";
102
- return /* @__PURE__ */ jsx(
103
- DialogPrimitive.Description,
104
- {
105
- ref,
106
- className: cn("dialog-description", className),
107
- "data-cy": finalDataCy,
108
- "data-testid": finalTestId,
109
- ...props
110
- }
111
- );
112
- });
113
- DialogDescription.displayName = DialogPrimitive.Description.displayName;
479
+ ChipGroup.displayName = "ChipGroup";
114
480
  export {
115
- Dialog,
116
- DialogClose,
117
- DialogContent,
118
- DialogDescription,
119
- DialogFooter,
120
- DialogHeader,
121
- DialogOverlay,
122
- DialogPortal,
123
- DialogTitle,
124
- DialogTrigger
481
+ ChipGroup
125
482
  };
package/dist/index16.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),a=require("react"),e=require("./index17.cjs");;/* empty css */const s=a.forwardRef(({direction:a="vertical",spacing:s="4",align:c="stretch",justify:r="start",wrap:i=!1,className:n,children:d,"data-cy":l,"data-testid":o,...u},k)=>{const p=l||`stack-${a}`,j=o||`stack-${a}`;return t.jsx("div",{ref:k,className:e.cn("stack",`stack--${a}`,`stack--spacing-${s}`,`stack--align-${c}`,`stack--justify-${r}`,i&&"stack--wrap",n),"data-cy":p,"data-testid":j,...u,children:d})});s.displayName="Stack",exports.Stack=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),t=require("@radix-ui/react-dialog"),o=require("./index18.cjs");function i(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const t in e)if("default"!==t){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(a,t,o.get?o:{enumerable:!0,get:()=>e[t]})}return a.default=e,Object.freeze(a)};/* empty css */const r=i(t),s=r.Root,d=r.Trigger,l=r.Portal,c=r.Close,n=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-overlay",c=i||"dialog-overlay";return e.jsx(r.Overlay,{ref:d,className:o.cn("dialog-overlay",a),"data-cy":l,"data-testid":c,...s})});n.displayName=r.Overlay.displayName;const g=a.forwardRef(({className:a,children:t,"data-cy":i,"data-testid":s,...d},c)=>{const g=i||"dialog-content",y=s||"dialog-content";return e.jsxs(l,{children:[e.jsx(n,{}),e.jsx(r.Content,{ref:c,className:o.cn("dialog-content",a),"data-cy":g,"data-testid":y,...d,children:t})]})});g.displayName=r.Content.displayName;const y=({className:a,"data-cy":t,"data-testid":i,...r})=>{const s=t||"dialog-header",d=i||"dialog-header";return e.jsx("div",{className:o.cn("dialog-header",a),"data-cy":s,"data-testid":d,...r})};y.displayName="DialogHeader";const p=({className:a,"data-cy":t,"data-testid":i,...r})=>{const s=t||"dialog-footer",d=i||"dialog-footer";return e.jsx("div",{className:o.cn("dialog-footer",a),"data-cy":s,"data-testid":d,...r})};p.displayName="DialogFooter";const m=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-title",c=i||"dialog-title";return e.jsx(r.Title,{ref:d,className:o.cn("dialog-title",a),"data-cy":l,"data-testid":c,...s})});m.displayName=r.Title.displayName;const f=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-description",c=i||"dialog-description";return e.jsx(r.Description,{ref:d,className:o.cn("dialog-description",a),"data-cy":l,"data-testid":c,...s})});f.displayName=r.Description.displayName,exports.Dialog=s,exports.DialogClose=c,exports.DialogContent=g,exports.DialogDescription=f,exports.DialogFooter=p,exports.DialogHeader=y,exports.DialogOverlay=n,exports.DialogPortal=l,exports.DialogTitle=m,exports.DialogTrigger=d;