govuk-components 2.0.0b3 → 2.0.0b4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6865ba0192a8b3b74dbf3606bdb5c223f6e8ccd200257779d4e55516e07765a5
4
- data.tar.gz: a97b96623bc61a2ed3a1d1cd18b65c7e5a77ac0070fd65d22bd2d35f5763f68b
3
+ metadata.gz: adc43cd112d0d674ac3780c1b8d82b73085994b4d94d4637b555309c35339f3f
4
+ data.tar.gz: c48babb1d6c848ce088a4677021dfdf6b85e99381de187856db129f3256026c1
5
5
  SHA512:
6
- metadata.gz: 7382fc831161df5683e09d30f7f8e296f6019fd6137e476556e9f0056a45c644cade8f66db02ef05c57984a977a3bd82d53781259612cb4513b1a30290e495e3
7
- data.tar.gz: 7961d834d1c290a9bd3ac4b79b145013b943eb4ada59f983ebb20461e692aedfd1944130f194ca4a65f041aeb938dcd629e751f42573e84d7a6980be521153e5
6
+ metadata.gz: c8d079f362768501769be70a9ab9e18664b995f32a36693b1b7f6be230c4394d61a006255703f467fd7d80b190976690f1268ca303914e1c6155bc9e2f56ab4b
7
+ data.tar.gz: ffee587ebba53cdde8399c898a34cf0def0d7d43327153300972afd6a0e6c4e08fdf64bfb3bda90b178152ab0f71f50daca9532f33542dc5654d80a259ca99c6
@@ -1,7 +1,7 @@
1
1
  class GovukComponent::AccordionComponent < GovukComponent::Base
2
2
  renders_many :sections, "Section"
3
3
 
4
- attr_accessor :id
4
+ attr_reader :id
5
5
 
6
6
  def initialize(id: nil, classes: [], html_attributes: {})
7
7
  super(classes: classes, html_attributes: html_attributes)
@@ -16,26 +16,22 @@ private
16
16
  end
17
17
 
18
18
  class Section < GovukComponent::Base
19
- attr_accessor :title, :summary, :expanded
19
+ attr_reader :title, :summary, :expanded
20
20
 
21
21
  alias_method :expanded?, :expanded
22
22
 
23
23
  def initialize(title:, summary: nil, expanded: false, classes: [], html_attributes: {})
24
24
  super(classes: classes, html_attributes: html_attributes)
25
25
 
26
- self.title = title
27
- self.summary = summary
28
- self.expanded = expanded
26
+ @title = title
27
+ @summary = summary
28
+ @expanded = expanded
29
29
  end
30
30
 
31
31
  def id(suffix: nil)
32
32
  [title.parameterize, suffix].compact.join('-')
33
33
  end
34
34
 
35
- def classes
36
- super + (expanded? ? %w(govuk-accordion__section--expanded) : [])
37
- end
38
-
39
35
  def call
40
36
  tag.div(content, id: id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: id })
41
37
  end
@@ -43,7 +39,9 @@ private
43
39
  private
44
40
 
45
41
  def default_classes
46
- %w(govuk-accordion__section)
42
+ %w(govuk-accordion__section).tap do |classes|
43
+ classes.append("govuk-accordion__section--expanded") if expanded?
44
+ end
47
45
  end
48
46
  end
49
47
  end
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::BackLinkComponent < GovukComponent::Base
2
- attr_accessor :text, :href, :options
2
+ attr_reader :text, :href, :options
3
3
 
4
4
  def initialize(text:, href:, classes: nil, html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -9,7 +9,7 @@ class GovukComponent::BackLinkComponent < GovukComponent::Base
9
9
  end
10
10
 
11
11
  def call
12
- link_to(@text, @href, class: classes, **html_attributes)
12
+ link_to(text, href, class: classes, **html_attributes)
13
13
  end
14
14
 
15
15
  private
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::BreadcrumbsComponent < GovukComponent::Base
2
- attr_accessor :breadcrumbs
2
+ attr_reader :breadcrumbs, :hide_in_print, :collapse_on_mobile
3
3
 
4
4
  def initialize(breadcrumbs:, hide_in_print: false, collapse_on_mobile: false, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -13,8 +13,8 @@ private
13
13
 
14
14
  def default_classes
15
15
  %w(govuk-breadcrumbs).tap do |classes|
16
- classes << "govuk-!-display-none-print" if @hide_in_print
17
- classes << "govuk-breadcrumbs--collapse-on-mobile" if @collapse_on_mobile
16
+ classes << "govuk-!-display-none-print" if hide_in_print
17
+ classes << "govuk-breadcrumbs--collapse-on-mobile" if collapse_on_mobile
18
18
  end
19
19
  end
20
20
  end
@@ -1,5 +1,7 @@
1
1
  class GovukComponent::DetailsComponent < GovukComponent::Base
2
- attr_accessor :summary_text, :text
2
+ attr_reader :summary_text, :text
3
+
4
+ renders_one :summary_html
3
5
 
4
6
  def initialize(summary_text:, text: nil, classes: [], html_attributes: {})
5
7
  super(classes: classes, html_attributes: html_attributes)
@@ -18,10 +20,14 @@ private
18
20
 
19
21
  def summary
20
22
  tag.summary(class: "govuk-details__summary") do
21
- tag.span(summary_text, class: "govuk-details__summary-text")
23
+ tag.span(summary_content, class: "govuk-details__summary-text")
22
24
  end
23
25
  end
24
26
 
27
+ def summary_content
28
+ summary_html || summary_text
29
+ end
30
+
25
31
  def description
26
32
  tag.div(class: "govuk-details__text") do
27
33
  content.presence || text
@@ -2,7 +2,7 @@ class GovukComponent::FooterComponent < GovukComponent::Base
2
2
  renders_one :meta_content
3
3
  renders_one :meta
4
4
 
5
- attr_accessor :meta_items, :meta_items_title, :meta_licence, :copyright
5
+ attr_reader :meta_items, :meta_items_title, :meta_licence, :copyright
6
6
 
7
7
  def initialize(meta_items: {}, meta_items_title: "Support links", meta_licence: nil, classes: [], html_attributes: {}, copyright_text: default_copright_text, copyright_url: default_copyright_url)
8
8
  super(classes: classes, html_attributes: html_attributes)
@@ -34,9 +34,9 @@
34
34
  <% items.each do |item| %>
35
35
  <%= tag.li(class: item.classes.append(item.active_class), **item.html_attributes) do %>
36
36
  <% if item.link? %>
37
- <%= link_to(item.title, item.href, class: "govuk-header__link") %>
37
+ <%= link_to(item.text, item.href, class: "govuk-header__link") %>
38
38
  <% else %>
39
- <%= item.title %>
39
+ <%= item.text %>
40
40
  <% end %>
41
41
  <% end %>
42
42
  <% end %>
@@ -3,13 +3,15 @@ class GovukComponent::HeaderComponent < GovukComponent::Base
3
3
  renders_one :custom_logo
4
4
  renders_one :product_name, "ProductName"
5
5
 
6
- attr_accessor :logotype,
7
- :crown,
8
- :homepage_url,
9
- :service_name,
10
- :service_url,
11
- :menu_button_label,
12
- :navigation_label
6
+ attr_reader :logotype,
7
+ :crown,
8
+ :homepage_url,
9
+ :service_name,
10
+ :service_url,
11
+ :menu_button_label,
12
+ :navigation_label,
13
+ :custom_navigation_classes,
14
+ :custom_container_classes
13
15
 
14
16
  def initialize(classes: [],
15
17
  html_attributes: {},
@@ -25,15 +27,15 @@ class GovukComponent::HeaderComponent < GovukComponent::Base
25
27
 
26
28
  super(classes: classes, html_attributes: html_attributes)
27
29
 
28
- @logotype = logotype
29
- @crown = crown
30
- @homepage_url = homepage_url
31
- @service_name = service_name
32
- @service_url = service_url
33
- @menu_button_label = menu_button_label
34
- @navigation_classes = navigation_classes
35
- @navigation_label = navigation_label
36
- @container_classes = container_classes
30
+ @logotype = logotype
31
+ @crown = crown
32
+ @homepage_url = homepage_url
33
+ @service_name = service_name
34
+ @service_url = service_url
35
+ @menu_button_label = menu_button_label
36
+ @custom_navigation_classes = navigation_classes
37
+ @navigation_label = navigation_label
38
+ @custom_container_classes = container_classes
37
39
  end
38
40
 
39
41
  private
@@ -43,22 +45,22 @@ private
43
45
  end
44
46
 
45
47
  def navigation_classes
46
- combine_classes(%w(govuk-header__navigation), @navigation_classes)
48
+ combine_classes(%w(govuk-header__navigation), custom_navigation_classes)
47
49
  end
48
50
 
49
51
  def container_classes
50
- combine_classes(%w(govuk-header__container govuk-width-container), @container_classes)
52
+ combine_classes(%w(govuk-header__container govuk-width-container), custom_container_classes)
51
53
  end
52
54
 
53
55
  class Item < GovukComponent::Base
54
- attr_accessor :title, :href, :active
56
+ attr_reader :text, :href, :active
55
57
 
56
- def initialize(title:, href: nil, active: false, classes: [], html_attributes: {})
58
+ def initialize(text:, href: nil, active: false, classes: [], html_attributes: {})
57
59
  super(classes: classes, html_attributes: html_attributes)
58
60
 
59
- self.title = title
60
- self.href = href
61
- self.active = active
61
+ @text = text
62
+ @href = href
63
+ @active = active
62
64
  end
63
65
 
64
66
  def active?
@@ -81,7 +83,7 @@ private
81
83
  end
82
84
 
83
85
  class ProductName < GovukComponent::Base
84
- attr_accessor :name
86
+ attr_reader :name
85
87
 
86
88
  def initialize(name: nil, html_attributes: {}, classes: [])
87
89
  super(classes: classes, html_attributes: html_attributes)
@@ -90,14 +92,14 @@ private
90
92
  end
91
93
 
92
94
  def render?
93
- @name.present? || content.present?
95
+ name.present? || content.present?
94
96
  end
95
97
 
96
98
  def call
97
99
  if content.present?
98
100
  tag.div(content, class: classes)
99
101
  else
100
- tag.span(@name, class: classes)
102
+ tag.span(name, class: classes)
101
103
  end
102
104
  end
103
105
 
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::InsetTextComponent < GovukComponent::Base
2
- attr_accessor :text
2
+ attr_reader :text
3
3
 
4
4
  def initialize(text: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -32,20 +32,20 @@ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
32
32
  end
33
33
 
34
34
  class Heading < GovukComponent::Base
35
- attr_accessor :text, :link_href, :link_text
35
+ attr_reader :text, :link_href, :link_text
36
36
 
37
37
  def initialize(text: nil, link_text: nil, link_href: nil, classes: [], html_attributes: {})
38
38
  super(classes: classes, html_attributes: html_attributes)
39
39
 
40
- @text = text
41
- @link_text = link_text
42
- @link_href = link_href
40
+ @text = text
41
+ @link_text = link_text
42
+ @link_href = link_href
43
43
  end
44
44
 
45
45
  def call
46
46
  tag.div(class: classes, **html_attributes) do
47
47
  if text.present?
48
- safe_join([text, link].compact)
48
+ safe_join([text, link].compact, " ")
49
49
  else
50
50
  content
51
51
  end
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::PanelComponent < GovukComponent::Base
2
- attr_accessor :title, :body
2
+ attr_reader :title, :body
3
3
 
4
4
  def initialize(title: nil, body: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -35,7 +35,7 @@ private
35
35
  def panel_body
36
36
  if display_body?
37
37
  tag.div(class: "govuk-panel__body") do
38
- content.presence || @body
38
+ content.presence || body
39
39
  end
40
40
  end
41
41
  end
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::PhaseBannerComponent < GovukComponent::Base
2
- attr_accessor :text
2
+ attr_reader :text, :phase_tag
3
3
 
4
4
  def initialize(phase_tag: nil, text: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -9,7 +9,7 @@ class GovukComponent::PhaseBannerComponent < GovukComponent::Base
9
9
  end
10
10
 
11
11
  def phase_tag_component
12
- GovukComponent::TagComponent.new(classes: "govuk-phase-banner__content__tag", **@phase_tag)
12
+ GovukComponent::TagComponent.new(classes: "govuk-phase-banner__content__tag", **phase_tag)
13
13
  end
14
14
 
15
15
  private
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::StartButtonComponent < GovukComponent::Base
2
- attr_accessor :text, :href
2
+ attr_reader :text, :href
3
3
 
4
4
  def initialize(text:, href:, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -9,8 +9,8 @@ class GovukComponent::StartButtonComponent < GovukComponent::Base
9
9
  end
10
10
 
11
11
  def call
12
- link_to(@href, **default_attributes, **html_attributes) do
13
- safe_join([@text, icon])
12
+ link_to(href, **default_attributes, **html_attributes) do
13
+ safe_join([text, icon])
14
14
  end
15
15
  end
16
16
 
@@ -33,13 +33,16 @@ private
33
33
  def initialize(key:, value:, action: {}, classes: [], html_attributes: {})
34
34
  super(classes: classes, html_attributes: html_attributes)
35
35
 
36
- @key = key
37
- @value = value
38
- @href = action[:href]
39
- @text = action[:text] || "Change"
40
- @visually_hidden_text = " #{action[:visually_hidden_text] || key.downcase}"
41
- @action_classes = action[:classes] || []
42
- @action_attributes = action[:html_attributes] || {}
36
+ @key = key
37
+ @value = value
38
+
39
+ if action.present?
40
+ @href = action[:href]
41
+ @text = action[:text] || "Change"
42
+ @visually_hidden_text = " #{action[:visually_hidden_text] || key.downcase}"
43
+ @action_classes = action[:classes] || []
44
+ @action_attributes = action[:html_attributes] || {}
45
+ end
43
46
  end
44
47
 
45
48
  def action
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::TagComponent < GovukComponent::Base
2
- attr_reader :text
2
+ attr_reader :text, :colour
3
3
 
4
4
  COLOURS = %w(
5
5
  grey
@@ -31,11 +31,11 @@ private
31
31
  end
32
32
 
33
33
  def colour_class
34
- return nil if @colour.blank?
34
+ return nil if colour.blank?
35
35
 
36
36
  fail(ArgumentError, colour_error_message) unless valid_colour?
37
37
 
38
- %(govuk-tag--#{@colour})
38
+ %(govuk-tag--#{colour})
39
39
  end
40
40
 
41
41
  def valid_colour?
@@ -43,6 +43,6 @@ private
43
43
  end
44
44
 
45
45
  def colour_error_message
46
- "invalid tag colour #{@colour}, supported colours are #{COLOURS.to_sentence}"
46
+ "invalid tag colour #{colour}, supported colours are #{COLOURS.to_sentence}"
47
47
  end
48
48
  end
@@ -12,7 +12,7 @@ class GovukComponent::WarningTextComponent < GovukComponent::Base
12
12
 
13
13
  def call
14
14
  tag.div(class: classes, **html_attributes) do
15
- safe_join([icon, strong])
15
+ safe_join([icon, (content || strong)])
16
16
  end
17
17
  end
18
18
 
@@ -1,10 +1,14 @@
1
1
  module GovukLinkHelper
2
- def govuk_link_to(*args, button: false, **kwargs, &block)
3
- link_to(*args, **inject_class(kwargs, class_name: link_class(button)), &block)
2
+ def govuk_link_to(*args, button: false, no_visited_state: false, muted: false, text_colour: false, inverse: false, no_underline: false, **kwargs, &block)
3
+ classes = build_classes(button, no_visited_state, muted, text_colour, inverse, no_underline)
4
+
5
+ link_to(*args, **inject_class(kwargs, class_name: classes), &block)
4
6
  end
5
7
 
6
- def govuk_mail_to(*args, button: false, **kwargs, &block)
7
- mail_to(*args, **inject_class(kwargs, class_name: link_class(button)), &block)
8
+ def govuk_mail_to(*args, button: false, no_visited_state: false, muted: false, text_colour: false, inverse: false, no_underline: false, **kwargs, &block)
9
+ classes = build_classes(button, no_visited_state, muted, text_colour, inverse, no_underline)
10
+
11
+ mail_to(*args, **inject_class(kwargs, class_name: classes), &block)
8
12
  end
9
13
 
10
14
  def govuk_button_to(*args, **kwargs)
@@ -13,6 +17,17 @@ module GovukLinkHelper
13
17
 
14
18
  private
15
19
 
20
+ def build_classes(button, no_visited_state, muted, text_colour, inverse, no_underline)
21
+ [
22
+ link_class(button),
23
+ no_visited_state_class(no_visited_state),
24
+ muted_class(muted),
25
+ text_colour_class(text_colour),
26
+ inverse_class(inverse),
27
+ no_underline_class(no_underline),
28
+ ]
29
+ end
30
+
16
31
  def inject_class(attributes, class_name:)
17
32
  attributes.with_indifferent_access.tap do |attrs|
18
33
  attrs[:class] = Array.wrap(attrs[:class]).prepend(class_name)
@@ -22,6 +37,26 @@ private
22
37
  def link_class(button)
23
38
  button ? 'govuk-button' : 'govuk-link'
24
39
  end
40
+
41
+ def no_visited_state_class(no_visited_state)
42
+ 'govuk-link--no-visited-state' if no_visited_state
43
+ end
44
+
45
+ def muted_class(muted)
46
+ 'govuk-link--muted' if muted
47
+ end
48
+
49
+ def text_colour_class(colour)
50
+ 'govuk-link--text-colour' if colour
51
+ end
52
+
53
+ def inverse_class(inverse)
54
+ 'govuk-link--inverse' if inverse
55
+ end
56
+
57
+ def no_underline_class(no_underline)
58
+ 'govuk-link--no-underline' if no_underline
59
+ end
25
60
  end
26
61
 
27
62
  ActiveSupport.on_load(:action_view) { include GovukLinkHelper }
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '2.0.0b3'.freeze
3
+ VERSION = '2.0.0b4'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0b3
4
+ version: 2.0.0b4
5
5
  platform: ruby
6
6
  authors:
7
7
  - DfE developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-08 00:00:00.000000000 Z
11
+ date: 2021-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.31.1
55
- - !ruby/object:Gem::Dependency
56
- name: capybara
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: pry-byebug
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +100,14 @@ dependencies:
114
100
  requirements:
115
101
  - - '='
116
102
  - !ruby/object:Gem::Version
117
- version: 4.0.0.pre.1
103
+ version: 4.0.0
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - '='
123
109
  - !ruby/object:Gem::Version
124
- version: 4.0.0.pre.1
110
+ version: 4.0.0
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: sassc-rails
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -194,7 +180,6 @@ files:
194
180
  - app/components/govuk_component/panel_component.rb
195
181
  - app/components/govuk_component/phase_banner_component.html.erb
196
182
  - app/components/govuk_component/phase_banner_component.rb
197
- - app/components/govuk_component/slot.rb
198
183
  - app/components/govuk_component/start_button_component.rb
199
184
  - app/components/govuk_component/summary_list_component.html.erb
200
185
  - app/components/govuk_component/summary_list_component.rb
@@ -218,7 +203,7 @@ homepage: https://github.com/DFE-Digital/govuk-components
218
203
  licenses:
219
204
  - MIT
220
205
  metadata: {}
221
- post_install_message:
206
+ post_install_message:
222
207
  rdoc_options: []
223
208
  require_paths:
224
209
  - lib
@@ -233,8 +218,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
218
  - !ruby/object:Gem::Version
234
219
  version: 1.3.1
235
220
  requirements: []
236
- rubygems_version: 3.1.4
237
- signing_key:
221
+ rubygems_version: 3.1.6
222
+ signing_key:
238
223
  specification_version: 4
239
224
  summary: Lightweight set of reusable GOV.UK Design System components
240
225
  test_files: []
@@ -1,9 +0,0 @@
1
- class GovukComponent::Slot < ViewComponent::Slot
2
- include GovukComponent::Traits::CustomClasses
3
- include GovukComponent::Traits::CustomHtmlAttributes
4
-
5
- def initialize(classes: [], html_attributes: {})
6
- @classes = parse_classes(classes)
7
- @html_attributes = html_attributes
8
- end
9
- end