stimulus-infinite-scroll
v2.0.0
Published
Stimulus Infinite Scroll based on pagination
Downloads
2
Readme
Stimulus Infinite Scroll controller
Installation
- Add package
yarn add stimulus-infinite-scroll
- Import package in your application
Note: Rails is required
import { Application } from 'stimulus'
const application = Application.start()
import InfiniteScrollController from 'stimulus-infinite-scroll'
application.register('toggle', InfiniteScrollController)
Example
<div data-controller='infinite-scroll'
data-infinite-scroll-root-margin-value="200px"> <-- optional -->
<div data-infinite-scroll-target='entries'>
<%= render 'posts' %>
</div>
<div data-infinite-scroll-target='pagination' class='d-none'>
<%== pagy_nav @pagy %>
</div>
</div>
.invisible { visibility: hidden; }
# controller
def index
@pagy, @rewards = pagy ...
respond_to do |format|
format.json {
render json: {
entries: render_to_string(partial: 'rewards/rewards', formats: [:html]),
pagination: view_context.pagy_nav(@pagy)
}
}
end
end
# view
<%= render partial: 'rewards/reward', collection: @rewards, cached: true %>
Publish new version
- Run
yarn build
- Update
CHANGELOG.md
- Run
yarn publish
Credit
Chris Oliver @ https://github.com/gorails-screencasts/infinite-scroll-stimulus-js