mui-collage-fab 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Radomir Wojtera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,162 @@
1
- # Temporary Holding Version
1
+ # MUI CollageFab
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **[Live demo →](https://www.radomir.dev/mui-collage-fab/)**
4
+
5
+ | Collapsed | Expanded |
6
+ | --- | --- |
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" width="400" /> | <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" width="560" /> |
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.
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.
12
+
13
+ Not affiliated with or endorsed by MUI.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install mui-collage-fab @mui/material @emotion/react @emotion/styled
19
+ ```
20
+
21
+ `react`, `react-dom`, `@mui/material` and the two emotion packages are peer
22
+ dependencies, so the package never ships its own copy of React or MUI.
23
+
24
+ ## Usage
25
+
26
+ ```tsx
27
+ import { Fab } from '@mui/material';
28
+ import { Settings, BugReport, Speed } from '@mui/icons-material';
29
+ import { CollageFab } from 'mui-collage-fab';
30
+
31
+ <CollageFab
32
+ direction="left"
33
+ trigger="hover"
34
+ gap={14}
35
+ fadeWidth={12}
36
+ aria-label="Tools"
37
+ slotProps={{
38
+ item: (ownerState) =>
39
+ ownerState.isAnchor ? { sx: { outline: '2px solid white' } } : {},
40
+ }}
41
+ >
42
+ {/* Index 0 is the anchor: it never moves and is never clipped. */}
43
+ <Fab color="primary"><Settings /></Fab>
44
+ <Fab color="secondary"><BugReport /></Fab>
45
+ <Fab color="success"><Speed /></Fab>
46
+ </CollageFab>
47
+ ```
48
+
49
+ Controlled usage, when the open state has to live in your own state:
50
+
51
+ ```tsx
52
+ const [open, setOpen] = useState(false);
53
+
54
+ <CollageFab
55
+ trigger="manual"
56
+ open={open}
57
+ onOpen={() => setOpen(true)}
58
+ onClose={() => setOpen(false)}
59
+ >
60
+ {/* children */}
61
+ </CollageFab>
62
+ ```
63
+
64
+ ## Props
65
+
66
+ | Prop | Type | Default | Description |
67
+ | --- | --- | --- | --- |
68
+ | `children` | `React.ReactNode` | — | The buttons to stack. Order matters: index 0 is the anchor. |
69
+ | `direction` | `'left' \| 'right' \| 'up' \| 'down'` | `'left'` | Which way the row fans out from the anchor. `'left'` pins the stack to the right edge and expands leftward. |
70
+ | `size` | `'small' \| 'medium' \| 'large' \| number` | `'large'` | Diameter of each button. `small` 40, `medium` 48, `large` 56; numbers are used verbatim. |
71
+ | `variant` | `'circular' \| 'rounded' \| 'square'` | `'circular'` | Shape of each button. `rounded` uses a 25% corner radius, which scales with `size`. For an arbitrary radius, use `slotProps.item.sx`. |
72
+ | `gap` | `number` | `16` | Main-axis gap in pixels between buttons when expanded. |
73
+ | `fadeWidth` | `number` | `12` | Width in pixels of the soft gradient ramp at each slice edge. `0` gives a hard cut. |
74
+ | `trigger` | `'hover' \| 'click' \| 'manual'` | `'hover'` | `'hover'` opens on mouse enter, closes on leave, toggles on touch/pen tap. `'click'` toggles on any click. `'manual'` disables built-in pointer interaction. |
75
+ | `open` | `boolean` | — | Controlled open state. Passing it makes the component controlled. |
76
+ | `defaultOpen` | `boolean` | `false` | Initial state when uncontrolled. |
77
+ | `onOpen` | `(event) => void` | — | Fired on the closed → open transition. |
78
+ | `onClose` | `(event) => void` | — | Fired on the open → closed transition. |
79
+ | `disableClickAway` | `boolean` | `false` | If `true`, an outside press does not close the group. |
80
+ | `transitionDuration` | `number` | `400` | Duration of the morph in milliseconds. |
81
+ | `transitionEasing` | `string` | `'cubic-bezier(0.4, 0, 0.2, 1)'` | Easing of the morph. |
82
+ | `sx` | `SxProps<Theme>` | — | System overrides for the root. |
83
+ | `classes` | `Partial<CollageFabClasses>` | — | Override the `root` / `item` / `expanded` / `collapsed` classes. |
84
+ | `slots` | `Partial<CollageFabSlots>` | — | Replace the `root` or `item` slot component. |
85
+ | `slotProps` | `CollageFabSlotProps` | — | Props for each slot, or a callback `(ownerState) => props`. |
86
+
87
+ Remaining `div` attributes, including `aria-label` and `aria-labelledby`, are spread onto the root.
88
+
89
+ ## Slots
90
+
91
+ 1. `root` — the animated container. Owns the anchor-edge alignment, the animated main-axis extent, and the single `drop-shadow` filter. A replacement must forward `ref`, because the `ClickAwayListener` needs it.
92
+ 2. `item` — one masked circular wrapper per child. `slotProps.item` accepts a props object or a callback `(ownerState) => props`, which is the per-child escape hatch: switch on `ownerState.index` or `ownerState.isAnchor` to style an individual button.
93
+
94
+ ## ownerState
95
+
96
+ `CollageFabOwnerState` carries `open`, `direction`, `trigger`, `size` (resolved pixels), `gap`, `fadeWidth`, `count`, `transitionDuration` and `transitionEasing`. `CollageFabItemOwnerState` adds `index` and `isAnchor`.
97
+
98
+ Theme-level defaults and overrides work through the `MuiCollageFab` component key:
99
+
100
+ ```tsx
101
+ const theme = createTheme({
102
+ components: {
103
+ MuiCollageFab: {
104
+ defaultProps: { gap: 10 },
105
+ styleOverrides: { item: { borderRadius: '8px' } },
106
+ },
107
+ },
108
+ });
109
+ ```
110
+
111
+ ## Notes
112
+
113
+ 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.
114
+ 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`.
115
+ 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.
116
+ 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`.
117
+ 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.
118
+ 6. **With a single child no mask is applied** — it behaves like a plain `Fab`.
119
+ 7. **`direction` is physical, not logical.** It is not mirrored under RTL; right-to-left layouts should set `direction="left"` explicitly.
120
+
121
+ ## Demo site
122
+
123
+ 1. Demo — <https://www.radomir.dev/mui-collage-fab/>
124
+ 2. Components API — <https://www.radomir.dev/mui-collage-fab/#/docs>
125
+ 3. Playground — <https://www.radomir.dev/mui-collage-fab/#/playground>
126
+
127
+ Routing is hash-based, so the built site works on any static host without a
128
+ server-side fallback.
129
+
130
+ | URL | Page |
131
+ | --- | --- |
132
+ | `/` | Demo — the component across button counts and directions. |
133
+ | `#/docs` | Components API reference for `CollageFab`. |
134
+ | anything else | Redirects to `#/`. |
135
+
136
+ ## Development
137
+
138
+ Requires Node.js 18 or newer.
139
+
140
+ ```bash
141
+ npm install
142
+ npm run dev
143
+ ```
144
+
145
+ | Command | Description |
146
+ | --- | --- |
147
+ | `npm run dev` | Start the Vite dev server with HMR. |
148
+ | `npm run build` | Type-check with `tsc --noEmit`, then build the demo to `dist/`. |
149
+ | `npm run build:lib` | Build the publishable package to `dist-lib/` (ESM + CJS + types). |
150
+ | `npm run preview` | Serve the production build locally. |
151
+
152
+ Deployment: `.github/workflows/deploy.yml` builds the demo on every push to
153
+ `main` and force-pushes `dist/` to the orphan `gh-pages` branch, which GitHub
154
+ Pages serves. The branch has no shared history with `main`, so it only ever
155
+ holds built files. `.github/workflows/publish.yml` runs `semantic-release` on
156
+ every push to `main`: conventional commit subjects decide the version (`fix:`
157
+ patch, `feat:` minor, `BREAKING CHANGE:` major), and a release publishes the
158
+ package, writes `CHANGELOG.md`, and commits the bump back with `[skip ci]`.
159
+ Pull request titles are linted to the same convention, which matters because
160
+ squash merges put the PR title in the commit subject. The production build uses a `/mui-collage-fab/` asset
161
+ base while the dev server stays at the root, so the local URL is unchanged —
162
+ see `vite.config.ts`.
File without changes
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("react/jsx-runtime"),te=require("react"),oe=require("@mui/material"),z=require("@mui/material/styles"),T=require("@mui/material/utils"),W=require("@mui/utils/useSlotProps"),ne=require("@mui/utils/composeClasses"),re=require("@mui/utils/generateUtilityClass");function se(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const c=se(te),ae={small:40,medium:48,large:56},ie={circular:"50%",rounded:"25%",square:0},le=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");function ce(t){return typeof t=="number"?t:ae[t]}function L(t,o){return`${t}ms ${o}`}function ue(t,o){const{count:n,size:s,gap:i,fadeWidth:l,open:m,direction:u}=o,p=s+i,a=(n-1)*p+s+l,r=t*p,h=u==="left"||u==="up",b=u==="left"||u==="right",k=t===0?a:(n-t)*(s/n),y=t===0?-l/2:t*(s/n),R=m?r:0,g=h?k-a-l/2+R:y-a-l/2-R,E=h?`#000 0px, #000 ${a}px, transparent ${a+l}px, transparent ${2*a}px`:`transparent 0px, transparent ${a}px, #000 ${a+l}px, #000 ${2*a}px`,S=`${h?"-":""}${R}`;return{translate:b?`translateX(${S}px)`:`translateY(${S}px)`,maskImage:n>1?`linear-gradient(${b?"to right":"to bottom"}, ${E})`:"none",maskSize:b?`${2*a}px 100%`:`100% ${2*a}px`,maskPosition:b?`${g}px 0px`:`0px ${g}px`}}function pe(t){return re("MuiCollageFab",t)}const fe=(t,o)=>ne({root:["root",t?"expanded":"collapsed"],item:["item"]},pe,o),me=z.styled("div",{name:"MuiCollageFab",slot:"root",overridesResolver:(t,o)=>o.root})(({ownerState:t})=>{const{open:o,direction:n,size:s,gap:i,count:l,transitionDuration:m,transitionEasing:u}=t,p=n==="left"||n==="right",a=n==="left"||n==="up",r=o?l*s+Math.max(l-1,0)*i:s;return{position:"relative",width:p?r:s,height:p?s:r,display:"flex",flexDirection:p?"row":"column",justifyContent:a?"flex-end":"flex-start",transition:`${p?"width":"height"} ${L(m,u)}`,filter:"drop-shadow(0px 6px 12px rgba(0,0,0,0.25))",cursor:o?"default":"pointer",WebkitTapHighlightColor:"transparent"}}),de=z.styled("div",{name:"MuiCollageFab",slot:"item",overridesResolver:(t,o)=>o.item})(({ownerState:t})=>{const{direction:o,size:n,index:s,geometry:i,cornerRadius:l,transitionDuration:m,transitionEasing:u}=t,p=o==="left"||o==="right",a=o==="left"?{right:0}:o==="right"?{left:0}:o==="up"?{bottom:0}:{top:0},r=L(m,u);return{position:"absolute",...a,...p?{top:0}:{left:0},width:n,height:n,borderRadius:l,overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center",zIndex:s,transform:i.translate,WebkitMaskImage:i.maskImage,maskImage:i.maskImage,WebkitMaskSize:i.maskSize,maskSize:i.maskSize,WebkitMaskPosition:i.maskPosition,maskPosition:i.maskPosition,WebkitMaskRepeat:"no-repeat",maskRepeat:"no-repeat",transition:`transform ${r}, -webkit-mask-position ${r}, mask-position ${r}`,"& > *":{boxShadow:"none !important",borderRadius:"inherit !important",width:"100%",height:"100%",margin:0}}});function ge(t){const{index:o,ownerState:n,geometry:s,className:i,component:l,inert:m,itemRefs:u,slotProps:p,children:a}=t,r=c.useMemo(()=>({...n,index:o,isAnchor:o===0,geometry:s}),[n,o,s]),h=c.useRef(null),b=c.useCallback(g=>{u.current[o]=g},[u,o]),k=T.useForkRef(b,h);c.useEffect(()=>{const g=h.current;!g||!("inert"in HTMLElement.prototype)||(g.inert=m)},[m]);const y=W({elementType:l,externalSlotProps:p,ownerState:r,additionalProps:{ref:k,className:i,"aria-hidden":m||void 0,children:a}}),R=l;return $.jsx(R,{...y})}const he=c.forwardRef(function(o,n){const s=z.useThemeProps({props:o,name:"MuiCollageFab"}),{children:i,direction:l="left",size:m="large",variant:u="circular",gap:p=16,fadeWidth:a=12,trigger:r="hover",open:h,defaultOpen:b=!1,onOpen:k,onClose:y,disableClickAway:R=!1,transitionDuration:g=400,transitionEasing:E="cubic-bezier(0.4, 0, 0.2, 1)",classes:S,slots:x,slotProps:P,className:U,...B}=s,[f,D]=T.useControlled({controlled:h,default:b,name:"CollageFab",state:"open"}),M=c.useMemo(()=>c.Children.toArray(i).filter(e=>c.isValidElement(e)),[i]),j=M.length,I={open:f,direction:l,trigger:r,size:ce(m),variant:u,cornerRadius:ie[u],gap:p,fadeWidth:a,count:j,transitionDuration:g,transitionEasing:E},O=fe(f,S),A=c.useRef(null),q=c.useRef([]),w=c.useRef(!1),_=c.useRef("mouse"),F=c.useRef(!1),H=T.useForkRef(A,n),C=c.useCallback((e,d)=>{e!==f&&(D(e),e?k==null||k(d):y==null||y(d))},[f,D,k,y]),K=e=>{r!=="hover"||e.pointerType!=="mouse"||C(!0,e)},G=e=>{r!=="hover"||e.pointerType!=="mouse"||C(!1,e)},V=e=>{r!=="manual"&&(_.current=e.pointerType,w.current=!1,!(e.pointerType==="mouse"||f)&&(w.current=!0,C(!0,e)))},X=e=>{w.current&&(w.current=!1,e.stopPropagation(),e.preventDefault())},Y=e=>{if(r!=="manual"){if(r==="click"){C(!f,e);return}f&&_.current!=="mouse"&&C(!1,e)}},Z=e=>{var d;if(r!=="manual"){if(f){if(e.key!=="Escape")return;e.stopPropagation(),C(!1,e),(d=A.current)==null||d.focus();return}e.key!=="Enter"&&e.key!==" "||(e.preventDefault(),F.current=!0,C(!0,e))}},J=e=>{C(!1,e)},N=(x==null?void 0:x.root)??me,Q=(x==null?void 0:x.item)??de,ee=W({elementType:N,externalForwardedProps:B,externalSlotProps:P==null?void 0:P.root,ownerState:I,additionalProps:{ref:H,role:"group",tabIndex:!f&&r!=="manual"?0:-1,onPointerEnter:K,onPointerLeave:G,onPointerDown:V,onClick:Y,onClickCapture:X,onKeyDown:Z},className:[O.root,U]});if(c.useEffect(()=>{if(!f||!F.current)return;F.current=!1;const e=q.current[0];if(!e)return;(e.querySelector(le)??e).focus()},[f]),j===0)return null;const v=$.jsx(N,{...ee,children:M.map((e,d)=>$.jsx(ge,{index:d,ownerState:I,geometry:ue(d,I),className:O.item,component:Q,inert:!f&&r!=="manual",itemRefs:q,slotProps:P==null?void 0:P.item,children:e},d))});return R||r==="manual"?v:$.jsx(oe.ClickAwayListener,{onClickAway:J,children:v})});exports.CollageFab=he;
@@ -0,0 +1,271 @@
1
+ import { jsx as $ } from "react/jsx-runtime";
2
+ import * as c from "react";
3
+ import { ClickAwayListener as et } from "@mui/material";
4
+ import { styled as _, useThemeProps as ot } from "@mui/material/styles";
5
+ import { useControlled as nt, useForkRef as v } from "@mui/material/utils";
6
+ import U from "@mui/utils/useSlotProps";
7
+ import rt from "@mui/utils/composeClasses";
8
+ import at from "@mui/utils/generateUtilityClass";
9
+ const st = {
10
+ small: 40,
11
+ medium: 48,
12
+ large: 56
13
+ }, it = {
14
+ circular: "50%",
15
+ rounded: "25%",
16
+ square: 0
17
+ }, lt = [
18
+ "a[href]",
19
+ "button:not([disabled])",
20
+ "input:not([disabled])",
21
+ "select:not([disabled])",
22
+ "textarea:not([disabled])",
23
+ '[tabindex]:not([tabindex="-1"])'
24
+ ].join(",");
25
+ function ct(o) {
26
+ return typeof o == "number" ? o : st[o];
27
+ }
28
+ function j(o, e) {
29
+ return `${o}ms ${e}`;
30
+ }
31
+ function ut(o, e) {
32
+ const { count: r, size: s, gap: i, fadeWidth: l, open: f, direction: u } = e, p = s + i, a = (r - 1) * p + s + l, n = o * p, h = u === "left" || u === "up", k = u === "left" || u === "right", C = o === 0 ? a : (r - o) * (s / r), b = o === 0 ? -l / 2 : o * (s / r), R = f ? n : 0, g = h ? C - a - l / 2 + R : b - a - l / 2 - R, E = h ? `#000 0px, #000 ${a}px, transparent ${a + l}px, transparent ${2 * a}px` : `transparent 0px, transparent ${a}px, #000 ${a + l}px, #000 ${2 * a}px`, w = `${h ? "-" : ""}${R}`;
33
+ return {
34
+ translate: k ? `translateX(${w}px)` : `translateY(${w}px)`,
35
+ maskImage: r > 1 ? `linear-gradient(${k ? "to right" : "to bottom"}, ${E})` : "none",
36
+ maskSize: k ? `${2 * a}px 100%` : `100% ${2 * a}px`,
37
+ maskPosition: k ? `${g}px 0px` : `0px ${g}px`
38
+ };
39
+ }
40
+ function pt(o) {
41
+ return at("MuiCollageFab", o);
42
+ }
43
+ const mt = (o, e) => rt({
44
+ root: ["root", o ? "expanded" : "collapsed"],
45
+ item: ["item"]
46
+ }, pt, e), ft = _("div", {
47
+ name: "MuiCollageFab",
48
+ slot: "root",
49
+ overridesResolver: (o, e) => e.root
50
+ })(({ ownerState: o }) => {
51
+ const { open: e, direction: r, size: s, gap: i, count: l, transitionDuration: f, transitionEasing: u } = o, p = r === "left" || r === "right", a = r === "left" || r === "up", n = e ? l * s + Math.max(l - 1, 0) * i : s;
52
+ return {
53
+ position: "relative",
54
+ width: p ? n : s,
55
+ height: p ? s : n,
56
+ display: "flex",
57
+ flexDirection: p ? "row" : "column",
58
+ justifyContent: a ? "flex-end" : "flex-start",
59
+ transition: `${p ? "width" : "height"} ${j(
60
+ f,
61
+ u
62
+ )}`,
63
+ // A filter traces the soft mask edges; a box-shadow would trace the wrapper rectangles.
64
+ filter: "drop-shadow(0px 6px 12px rgba(0,0,0,0.25))",
65
+ cursor: e ? "default" : "pointer",
66
+ WebkitTapHighlightColor: "transparent"
67
+ };
68
+ }), dt = _("div", {
69
+ name: "MuiCollageFab",
70
+ slot: "item",
71
+ overridesResolver: (o, e) => e.item
72
+ })(({ ownerState: o }) => {
73
+ const { direction: e, size: r, index: s, geometry: i, cornerRadius: l, transitionDuration: f, transitionEasing: u } = o, p = e === "left" || e === "right", a = e === "left" ? { right: 0 } : e === "right" ? { left: 0 } : e === "up" ? { bottom: 0 } : { top: 0 }, n = j(f, u);
74
+ return {
75
+ position: "absolute",
76
+ ...a,
77
+ ...p ? { top: 0 } : { left: 0 },
78
+ width: r,
79
+ height: r,
80
+ borderRadius: l,
81
+ overflow: "hidden",
82
+ display: "flex",
83
+ alignItems: "center",
84
+ justifyContent: "center",
85
+ // The left-most slices have to stack on top of the right-ward ones.
86
+ zIndex: s,
87
+ // Always present, even collapsed: the transform is what makes this wrapper a
88
+ // stacking context, which neutralizes the child's own z-index.
89
+ transform: i.translate,
90
+ WebkitMaskImage: i.maskImage,
91
+ maskImage: i.maskImage,
92
+ WebkitMaskSize: i.maskSize,
93
+ maskSize: i.maskSize,
94
+ WebkitMaskPosition: i.maskPosition,
95
+ maskPosition: i.maskPosition,
96
+ WebkitMaskRepeat: "no-repeat",
97
+ maskRepeat: "no-repeat",
98
+ transition: `transform ${n}, -webkit-mask-position ${n}, mask-position ${n}`,
99
+ // Strip arbitrary shadows from the children and make them inherit the wrapper's
100
+ // silhouette, so the root controls the global 3D shape.
101
+ "& > *": {
102
+ boxShadow: "none !important",
103
+ borderRadius: "inherit !important",
104
+ width: "100%",
105
+ height: "100%",
106
+ margin: 0
107
+ }
108
+ };
109
+ });
110
+ function gt(o) {
111
+ const {
112
+ index: e,
113
+ ownerState: r,
114
+ geometry: s,
115
+ className: i,
116
+ component: l,
117
+ inert: f,
118
+ itemRefs: u,
119
+ slotProps: p,
120
+ children: a
121
+ } = o, n = c.useMemo(
122
+ () => ({ ...r, index: e, isAnchor: e === 0, geometry: s }),
123
+ [r, e, s]
124
+ ), h = c.useRef(null), k = c.useCallback(
125
+ (g) => {
126
+ u.current[e] = g;
127
+ },
128
+ [u, e]
129
+ ), C = v(k, h);
130
+ c.useEffect(() => {
131
+ const g = h.current;
132
+ !g || !("inert" in HTMLElement.prototype) || (g.inert = f);
133
+ }, [f]);
134
+ const b = U({
135
+ elementType: l,
136
+ externalSlotProps: p,
137
+ ownerState: n,
138
+ additionalProps: {
139
+ ref: C,
140
+ className: i,
141
+ "aria-hidden": f || void 0,
142
+ children: a
143
+ }
144
+ });
145
+ return /* @__PURE__ */ $(l, { ...b });
146
+ }
147
+ const Pt = c.forwardRef(
148
+ function(e, r) {
149
+ const s = ot({ props: e, name: "MuiCollageFab" }), {
150
+ children: i,
151
+ direction: l = "left",
152
+ size: f = "large",
153
+ variant: u = "circular",
154
+ gap: p = 16,
155
+ fadeWidth: a = 12,
156
+ trigger: n = "hover",
157
+ open: h,
158
+ defaultOpen: k = !1,
159
+ onOpen: C,
160
+ onClose: b,
161
+ disableClickAway: R = !1,
162
+ transitionDuration: g = 400,
163
+ transitionEasing: E = "cubic-bezier(0.4, 0, 0.2, 1)",
164
+ classes: w,
165
+ slots: x,
166
+ slotProps: P,
167
+ className: q,
168
+ ...B
169
+ } = s, [m, z] = nt({
170
+ controlled: h,
171
+ default: k,
172
+ name: "CollageFab",
173
+ state: "open"
174
+ }), T = c.useMemo(
175
+ () => c.Children.toArray(i).filter((t) => c.isValidElement(t)),
176
+ [i]
177
+ ), D = T.length, I = {
178
+ open: m,
179
+ direction: l,
180
+ trigger: n,
181
+ size: ct(f),
182
+ variant: u,
183
+ cornerRadius: it[u],
184
+ gap: p,
185
+ fadeWidth: a,
186
+ count: D,
187
+ transitionDuration: g,
188
+ transitionEasing: E
189
+ }, M = mt(m, w), A = c.useRef(null), N = c.useRef([]), S = c.useRef(!1), W = c.useRef("mouse"), F = c.useRef(!1), H = v(A, r), y = c.useCallback(
190
+ (t, d) => {
191
+ t !== m && (z(t), t ? C == null || C(d) : b == null || b(d));
192
+ },
193
+ [m, z, C, b]
194
+ ), K = (t) => {
195
+ n !== "hover" || t.pointerType !== "mouse" || y(!0, t);
196
+ }, G = (t) => {
197
+ n !== "hover" || t.pointerType !== "mouse" || y(!1, t);
198
+ }, V = (t) => {
199
+ n !== "manual" && (W.current = t.pointerType, S.current = !1, !(t.pointerType === "mouse" || m) && (S.current = !0, y(!0, t)));
200
+ }, X = (t) => {
201
+ S.current && (S.current = !1, t.stopPropagation(), t.preventDefault());
202
+ }, Y = (t) => {
203
+ if (n !== "manual") {
204
+ if (n === "click") {
205
+ y(!m, t);
206
+ return;
207
+ }
208
+ m && W.current !== "mouse" && y(!1, t);
209
+ }
210
+ }, Z = (t) => {
211
+ var d;
212
+ if (n !== "manual") {
213
+ if (m) {
214
+ if (t.key !== "Escape")
215
+ return;
216
+ t.stopPropagation(), y(!1, t), (d = A.current) == null || d.focus();
217
+ return;
218
+ }
219
+ t.key !== "Enter" && t.key !== " " || (t.preventDefault(), F.current = !0, y(!0, t));
220
+ }
221
+ }, J = (t) => {
222
+ y(!1, t);
223
+ }, L = (x == null ? void 0 : x.root) ?? ft, Q = (x == null ? void 0 : x.item) ?? dt, tt = U({
224
+ elementType: L,
225
+ externalForwardedProps: B,
226
+ externalSlotProps: P == null ? void 0 : P.root,
227
+ ownerState: I,
228
+ additionalProps: {
229
+ ref: H,
230
+ role: "group",
231
+ tabIndex: !m && n !== "manual" ? 0 : -1,
232
+ onPointerEnter: K,
233
+ onPointerLeave: G,
234
+ onPointerDown: V,
235
+ onClick: Y,
236
+ onClickCapture: X,
237
+ onKeyDown: Z
238
+ },
239
+ className: [M.root, q]
240
+ });
241
+ if (c.useEffect(() => {
242
+ if (!m || !F.current)
243
+ return;
244
+ F.current = !1;
245
+ const t = N.current[0];
246
+ if (!t)
247
+ return;
248
+ (t.querySelector(lt) ?? t).focus();
249
+ }, [m]), D === 0)
250
+ return null;
251
+ const O = /* @__PURE__ */ $(L, { ...tt, children: T.map((t, d) => /* @__PURE__ */ $(
252
+ gt,
253
+ {
254
+ index: d,
255
+ ownerState: I,
256
+ geometry: ut(d, I),
257
+ className: M.item,
258
+ component: Q,
259
+ inert: !m && n !== "manual",
260
+ itemRefs: N,
261
+ slotProps: P == null ? void 0 : P.item,
262
+ children: t
263
+ },
264
+ d
265
+ )) });
266
+ return R || n === "manual" ? O : /* @__PURE__ */ $(et, { onClickAway: J, children: O });
267
+ }
268
+ );
269
+ export {
270
+ Pt as CollageFab
271
+ };
@@ -0,0 +1,134 @@
1
+ import * as React from 'react';
2
+ import type { SxProps, Theme } from '@mui/material/styles';
3
+ import type { CreateSlotsAndSlotProps, SlotProps } from '@mui/material/utils';
4
+ export type CollageFabDirection = 'left' | 'right' | 'up' | 'down';
5
+ export type CollageFabTrigger = 'hover' | 'click' | 'manual';
6
+ export type CollageFabSize = 'small' | 'medium' | 'large' | number;
7
+ export type CollageFabVariant = 'circular' | 'rounded' | 'square';
8
+ export interface CollageFabClasses {
9
+ root: string;
10
+ item: string;
11
+ expanded: string;
12
+ collapsed: string;
13
+ }
14
+ export type CollageFabClassKey = keyof CollageFabClasses;
15
+ export interface CollageFabRootSlotPropsOverrides {
16
+ }
17
+ export interface CollageFabItemSlotPropsOverrides {
18
+ }
19
+ export interface CollageFabOwnerState {
20
+ open: boolean;
21
+ direction: CollageFabDirection;
22
+ trigger: CollageFabTrigger;
23
+ size: number;
24
+ variant: CollageFabVariant;
25
+ cornerRadius: number | string;
26
+ gap: number;
27
+ fadeWidth: number;
28
+ count: number;
29
+ transitionDuration: number;
30
+ transitionEasing: string;
31
+ }
32
+ export interface CollageFabItemGeometry {
33
+ translate: string;
34
+ maskImage: string;
35
+ maskSize: string;
36
+ maskPosition: string;
37
+ }
38
+ export interface CollageFabItemOwnerState extends CollageFabOwnerState {
39
+ index: number;
40
+ isAnchor: boolean;
41
+ geometry: CollageFabItemGeometry;
42
+ }
43
+ export interface CollageFabSlots {
44
+ root?: React.ElementType;
45
+ item?: React.ElementType;
46
+ }
47
+ export type CollageFabSlotsAndSlotProps = CreateSlotsAndSlotProps<CollageFabSlots, {
48
+ root: SlotProps<'div', CollageFabRootSlotPropsOverrides, CollageFabOwnerState>;
49
+ item: SlotProps<'div', CollageFabItemSlotPropsOverrides, CollageFabItemOwnerState>;
50
+ }>;
51
+ export interface CollageFabProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'>, CollageFabSlotsAndSlotProps {
52
+ /**
53
+ * The buttons to stack. Order matters: index 0 is the anchor, the remaining
54
+ * children fan out along `direction`.
55
+ */
56
+ children?: React.ReactNode;
57
+ /**
58
+ * The axis the buttons fan out on, starting from the anchor child.
59
+ * @default 'left'
60
+ */
61
+ direction?: CollageFabDirection;
62
+ /**
63
+ * Diameter of every button, in pixels. Numeric values are used verbatim.
64
+ * @default 'large'
65
+ */
66
+ size?: CollageFabSize;
67
+ /**
68
+ * The shape of every button. `'circular'` clips each slice to a circle,
69
+ * `'rounded'` to a rounded square and `'square'` to a sharp-cornered square.
70
+ * The mask still slices the silhouette along the main axis, so the stack reads
71
+ * as one shape when collapsed and as separate shapes when expanded.
72
+ * @default 'circular'
73
+ */
74
+ variant?: CollageFabVariant;
75
+ /**
76
+ * Main axis gap between two buttons when expanded, in pixels.
77
+ * @default 16
78
+ */
79
+ gap?: number;
80
+ /**
81
+ * Width of the soft cut line between two slices, in pixels.
82
+ * @default 12
83
+ */
84
+ fadeWidth?: number;
85
+ /**
86
+ * How the group reacts to pointers. `'hover'` opens on mouse enter, closes on
87
+ * mouse leave and toggles on touch/pen tap. `'click'` toggles on any click.
88
+ * `'manual'` disables all built-in pointer interaction.
89
+ * @default 'hover'
90
+ */
91
+ trigger?: CollageFabTrigger;
92
+ /**
93
+ * If `true`, the group is expanded. Use it to control the component.
94
+ */
95
+ open?: boolean;
96
+ /**
97
+ * If `true`, the group is expanded by default.
98
+ * @default false
99
+ */
100
+ defaultOpen?: boolean;
101
+ /**
102
+ * Callback fired when the group is expanded.
103
+ */
104
+ onOpen?: (event: React.SyntheticEvent) => void;
105
+ /**
106
+ * Callback fired when the group is collapsed.
107
+ */
108
+ onClose?: (event: React.SyntheticEvent) => void;
109
+ /**
110
+ * If `true`, the group does not collapse when the user clicks away from it.
111
+ * @default false
112
+ */
113
+ disableClickAway?: boolean;
114
+ /**
115
+ * Duration of the morph, in milliseconds.
116
+ * @default 400
117
+ */
118
+ transitionDuration?: number;
119
+ /**
120
+ * Easing of the morph.
121
+ * @default 'cubic-bezier(0.4, 0, 0.2, 1)'
122
+ */
123
+ transitionEasing?: string;
124
+ /**
125
+ * The system prop that allows defining system overrides as well as additional CSS styles.
126
+ */
127
+ sx?: SxProps<Theme>;
128
+ /**
129
+ * Override or extend the styles applied to the component.
130
+ */
131
+ classes?: Partial<CollageFabClasses>;
132
+ }
133
+ export declare const CollageFab: React.ForwardRefExoticComponent<CollageFabProps & React.RefAttributes<HTMLDivElement>>;
134
+ //# sourceMappingURL=CollageFab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CollageFab.d.ts","sourceRoot":"","sources":["../../../src/components/CollageFab.tsx"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export * from './components/CollageFab';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,85 @@
1
1
  {
2
2
  "name": "mui-collage-fab",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Material UI floating action button that unfolds a stack of overlapping Fab circles into a row.",
5
+ "license": "MIT",
6
+ "author": "Radomir Wojtera",
7
+ "homepage": "https://www.radomir.dev/mui-collage-fab/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/radomir-dev/mui-collage-fab.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/radomir-dev/mui-collage-fab/issues"
14
+ },
15
+ "keywords": [
16
+ "mui",
17
+ "material-ui",
18
+ "react",
19
+ "component",
20
+ "floating-action-button",
21
+ "fab",
22
+ "animation",
23
+ "collage"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "files": [
28
+ "dist-lib"
29
+ ],
30
+ "main": "./dist-lib/index.cjs",
31
+ "module": "./dist-lib/index.js",
32
+ "types": "./dist-lib/types/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist-lib/types/index.d.ts",
36
+ "import": "./dist-lib/index.js",
37
+ "require": "./dist-lib/index.cjs"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "provenance": true
44
+ },
45
+ "engines": {
46
+ "node": ">=18"
47
+ },
48
+ "scripts": {
49
+ "dev": "vite",
50
+ "build": "tsc --noEmit && vite build",
51
+ "build:lib": "vite build --config vite.lib.config.ts && tsc -p tsconfig.build.json",
52
+ "prepublishOnly": "npm run build:lib",
53
+ "preview": "vite preview",
54
+ "release": "semantic-release"
55
+ },
56
+ "dependencies": {
57
+ "@mui/utils": "^5.15.0"
58
+ },
59
+ "peerDependencies": {
60
+ "@emotion/react": "^11.0.0",
61
+ "@emotion/styled": "^11.0.0",
62
+ "@mui/material": "^5.0.0",
63
+ "react": "^18.0.0",
64
+ "react-dom": "^18.0.0"
65
+ },
66
+ "devDependencies": {
67
+ "@emotion/react": "^11.13.3",
68
+ "@emotion/styled": "^11.13.0",
69
+ "@mui/icons-material": "^5.16.7",
70
+ "@mui/material": "^5.16.7",
71
+ "@semantic-release/changelog": "^7.0.0",
72
+ "@semantic-release/git": "^11.0.1",
73
+ "@semantic-release/github": "^12.0.11",
74
+ "@semantic-release/npm": "^13.2.0",
75
+ "@types/react": "^18.3.12",
76
+ "@types/react-dom": "^18.3.1",
77
+ "@vitejs/plugin-react": "^4.3.3",
78
+ "react": "^18.3.1",
79
+ "react-dom": "^18.3.1",
80
+ "react-router-dom": "^7.18.4",
81
+ "semantic-release": "^25.0.9",
82
+ "typescript": "~5.6.3",
83
+ "vite": "^5.4.10"
84
+ }
85
+ }