- Code
WidgetProvider.jsx
Installation
Usage
Wrap a single element inWidgetProvider and read the mode with
WidgetConsumer (a render prop) or the useWidgetContext hook.
WidgetProvider tracks whether its child is on screen (via
react-intersection-observer). It exposes:
mode:"inline"while the child is in view, the player isstopped, or the widget was closed. Otherwise"widget"(e.g. a floating mini-player once the user scrolls past it).close(): pinsmodeback to"inline"permanently.
WidgetProvider clones its single child to attach the visibility ref, so it
must wrap exactly one element. Read the value lower in the tree with
useWidgetContext(), which throws if used outside a WidgetProvider.