govuk-components 0.5.0 → 1.0.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 +4 -4
- data/README.md +23 -19
- data/app/components/govuk_component/base.rb +1 -1
- data/app/components/govuk_component/footer.rb +1 -1
- data/app/components/govuk_component/notification_banner.html.erb +19 -0
- data/app/components/govuk_component/notification_banner.rb +59 -0
- data/app/components/govuk_component/tag.rb +1 -1
- data/app/components/govuk_component/traits/custom_classes.rb +1 -2
- data/app/helpers/govuk_components_helper.rb +2 -1
- data/app/helpers/govuk_link_helper.rb +17 -5
- data/lib/govuk/components/engine.rb +1 -1
- data/lib/govuk/components/version.rb +1 -1
- metadata +47 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '094a8aaa90e8f699ce0844e4770b91f8fc62b7481d9cd2be1fbe480726163f96'
|
4
|
+
data.tar.gz: b170c99c2ac73c56bf502f26ba232d2abfef6459cebf52c53677e70b8a84c646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7802eb767bbcf892ab6f3fa5c149db8629f1002bafc2a787e15e67f6317d33df7f23f646f39d92280b8d3db542537ea2b023823548180e51e79042ad19401c18
|
7
|
+
data.tar.gz: f5b2381662b5c79be177c19a5fa98757e61b8f852f28316b7c12cf3589164bf582f20b83a6632f00576d723597063c130dfcb84db6e1d52a0f7fa6971b3e3c21
|
data/README.md
CHANGED
@@ -1,29 +1,33 @@
|
|
1
|
-
**This gem is under heavy development and the API is likely to change.**
|
2
|
-
|
3
1
|
# GOV.UK Components
|
4
2
|
|
5
|
-
[](https://github.com/DFE-Digital/govuk-components/actions?query=workflow%3ATests)
|
4
|
+
[](https://codeclimate.com/github/DFE-Digital/govuk-components/maintainability)
|
5
|
+
[](https://codeclimate.com/github/DFE-Digital/govuk-components/test_coverage)
|
6
|
+
[](https://github.com/DFE-Digital/govuk-components/blob/master/LICENSE)
|
7
|
+
[](https://dependabot.com)
|
8
|
+
[](https://design-system.service.gov.uk)
|
6
9
|
|
7
10
|
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. ViewComponent will be [supported natively in Rails 6.1](https://edgeguides.rubyonrails.org/layouts_and_rendering.html#rendering-objects).
|
8
11
|
|
9
12
|
## What's included
|
10
13
|
|
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
|
-
| [
|
14
|
+
| Component name | Helper |
|
15
|
+
| -------------- | ------ |
|
16
|
+
| [Accordion](app/components/govuk_component/accordion.rb) | `govuk_accordion` |
|
17
|
+
| [Back link](app/components/govuk_component/back_link.rb) | `govuk_back_link` |
|
18
|
+
| [Breadcrumbs](app/components/govuk_component/breadcrumbs.rb) | `govuk_breadcrumbs` |
|
19
|
+
| [Details](app/components/govuk_component/details.rb) | `govuk_details` |
|
20
|
+
| [Footer](app/components/govuk_component/footer.rb) | `govuk_footer` |
|
21
|
+
| [Header](app/components/govuk_component/header.rb) | `govuk_header` |
|
22
|
+
| [Inset text](app/components/govuk_component/inset_text.rb) | `govuk_inset_text` |
|
23
|
+
| [Notification banner](app/components/govuk_component/notification_banner.rb) | `govuk_notification_banner` |
|
24
|
+
| [Panel](app/components/govuk_component/panel.rb) | `govuk_panel` |
|
25
|
+
| [Phase banner](app/components/govuk_component/phase_banner.rb) | `govuk_phase_banner` |
|
26
|
+
| [Start now button](app/components/govuk_component/start_now_button.rb) | `govuk_start_now_button` |
|
27
|
+
| [Summary list](app/components/govuk_component/summary_list.rb) | `govuk_summary_list` |
|
28
|
+
| [Tabs](app/components/govuk_component/tabs.rb) | `govuk_tabs` |
|
29
|
+
| [Tag](app/components/govuk_component/tag.rb) | `govuk_tag` |
|
30
|
+
| [Warning text](app/components/govuk_component/warning.rb) | `govuk_warning` |
|
27
31
|
|
28
32
|
### Helpers
|
29
33
|
|
@@ -11,7 +11,7 @@ class GovukComponent::Base < ViewComponent::Base
|
|
11
11
|
# with slots feel more DSL-like
|
12
12
|
def self.wrap_slot(name)
|
13
13
|
define_method(%(add_#{name})) do |*args, **kwargs, &block|
|
14
|
-
|
14
|
+
slot(name, *args, **kwargs, &block)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -29,7 +29,7 @@ private
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def default_licence
|
32
|
-
link = link_to("Open Government Licence v3.0", "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/")
|
32
|
+
link = link_to("Open Government Licence v3.0", "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/", class: %w(govuk-footer__link))
|
33
33
|
|
34
34
|
raw(%(All content is available under the #{link}, except where otherwise stated))
|
35
35
|
end
|
@@ -0,0 +1,19 @@
|
|
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
|
+
<%= heading.text %>
|
11
|
+
<% if heading.link_target && heading.link_text %>
|
12
|
+
<%= link_to(heading.link_text, heading.link_target, class: "govuk-notification-banner__link") %>.
|
13
|
+
<% end %>
|
14
|
+
</p>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<%= content %>
|
18
|
+
</div>
|
19
|
+
<% end %>
|
@@ -0,0 +1,59 @@
|
|
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
|
+
wrap_slot(:heading)
|
7
|
+
|
8
|
+
def initialize(title:, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
|
9
|
+
super(classes: classes, html_attributes: html_attributes)
|
10
|
+
|
11
|
+
@title = title
|
12
|
+
@title_id = title_id
|
13
|
+
@success = success
|
14
|
+
@title_heading_level = title_heading_level
|
15
|
+
@disable_auto_focus = disable_auto_focus
|
16
|
+
end
|
17
|
+
|
18
|
+
def success_class
|
19
|
+
%(govuk-notification-banner--success) if success?
|
20
|
+
end
|
21
|
+
|
22
|
+
def success?
|
23
|
+
@success
|
24
|
+
end
|
25
|
+
|
26
|
+
def render?
|
27
|
+
headings.any?
|
28
|
+
end
|
29
|
+
|
30
|
+
def title_tag
|
31
|
+
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)
|
32
|
+
|
33
|
+
"h#{title_heading_level}"
|
34
|
+
end
|
35
|
+
|
36
|
+
class Heading < ViewComponent::Slot
|
37
|
+
attr_accessor :text, :link_target, :link_text
|
38
|
+
|
39
|
+
def initialize(text:, link_text: nil, link_target: nil)
|
40
|
+
@text = text
|
41
|
+
@link_text = link_text
|
42
|
+
@link_target = link_target
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_classes
|
46
|
+
%w(govuk-notification-banner__heading)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def default_classes
|
53
|
+
%w(govuk-notification-banner)
|
54
|
+
end
|
55
|
+
|
56
|
+
def data_params
|
57
|
+
{ "module" => "govuk-notification-banner", "disable-auto-focus" => disable_auto_focus }.compact
|
58
|
+
end
|
59
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module GovukComponent
|
2
2
|
module Traits
|
3
3
|
module CustomClasses
|
4
|
-
|
5
4
|
def classes
|
6
5
|
default_classes.concat(Array.wrap(@classes))
|
7
6
|
end
|
@@ -15,7 +14,7 @@ module GovukComponent
|
|
15
14
|
private
|
16
15
|
|
17
16
|
def parse_classes(classes)
|
18
|
-
return []
|
17
|
+
return [] if classes.blank?
|
19
18
|
|
20
19
|
case classes
|
21
20
|
when Array
|
@@ -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',
|
@@ -18,7 +19,7 @@ module GovukComponentsHelper
|
|
18
19
|
define_method(name) do |*args, **kwargs, &block|
|
19
20
|
capture do
|
20
21
|
render(klass.constantize.new(*args, **kwargs)) do |com|
|
21
|
-
block.call(com)
|
22
|
+
block.call(com) if block.present?
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -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,51 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk-components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.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:
|
11
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0.3
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 6.0
|
19
|
+
version: '6.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 6.0.3
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 6.0
|
26
|
+
version: '6.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: view_component
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- - "
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.22.1
|
34
|
+
- - "<"
|
38
35
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
36
|
+
version: 2.25.0
|
40
37
|
type: :runtime
|
41
38
|
prerelease: false
|
42
39
|
version_requirements: !ruby/object:Gem::Requirement
|
43
40
|
requirements:
|
44
|
-
- - "
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.22.1
|
44
|
+
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 2.
|
46
|
+
version: 2.25.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: capybara
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: pry-byebug
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: rubocop-govuk
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
@@ -114,6 +114,34 @@ dependencies:
|
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: simplecov
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.20'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.20'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: sqlite3
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
117
145
|
description: A collection of components intended to ease the building of GOV.UK Design
|
118
146
|
System web applications
|
119
147
|
email:
|
@@ -139,6 +167,8 @@ files:
|
|
139
167
|
- app/components/govuk_component/header.html.erb
|
140
168
|
- app/components/govuk_component/header.rb
|
141
169
|
- app/components/govuk_component/inset_text.rb
|
170
|
+
- app/components/govuk_component/notification_banner.html.erb
|
171
|
+
- app/components/govuk_component/notification_banner.rb
|
142
172
|
- app/components/govuk_component/panel.html.erb
|
143
173
|
- app/components/govuk_component/panel.rb
|
144
174
|
- app/components/govuk_component/phase_banner.html.erb
|