govuk_publishing_components 20.4.0 → 20.5.0

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: be9c34e0c68a4a32acc65f384dd54ac57e84773a5fc4099bdd9c12d20eedbbdd
4
- data.tar.gz: e6fcf672363a3b0feee426acc8135e65948802b9dc983d9c8b2eb44a8624b228
3
+ metadata.gz: edb735f60baaa578cdab6eb211bc872cd96ad7ee67c70f4905ae8ece490e389b
4
+ data.tar.gz: a6e7d541c2e4808d5e300045ed049f8796dc3841c5054929750532df473e2dbc
5
5
  SHA512:
6
- metadata.gz: b56ee33a9621f7e751f113b61505dcadc0590a284374b3af27d33ba0a6d5aea313ed012a64ae156edef9297e7f0a54265da6ce79543ab712b8b3d7bcae4841f2
7
- data.tar.gz: 90b2345ffb9bf05079648ef713fbcac8a18899d7cdc361d58c0b4fcad852a91d8d75bfd44c0bf09e19e5f8c3fab454fbf2c26392668e6cad9579e670baa360f7
6
+ metadata.gz: 305ad429e9948e5d059379290532eb4f2bda6aaea82d1b06305151f897e16730ea94b6dfacb4d410c4c1f5e64ef5bcf53f0fce300fb1aeb7e691cede9a22b21a
7
+ data.tar.gz: a9cbbecf9101e75b8f04342f65b2a1f16a4f84c6f6b35bc3371d8f0902af99c98446fe574f49cc42c38afd8f5012e8b414c87afad603244237c7acb55cd8240c
@@ -10,6 +10,16 @@
10
10
  box-shadow: 0 20px 15px -10px govuk-colour("white");
11
11
  }
12
12
 
13
+ .gem-c-contents-list--font-size-19 .gem-c-contents-list__title,
14
+ .gem-c-contents-list--font-size-19 .gem-c-contents-list__list {
15
+ @include govuk-font($size: 19, $line-height: 1.5);
16
+ }
17
+
18
+ .gem-c-contents-list--font-size-24 .gem-c-contents-list__title,
19
+ .gem-c-contents-list--font-size-24 .gem-c-contents-list__list {
20
+ @include govuk-font($size: 24, $line-height: 1.5);
21
+ }
22
+
13
23
  .gem-c-contents-list__title {
14
24
  @include govuk-text-colour;
15
25
  @include govuk-font($size: 16, $weight: regular, $line-height: 1.5);
@@ -1,47 +1,35 @@
1
- <%
2
- cl_helper = GovukPublishingComponents::Presenters::ContentsListHelper.new
1
+ <%-
2
+ cl_helper = GovukPublishingComponents::Presenters::ContentsListHelper.new(local_assigns)
3
+ aria_label ||= nil
3
4
  format_numbers ||= false
4
- underline_links ||= false
5
- contents ||= []
6
- aria_label ||= ''
7
- nested = !!contents.find { |c| c[:items] && c[:items].any? }
8
- parent_list_item_modifier = if nested
9
- 'parent'
10
- elsif format_numbers
11
- 'numbered'
12
- else
13
- 'dashed'
14
- end
5
+ hide_title ||= false
6
+
15
7
  brand ||= false
16
8
  brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand)
17
- hide_title ||= false
18
- %>
19
- <% if contents.any? %>
20
- <nav
21
- role="navigation"
22
- class="gem-c-contents-list <%= 'gem-c-contents-list--no-underline' unless underline_links %> <%= brand_helper.brand_class %>"
23
- data-module="track-click"
24
- <% if aria_label.present? %>
25
- aria-label="<%= aria_label %>"
26
- <% end %>
27
- >
9
+
10
+ classes = cl_helper.classes
11
+ classes << brand_helper.brand_class
12
+ -%>
13
+ <% if cl_helper.contents.any? %>
14
+ <%= content_tag(
15
+ :nav,
16
+ class: classes,
17
+ "aria-label": aria_label,
18
+ role: "navigation",
19
+ data: {
20
+ module: "track-click"
21
+ }
22
+ ) do %>
28
23
  <% unless hide_title %>
29
24
  <h2 class="gem-c-contents-list__title"><%= t("components.contents_list.contents") %></h2>
30
25
  <% end %>
31
26
 
32
27
  <ol class="gem-c-contents-list__list">
33
28
  <% contents.each.with_index(1) do |contents_item, position| %>
34
- <%
35
- active_class = "gem-c-contents-list__list-item--active" if contents_item[:active]
36
- aria_current = "aria-current = true" if contents_item[:active]
37
- %>
38
- <li
39
- class="gem-c-contents-list__list-item gem-c-contents-list__list-item--<%= parent_list_item_modifier %> <%= active_class %>"
40
- <%= aria_current %>
41
- >
29
+ <li class="<%= cl_helper.list_item_classes(contents_item, false) %>" <%= "aria-current=true" if contents_item[:active] %>>
42
30
  <% link_text = format_numbers ? cl_helper.wrap_numbers_with_spans(contents_item[:text]) : contents_item[:text] %>
43
31
  <%= link_to_if !contents_item[:active], link_text, contents_item[:href],
44
- class: "gem-c-contents-list__link #{brand_helper.color_class}",
32
+ class: "gem-c-contents-list__link govuk-link #{brand_helper.color_class}",
45
33
  data: {
46
34
  track_category: 'contentsClicked',
47
35
  track_action: "content_item #{position}",
@@ -51,19 +39,13 @@
51
39
  }
52
40
  }
53
41
  %>
42
+
54
43
  <% if contents_item[:items] && contents_item[:items].any? %>
55
44
  <ol class="gem-c-contents-list__nested-list">
56
45
  <% contents_item[:items].each.with_index(1) do |nested_contents_item, nested_position| %>
57
- <%
58
- active_class = "gem-c-contents-list__list-item--active" if nested_contents_item[:active]
59
- aria_current = "aria-current = true" if nested_contents_item[:active]
60
- %>
61
- <li
62
- class="gem-c-contents-list__list-item gem-c-contents-list__list-item--dashed <%= active_class %>"
63
- <%= aria_current %>
64
- >
46
+ <li class="<%= cl_helper.list_item_classes(nested_contents_item, true) %>" <%= "aria-current=true" if nested_contents_item[:active] %>>
65
47
  <%= link_to_if !nested_contents_item[:active], nested_contents_item[:text], nested_contents_item[:href],
66
- class: "gem-c-contents-list__link #{brand_helper.color_class}",
48
+ class: "gem-c-contents-list__link govuk-link #{brand_helper.color_class}",
67
49
  data: {
68
50
  track_category: 'contentsClicked',
69
51
  track_action: "nested_content_item #{position}:#{nested_position}",
@@ -76,9 +58,9 @@
76
58
  </li>
77
59
  <% end %>
78
60
  </ol>
79
- <% end %>
61
+ <% end %>
80
62
  </li>
81
63
  <% end %>
82
64
  </ol>
83
- </nav>
65
+ <% end %>
84
66
  <% end %>
@@ -1,10 +1,15 @@
1
1
  <%
2
2
  text ||= ""
3
3
  inverse ||= false
4
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
5
+
6
+ custom_margin_bottom_class = shared_helper.get_margin_bottom if [*0..9].include?(local_assigns[:margin_bottom])
7
+
8
+ classes = %w(gem-c-lead-paragraph)
9
+ classes << "gem-c-lead-paragraph--inverse" if inverse
10
+ classes << custom_margin_bottom_class if local_assigns[:margin_bottom]
4
11
  %>
5
12
 
6
13
  <% if text.present? %>
7
- <p class="gem-c-lead-paragraph <% if inverse %>gem-c-lead-paragraph--inverse<% end %>">
8
- <%= text %>
9
- </p>
14
+ <%= content_tag :p, text, class: classes %>
10
15
  <% end %>
@@ -215,3 +215,14 @@ examples:
215
215
  text: Guidance and regulation
216
216
  - href: "#third-thing"
217
217
  text: Consultations
218
+ with_different_font_size:
219
+ description: Choose a different font size. Valid options are 24 (24px) and 19 (19px), with the component defaulting to 16px.
220
+ data:
221
+ font_size: 24
222
+ contents:
223
+ - href: "#first-thing"
224
+ text: Community best practice
225
+ - href: "#second-thing"
226
+ text: Guidance and regulation
227
+ - href: "#third-thing"
228
+ text: Consultations
@@ -20,3 +20,8 @@ examples:
20
20
  inverse: true
21
21
  context:
22
22
  dark_background: true
23
+ custom_margin_bottom:
24
+ description: The component accepts a number for margin bottom from 0 to 9 (0px to 60px) using the [GOV.UK Frontend spacing scale](https://design-system.service.gov.uk/styles/spacing/#the-responsive-spacing-scale). It defaults to having a margin bottom of 45px.
25
+ data:
26
+ text: This is some example text for a lead paragraph
27
+ margin_bottom: 6
@@ -5,6 +5,28 @@ module GovukPublishingComponents
5
5
  class ContentsListHelper
6
6
  include ActionView::Helpers::SanitizeHelper
7
7
 
8
+ attr_reader :classes, :contents
9
+
10
+ def initialize(options)
11
+ @contents = options[:contents] || []
12
+ @nested = !!@contents.find { |c| c[:items] && c[:items].any? }
13
+ @format_numbers = options[:format_numbers]
14
+ @font_size = options[:font_size]
15
+
16
+ @classes = %w(gem-c-contents-list)
17
+ @classes << " gem-c-contents-list--no-underline" unless options[:underline_links]
18
+ @classes << " gem-c-contents-list--font-size-#{@font_size}" if [24, 19].include? @font_size
19
+ end
20
+
21
+ def list_item_classes(list_item, nested)
22
+ list_item_classes = "gem-c-contents-list__list-item"
23
+ list_item_classes << " gem-c-contents-list__list-item--#{parent_modifier}" unless nested
24
+ list_item_classes << " gem-c-contents-list__list-item--dashed" if nested
25
+ list_item_classes << " gem-c-contents-list__list-item--active" if list_item[:active]
26
+
27
+ list_item_classes
28
+ end
29
+
8
30
  def wrap_numbers_with_spans(content_item_link)
9
31
  content_item_text = strip_tags(content_item_link) #just the text of the link
10
32
 
@@ -22,6 +44,18 @@ module GovukPublishingComponents
22
44
  content_item_link
23
45
  end
24
46
  end
47
+
48
+ private
49
+
50
+ def parent_modifier
51
+ if @nested
52
+ 'parent'
53
+ elsif @format_numbers
54
+ 'numbered'
55
+ else
56
+ 'dashed'
57
+ end
58
+ end
25
59
  end
26
60
  end
27
61
  end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = '20.4.0'.freeze
2
+ VERSION = '20.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 20.4.0
4
+ version: 20.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gds-api-adapters