Skip to content

Commit

Permalink
Add DEFAULT[:bulma_nav_classes]; small fixes in frontend styles
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jan 26, 2024
1 parent 618b7ca commit dcfe261
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 281 deletions.
4 changes: 4 additions & 0 deletions docs/extras/bulma.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ See [Javascript](/docs/api/javascript.md) if you use `pagy_bulma_nav_js` or `pag
- [bulma_nav.html.haml](https://github.com/ddnexus/pagy/blob/master/lib/templates/bulma_nav.html.haml) (optional template)
- [bulma_nav.html.slim](https://github.com/ddnexus/pagy/blob/master/lib/templates/bulma_nav.html.slim) (optional template)

| Variable | Description | Default |
|:---------------------|:------------------------------------------------------------------------------|:---------------|
| `:bulma_nav_classes` | Edit the classes for the nav element. You can try "is-small", "is-round" etc. | `"is-centered"` |

## Methods

This extra adds 3 nav helpers to the `Pagy::Frontend` module.
Expand Down
174 changes: 87 additions & 87 deletions e2e/snapshots.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/config/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
# Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination
# See https://ddnexus.github.io/pagy/docs/extras/bulma
# require 'pagy/extras/bulma'
# DEFAULT[:bulma_nav_classes] = 'is-centered' # default

# Foundation extra: Add nav, nav_js and combo_nav_js helpers and templates for Foundation pagination
# See https://ddnexus.github.io/pagy/docs/extras/foundation
Expand Down
9 changes: 6 additions & 3 deletions lib/pagy/extras/bulma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require 'pagy/extras/frontend_helpers'

class Pagy # :nodoc:
DEFAULT[:bulma_nav_classes] = 'is-centered'

# Frontend modules are specially optimized for performance.
# The resulting code may not look very elegant, but produces the best benchmarks
module BulmaExtra
Expand All @@ -13,7 +15,7 @@ def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '',
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra:)

html = +%(<nav#{p_id} class="pagy-bulma-nav pagination is-centered" #{
html = +%(<nav#{p_id} class="pagy-bulma-nav pagination #{DEFAULT[:bulma_nav_classes]}" #{
pagy_aria_label(pagy, page_label, page_i18n_key)}>)
html << pagy_bulma_prev_next_html(pagy, link)
html << %(<ul class="pagination-list">)
Expand Down Expand Up @@ -43,7 +45,7 @@ def pagy_bulma_nav_js(pagy, pagy_id: nil, link_extra: '',
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>),
'after' => '</ul>' }

%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bulma-nav-js pagination is-centered" #{
%(<nav#{p_id} class="#{'pagy-rjs ' if sequels.size > 1}pagy-bulma-nav-js pagination #{DEFAULT[:bulma_nav_classes]}" #{
pagy_aria_label(pagy, page_label, page_i18n_key)}#{
pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels))}></nav>)
end
Expand All @@ -58,7 +60,8 @@ def pagy_bulma_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
input = %(<input class="input" type="number" min="1" max="#{p_pages}" value="#{
p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length + 1}rem; margin:0 0.3rem;">)

html = %(<nav#{p_id} class="pagy-bulma-combo-nav-js" #{pagy_aria_label(pagy, page_label, page_i18n_key)}>)
html = %(<nav#{p_id} class="pagy-bulma-combo-nav-js #{DEFAULT[:bulma_nav_classes]}" #{
pagy_aria_label(pagy, page_label, page_i18n_key)}>)
%(#{html}<div class="field is-grouped is-grouped-centered" role="group" #{
pagy_data(pagy, :combo, pagy_marked_link(link))}>#{
if (p_prev = pagy.prev)
Expand Down
10 changes: 5 additions & 5 deletions lib/pagy/extras/foundation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def pagy_foundation_nav(pagy, pagy_id: nil, link_extra: '',
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra:)

html = +%(<nav#{p_id} class="pagy-foundation-nav" aria-label="Pagination" #{
html = +%(<nav#{p_id} class="pagy-foundation-nav" #{
pagy_aria_label(pagy, page_label, page_i18n_key)}><ul class="pagination">)
html << pagy_foundation_prev_html(pagy, link)
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
html << case item
when Integer # page link
when Integer
%(<li>#{link.call item}</li>)
when String # active page
when String
%(<li class="current" role="link" aria-current="page" aria-disabled="true">#{pagy.label_for(item)}</li>)
when :gap # page gap
when :gap
%(<li class="ellipsis gap"></li>)
else
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
Expand Down Expand Up @@ -74,7 +74,7 @@ def pagy_foundation_combo_nav_js(pagy, pagy_id: nil, link_extra: '',
pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
.sub!('<label>', '<label class="input-group-label">')}#{ # add the class to the official dictionary string
if (p_next = pagy.next)
link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0" aria-label="next" class="next button primary"'
link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0" class="next button primary"'
else
%(<a style="margin-bottom: 0" class="next button primary disabled" role="link" aria-disabled="true">#{
pagy_t 'pagy.nav.next'}</a>)
Expand Down
6 changes: 3 additions & 3 deletions lib/pagy/extras/materialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '',
html << pagy_materialize_prev_html(pagy, link)
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
html << case item
when Integer # page link
when Integer
%(<li class="waves-effect">#{link.call(item)}</li>)
when String # active page
when String
%(<li class="active">#{link.call(item)}</li>)
when :gap # page gap
when :gap
%(<li class="gap disabled"><a href="#" aria-disabled="true">#{pagy_t 'pagy.nav.gap'}</a></li>)
else
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
Expand Down
10 changes: 5 additions & 5 deletions lib/pagy/extras/overflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Pagy # :nodoc:
# Handles OverflowError exceptions for different classes with different options
module OverflowExtra
# Support for Pagy class
module Pagy
module PagyOverride
# Is the requested page overflowing?
def overflow?
@overflow
Expand Down Expand Up @@ -50,9 +50,11 @@ def series(*, **)
end
end
end
::Pagy.prepend PagyOverride
::Pagy::Calendar.prepend PagyOverride if defined?(Calendar)

# Support for Pagy::Countless class
module Countless
module CountlessOverride
# Add rescue clause for different behaviors
def finalize(items)
@overflow = false
Expand All @@ -71,8 +73,6 @@ def finalize(items)
end
end
end
::Pagy::Countless.prepend CountlessOverride if defined?(Countless)
end
prepend OverflowExtra::Pagy
Calendar.prepend OverflowExtra::Pagy if defined?(Calendar)
Countless.prepend OverflowExtra::Countless if defined?(Countless)
end
4 changes: 2 additions & 2 deletions lib/pagy/extras/semantic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def pagy_semantic_prev_html(pagy, link)
if (p_prev = pagy.prev)
link.call(p_prev, pagy_t('pagy.nav.prev'), %(class="item"))
else
+%(<div class="item disabled" role="link" aria-label="disabled">#{pagy_t('pagy.nav.prev')}</div>)
+%(<div class="item disabled" role="link" aria-disabled="true">#{pagy_t('pagy.nav.prev')}</div>)
end
end

def pagy_semantic_next_html(pagy, link)
if (p_next = pagy.next)
link.call(p_next, pagy_t('pagy.nav.next'), %(class="item"))
else
+%(<div class="item disabled" role="link" aria-label="disabled">#{pagy_t('pagy.nav.next')}</div>)
+%(<div class="item disabled" role="link" aria-disabled="true">#{pagy_t('pagy.nav.next')}</div>)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/pagy/extras/uikit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def pagy_uikit_nav(pagy, pagy_id: nil, link_extra: '',
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
html << case item
when Integer
%(<li>#{link.call(item, pagy.label_for(item))}</li>)
%(<li>#{link.call(item)}</li>)
when String
%(<li class="uk-active"><span role="link" aria-current="true" aria-disabled="true">#{
%(<li class="uk-active"><span role="link" aria-current="page" aria-disabled="true">#{
pagy.label_for(item)}</span></li>)
when :gap
%(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>)
Expand All @@ -40,7 +40,7 @@ def pagy_uikit_nav_js(pagy, pagy_id: nil, link_extra: '',
link = pagy_link_proc(pagy, link_extra:)
tags = { 'before' => pagy_uikit_prev_html(pagy, link),
'link' => %(<li>#{link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER)}</li>),
'active' => %(<li class="uk-active"><span role="link" aria-current="true" aria-disabled="true">#{
'active' => %(<li class="uk-active"><span role="link" aria-current="page" aria-disabled="true">#{
LABEL_PLACEHOLDER}</span></li>),
'gap' => %(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>),
'after' => pagy_uikit_next_html(pagy, link) }
Expand Down Expand Up @@ -79,7 +79,7 @@ def pagy_uikit_prev_html(pagy, link)
if (p_prev = pagy.prev)
%(<li>#{link.call(p_prev, previous_span)}</li>)
else
%(<li class="uk-disabled"><a href="#" aria-disabled="true">#{previous_span}</a></li>)
%(<li class="uk-disabled"><span role="link" aria-disabled="true">#{previous_span}</a></li>)
end
end

Expand All @@ -88,7 +88,7 @@ def pagy_uikit_next_html(pagy, link)
if (p_next = pagy.next)
%(<li>#{link.call(p_next, next_span)}</li>)
else
%(<li class="uk-disabled"><a href="#" aria-disabled="true">#{next_span}</a></li>)
%(<li class="uk-disabled"><span role="link" aria-disabled="true">#{next_span}</span></li>)
end
end
end
Expand Down
Loading

0 comments on commit dcfe261

Please sign in to comment.