govuk-components 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -16
- data/app/components/govuk_component/notification_banner.html.erb +20 -0
- data/app/components/govuk_component/notification_banner.rb +58 -0
- data/app/helpers/govuk_components_helper.rb +1 -0
- data/app/helpers/govuk_link_helper.rb +17 -5
- data/lib/govuk/components/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90eede10baca630edcdc6999469783ab08332a02d7c03e7ca6b27bef6fb8e328
|
4
|
+
data.tar.gz: bfb02cc50490be25acd650a28e2deda67841c5719901db3869919c4d08ac2337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc3c98d97c246ee149dc10856a90214db31951b0d2184b16de886fa62704e9aa32d0e81df90bbc5cbb9763e19120f1be8697d773fcde996a60da17d1615f612e
|
7
|
+
data.tar.gz: 4a86ca1483dc684ce18163abe7b5ff1b13a22383b3b77fb17e57251ab4d03e77553c83c0a3443378e353203a843d1a675088a867e481fad0e0357e57310eb8ae
|
data/README.md
CHANGED
@@ -8,22 +8,23 @@ This gem provides a suite of reusable components for the [GOV.UK Design System](
|
|
8
8
|
|
9
9
|
## What's included
|
10
10
|
|
11
|
-
| Component name
|
12
|
-
| --------------
|
13
|
-
| [Accordion](app/components/govuk_component/accordion.rb)
|
14
|
-
| [Back link](app/components/govuk_component/back_link.rb)
|
15
|
-
| [Breadcrumbs](app/components/govuk_component/breadcrumbs.rb)
|
16
|
-
| [Details](app/components/govuk_component/details.rb)
|
17
|
-
| [Footer](app/components/govuk_component/footer.rb)
|
18
|
-
| [Header](app/components/govuk_component/header.rb)
|
19
|
-
| [Inset text](app/components/govuk_component/inset_text.rb)
|
20
|
-
| [
|
21
|
-
| [
|
22
|
-
| [
|
23
|
-
| [
|
24
|
-
| [
|
25
|
-
| [
|
26
|
-
| [
|
11
|
+
| Component name | Helper |
|
12
|
+
| -------------- | ------ |
|
13
|
+
| [Accordion](app/components/govuk_component/accordion.rb) | `govuk_accordion` |
|
14
|
+
| [Back link](app/components/govuk_component/back_link.rb) | `govuk_back_link` |
|
15
|
+
| [Breadcrumbs](app/components/govuk_component/breadcrumbs.rb) | `govuk_breadcrumbs` |
|
16
|
+
| [Details](app/components/govuk_component/details.rb) | `govuk_details` |
|
17
|
+
| [Footer](app/components/govuk_component/footer.rb) | `govuk_footer` |
|
18
|
+
| [Header](app/components/govuk_component/header.rb) | `govuk_header` |
|
19
|
+
| [Inset text](app/components/govuk_component/inset_text.rb) | `govuk_inset_text` |
|
20
|
+
| [Notification banner](app/components/govuk_component/notification_banner.rb) | `govuk_notification_banner` |
|
21
|
+
| [Panel](app/components/govuk_component/panel.rb) | `govuk_panel` |
|
22
|
+
| [Phase banner](app/components/govuk_component/phase_banner.rb) | `govuk_phase_banner` |
|
23
|
+
| [Start now button](app/components/govuk_component/start_now_button.rb) | `govuk_start_now_button` |
|
24
|
+
| [Summary list](app/components/govuk_component/summary_list.rb) | `govuk_summary_list` |
|
25
|
+
| [Tabs](app/components/govuk_component/tabs.rb) | `govuk_tabs` |
|
26
|
+
| [Tag](app/components/govuk_component/tag.rb) | `govuk_tag` |
|
27
|
+
| [Warning text](app/components/govuk_component/warning.rb) | `govuk_warning` |
|
27
28
|
|
28
29
|
### Helpers
|
29
30
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%= tag.div(class: classes.append(success_class).compact, **html_attributes, role: "region", aria: { labelledby: title_id }, data: data_params) 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
|
+
<p class="govuk-notification-banner__heading">
|
10
|
+
|
11
|
+
<%= heading.text %>.
|
12
|
+
<% if heading.link_target && heading.link_text %>
|
13
|
+
<%= link_to(heading.link_text, heading.link_target, class: "govuk-notification-banner__link") %>.
|
14
|
+
<% end %>
|
15
|
+
</p>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<%= content %>
|
19
|
+
</div>
|
20
|
+
<% end %>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class GovukComponent::NotificationBanner < GovukComponent::Base
|
2
|
+
attr_reader :title, :title_id, :success, :title_heading_level, :disable_auto_focus
|
3
|
+
|
4
|
+
include ViewComponent::Slotable
|
5
|
+
with_slot :heading, collection: true, class_name: 'Heading'
|
6
|
+
|
7
|
+
def initialize(title:, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
|
8
|
+
super(classes: classes, html_attributes: html_attributes)
|
9
|
+
|
10
|
+
@title = title
|
11
|
+
@title_id = title_id
|
12
|
+
@success = success
|
13
|
+
@title_heading_level = title_heading_level
|
14
|
+
@disable_auto_focus = disable_auto_focus
|
15
|
+
end
|
16
|
+
|
17
|
+
def success_class
|
18
|
+
%(govuk-notification-banner--success) if success?
|
19
|
+
end
|
20
|
+
|
21
|
+
def success?
|
22
|
+
@success
|
23
|
+
end
|
24
|
+
|
25
|
+
def render?
|
26
|
+
headings.any?
|
27
|
+
end
|
28
|
+
|
29
|
+
def title_tag
|
30
|
+
fail "title_heading_level must be a number between 1 and 6" unless title_heading_level.is_a?(Integer) && title_heading_level.in?(1..6)
|
31
|
+
|
32
|
+
"h#{title_heading_level}"
|
33
|
+
end
|
34
|
+
|
35
|
+
class Heading < ViewComponent::Slot
|
36
|
+
attr_accessor :text, :link_target, :link_text
|
37
|
+
|
38
|
+
def initialize(text:, link_text: nil, link_target: nil)
|
39
|
+
@text = text
|
40
|
+
@link_text = link_text
|
41
|
+
@link_target = link_target
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_classes
|
45
|
+
%w(govuk-notification-banner__heading)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def default_classes
|
52
|
+
%w(govuk-notification-banner)
|
53
|
+
end
|
54
|
+
|
55
|
+
def data_params
|
56
|
+
{ "module" => "govuk-notification-banner", "disable-auto-focus" => disable_auto_focus }.compact
|
57
|
+
end
|
58
|
+
end
|
@@ -7,6 +7,7 @@ module GovukComponentsHelper
|
|
7
7
|
govuk_footer: 'GovukComponent::Footer',
|
8
8
|
govuk_header: 'GovukComponent::Header',
|
9
9
|
govuk_inset_text: 'GovukComponent::InsetText',
|
10
|
+
govuk_notification_banner: 'GovukComponent::NotificationBanner',
|
10
11
|
govuk_panel: 'GovukComponent::Panel',
|
11
12
|
govuk_phase_banner: 'GovukComponent::PhaseBanner',
|
12
13
|
govuk_start_now_button: 'GovukComponent::StartNowButton',
|
@@ -1,14 +1,26 @@
|
|
1
1
|
module GovukLinkHelper
|
2
|
-
def govuk_link_to(*args, **kwargs, &block)
|
3
|
-
link_to(*args, **
|
2
|
+
def govuk_link_to(*args, button: false, **kwargs, &block)
|
3
|
+
link_to(*args, **inject_class(kwargs, class_name: link_class(button)), &block)
|
4
4
|
end
|
5
5
|
|
6
|
-
def govuk_mail_to(*args, **kwargs, &block)
|
7
|
-
mail_to(*args, **
|
6
|
+
def govuk_mail_to(*args, button: false, **kwargs, &block)
|
7
|
+
mail_to(*args, **inject_class(kwargs, class_name: link_class(button)), &block)
|
8
8
|
end
|
9
9
|
|
10
10
|
def govuk_button_to(*args, **kwargs)
|
11
|
-
button_to(*args, **
|
11
|
+
button_to(*args, **inject_class(kwargs, class_name: 'govuk-button'))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def inject_class(attributes, class_name:)
|
17
|
+
attributes.with_indifferent_access.tap do |attrs|
|
18
|
+
attrs[:class] = Array.wrap(attrs[:class]).prepend(class_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def link_class(button)
|
23
|
+
button ? 'govuk-button' : 'govuk-link'
|
12
24
|
end
|
13
25
|
end
|
14
26
|
|
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: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DfE developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
39
|
+
version: 2.22.1
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 2.
|
46
|
+
version: 2.22.1
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +139,8 @@ files:
|
|
139
139
|
- app/components/govuk_component/header.html.erb
|
140
140
|
- app/components/govuk_component/header.rb
|
141
141
|
- app/components/govuk_component/inset_text.rb
|
142
|
+
- app/components/govuk_component/notification_banner.html.erb
|
143
|
+
- app/components/govuk_component/notification_banner.rb
|
142
144
|
- app/components/govuk_component/panel.html.erb
|
143
145
|
- app/components/govuk_component/panel.rb
|
144
146
|
- app/components/govuk_component/phase_banner.html.erb
|