# `LedgerUI.Components.Sticky`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/sticky.ex#L1)

A block that sticks to the top of the page and takes classes while the page is scrolled: a header
that gets an edge, a bar that gets a shadow.

    <.sticky id="page-bar" stuck_class="shadow-md">...</.sticky>

The hook `LedgerUI.Sticky` (`priv/static/ledger_ui/hooks/sticky.js`) adds `stuck_class` and sets
`data-stuck` once the page is scrolled past `offset` pixels, and takes them off when it is back.
The block is `position: sticky; top: 0`.

## Preview

`preview` draws the canvas picture of the behavior: a frame (`lu-sticky`) with the `:header` slot on a
translucent bar and the content scrolling under it (`body_class` / `body_style` go to the content, for
the scrolling animation). No hook. For the documentation and the showcase only.

    <.sticky id="demo" preview body_class="mo-scroll" body_style="--sy:-160px">
      <:header>Orders today</:header>
      <i style="width:90%"></i>
    </.sticky>

# `sticky`

## Attributes

* `id` (`:string`) (required)
* `offset` (`:integer`) - Pixels the page scrolls before the block counts as stuck. Defaults to `0`.
* `stuck_class` (`:string`) - Classes added while stuck. Without it the hook draws a 1px bottom line. Defaults to `nil`.
* `preview` (`:boolean`) - The canvas picture of a sticky header. Defaults to `false`.
* `body_class` (`:string`) - With `preview`: extra classes of the content. Defaults to `nil`.
* `body_style` (`:string`) - With `preview`: the style of the content. Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `inner_block` (required)
* `header` - With `preview`: the content of the bar.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
