mui-collage-fab 0.2.0 → 0.3.0

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
@@ -73,8 +73,9 @@ const [open, setOpen] = useState(false);
73
73
 
74
74
  | Prop | Type | Default | Description |
75
75
  | -------------------- | ------------------------------------------ | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
76
- | `children` | `React.ReactNode` | — | The buttons to stack. Every valid element is wrapped in a masked slot shaped by `variant`. Order matters: index 0 is the anchor, the rest fan out along `direction`. |
76
+ | `children` | `React.ReactNode` | — | The buttons to stack. Every valid element is wrapped in a masked slot shaped by `variant`. Order matters: index 0 is the anchor, the rest fan out along `direction` or their own entry in `directions`. |
77
77
  | `direction` | `'left' \| 'right' \| 'up' \| 'down'` | `'left'` | The axis the buttons fan out on, starting from the anchor child. `left` matches the original right-anchored behaviour. |
78
+ | `directions` | `('left' \| 'right' \| 'up' \| 'down')[]` | — | A direction per child, in child order, so one group can fan over several axes. Entry 0 belongs to the anchor and has no visible effect; an entry that is missing or past the end of the list falls back to `direction`. |
78
79
  | `size` | `'small' \| 'medium' \| 'large' \| number` | `'large'` | Diameter of every button. Named sizes resolve to small 40px, medium 48px, large 56px; numeric values are used verbatim. |
79
80
  | `variant` | `'circular' \| 'rounded' \| 'square'` | `'circular'` | The shape of every button. `'circular'` clips each slice to a circle, `'rounded'` to a rounded square and `'square'` to a sharp-cornered square. The mask still slices the silhouette along the main axis, so the stack reads as one shape when collapsed and as separate shapes when expanded. |
80
81
  | `gap` | `number` | `16` | Main-axis gap in pixels between two buttons when expanded. |
@@ -108,7 +109,7 @@ const [open, setOpen] = useState(false);
108
109
 
109
110
  <!-- api:owner-state:start -->
110
111
 
111
- `CollageFabOwnerState` carries `open`, `direction`, `trigger`, `size`, `variant`, `cornerRadius`, `gap`, `fadeWidth`, `count`, `transitionDuration` and `transitionEasing`. `CollageFabItemOwnerState` adds `index`, `isAnchor` and `geometry`.
112
+ `CollageFabOwnerState` carries `open`, `direction`, `directions`, `trigger`, `size`, `variant`, `cornerRadius`, `gap`, `fadeWidth`, `count`, `transitionDuration` and `transitionEasing`. `CollageFabItemOwnerState` adds `index`, `isAnchor` and `geometry`.
112
113
  <!-- api:owner-state:end -->
113
114
 
114
115
  Theme-level defaults and overrides work through the `MuiCollageFab` component key:
@@ -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={left:{x:-1,y:0},right:{x:1,y:0},up:{x:0,y:-1},down:{x:0,y:1}};function y({x:e,y:t},n){return e!==0&&t!==0?`translate(${e}px, ${t}px)`:n?`translateX(${e}px)`:`translateY(${t}px)`}function b(e,t){let n=v[t.direction],r=e*(t.size+t.gap);return{x:n.x*r,y:n.y*r}}function x(e){return e.every(e=>e<=0)&&e.some(e=>e<0)?`end`:`start`}function S(e){let{count:t,size:n}=e,r=Array.from({length:t},(t,n)=>b(n,e)),i=r.map(e=>e.x),a=r.map(e=>e.y);return{extent:{width:Math.max(...i,0)-Math.min(...i,0)+n,height:Math.max(...a,0)-Math.min(...a,0)+n},align:{x:x(i),y:x(a)}}}function C(e,t){let{count:n,size:r,gap:i,fadeWidth:a,open:o,direction:s}=t,c=r+i,l=(n-1)*c+r+a,u=v[s],d=u.x!==0,f=(d?u.x:u.y)<0,p=o?b(e,t):{x:0,y:0},m=e===0?l:(n-e)*(r/n),h=e===0?-a/2:r/n*e,g=(f?m:h)-l-a/2,_=d?{x:g,y:0}:{x:0,y:g},x={x:_.x-p.x,y:_.y-p.y},S=f?`#000 0px, #000 ${l}px, transparent ${l+a}px, transparent ${2*l}px`:`transparent 0px, transparent ${l}px, #000 ${l+a}px, #000 ${2*l}px`;return{translate:y(p,d),maskImage:n>1?`linear-gradient(${d?`to right`:`to bottom`}, ${S})`:`none`,maskSize:d?`${2*l}px 100%`:`100% ${2*l}px`,maskPosition:`${x.x}px ${x.y}px`}}var w={direction:`left`,size:`large`,variant:`circular`,gap:16,fadeWidth:12,trigger:`hover`,defaultOpen:!1,disableClickAway:!1,transitionDuration:400,transitionEasing:`cubic-bezier(0.4, 0, 0.2, 1)`},T={circular:`50%`,rounded:`25%`,square:0},ee=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function E(e,t){return`${e}ms ${t}`}function D(e){return(0,m.default)(`MuiCollageFab`,e)}var te=(e,t)=>(0,p.default)({root:[`root`,e?`expanded`:`collapsed`],item:[`item`]},D,t),O=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`root`,overridesResolver:(e,t)=>t.root})(({ownerState:e})=>{let{open:t,size:n,transitionDuration:r,transitionEasing:i}=e,{extent:a}=S(e),o=E(r,i);return{position:`relative`,width:t?a.width:n,height:t?a.height:n,transition:`width ${o}, height ${o}`,filter:`drop-shadow(0px 6px 12px rgba(0,0,0,0.25))`,cursor:t?`default`:`pointer`,WebkitTapHighlightColor:`transparent`}}),k=(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}=S(e),c={...s.x===`end`?{right:0}:{left:0},...s.y===`end`?{bottom:0}:{top:0}},l=E(a,o);return{position:`absolute`,...c,width:t,height:t,borderRadius:i,overflow:`hidden`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex: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 A(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 j=c.forwardRef(function(e,t){let{children:n,direction:r=w.direction,size:i=w.size,variant:a=w.variant,gap:o=w.gap,fadeWidth:s=w.fadeWidth,trigger:p=w.trigger,open:m,defaultOpen:g=w.defaultOpen,onOpen:v,onClose:y,disableClickAway:b=w.disableClickAway,transitionDuration:x=w.transitionDuration,transitionEasing:S=w.transitionEasing,classes:E,slots:D,slotProps:j,className:ne,...M}=(0,u.useThemeProps)({props:e,name:`MuiCollageFab`}),[N,P]=(0,d.useControlled)({controlled:m,default:g,name:`CollageFab`,state:`open`}),F=c.useMemo(()=>c.Children.toArray(n).filter(e=>c.isValidElement(e)),[n]),I=F.length,L={open:N,direction:r,trigger:p,size:_(i),variant:a,cornerRadius:T[a],gap:o,fadeWidth:s,count:I,transitionDuration:x,transitionEasing:S},R=te(N,E),z=c.useRef(null),B=c.useRef([]),V=c.useRef(!1),H=c.useRef(`mouse`),U=c.useRef(!1),W=(0,d.useForkRef)(z,t),G=c.useCallback((e,t)=>{e!==N&&(P(e),e?v?.(t):y?.(t))},[N,P,v,y]),K=e=>{p===`hover`&&e.pointerType===`mouse`&&G(!0,e)},q=e=>{p===`hover`&&e.pointerType===`mouse`&&G(!1,e)},J=e=>{p!==`manual`&&(H.current=e.pointerType,V.current=!1,e.pointerType===`mouse`||N||(V.current=!0,G(!0,e)))},Y=e=>{V.current&&(V.current=!1,e.stopPropagation(),e.preventDefault())},X=e=>{p!==`manual`&&(p===`click`?G(!N,e):N&&H.current!==`mouse`&&G(!1,e))},Z=e=>{if(p!==`manual`){if(N){if(e.key!==`Escape`)return;e.stopPropagation(),G(!1,e),z.current?.focus()}else(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),U.current=!0,G(!0,e))}},re=e=>{G(!1,e)},Q=D?.root??O,ie=D?.item??k,ae=(0,f.default)({elementType:Q,externalForwardedProps:M,externalSlotProps:j?.root,ownerState:L,additionalProps:{ref:W,role:`group`,tabIndex:!N&&p!==`manual`?0:-1,onPointerEnter:K,onPointerLeave:q,onPointerDown:J,onClick:X,onClickCapture:Y,onKeyDown:Z},className:[R.root,ne]});if(c.useEffect(()=>{if(!N||!U.current)return;U.current=!1;let e=B.current[0];e&&(e.querySelector(ee)??e).focus()},[N]),I===0)return null;let $=(0,h.jsx)(Q,{...ae,children:F.map((e,t)=>(0,h.jsx)(A,{index:t,ownerState:L,geometry:C(t,L),className:R.item,component:ie,inert:!N&&p!==`manual`,itemRefs:B,slotProps:j?.item,children:e},t))});return b||p===`manual`?$:(0,h.jsx)(l.ClickAwayListener,{onClickAway:re,children:$})});exports.CollageFab=j;
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={left:{x:-1,y:0},right:{x:1,y:0},up:{x:0,y:-1},down:{x:0,y:1}};function y({x:e,y:t},n){return e!==0&&t!==0?`translate(${e}px, ${t}px)`:n?`translateX(${e}px)`:`translateY(${t}px)`}function b(e,t){return t.directions[e]??t.direction}function x(e,t){let n=b(e,t),r=v[n],i=t.size+t.gap,a=0;for(let r=0;r<e;r+=1)b(r,t)===n&&(a+=1);let o=(a+(n===b(0,t)?0:1))*i;return{x:r.x*o,y:r.y*o}}function S(e){let t=e.some(e=>e<0),n=e.some(e=>e>0);return t&&n?`center`:t?`end`:`start`}function C(e){let{count:t,size:n}=e,r=Array.from({length:t},(t,n)=>x(n,e)),i=r.map(e=>e.x),a=r.map(e=>e.y),o=e=>{let t=Math.min(...e,0),r=Math.max(...e,0);return S(e)===`center`?2*Math.max(-t,r)+n:r-t+n};return{extent:{width:o(i),height:o(a)},align:{x:S(i),y:S(a)}}}function w(e,t){let{count:n,size:r,gap:i,fadeWidth:a,open:o}=t,s=r+i,c=(n-1)*s+r+a,l=v[b(e,t)],u=l.x!==0,d=(u?l.x:l.y)<0,f=o?x(e,t):{x:0,y:0},p=e===0?c:(n-e)*(r/n),m=e===0?-a/2:r/n*e,h=(d?p:m)-c-a/2,g=u?{x:h,y:0}:{x:0,y:h},_={x:g.x-f.x,y:g.y-f.y},S=d?`#000 0px, #000 ${c}px, transparent ${c+a}px, transparent ${2*c}px`:`transparent 0px, transparent ${c}px, #000 ${c+a}px, #000 ${2*c}px`;return{translate:y(f,u),maskImage:n>1?`linear-gradient(${u?`to right`:`to bottom`}, ${S})`:`none`,maskSize:u?`${2*c}px 100%`:`100% ${2*c}px`,maskPosition:`${_.x}px ${_.y}px`}}var T={direction:`left`,size:`large`,variant:`circular`,gap:16,fadeWidth:12,trigger:`hover`,defaultOpen:!1,disableClickAway:!1,transitionDuration:400,transitionEasing:`cubic-bezier(0.4, 0, 0.2, 1)`},E={circular:`50%`,rounded:`25%`,square:0},D=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function O(e,t){return`${e}ms ${t}`}function k(e){return(0,m.default)(`MuiCollageFab`,e)}var A=(e,t)=>(0,p.default)({root:[`root`,e?`expanded`:`collapsed`],item:[`item`]},k,t),j=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`root`,overridesResolver:(e,t)=>t.root})(({ownerState:e})=>{let{open:t,size:n,transitionDuration:r,transitionEasing:i}=e,{extent:a}=C(e),o=O(r,i);return{position:`relative`,width:t?a.width:n,height:t?a.height:n,transition:`width ${o}, height ${o}`,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}=e,{align:s}=C(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=O(a,o);return{position:`absolute`,...c,width:t,height:t,borderRadius:i,overflow:`hidden`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex: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 te(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 M=c.forwardRef(function(e,t){let{children:n,direction:r=T.direction,directions:i,size:a=T.size,variant:o=T.variant,gap:s=T.gap,fadeWidth:p=T.fadeWidth,trigger:m=T.trigger,open:g,defaultOpen:v=T.defaultOpen,onOpen:y,onClose:b,disableClickAway:x=T.disableClickAway,transitionDuration:S=T.transitionDuration,transitionEasing:C=T.transitionEasing,classes:O,slots:k,slotProps:M,className:N,...P}=(0,u.useThemeProps)({props:e,name:`MuiCollageFab`}),[F,I]=(0,d.useControlled)({controlled:g,default:v,name:`CollageFab`,state:`open`}),L=c.useMemo(()=>c.Children.toArray(n).filter(e=>c.isValidElement(e)),[n]),R=L.length,z={open:F,direction:r,directions:c.useMemo(()=>L.map((e,t)=>i?.[t]??r),[L,i,r]),trigger:m,size:_(a),variant:o,cornerRadius:E[o],gap:s,fadeWidth:p,count:R,transitionDuration:S,transitionEasing:C},B=A(F,O),V=c.useRef(null),H=c.useRef([]),U=c.useRef(!1),W=c.useRef(`mouse`),G=c.useRef(!1),K=(0,d.useForkRef)(V,t),q=c.useCallback((e,t)=>{e!==F&&(I(e),e?y?.(t):b?.(t))},[F,I,y,b]),J=e=>{m===`hover`&&e.pointerType===`mouse`&&q(!0,e)},Y=e=>{m===`hover`&&e.pointerType===`mouse`&&q(!1,e)},X=e=>{m!==`manual`&&(W.current=e.pointerType,U.current=!1,e.pointerType===`mouse`||F||(U.current=!0,q(!0,e)))},Z=e=>{U.current&&(U.current=!1,e.stopPropagation(),e.preventDefault())},ne=e=>{m!==`manual`&&(m===`click`?q(!F,e):F&&W.current!==`mouse`&&q(!1,e))},re=e=>{if(m!==`manual`){if(F){if(e.key!==`Escape`)return;e.stopPropagation(),q(!1,e),V.current?.focus()}else(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),G.current=!0,q(!0,e))}},ie=e=>{q(!1,e)},Q=k?.root??j,ae=k?.item??ee,oe=(0,f.default)({elementType:Q,externalForwardedProps:P,externalSlotProps:M?.root,ownerState:z,additionalProps:{ref:K,role:`group`,tabIndex:!F&&m!==`manual`?0:-1,onPointerEnter:J,onPointerLeave:Y,onPointerDown:X,onClick:ne,onClickCapture:Z,onKeyDown:re},className:[B.root,N]});if(c.useEffect(()=>{if(!F||!G.current)return;G.current=!1;let e=H.current[0];e&&(e.querySelector(D)??e).focus()},[F]),R===0)return null;let $=(0,h.jsx)(Q,{...oe,children:L.map((e,t)=>(0,h.jsx)(te,{index:t,ownerState:z,geometry:w(t,z),className:B.item,component:ae,inert:!F&&m!==`manual`,itemRefs:H,slotProps:M?.item,children:e},t))});return x||m===`manual`?$:(0,h.jsx)(l.ClickAwayListener,{onClickAway:ie,children:$})});exports.CollageFab=M;
@@ -53,8 +53,10 @@ interface CollageFabItemSlotPropsOverrides {
53
53
  interface CollageFabOwnerState {
54
54
  /** Whether the group is currently expanded. */
55
55
  open: boolean;
56
- /** The resolved fan-out direction. */
56
+ /** The resolved fan-out direction used by every child without a `directions` entry. */
57
57
  direction: CollageFabDirection;
58
+ /** The resolved direction of each child, in child order. */
59
+ directions: CollageFabDirection[];
58
60
  /** The resolved pointer trigger mode. */
59
61
  trigger: CollageFabTrigger;
60
62
  /** The button diameter in pixels, after resolving the named size. */
@@ -124,7 +126,7 @@ interface CollageFabProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'ch
124
126
  /**
125
127
  * The buttons to stack. Every valid element is wrapped in a masked slot shaped
126
128
  * by `variant`. Order matters: index 0 is the anchor, the rest fan out along
127
- * `direction`.
129
+ * `direction` or their own entry in `directions`.
128
130
  */
129
131
  children?: React.ReactNode;
130
132
  /**
@@ -132,6 +134,12 @@ interface CollageFabProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'ch
132
134
  * matches the original right-anchored behaviour.
133
135
  */
134
136
  direction?: CollageFabDirection;
137
+ /**
138
+ * A direction per child, in child order, so one group can fan over several axes.
139
+ * Entry 0 belongs to the anchor and has no visible effect; an entry that is
140
+ * missing or past the end of the list falls back to `direction`.
141
+ */
142
+ directions?: CollageFabDirection[];
135
143
  /**
136
144
  * Diameter of every button. Named sizes resolve to small 40px, medium 48px,
137
145
  * large 56px; numeric values are used verbatim.
@@ -53,8 +53,10 @@ interface CollageFabItemSlotPropsOverrides {
53
53
  interface CollageFabOwnerState {
54
54
  /** Whether the group is currently expanded. */
55
55
  open: boolean;
56
- /** The resolved fan-out direction. */
56
+ /** The resolved fan-out direction used by every child without a `directions` entry. */
57
57
  direction: CollageFabDirection;
58
+ /** The resolved direction of each child, in child order. */
59
+ directions: CollageFabDirection[];
58
60
  /** The resolved pointer trigger mode. */
59
61
  trigger: CollageFabTrigger;
60
62
  /** The button diameter in pixels, after resolving the named size. */
@@ -124,7 +126,7 @@ interface CollageFabProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'ch
124
126
  /**
125
127
  * The buttons to stack. Every valid element is wrapped in a masked slot shaped
126
128
  * by `variant`. Order matters: index 0 is the anchor, the rest fan out along
127
- * `direction`.
129
+ * `direction` or their own entry in `directions`.
128
130
  */
129
131
  children?: React.ReactNode;
130
132
  /**
@@ -132,6 +134,12 @@ interface CollageFabProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'ch
132
134
  * matches the original right-anchored behaviour.
133
135
  */
134
136
  direction?: CollageFabDirection;
137
+ /**
138
+ * A direction per child, in child order, so one group can fan over several axes.
139
+ * Entry 0 belongs to the anchor and has no visible effect; an entry that is
140
+ * missing or past the end of the list falls back to `direction`.
141
+ */
142
+ directions?: CollageFabDirection[];
135
143
  /**
136
144
  * Diameter of every button. Named sizes resolve to small 40px, medium 48px,
137
145
  * large 56px; numeric values are used verbatim.
package/dist-lib/index.js CHANGED
@@ -37,33 +37,42 @@ function p({ x: e, y: t }, n) {
37
37
  return e !== 0 && t !== 0 ? `translate(${e}px, ${t}px)` : n ? `translateX(${e}px)` : `translateY(${t}px)`;
38
38
  }
39
39
  function m(e, t) {
40
- let n = f[t.direction], r = e * (t.size + t.gap);
40
+ return t.directions[e] ?? t.direction;
41
+ }
42
+ function h(e, t) {
43
+ let n = m(e, t), r = f[n], i = t.size + t.gap, a = 0;
44
+ for (let r = 0; r < e; r += 1) m(r, t) === n && (a += 1);
45
+ let o = (a + (n === m(0, t) ? 0 : 1)) * i;
41
46
  return {
42
- x: n.x * r,
43
- y: n.y * r
47
+ x: r.x * o,
48
+ y: r.y * o
44
49
  };
45
50
  }
46
- function h(e) {
47
- return e.every((e) => e <= 0) && e.some((e) => e < 0) ? "end" : "start";
48
- }
49
51
  function g(e) {
50
- let { count: t, size: n } = e, r = Array.from({ length: t }, (t, n) => m(n, e)), i = r.map((e) => e.x), a = r.map((e) => e.y);
52
+ let t = e.some((e) => e < 0), n = e.some((e) => e > 0);
53
+ return t && n ? "center" : t ? "end" : "start";
54
+ }
55
+ function _(e) {
56
+ let { count: t, size: n } = e, r = Array.from({ length: t }, (t, n) => h(n, e)), i = r.map((e) => e.x), a = r.map((e) => e.y), o = (e) => {
57
+ let t = Math.min(...e, 0), r = Math.max(...e, 0);
58
+ return g(e) === "center" ? 2 * Math.max(-t, r) + n : r - t + n;
59
+ };
51
60
  return {
52
61
  extent: {
53
- width: Math.max(...i, 0) - Math.min(...i, 0) + n,
54
- height: Math.max(...a, 0) - Math.min(...a, 0) + n
62
+ width: o(i),
63
+ height: o(a)
55
64
  },
56
65
  align: {
57
- x: h(i),
58
- y: h(a)
66
+ x: g(i),
67
+ y: g(a)
59
68
  }
60
69
  };
61
70
  }
62
- function _(e, t) {
63
- let { count: n, size: r, gap: i, fadeWidth: a, open: o, direction: s } = t, c = r + i, l = (n - 1) * c + r + a, u = f[s], d = u.x !== 0, h = (d ? u.x : u.y) < 0, g = o ? m(e, t) : {
71
+ function v(e, t) {
72
+ let { count: n, size: r, gap: i, fadeWidth: a, open: o } = t, s = r + i, c = (n - 1) * s + r + a, l = f[m(e, t)], u = l.x !== 0, d = (u ? l.x : l.y) < 0, g = o ? h(e, t) : {
64
73
  x: 0,
65
74
  y: 0
66
- }, _ = e === 0 ? l : (n - e) * (r / n), v = e === 0 ? -a / 2 : r / n * e, y = (h ? _ : v) - l - a / 2, b = d ? {
75
+ }, _ = e === 0 ? c : (n - e) * (r / n), v = e === 0 ? -a / 2 : r / n * e, y = (d ? _ : v) - c - a / 2, b = u ? {
67
76
  x: y,
68
77
  y: 0
69
78
  } : {
@@ -72,16 +81,16 @@ function _(e, t) {
72
81
  }, x = {
73
82
  x: b.x - g.x,
74
83
  y: b.y - g.y
75
- }, S = h ? `#000 0px, #000 ${l}px, transparent ${l + a}px, transparent ${2 * l}px` : `transparent 0px, transparent ${l}px, #000 ${l + a}px, #000 ${2 * l}px`;
84
+ }, S = d ? `#000 0px, #000 ${c}px, transparent ${c + a}px, transparent ${2 * c}px` : `transparent 0px, transparent ${c}px, #000 ${c + a}px, #000 ${2 * c}px`;
76
85
  return {
77
- translate: p(g, d),
78
- maskImage: n > 1 ? `linear-gradient(${d ? "to right" : "to bottom"}, ${S})` : "none",
79
- maskSize: d ? `${2 * l}px 100%` : `100% ${2 * l}px`,
86
+ translate: p(g, u),
87
+ maskImage: n > 1 ? `linear-gradient(${u ? "to right" : "to bottom"}, ${S})` : "none",
88
+ maskSize: u ? `${2 * c}px 100%` : `100% ${2 * c}px`,
80
89
  maskPosition: `${x.x}px ${x.y}px`
81
90
  };
82
91
  }
83
92
  // src/components/collageFabDefaults.ts
84
- var v = {
93
+ var y = {
85
94
  direction: "left",
86
95
  size: "large",
87
96
  variant: "circular",
@@ -92,26 +101,26 @@ var v = {
92
101
  disableClickAway: !1,
93
102
  transitionDuration: 400,
94
103
  transitionEasing: "cubic-bezier(0.4, 0, 0.2, 1)"
95
- }, y = {
104
+ }, b = {
96
105
  circular: "50%",
97
106
  rounded: "25%",
98
107
  square: 0
99
- }, b = "a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])";
100
- function x(e, t) {
108
+ }, x = "a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])";
109
+ function S(e, t) {
101
110
  return `${e}ms ${t}`;
102
111
  }
103
- function S(e) {
112
+ function C(e) {
104
113
  return c("MuiCollageFab", e);
105
114
  }
106
- var C = (e, t) => s({
115
+ var w = (e, t) => s({
107
116
  root: ["root", e ? "expanded" : "collapsed"],
108
117
  item: ["item"]
109
- }, S, t), w = n("div", {
118
+ }, C, t), T = n("div", {
110
119
  name: "MuiCollageFab",
111
120
  slot: "root",
112
121
  overridesResolver: (e, t) => t.root
113
122
  })(({ ownerState: e }) => {
114
- let { open: t, size: n, transitionDuration: r, transitionEasing: i } = e, { extent: a } = g(e), o = x(r, i);
123
+ let { open: t, size: n, transitionDuration: r, transitionEasing: i } = e, { extent: a } = _(e), o = S(r, i);
115
124
  return {
116
125
  position: "relative",
117
126
  width: t ? a.width : n,
@@ -121,15 +130,21 @@ var C = (e, t) => s({
121
130
  cursor: t ? "default" : "pointer",
122
131
  WebkitTapHighlightColor: "transparent"
123
132
  };
124
- }), T = n("div", {
133
+ }), ee = n("div", {
125
134
  name: "MuiCollageFab",
126
135
  slot: "item",
127
136
  overridesResolver: (e, t) => t.item
128
137
  })(({ ownerState: e }) => {
129
- let { size: t, index: n, geometry: r, cornerRadius: i, transitionDuration: a, transitionEasing: o } = e, { align: s } = g(e), c = {
130
- ...s.x === "end" ? { right: 0 } : { left: 0 },
131
- ...s.y === "end" ? { bottom: 0 } : { top: 0 }
132
- }, l = x(a, o);
138
+ let { size: t, index: n, geometry: r, cornerRadius: i, transitionDuration: a, transitionEasing: o } = e, { align: s } = _(e), c = {
139
+ ...s.x === "end" ? { right: 0 } : s.x === "center" ? {
140
+ left: "50%",
141
+ marginLeft: -t / 2
142
+ } : { left: 0 },
143
+ ...s.y === "end" ? { bottom: 0 } : s.y === "center" ? {
144
+ top: "50%",
145
+ marginTop: -t / 2
146
+ } : { top: 0 }
147
+ }, l = S(a, o);
133
148
  return {
134
149
  position: "absolute",
135
150
  ...c,
@@ -160,7 +175,7 @@ var C = (e, t) => s({
160
175
  }
161
176
  };
162
177
  });
163
- function E(t) {
178
+ function te(t) {
164
179
  let { index: n, ownerState: r, geometry: i, className: s, component: c, inert: u, itemRefs: d, slotProps: f, children: p } = t, m = e.useMemo(() => ({
165
180
  ...r,
166
181
  index: n,
@@ -190,94 +205,99 @@ function E(t) {
190
205
  });
191
206
  return /* @__PURE__ */ l(c, { ...v });
192
207
  }
193
- var D = e.forwardRef(function(n, s) {
194
- let { children: c, direction: u = v.direction, size: f = v.size, variant: p = v.variant, gap: m = v.gap, fadeWidth: h = v.fadeWidth, trigger: g = v.trigger, open: x, defaultOpen: S = v.defaultOpen, onOpen: D, onClose: O, disableClickAway: k = v.disableClickAway, transitionDuration: ee = v.transitionDuration, transitionEasing: te = v.transitionEasing, classes: A, slots: j, slotProps: M, className: N, ...P } = r({
208
+ var E = e.forwardRef(function(n, s) {
209
+ let { children: c, direction: u = y.direction, directions: f, size: p = y.size, variant: m = y.variant, gap: h = y.gap, fadeWidth: g = y.fadeWidth, trigger: _ = y.trigger, open: S, defaultOpen: C = y.defaultOpen, onOpen: E, onClose: D, disableClickAway: O = y.disableClickAway, transitionDuration: k = y.transitionDuration, transitionEasing: A = y.transitionEasing, classes: j, slots: M, slotProps: N, className: P, ...F } = r({
195
210
  props: n,
196
211
  name: "MuiCollageFab"
197
- }), [F, I] = i({
198
- controlled: x,
199
- default: S,
212
+ }), [I, L] = i({
213
+ controlled: S,
214
+ default: C,
200
215
  name: "CollageFab",
201
216
  state: "open"
202
- }), L = e.useMemo(() => e.Children.toArray(c).filter((t) => e.isValidElement(t)), [c]), R = L.length, z = {
203
- open: F,
217
+ }), R = e.useMemo(() => e.Children.toArray(c).filter((t) => e.isValidElement(t)), [c]), z = R.length, B = {
218
+ open: I,
204
219
  direction: u,
205
- trigger: g,
206
- size: d(f),
207
- variant: p,
208
- cornerRadius: y[p],
209
- gap: m,
210
- fadeWidth: h,
211
- count: R,
212
- transitionDuration: ee,
213
- transitionEasing: te
214
- }, B = C(F, A), V = e.useRef(null), H = e.useRef([]), U = e.useRef(!1), W = e.useRef("mouse"), G = e.useRef(!1), K = a(V, s), q = e.useCallback((e, t) => {
215
- e !== F && (I(e), e ? D?.(t) : O?.(t));
220
+ directions: e.useMemo(() => R.map((e, t) => f?.[t] ?? u), [
221
+ R,
222
+ f,
223
+ u
224
+ ]),
225
+ trigger: _,
226
+ size: d(p),
227
+ variant: m,
228
+ cornerRadius: b[m],
229
+ gap: h,
230
+ fadeWidth: g,
231
+ count: z,
232
+ transitionDuration: k,
233
+ transitionEasing: A
234
+ }, V = w(I, j), H = e.useRef(null), U = e.useRef([]), W = e.useRef(!1), G = e.useRef("mouse"), K = e.useRef(!1), q = a(H, s), J = e.useCallback((e, t) => {
235
+ e !== I && (L(e), e ? E?.(t) : D?.(t));
216
236
  }, [
217
- F,
218
237
  I,
219
- D,
220
- O
221
- ]), J = (e) => {
222
- g === "hover" && e.pointerType === "mouse" && q(!0, e);
223
- }, Y = (e) => {
224
- g === "hover" && e.pointerType === "mouse" && q(!1, e);
238
+ L,
239
+ E,
240
+ D
241
+ ]), Y = (e) => {
242
+ _ === "hover" && e.pointerType === "mouse" && J(!0, e);
225
243
  }, X = (e) => {
226
- g !== "manual" && (W.current = e.pointerType, U.current = !1, e.pointerType === "mouse" || F || (U.current = !0, q(!0, e)));
244
+ _ === "hover" && e.pointerType === "mouse" && J(!1, e);
227
245
  }, Z = (e) => {
228
- U.current && (U.current = !1, e.stopPropagation(), e.preventDefault());
246
+ _ !== "manual" && (G.current = e.pointerType, W.current = !1, e.pointerType === "mouse" || I || (W.current = !0, J(!0, e)));
229
247
  }, ne = (e) => {
230
- g !== "manual" && (g === "click" ? q(!F, e) : F && W.current !== "mouse" && q(!1, e));
248
+ W.current && (W.current = !1, e.stopPropagation(), e.preventDefault());
231
249
  }, re = (e) => {
232
- if (g !== "manual") {
233
- if (F) {
250
+ _ !== "manual" && (_ === "click" ? J(!I, e) : I && G.current !== "mouse" && J(!1, e));
251
+ }, ie = (e) => {
252
+ if (_ !== "manual") {
253
+ if (I) {
234
254
  if (e.key !== "Escape") return;
235
- e.stopPropagation(), q(!1, e), V.current?.focus();
236
- } else (e.key === "Enter" || e.key === " ") && (e.preventDefault(), G.current = !0, q(!0, e));
255
+ e.stopPropagation(), J(!1, e), H.current?.focus();
256
+ } else (e.key === "Enter" || e.key === " ") && (e.preventDefault(), K.current = !0, J(!0, e));
237
257
  }
238
- }, ie = (e) => {
239
- q(!1, e);
240
- }, Q = j?.root ?? w, ae = j?.item ?? T, oe = o({
258
+ }, ae = (e) => {
259
+ J(!1, e);
260
+ }, Q = M?.root ?? T, oe = M?.item ?? ee, se = o({
241
261
  elementType: Q,
242
- externalForwardedProps: P,
243
- externalSlotProps: M?.root,
244
- ownerState: z,
262
+ externalForwardedProps: F,
263
+ externalSlotProps: N?.root,
264
+ ownerState: B,
245
265
  additionalProps: {
246
- ref: K,
266
+ ref: q,
247
267
  role: "group",
248
- tabIndex: !F && g !== "manual" ? 0 : -1,
249
- onPointerEnter: J,
250
- onPointerLeave: Y,
251
- onPointerDown: X,
252
- onClick: ne,
253
- onClickCapture: Z,
254
- onKeyDown: re
268
+ tabIndex: !I && _ !== "manual" ? 0 : -1,
269
+ onPointerEnter: Y,
270
+ onPointerLeave: X,
271
+ onPointerDown: Z,
272
+ onClick: re,
273
+ onClickCapture: ne,
274
+ onKeyDown: ie
255
275
  },
256
- className: [B.root, N]
276
+ className: [V.root, P]
257
277
  });
258
278
  if (e.useEffect(() => {
259
- if (!F || !G.current) return;
260
- G.current = !1;
261
- let e = H.current[0];
262
- e && (e.querySelector(b) ?? e).focus();
263
- }, [F]), R === 0) return null;
279
+ if (!I || !K.current) return;
280
+ K.current = !1;
281
+ let e = U.current[0];
282
+ e && (e.querySelector(x) ?? e).focus();
283
+ }, [I]), z === 0) return null;
264
284
  let $ = /* @__PURE__ */ l(Q, {
265
- ...oe,
266
- children: L.map((e, t) => /* @__PURE__ */ l(E, {
285
+ ...se,
286
+ children: R.map((e, t) => /* @__PURE__ */ l(te, {
267
287
  index: t,
268
- ownerState: z,
269
- geometry: _(t, z),
270
- className: B.item,
271
- component: ae,
272
- inert: !F && g !== "manual",
273
- itemRefs: H,
274
- slotProps: M?.item,
288
+ ownerState: B,
289
+ geometry: v(t, B),
290
+ className: V.item,
291
+ component: oe,
292
+ inert: !I && _ !== "manual",
293
+ itemRefs: U,
294
+ slotProps: N?.item,
275
295
  children: e
276
296
  }, t))
277
297
  });
278
- return k || g === "manual" ? $ : /* @__PURE__ */ l(t, {
279
- onClickAway: ie,
298
+ return O || _ === "manual" ? $ : /* @__PURE__ */ l(t, {
299
+ onClickAway: ae,
280
300
  children: $
281
301
  });
282
302
  });
283
- export { D as CollageFab };
303
+ export { E as CollageFab };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mui-collage-fab",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Material UI floating action button that unfolds a stack of overlapping Fab circles into a row.",
5
5
  "license": "MIT",
6
6
  "author": "Radomir Wojtera",