govuk-components 3.0.5 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d5cf5d99c77bcfbd24e77252b855265660bc80e2496b75adda9cf10362c9ee1
4
- data.tar.gz: c54839796cf802ebe85dddf875a269b67a423856d36c87cdc7e16a4f90ee830d
3
+ metadata.gz: bb212d5aeb799affbe885b0a386f4f012e29938efeb71c7f4931c8ba5d16eb15
4
+ data.tar.gz: 45cb8082ee1df09af0a0528d1fb6f05e3113b2bd958bc334065e1c651017bff2
5
5
  SHA512:
6
- metadata.gz: 246a31f6ea734ae757f88bf92e0d2bf1ea15daa741fb87318f257b9d79926b189b8cf9312b492d6f82a9180608dec25344f7328f98c74f49d4ffd81fdda3540f
7
- data.tar.gz: 61d94fc80d6e125d198eb388afd056b3edd612b6463adb06a17fb9fbfe8e37862b93f99ce45603a21cdf8c32a8a1cfe28edbd463b952ea73c08e003948d4175c
6
+ metadata.gz: 46fedf48b9bacd94e9c846cad6fbf7a1bcbb342aa01f6f2e06123131dcd1982c01b0420ad2a1b9f62a78298575b81fb6de8b2047ee1d75d43ad490837046e95a
7
+ data.tar.gz: 3913d6cadd186bf5d0c349e644bd27234a6a0aa94b7b45fe33ed30eec342addb6ef53e5b4d43ab5e89ae7bb361d1e2cecb1d7e10580db33ccb18d74ef19ad5df
data/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  [![Gem](https://img.shields.io/gem/dt/govuk-components?logo=rubygems)](https://rubygems.org/gems/govuk-components)
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cbcbc140f300b920d833/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk-components/test_coverage)
8
8
  [![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk-components)](https://github.com/DFE-Digital/govuk-components/blob/main/LICENSE)
9
- [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.1.0-brightgreen)](https://design-system.service.gov.uk)
9
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.2.0-brightgreen)](https://design-system.service.gov.uk)
10
10
  [![Rails](https://img.shields.io/badge/Rails-6.1.5%20%E2%95%B1%207.0.3-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
- [![Ruby](https://img.shields.io/badge/Ruby-2.7.5%20%20%E2%95%B1%203.0.3%20%20%E2%95%B1%203.1.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
11
+ [![Ruby](https://img.shields.io/badge/Ruby-2.7.5%20%20%E2%95%B1%203.0.3%20%20%E2%95%B1%203.1.2-E16D6D)](https://www.ruby-lang.org/en/downloads/)
12
12
 
13
13
  This gem provides a suite of reusable components for the [GOV.UK Design System](https://design-system.service.gov.uk/). It is intended to provide a lightweight alternative to the [GOV.UK Publishing Components](https://github.com/alphagov/govuk_publishing_components) library and is built with GitHub’s [ViewComponent](https://github.com/github/view_component) framework.
14
14
 
@@ -30,6 +30,7 @@ The provided components are:
30
30
  * [Inset text](https://govuk-components.netlify.app/components/inset-text)
31
31
  * [Notification banner](https://govuk-components.netlify.app/components/notification-banner)
32
32
  * [Panel](https://govuk-components.netlify.app/components/panel)
33
+ * [Pagination](https://govuk-components.netlify.app/components/pagination)
33
34
  * [Phase banner](https://govuk-components.netlify.app/components/phase-banner)
34
35
  * [Section break](https://govuk-components.netlify.app/components/section-break)
35
36
  * [Start button](https://govuk-components.netlify.app/components/start-button)
@@ -4,6 +4,11 @@ class GovukComponent::Base < ViewComponent::Base
4
4
  attr_reader :html_attributes
5
5
 
6
6
  def initialize(classes:, html_attributes:)
7
+ if classes.nil?
8
+ Rails.logger.warn("classes is nil, if no custom classes are needed omit the param")
9
+
10
+ classes = []
11
+ end
7
12
  # FIXME: remove first merge when we deprecate classes
8
13
  #
9
14
  # This step only needs to be here while we still accept classes:, now
@@ -32,7 +32,7 @@
32
32
  <% if service_name.present? || navigation_items.present? %>
33
33
  <div class="govuk-header__content">
34
34
  <% if service_name.present? %>
35
- <%= link_to(service_name, service_url, class: %w(govuk-header__link govuk-header__link--service-name)) %>
35
+ <%= link_to(service_name, service_url, class: %w(govuk-header__link govuk-header__service-name)) %>
36
36
  <% end %>
37
37
 
38
38
  <% if navigation_items.any? %>
@@ -0,0 +1,60 @@
1
+ class GovukComponent::PaginationComponent::AdjacentPage < GovukComponent::Base
2
+ attr_reader :href, :label_text, :text, :suffix, :block_mode, :visually_hidden_text
3
+ alias_method :block_mode?, :block_mode
4
+
5
+ def initialize(href:, suffix:, visually_hidden_text:, text:, block_mode: true, label_text: nil, classes: [], html_attributes: {})
6
+ @href = href
7
+ @label_text = label_text
8
+ @text = text
9
+ @block_mode = block_mode
10
+ @suffix = suffix
11
+ @visually_hidden_text = visually_hidden_text
12
+
13
+ super(html_attributes: html_attributes, classes: classes)
14
+ end
15
+
16
+ def call
17
+ tag.div(**html_attributes) do
18
+ tag.a(href: href, class: %w(govuk-link govuk-pagination__link), rel: suffix, aria: { label: aria_label }) do
19
+ safe_join([body, divider, label_content])
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def default_attributes
27
+ { class: ["govuk-pagination__#{suffix}"] }
28
+ end
29
+
30
+ def body
31
+ [arrow, title_span]
32
+ end
33
+
34
+ def title_span
35
+ tag.span(text, class: title_classes)
36
+ end
37
+
38
+ def divider
39
+ return if label_text.blank?
40
+
41
+ tag.span(":", class: %w(govuk-visually-hidden))
42
+ end
43
+
44
+ def label_content
45
+ return if label_text.blank?
46
+
47
+ tag.span(label_text, class: label_classes)
48
+ end
49
+
50
+ def title_classes
51
+ class_names(
52
+ %(govuk-pagination__link-title),
53
+ %(govuk-pagination__link-title--decorated) => label_text.blank?
54
+ )
55
+ end
56
+
57
+ def label_classes
58
+ %w(govuk-pagination__link-label)
59
+ end
60
+ end
@@ -0,0 +1,77 @@
1
+ class GovukComponent::PaginationComponent::Item < GovukComponent::Base
2
+ attr_reader :number, :href, :visually_hidden_text, :mode
3
+
4
+ def initialize(number: nil, href: nil, current: false, ellipsis: false, from_pagy: false, visually_hidden_text: nil, classes: [], html_attributes: {})
5
+ @number = number
6
+ @href = href
7
+ @visually_hidden_text = visually_hidden_text
8
+
9
+ # We have three modes for rendering links:
10
+ #
11
+ # * link (a link to another page)
12
+ # * current (a link to the current page)
13
+ # * gap (an ellipsis symbol)
14
+ #
15
+ # Pagy sets these by object type:
16
+ # Integer = link
17
+ # String = current
18
+ # :gap = gap
19
+ #
20
+ # The original Nunjucks component has two boolean settings instead,
21
+ # ellipsis and current. When ellipsis is true all other arguments are
22
+ # ignored
23
+ @mode = from_pagy ? pagy_mode(number) : manual_mode(ellipsis, current)
24
+
25
+ super(classes: classes, html_attributes: html_attributes)
26
+ end
27
+
28
+ def call
29
+ case mode
30
+ when :link
31
+ link(current: false)
32
+ when :current
33
+ link(current: true)
34
+ when :gap
35
+ ellipsis_item
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def pagy_mode(number)
42
+ return :link if number.is_a?(Integer)
43
+ return :current if number.is_a?(String)
44
+
45
+ :gap
46
+ end
47
+
48
+ def manual_mode(ellipsis, current)
49
+ return :gap if ellipsis
50
+ return :current if current
51
+
52
+ :link
53
+ end
54
+
55
+ def link(current: false)
56
+ attributes = html_attributes.tap { |ha| ha[:class] << "govuk-pagination__item--current" if current }
57
+
58
+ tag.li(**attributes) do
59
+ tag.a(href: href, class: %w(govuk-link govuk-pagination__link)) { number.to_s }
60
+ end
61
+ end
62
+
63
+ def ellipsis_item
64
+ tag.li("⋯", class: %w(govuk-pagination__item govuk-pagination__item--ellipses))
65
+ end
66
+
67
+ def default_attributes
68
+ {
69
+ class: %w(govuk-pagination__item),
70
+ aria: { label: aria_label }
71
+ }
72
+ end
73
+
74
+ def aria_label
75
+ visually_hidden_text || "Page #{number}"
76
+ end
77
+ end
@@ -0,0 +1,32 @@
1
+ class GovukComponent::PaginationComponent::NextPage < GovukComponent::PaginationComponent::AdjacentPage
2
+ def initialize(href:, text:, label_text: nil, visually_hidden_text: nil, block_mode: true, classes: [], html_attributes: {})
3
+ super(
4
+ suffix: "next",
5
+ text: text,
6
+ href: href,
7
+ label_text: label_text,
8
+ block_mode: block_mode,
9
+ visually_hidden_text: visually_hidden_text,
10
+ classes: classes,
11
+ html_attributes: html_attributes
12
+ )
13
+ end
14
+
15
+ def body
16
+ return [arrow, title_span] if block_mode?
17
+
18
+ [title_span, arrow]
19
+ end
20
+
21
+ private
22
+
23
+ def aria_label
24
+ @visually_hidden_text || "Next page"
25
+ end
26
+
27
+ def arrow
28
+ tag.svg(class: "govuk-pagination__icon govuk-pagination__icon--next", xmlns: "http://www.w3.org/2000/svg", height: "13", width: "15", focusable: "false", viewBox: "0 0 15 13", aria: { hidden: "true" }) do
29
+ tag.path(d: "m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ class GovukComponent::PaginationComponent::PreviousPage < GovukComponent::PaginationComponent::AdjacentPage
2
+ def initialize(href:, text:, label_text: nil, visually_hidden_text: nil, block_mode: true, classes: [], html_attributes: {})
3
+ super(
4
+ suffix: "prev",
5
+ text: text,
6
+ href: href,
7
+ label_text: label_text,
8
+ block_mode: block_mode,
9
+ visually_hidden_text: visually_hidden_text,
10
+ classes: classes,
11
+ html_attributes: html_attributes
12
+ )
13
+ end
14
+
15
+ private
16
+
17
+ def aria_label
18
+ @visually_hidden_text || "Previous page"
19
+ end
20
+
21
+ def arrow
22
+ tag.svg(class: "govuk-pagination__icon govuk-pagination__icon--prev", xmlns: "http://www.w3.org/2000/svg", height: "13", width: "15", focusable: "false", viewBox: "0 0 15 13", aria: { hidden: "true" }) do
23
+ tag.path(d: "m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,126 @@
1
+ class GovukComponent::PaginationComponent < GovukComponent::Base
2
+ include Pagy::UrlHelpers
3
+
4
+ attr_reader :pagy,
5
+ :next_text,
6
+ :previous_text,
7
+ :visually_hidden_next_text,
8
+ :visually_hidden_previous_text,
9
+ :page_items,
10
+ :previous_content,
11
+ :next_content,
12
+ :block_mode,
13
+ :landmark_label
14
+
15
+ alias_method :block_mode?, :block_mode
16
+
17
+ renders_many :items, "GovukComponent::PaginationComponent::Item"
18
+
19
+ renders_one :next_page, ->(href:, text: default_next_text, label_text: nil, visually_hidden_text: nil, classes: [], html_attributes: {}) do
20
+ GovukComponent::PaginationComponent::NextPage.new(
21
+ text: text,
22
+ href: href,
23
+ label_text: label_text,
24
+ block_mode: block_mode?,
25
+ visually_hidden_text: visually_hidden_text,
26
+ classes: classes,
27
+ html_attributes: html_attributes
28
+ )
29
+ end
30
+
31
+ renders_one :previous_page, ->(href:, text: default_previous_text, label_text: nil, visually_hidden_text: nil, classes: [], html_attributes: {}) do
32
+ GovukComponent::PaginationComponent::PreviousPage.new(
33
+ text: text,
34
+ href: href,
35
+ label_text: label_text,
36
+ block_mode: block_mode?,
37
+ visually_hidden_text: visually_hidden_text,
38
+ classes: classes,
39
+ html_attributes: html_attributes
40
+ )
41
+ end
42
+
43
+ def initialize(pagy: nil, next_text: nil, previous_text: nil, visually_hidden_next_text: nil, visually_hidden_previous_text: nil, block_mode: false, landmark_label: "results", classes: [], html_attributes: {})
44
+ @pagy = pagy
45
+ @next_text = next_text
46
+ @previous_text = previous_text
47
+ @visually_hidden_next_text = visually_hidden_next_text
48
+ @visually_hidden_previous_text = visually_hidden_previous_text
49
+ @block_mode = block_mode
50
+ @landmark_label = landmark_label
51
+
52
+ super(classes: classes, html_attributes: html_attributes)
53
+ end
54
+
55
+ def before_render
56
+ @page_items = if pagy.present?
57
+ build_items
58
+ elsif items.any?
59
+ items
60
+ else
61
+ []
62
+ end
63
+
64
+ @previous_content = previous_page || build_previous
65
+ @next_content = next_page || build_next
66
+ end
67
+
68
+ def call
69
+ attributes = html_attributes.tap { |ha| (ha[:class] << "govuk-pagination--block") if items.empty? }
70
+
71
+ tag.nav(**attributes) do
72
+ safe_join([
73
+ previous_content,
74
+ tag.ul(class: "govuk-pagination__list") { safe_join(page_items) },
75
+ next_content
76
+ ])
77
+ end
78
+ end
79
+
80
+ def render?
81
+ # probably isn't any point rendering if there's only one page
82
+ (pagy.present? && pagy.series.size > 1) || @previous_content.present? || @next_content.present?
83
+ end
84
+
85
+ private
86
+
87
+ def default_attributes
88
+ { role: "navigation", aria: { label: landmark_label }, class: %w(govuk-pagination) }
89
+ end
90
+
91
+ def build_previous
92
+ return unless pagy&.prev
93
+
94
+ kwargs = {
95
+ href: pagy_url_for(pagy, pagy.prev),
96
+ text: @previous_text,
97
+ visually_hidden_text: visually_hidden_previous_text,
98
+ }
99
+
100
+ previous_page(**kwargs.compact)
101
+ end
102
+
103
+ def build_next
104
+ return unless pagy&.next
105
+
106
+ kwargs = {
107
+ href: pagy_url_for(pagy, pagy.next),
108
+ text: @next_text,
109
+ visually_hidden_text: visually_hidden_next_text,
110
+ }
111
+
112
+ next_page(**kwargs.compact)
113
+ end
114
+
115
+ def build_items
116
+ pagy.series.map { |i| item(number: i, href: pagy_url_for(pagy, i), from_pagy: true) }
117
+ end
118
+
119
+ def default_next_text
120
+ safe_join(["Next", tag.span(class: "govuk-visually-hidden") { " page" }])
121
+ end
122
+
123
+ def default_previous_text
124
+ safe_join(["Previous", tag.span(class: "govuk-visually-hidden") { " page" }])
125
+ end
126
+ end
@@ -9,6 +9,7 @@ module GovukComponentsHelper
9
9
  govuk_header: 'GovukComponent::HeaderComponent',
10
10
  govuk_inset_text: 'GovukComponent::InsetTextComponent',
11
11
  govuk_notification_banner: 'GovukComponent::NotificationBannerComponent',
12
+ govuk_pagination: 'GovukComponent::PaginationComponent',
12
13
  govuk_panel: 'GovukComponent::PanelComponent',
13
14
  govuk_phase_banner: 'GovukComponent::PhaseBannerComponent',
14
15
  govuk_section_break: 'GovukComponent::SectionBreakComponent',
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '3.0.5'.freeze
3
+ VERSION = '3.1.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DfE developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: activemodel
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +58,34 @@ dependencies:
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 0.9.0
61
+ version: '0.9'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.9.2
48
65
  type: :runtime
49
66
  prerelease: false
50
67
  version_requirements: !ruby/object:Gem::Requirement
51
68
  requirements:
52
69
  - - "~>"
53
70
  - !ruby/object:Gem::Version
54
- version: 0.9.0
71
+ version: '0.9'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.9.2
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: view_component
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: 2.49.1
81
+ version: 2.56.2
62
82
  type: :runtime
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
- version: 2.49.1
88
+ version: 2.56.2
69
89
  - !ruby/object:Gem::Dependency
70
90
  name: deep_merge
71
91
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +226,20 @@ dependencies:
206
226
  - - "~>"
207
227
  - !ruby/object:Gem::Version
208
228
  version: '4.11'
229
+ - !ruby/object:Gem::Dependency
230
+ name: pagy
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: 5.10.1
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: 5.10.1
209
243
  - !ruby/object:Gem::Dependency
210
244
  name: redcarpet
211
245
  requirement: !ruby/object:Gem::Requirement
@@ -348,6 +382,11 @@ files:
348
382
  - app/components/govuk_component/inset_text_component.rb
349
383
  - app/components/govuk_component/notification_banner_component.html.erb
350
384
  - app/components/govuk_component/notification_banner_component.rb
385
+ - app/components/govuk_component/pagination_component.rb
386
+ - app/components/govuk_component/pagination_component/adjacent_page.rb
387
+ - app/components/govuk_component/pagination_component/item.rb
388
+ - app/components/govuk_component/pagination_component/next_page.rb
389
+ - app/components/govuk_component/pagination_component/previous_page.rb
351
390
  - app/components/govuk_component/panel_component.rb
352
391
  - app/components/govuk_component/phase_banner_component.html.erb
353
392
  - app/components/govuk_component/phase_banner_component.rb
@@ -373,7 +412,6 @@ files:
373
412
  - app/components/govuk_component/table_component/row_component.rb
374
413
  - app/components/govuk_component/tag_component.rb
375
414
  - app/components/govuk_component/traits.rb
376
- - app/components/govuk_component/traits/custom_classes.rb
377
415
  - app/components/govuk_component/traits/custom_html_attributes.rb
378
416
  - app/components/govuk_component/warning_text_component.rb
379
417
  - app/helpers/govuk_back_to_top_link_helper.rb
@@ -1,4 +0,0 @@
1
- module GovukComponent
2
- module Traits
3
- end
4
- end