https://github.com/alpine-collective/alpine-magic-helpers
Skip to content
Sign up
* Why GitHub?
Features -
+ Mobile -
+ Actions -
+ Codespaces -
+ Packages -
+ Security -
+ Code review -
+ Project management -
+ Integrations -
+ GitHub Sponsors -
+ Customer stories -
+ Security -
* Team
* Enterprise
* Explore
+ Explore GitHub -
Learn & contribute
+ Topics -
+ Collections -
+ Trending -
+ Learning Lab -
+ Open source guides -
Connect with others
+ The ReadME Project -
+ Events -
+ Community forum -
+ GitHub Education -
+ GitHub Stars program -
* Marketplace
* Pricing
Plans -
+ Compare plans -
+ Contact Sales -
+ Nonprofit -
+ Education -
[ ] [search-key]
*
#
In this repository All GitHub |
Jump to |
* No suggested jump to results
*
#
In this repository All GitHub |
Jump to |
*
#
In this organization All GitHub |
Jump to |
*
#
In this repository All GitHub |
Jump to |
Sign in Sign up
{{ message }}
alpine-collective / alpine-magic-helpers
generated from KevinBatdorf/alpine-plugin-template
* Sponsor
Sponsor alpine-collective/alpine-magic-helpers
* Watch 6
* Star 280
* Fork 8
A collection of magic properties and helper functions for use with
Alpine.js
npmjs.com/alpine-magic-helpers
MIT License
280 stars 8 forks
Star
Watch
* Code
* Issues 1
* Pull requests 0
* Discussions
* Actions
* Projects 1
* Security
* Insights
More
* Code
* Issues
* Pull requests
* Discussions
* Actions
* Projects
* Security
* Insights
master
5 branches 17 tags
Go to file Code
Clone
HTTPS GitHub CLI
[https://github.com/a]
Use Git or checkout with SVN using the web URL.
[gh repo clone alpine]
Work fast with our official CLI. Learn more.
* Open with GitHub Desktop
* Download ZIP
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Go back
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Go back
Launching Xcode
If nothing happens, download Xcode and try again.
Go back
Launching Visual Studio
If nothing happens, download the GitHub extension for Visual Studio
and try again.
Go back
Latest commit
KevinBatdorf@users.noreply.github.com
KevinBatdorf@users.noreply.github.com Update version in README
...
7a6beba Feb 13, 2021
Update version in README
7a6beba
Git stats
* 91 commits
Files
Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
.github
remove pr approval requirement (#80)
Feb 10, 2021
dist
Feature/magic properties in component (#82)
Feb 10, 2021
examples
Feature/magic properties in component (#82)
Feb 10, 2021
src
Feature/magic properties in component (#82)
Feb 10, 2021
tests
Feature/magic properties in component (#82)
Feb 10, 2021
.editorconfig
Initial commit
Aug 16, 2020
.eslintignore
refactor (#7)
Sep 30, 2020
.eslintrc.js
refactor (#7)
Sep 30, 2020
.gitignore
Initial commit
Aug 16, 2020
CHANGELOG.md
Feature/magic properties in component (#82)
Feb 10, 2021
LICENSE.md
refactor (#7)
Sep 30, 2020
README.md
Update version in README
Feb 13, 2021
babel.config.js
refactor (#7)
Sep 30, 2020
jest.config.js
refactor (#7)
Sep 30, 2020
package-lock.json
1.0.0
Feb 13, 2021
package.json
1.0.0
Feb 13, 2021
rollup.config.js
feature: add new $refresh helper (#75)
Feb 5, 2021
View code
README.md
Magic Helpers
A collection of magic properties and helper functions for use with
Alpine.js
GitHub tag (latest by date) [6874747073]
About
Adds the following magic helpers to use with Alpine JS. More to come!
Magic Helpers Description
$component/ Natively access and update data from other components
$parent or the parent component.
$fetch Using Axios, fetch JSON from an external source.
$interval Run a function every n milliseconds. Optionally start
and stop the timer.
$range Iterate over a range of values.
$refresh Manually refresh a component.
$screen Detect if the current browser width is equal or greater
than a given breakpoint.
$scroll Scroll the page vertically to a specific position.
$truncate Limit a text string to a specific number of characters
or words.
$undo Track and undo state changes inside your component.
If you have ideas for more magic helpers, please open a discussion
or join us on the AlpineJS Discord
Installation
Include the following
Or you can use the specific magic helpers you need:
---------------------------------------------------------------------
Manual
If you wish to create your own bundle:
npm install alpine-magic-helpers --save
Then add the following to your script:
import 'alpine-magic-helpers'
import 'alpinejs'
Or you can import the specific magic helpers you need like so:
import 'alpine-magic-helpers/dist/component'
import 'alpine-magic-helpers/dist/fetch'
import 'alpinejs'
$component
Example:
Arguably more useful, this also adds a $parent magic helper to access
parent data
Demo
You may watch other components, but you must give them each an id
using the 'id' attribute or x-id if you need more flexibility:
$fetch
Example:
Demo
Optionally pass in an options object
By default, $fetch will return the JSON data object. However, because
we are using Axios behind the scenes, you may pass in an object to
customize the request See all options.
Example:
Note that this will return the entire response object, whereas by
default $fetch will only return the data
---------------------------------------------------------------------
$interval
Example:
Demo
Optionally pass in options
By default, $interval will run your function every nth millisecond
when browser provides an animation frame (via requestAnimationFrame).
This means that the function will not run if the browser tab is not
visible. Optionally, you may pass in the following options as the
second parameter:
Property Description
timer Timer in milliseconds.
delay Delay the first run. N.B. The first run is also delayed
by the timer time.
forceInterval Ignore the browser animation request mechanism. Default
is false
[?][?] We also add a hidden property autoIntervalTest that will clear
/stop the timer if set to false, and start the timer if then set
to true.
Example:
Demo
---------------------------------------------------------------------
$range
Example:
The $range helper mostly mimics implementations found in other
languages $range(start, stop, step = 1)
...
Demo
N.B: You may use $range(10) which will compute to [1...10]
---------------------------------------------------------------------
$refresh
Example:
Demo
---------------------------------------------------------------------
$screen
Example:
The $screen helper detects if the current browser width is equal or
greater than a given breakpoint and returns true or false based on
the result.
This will be visible if the window width is equal or greater than 1024px.
By default the $screen helper uses the following endpoint borrowed by
Tailwind CSS:
* xs: 0px
* sm: 640px
* md: 768px
* lg: 1024px
* xl: 1280px
* 2xl: 1536px
[?][?] NOTE: A single breakpoint is only going to tell you if the
browser width is equal or greater than the given breakpoint. If
you want to restrict the check to a specific range, you will need
to negate the next endpoint as:
This will be visible if screen width is equal or greater than 768px but smaller then 1024px.
Custom breakpoints
You can pass a numeric value to use an ad-hoc breakpoint.
This will be visible if screen width is equal or greater than 999px.
You can also override the default breakpoints including the following
And using those breakpoints in your page.
This will be visible if screen width is equal or greater than 769px.