-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Following the release of [GOV.UK Design System v5.0](https://github.com/alphagov/govuk-design-system/milestone/16), govuk-components v5.0.0 will be released. The headline features are: * support for GOV.UK Design System v5.0 * inclusion of [the task list component](alphagov/govuk-frontend#2261) #425 * all new link helpers #419 * update header to use new SVG which combines the crown and the GOV.UK test #466 Release notes will be drafted in #469.
- Loading branch information
Showing
63 changed files
with
1,055 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module GovukComponent | ||
class TaskListComponent < GovukComponent::Base | ||
renders_many :items, ->(title: nil, href: nil, hint: nil, status: {}, classes: [], html_attributes: {}) do | ||
GovukComponent::TaskListComponent::ItemComponent.new( | ||
title: title, | ||
href: href, | ||
hint: hint, | ||
id_prefix: @id_prefix, | ||
count: @count, | ||
status: status, | ||
classes: classes, | ||
html_attributes: html_attributes | ||
) | ||
end | ||
|
||
def initialize(id_prefix: "task-list", classes: [], html_attributes: {}) | ||
@id_prefix = id_prefix | ||
@count = 0 | ||
|
||
super(classes: classes, html_attributes: html_attributes) | ||
end | ||
|
||
def call | ||
numbered_items = items.each.with_index(1) { |item, count| item.count = count } | ||
|
||
tag.ul(**html_attributes) do | ||
safe_join(numbered_items) | ||
end | ||
end | ||
|
||
private | ||
|
||
def default_attributes | ||
{ class: 'govuk-task-list' } | ||
end | ||
end | ||
end |
77 changes: 77 additions & 0 deletions
77
app/components/govuk_component/task_list_component/item_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module GovukComponent | ||
class TaskListComponent::ItemComponent < GovukComponent::Base | ||
renders_one :status, ->(text: nil, classes: [], html_attributes: {}, &block) do | ||
GovukComponent::TaskListComponent::StatusComponent.new( | ||
id_prefix: @id_prefix, | ||
count: @count, | ||
text: text, | ||
classes: classes, | ||
html_attributes: html_attributes, | ||
&block | ||
) | ||
end | ||
|
||
renders_one :title, ->(text: nil, href: nil, hint: nil, classes: [], html_attributes: {}, &block) do | ||
GovukComponent::TaskListComponent::TitleComponent.new( | ||
id_prefix: @id_prefix, | ||
count: @count, | ||
text: text, | ||
href: href, | ||
hint: hint, | ||
classes: classes, | ||
html_attributes: html_attributes, | ||
&block | ||
) | ||
end | ||
|
||
attr_reader :raw_title, :hint, :href, :raw_status | ||
attr_writer :count | ||
|
||
def initialize(title: nil, href: nil, hint: nil, count: nil, id_prefix: nil, status: {}, classes: [], html_attributes: {}) | ||
@raw_title = title | ||
@href = href | ||
@hint = hint | ||
@raw_status = status | ||
@id_prefix = id_prefix | ||
@count = count | ||
|
||
super(classes: classes, html_attributes: html_attributes) | ||
end | ||
|
||
def call | ||
adjusted_html_attributes = if href.present? || title&.href.present? | ||
html_attributes_with_link_class | ||
else | ||
html_attributes | ||
end | ||
|
||
tag.li(safe_join([title_content, status_content].compact), **adjusted_html_attributes) | ||
end | ||
|
||
private | ||
|
||
def title_content | ||
title || with_title(**title_attributes) | ||
end | ||
|
||
def status_content | ||
status || with_status(**status_attributes) | ||
end | ||
|
||
def default_attributes | ||
{ class: 'govuk-task-list__item' } | ||
end | ||
|
||
def title_attributes | ||
{ text: raw_title, href: href, hint: hint } | ||
end | ||
|
||
def html_attributes_with_link_class | ||
html_attributes.tap { |h| h[:class].append("govuk-task-list__item--with-link") } | ||
end | ||
|
||
def status_attributes | ||
raw_status.is_a?(String) ? { text: raw_status } : raw_status | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
app/components/govuk_component/task_list_component/status_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module GovukComponent | ||
class TaskListComponent::StatusComponent < GovukComponent::Base | ||
attr_reader :id_prefix, :text, :count | ||
|
||
def initialize(text: nil, id_prefix: nil, count: nil, classes: [], html_attributes: {}) | ||
@text = text | ||
@count = count | ||
@id_prefix = id_prefix | ||
|
||
super(classes: classes, html_attributes: html_attributes) | ||
end | ||
|
||
def call | ||
tag.div(status_text, **html_attributes) | ||
end | ||
|
||
def render? | ||
status_text.present? | ||
end | ||
|
||
private | ||
|
||
def default_attributes | ||
{ class: %w(govuk-task-list__status), id: [id_prefix, count, "status"].compact.join("-") } | ||
end | ||
|
||
def status_text | ||
text || content | ||
end | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
app/components/govuk_component/task_list_component/title_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module GovukComponent | ||
class TaskListComponent::TitleComponent < GovukComponent::Base | ||
using HTMLAttributesUtils | ||
|
||
attr_reader :id_prefix, :text, :href, :hint, :count | ||
|
||
def initialize(text: nil, href: nil, hint: nil, id_prefix: nil, count: nil, classes: [], html_attributes: {}) | ||
@text = text | ||
@href = href | ||
@hint = hint | ||
@id_prefix = id_prefix | ||
@count = count | ||
|
||
super(classes: classes, html_attributes: html_attributes) | ||
end | ||
|
||
def call | ||
tag.div(**html_attributes) { safe_join([title_content, hint_content]) } | ||
end | ||
|
||
private | ||
|
||
def title_content | ||
(href.present?) ? govuk_link_to(text, href, **link_attributes) : text | ||
end | ||
|
||
def hint_content | ||
return if hint.blank? | ||
|
||
tag.div(hint, class: "govuk-task-list__hint", id: hint_id) | ||
end | ||
|
||
def default_attributes | ||
{ class: "govuk-task-list__name-and-hint" } | ||
end | ||
|
||
def link_attributes | ||
{ class: "govuk-task-list__link", **aria_described_by_attributes } | ||
end | ||
|
||
def aria_described_by_attributes | ||
{ aria: { describedby: [*status_id, *hint_id] } } | ||
end | ||
|
||
def hint_id | ||
[id_prefix, count, "hint"].compact.join("-") if hint.present? | ||
end | ||
|
||
def status_id | ||
[id_prefix, count, "status"].compact.join("-") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.