control_button
StableA map control button with an icon or your own content, and an active state.
<div id="control-button-example">
<.example_frame error={@map_error} error_id="example-control-button-map-error">
<.map
id="example-control-button-map"
center={[2.1734, 41.3851]}
zoom={15}
pitch={@pitch}
bearing={-20}
style={basemap(@theme)}
events={["map:moved", "map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- phx-click is passed on to the button on the map; active tints it,
in the colour this app gives --maplibrex-control-active-background. --%>
<.control_button
id="example-control-button-tilt"
map_id="example-control-button-map"
position="top-left"
tooltip={tooltip(@tilted)}
active={@tilted}
class="grid! place-items-center"
phx-click="tilt"
>
<.icon name="hero-cube-transparent" class="size-5" />
</.control_button>
<div class="border-t border-line px-4 py-4">
<.example_note id="example-control-button-hint" icon="hero-cursor-arrow-rays-micro">
{gettext(
"Press the button in the map's top-left corner: each press reaches handle_event/3, which tilts or flattens the map."
)}
</.example_note>
</div>
<%!-- map:moved keeps pitch current when the map is tilted by hand. --%>
<.example_readout values={[tilted: @tilted, pitch: @pitch, presses: @presses]} />
</div>
Generated from the component's definition in the library, so it always matches the version this demo runs.
| Attribute | Type | Default | Description |
|---|---|---|---|
| id required | string | — | Unique identifier for the control button |
| map_id required | string | — | ID of the map to add the control to |
| position | string |
"top-right"
|
Control position: "top-left", "top-right", "bottom-left", "bottom-right". Defaults to "top-right". A new value moves the button to that corner
|
| icon | string |
nil
|
Text icon or emoji to display (if no slot provided). A new value, or new slot content, is shown at once |
| tooltip | string |
nil
|
Tooltip text shown on hover, also the button's accessible name. A new value applies at once |
| active | boolean |
nil
|
Whether the button is in active state, for a button that toggles something. Given (true or false), it makes the button a toggle button: the <button> has aria-pressed="true" or aria-pressed="false", as terrain_control's has. Left out (or nil), the button is not a toggle and has no aria-pressed; it looks inactive. An active button gets the maplibregl-ctrl-active class, which maplibrex.css gives a tinted background, kept while the button is hovered or pressed (--maplibrex-control-active-background sets it, and --maplibrex-control-active-hover-background its hover shade). A new value applies at once
|
| class | string |
""
|
Additional CSS classes to apply to the button. A new value applies at once |
| global attributes | global | — | Any other HTML attribute, passed on to the component's element. |
Slots
- inner_block Optional.