Customising a component
Every knob is an attribute or a CSS variable, so you never edit the files, and updates from the Vault drop in cleanly.
Options
Each resource lists its options. They are data-au-<option> attributes on the root element, and the copied HTML spells out every one with its default value.
<a class="mgb_button" data-au-magnetic-button
data-au-variant="outline" data-au-strength="8" data-au-label-strength="20" href="#">…</a>Three kinds:
- Range: a number inside a stated range, like
data-au-strength="18". - Toggle:
trueorfalse. - Select: one of a few named modes, like
data-au-variant="outline". Modes are how a component's variants are chosen.
The script reads options once, when it boots. If you change an attribute afterwards, call refresh() (below) so it reads them again.
In React, the same options are props in camelCase: strength={18}, labelStrength={10}. Changing a prop remounts the effect.
Trying values
Each resource page has a control for every option beside the preview. Try values there and watch the effect, then write the ones you like into the attributes, or the props.
CSS variables
Colours and sizes live in CSS variables named after the component's prefix, declared on its root element with the library's defaults.
.mgb_button {
--mgb-bg: #d24600; /* the pill */
--mgb-text: #ffffff; /* label at rest */
--mgb-fill: #f4f4f4; /* the shape that rises in */
--mgb-ink: #151314; /* label on the fill */
}Override them on the root, or on any parent, and leave the rules alone.
.hero .mgb_button {
--mgb-bg: #151314;
--mgb-fill: #fe773d;
--mgb-ink: #151314;
}Keep pairs readable: --mgb-ink sits on --mgb-fill, so if you change one, check the other.
Each resource's notes list its variables; the MCP's get_resource lists them too.
Size and type
Inside a component, anything that should scale with text is in em: padding, gaps, type, radii. So font-size on the root scales the whole thing.
.hero .mgb_button {
font-size: 1.125rem; /* a bigger button, same proportions */
}Type is font-family: inherit, so components take your site's font.
Classes and attributes
- Classes (
mgb_button,mgb_label) are styling only. You can rename them, as long as you rename them in the CSS too. - Attributes (
data-au-magnetic-button,data-mgb-fill) are how the script finds things. Keep them exactly as copied. If one is missing, the script logs a line saying so and leaves that instance alone.
The window.au API
Each script registers itself as window.au.<Name>, in PascalCase: window.au.MagneticButton, window.au.WavyAccordion.
window.au.MagneticButton.init(el); // start one element
window.au.MagneticButton.refresh(); // destroy and re-init every instance, re-reading options
window.au.MagneticButton.refresh(el); // the same for one element
window.au.MagneticButton.destroy(el); // tear one down; leave out `el` for all of themdestroy removes everything the component created: tweens, ScrollTriggers, observers and listeners.
Content added after load
Components boot once, on DOMContentLoaded. Instances that arrive later (client-side routing, a modal, a CMS list rendered by your framework) need a nudge.
// after the new markup is in the DOM
window.au.MagneticButton.refresh();The React versions do this for you: each instance starts on mount and is torn down on unmount.
Transforms
Components that move their root element, like the Magnetic Button's pull, own its transform. Don't animate that element's transform yourself for entrances or hover lifts; wrap it and animate the wrapper.