mui-collage-fab 0.4.0 → 0.5.1

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/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7
7
  | <img src="https://raw.githubusercontent.com/radomir-dev/mui-collage-fab/main/docs/collagefab-collapsed.png" alt="Three CollageFab buttons collapsed into a single stacked circle" height="104" /> | <img src="https://raw.githubusercontent.com/radomir-dev/mui-collage-fab/main/docs/collagefab-expanded.png" alt="Three CollageFab buttons fanned out into a horizontal row" height="104" /> |
8
8
 
9
- A Material UI floating action button that behaves like a collapsed stack of overlapping circles. Collapsed, a set of `Fab`s sits perfectly stacked and reads as a single button with soft gradient slices at the edges. On hover (mouse) or tap (touch), the parent expands its main-axis extent and the buttons fan out into a row while their CSS masks slide in lockstep with the movement — so the unfold reads as one continuous morph instead of a pop.
9
+ A Material UI floating action button that behaves like a collapsed stack of overlapping circles. Collapsed, a set of `Fab`s sits perfectly stacked and reads as a single button with soft gradient slices at the edges. On hover (mouse) or tap (touch), the parent grows into the box its children travel through and they fan out — into a row, into two axes with `directions`, or onto a ring with `spread="radial"` — while their CSS masks slide in lockstep with the movement, so the unfold reads as one continuous morph instead of a pop.
10
10
 
11
- The trick is that each child is a full circle clipped by a static linear-gradient mask. As the element translates along the main axis, the `mask-position` is translated back by the same amount, keeping the fade boundary fixed in container space. Because the fade is a gradient rather than a hard clip, the parent's `filter: drop-shadow(...)` traces the soft edges cleanly.
11
+ The trick is that each child is a full circle clipped by a static mask that the item slides through: a linear-gradient band for a row, a conic-gradient wedge whose apex sits on the anchor for a ring. As the element translates, the `mask-position` is translated back by the same amount, keeping the cut line fixed in container space. Because the cut is a gradient rather than a hard clip, the parent's `filter: drop-shadow(...)` traces the soft edges cleanly.
12
12
 
13
13
  Not affiliated with or endorsed by MUI.
14
14
 
@@ -130,13 +130,15 @@ const theme = createTheme({
130
130
 
131
131
  ## Notes
132
132
 
133
- 1. **The parent must pin the anchor edge.** The root animates its own main-axis extent, so it only fans out if its parent keeps the anchor edge fixed: `justify-content: flex-end` for `direction="left"`, `flex-start` for `"right"`, `align-items: flex-end` for `"up"`, `flex-start` for `"down"`. Otherwise the root grows in place and pushes surrounding content instead of fanning out.
133
+ 1. **The parent must pin the anchor.** The root animates its own extent, so it only fans out if its parent keeps the anchor still: the corner the fan leaves behind (`justify-content: flex-end` for `direction="left"`, `flex-start` for `"right"`, `align-items: flex-end` for `"up"`, `flex-start` for `"down"`), or the centre for an axis that fans both ways. A radial group keeps its single-button box and paints the ring outside it, so it only needs room around it. Otherwise the root grows in place and pushes surrounding content instead of fanning out.
134
134
  2. **Each child is forced to `box-shadow: none` and 100% size**, so the parent owns the global shadow shape. Pass visual styles via each child's `sx`; the component overrides sizing and shadow only. Overriding that reset requires `slotProps.item.sx['& > *']` with `!important`.
135
135
  3. **The single `drop-shadow` lives on the root**, because a filter traces the soft mask edges while a `box-shadow` would trace the wrapper rectangles. Setting `overflow: hidden` on the root via `sx` clips the fan-out.
136
136
  4. **Shapes.** `variant` covers the three common cases; children inherit the wrapper's corner radius, so the shape applies to the whole group rather than to each button's own `Fab` default. Any other radius is reachable with `slotProps.item.sx`.
137
- 5. **Collapsed slices are hidden from assistive technology.** While collapsed, the item wrappers are `aria-hidden` and made non-focusable, so they leave the tab order and the accessibility tree. The root stays focusable: Enter or Space opens the group, focus moves to the first item, and Escape closes it and returns focus to the root.
137
+ 5. **Collapsed slices are hidden from assistive technology.** While collapsed, the item wrappers are `aria-hidden` and made non-focusable, so they leave the tab order and the accessibility tree — under `trigger="manual"` the anchor stays live so it can be the handle. The root stays focusable: Enter or Space opens the group, focus moves to the first item, and Escape closes it and returns focus to the root.
138
138
  6. **With a single child no mask is applied** — it behaves like a plain `Fab`.
139
139
  7. **`direction` is physical, not logical.** It is not mirrored under RTL; right-to-left layouts should set `direction="left"` explicitly.
140
+ 8. **`directions` gives each child its own direction**, in child order; children that share one fan a pitch apart, so a group can split into a row and a column.
141
+ 9. **`spread="radial"` rings the children around the anchor** at one pitch, with `radialStart` rotating the ring and `radialStep` (default `360 / (count - 1)`) spacing the ring children evenly. The anchor stays at the centre and never moves: a wedge cuts each child so it emerges as a petal, each petal fades in from the one before it, and the last one fades back into the anchor's disc, which is the base the collapsed stack reads as.
140
142
 
141
143
  ## Demo site
142
144
 
@@ -162,7 +164,9 @@ the cut line stays pinned while the button travels. `tests/behaviour.test.tsx` r
162
164
  component in jsdom for triggers, keyboard flow, controlled state and click-away.
163
165
  `e2e/collagefab.spec.ts` is the browser-level check, because jsdom cannot compute masks:
164
166
  it reads the real `transform` and `mask-position` after hovering and verifies they move by
165
- the same pitch in opposite directions.
167
+ the same pitch in opposite directions, and checks the mixed-axis and radial layouts.
168
+ `e2e/conic-mask.spec.ts` proves the compensated conic mask clips the same in chromium,
169
+ firefox and webkit against a single shared screenshot baseline.
166
170
 
167
171
  ## Development
168
172
 
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);let l=require("@mui/material"),u=require("@mui/material/styles"),d=require("@mui/material/utils"),f=require("@mui/utils/useSlotProps");f=s(f,1);let p=require("@mui/utils/composeClasses");p=s(p,1);let m=require("@mui/utils/generateUtilityClass");m=s(m,1);let h=require("react/jsx-runtime");var g={small:40,medium:48,large:56};function _(e){return typeof e==`number`?e:g[e]}var v={x:0,y:0},y={left:[-1,0],right:[1,0],up:[0,-1],down:[0,1]};function b({x:e,y:t},n){return t===0&&(n||e!==0)?`translateX(${e}px)`:e===0?`translateY(${t}px)`:`translate(${e}px, ${t}px)`}function x(e){return+e.toFixed(4)}function S(e,t){return t.directions[e]??t.direction}function C(e,t){let n=t.size+t.gap;if(t.spread===`radial`){if(e===0)return v;let r=(t.radialStart+(e-1)*t.radialStep)*Math.PI/180;return{x:x(Math.sin(r)*n),y:x(-Math.cos(r)*n)}}let r=S(e,t),[i,a]=y[r],o=0;for(let n=0;n<e;n+=1)S(n,t)===r&&(o+=1);let s=(o+(r===S(0,t)?0:1))*n;return{x:i*s,y:a*s}}function w(e,t){let n=Math.min(...e,0),r=Math.max(...e,0),i=n<0&&r>0?`center`:n<0?`end`:`start`;return[i===`center`?2*Math.max(-n,r)+t:r-n+t,i]}function T(e){let{count:t,size:n}=e;if(e.spread===`radial`)return{extent:{width:n,height:n},align:{x:`center`,y:`center`}};let r=Array.from({length:t},(t,n)=>C(n,e)),i=r.map(e=>e.x),a=r.map(e=>e.y),[o,s]=w(i,n),[c,l]=w(a,n);return{extent:{width:o,height:c},align:{x:s,y:l}}}function E(e,t){if(t.spread===`radial`)return D(e,t);let{count:n,size:r,gap:i,fadeWidth:a,open:o}=t,s=(n-1)*(r+i)+r+a,[c,l]=y[S(e,t)],u=c!==0,d=(u?c:l)<0,f=o?C(e,t):v,p=e===0?s:(n-e)*(r/n),m=e===0?-a/2:r/n*e,h=(d?p:m)-s-a/2,g=u?h-f.x:-f.x,_=u?-f.y:h-f.y,x=d?`#000 0px, #000 ${s}px, transparent ${s+a}px, transparent ${2*s}px`:`transparent 0px, transparent ${s}px, #000 ${s+a}px, #000 ${2*s}px`;return{translate:b(f,u),maskImage:n>1?`linear-gradient(${u?`to right`:`to bottom`}, ${x})`:`none`,maskSize:u?`${2*s}px 100%`:`100% ${2*s}px`,maskPosition:`${g}px ${_}px`}}function D(e,t){let{count:n,size:r,gap:i,fadeWidth:a,open:o}=t,s=t.radialStep,c=o?C(e,t):v,l=n>1?r+i:0,u=r+2*l,d=a?a/(r/2)*180/Math.PI:0,f=t.radialStart+(e-1)*s-s/2-d/2,p=x(s+d);return{translate:b(c,!1),maskImage:n>1&&e>0?`conic-gradient(from ${x(f)}deg, #0000 0deg, #000 ${x(d)}deg, #000 ${x(e===n-1?s:s+d)}deg, transparent ${p}deg)`:`none`,maskSize:`${u}px ${u}px`,maskPosition:`${-c.x-l}px ${-c.y-l}px`}}var O={direction:`left`,size:`large`,variant:`circular`,gap:16,fadeWidth:12,spread:`line`,radialStart:0,trigger:`hover`,defaultOpen:!1,disableClickAway:!1,transitionDuration:400,transitionEasing:`cubic-bezier(0.4, 0, 0.2, 1)`},ee={circular:`50%`,rounded:`25%`,square:0},k=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function A(e,t){return`${e}ms ${t}`}function j(e){return(0,m.default)(`MuiCollageFab`,e)}var M=(e,t)=>(0,p.default)({root:[`root`,e?`expanded`:`collapsed`],item:[`item`]},j,t),N=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`root`,overridesResolver:(e,t)=>t.root})(({ownerState:e})=>{let{open:t,size:n,spread:r,gap:i,count:a,transitionDuration:o,transitionEasing:s}=e,{extent:c}=T(e),l=A(o,s),u=t&&r===`radial`&&a>1?n+i:0;return{position:`relative`,...u>0&&{"&::after":{content:`""`,position:`absolute`,inset:-u,borderRadius:`50%`,zIndex:-1}},width:t?c.width:n,height:t?c.height:n,transition:`width ${l}, height ${l}`,filter:`drop-shadow(0px 6px 12px rgba(0,0,0,0.25))`,cursor:t?`default`:`pointer`,WebkitTapHighlightColor:`transparent`}}),P=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`item`,overridesResolver:(e,t)=>t.item})(({ownerState:e})=>{let{size:t,index:n,geometry:r,cornerRadius:i,transitionDuration:a,transitionEasing:o}=e,{align:s}=T(e),c={...s.x===`end`?{right:0}:s.x===`center`?{left:`50%`,marginLeft:-t/2}:{left:0},...s.y===`end`?{bottom:0}:s.y===`center`?{top:`50%`,marginTop:-t/2}:{top:0}},l=A(a,o);return{position:`absolute`,...c,width:t,height:t,borderRadius:i,overflow:`hidden`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:e.spread===`radial`?e.count-n:n,transform:r.translate,WebkitMaskImage:r.maskImage,maskImage:r.maskImage,WebkitMaskSize:r.maskSize,maskSize:r.maskSize,WebkitMaskPosition:r.maskPosition,maskPosition:r.maskPosition,WebkitMaskRepeat:`no-repeat`,maskRepeat:`no-repeat`,transition:`transform ${l}, -webkit-mask-position ${l}, mask-position ${l}`,"& > *":{boxShadow:`none !important`,borderRadius:`inherit !important`,width:`100%`,height:`100%`,margin:0}}});function F(e){let{index:t,ownerState:n,geometry:r,className:i,component:a,inert:o,itemRefs:s,slotProps:l,children:u}=e,p=c.useMemo(()=>({...n,index:t,isAnchor:t===0,geometry:r}),[n,t,r]),m=c.useRef(null),g=c.useCallback(e=>{s.current[t]=e},[s,t]),_=(0,d.useForkRef)(g,m);c.useEffect(()=>{let e=m.current;e&&`inert`in HTMLElement.prototype&&(e.inert=o)},[o]);let v=(0,f.default)({elementType:a,externalSlotProps:l,ownerState:p,additionalProps:{ref:_,className:i,"aria-hidden":o||void 0,children:u}});return(0,h.jsx)(a,{...v})}var I=c.forwardRef(function(e,t){let{children:n,direction:r=O.direction,directions:i,spread:a=O.spread,radialStart:o=O.radialStart,radialStep:s,size:p=O.size,variant:m=O.variant,gap:g=O.gap,fadeWidth:v=O.fadeWidth,trigger:y=O.trigger,open:b,defaultOpen:x=O.defaultOpen,onOpen:S,onClose:C,disableClickAway:w=O.disableClickAway,transitionDuration:T=O.transitionDuration,transitionEasing:D=O.transitionEasing,classes:A,slots:j,slotProps:I,className:L,...R}=(0,u.useThemeProps)({props:e,name:`MuiCollageFab`}),[z,B]=(0,d.useControlled)({controlled:b,default:x,name:`CollageFab`,state:`open`}),V=c.useMemo(()=>c.Children.toArray(n).filter(e=>c.isValidElement(e)),[n]),H=V.length,U={open:z,direction:r,directions:c.useMemo(()=>V.map((e,t)=>i?.[t]??r),[V,i,r]),spread:a,radialStart:o,radialStep:s??360/Math.max(H-1,1),trigger:y,size:_(p),variant:m,cornerRadius:ee[m],gap:g,fadeWidth:v,count:H,transitionDuration:T,transitionEasing:D},W=M(z,A),G=c.useRef(null),K=c.useRef([]),q=c.useRef(!1),J=c.useRef(`mouse`),Y=c.useRef(!1),X=(0,d.useForkRef)(G,t),Z=c.useCallback((e,t)=>{e!==z&&(B(e),e?S?.(t):C?.(t))},[z,B,S,C]),te=e=>{y===`hover`&&e.pointerType===`mouse`&&Z(!0,e)},ne=e=>{y===`hover`&&e.pointerType===`mouse`&&Z(!1,e)},re=e=>{y!==`manual`&&(J.current=e.pointerType,q.current=!1,e.pointerType===`mouse`||z||(q.current=!0,Z(!0,e)))},ie=e=>{q.current&&(q.current=!1,e.stopPropagation(),e.preventDefault())},ae=e=>{y!==`manual`&&(y===`click`?Z(!z,e):z&&J.current!==`mouse`&&Z(!1,e))},oe=e=>{if(y!==`manual`){if(z){if(e.key!==`Escape`)return;e.stopPropagation(),Z(!1,e),G.current?.focus()}else(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),Y.current=!0,Z(!0,e))}},se=e=>{Z(!1,e)},Q=j?.root??N,ce=j?.item??P,le=(0,f.default)({elementType:Q,externalForwardedProps:R,externalSlotProps:I?.root,ownerState:U,additionalProps:{ref:X,role:`group`,tabIndex:!z&&y!==`manual`?0:-1,onPointerEnter:te,onPointerLeave:ne,onPointerDown:re,onClick:ae,onClickCapture:ie,onKeyDown:oe},className:[W.root,L]});if(c.useEffect(()=>{if(!z||!Y.current)return;Y.current=!1;let e=K.current[0];e&&(e.querySelector(k)??e).focus()},[z]),H===0)return null;let $=(0,h.jsx)(Q,{...le,children:V.map((e,t)=>(0,h.jsx)(F,{index:t,ownerState:U,geometry:E(t,U),className:W.item,component:ce,inert:!z&&y!==`manual`,itemRefs:K,slotProps:I?.item,children:e},t))});return w||y===`manual`?$:(0,h.jsx)(l.ClickAwayListener,{onClickAway:se,children:$})});exports.CollageFab=I;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);let l=require("@mui/material"),u=require("@mui/material/styles"),d=require("@mui/material/utils"),f=require("@mui/utils/useSlotProps");f=s(f,1);let p=require("@mui/utils/composeClasses");p=s(p,1);let m=require("@mui/utils/generateUtilityClass");m=s(m,1);let h=require("react/jsx-runtime");var g={small:40,medium:48,large:56};function _(e){return typeof e==`number`?e:g[e]}var v={x:0,y:0},y={left:[-1,0],right:[1,0],up:[0,-1],down:[0,1]};function b({x:e,y:t},n){return t===0&&(n||e!==0)?`translateX(${e}px)`:e===0?`translateY(${t}px)`:`translate(${e}px, ${t}px)`}function x(e){return+e.toFixed(4)}function S(e,t){return t.directions[e]??t.direction}function C(e,t){let n=t.size+t.gap;if(t.spread===`radial`){if(e===0)return v;let r=(t.radialStart+(e-1)*t.radialStep)*Math.PI/180;return{x:x(Math.sin(r)*n),y:x(-Math.cos(r)*n)}}let r=S(e,t),[i,a]=y[r],o=0;for(let n=0;n<e;n+=1)S(n,t)===r&&(o+=1);let s=(o+(r===S(0,t)?0:1))*n;return{x:i*s,y:a*s}}function w(e,t){let n=Math.min(...e,0),r=Math.max(...e,0),i=n<0&&r>0?`center`:n<0?`end`:`start`;return[i===`center`?2*Math.max(-n,r)+t:r-n+t,i]}function T(e){let{count:t,size:n}=e;if(e.spread===`radial`)return{extent:{width:n,height:n},align:{x:`center`,y:`center`}};let r=Array.from({length:t},(t,n)=>C(n,e)),i=r.map(e=>e.x),a=r.map(e=>e.y),[o,s]=w(i,n),[c,l]=w(a,n);return{extent:{width:o,height:c},align:{x:s,y:l}}}function E(e,t){if(t.spread===`radial`)return D(e,t);let{count:n,size:r,gap:i,fadeWidth:a,open:o}=t,s=(n-1)*(r+i)+r+a,[c,l]=y[S(e,t)],u=c!==0,d=(u?c:l)<0,f=o?C(e,t):v,p=e===0?s:(n-e)*(r/n),m=e===0?-a/2:r/n*e,h=(d?p:m)-s-a/2,g=u?h-f.x:-f.x,_=u?-f.y:h-f.y,x=d?`#000 0px, #000 ${s}px, transparent ${s+a}px, transparent ${2*s}px`:`transparent 0px, transparent ${s}px, #000 ${s+a}px, #000 ${2*s}px`;return{translate:b(f,u),maskImage:n>1?`linear-gradient(${u?`to right`:`to bottom`}, ${x})`:`none`,maskSize:u?`${2*s}px 100%`:`100% ${2*s}px`,maskPosition:`${g}px ${_}px`}}function D(e,t){let{count:n,size:r,gap:i,fadeWidth:a,open:o}=t,s=t.radialStep,c=o?C(e,t):v,l=n>1?r+i:0,u=r+2*l,d=a?a/(r/2)*180/Math.PI:0,f=t.radialStart+(e-1)*s-s/2-d/2,p=x(s+d);return{translate:b(c,!1),maskImage:n>1&&e>0?`conic-gradient(from ${x(f)}deg, #0000 0deg, #000 ${x(d)}deg, #000 ${x(e===n-1?s:s+d)}deg, transparent ${p}deg)`:`none`,maskSize:`${u}px ${u}px`,maskPosition:`${-c.x-l}px ${-c.y-l}px`}}var O={direction:`left`,size:`large`,variant:`circular`,gap:16,fadeWidth:12,spread:`line`,radialStart:0,trigger:`hover`,defaultOpen:!1,disableClickAway:!1,transitionDuration:400,transitionEasing:`cubic-bezier(0.4, 0, 0.2, 1)`},k=1.08,A={circular:`50%`,rounded:`25%`,square:0},j=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function M(e,t){return`${e}ms ${t}`}function N(e){return(0,m.default)(`MuiCollageFab`,e)}var P=(e,t)=>(0,p.default)({root:[`root`,e?`expanded`:`collapsed`],item:[`item`]},N,t),F=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`root`,overridesResolver:(e,t)=>t.root})(({ownerState:e})=>{let{open:t,size:n,spread:r,gap:i,count:a,transitionDuration:o,transitionEasing:s}=e,{extent:c}=T(e),l=M(o,s),u=t&&r===`radial`&&a>1?n+i:0;return{position:`relative`,...u>0&&{"&::after":{content:`""`,position:`absolute`,inset:-u,borderRadius:`50%`,zIndex:-1}},width:t?c.width:n,height:t?c.height:n,transition:`width ${l}, height ${l}`,filter:`drop-shadow(0px 6px 12px rgba(0,0,0,0.25))`,cursor:t?`default`:`pointer`,WebkitTapHighlightColor:`transparent`}}),ee=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`item`,overridesResolver:(e,t)=>t.item})(({ownerState:e})=>{let{size:t,index:n,geometry:r,cornerRadius:i,transitionDuration:a,transitionEasing:o,open:s,spread:c,count:l}=e,u=!s&&c===`radial`&&l>1&&n>0,{align:d}=T(e),f={...d.x===`end`?{right:0}:d.x===`center`?{left:`50%`,marginLeft:-t/2}:{left:0},...d.y===`end`?{bottom:0}:d.y===`center`?{top:`50%`,marginTop:-t/2}:{top:0}},p=M(a,o);return{position:`absolute`,...f,width:t,height:t,borderRadius:i,overflow:`hidden`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:e.spread===`radial`?e.count-n:n,transform:`${r.translate} scale(${u?k:1})`,WebkitMaskImage:r.maskImage,maskImage:r.maskImage,WebkitMaskSize:r.maskSize,maskSize:r.maskSize,WebkitMaskPosition:r.maskPosition,maskPosition:r.maskPosition,WebkitMaskRepeat:`no-repeat`,maskRepeat:`no-repeat`,transition:`transform ${p}, -webkit-mask-position ${p}, mask-position ${p}`,"& > *":{boxShadow:`none !important`,borderRadius:`inherit !important`,width:`100%`,height:`100%`,margin:0}}});function I(e){let{index:t,ownerState:n,geometry:r,className:i,component:a,inert:o,itemRefs:s,slotProps:l,children:u}=e,p=c.useMemo(()=>({...n,index:t,isAnchor:t===0,geometry:r}),[n,t,r]),m=c.useRef(null),g=c.useCallback(e=>{s.current[t]=e},[s,t]),_=(0,d.useForkRef)(g,m);c.useEffect(()=>{let e=m.current;e&&`inert`in HTMLElement.prototype&&(e.inert=o)},[o]);let v=(0,f.default)({elementType:a,externalSlotProps:l,ownerState:p,additionalProps:{ref:_,className:i,"aria-hidden":o||void 0,children:u}});return(0,h.jsx)(a,{...v})}var L=c.forwardRef(function(e,t){let{children:n,direction:r=O.direction,directions:i,spread:a=O.spread,radialStart:o=O.radialStart,radialStep:s,size:p=O.size,variant:m=O.variant,gap:g=O.gap,fadeWidth:v=O.fadeWidth,trigger:y=O.trigger,open:b,defaultOpen:x=O.defaultOpen,onOpen:S,onClose:C,disableClickAway:w=O.disableClickAway,transitionDuration:T=O.transitionDuration,transitionEasing:D=O.transitionEasing,classes:k,slots:M,slotProps:N,className:L,...R}=(0,u.useThemeProps)({props:e,name:`MuiCollageFab`}),[z,B]=(0,d.useControlled)({controlled:b,default:x,name:`CollageFab`,state:`open`}),V=c.useMemo(()=>c.Children.toArray(n).filter(e=>c.isValidElement(e)),[n]),H=V.length,U={open:z,direction:r,directions:c.useMemo(()=>V.map((e,t)=>i?.[t]??r),[V,i,r]),spread:a,radialStart:o,radialStep:s??360/Math.max(H-1,1),trigger:y,size:_(p),variant:m,cornerRadius:A[m],gap:g,fadeWidth:v,count:H,transitionDuration:T,transitionEasing:D},W=P(z,k),G=c.useRef(null),K=c.useRef([]),q=c.useRef(!1),J=c.useRef(`mouse`),Y=c.useRef(!1),X=(0,d.useForkRef)(G,t),Z=c.useCallback((e,t)=>{e!==z&&(B(e),e?S?.(t):C?.(t))},[z,B,S,C]),te=e=>{y===`hover`&&e.pointerType===`mouse`&&Z(!0,e)},ne=e=>{y===`hover`&&e.pointerType===`mouse`&&Z(!1,e)},re=e=>{y!==`manual`&&(J.current=e.pointerType,q.current=!1,e.pointerType===`mouse`||z||(q.current=!0,Z(!0,e)))},ie=e=>{q.current&&(q.current=!1,e.stopPropagation(),e.preventDefault())},ae=e=>{y!==`manual`&&(y===`click`?Z(!z,e):z&&J.current!==`mouse`&&Z(!1,e))},oe=e=>{if(y!==`manual`){if(z){if(e.key!==`Escape`)return;e.stopPropagation(),Z(!1,e),G.current?.focus()}else(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),Y.current=!0,Z(!0,e))}},se=e=>{Z(!1,e)},Q=M?.root??F,ce=M?.item??ee,le=(0,f.default)({elementType:Q,externalForwardedProps:R,externalSlotProps:N?.root,ownerState:U,additionalProps:{ref:X,role:`group`,tabIndex:!z&&y!==`manual`?0:-1,onPointerEnter:te,onPointerLeave:ne,onPointerDown:re,onClick:ae,onClickCapture:ie,onKeyDown:oe},className:[W.root,L]});if(c.useEffect(()=>{if(!z||!Y.current)return;Y.current=!1;let e=K.current[0];e&&(e.querySelector(j)??e).focus()},[z]),H===0)return null;let $=(0,h.jsx)(Q,{...le,children:V.map((e,t)=>(0,h.jsx)(I,{index:t,ownerState:U,geometry:E(t,U),className:W.item,component:ce,inert:!z&&(y!==`manual`||t>0),itemRefs:K,slotProps:N?.item,children:e},t))});return w||y===`manual`?$:(0,h.jsx)(l.ClickAwayListener,{onClickAway:se,children:$})});exports.CollageFab=L;
package/dist-lib/index.js CHANGED
@@ -112,11 +112,11 @@ var S = {
112
112
  disableClickAway: !1,
113
113
  transitionDuration: 400,
114
114
  transitionEasing: "cubic-bezier(0.4, 0, 0.2, 1)"
115
- }, C = {
115
+ }, C = 1.08, w = {
116
116
  circular: "50%",
117
117
  rounded: "25%",
118
118
  square: 0
119
- }, w = "a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])";
119
+ }, ee = "a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])";
120
120
  function T(e, t) {
121
121
  return `${e}ms ${t}`;
122
122
  }
@@ -153,19 +153,19 @@ var D = (e, t) => s({
153
153
  slot: "item",
154
154
  overridesResolver: (e, t) => t.item
155
155
  })(({ ownerState: e }) => {
156
- let { size: t, index: n, geometry: r, cornerRadius: i, transitionDuration: a, transitionEasing: o } = e, { align: s } = y(e), c = {
157
- ...s.x === "end" ? { right: 0 } : s.x === "center" ? {
156
+ let { size: t, index: n, geometry: r, cornerRadius: i, transitionDuration: a, transitionEasing: o, open: s, spread: c, count: l } = e, u = !s && c === "radial" && l > 1 && n > 0, { align: d } = y(e), f = {
157
+ ...d.x === "end" ? { right: 0 } : d.x === "center" ? {
158
158
  left: "50%",
159
159
  marginLeft: -t / 2
160
160
  } : { left: 0 },
161
- ...s.y === "end" ? { bottom: 0 } : s.y === "center" ? {
161
+ ...d.y === "end" ? { bottom: 0 } : d.y === "center" ? {
162
162
  top: "50%",
163
163
  marginTop: -t / 2
164
164
  } : { top: 0 }
165
- }, l = T(a, o);
165
+ }, p = T(a, o);
166
166
  return {
167
167
  position: "absolute",
168
- ...c,
168
+ ...f,
169
169
  width: t,
170
170
  height: t,
171
171
  borderRadius: i,
@@ -174,7 +174,7 @@ var D = (e, t) => s({
174
174
  alignItems: "center",
175
175
  justifyContent: "center",
176
176
  zIndex: e.spread === "radial" ? e.count - n : n,
177
- transform: r.translate,
177
+ transform: `${r.translate} scale(${u ? C : 1})`,
178
178
  WebkitMaskImage: r.maskImage,
179
179
  maskImage: r.maskImage,
180
180
  WebkitMaskSize: r.maskSize,
@@ -183,7 +183,7 @@ var D = (e, t) => s({
183
183
  maskPosition: r.maskPosition,
184
184
  WebkitMaskRepeat: "no-repeat",
185
185
  maskRepeat: "no-repeat",
186
- transition: `transform ${l}, -webkit-mask-position ${l}, mask-position ${l}`,
186
+ transition: `transform ${p}, -webkit-mask-position ${p}, mask-position ${p}`,
187
187
  "& > *": {
188
188
  boxShadow: "none !important",
189
189
  borderRadius: "inherit !important",
@@ -193,7 +193,7 @@ var D = (e, t) => s({
193
193
  }
194
194
  };
195
195
  });
196
- function A(t) {
196
+ function te(t) {
197
197
  let { index: n, ownerState: r, geometry: i, className: s, component: c, inert: u, itemRefs: d, slotProps: f, children: p } = t, m = e.useMemo(() => ({
198
198
  ...r,
199
199
  index: n,
@@ -223,13 +223,13 @@ function A(t) {
223
223
  });
224
224
  return /* @__PURE__ */ l(c, { ...v });
225
225
  }
226
- var j = e.forwardRef(function(n, s) {
227
- let { children: c, direction: u = S.direction, directions: f, spread: p = S.spread, radialStart: m = S.radialStart, radialStep: h, size: g = S.size, variant: _ = S.variant, gap: v = S.gap, fadeWidth: y = S.fadeWidth, trigger: x = S.trigger, open: T, defaultOpen: E = S.defaultOpen, onOpen: j, onClose: M, disableClickAway: ee = S.disableClickAway, transitionDuration: te = S.transitionDuration, transitionEasing: ne = S.transitionEasing, classes: N, slots: P, slotProps: F, className: I, ...L } = r({
226
+ var A = e.forwardRef(function(n, s) {
227
+ let { children: c, direction: u = S.direction, directions: f, spread: p = S.spread, radialStart: m = S.radialStart, radialStep: h, size: g = S.size, variant: _ = S.variant, gap: v = S.gap, fadeWidth: y = S.fadeWidth, trigger: x = S.trigger, open: C, defaultOpen: T = S.defaultOpen, onOpen: E, onClose: A, disableClickAway: ne = S.disableClickAway, transitionDuration: j = S.transitionDuration, transitionEasing: M = S.transitionEasing, classes: N, slots: P, slotProps: F, className: I, ...L } = r({
228
228
  props: n,
229
229
  name: "MuiCollageFab"
230
230
  }), [R, z] = i({
231
- controlled: T,
232
- default: E,
231
+ controlled: C,
232
+ default: T,
233
233
  name: "CollageFab",
234
234
  state: "open"
235
235
  }), B = e.useMemo(() => e.Children.toArray(c).filter((t) => e.isValidElement(t)), [c]), V = B.length, H = {
@@ -246,19 +246,19 @@ var j = e.forwardRef(function(n, s) {
246
246
  trigger: x,
247
247
  size: d(g),
248
248
  variant: _,
249
- cornerRadius: C[_],
249
+ cornerRadius: w[_],
250
250
  gap: v,
251
251
  fadeWidth: y,
252
252
  count: V,
253
- transitionDuration: te,
254
- transitionEasing: ne
253
+ transitionDuration: j,
254
+ transitionEasing: M
255
255
  }, U = D(R, N), W = e.useRef(null), G = e.useRef([]), K = e.useRef(!1), q = e.useRef("mouse"), J = e.useRef(!1), Y = a(W, s), X = e.useCallback((e, t) => {
256
- e !== R && (z(e), e ? j?.(t) : M?.(t));
256
+ e !== R && (z(e), e ? E?.(t) : A?.(t));
257
257
  }, [
258
258
  R,
259
259
  z,
260
- j,
261
- M
260
+ E,
261
+ A
262
262
  ]), re = (e) => {
263
263
  x === "hover" && e.pointerType === "mouse" && X(!0, e);
264
264
  }, ie = (e) => {
@@ -300,25 +300,25 @@ var j = e.forwardRef(function(n, s) {
300
300
  if (!R || !J.current) return;
301
301
  J.current = !1;
302
302
  let e = G.current[0];
303
- e && (e.querySelector(w) ?? e).focus();
303
+ e && (e.querySelector(ee) ?? e).focus();
304
304
  }, [R]), V === 0) return null;
305
305
  let $ = /* @__PURE__ */ l(Q, {
306
306
  ...ue,
307
- children: B.map((e, t) => /* @__PURE__ */ l(A, {
307
+ children: B.map((e, t) => /* @__PURE__ */ l(te, {
308
308
  index: t,
309
309
  ownerState: H,
310
310
  geometry: b(t, H),
311
311
  className: U.item,
312
312
  component: le,
313
- inert: !R && x !== "manual",
313
+ inert: !R && (x !== "manual" || t > 0),
314
314
  itemRefs: G,
315
315
  slotProps: F?.item,
316
316
  children: e
317
317
  }, t))
318
318
  });
319
- return ee || x === "manual" ? $ : /* @__PURE__ */ l(t, {
319
+ return ne || x === "manual" ? $ : /* @__PURE__ */ l(t, {
320
320
  onClickAway: Z,
321
321
  children: $
322
322
  });
323
323
  });
324
- export { j as CollageFab };
324
+ export { A as CollageFab };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mui-collage-fab",
3
- "version": "0.4.0",
4
- "description": "Material UI floating action button that unfolds a stack of overlapping Fab circles into a row.",
3
+ "version": "0.5.1",
4
+ "description": "Material UI floating action button that unfolds a stack of overlapping Fab circles into a row, a fan or a ring.",
5
5
  "license": "MIT",
6
6
  "author": "Radomir Wojtera",
7
7
  "homepage": "https://www.radomir.dev/mui-collage-fab/",
@@ -146,12 +146,12 @@
146
146
  {
147
147
  "name": "ESM build",
148
148
  "path": "dist-lib/index.js",
149
- "limit": "3.6 kB"
149
+ "limit": "3.4 kB"
150
150
  },
151
151
  {
152
152
  "name": "CJS build",
153
153
  "path": "dist-lib/index.cjs",
154
- "limit": "3.2 kB"
154
+ "limit": "3.3 kB"
155
155
  }
156
156
  ]
157
157
  }