govuk-components 1.1.9 → 2.0.0b4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/app/components/govuk_component/{accordion.html.erb → accordion_component.html.erb} +2 -2
- data/app/components/govuk_component/{accordion.rb → accordion_component.rb} +13 -14
- data/app/components/govuk_component/{back_link.rb → back_link_component.rb} +6 -2
- data/app/components/govuk_component/base.rb +9 -7
- data/app/components/govuk_component/{breadcrumbs.html.erb → breadcrumbs_component.html.erb} +3 -6
- data/app/components/govuk_component/{breadcrumbs.rb → breadcrumbs_component.rb} +4 -4
- data/app/components/govuk_component/{cookie_banner.html.erb → cookie_banner_component.html.erb} +2 -6
- data/app/components/govuk_component/{cookie_banner.rb → cookie_banner_component.rb} +1 -1
- data/app/components/govuk_component/details_component.rb +40 -0
- data/app/components/govuk_component/{footer.html.erb → footer_component.html.erb} +3 -5
- data/app/components/govuk_component/{footer.rb → footer_component.rb} +4 -9
- data/app/components/govuk_component/header_component.html.erb +49 -0
- data/app/components/govuk_component/header_component.rb +112 -0
- data/app/components/govuk_component/{inset_text.rb → inset_text_component.rb} +4 -4
- data/app/components/govuk_component/notification_banner_component.html.erb +14 -0
- data/app/components/govuk_component/{notification_banner.rb → notification_banner_component.rb} +30 -16
- data/app/components/govuk_component/panel_component.rb +46 -0
- data/app/components/govuk_component/phase_banner_component.html.erb +6 -0
- data/app/components/govuk_component/phase_banner_component.rb +20 -0
- data/app/components/govuk_component/start_button_component.rb +47 -0
- data/app/components/govuk_component/summary_list_component.html.erb +11 -0
- data/app/components/govuk_component/summary_list_component.rb +64 -0
- data/app/components/govuk_component/tab_component.html.erb +11 -0
- data/app/components/govuk_component/{tabs.rb → tab_component.rb} +23 -12
- data/app/components/govuk_component/tag_component.rb +48 -0
- data/app/components/govuk_component/warning_text_component.rb +38 -0
- data/app/helpers/govuk_components_helper.rb +16 -16
- data/app/helpers/govuk_link_helper.rb +39 -4
- data/lib/govuk/components.rb +1 -0
- data/lib/govuk/components/helpers/css_utilities.rb +22 -0
- data/lib/govuk/components/version.rb +1 -1
- metadata +48 -53
- data/app/components/govuk_component/back_link.html.erb +0 -1
- data/app/components/govuk_component/details.html.erb +0 -10
- data/app/components/govuk_component/details.rb +0 -16
- data/app/components/govuk_component/header.html.erb +0 -52
- data/app/components/govuk_component/header.rb +0 -65
- data/app/components/govuk_component/notification_banner.html.erb +0 -23
- data/app/components/govuk_component/panel.html.erb +0 -13
- data/app/components/govuk_component/panel.rb +0 -28
- data/app/components/govuk_component/phase_banner.html.erb +0 -8
- data/app/components/govuk_component/phase_banner.rb +0 -16
- data/app/components/govuk_component/slot.rb +0 -9
- data/app/components/govuk_component/start_now_button.html.erb +0 -6
- data/app/components/govuk_component/start_now_button.rb +0 -16
- data/app/components/govuk_component/summary_list.html.erb +0 -19
- data/app/components/govuk_component/summary_list.rb +0 -34
- data/app/components/govuk_component/tabs.html.erb +0 -19
- data/app/components/govuk_component/tag.rb +0 -30
- data/app/components/govuk_component/warning.html.erb +0 -7
- data/app/components/govuk_component/warning.rb +0 -14
@@ -1,5 +1,5 @@
|
|
1
|
-
class GovukComponent::
|
2
|
-
|
1
|
+
class GovukComponent::InsetTextComponent < GovukComponent::Base
|
2
|
+
attr_reader :text
|
3
3
|
|
4
4
|
def initialize(text: nil, classes: [], html_attributes: {})
|
5
5
|
super(classes: classes, html_attributes: html_attributes)
|
@@ -8,11 +8,11 @@ class GovukComponent::InsetText < GovukComponent::Base
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call
|
11
|
-
tag.div(class: classes, **html_attributes) { content.presence ||
|
11
|
+
tag.div(class: classes, **html_attributes) { content.presence || text }
|
12
12
|
end
|
13
13
|
|
14
14
|
def render?
|
15
|
-
|
15
|
+
text.present? || content.present?
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%= tag.div(class: classes, role: "region", aria: { labelledby: title_id }, data: data_params, **html_attributes) do %>
|
2
|
+
<div class="govuk-notification-banner__header">
|
3
|
+
<%= content_tag(title_tag, class: "govuk-notification-banner__title", id: title_id) do %>
|
4
|
+
<%= title %>
|
5
|
+
<% end %>
|
6
|
+
</div>
|
7
|
+
<div class="govuk-notification-banner__content">
|
8
|
+
<% headings.each do |heading| %>
|
9
|
+
<%= heading %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= content %>
|
13
|
+
</div>
|
14
|
+
<% end %>
|
data/app/components/govuk_component/{notification_banner.rb → notification_banner_component.rb}
RENAMED
@@ -1,9 +1,7 @@
|
|
1
|
-
class GovukComponent::
|
1
|
+
class GovukComponent::NotificationBannerComponent < GovukComponent::Base
|
2
2
|
attr_reader :title, :title_id, :success, :title_heading_level, :disable_auto_focus
|
3
3
|
|
4
|
-
|
5
|
-
with_slot :heading, collection: true, class_name: 'Heading'
|
6
|
-
wrap_slot(:heading)
|
4
|
+
renders_many :headings, "Heading"
|
7
5
|
|
8
6
|
def initialize(title:, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
|
9
7
|
super(classes: classes, html_attributes: html_attributes)
|
@@ -15,16 +13,16 @@ class GovukComponent::NotificationBanner < GovukComponent::Base
|
|
15
13
|
@disable_auto_focus = disable_auto_focus
|
16
14
|
end
|
17
15
|
|
18
|
-
def
|
19
|
-
|
16
|
+
def render?
|
17
|
+
headings.any? || content.present?
|
20
18
|
end
|
21
19
|
|
22
|
-
def
|
23
|
-
|
20
|
+
def classes
|
21
|
+
super.append(success_class).compact
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
24
|
+
def success_class
|
25
|
+
%(govuk-notification-banner--success) if success
|
28
26
|
end
|
29
27
|
|
30
28
|
def title_tag
|
@@ -33,13 +31,29 @@ class GovukComponent::NotificationBanner < GovukComponent::Base
|
|
33
31
|
"h#{title_heading_level}"
|
34
32
|
end
|
35
33
|
|
36
|
-
class Heading <
|
37
|
-
|
34
|
+
class Heading < GovukComponent::Base
|
35
|
+
attr_reader :text, :link_href, :link_text
|
36
|
+
|
37
|
+
def initialize(text: nil, link_text: nil, link_href: nil, classes: [], html_attributes: {})
|
38
|
+
super(classes: classes, html_attributes: html_attributes)
|
39
|
+
|
40
|
+
@text = text
|
41
|
+
@link_text = link_text
|
42
|
+
@link_href = link_href
|
43
|
+
end
|
44
|
+
|
45
|
+
def call
|
46
|
+
tag.div(class: classes, **html_attributes) do
|
47
|
+
if text.present?
|
48
|
+
safe_join([text, link].compact, " ")
|
49
|
+
else
|
50
|
+
content
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
38
54
|
|
39
|
-
def
|
40
|
-
|
41
|
-
@link_text = link_text
|
42
|
-
@link_target = link_target
|
55
|
+
def link
|
56
|
+
link_to(link_text, link_href, class: 'govuk-notification-banner__link') if link_text.present? && link_href.present?
|
43
57
|
end
|
44
58
|
|
45
59
|
def default_classes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class GovukComponent::PanelComponent < GovukComponent::Base
|
2
|
+
attr_reader :title, :body
|
3
|
+
|
4
|
+
def initialize(title: nil, body: nil, classes: [], html_attributes: {})
|
5
|
+
super(classes: classes, html_attributes: html_attributes)
|
6
|
+
|
7
|
+
@title = title
|
8
|
+
@body = body
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
tag.div(class: classes, **html_attributes) do
|
13
|
+
safe_join([panel_title, panel_body].compact)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def default_classes
|
20
|
+
%w(govuk-panel govuk-panel--confirmation)
|
21
|
+
end
|
22
|
+
|
23
|
+
def display_title?
|
24
|
+
title.present?
|
25
|
+
end
|
26
|
+
|
27
|
+
def display_body?
|
28
|
+
body.present? || content.present?
|
29
|
+
end
|
30
|
+
|
31
|
+
def panel_title
|
32
|
+
tag.h1(title, class: "govuk-panel__title") if display_title?
|
33
|
+
end
|
34
|
+
|
35
|
+
def panel_body
|
36
|
+
if display_body?
|
37
|
+
tag.div(class: "govuk-panel__body") do
|
38
|
+
content.presence || body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render?
|
44
|
+
display_title? || display_body?
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class GovukComponent::PhaseBannerComponent < GovukComponent::Base
|
2
|
+
attr_reader :text, :phase_tag
|
3
|
+
|
4
|
+
def initialize(phase_tag: nil, text: nil, classes: [], html_attributes: {})
|
5
|
+
super(classes: classes, html_attributes: html_attributes)
|
6
|
+
|
7
|
+
@phase_tag = phase_tag
|
8
|
+
@text = text
|
9
|
+
end
|
10
|
+
|
11
|
+
def phase_tag_component
|
12
|
+
GovukComponent::TagComponent.new(classes: "govuk-phase-banner__content__tag", **phase_tag)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def default_classes
|
18
|
+
%w(govuk-phase-banner)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class GovukComponent::StartButtonComponent < GovukComponent::Base
|
2
|
+
attr_reader :text, :href
|
3
|
+
|
4
|
+
def initialize(text:, href:, classes: [], html_attributes: {})
|
5
|
+
super(classes: classes, html_attributes: html_attributes)
|
6
|
+
|
7
|
+
@text = text
|
8
|
+
@href = href
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
link_to(href, **default_attributes, **html_attributes) do
|
13
|
+
safe_join([text, icon])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def default_attributes
|
20
|
+
{
|
21
|
+
role: 'button',
|
22
|
+
draggable: 'false',
|
23
|
+
class: classes,
|
24
|
+
data: { module: 'govuk-button' }
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_classes
|
29
|
+
%w(govuk-button govuk-button--start)
|
30
|
+
end
|
31
|
+
|
32
|
+
def icon
|
33
|
+
svg_attributes = {
|
34
|
+
class: "govuk-button__start-icon",
|
35
|
+
xmlns: "http://www.w3.org/2000/svg",
|
36
|
+
width: "17.5",
|
37
|
+
height: "19",
|
38
|
+
viewBox: "0 0 33 40",
|
39
|
+
focusable: "false",
|
40
|
+
aria: { hidden: "true" }
|
41
|
+
}
|
42
|
+
|
43
|
+
tag.svg(**svg_attributes) do
|
44
|
+
tag.path(fill: "currentColor", d: "M0 0h13l20 20-20 20H0l20-20z")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= tag.dl(class: classes, **html_attributes) do %>
|
2
|
+
<% rows.each do |row| %>
|
3
|
+
<%= tag.div(class: row.classes, **row.html_attributes) do %>
|
4
|
+
<%= tag.dt(row.key, class: "govuk-summary-list__key") %>
|
5
|
+
<%= tag.dd(row.value, class: "govuk-summary-list__value") %>
|
6
|
+
<% if any_row_has_actions? %>
|
7
|
+
<%= row.action %>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class GovukComponent::SummaryListComponent < GovukComponent::Base
|
2
|
+
attr_reader :borders
|
3
|
+
|
4
|
+
renders_many :rows, "Row"
|
5
|
+
|
6
|
+
def initialize(borders: true, classes: [], html_attributes: {})
|
7
|
+
super(classes: classes, html_attributes: html_attributes)
|
8
|
+
|
9
|
+
@borders = borders
|
10
|
+
end
|
11
|
+
|
12
|
+
def any_row_has_actions?
|
13
|
+
rows.any? { |row| row.href.present? }
|
14
|
+
end
|
15
|
+
|
16
|
+
def classes
|
17
|
+
super.append(borders_class).compact
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def borders_class
|
23
|
+
%(govuk-summary-list--no-border) unless borders
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_classes
|
27
|
+
%w(govuk-summary-list)
|
28
|
+
end
|
29
|
+
|
30
|
+
class Row < GovukComponent::Base
|
31
|
+
attr_reader :key, :value, :href, :text, :visually_hidden_text, :action_classes, :action_attributes
|
32
|
+
|
33
|
+
def initialize(key:, value:, action: {}, classes: [], html_attributes: {})
|
34
|
+
super(classes: classes, html_attributes: html_attributes)
|
35
|
+
|
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
|
46
|
+
end
|
47
|
+
|
48
|
+
def action
|
49
|
+
tag.dd(class: "govuk-summary-list__actions") do
|
50
|
+
if href.present?
|
51
|
+
govuk_link_to(href, class: action_classes, **action_attributes) do
|
52
|
+
safe_join([text, tag.span(visually_hidden_text, class: "govuk-visually-hidden")])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def default_classes
|
61
|
+
%w(govuk-summary-list__row)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= tag.div(class: classes, data: { module: 'govuk-tabs' }, **html_attributes) do %>
|
2
|
+
<%= tag.h2(title, class: "govuk-tabs__title") %>
|
3
|
+
<ul class="govuk-tabs__list">
|
4
|
+
<% tabs.each.with_index do |tab, i| %>
|
5
|
+
<%= tag.li(tab.li_link, class: tab.li_classes(i)) %>
|
6
|
+
<% end %>
|
7
|
+
</ul>
|
8
|
+
<% tabs.each.with_index do |tab, i| %>
|
9
|
+
<%= tag.div(tab, class: tab.classes.append(tab.hidden_class(i)), id: tab.id, **tab.html_attributes) %>
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
@@ -1,15 +1,12 @@
|
|
1
|
-
class GovukComponent::
|
2
|
-
|
1
|
+
class GovukComponent::TabComponent < GovukComponent::Base
|
2
|
+
renders_many :tabs, "Tab"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
with_slot :tab, collection: true, class_name: 'Tab'
|
7
|
-
wrap_slot :tab
|
4
|
+
attr_reader :title
|
8
5
|
|
9
6
|
def initialize(title:, classes: [], html_attributes: {})
|
10
7
|
super(classes: classes, html_attributes: html_attributes)
|
11
8
|
|
12
|
-
|
9
|
+
@title = title
|
13
10
|
end
|
14
11
|
|
15
12
|
private
|
@@ -18,25 +15,39 @@ private
|
|
18
15
|
%w(govuk-tabs)
|
19
16
|
end
|
20
17
|
|
21
|
-
class Tab < GovukComponent::
|
22
|
-
|
18
|
+
class Tab < GovukComponent::Base
|
19
|
+
attr_reader :title
|
23
20
|
|
24
21
|
def initialize(title:, classes: [], html_attributes: {})
|
25
22
|
super(classes: classes, html_attributes: html_attributes)
|
26
23
|
|
27
|
-
|
24
|
+
@title = title
|
28
25
|
end
|
29
26
|
|
30
27
|
def id(prefix: nil)
|
31
28
|
[prefix, title.parameterize].join
|
32
29
|
end
|
33
30
|
|
31
|
+
def hidden_class(i = nil)
|
32
|
+
%(govuk-tabs__panel--hidden) unless i&.zero?
|
33
|
+
end
|
34
|
+
|
35
|
+
def li_classes(i = nil)
|
36
|
+
%w(govuk-tabs__list-item).tap do |c|
|
37
|
+
c.append("govuk-tabs__list-item--selected") if i&.zero?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def li_link
|
42
|
+
link_to(title, id(prefix: '#'), class: "govuk-tabs__tab")
|
43
|
+
end
|
44
|
+
|
34
45
|
def default_classes
|
35
46
|
%w(govuk-tabs__panel)
|
36
47
|
end
|
37
48
|
|
38
|
-
def
|
39
|
-
|
49
|
+
def call
|
50
|
+
content
|
40
51
|
end
|
41
52
|
end
|
42
53
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class GovukComponent::TagComponent < GovukComponent::Base
|
2
|
+
attr_reader :text, :colour
|
3
|
+
|
4
|
+
COLOURS = %w(
|
5
|
+
grey
|
6
|
+
green
|
7
|
+
turquoise
|
8
|
+
blue
|
9
|
+
red
|
10
|
+
purple
|
11
|
+
pink
|
12
|
+
orange
|
13
|
+
yellow
|
14
|
+
).freeze
|
15
|
+
|
16
|
+
def initialize(text:, colour: nil, classes: [], html_attributes: {})
|
17
|
+
super(classes: classes, html_attributes: html_attributes)
|
18
|
+
|
19
|
+
@text = text
|
20
|
+
@colour = colour
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
tag.strong(@text, class: classes.append(colour_class), **html_attributes)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def default_classes
|
30
|
+
%w(govuk-tag)
|
31
|
+
end
|
32
|
+
|
33
|
+
def colour_class
|
34
|
+
return nil if colour.blank?
|
35
|
+
|
36
|
+
fail(ArgumentError, colour_error_message) unless valid_colour?
|
37
|
+
|
38
|
+
%(govuk-tag--#{colour})
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_colour?
|
42
|
+
@colour.in?(COLOURS)
|
43
|
+
end
|
44
|
+
|
45
|
+
def colour_error_message
|
46
|
+
"invalid tag colour #{colour}, supported colours are #{COLOURS.to_sentence}"
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class GovukComponent::WarningTextComponent < GovukComponent::Base
|
2
|
+
attr_reader :text, :assistive_text
|
3
|
+
|
4
|
+
ICON = '!'.freeze
|
5
|
+
|
6
|
+
def initialize(text:, assistive_text: 'Warning', classes: [], html_attributes: {})
|
7
|
+
super(classes: classes, html_attributes: html_attributes)
|
8
|
+
|
9
|
+
@text = text
|
10
|
+
@assistive_text = assistive_text
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
tag.div(class: classes, **html_attributes) do
|
15
|
+
safe_join([icon, (content || strong)])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def icon
|
22
|
+
tag.span(ICON, class: 'govuk-warning-text__icon', aria: { hidden: true })
|
23
|
+
end
|
24
|
+
|
25
|
+
def strong
|
26
|
+
tag.strong(class: 'govuk-warning-text__text') do
|
27
|
+
safe_join([assistive, text])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def assistive
|
32
|
+
tag.span(assistive_text, class: 'govuk-warning-text__assistive')
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_classes
|
36
|
+
%w(govuk-warning-text)
|
37
|
+
end
|
38
|
+
end
|