The currently active content key
An element ref to the background element
All user data, keyed by content id
The context provider's group id, used internally by useAmbient
Props which you should pass to your content component
By default, backgrounds will fade to transition from one to another. You can override
this behavior by providing your own wrapper component to implement the transition. If
you like, you can provide null
to have no transition at all. If you provide a custom
WrapperComponent, you probably also want to override the getWrapperProps value to pass
the correct props to your component.
You can provide any arbitrary data you like for this content, which will be made
available to all other uses of this hook inside the same parent context. Use
this feature for things like choosing a foreground color which is applied to every
section based on the current active section, by having each content section pass
a color value in data
, and then use the color value from the activeData
return
value to set the CSS foreground color.
If you provide your own WrapperComponent, it might have specific props it needs to render
correctly - use this function to compute the props that will be passed to that component
based on the current ambient state. Or, even if you use the default wrapper, you can provide
extra props to that wrapper using this function - for example, you can provide fadeDurationSeconds
to override the default fade duration on the built-in wrapper. If you override props for the
built-in wrapper (i.e. you provide this function without providing WrapperComponent), you must
at minimum return an object with active
set to state.active
.
Optionally, you can provide your own key for this content. By providing your own key, you can include logic which utilizes the activeKey value meaningfully.
A set of utilities for interacting with the ambient system. Includes
a function you should wrap your background content in when rendering,
and information about the currently active content. active
will be
true if the component which is bound to this hook usage is active.
Whether the content section which is bound to this hook usage is currently active.
The user-defined context data for the active content. This is the value
that was passed to the data
config property by the currently active
content when it called useAmbient.
The key of the currently active content. You can pass your own key to useActive if you want to utilize this meaningfully. Otherwise, it's a random value generated at runtime for each content item.
Wrap your background React content in this function and call it within your component JSX. You can also omit any content to render a blank background for this content.
The data- attribute used to identify the group a content element belongs to
The data- attribute used to identify content elements
A top-level Provider for the ambient system. Place this component
in the React tree above all usages of useAmbient. You can have multiple
different ambient systems at once, whether parallel or nested - but
note that since the default styling of the background pane is position: fixed,
by default multiple usages will collide! To fix this, change the styling
of the background pane using backgroundElementProps
.
The default background transition component. It fades quickly between active backgrounds as they change.
Hooks into the ambient background system and provides props to give to your content component, plus utilities for drawing your background and reacting to changes in the active content.
Generated using TypeDoc
The user data for the currently active content