mui-collage-fab 0.1.1 → 0.1.3
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 +131 -54
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/index.d.cts +216 -0
- package/dist-lib/index.d.ts +216 -0
- package/dist-lib/index.js +222 -265
- package/package.json +81 -14
- package/dist-lib/.nojekyll +0 -0
- package/dist-lib/types/components/CollageFab.d.ts +0 -134
- package/dist-lib/types/components/CollageFab.d.ts.map +0 -1
- package/dist-lib/types/index.d.ts +0 -2
- package/dist-lib/types/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# MUI CollageFab
|
|
2
2
|
|
|
3
|
-
**[Live demo →](https://
|
|
3
|
+
**[Live demo →](https://radomir.dev/mui-collage-fab/)**
|
|
4
4
|
|
|
5
|
-
| Collapsed
|
|
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"
|
|
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" 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
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
10
|
|
|
@@ -35,15 +35,20 @@ import { CollageFab } from 'mui-collage-fab';
|
|
|
35
35
|
fadeWidth={12}
|
|
36
36
|
aria-label="Tools"
|
|
37
37
|
slotProps={{
|
|
38
|
-
item: (ownerState) =>
|
|
39
|
-
ownerState.isAnchor ? { sx: { outline: '2px solid white' } } : {},
|
|
38
|
+
item: (ownerState) => (ownerState.isAnchor ? { sx: { outline: '2px solid white' } } : {}),
|
|
40
39
|
}}
|
|
41
40
|
>
|
|
42
41
|
{/* Index 0 is the anchor: it never moves and is never clipped. */}
|
|
43
|
-
<Fab color="primary"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
<Fab color="primary">
|
|
43
|
+
<Settings />
|
|
44
|
+
</Fab>
|
|
45
|
+
<Fab color="secondary">
|
|
46
|
+
<BugReport />
|
|
47
|
+
</Fab>
|
|
48
|
+
<Fab color="success">
|
|
49
|
+
<Speed />
|
|
50
|
+
</Fab>
|
|
51
|
+
</CollageFab>;
|
|
47
52
|
```
|
|
48
53
|
|
|
49
54
|
Controlled usage, when the open state has to live in your own state:
|
|
@@ -58,42 +63,52 @@ const [open, setOpen] = useState(false);
|
|
|
58
63
|
onClose={() => setOpen(false)}
|
|
59
64
|
>
|
|
60
65
|
{/* children */}
|
|
61
|
-
</CollageFab
|
|
66
|
+
</CollageFab>;
|
|
62
67
|
```
|
|
63
68
|
|
|
64
69
|
## Props
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
<!-- api:props:start -->
|
|
72
|
+
|
|
73
|
+
| Prop | Type | Default | Description |
|
|
74
|
+
| -------------------- | ------------------------------------------ | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
75
|
+
| `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
|
+
| `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. |
|
|
77
|
+
| `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. |
|
|
78
|
+
| `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. |
|
|
79
|
+
| `gap` | `number` | `16` | Main-axis gap in pixels between two buttons when expanded. |
|
|
80
|
+
| `fadeWidth` | `number` | `12` | Width in pixels of the soft cut line between two slices. |
|
|
81
|
+
| `trigger` | `'hover' \| 'click' \| 'manual'` | `'hover'` | How the group reacts to pointers. `'hover'` opens on mouse enter, closes on mouse leave and toggles on touch or pen tap; `'click'` toggles on any click; `'manual'` disables all built-in pointer interaction. |
|
|
82
|
+
| `open` | `boolean` | — | If `true`, the group is expanded. Use it to control the component. |
|
|
83
|
+
| `defaultOpen` | `boolean` | `false` | If `true`, the group is expanded by default (uncontrolled). |
|
|
84
|
+
| `onOpen` | `(event: React.SyntheticEvent) => void` | — | Callback fired when the group is expanded. |
|
|
85
|
+
| `onClose` | `(event: React.SyntheticEvent) => void` | — | Callback fired when the group is collapsed. |
|
|
86
|
+
| `disableClickAway` | `boolean` | `false` | If `true`, the group does not collapse when the user clicks away from it. |
|
|
87
|
+
| `transitionDuration` | `number` | `400` | Duration of the morph, in milliseconds. |
|
|
88
|
+
| `transitionEasing` | `string` | `'cubic-bezier(0.4, 0, 0.2, 1)'` | Easing of the morph. |
|
|
89
|
+
| `sx` | `SxProps<Theme>` | — | System prop that defines system overrides as well as additional CSS styles. |
|
|
90
|
+
| `classes` | `Partial<CollageFabClasses>` | — | Override or extend the styles applied to the component. |
|
|
91
|
+
| `slots` | `CollageFabSlots` | — | Custom components for the `root` and `item` slots. |
|
|
92
|
+
| `slotProps` | `{ root?, item? }` | — | Props for each slot. `slotProps.item` accepts either a props object or an `(ownerState) => props` callback, which is the per-child escape hatch. |
|
|
93
|
+
| `...divProps` | `React.HTMLAttributes<HTMLDivElement>` | — | The remaining div attributes are spread onto the root. |
|
|
94
|
+
|
|
95
|
+
<!-- api:props:end -->
|
|
88
96
|
|
|
89
97
|
## Slots
|
|
90
98
|
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
<!-- api:slots:start -->
|
|
100
|
+
|
|
101
|
+
1. `root` — The animated container. A replacement must forward `ref`, which `ClickAwayListener` needs.
|
|
102
|
+
2. `item` — One masked wrapper per child, shaped by `variant`.
|
|
103
|
+
|
|
104
|
+
<!-- api:slots:end -->
|
|
93
105
|
|
|
94
106
|
## ownerState
|
|
95
107
|
|
|
96
|
-
|
|
108
|
+
<!-- api:owner-state:start -->
|
|
109
|
+
|
|
110
|
+
`CollageFabOwnerState` carries `open`, `direction`, `trigger`, `size`, `variant`, `cornerRadius`, `gap`, `fadeWidth`, `count`, `transitionDuration` and `transitionEasing`. `CollageFabItemOwnerState` adds `index`, `isAnchor` and `geometry`.
|
|
111
|
+
<!-- api:owner-state:end -->
|
|
97
112
|
|
|
98
113
|
Theme-level defaults and overrides work through the `MuiCollageFab` component key:
|
|
99
114
|
|
|
@@ -120,39 +135,101 @@ const theme = createTheme({
|
|
|
120
135
|
|
|
121
136
|
## Demo site
|
|
122
137
|
|
|
123
|
-
1. Demo — <https://
|
|
124
|
-
2. Components API — <https://
|
|
125
|
-
3. Playground — <https://
|
|
138
|
+
1. Demo — <https://radomir.dev/mui-collage-fab/>
|
|
139
|
+
2. Components API — <https://radomir.dev/mui-collage-fab/#/docs>
|
|
140
|
+
3. Playground — <https://radomir.dev/mui-collage-fab/#/playground>
|
|
126
141
|
|
|
127
142
|
Routing is hash-based, so the built site works on any static host without a
|
|
128
143
|
server-side fallback.
|
|
129
144
|
|
|
130
|
-
| URL
|
|
131
|
-
|
|
|
132
|
-
| `/`
|
|
133
|
-
| `#/docs`
|
|
134
|
-
| anything else | Redirects to `#/`.
|
|
145
|
+
| URL | Page |
|
|
146
|
+
| ------------- | --------------------------------------------------------- |
|
|
147
|
+
| `/` | Demo — the component across button counts and directions. |
|
|
148
|
+
| `#/docs` | Components API reference for `CollageFab`. |
|
|
149
|
+
| anything else | Redirects to `#/`. |
|
|
150
|
+
|
|
151
|
+
## Testing
|
|
152
|
+
|
|
153
|
+
`src/components/collageFabGeometry.ts` holds the mask and translation maths, so it can be
|
|
154
|
+
tested without a DOM: `tests/geometry.test.ts` asserts the translate offsets, the mask axis
|
|
155
|
+
and stop order, and the invariant that a slice's mask position and translation cancel out —
|
|
156
|
+
the cut line stays pinned while the button travels. `tests/behaviour.test.tsx` runs the
|
|
157
|
+
component in jsdom for triggers, keyboard flow, controlled state and click-away.
|
|
158
|
+
`e2e/collagefab.spec.ts` is the browser-level check, because jsdom cannot compute masks:
|
|
159
|
+
it reads the real `transform` and `mask-position` after hovering and verifies they move by
|
|
160
|
+
the same pitch in opposite directions.
|
|
135
161
|
|
|
136
162
|
## Development
|
|
137
163
|
|
|
138
|
-
Requires Node.js
|
|
164
|
+
Requires Node.js 22.13 or newer.
|
|
139
165
|
|
|
140
166
|
```bash
|
|
141
167
|
npm install
|
|
142
168
|
npm run dev
|
|
143
169
|
```
|
|
144
170
|
|
|
145
|
-
| Command
|
|
146
|
-
|
|
|
147
|
-
| `npm run dev`
|
|
148
|
-
| `npm run build`
|
|
149
|
-
| `npm run build:
|
|
150
|
-
| `npm run
|
|
171
|
+
| Command | Description |
|
|
172
|
+
| -------------------------------- | ------------------------------------------------------------------------ |
|
|
173
|
+
| `npm run dev` | Start the Vite dev server with HMR. |
|
|
174
|
+
| `npm run build` | Type-check with `tsc --noEmit`, then build the demo to `dist/`. |
|
|
175
|
+
| `npm run build:preview` | Same, with the asset base taken from `SITE_BASE_PATH`. |
|
|
176
|
+
| `npm run build:lib` | Build the publishable package to `dist-lib/` (ESM + CJS + types). |
|
|
177
|
+
| `npm run preview` | Serve the production build locally. |
|
|
178
|
+
| `npm test` | Run the Vitest suite (geometry + behaviour in jsdom). |
|
|
179
|
+
| `npm run test:coverage` | Same suite with a v8 coverage report. |
|
|
180
|
+
| `npm run test:e2e` | Build, then run the Playwright checks against `vite preview`. |
|
|
181
|
+
| `npm run types:test` | Type-check the public API surface (`expectTypeOf` + `@ts-expect-error`). |
|
|
182
|
+
| `npm run check:package` | `publint`, `attw --pack` and a tarball content assertion. |
|
|
183
|
+
| `npm run check:size` | Enforce the size-limit budgets for `dist-lib`. |
|
|
184
|
+
| `npm run lint` | ESLint, type-aware, with hooks and jsx-a11y rules. |
|
|
185
|
+
| `npm run format:check` | Prettier check. `npm run format` rewrites in place. |
|
|
186
|
+
| `npm run check:unused` | Knip: unused files, exports and dependencies. |
|
|
187
|
+
| `npm run check:release` | `semantic-release --dry-run`, validating the release config. |
|
|
188
|
+
| `npm run check:actions-security` | Zizmor audit of the workflows. |
|
|
189
|
+
| `npm run doctor` | Run every check below in one pass. |
|
|
190
|
+
| `npm run doctor:fast` | Same, minus the browser suite and `npm audit`. |
|
|
191
|
+
|
|
192
|
+
### Checks
|
|
193
|
+
|
|
194
|
+
`npm run doctor` (listr2) runs the checks in sequence and keeps going after a
|
|
195
|
+
failure, so one pass reports everything that is broken:
|
|
196
|
+
|
|
197
|
+
1. `format:check`, `lint`, `typecheck` — style and static analysis.
|
|
198
|
+
2. `types:test` — the public prop unions and slot overrides, pinned by type tests.
|
|
199
|
+
3. `test:coverage` — Vitest with coverage thresholds of 85 statements / 75 branches.
|
|
200
|
+
4. `build`, `build:lib` — demo and library bundles.
|
|
201
|
+
5. `check:package` — `publint`, `attw --pack` and a tarball assertion, so the
|
|
202
|
+
published `exports`/types map and file list stay correct.
|
|
203
|
+
6. `check:size` — size-limit budgets for the ESM and CJS bundles.
|
|
204
|
+
7. `docs:check`, `actionlint`, `audit` and `test:e2e` — skipped with a reason when
|
|
205
|
+
the script exists but the tool is missing (for example `actionlint` locally).
|
|
206
|
+
|
|
207
|
+
Property tests (`fast-check`, `tests/geometry.property.test.ts`) generate sizes, gaps,
|
|
208
|
+
fade widths, counts and directions and assert the geometry invariants rather than
|
|
209
|
+
enumerating cases: one pitch of translation per slice, a cut line pinned in container
|
|
210
|
+
space, and a mask window wide enough to cover the fan. `check:unused` (knip) catches dead
|
|
211
|
+
files, exports and dependencies; `check:release` loads every semantic-release plugin
|
|
212
|
+
through `--dry-run`; the e2e suite also runs a Pixel-class mobile project with touch
|
|
213
|
+
gesture specs, and zizmor audits the workflows themselves in CI.
|
|
214
|
+
|
|
215
|
+
`--fast` drops `test:e2e` and `audit`, `--only=lint,unit` runs a subset. Each failed
|
|
216
|
+
step keeps its output in `node_modules/.cache/doctor/<step>.log`. CI runs
|
|
217
|
+
`npm run doctor -- --fast` plus a separate e2e job covering chromium, firefox, webkit and
|
|
218
|
+
a Pixel-class mobile viewport, `zizmor` on the workflows, and `dependency-review` on pull
|
|
219
|
+
requests.
|
|
151
220
|
|
|
152
221
|
Deployment: `.github/workflows/deploy.yml` builds the demo on every push to
|
|
153
|
-
`main` and
|
|
154
|
-
|
|
155
|
-
|
|
222
|
+
`main` and pushes `dist/` to the `gh-pages` branch, which GitHub Pages serves.
|
|
223
|
+
The branch holds nothing but built files. Every pull request gets that same
|
|
224
|
+
build one directory deeper, at
|
|
225
|
+
`https://radomir.dev/mui-collage-fab/pr-preview/pr-<number>/`:
|
|
226
|
+
`.github/workflows/preview.yml` builds it with `SITE_BASE_PATH` set to that
|
|
227
|
+
path, the preview action writes it to `gh-pages`, comments the URL on the pull
|
|
228
|
+
request, and removes the directory again when the pull request closes. The
|
|
229
|
+
deploy workflow keeps `pr-preview/` intact rather than cleaning the branch, so
|
|
230
|
+
a push to `main` does not take the open previews with it.
|
|
231
|
+
|
|
232
|
+
`.github/workflows/publish.yml` runs `semantic-release` on
|
|
156
233
|
every push to `main`: conventional commit subjects decide the version (`fix:`
|
|
157
234
|
patch, `feat:` minor, `BREAKING CHANGE:` major), and a release publishes the
|
|
158
235
|
package, writes `CHANGELOG.md`, and commits the bump back with `[skip ci]`.
|
package/dist-lib/index.cjs
CHANGED
|
@@ -1 +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]}function v(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=e*c,d=s===`left`||s===`up`,f=s===`left`||s===`right`,p=e===0?l:(n-e)*(r/n),m=e===0?-a/2:r/n*e,h=o?u:0,g=d?p-l-a/2+h:m-l-a/2-h,_=d?`#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`,v=`${d?`-`:``}${h}`;return{translate:f?`translateX(${v}px)`:`translateY(${v}px)`,maskImage:n>1?`linear-gradient(${f?`to right`:`to bottom`}, ${_})`:`none`,maskSize:f?`${2*l}px 100%`:`100% ${2*l}px`,maskPosition:f?`${g}px 0px`:`0px ${g}px`}}var y={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)`},b={circular:`50%`,rounded:`25%`,square:0},x=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function S(e,t){return`${e}ms ${t}`}function C(e){return(0,m.default)(`MuiCollageFab`,e)}var w=(e,t)=>(0,p.default)({root:[`root`,e?`expanded`:`collapsed`],item:[`item`]},C,t),T=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`root`,overridesResolver:(e,t)=>t.root})(({ownerState:e})=>{let{open:t,direction:n,size:r,gap:i,count:a,transitionDuration:o,transitionEasing:s}=e,c=n===`left`||n===`right`,l=n===`left`||n===`up`,u=t?a*r+Math.max(a-1,0)*i:r;return{position:`relative`,width:c?u:r,height:c?r:u,display:`flex`,flexDirection:c?`row`:`column`,justifyContent:l?`flex-end`:`flex-start`,transition:`${c?`width`:`height`} ${S(o,s)}`,filter:`drop-shadow(0px 6px 12px rgba(0,0,0,0.25))`,cursor:t?`default`:`pointer`,WebkitTapHighlightColor:`transparent`}}),E=(0,u.styled)(`div`,{name:`MuiCollageFab`,slot:`item`,overridesResolver:(e,t)=>t.item})(({ownerState:e})=>{let{direction:t,size:n,index:r,geometry:i,cornerRadius:a,transitionDuration:o,transitionEasing:s}=e,c=t===`left`||t===`right`,l=t===`left`?{right:0}:t===`right`?{left:0}:t===`up`?{bottom:0}:{top:0},u=S(o,s);return{position:`absolute`,...l,...c?{top:0}:{left:0},width:n,height:n,borderRadius:a,overflow:`hidden`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:r,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 ${u}, -webkit-mask-position ${u}, mask-position ${u}`,"& > *":{boxShadow:`none !important`,borderRadius:`inherit !important`,width:`100%`,height:`100%`,margin:0}}});function D(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 O=c.forwardRef(function(e,t){let{children:n,direction:r=y.direction,size:i=y.size,variant:a=y.variant,gap:o=y.gap,fadeWidth:s=y.fadeWidth,trigger:p=y.trigger,open:m,defaultOpen:g=y.defaultOpen,onOpen:S,onClose:C,disableClickAway:O=y.disableClickAway,transitionDuration:k=y.transitionDuration,transitionEasing:A=y.transitionEasing,classes:j,slots:M,slotProps:N,className:P,...F}=(0,u.useThemeProps)({props:e,name:`MuiCollageFab`}),[I,L]=(0,d.useControlled)({controlled:m,default:g,name:`CollageFab`,state:`open`}),R=c.useMemo(()=>c.Children.toArray(n).filter(e=>c.isValidElement(e)),[n]),z=R.length,B={open:I,direction:r,trigger:p,size:_(i),variant:a,cornerRadius:b[a],gap:o,fadeWidth:s,count:z,transitionDuration:k,transitionEasing:A},V=w(I,j),H=c.useRef(null),U=c.useRef([]),W=c.useRef(!1),G=c.useRef(`mouse`),K=c.useRef(!1),q=(0,d.useForkRef)(H,t),J=c.useCallback((e,t)=>{e!==I&&(L(e),e?S?.(t):C?.(t))},[I,L,S,C]),Y=e=>{p===`hover`&&e.pointerType===`mouse`&&J(!0,e)},X=e=>{p===`hover`&&e.pointerType===`mouse`&&J(!1,e)},Z=e=>{p!==`manual`&&(G.current=e.pointerType,W.current=!1,e.pointerType===`mouse`||I||(W.current=!0,J(!0,e)))},ee=e=>{W.current&&(W.current=!1,e.stopPropagation(),e.preventDefault())},te=e=>{p!==`manual`&&(p===`click`?J(!I,e):I&&G.current!==`mouse`&&J(!1,e))},ne=e=>{if(p!==`manual`){if(I){if(e.key!==`Escape`)return;e.stopPropagation(),J(!1,e),H.current?.focus()}else(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),K.current=!0,J(!0,e))}},re=e=>{J(!1,e)},Q=M?.root??T,ie=M?.item??E,ae=(0,f.default)({elementType:Q,externalForwardedProps:F,externalSlotProps:N?.root,ownerState:B,additionalProps:{ref:q,role:`group`,tabIndex:!I&&p!==`manual`?0:-1,onPointerEnter:Y,onPointerLeave:X,onPointerDown:Z,onClick:te,onClickCapture:ee,onKeyDown:ne},className:[V.root,P]});if(c.useEffect(()=>{if(!I||!K.current)return;K.current=!1;let e=U.current[0];e&&(e.querySelector(x)??e).focus()},[I]),z===0)return null;let $=(0,h.jsx)(Q,{...ae,children:R.map((e,t)=>(0,h.jsx)(D,{index:t,ownerState:B,geometry:v(t,B),className:V.item,component:ie,inert:!I&&p!==`manual`,itemRefs:U,slotProps:N?.item,children:e},t))});return O||p===`manual`?$:(0,h.jsx)(l.ClickAwayListener,{onClickAway:re,children:$})});exports.CollageFab=O;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SxProps, Theme } from '@mui/material/styles';
|
|
3
|
+
import { CreateSlotsAndSlotProps, SlotProps } from '@mui/material/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The axis the buttons fan out on, starting from the anchor child.
|
|
7
|
+
*/
|
|
8
|
+
type CollageFabDirection = 'left' | 'right' | 'up' | 'down';
|
|
9
|
+
/**
|
|
10
|
+
* How the group reacts to pointers.
|
|
11
|
+
*/
|
|
12
|
+
type CollageFabTrigger = 'hover' | 'click' | 'manual';
|
|
13
|
+
/**
|
|
14
|
+
* Diameter of every button. Named sizes resolve to small 40px, medium 48px and
|
|
15
|
+
* large 56px; numeric values are used verbatim.
|
|
16
|
+
*/
|
|
17
|
+
type CollageFabSize = 'small' | 'medium' | 'large' | number;
|
|
18
|
+
/**
|
|
19
|
+
* The shape of every button: a circle, a rounded square or a sharp-cornered
|
|
20
|
+
* square.
|
|
21
|
+
*/
|
|
22
|
+
type CollageFabVariant = 'circular' | 'rounded' | 'square';
|
|
23
|
+
/**
|
|
24
|
+
* Class names the component applies, and the accepted keys for `classes`.
|
|
25
|
+
*/
|
|
26
|
+
interface CollageFabClasses {
|
|
27
|
+
/** The animated container that holds every slice. */
|
|
28
|
+
root: string;
|
|
29
|
+
/** One masked wrapper per child. */
|
|
30
|
+
item: string;
|
|
31
|
+
/** Applied to the root while the group is expanded. */
|
|
32
|
+
expanded: string;
|
|
33
|
+
/** Applied to the root while the group is collapsed. */
|
|
34
|
+
collapsed: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Every key accepted by `classes`.
|
|
38
|
+
*/
|
|
39
|
+
type CollageFabClassKey = keyof CollageFabClasses;
|
|
40
|
+
/**
|
|
41
|
+
* Slot props accepted by a custom `root` slot component.
|
|
42
|
+
*/
|
|
43
|
+
interface CollageFabRootSlotPropsOverrides {
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Slot props accepted by a custom `item` slot component.
|
|
47
|
+
*/
|
|
48
|
+
interface CollageFabItemSlotPropsOverrides {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* State shared by the root slot and the item slots while styling.
|
|
52
|
+
*/
|
|
53
|
+
interface CollageFabOwnerState {
|
|
54
|
+
/** Whether the group is currently expanded. */
|
|
55
|
+
open: boolean;
|
|
56
|
+
/** The resolved fan-out direction. */
|
|
57
|
+
direction: CollageFabDirection;
|
|
58
|
+
/** The resolved pointer trigger mode. */
|
|
59
|
+
trigger: CollageFabTrigger;
|
|
60
|
+
/** The button diameter in pixels, after resolving the named size. */
|
|
61
|
+
size: number;
|
|
62
|
+
/** The resolved shape of every button. */
|
|
63
|
+
variant: CollageFabVariant;
|
|
64
|
+
/** The corner radius resolved from `variant`, inherited by every child. */
|
|
65
|
+
cornerRadius: number | string;
|
|
66
|
+
/** The main-axis gap in pixels. */
|
|
67
|
+
gap: number;
|
|
68
|
+
/** The fade width in pixels. */
|
|
69
|
+
fadeWidth: number;
|
|
70
|
+
/** The number of valid children currently rendered. */
|
|
71
|
+
count: number;
|
|
72
|
+
/** The morph duration in milliseconds. */
|
|
73
|
+
transitionDuration: number;
|
|
74
|
+
/** The morph easing. */
|
|
75
|
+
transitionEasing: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The per-slice CSS computed for one child.
|
|
79
|
+
*/
|
|
80
|
+
interface CollageFabItemGeometry {
|
|
81
|
+
/** The translate that moves the slice along the main axis. */
|
|
82
|
+
translate: string;
|
|
83
|
+
/** The gradient that cuts the slice out of the container. */
|
|
84
|
+
maskImage: string;
|
|
85
|
+
/** The size of that gradient, wide enough to cover the expanded row. */
|
|
86
|
+
maskSize: string;
|
|
87
|
+
/** The offset that pins the cut line in container space. */
|
|
88
|
+
maskPosition: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* State handed to the item slot. It extends the shared state with the position
|
|
92
|
+
* of the child, so an item can be styled individually.
|
|
93
|
+
*/
|
|
94
|
+
interface CollageFabItemOwnerState extends CollageFabOwnerState {
|
|
95
|
+
/** The position of the child in the stack. 0 is the anchor. */
|
|
96
|
+
index: number;
|
|
97
|
+
/** True for the anchor child (index 0). */
|
|
98
|
+
isAnchor: boolean;
|
|
99
|
+
/** The computed translate, mask image, mask size and mask position for this slice. */
|
|
100
|
+
geometry: CollageFabItemGeometry;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Replaceable internal components.
|
|
104
|
+
*/
|
|
105
|
+
interface CollageFabSlots {
|
|
106
|
+
/** The animated container. A replacement must forward `ref`, which `ClickAwayListener` needs. */
|
|
107
|
+
root?: React.ElementType;
|
|
108
|
+
/** One masked wrapper per child, shaped by `variant`. */
|
|
109
|
+
item?: React.ElementType;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The `slots` and `slotProps` props, typed per slot.
|
|
113
|
+
*/
|
|
114
|
+
type CollageFabSlotsAndSlotProps = CreateSlotsAndSlotProps<CollageFabSlots, {
|
|
115
|
+
/** Props for the root slot, or a resolver that receives the shared ownerState. */
|
|
116
|
+
root: SlotProps<'div', CollageFabRootSlotPropsOverrides, CollageFabOwnerState>;
|
|
117
|
+
/** Props for the item slot, or a resolver that receives the item ownerState. */
|
|
118
|
+
item: SlotProps<'div', CollageFabItemSlotPropsOverrides, CollageFabItemOwnerState>;
|
|
119
|
+
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Props for the CollageFab component.
|
|
122
|
+
*/
|
|
123
|
+
interface CollageFabProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
124
|
+
/**
|
|
125
|
+
* The buttons to stack. Every valid element is wrapped in a masked slot shaped
|
|
126
|
+
* by `variant`. Order matters: index 0 is the anchor, the rest fan out along
|
|
127
|
+
* `direction`.
|
|
128
|
+
*/
|
|
129
|
+
children?: React.ReactNode;
|
|
130
|
+
/**
|
|
131
|
+
* The axis the buttons fan out on, starting from the anchor child. `left`
|
|
132
|
+
* matches the original right-anchored behaviour.
|
|
133
|
+
*/
|
|
134
|
+
direction?: CollageFabDirection;
|
|
135
|
+
/**
|
|
136
|
+
* Diameter of every button. Named sizes resolve to small 40px, medium 48px,
|
|
137
|
+
* large 56px; numeric values are used verbatim.
|
|
138
|
+
*/
|
|
139
|
+
size?: CollageFabSize;
|
|
140
|
+
/**
|
|
141
|
+
* The shape of every button. `'circular'` clips each slice to a circle,
|
|
142
|
+
* `'rounded'` to a rounded square and `'square'` to a sharp-cornered square.
|
|
143
|
+
* The mask still slices the silhouette along the main axis, so the stack reads
|
|
144
|
+
* as one shape when collapsed and as separate shapes when expanded.
|
|
145
|
+
*/
|
|
146
|
+
variant?: CollageFabVariant;
|
|
147
|
+
/**
|
|
148
|
+
* Main-axis gap in pixels between two buttons when expanded.
|
|
149
|
+
*/
|
|
150
|
+
gap?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Width in pixels of the soft cut line between two slices.
|
|
153
|
+
*/
|
|
154
|
+
fadeWidth?: number;
|
|
155
|
+
/**
|
|
156
|
+
* How the group reacts to pointers. `'hover'` opens on mouse enter, closes on
|
|
157
|
+
* mouse leave and toggles on touch or pen tap; `'click'` toggles on any click;
|
|
158
|
+
* `'manual'` disables all built-in pointer interaction.
|
|
159
|
+
*/
|
|
160
|
+
trigger?: CollageFabTrigger;
|
|
161
|
+
/**
|
|
162
|
+
* If `true`, the group is expanded. Use it to control the component.
|
|
163
|
+
*/
|
|
164
|
+
open?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* If `true`, the group is expanded by default (uncontrolled).
|
|
167
|
+
*/
|
|
168
|
+
defaultOpen?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Callback fired when the group is expanded.
|
|
171
|
+
*/
|
|
172
|
+
onOpen?: (event: React.SyntheticEvent) => void;
|
|
173
|
+
/**
|
|
174
|
+
* Callback fired when the group is collapsed.
|
|
175
|
+
*/
|
|
176
|
+
onClose?: (event: React.SyntheticEvent) => void;
|
|
177
|
+
/**
|
|
178
|
+
* If `true`, the group does not collapse when the user clicks away from it.
|
|
179
|
+
*/
|
|
180
|
+
disableClickAway?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Duration of the morph, in milliseconds.
|
|
183
|
+
*/
|
|
184
|
+
transitionDuration?: number;
|
|
185
|
+
/**
|
|
186
|
+
* Easing of the morph.
|
|
187
|
+
*/
|
|
188
|
+
transitionEasing?: string;
|
|
189
|
+
/**
|
|
190
|
+
* System prop that defines system overrides as well as additional CSS styles.
|
|
191
|
+
*/
|
|
192
|
+
sx?: SxProps<Theme>;
|
|
193
|
+
/**
|
|
194
|
+
* Override or extend the styles applied to the component.
|
|
195
|
+
*/
|
|
196
|
+
classes?: Partial<CollageFabClasses>;
|
|
197
|
+
/**
|
|
198
|
+
* Custom components for the `root` and `item` slots.
|
|
199
|
+
*/
|
|
200
|
+
slots?: CollageFabSlotsAndSlotProps['slots'];
|
|
201
|
+
/**
|
|
202
|
+
* Props for each slot. `slotProps.item` accepts either a props object or an
|
|
203
|
+
* `(ownerState) => props` callback, which is the per-child escape hatch.
|
|
204
|
+
*/
|
|
205
|
+
slotProps?: CollageFabSlotsAndSlotProps['slotProps'];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A floating action button that stacks several children into a single shape and
|
|
209
|
+
* unfolds them along a configurable direction on interaction. The root animates
|
|
210
|
+
* its own main-axis extent and applies one shared drop shadow, while each child
|
|
211
|
+
* is clipped by a moving gradient mask.
|
|
212
|
+
*/
|
|
213
|
+
declare const CollageFab: React.ForwardRefExoticComponent<CollageFabProps & React.RefAttributes<HTMLDivElement>>;
|
|
214
|
+
|
|
215
|
+
export { CollageFab };
|
|
216
|
+
export type { CollageFabClassKey, CollageFabClasses, CollageFabDirection, CollageFabItemGeometry, CollageFabItemOwnerState, CollageFabItemSlotPropsOverrides, CollageFabOwnerState, CollageFabProps, CollageFabRootSlotPropsOverrides, CollageFabSize, CollageFabSlots, CollageFabSlotsAndSlotProps, CollageFabTrigger, CollageFabVariant };
|