dsfr-view-components 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -28
  3. data/app/components/dsfr_component/accordion_component/section_component.html.erb +15 -9
  4. data/app/components/dsfr_component/accordion_component/section_component.rb +11 -24
  5. data/app/components/dsfr_component/accordion_component.rb +5 -16
  6. data/app/components/dsfr_component/alert_component.rb +72 -5
  7. data/app/components/dsfr_component/badge_component.rb +30 -0
  8. data/app/components/dsfr_component/stepper_component.html.erb +18 -0
  9. data/app/components/dsfr_component/stepper_component.rb +26 -0
  10. data/app/components/dsfr_component/tag_component.rb +60 -31
  11. data/app/components/dsfr_component/tile_component.html.erb +19 -0
  12. data/app/components/dsfr_component/tile_component.rb +31 -0
  13. data/app/helpers/dsfr_components_helper.rb +11 -19
  14. data/app/helpers/dsfr_link_helper.rb +41 -90
  15. data/lib/dsfr/components/version.rb +1 -1
  16. data/lib/generators/dsfr_component/USAGE +28 -0
  17. data/lib/generators/dsfr_component/dsfr_component_generator.rb +50 -0
  18. data/lib/generators/dsfr_component/templates/component.haml.erb +13 -0
  19. data/lib/generators/dsfr_component/templates/component.rb.erb +32 -0
  20. data/lib/generators/dsfr_component/templates/component_helper.rb.erb +10 -0
  21. data/lib/generators/dsfr_component/templates/component_spec.rb.erb +5 -0
  22. metadata +84 -65
  23. data/app/components/dsfr_component/back_link_component.rb +0 -24
  24. data/app/components/dsfr_component/breadcrumbs_component.html.erb +0 -7
  25. data/app/components/dsfr_component/breadcrumbs_component.rb +0 -51
  26. data/app/components/dsfr_component/cookie_banner_component/message_component.rb +0 -62
  27. data/app/components/dsfr_component/cookie_banner_component.rb +0 -35
  28. data/app/components/dsfr_component/details_component.rb +0 -42
  29. data/app/components/dsfr_component/footer_component.html.erb +0 -49
  30. data/app/components/dsfr_component/footer_component.rb +0 -87
  31. data/app/components/dsfr_component/header_component.html.erb +0 -51
  32. data/app/components/dsfr_component/header_component.rb +0 -145
  33. data/app/components/dsfr_component/inset_text_component.rb +0 -28
  34. data/app/components/dsfr_component/notification_banner_component.html.erb +0 -14
  35. data/app/components/dsfr_component/notification_banner_component.rb +0 -93
  36. data/app/components/dsfr_component/pagination_component/adjacent_page.rb +0 -59
  37. data/app/components/dsfr_component/pagination_component/item.rb +0 -77
  38. data/app/components/dsfr_component/pagination_component/next_page.rb +0 -27
  39. data/app/components/dsfr_component/pagination_component/previous_page.rb +0 -21
  40. data/app/components/dsfr_component/pagination_component.rb +0 -129
  41. data/app/components/dsfr_component/panel_component.rb +0 -56
  42. data/app/components/dsfr_component/phase_banner_component.html.erb +0 -6
  43. data/app/components/dsfr_component/phase_banner_component.rb +0 -25
  44. data/app/components/dsfr_component/section_break_component.rb +0 -49
  45. data/app/components/dsfr_component/start_button_component.rb +0 -55
  46. data/app/components/dsfr_component/summary_list_component/action_component.rb +0 -42
  47. data/app/components/dsfr_component/summary_list_component/key_component.rb +0 -23
  48. data/app/components/dsfr_component/summary_list_component/row_component.rb +0 -57
  49. data/app/components/dsfr_component/summary_list_component/value_component.rb +0 -23
  50. data/app/components/dsfr_component/summary_list_component.html.erb +0 -5
  51. data/app/components/dsfr_component/summary_list_component.rb +0 -49
  52. data/app/components/dsfr_component/tab_component.html.erb +0 -11
  53. data/app/components/dsfr_component/tab_component.rb +0 -61
  54. data/app/components/dsfr_component/table_component/body_component.html.erb +0 -5
  55. data/app/components/dsfr_component/table_component/body_component.rb +0 -21
  56. data/app/components/dsfr_component/table_component/caption_component.rb +0 -37
  57. data/app/components/dsfr_component/table_component/cell_component.rb +0 -57
  58. data/app/components/dsfr_component/table_component/head_component.html.erb +0 -5
  59. data/app/components/dsfr_component/table_component/head_component.rb +0 -23
  60. data/app/components/dsfr_component/table_component/row_component.html.erb +0 -5
  61. data/app/components/dsfr_component/table_component/row_component.rb +0 -30
  62. data/app/components/dsfr_component/table_component.html.erb +0 -7
  63. data/app/components/dsfr_component/table_component.rb +0 -35
  64. data/app/components/dsfr_component/warning_text_component.rb +0 -37
@@ -1,61 +0,0 @@
1
- class DsfrComponent::TabComponent < DsfrComponent::Base
2
- using HTMLAttributesUtils
3
-
4
- renders_many :tabs, "Tab"
5
-
6
- attr_reader :title, :id
7
-
8
- def initialize(title:, id: nil, classes: [], html_attributes: {})
9
- @title = title
10
- @id = id
11
-
12
- super(classes: classes, html_attributes: html_attributes)
13
- end
14
-
15
- private
16
-
17
- def default_attributes
18
- { id: id, class: %w(govuk-tabs), data: { module: 'govuk-tabs' } }
19
- end
20
-
21
- class Tab < DsfrComponent::Base
22
- attr_reader :label, :text
23
-
24
- def initialize(label:, text: nil, classes: [], html_attributes: {})
25
- @label = label
26
- @text = text
27
-
28
- super(classes: classes, html_attributes: html_attributes)
29
- end
30
-
31
- def id(prefix: nil)
32
- [prefix, label.parameterize].join
33
- end
34
-
35
- def hidden_class(i = nil)
36
- return [] if i&.zero?
37
-
38
- %w(fr-tabs__panel--hidden)
39
- end
40
-
41
- def li_classes(i = nil)
42
- class_names("govuk-tabs__list-item", "govuk-tabs__list-item--selected" => i&.zero?).split
43
- end
44
-
45
- def li_link
46
- link_to(label, id(prefix: '#'), class: "govuk-tabs__tab")
47
- end
48
-
49
- def default_attributes
50
- { id: id, class: %w(fr-tabs__panel) }
51
- end
52
-
53
- def combined_attributes(i)
54
- html_attributes.deep_merge_html_attributes({ class: hidden_class(i) }).deep_tidy_html_attributes
55
- end
56
-
57
- def call
58
- content || text || fail(ArgumentError, "no text or content")
59
- end
60
- end
61
- end
@@ -1,5 +0,0 @@
1
- <%= tag.tbody(**html_attributes) do %>
2
- <% rows.each do |row| %>
3
- <%= row %>
4
- <% end %>
5
- <% end %>
@@ -1,21 +0,0 @@
1
- class DsfrComponent::TableComponent::BodyComponent < DsfrComponent::Base
2
- renders_many :rows, "DsfrComponent::TableComponent::RowComponent"
3
-
4
- def initialize(rows: nil, first_cell_is_header: false, classes: [], html_attributes: {})
5
- super(classes: classes, html_attributes: html_attributes)
6
-
7
- build_rows_from_row_data(rows, first_cell_is_header)
8
- end
9
-
10
- private
11
-
12
- def build_rows_from_row_data(data, first_cell_is_header)
13
- return if data.blank?
14
-
15
- data.each { |d| row(cell_data: d, first_cell_is_header: first_cell_is_header) }
16
- end
17
-
18
- def default_attributes
19
- { class: %w(govuk-table__body) }
20
- end
21
- end
@@ -1,37 +0,0 @@
1
- class DsfrComponent::TableComponent::CaptionComponent < DsfrComponent::Base
2
- attr_reader :text, :size
3
-
4
- SIZES = %w(s m l xl).freeze
5
-
6
- def initialize(text: nil, id: nil, size: 'm', classes: [], html_attributes: {})
7
- @id = id
8
- @text = text
9
- @size = size
10
-
11
- super(classes: classes, html_attributes: html_attributes)
12
- end
13
-
14
- def call
15
- tag.caption(caption_content, **html_attributes)
16
- end
17
-
18
- def render?
19
- caption_content.present?
20
- end
21
-
22
- private
23
-
24
- def caption_content
25
- @caption_content ||= (content || text)
26
- end
27
-
28
- def default_attributes
29
- { class: class_names("govuk-table__caption", caption_size_class => size).split }
30
- end
31
-
32
- def caption_size_class
33
- fail(ArgumentError, "bad size #{size}, must be in #{SIZES}") unless size.in?(SIZES)
34
-
35
- %(govuk-table__caption--#{size})
36
- end
37
- end
@@ -1,57 +0,0 @@
1
- class DsfrComponent::TableComponent::CellComponent < DsfrComponent::Base
2
- attr_reader :text, :header, :numeric, :width
3
-
4
- alias_method :numeric?, :numeric
5
-
6
- WIDTHS = {
7
- "full" => "govuk-!-width-full",
8
- "three-quarters" => "govuk-!-width-three-quarters",
9
- "two-thirds" => "govuk-!-width-two-thirds",
10
- "one-half" => "govuk-!-width-one-half",
11
- "one-third" => "govuk-!-width-one-third",
12
- "one-quarter" => "govuk-!-width-one-quarter",
13
- }.freeze
14
-
15
- def initialize(header: false, text: nil, numeric: false, width: nil, classes: [], html_attributes: {})
16
- @header = header
17
- @text = text
18
- @numeric = numeric
19
- @width = width
20
-
21
- super(classes: classes, html_attributes: html_attributes)
22
- end
23
-
24
- def call
25
- content_tag(cell_element, cell_content, **html_attributes)
26
- end
27
-
28
- private
29
-
30
- def width?
31
- width.present?
32
- end
33
-
34
- def cell_content
35
- content || text
36
- end
37
-
38
- def cell_element
39
- header ? :th : :td
40
- end
41
-
42
- def default_attributes
43
- { class: default_classes }
44
- end
45
-
46
- def default_classes
47
- if header
48
- class_names("govuk-table__header", "govuk-table__header--numeric" => numeric?, width_class => width?).split
49
- else
50
- class_names("govuk-table__cell", "govuk-table__cell--numeric" => numeric?, width_class => width?).split
51
- end
52
- end
53
-
54
- def width_class
55
- WIDTHS.fetch(width, nil)
56
- end
57
- end
@@ -1,5 +0,0 @@
1
- <%= tag.thead(**html_attributes) do %>
2
- <% rows.each do |row| %>
3
- <%= row %>
4
- <% end %>
5
- <% end %>
@@ -1,23 +0,0 @@
1
- class DsfrComponent::TableComponent::HeadComponent < DsfrComponent::Base
2
- renders_many :rows, "DsfrComponent::TableComponent::RowComponent"
3
-
4
- attr_reader :row_data
5
-
6
- def initialize(rows: nil, classes: [], html_attributes: {})
7
- super(classes: classes, html_attributes: html_attributes)
8
-
9
- build_rows_from_row_data(rows)
10
- end
11
-
12
- private
13
-
14
- def build_rows_from_row_data(data)
15
- return if data.blank?
16
-
17
- data.each { |d| row(cell_data: d, header: true) }
18
- end
19
-
20
- def default_attributes
21
- { class: %w(govuk-table__head) }
22
- end
23
- end
@@ -1,5 +0,0 @@
1
- <%= tag.tr(**html_attributes) do %>
2
- <% cells.each do |cell| %>
3
- <%= cell %>
4
- <% end %>
5
- <% end %>
@@ -1,30 +0,0 @@
1
- class DsfrComponent::TableComponent::RowComponent < DsfrComponent::Base
2
- renders_many :cells, "DsfrComponent::TableComponent::CellComponent"
3
-
4
- attr_reader :header, :first_cell_is_header
5
-
6
- def initialize(cell_data: nil, first_cell_is_header: false, header: false, classes: [], html_attributes: {})
7
- @header = header
8
- @first_cell_is_header = first_cell_is_header
9
-
10
- super(classes: classes, html_attributes: html_attributes)
11
-
12
- build_cells_from_cell_data(cell_data)
13
- end
14
-
15
- private
16
-
17
- def build_cells_from_cell_data(cell_data)
18
- return if cell_data.blank?
19
-
20
- cell_data.map.with_index { |cd, i| cell(header: cell_is_header?(i), text: cd) }
21
- end
22
-
23
- def cell_is_header?(count)
24
- header || (first_cell_is_header && count.zero?)
25
- end
26
-
27
- def default_attributes
28
- { class: %w(govuk-table__row) }
29
- end
30
- end
@@ -1,7 +0,0 @@
1
- <%= tag.table(**html_attributes) do %>
2
- <%= caption %>
3
- <%= head %>
4
- <% bodies.each do |body| %>
5
- <%= body %>
6
- <% end %>
7
- <% end %>
@@ -1,35 +0,0 @@
1
- module DsfrComponent
2
- class TableComponent < DsfrComponent::Base
3
- renders_one :caption, "DsfrComponent::TableComponent::CaptionComponent"
4
- renders_one :head, "DsfrComponent::TableComponent::HeadComponent"
5
- renders_many :bodies, "DsfrComponent::TableComponent::BodyComponent"
6
-
7
- attr_accessor :id, :first_cell_is_header, :caption_text
8
-
9
- def initialize(id: nil, rows: nil, head: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {})
10
- @id = id
11
- @first_cell_is_header = first_cell_is_header
12
- @caption_text = caption
13
-
14
- super(classes: classes, html_attributes: html_attributes)
15
-
16
- # when no rows are passed in it's likely we're taking the slot approach
17
- return unless rows.presence
18
-
19
- # if no head is passed in,use the first row for headers
20
- build(*(head ? [head, rows] : [rows[0], rows[1..]]), caption_text)
21
- end
22
-
23
- private
24
-
25
- def build(head_data, body_data, caption_text)
26
- caption(text: caption_text)
27
- head(rows: [head_data])
28
- body(rows: body_data, first_cell_is_header: first_cell_is_header)
29
- end
30
-
31
- def default_attributes
32
- { id: id, class: %w(govuk-table) }
33
- end
34
- end
35
- end
@@ -1,37 +0,0 @@
1
- class DsfrComponent::WarningTextComponent < DsfrComponent::Base
2
- attr_reader :text, :icon, :icon_fallback_text
3
-
4
- def initialize(text: nil, icon_fallback_text: config.default_warning_text_icon_fallback_text, icon: config.default_warning_text_icon, classes: [], html_attributes: {})
5
- @text = text
6
- @icon = icon
7
- @icon_fallback_text = icon_fallback_text
8
-
9
- super(classes: classes, html_attributes: html_attributes)
10
- end
11
-
12
- def call
13
- tag.div(**html_attributes) do
14
- safe_join([icon_element, warning_text])
15
- end
16
- end
17
-
18
- private
19
-
20
- def icon_element
21
- tag.span(icon, class: 'govuk-warning-text__icon', aria: { hidden: true })
22
- end
23
-
24
- def warning_text
25
- tag.strong(class: 'govuk-warning-text__text') do
26
- safe_join([assistive, (content || text)])
27
- end
28
- end
29
-
30
- def assistive
31
- tag.span(icon_fallback_text, class: 'govuk-warning-text__assistive')
32
- end
33
-
34
- def default_attributes
35
- { class: %w(govuk-warning-text) }
36
- end
37
- end