govuk-components 0.3.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d957c212c5a58ad13e5e6296200d65d1d5571ede1ad3a466a2d799bd33cab59
4
- data.tar.gz: 4bb34fa91578e1d5fa59f7a0f80fb1d363c0dbeb87979328c64c35d83ca0c471
3
+ metadata.gz: 8778178d28b737c89fedbcaf30738c77c33f38a4826ea907327b80c38f33a434
4
+ data.tar.gz: 356e6a1bdfbeec1f3d602707e8773f500d86bad394ab6ebef6f79a58b42bc8b2
5
5
  SHA512:
6
- metadata.gz: '080f8799ba56540bd4ecd4d7e038f1c413a6c12955bf10a87ba547d4cd120196a0e2a95ad1a4f75e8177cf467044d39a7dc4641c280480c1bef691c036818f26'
7
- data.tar.gz: 61957c3b0aeb5fcca7a420445ad5ecc3013d5a42b054c291898d276505322e5cc057efd7d92c860dad20da2f3f0cd4360586bba06939f62f4ad6b1f2b9f6cf82
6
+ metadata.gz: 7d36cf6f689c2c5890bd7ef3f63c71214f111400637fb72578dc42f6bfb1aa253658ab46fe8737c1c8e96d363e57d871a6cacc998761dc907c76ebdf7214bc8b
7
+ data.tar.gz: 3d5365cf1fa97c3aa62ebed22c90d87a309f9a080f44b9839f24e3face33fd056a47194102754e8ddc857fbb24b58971acf88f9d323db5c64d056daf254c85dc
data/README.md CHANGED
@@ -1,45 +1,64 @@
1
- > **Note!** This repository is very new and not yet fully built and documented. Breaking changes can happen at any time. Please check the [components tracker](https://github.com/DFE-Digital/govuk-components/issues/18) to see progress.
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
  [![Build Status](https://travis-ci.com/DFE-Digital/govuk-components.svg?branch=master)](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 is [supported natively in Rails 6.1](https://edgeguides.rubyonrails.org/layouts_and_rendering.html#rendering-objects).
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
- The gem will include the following components and helpers, [track their progress](https://github.com/DFE-Digital/govuk-components/issues/18):
12
-
13
- ### Components
14
-
15
- * Accordion ✔️
16
- * Back link ✔️
17
- * Breadcrumbs ✔️
18
- * Details ✔️
19
- * Footer ✔️
20
- * Header ✔️
21
- * Inset text ✔️
22
- * Panel ✔️
23
- * Phase banner ✔️
24
- * Start now button ✔️
25
- * Summary list ✔️
26
- * Tabs ✔️
27
- * Tag ✔️
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
- * Skip link ✔️
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
- ## Examples
57
+ ![Accordion preview](docs/images/accordion.png)
39
58
 
40
59
  For examples on usage see the [guide page](https://dfe-digital.github.io/govuk-components/).
41
60
 
42
- ## Usage
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 #name to #slot(:name) to make building components
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,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
@@ -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)
3
- link_to(*args, **{ class: 'govuk-link' }.deep_merge(kwargs))
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, **{ class: 'govuk-link' }.deep_merge(kwargs))
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, **{ class: 'govuk-button' }.deep_merge(kwargs))
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
 
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '0.3.0'
3
+ VERSION = '0.8.0'
4
4
  end
5
5
  end
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.3.0
4
+ version: 0.8.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-09-16 00:00:00.000000000 Z
11
+ date: 2020-12-10 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.18.1
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.18.1
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
@@ -164,7 +166,7 @@ files:
164
166
  - lib/govuk/components/engine.rb
165
167
  - lib/govuk/components/version.rb
166
168
  - lib/tasks/govuk/components_tasks.rake
167
- homepage: https://www.github.com/dfe-digital
169
+ homepage: https://github.com/DFE-Digital/govuk-components
168
170
  licenses:
169
171
  - MIT
170
172
  metadata: {}