@namroodinc/liquid-editorial 0.6.0 → 0.6.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.
Files changed (126) hide show
  1. package/README.md +27 -3
  2. package/UPGRADING.md +109 -0
  3. package/dist/chunks/Avatar-BTKqaJLP.cjs +2 -0
  4. package/dist/chunks/Avatar-BTKqaJLP.cjs.map +1 -0
  5. package/dist/chunks/Avatar-C1q2AUD-.js +149 -0
  6. package/dist/chunks/Avatar-C1q2AUD-.js.map +1 -0
  7. package/dist/chunks/{ColourField-Doew1hLw.js → ColourField-BmHHxU6T.js} +119 -162
  8. package/dist/chunks/ColourField-BmHHxU6T.js.map +1 -0
  9. package/dist/chunks/ColourField-DWdc4d9E.cjs +2 -0
  10. package/dist/chunks/ColourField-DWdc4d9E.cjs.map +1 -0
  11. package/dist/chunks/{DatePicker-DmeWUsOS.js → DatePicker-CFYwk6eA.js} +2 -1
  12. package/dist/chunks/{DatePicker-DmeWUsOS.js.map → DatePicker-CFYwk6eA.js.map} +1 -1
  13. package/dist/chunks/{DatePicker-C0-609Zx.cjs → DatePicker-D5-LzTXS.cjs} +2 -2
  14. package/dist/chunks/{DatePicker-C0-609Zx.cjs.map → DatePicker-D5-LzTXS.cjs.map} +1 -1
  15. package/dist/chunks/FormEditor-B-XLNrub.cjs +2 -0
  16. package/dist/chunks/FormEditor-B-XLNrub.cjs.map +1 -0
  17. package/dist/chunks/{FormEditor-DTnFO4oS.js → FormEditor-_gqfxL_g.js} +4 -3
  18. package/dist/chunks/{FormEditor-DTnFO4oS.js.map → FormEditor-_gqfxL_g.js.map} +1 -1
  19. package/dist/chunks/colour-BmtxDlWF.cjs +2 -0
  20. package/dist/chunks/colour-BmtxDlWF.cjs.map +1 -0
  21. package/dist/chunks/colour-CYEF4Q_n.js +48 -0
  22. package/dist/chunks/colour-CYEF4Q_n.js.map +1 -0
  23. package/dist/chunks/isComposing-8bRWyiLF.js +8 -0
  24. package/dist/chunks/isComposing-8bRWyiLF.js.map +1 -0
  25. package/dist/chunks/isComposing-BrBcAANm.cjs +2 -0
  26. package/dist/chunks/isComposing-BrBcAANm.cjs.map +1 -0
  27. package/dist/chunks/transitionDuration-B4UnScFc.cjs +2 -0
  28. package/dist/chunks/transitionDuration-B4UnScFc.cjs.map +1 -0
  29. package/dist/chunks/transitionDuration-BIBA3V7G.js +8 -0
  30. package/dist/chunks/transitionDuration-BIBA3V7G.js.map +1 -0
  31. package/dist/chunks/useModalDialog-Cgus9408.cjs +2 -0
  32. package/dist/chunks/useModalDialog-Cgus9408.cjs.map +1 -0
  33. package/dist/chunks/useModalDialog-Dh-_6A0j.js +85 -0
  34. package/dist/chunks/useModalDialog-Dh-_6A0j.js.map +1 -0
  35. package/dist/chunks/useTooltip-CCf79zE9.cjs +2 -0
  36. package/dist/chunks/useTooltip-CCf79zE9.cjs.map +1 -0
  37. package/dist/chunks/useTooltip-D6cJji8v.js +73 -0
  38. package/dist/chunks/useTooltip-D6cJji8v.js.map +1 -0
  39. package/dist/components/Avatar/colour.d.cts +6 -0
  40. package/dist/components/Avatar/colour.d.cts.map +1 -0
  41. package/dist/components/Avatar/colour.d.ts +6 -0
  42. package/dist/components/Avatar/colour.d.ts.map +1 -0
  43. package/dist/components/Avatar/index.cjs +1 -2
  44. package/dist/components/Avatar/index.d.cts +16 -9
  45. package/dist/components/Avatar/index.d.cts.map +1 -1
  46. package/dist/components/Avatar/index.d.ts +16 -9
  47. package/dist/components/Avatar/index.d.ts.map +1 -1
  48. package/dist/components/Avatar/index.js +1 -43
  49. package/dist/components/Avatar/style.css +65 -16
  50. package/dist/components/ColourField/index.cjs +1 -1
  51. package/dist/components/ColourField/index.d.cts.map +1 -1
  52. package/dist/components/ColourField/index.d.ts.map +1 -1
  53. package/dist/components/ColourField/index.js +1 -1
  54. package/dist/components/DatePicker/index.cjs +1 -1
  55. package/dist/components/DatePicker/index.d.cts.map +1 -1
  56. package/dist/components/DatePicker/index.d.ts.map +1 -1
  57. package/dist/components/DatePicker/index.js +1 -1
  58. package/dist/components/Drawer/index.cjs +1 -1
  59. package/dist/components/Drawer/index.cjs.map +1 -1
  60. package/dist/components/Drawer/index.d.cts.map +1 -1
  61. package/dist/components/Drawer/index.d.ts.map +1 -1
  62. package/dist/components/Drawer/index.js +37 -36
  63. package/dist/components/Drawer/index.js.map +1 -1
  64. package/dist/components/Field/style.css +2 -0
  65. package/dist/components/FormEditor/index.cjs +1 -1
  66. package/dist/components/FormEditor/index.js +1 -1
  67. package/dist/components/FormEditor/style.css +0 -1
  68. package/dist/components/Menu/index.cjs +1 -1
  69. package/dist/components/Menu/index.cjs.map +1 -1
  70. package/dist/components/Menu/index.d.cts.map +1 -1
  71. package/dist/components/Menu/index.d.ts.map +1 -1
  72. package/dist/components/Menu/index.js +2 -1
  73. package/dist/components/Menu/index.js.map +1 -1
  74. package/dist/components/Modal/index.cjs +1 -1
  75. package/dist/components/Modal/index.js +1 -1
  76. package/dist/components/Popover/index.cjs +1 -1
  77. package/dist/components/Popover/index.cjs.map +1 -1
  78. package/dist/components/Popover/index.d.cts +2 -2
  79. package/dist/components/Popover/index.d.cts.map +1 -1
  80. package/dist/components/Popover/index.d.ts +2 -2
  81. package/dist/components/Popover/index.d.ts.map +1 -1
  82. package/dist/components/Popover/index.js +69 -53
  83. package/dist/components/Popover/index.js.map +1 -1
  84. package/dist/components/Popover/style.css +33 -1
  85. package/dist/components/Popover/useTooltip.d.cts +33 -0
  86. package/dist/components/Popover/useTooltip.d.cts.map +1 -0
  87. package/dist/components/Popover/useTooltip.d.ts +33 -0
  88. package/dist/components/Popover/useTooltip.d.ts.map +1 -0
  89. package/dist/components/Select/index.cjs +1 -1
  90. package/dist/components/Select/index.cjs.map +1 -1
  91. package/dist/components/Select/index.d.cts.map +1 -1
  92. package/dist/components/Select/index.d.ts.map +1 -1
  93. package/dist/components/Select/index.js +1 -0
  94. package/dist/components/Select/index.js.map +1 -1
  95. package/dist/components/Time/index.cjs +1 -1
  96. package/dist/components/Time/index.cjs.map +1 -1
  97. package/dist/components/Time/index.d.cts.map +1 -1
  98. package/dist/components/Time/index.d.ts.map +1 -1
  99. package/dist/components/Time/index.js +25 -42
  100. package/dist/components/Time/index.js.map +1 -1
  101. package/dist/components/Time/style.css +1 -3
  102. package/dist/index.cjs +1 -1
  103. package/dist/index.js +5 -5
  104. package/dist/internal/isComposing.d.cts +3 -0
  105. package/dist/internal/isComposing.d.cts.map +1 -0
  106. package/dist/internal/isComposing.d.ts +3 -0
  107. package/dist/internal/isComposing.d.ts.map +1 -0
  108. package/dist/internal/transitionDuration.d.cts +3 -0
  109. package/dist/internal/transitionDuration.d.cts.map +1 -0
  110. package/dist/internal/transitionDuration.d.ts +3 -0
  111. package/dist/internal/transitionDuration.d.ts.map +1 -0
  112. package/dist/internal/useModalDialog.d.cts.map +1 -1
  113. package/dist/internal/useModalDialog.d.ts.map +1 -1
  114. package/dist/styles.css +1 -1
  115. package/package.json +1 -1
  116. package/dist/chunks/ColourField-BQ4a5tAV.cjs +0 -2
  117. package/dist/chunks/ColourField-BQ4a5tAV.cjs.map +0 -1
  118. package/dist/chunks/ColourField-Doew1hLw.js.map +0 -1
  119. package/dist/chunks/FormEditor-DfQLJnsO.cjs +0 -2
  120. package/dist/chunks/FormEditor-DfQLJnsO.cjs.map +0 -1
  121. package/dist/chunks/useModalDialog-BVaG--b3.js +0 -87
  122. package/dist/chunks/useModalDialog-BVaG--b3.js.map +0 -1
  123. package/dist/chunks/useModalDialog-Ctu270Dp.cjs +0 -2
  124. package/dist/chunks/useModalDialog-Ctu270Dp.cjs.map +0 -1
  125. package/dist/components/Avatar/index.cjs.map +0 -1
  126. package/dist/components/Avatar/index.js.map +0 -1
package/README.md CHANGED
@@ -330,7 +330,7 @@ Keep Drawer mounted while changing `isOpen`: closing immediately makes the exiti
330
330
 
331
331
  ### Popover
332
332
 
333
- Low-level anchored positioning shared by menus, selects, calendars, colour pickers, and tooltips. It measures the anchor, flips when needed, clamps to the viewport, and follows scrolling and anchor/content resizing. Defaults: `align="start"`, `placement="bottom"`, `offset={4}`.
333
+ Low-level anchored positioning shared by menus, selects, calendars, colour pickers, and tooltips. It measures the anchor, flips when needed, clamps to the viewport, and follows scrolling and anchor/content resizing. Defaults: `align="center"`, `placement="bottom"`, `offset={4}`. Use `align="start"` or `"end"` for edge alignment; Menu, Select, DatePicker and ColourField use `"start"`, and tooltips are centred. Centred panels shift inward at viewport edges and flip vertically when needed, keeping an 8px viewport gutter. Popovers fade in and out using `--duration-fast` and respect reduced motion. Keep Popover mounted and toggle `isOpen` to allow the exit fade; closing panels are inert and hidden from assistive technology until removed.
334
334
 
335
335
  ```tsx
336
336
  import { useId, useRef, useState } from "react";
@@ -465,7 +465,31 @@ import { Avatar, AvatarGroup } from "@namroodinc/liquid-editorial";
465
465
  </>;
466
466
  ```
467
467
 
468
- Use `aria-hidden="true"` when an adjacent label already identifies the person. Wrap interactive avatars in a named Button or link.
468
+ Pass `colour` to Avatar or a `people` entry to set a solid background. Initials automatically use whichever of black or white gives the higher contrast ratio (at least 4.5:1 for supported opaque colours). Accepts hex, RGB, HSL and named colours. Missing, invalid, translucent, and unresolved CSS variable values use the neutral theme styling. Images still render over the background. Colours are supplied explicitly, never generated from names.
469
+
470
+ ```tsx
471
+ <Avatar name="Ada Lovelace" colour="#075985" />
472
+ <AvatarGroup people={[
473
+ { name: "Grace Hopper", colour: "gold" },
474
+ { name: "Alan Turing", colour: "hsl(260, 65%, 30%)" },
475
+ ]} />
476
+ ```
477
+
478
+ Tooltips show the name on hover or focus, stay while the pointer moves onto them or keyboard focus remains, and close on Escape. Set `tooltip="Editor"` for custom text or `tooltip={false}` to disable. The overflow chip, named "1 more person" or "n more people", lists hidden names in its tooltip.
479
+
480
+ Pass `href` (with optional `target` and `rel`) for a link, or `onClick` for a shared Button action. If both exist, the callback runs on the link and can call `event.preventDefault()` to cancel navigation. These options also work on each `people` entry; AvatarGroup itself remains a group. With neither action prop, Avatar stays passive. The outer span and its forwarded ref remain stable in every mode; inherited `onClick` events still bubble through that span. On linked and callback avatars, `id` and `aria-*` props such as `aria-expanded` or `aria-current` go to the inner link or Button, which uses Button's standard `xs`, `sm` or `md` size. AvatarGroup passes only these documented person fields to each Avatar.
481
+
482
+ ```tsx
483
+ <AvatarGroup
484
+ people={[
485
+ { name: "Ada Lovelace", href: "/people/ada", tooltip: "Editor" },
486
+ { name: "Grace Hopper", onClick: () => openPerson("grace") },
487
+ { name: "Alan Turing", tooltip: false },
488
+ ]}
489
+ />
490
+ ```
491
+
492
+ Avatars keep equal, fixed dimensions in flex and grid layouts; photographs are cropped to the circle. Passive avatars with tooltips and the overflow chip are keyboard-focusable. Use `aria-hidden="true"` for a decorative avatar next to an identifying label or inside a named link or Button: it shows no tooltip and is never focusable. Do not give an Avatar inside another control its own action.
469
493
 
470
494
  ### Skeleton
471
495
 
@@ -494,7 +518,7 @@ Individual Skeleton placeholders are hidden from assistive technology. SkeletonT
494
518
 
495
519
  ### Time
496
520
 
497
- A semantic time element with relative text and an absolute tooltip on hover/focus. `format` defaults to `"auto"`; `"absolute"` always displays the date. Relative formatting ages to an absolute date after a week, and future dates display as absolute dates.
521
+ A semantic time element with relative text and an absolute tooltip on hover/focus, sharing Avatar's tooltip behaviour (pointer transfer, keyboard focus, Escape). `format` defaults to `"auto"`; `"absolute"` always displays the date. Relative formatting ages to an absolute date after a week, and future dates display as absolute dates.
498
522
 
499
523
  ```tsx
500
524
  import {
package/UPGRADING.md CHANGED
@@ -2,6 +2,115 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.6.2
6
+
7
+ ### Avatar background colours with automatic text contrast
8
+
9
+ Avatar and each AvatarGroup `people` entry accept `colour` for an explicit solid
10
+ background. Initials use black or white, whichever has the higher contrast ratio,
11
+ meeting at least 4.5:1 for supported opaque colours. Hex, RGB, HSL and named
12
+ colours are supported and parsed exactly as ColourField parses them, including
13
+ precise hex alpha. Missing, invalid, translucent (including `#000000fe`) and
14
+ unresolved CSS-variable values retain neutral theme styling. Images continue to
15
+ cover the background.
16
+
17
+ Adoption: use `<Avatar name="Ada Lovelace" colour="#075985" />` or add `colour`
18
+ to individual people. Existing avatars remain neutral. Supply a resolved opaque
19
+ colour and allow the component to choose the text colour; overriding its content
20
+ styles can invalidate the contrast guarantee.
21
+
22
+ Verification: check light/dark/saturated backgrounds, linked and callback avatars
23
+ through hover/focus/press, both themes, grouped people and image avatars. Confirm
24
+ invalid/translucent colours fall back and removing `colour` restores defaults.
25
+
26
+ ### Popover fades and centred alignment
27
+
28
+ Popover now defaults to `align="center"`, with `"start"` and `"end"` still
29
+ available. Centred panels shift inward near viewport edges and retain vertical
30
+ flipping and scrollable height limits. Panels fade using `--duration-fast`, with
31
+ no motion under reduced-motion preferences. Closing panels briefly remain in the
32
+ DOM for the exit fade, immediately becoming inert and `aria-hidden` and leaving
33
+ the enclosing dialog's popup registration.
34
+
35
+ Menu, Select, DatePicker (DateField and DateRangeField) and ColourField pass
36
+ `align="start"` and keep their panels on the field's start edge. Time's tooltip,
37
+ like Avatar's, is now centred on its anchor. Menu's forwarded ref becomes `null`
38
+ as soon as the menu closes, while its inert panel is still fading out.
39
+
40
+ Adoption: set `align="start"` on application Popovers to preserve the previous
41
+ alignment. Keep Popover mounted and toggle `isOpen` to animate exits;
42
+ conditional unmounting removes it immediately. DOM-based tests should await exit
43
+ removal or query accessible roles, which disappear immediately on close. Code
44
+ that reads a Menu ref to detect an open menu keeps working.
45
+
46
+ Verification: check default centring, explicit alignment, both viewport edges,
47
+ vertical flipping, scroll/resize tracking, closing/reopening during a fade,
48
+ keyboard focus and reduced motion. Open each date, colour and select field in a
49
+ full-width layout and confirm its panel starts at the field's start edge.
50
+
51
+ ### Avatar tooltips, actions, and fixed circles
52
+
53
+ Avatar now shows a styled name tooltip on hover or focus. Set `tooltip` to custom
54
+ text or `false` to disable it. AvatarGroup's overflow chip lists hidden names; it
55
+ is a focusable image named "1 more person" or "n more people". Pass `href`,
56
+ optional `target`/`rel`, or `onClick` to Avatar or individual `people` entries.
57
+ Links support both navigation and a callback; `preventDefault()` cancels
58
+ navigation. Callback-only avatars use the shared Button at its standard `xs`,
59
+ `sm` or `md` size (for avatar sizes 24, 32 and 40), with Button's own focus ring
60
+ and fills. Circles keep their selected dimensions in constrained flex/grid
61
+ layouts, with cropped images and visible focus rings.
62
+
63
+ For linked and callback avatars, `id` and every `aria-*` prop (for example
64
+ `aria-expanded`, `aria-haspopup`, `aria-controls` or `aria-current`) go to the
65
+ inner link or Button that carries the role; the forwarded ref stays on the outer
66
+ span. AvatarGroup forwards only the documented person fields (`name`, `src`,
67
+ `colour`, `tooltip`, `href`, `target`, `rel`, `onClick`), so extra fields on
68
+ application records never reach the DOM.
69
+
70
+ Adoption: replace application-owned avatar action wrappers with these props, or
71
+ keep existing wrappers and set `tooltip={false}` on their passive Avatar child.
72
+ Do not nest an actionable Avatar inside another control. Passive tipped avatars
73
+ and the overflow chip now enter the tab order. An avatar with
74
+ `aria-hidden="true"` shows no tooltip and is not focusable, so it can sit inside a
75
+ named Button or link; an actionable hidden avatar leaves the tab order. Spread
76
+ Menu trigger props straight onto an actionable Avatar. Existing span refs, sizes,
77
+ initials, group limits and native attributes remain supported. Explicit `title`
78
+ values remain, but automatic native name titles are replaced by styled tooltips.
79
+
80
+ Compatibility: size 24 now uses `--space-6`, which equals the previous 24px at the
81
+ default root font size and scales with it like sizes 32 and 40.
82
+
83
+ Verification: tab through passive/link/action avatars, activate actions with
84
+ Enter/Space, check cancelled navigation and Escape tooltip dismissal, click an
85
+ `aria-hidden` avatar inside a Button and confirm the Button keeps focus, and
86
+ inspect all sizes with images and group overflow in narrow flex/grid containers.
87
+
88
+ ### Shared tooltip behaviour for Avatar and Time
89
+
90
+ Avatar and Time share one tooltip. It opens on hover or focus. It stays open
91
+ while the pointer moves onto its text, closing 100ms after the pointer leaves
92
+ both, and stays while keyboard focus remains; focus left by a mouse click no
93
+ longer holds it open. Escape anywhere closes an open tooltip and claims the key
94
+ with `preventDefault()` without stopping propagation, so window listeners still
95
+ receive it and an enclosing Modal or Drawer stays open for that Escape. Escape
96
+ during IME composition is left alone. A tooltip mounts its Popover only after it
97
+ first opens. Disabling a tooltip while it is open closes it.
98
+
99
+ Shared `.ds-tooltip` and `.ds-tooltip__content` classes now style both tooltips.
100
+ Time's tooltip padding moved from the panel to the inner content span.
101
+
102
+ Adoption: tests that dismiss Time's tooltip with a leave event should wait about
103
+ 100ms. Tests that expect focus to hold a tooltip open should move real focus
104
+ (`element.focus()` or `userEvent.tab()`) and account for jsdom's limited
105
+ `:focus-visible` support. Restyle `.ds-time-tooltip` padding on
106
+ `.ds-time-tooltip .ds-tooltip__content` if overridden.
107
+
108
+ Verification: hover a Time and an Avatar, move onto the tooltip text, tab to
109
+ each, click each and move the pointer away, and press Escape inside a Modal to
110
+ confirm the first Escape closes only the tooltip.
111
+
112
+ ## 0.6.1
113
+
5
114
  ## 0.6.0
6
115
 
7
116
  ### Breaking changes
@@ -0,0 +1,2 @@
1
+ const e=require("./colour-BmtxDlWF.cjs"),t=require("../components/Button/index.cjs"),n=require("./mergeRefs-Bc3qS0Tt.cjs"),r=require("./useTooltip-CCf79zE9.cjs");let i=require("react"),a=require("react/jsx-runtime"),o=require("colord"),s=require("colord/plugins/a11y");s=e.a(s,1),(0,o.extend)([s.default]);function c(t){let n=t?e.i(t):null;if(n&&n.alpha()===1)return{"--avatar-background":n.toHex(),"--avatar-foreground":n.contrast(`#000`)>=n.contrast(`#fff`)?`#000000`:`#ffffff`}}var l={24:`xs`,32:`sm`,40:`md`};function u(e){let t=e.trim().split(/\s+/);return((t[0]?.[0]??``)+(t.length>1?t[t.length-1][0]:``)).toUpperCase()}function d(e){let t={},n={};for(let[r,i]of Object.entries(e))(r.startsWith(`aria-`)?t:n)[r]=i;return{aria:t,other:n}}function f(e,t,n){return e?t?-1:void 0:!t&&n?0:void 0}function p({name:e,src:t}){return(0,a.jsx)(`span`,{className:`ds-avatar__content`,children:t?(0,a.jsx)(`img`,{src:t,alt:``}):u(e)})}function m({href:e,target:n,rel:r,hasCallback:i,size:o,semantics:s,children:c}){return e?(0,a.jsx)(`a`,{className:`ds-avatar__control`,href:e,target:n,rel:r,...s,children:c}):i?(0,a.jsx)(t.Button,{variant:`simple`,size:l[o],isIconOnly:!0,className:`ds-avatar__control`,...s,children:c}):(0,a.jsx)(a.Fragment,{children:c})}var h=(0,i.forwardRef)(function({name:e,src:t,colour:o,style:s,size:l=24,tooltip:u=e,href:h,target:g,rel:_,className:v,onClick:y,onMouseEnter:b,onMouseLeave:x,onFocus:S,onBlur:C,id:w,tabIndex:T,"aria-label":E=e,"aria-describedby":D,"aria-hidden":O,...k},A){let j=O===!0||O===`true`,M=!!h||!!y,{anchorRef:N,description:P,triggerProps:F,panel:I}=r.t(!j&&u,{placement:`top`,className:`ds-avatar-tooltip`}),L=(0,i.useMemo)(()=>n.t(N,A),[N,A]),R=(0,i.useMemo)(()=>c(o),[o]),{aria:z,other:B}=d(k),V={...z,id:w,"aria-label":E,"aria-describedby":[D,P].filter(Boolean).join(` `)||void 0,tabIndex:T??f(M,j,!!u)};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`span`,{ref:L,role:M?void 0:`img`,"aria-hidden":O,...M?{}:V,"data-size":l,className:[`ds-avatar`,v].filter(Boolean).join(` `),...B,style:{...s,...R},onClick:y,...F({onMouseEnter:b,onMouseLeave:x,onFocus:S,onBlur:C}),children:(0,a.jsx)(m,{href:h,target:g,rel:_,hasCallback:!!y,size:l,semantics:V,children:(0,a.jsx)(p,{name:e,src:t})})}),I]})});function g({names:e}){let{anchorRef:t,description:n,triggerProps:i,panel:o}=r.t(e.join(`, `),{placement:`top`,className:`ds-avatar-tooltip`}),s=e.length;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`span`,{ref:t,role:`img`,className:`ds-avatar-group__count`,tabIndex:0,"aria-label":`${s} more ${s===1?`person`:`people`}`,"aria-describedby":n,...i(),children:[`+`,s]}),o]})}var _=(0,i.forwardRef)(function({people:e,size:t=24,className:n,...r},i){return(0,a.jsxs)(`span`,{ref:i,role:`group`,"aria-label":e.map(e=>e.name).join(`, `),className:[`ds-avatar-group`,n].filter(Boolean).join(` `),...r,children:[e.slice(0,3).map(({name:e,src:n,colour:r,tooltip:i,href:o,target:s,rel:c,onClick:l},u)=>(0,a.jsx)(h,{name:e,src:n,colour:r,tooltip:i,href:o,target:s,rel:c,onClick:l,size:t},`${e}-${u}`)),e.length>3&&(0,a.jsx)(g,{names:e.slice(3).map(e=>e.name)})]})});Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return h}});
2
+ //# sourceMappingURL=Avatar-BTKqaJLP.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avatar-BTKqaJLP.cjs","names":["extend","a11yPlugin","parseColour","Button","_Fragment","forwardRef","useTooltip","useMemo","mergeRefs","require_colour","require_components_Button_index","require_mergeRefs","require_useTooltip","react","react_jsx_runtime","colord","colord_plugins_a11y","avatarColours","background","value","buttonSizes","initialsOf","words","name","splitAria","aria","other","key","props","defaultTabIndex","isActionable","isHidden","hasTooltip","AvatarContent","src","AvatarControl","href","semantics","hasCallback","size","Avatar","label","describedBy","hidden","onClick","tooltip","spanRef","anchorRef","ref","colours","colour","description","tabIndex","className","style","triggerProps","panel","OverflowCount","names","count","AvatarGroup","rest","people","p","index","person"],"sources":["../../src/components/Avatar/colour.ts","../../src/components/Avatar/index.tsx"],"sourcesContent":["import { extend } from \"colord\";\nimport a11yPlugin from \"colord/plugins/a11y\";\nimport { parseColour } from \"../ColourField/colour\";\n\nextend([a11yPlugin]);\n\n/** Opaque colours only: transparency would make contrast depend on the surface below. */\nexport function avatarColours(value?: string) {\n // Share ColourField's parser so both components accept and classify colours identically.\n const background = value ? parseColour(value) : null;\n if (!background || background.alpha() !== 1) {\n return undefined;\n }\n return {\n \"--avatar-background\": background.toHex(),\n \"--avatar-foreground\":\n background.contrast(\"#000\") >= background.contrast(\"#fff\") ? \"#000000\" : \"#ffffff\",\n };\n}\n","import {\n forwardRef,\n useMemo,\n type AnchorHTMLAttributes,\n type AriaAttributes,\n type HTMLAttributes,\n type ReactNode,\n} from \"react\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { Button, type ButtonSize } from \"../Button\";\nimport { useTooltip } from \"../Popover/useTooltip\";\nimport { avatarColours } from \"./colour\";\nimport \"./style.css\";\n\nexport type AvatarSize = 24 | 32 | 40;\n\n/** Each avatar size is one of Button's square sizes, so callback avatars use Button unchanged. */\nconst buttonSizes: Record<AvatarSize, ButtonSize> = { 24: \"xs\", 32: \"sm\", 40: \"md\" };\n\nexport interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {\n /** Required — drives the initials and the accessible name. */\n name: string;\n src?: string;\n size?: AvatarSize;\n /** Solid hex, RGB, HSL or named background; initials automatically use contrasting black/white. */\n colour?: string;\n /** Defaults to name; false disables the hover/focus tooltip. */\n tooltip?: string | false;\n href?: string;\n target?: AnchorHTMLAttributes<HTMLAnchorElement>[\"target\"];\n rel?: string;\n}\n\nfunction initialsOf(name: string) {\n const words = name.trim().split(/\\s+/);\n const first = words[0]?.[0] ?? \"\";\n const last = words.length > 1 ? words[words.length - 1][0] : \"\";\n return (first + last).toUpperCase();\n}\n\n/** Separate ARIA attributes so they can follow the element that carries the role. */\nfunction splitAria<T extends object>(props: T) {\n const aria: Record<string, unknown> = {};\n const other: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n (key.startsWith(\"aria-\") ? aria : other)[key] = value;\n }\n return { aria: aria as AriaAttributes, other: other as Omit<T, keyof AriaAttributes> };\n}\n\n/**\n * Links and Buttons are natively focusable, and hidden ones leave the tab order.\n * A passive avatar is focusable only for a visible tooltip.\n */\nfunction defaultTabIndex(isActionable: boolean, isHidden: boolean, hasTooltip: boolean) {\n if (isActionable) {\n return isHidden ? -1 : undefined;\n }\n return !isHidden && hasTooltip ? 0 : undefined;\n}\n\nfunction AvatarContent({ name, src }: Pick<AvatarProps, \"name\" | \"src\">) {\n return (\n <span className=\"ds-avatar__content\">\n {src ? (\n <img\n src={src}\n alt=\"\"\n />\n ) : (\n initialsOf(name)\n )}\n </span>\n );\n}\n\ninterface AvatarControlProps extends Pick<AvatarProps, \"href\" | \"target\" | \"rel\"> {\n hasCallback: boolean;\n size: AvatarSize;\n /** Naming, description, id, ARIA state and tab order for the control. */\n semantics: HTMLAttributes<HTMLElement>;\n children: ReactNode;\n}\n\n/** The inner link or shared Button of an actionable avatar; passive content otherwise. */\nfunction AvatarControl({\n href,\n target,\n rel,\n hasCallback,\n size,\n semantics,\n children,\n}: AvatarControlProps) {\n if (href) {\n return (\n <a\n className=\"ds-avatar__control\"\n href={href}\n target={target}\n rel={rel}\n {...semantics}\n >\n {children}\n </a>\n );\n }\n if (hasCallback) {\n return (\n <Button\n variant=\"simple\"\n size={buttonSizes[size]}\n isIconOnly\n className=\"ds-avatar__control\"\n {...semantics}\n >\n {children}\n </Button>\n );\n }\n return <>{children}</>;\n}\n\n/**\n * A circular person identifier, optionally linked or actionable. The ref stays on\n * the outer span; `id` and ARIA attributes go to the image span, or to the inner\n * link or Button when the avatar is actionable.\n */\nexport const Avatar = forwardRef<HTMLSpanElement, AvatarProps>(function Avatar(\n {\n name,\n src,\n colour,\n style,\n size = 24,\n tooltip = name,\n href,\n target,\n rel,\n className,\n onClick,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n id,\n tabIndex,\n \"aria-label\": label = name,\n \"aria-describedby\": describedBy,\n \"aria-hidden\": hidden,\n ...props\n },\n ref,\n) {\n const isHidden = hidden === true || hidden === \"true\";\n const isActionable = !!href || !!onClick;\n const { anchorRef, description, triggerProps, panel } = useTooltip<HTMLSpanElement>(\n isHidden ? false : tooltip,\n { placement: \"top\", className: \"ds-avatar-tooltip\" },\n );\n // Stable across renders, so tooltip state changes never detach a caller's callback ref.\n const spanRef = useMemo(() => mergeRefs(anchorRef, ref), [anchorRef, ref]);\n const colours = useMemo(() => avatarColours(colour), [colour]);\n const { aria, other } = splitAria(props);\n const semantics = {\n ...aria,\n id,\n \"aria-label\": label,\n \"aria-describedby\": [describedBy, description].filter(Boolean).join(\" \") || undefined,\n tabIndex: tabIndex ?? defaultTabIndex(isActionable, isHidden, !!tooltip),\n };\n return (\n <>\n <span\n ref={spanRef}\n role={isActionable ? undefined : \"img\"}\n aria-hidden={hidden}\n {...(isActionable ? {} : semantics)}\n data-size={size}\n className={[\"ds-avatar\", className].filter(Boolean).join(\" \")}\n {...other}\n style={{ ...style, ...colours }}\n onClick={onClick}\n {...triggerProps({ onMouseEnter, onMouseLeave, onFocus, onBlur })}\n >\n <AvatarControl\n href={href}\n target={target}\n rel={rel}\n hasCallback={!!onClick}\n size={size}\n semantics={semantics}\n >\n <AvatarContent\n name={name}\n src={src}\n />\n </AvatarControl>\n </span>\n {panel}\n </>\n );\n});\n\ntype AvatarPerson = Pick<\n AvatarProps,\n \"name\" | \"src\" | \"colour\" | \"tooltip\" | \"href\" | \"target\" | \"rel\" | \"onClick\"\n>;\n\nexport interface AvatarGroupProps extends HTMLAttributes<HTMLSpanElement> {\n /** Up to three render; the rest become a +n count with a hidden-name tooltip. */\n people: AvatarPerson[];\n size?: AvatarSize;\n}\n\nfunction OverflowCount({ names }: { names: string[] }) {\n const { anchorRef, description, triggerProps, panel } = useTooltip<HTMLSpanElement>(\n names.join(\", \"),\n { placement: \"top\", className: \"ds-avatar-tooltip\" },\n );\n const count = names.length;\n return (\n <>\n <span\n ref={anchorRef}\n role=\"img\"\n className=\"ds-avatar-group__count\"\n tabIndex={0}\n aria-label={`${count} more ${count === 1 ? \"person\" : \"people\"}`}\n aria-describedby={description}\n {...triggerProps()}\n >\n +{count}\n </span>\n {panel}\n </>\n );\n}\n\n/** Overlapping stack of at most three avatars, then a +n chip. */\nexport const AvatarGroup = forwardRef<HTMLSpanElement, AvatarGroupProps>(function AvatarGroup(\n { people, size = 24, className, ...rest },\n ref,\n) {\n return (\n <span\n ref={ref}\n role=\"group\"\n aria-label={people.map((p) => p.name).join(\", \")}\n className={[\"ds-avatar-group\", className].filter(Boolean).join(\" \")}\n {...rest}\n >\n {/* Only documented person fields reach Avatar; extra application data stays off the DOM. */}\n {people\n .slice(0, 3)\n .map(({ name, src, colour, tooltip, href, target, rel, onClick }, index) => (\n <Avatar\n key={`${name}-${index}`}\n name={name}\n src={src}\n colour={colour}\n tooltip={tooltip}\n href={href}\n target={target}\n rel={rel}\n onClick={onClick}\n size={size}\n />\n ))}\n {people.length > 3 && <OverflowCount names={people.slice(3).map((person) => person.name)} />}\n </span>\n );\n});\n"],"mappings":"A,yRAIAA,EAAAA,EAAAA,OAAAA,CAAO,CAACC,EAAAA,OAAU,CAAC,EAGnB,SAAgBgB,EAAc,EAAgB,CAE5C,IAAMC,EAAaC,EAAQjB,EAAAA,EAAYiB,CAAK,EAAI,KAChD,GAAKD,GAAcA,EAAW,MAAM,IAAM,EAG1C,MAAO,CACL,sBAAuBA,EAAW,MAAM,EACxC,sBACEA,EAAW,SAAS,MAAM,GAAKA,EAAW,SAAS,MAAM,EAAI,UAAY,SAC7E,CACF,CCDA,IAAME,EAA8C,CAAE,GAAI,KAAM,GAAI,KAAM,GAAI,IAAK,EAgBnF,SAASC,EAAW,EAAc,CAChC,IAAMC,EAAQC,EAAK,KAAK,CAAC,CAAC,MAAM,KAAK,EAGrC,QAFcD,EAAM,EAAE,GAAG,IAAM,KAClBA,EAAM,OAAS,EAAIA,EAAMA,EAAM,OAAS,EAAE,CAAC,GAAK,IAAA,CACvC,YAAY,CACpC,CAGA,SAASE,EAA4B,EAAU,CAC7C,IAAMC,EAAgC,CAAC,EACjCC,EAAiC,CAAC,EACxC,IAAK,GAAM,CAACC,EAAKR,KAAU,OAAO,QAAQS,CAAK,EAC7C,CAACD,EAAI,WAAW,OAAO,EAAIF,EAAOC,EAAA,CAAOC,GAAOR,EAElD,MAAO,CAAQ,OAA+B,OAAuC,CACvF,CAMA,SAASU,EAAgB,EAAuB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BACV,SAAU,EACV,aAAY,GAAGY,EAAM,QAAQA,IAAU,EAAI,SAAW,WACtD,mBAAkBR,EAClB,GAAII,EAAa,EAPnB,SAAA,CAQC,IACGI,CACE,CACL,CAAA,EAAAH,CACD,CAAA,CAAA,CAEN,CAGA,IAAaI,GAAA,EAAcvD,EAAAA,WAAAA,CAA8C,SACvE,CAAE,SAAQ,OAAO,GAAI,YAAW,GAAGwD,GACnC,EACA,CACA,OACE,EAAA/C,EAAA,KAAA,CAAC,OAAD,CACO,MACL,KAAK,QACL,aAAYgD,EAAO,IAAK,GAAMC,EAAE,IAAI,CAAC,CAAC,KAAK,IAAI,EAC/C,UAAW,CAAC,kBAAmBV,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EAClE,GAAIQ,EALN,SAAA,CAQGC,EACE,MAAM,EAAG,CAAC,CAAC,CACX,KAAK,CAAE,OAAM,MAAK,SAAQ,UAAS,OAAM,SAAQ,MAAK,WAAW,KAChE,EAAAhD,EAAA,IAAA,CAAC0B,EAAD,CAEQ,OACD,MACG,SACC,UACH,OACE,SACH,MACI,UACH,MACP,EAVM,GAAGjB,EAAK,GAAGyC,GAUjB,CACF,EACFF,EAAO,OAAS,IAAK,EAAAhD,EAAA,IAAA,CAAC2C,EAAD,CAAe,MAAOK,EAAO,MAAM,CAAC,CAAC,CAAC,IAAK,GAAWG,EAAO,IAAI,CAAI,CAAA,CACvF,C,EAEV,CAAC,E"}
@@ -0,0 +1,149 @@
1
+ import { Button as e } from "../components/Button/index.js";
2
+ import { t } from "./mergeRefs-DGM402mE.js";
3
+ import { i as n } from "./colour-CYEF4Q_n.js";
4
+ import { t as r } from "./useTooltip-D6cJji8v.js";
5
+ import { forwardRef as i, useMemo as a } from "react";
6
+ import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
7
+ import { extend as l } from "colord";
8
+ import u from "colord/plugins/a11y";
9
+ //#region src/components/Avatar/colour.ts
10
+ l([u]);
11
+ function d(e) {
12
+ let t = e ? n(e) : null;
13
+ if (t && t.alpha() === 1) return {
14
+ "--avatar-background": t.toHex(),
15
+ "--avatar-foreground": t.contrast("#000") >= t.contrast("#fff") ? "#000000" : "#ffffff"
16
+ };
17
+ }
18
+ //#endregion
19
+ //#region src/components/Avatar/index.tsx
20
+ var f = {
21
+ 24: "xs",
22
+ 32: "sm",
23
+ 40: "md"
24
+ };
25
+ function p(e) {
26
+ let t = e.trim().split(/\s+/);
27
+ return ((t[0]?.[0] ?? "") + (t.length > 1 ? t[t.length - 1][0] : "")).toUpperCase();
28
+ }
29
+ function m(e) {
30
+ let t = {}, n = {};
31
+ for (let [r, i] of Object.entries(e)) (r.startsWith("aria-") ? t : n)[r] = i;
32
+ return {
33
+ aria: t,
34
+ other: n
35
+ };
36
+ }
37
+ function h(e, t, n) {
38
+ return e ? t ? -1 : void 0 : !t && n ? 0 : void 0;
39
+ }
40
+ function g({ name: e, src: t }) {
41
+ return /* @__PURE__ */ s("span", {
42
+ className: "ds-avatar__content",
43
+ children: t ? /* @__PURE__ */ s("img", {
44
+ src: t,
45
+ alt: ""
46
+ }) : p(e)
47
+ });
48
+ }
49
+ function _({ href: t, target: n, rel: r, hasCallback: i, size: a, semantics: c, children: l }) {
50
+ return t ? /* @__PURE__ */ s("a", {
51
+ className: "ds-avatar__control",
52
+ href: t,
53
+ target: n,
54
+ rel: r,
55
+ ...c,
56
+ children: l
57
+ }) : i ? /* @__PURE__ */ s(e, {
58
+ variant: "simple",
59
+ size: f[a],
60
+ isIconOnly: !0,
61
+ className: "ds-avatar__control",
62
+ ...c,
63
+ children: l
64
+ }) : /* @__PURE__ */ s(o, { children: l });
65
+ }
66
+ var v = i(function({ name: e, src: n, colour: i, style: l, size: u = 24, tooltip: f = e, href: p, target: v, rel: y, className: b, onClick: x, onMouseEnter: S, onMouseLeave: C, onFocus: w, onBlur: T, id: E, tabIndex: D, "aria-label": O = e, "aria-describedby": k, "aria-hidden": A, ...j }, M) {
67
+ let N = A === !0 || A === "true", P = !!p || !!x, { anchorRef: F, description: I, triggerProps: L, panel: R } = r(!N && f, {
68
+ placement: "top",
69
+ className: "ds-avatar-tooltip"
70
+ }), z = a(() => t(F, M), [F, M]), B = a(() => d(i), [i]), { aria: V, other: H } = m(j), U = {
71
+ ...V,
72
+ id: E,
73
+ "aria-label": O,
74
+ "aria-describedby": [k, I].filter(Boolean).join(" ") || void 0,
75
+ tabIndex: D ?? h(P, N, !!f)
76
+ };
77
+ return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s("span", {
78
+ ref: z,
79
+ role: P ? void 0 : "img",
80
+ "aria-hidden": A,
81
+ ...P ? {} : U,
82
+ "data-size": u,
83
+ className: ["ds-avatar", b].filter(Boolean).join(" "),
84
+ ...H,
85
+ style: {
86
+ ...l,
87
+ ...B
88
+ },
89
+ onClick: x,
90
+ ...L({
91
+ onMouseEnter: S,
92
+ onMouseLeave: C,
93
+ onFocus: w,
94
+ onBlur: T
95
+ }),
96
+ children: /* @__PURE__ */ s(_, {
97
+ href: p,
98
+ target: v,
99
+ rel: y,
100
+ hasCallback: !!x,
101
+ size: u,
102
+ semantics: U,
103
+ children: /* @__PURE__ */ s(g, {
104
+ name: e,
105
+ src: n
106
+ })
107
+ })
108
+ }), R] });
109
+ });
110
+ function y({ names: e }) {
111
+ let { anchorRef: t, description: n, triggerProps: i, panel: a } = r(e.join(", "), {
112
+ placement: "top",
113
+ className: "ds-avatar-tooltip"
114
+ }), s = e.length;
115
+ return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ c("span", {
116
+ ref: t,
117
+ role: "img",
118
+ className: "ds-avatar-group__count",
119
+ tabIndex: 0,
120
+ "aria-label": `${s} more ${s === 1 ? "person" : "people"}`,
121
+ "aria-describedby": n,
122
+ ...i(),
123
+ children: ["+", s]
124
+ }), a] });
125
+ }
126
+ var b = i(function({ people: e, size: t = 24, className: n, ...r }, i) {
127
+ return /* @__PURE__ */ c("span", {
128
+ ref: i,
129
+ role: "group",
130
+ "aria-label": e.map((e) => e.name).join(", "),
131
+ className: ["ds-avatar-group", n].filter(Boolean).join(" "),
132
+ ...r,
133
+ children: [e.slice(0, 3).map(({ name: e, src: n, colour: r, tooltip: i, href: a, target: o, rel: c, onClick: l }, u) => /* @__PURE__ */ s(v, {
134
+ name: e,
135
+ src: n,
136
+ colour: r,
137
+ tooltip: i,
138
+ href: a,
139
+ target: o,
140
+ rel: c,
141
+ onClick: l,
142
+ size: t
143
+ }, `${e}-${u}`)), e.length > 3 && /* @__PURE__ */ s(y, { names: e.slice(3).map((e) => e.name) })]
144
+ });
145
+ });
146
+ //#endregion
147
+ export { b as n, v as t };
148
+
149
+ //# sourceMappingURL=Avatar-C1q2AUD-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avatar-C1q2AUD-.js","names":["_Fragment","parseColour","useTooltip","Fragment$1","a11yPlugin","extend","avatarColours","background","value","buttonSizes","initialsOf","words","name","splitAria","aria","other","key","props","defaultTabIndex","isActionable","isHidden","hasTooltip","AvatarContent","src","AvatarControl","href","semantics","hasCallback","Button","size","Avatar","forwardRef","label","describedBy","hidden","onClick","tooltip","spanRef","useMemo","mergeRefs","anchorRef","ref","colours","colour","description","tabIndex","className","style","triggerProps","panel","OverflowCount","names","count","AvatarGroup","rest","people","p","index","person"],"sources":["../../src/components/Avatar/colour.ts","../../src/components/Avatar/index.tsx"],"sourcesContent":["import { extend } from \"colord\";\nimport a11yPlugin from \"colord/plugins/a11y\";\nimport { parseColour } from \"../ColourField/colour\";\n\nextend([a11yPlugin]);\n\n/** Opaque colours only: transparency would make contrast depend on the surface below. */\nexport function avatarColours(value?: string) {\n // Share ColourField's parser so both components accept and classify colours identically.\n const background = value ? parseColour(value) : null;\n if (!background || background.alpha() !== 1) {\n return undefined;\n }\n return {\n \"--avatar-background\": background.toHex(),\n \"--avatar-foreground\":\n background.contrast(\"#000\") >= background.contrast(\"#fff\") ? \"#000000\" : \"#ffffff\",\n };\n}\n","import {\n forwardRef,\n useMemo,\n type AnchorHTMLAttributes,\n type AriaAttributes,\n type HTMLAttributes,\n type ReactNode,\n} from \"react\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { Button, type ButtonSize } from \"../Button\";\nimport { useTooltip } from \"../Popover/useTooltip\";\nimport { avatarColours } from \"./colour\";\nimport \"./style.css\";\n\nexport type AvatarSize = 24 | 32 | 40;\n\n/** Each avatar size is one of Button's square sizes, so callback avatars use Button unchanged. */\nconst buttonSizes: Record<AvatarSize, ButtonSize> = { 24: \"xs\", 32: \"sm\", 40: \"md\" };\n\nexport interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {\n /** Required — drives the initials and the accessible name. */\n name: string;\n src?: string;\n size?: AvatarSize;\n /** Solid hex, RGB, HSL or named background; initials automatically use contrasting black/white. */\n colour?: string;\n /** Defaults to name; false disables the hover/focus tooltip. */\n tooltip?: string | false;\n href?: string;\n target?: AnchorHTMLAttributes<HTMLAnchorElement>[\"target\"];\n rel?: string;\n}\n\nfunction initialsOf(name: string) {\n const words = name.trim().split(/\\s+/);\n const first = words[0]?.[0] ?? \"\";\n const last = words.length > 1 ? words[words.length - 1][0] : \"\";\n return (first + last).toUpperCase();\n}\n\n/** Separate ARIA attributes so they can follow the element that carries the role. */\nfunction splitAria<T extends object>(props: T) {\n const aria: Record<string, unknown> = {};\n const other: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(props)) {\n (key.startsWith(\"aria-\") ? aria : other)[key] = value;\n }\n return { aria: aria as AriaAttributes, other: other as Omit<T, keyof AriaAttributes> };\n}\n\n/**\n * Links and Buttons are natively focusable, and hidden ones leave the tab order.\n * A passive avatar is focusable only for a visible tooltip.\n */\nfunction defaultTabIndex(isActionable: boolean, isHidden: boolean, hasTooltip: boolean) {\n if (isActionable) {\n return isHidden ? -1 : undefined;\n }\n return !isHidden && hasTooltip ? 0 : undefined;\n}\n\nfunction AvatarContent({ name, src }: Pick<AvatarProps, \"name\" | \"src\">) {\n return (\n <span className=\"ds-avatar__content\">\n {src ? (\n <img\n src={src}\n alt=\"\"\n />\n ) : (\n initialsOf(name)\n )}\n </span>\n );\n}\n\ninterface AvatarControlProps extends Pick<AvatarProps, \"href\" | \"target\" | \"rel\"> {\n hasCallback: boolean;\n size: AvatarSize;\n /** Naming, description, id, ARIA state and tab order for the control. */\n semantics: HTMLAttributes<HTMLElement>;\n children: ReactNode;\n}\n\n/** The inner link or shared Button of an actionable avatar; passive content otherwise. */\nfunction AvatarControl({\n href,\n target,\n rel,\n hasCallback,\n size,\n semantics,\n children,\n}: AvatarControlProps) {\n if (href) {\n return (\n <a\n className=\"ds-avatar__control\"\n href={href}\n target={target}\n rel={rel}\n {...semantics}\n >\n {children}\n </a>\n );\n }\n if (hasCallback) {\n return (\n <Button\n variant=\"simple\"\n size={buttonSizes[size]}\n isIconOnly\n className=\"ds-avatar__control\"\n {...semantics}\n >\n {children}\n </Button>\n );\n }\n return <>{children}</>;\n}\n\n/**\n * A circular person identifier, optionally linked or actionable. The ref stays on\n * the outer span; `id` and ARIA attributes go to the image span, or to the inner\n * link or Button when the avatar is actionable.\n */\nexport const Avatar = forwardRef<HTMLSpanElement, AvatarProps>(function Avatar(\n {\n name,\n src,\n colour,\n style,\n size = 24,\n tooltip = name,\n href,\n target,\n rel,\n className,\n onClick,\n onMouseEnter,\n onMouseLeave,\n onFocus,\n onBlur,\n id,\n tabIndex,\n \"aria-label\": label = name,\n \"aria-describedby\": describedBy,\n \"aria-hidden\": hidden,\n ...props\n },\n ref,\n) {\n const isHidden = hidden === true || hidden === \"true\";\n const isActionable = !!href || !!onClick;\n const { anchorRef, description, triggerProps, panel } = useTooltip<HTMLSpanElement>(\n isHidden ? false : tooltip,\n { placement: \"top\", className: \"ds-avatar-tooltip\" },\n );\n // Stable across renders, so tooltip state changes never detach a caller's callback ref.\n const spanRef = useMemo(() => mergeRefs(anchorRef, ref), [anchorRef, ref]);\n const colours = useMemo(() => avatarColours(colour), [colour]);\n const { aria, other } = splitAria(props);\n const semantics = {\n ...aria,\n id,\n \"aria-label\": label,\n \"aria-describedby\": [describedBy, description].filter(Boolean).join(\" \") || undefined,\n tabIndex: tabIndex ?? defaultTabIndex(isActionable, isHidden, !!tooltip),\n };\n return (\n <>\n <span\n ref={spanRef}\n role={isActionable ? undefined : \"img\"}\n aria-hidden={hidden}\n {...(isActionable ? {} : semantics)}\n data-size={size}\n className={[\"ds-avatar\", className].filter(Boolean).join(\" \")}\n {...other}\n style={{ ...style, ...colours }}\n onClick={onClick}\n {...triggerProps({ onMouseEnter, onMouseLeave, onFocus, onBlur })}\n >\n <AvatarControl\n href={href}\n target={target}\n rel={rel}\n hasCallback={!!onClick}\n size={size}\n semantics={semantics}\n >\n <AvatarContent\n name={name}\n src={src}\n />\n </AvatarControl>\n </span>\n {panel}\n </>\n );\n});\n\ntype AvatarPerson = Pick<\n AvatarProps,\n \"name\" | \"src\" | \"colour\" | \"tooltip\" | \"href\" | \"target\" | \"rel\" | \"onClick\"\n>;\n\nexport interface AvatarGroupProps extends HTMLAttributes<HTMLSpanElement> {\n /** Up to three render; the rest become a +n count with a hidden-name tooltip. */\n people: AvatarPerson[];\n size?: AvatarSize;\n}\n\nfunction OverflowCount({ names }: { names: string[] }) {\n const { anchorRef, description, triggerProps, panel } = useTooltip<HTMLSpanElement>(\n names.join(\", \"),\n { placement: \"top\", className: \"ds-avatar-tooltip\" },\n );\n const count = names.length;\n return (\n <>\n <span\n ref={anchorRef}\n role=\"img\"\n className=\"ds-avatar-group__count\"\n tabIndex={0}\n aria-label={`${count} more ${count === 1 ? \"person\" : \"people\"}`}\n aria-describedby={description}\n {...triggerProps()}\n >\n +{count}\n </span>\n {panel}\n </>\n );\n}\n\n/** Overlapping stack of at most three avatars, then a +n chip. */\nexport const AvatarGroup = forwardRef<HTMLSpanElement, AvatarGroupProps>(function AvatarGroup(\n { people, size = 24, className, ...rest },\n ref,\n) {\n return (\n <span\n ref={ref}\n role=\"group\"\n aria-label={people.map((p) => p.name).join(\", \")}\n className={[\"ds-avatar-group\", className].filter(Boolean).join(\" \")}\n {...rest}\n >\n {/* Only documented person fields reach Avatar; extra application data stays off the DOM. */}\n {people\n .slice(0, 3)\n .map(({ name, src, colour, tooltip, href, target, rel, onClick }, index) => (\n <Avatar\n key={`${name}-${index}`}\n name={name}\n src={src}\n colour={colour}\n tooltip={tooltip}\n href={href}\n target={target}\n rel={rel}\n onClick={onClick}\n size={size}\n />\n ))}\n {people.length > 3 && <OverflowCount names={people.slice(3).map((person) => person.name)} />}\n </span>\n );\n});\n"],"mappings":";;;;;;;;;AAIAK,EAAO,CAACD,CAAU,CAAC;AAGnB,SAAgBE,EAAc,GAAgB;CAE5C,IAAMC,IAAaC,IAAQP,EAAYO,CAAK,IAAI;CAChD,IAAKD,KAAcA,EAAW,MAAM,MAAM,GAG1C,OAAO;EACL,uBAAuBA,EAAW,MAAM;EACxC,uBACEA,EAAW,SAAS,MAAM,KAAKA,EAAW,SAAS,MAAM,IAAI,YAAY;CAC7E;AACF;;;ACDA,IAAME,IAA8C;CAAE,IAAI;CAAM,IAAI;CAAM,IAAI;AAAK;AAgBnF,SAASC,EAAW,GAAc;CAChC,IAAMC,IAAQC,EAAK,KAAK,CAAC,CAAC,MAAM,KAAK;CAGrC,SAFcD,EAAM,EAAE,GAAG,MAAM,OAClBA,EAAM,SAAS,IAAIA,EAAMA,EAAM,SAAS,EAAE,CAAC,KAAK,IAAA,CACvC,YAAY;AACpC;AAGA,SAASE,EAA4B,GAAU;CAC7C,IAAMC,IAAgC,CAAC,GACjCC,IAAiC,CAAC;CACxC,KAAK,IAAM,CAACC,GAAKR,MAAU,OAAO,QAAQS,CAAK,GAC7C,CAACD,EAAI,WAAW,OAAO,IAAIF,IAAOC,EAAA,CAAOC,KAAOR;CAElD,OAAO;EAAQ;EAA+B;CAAuC;AACvF;AAMA,SAASU,EAAgB,GAAuB,GAAmB,GAAqB;CAItF,OAHIC,IACKC,IAAW,KAAK,KAAA,IAElB,CAACA,KAAYC,IAAa,IAAI,KAAA;AACvC;AAEA,SAAS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