alpine-breakpoint

1.0.0 • Public • Published

alpine-breakpoint

x-directive and $magic for responsive event handling

just the directive for now

<div x-data="{ test: null }" x-breakpoint:max.768 @breakpoint="test = $event.detail.matches">
    <p x-text="`component1: ${test}`"></p>
    <span x-text="(test) ? `👍` : `👎`"></span>
</div>

usage for initialization as follows: x-breakpoint.min|max.width

min|max min or max dictates the threshold type of viewport measurement (based on width)

.width written with integers, base unit is pixels.

directive makes use of:

window.matchMedia(`(${min|max}-width: ${width}px)`)

for checking viewport dimensions. whenever the query fires a 'change' event a custom @breakpoint event will fire, with the media query's matches state returned with it:

@breakpoint="test = $event.detail.matches"

the directive will automatically dispatch an event on initialization as well. Setting the above example's null value to the proper measurement when loaded.

Dependencies (5)

Dev Dependencies (1)

Package Sidebar

Install

npm i alpine-breakpoint

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

20 kB

Total Files

17

Last publish

Collaborators

  • thatonejustin