govuk-components 0.2.0 → 0.7.0
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 +46 -27
- data/app/components/govuk_component/base.rb +2 -2
- data/app/components/govuk_component/footer.rb +1 -1
- 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 +3 -2
- data/app/helpers/govuk_link_helper.rb +17 -5
- data/lib/govuk/components/version.rb +1 -1
- metadata +10 -22
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
@@ -1,45 +1,64 @@
|
|
1
|
-
|
1
|
+
**This gem is under heavy development and the API is likely to change.**
|
2
2
|
|
3
3
|
# GOV.UK Components
|
4
4
|
|
5
5
|
[](https://travis-ci.com/DFE-Digital/govuk-components)
|
6
6
|
|
7
|
-
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
|
7
|
+
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
8
|
|
9
9
|
## What's included
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
* Warning text ✔️
|
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` |
|
29
28
|
|
30
29
|
### Helpers
|
31
30
|
|
32
|
-
* `#govuk_link_to`
|
33
|
-
* `#govuk_mail_to`
|
34
|
-
* `#govuk_button_to`
|
35
|
-
* `#govuk_back_to_top_link`
|
36
|
-
*
|
31
|
+
* `#govuk_link_to`
|
32
|
+
* `#govuk_mail_to`
|
33
|
+
* `#govuk_button_to`
|
34
|
+
* `#govuk_back_to_top_link`
|
35
|
+
* `#govuk_skip_link`
|
36
|
+
|
37
|
+
## Example use
|
38
|
+
|
39
|
+
This library allows components to be rendered with Rails' `render` method or via the provided helpers. Here we'll use the `govuk_accordion` to render an accordion.
|
40
|
+
|
41
|
+
```erb
|
42
|
+
<%= govuk_accordion(id: 'def234') do |accordion| %>
|
43
|
+
<%= accordion.add_section(title: 'Section 1') do %>
|
44
|
+
<p class="govuk-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
|
45
|
+
<% end %>
|
46
|
+
<%= accordion.add_section(title: 'Section 2') do %>
|
47
|
+
<p class="govuk-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
|
48
|
+
<% end %>
|
49
|
+
<%= accordion.add_section(title: 'Section 3') do %>
|
50
|
+
<p class="govuk-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
|
51
|
+
<% end %>
|
52
|
+
<% end %>
|
53
|
+
```
|
54
|
+
|
55
|
+
Here is the rendered accordion.
|
37
56
|
|
38
|
-
|
57
|
+

|
39
58
|
|
40
59
|
For examples on usage see the [guide page](https://dfe-digital.github.io/govuk-components/).
|
41
60
|
|
42
|
-
##
|
61
|
+
## Setup
|
43
62
|
|
44
63
|
Add this line to your `config/application.rb`:
|
45
64
|
|
@@ -7,10 +7,10 @@ class GovukComponent::Base < ViewComponent::Base
|
|
7
7
|
@html_attributes = html_attributes
|
8
8
|
end
|
9
9
|
|
10
|
-
# Redirect #
|
10
|
+
# Redirect #add_name to #slot(:name) to make building components
|
11
11
|
# with slots feel more DSL-like
|
12
12
|
def self.wrap_slot(name)
|
13
|
-
define_method(name) do |*args, **kwargs, &block|
|
13
|
+
define_method(%(add_#{name})) do |*args, **kwargs, &block|
|
14
14
|
self.slot(name, *args, **kwargs, &block)
|
15
15
|
end
|
16
16
|
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,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
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module GovukComponentsHelper
|
2
2
|
{
|
3
3
|
govuk_accordion: 'GovukComponent::Accordion',
|
4
4
|
govuk_back_link: 'GovukComponent::BackLink',
|
@@ -7,6 +7,7 @@ module GovukComponentHelper
|
|
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',
|
@@ -25,4 +26,4 @@ module GovukComponentHelper
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
ActiveSupport.on_load(:action_view) { include
|
29
|
+
ActiveSupport.on_load(:action_view) { include GovukComponentsHelper }
|
@@ -1,14 +1,26 @@
|
|
1
1
|
module GovukLinkHelper
|
2
|
-
def govuk_link_to(*args, **kwargs)
|
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)
|
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
|
-
autorequire:
|
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
|
@@ -30,34 +30,20 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 6.0.3
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: slim-rails
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '3.2'
|
40
|
-
type: :runtime
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '3.2'
|
47
33
|
- !ruby/object:Gem::Dependency
|
48
34
|
name: view_component
|
49
35
|
requirement: !ruby/object:Gem::Requirement
|
50
36
|
requirements:
|
51
37
|
- - "~>"
|
52
38
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.
|
39
|
+
version: 2.22.1
|
54
40
|
type: :runtime
|
55
41
|
prerelease: false
|
56
42
|
version_requirements: !ruby/object:Gem::Requirement
|
57
43
|
requirements:
|
58
44
|
- - "~>"
|
59
45
|
- !ruby/object:Gem::Version
|
60
|
-
version: 2.
|
46
|
+
version: 2.22.1
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: sqlite3
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +139,8 @@ files:
|
|
153
139
|
- app/components/govuk_component/header.html.erb
|
154
140
|
- app/components/govuk_component/header.rb
|
155
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
|
156
144
|
- app/components/govuk_component/panel.html.erb
|
157
145
|
- app/components/govuk_component/panel.rb
|
158
146
|
- app/components/govuk_component/phase_banner.html.erb
|
@@ -178,11 +166,11 @@ files:
|
|
178
166
|
- lib/govuk/components/engine.rb
|
179
167
|
- lib/govuk/components/version.rb
|
180
168
|
- lib/tasks/govuk/components_tasks.rake
|
181
|
-
homepage: https://
|
169
|
+
homepage: https://github.com/DFE-Digital/govuk-components
|
182
170
|
licenses:
|
183
171
|
- MIT
|
184
172
|
metadata: {}
|
185
|
-
post_install_message:
|
173
|
+
post_install_message:
|
186
174
|
rdoc_options: []
|
187
175
|
require_paths:
|
188
176
|
- lib
|
@@ -198,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
186
|
version: '0'
|
199
187
|
requirements: []
|
200
188
|
rubygems_version: 3.1.2
|
201
|
-
signing_key:
|
189
|
+
signing_key:
|
202
190
|
specification_version: 4
|
203
191
|
summary: Lightweight set of reusable GOV.UK Design System components
|
204
192
|
test_files: []
|