polaris_view_components 0.3.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/polaris_view_components/button_controller.js +48 -0
  4. data/app/assets/javascripts/polaris_view_components/index.js +11 -1
  5. data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
  6. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +24 -0
  7. data/app/assets/javascripts/polaris_view_components/popover_controller.js +45 -0
  8. data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
  9. data/app/assets/javascripts/polaris_view_components/select_controller.js +6 -4
  10. data/app/assets/javascripts/polaris_view_components.js +1539 -5
  11. data/app/assets/stylesheets/polaris_view_components/custom.css +68 -0
  12. data/app/assets/stylesheets/polaris_view_components/shopify_navigation.css +0 -4
  13. data/app/assets/stylesheets/polaris_view_components/spacer_component.css +39 -0
  14. data/app/assets/stylesheets/polaris_view_components.css +93 -3
  15. data/app/assets/stylesheets/polaris_view_components.postcss.css +2 -0
  16. data/app/components/polaris/action.rb +3 -3
  17. data/app/components/polaris/action_list/item_component.html.erb +35 -0
  18. data/app/components/polaris/action_list/item_component.rb +41 -0
  19. data/app/components/polaris/action_list/section_component.html.erb +16 -0
  20. data/app/components/polaris/action_list/section_component.rb +26 -0
  21. data/app/components/polaris/action_list_component.html.erb +13 -0
  22. data/app/components/polaris/action_list_component.rb +25 -0
  23. data/app/components/polaris/application_component.rb +19 -19
  24. data/app/components/polaris/avatar_component.rb +1 -1
  25. data/app/components/polaris/badge_component.rb +1 -1
  26. data/app/components/polaris/banner_component.rb +6 -6
  27. data/app/components/polaris/base_button.rb +1 -1
  28. data/app/components/polaris/button_component.html.erb +13 -0
  29. data/app/components/polaris/button_group_component.rb +5 -5
  30. data/app/components/polaris/callout_card_component.rb +5 -5
  31. data/app/components/polaris/caption_component.rb +2 -2
  32. data/app/components/polaris/card/header_component.rb +1 -3
  33. data/app/components/polaris/card/section_component.rb +6 -2
  34. data/app/components/polaris/card_component.html.erb +4 -0
  35. data/app/components/polaris/card_component.rb +5 -6
  36. data/app/components/polaris/character_count.rb +10 -10
  37. data/app/components/polaris/checkbox_component.rb +4 -4
  38. data/app/components/polaris/choice_component.rb +1 -1
  39. data/app/components/polaris/choice_list_component.rb +4 -4
  40. data/app/components/polaris/data_table/cell_component.html.erb +18 -0
  41. data/app/components/polaris/data_table/cell_component.rb +49 -0
  42. data/app/components/polaris/data_table/column_component.rb +19 -0
  43. data/app/components/polaris/data_table_component.html.erb +77 -0
  44. data/app/components/polaris/data_table_component.rb +42 -0
  45. data/app/components/polaris/description_list_component.rb +3 -3
  46. data/app/components/polaris/display_text_component.rb +2 -2
  47. data/app/components/polaris/dropzone/component.rb +36 -38
  48. data/app/components/polaris/empty_state_component.html.erb +16 -11
  49. data/app/components/polaris/empty_state_component.rb +4 -3
  50. data/app/components/polaris/exception_list/item_component.rb +2 -2
  51. data/app/components/polaris/exception_list_component.rb +1 -1
  52. data/app/components/polaris/filters_component.html.erb +13 -0
  53. data/app/components/polaris/filters_component.rb +38 -0
  54. data/app/components/polaris/footer_help_component.rb +1 -1
  55. data/app/components/polaris/form_layout/group_component.rb +3 -3
  56. data/app/components/polaris/form_layout/item_component.rb +1 -1
  57. data/app/components/polaris/form_layout_component.rb +3 -3
  58. data/app/components/polaris/heading_component.rb +1 -1
  59. data/app/components/polaris/headless_button.html.erb +13 -0
  60. data/app/components/polaris/headless_button.rb +17 -5
  61. data/app/components/polaris/icon_component.rb +2 -2
  62. data/app/components/polaris/index_table/cell_component.rb +22 -0
  63. data/app/components/polaris/index_table/column_component.rb +13 -0
  64. data/app/components/polaris/index_table_component.html.erb +28 -0
  65. data/app/components/polaris/index_table_component.rb +25 -0
  66. data/app/components/polaris/inline_error_component.html.erb +2 -2
  67. data/app/components/polaris/inline_error_component.rb +7 -1
  68. data/app/components/polaris/label_component.rb +2 -2
  69. data/app/components/polaris/labelled_component.rb +2 -2
  70. data/app/components/polaris/layout/annotated_section.rb +1 -1
  71. data/app/components/polaris/layout/section.rb +2 -0
  72. data/app/components/polaris/layout_component.rb +3 -3
  73. data/app/components/polaris/link_component.rb +5 -3
  74. data/app/components/polaris/list_component.rb +3 -3
  75. data/app/components/polaris/modal/section_component.rb +19 -0
  76. data/app/components/polaris/modal_component.html.erb +79 -0
  77. data/app/components/polaris/modal_component.rb +98 -0
  78. data/app/components/polaris/page_actions_component.rb +21 -6
  79. data/app/components/polaris/page_component.rb +4 -4
  80. data/app/components/polaris/pagination_component.rb +1 -5
  81. data/app/components/polaris/popover/pane_component.html.erb +25 -0
  82. data/app/components/polaris/popover/pane_component.rb +20 -0
  83. data/app/components/polaris/popover/section_component.rb +19 -0
  84. data/app/components/polaris/popover_component.html.erb +38 -0
  85. data/app/components/polaris/popover_component.rb +90 -0
  86. data/app/components/polaris/progress_bar_component.rb +5 -5
  87. data/app/components/polaris/radio_button_component.rb +3 -3
  88. data/app/components/polaris/resource_item_component.html.erb +16 -6
  89. data/app/components/polaris/resource_item_component.rb +42 -9
  90. data/app/components/polaris/resource_list_component.html.erb +10 -0
  91. data/app/components/polaris/resource_list_component.rb +4 -10
  92. data/app/components/polaris/scrollable_component.html.erb +5 -0
  93. data/app/components/polaris/scrollable_component.rb +48 -0
  94. data/app/components/polaris/select_component.rb +10 -5
  95. data/app/components/polaris/setting_toggle_component.html.erb +10 -0
  96. data/app/components/polaris/setting_toggle_component.rb +24 -0
  97. data/app/components/polaris/shopify_navigation_component.rb +6 -6
  98. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  99. data/app/components/polaris/spacer_component.rb +50 -0
  100. data/app/components/polaris/spinner_component.rb +2 -2
  101. data/app/components/polaris/stack_component.rb +5 -5
  102. data/app/components/polaris/subheading_component.rb +1 -1
  103. data/app/components/polaris/tabs/tab_component.html.erb +10 -0
  104. data/app/components/polaris/tabs/tab_component.rb +34 -0
  105. data/app/components/polaris/tabs_component.html.erb +7 -0
  106. data/app/components/polaris/tabs_component.rb +37 -0
  107. data/app/components/polaris/tag_component.rb +2 -2
  108. data/app/components/polaris/text_container_component.rb +2 -2
  109. data/app/components/polaris/text_field_component.rb +8 -8
  110. data/app/components/polaris/text_style_component.rb +11 -2
  111. data/app/components/polaris/thumbnail_component.rb +2 -2
  112. data/app/helpers/polaris/form_builder.rb +30 -3
  113. data/app/helpers/polaris/url_helper.rb +3 -3
  114. data/app/helpers/polaris/view_helper.rb +26 -6
  115. data/app/validators/type_validator.rb +2 -2
  116. data/lib/generators/polaris_view_components/install_generator.rb +5 -5
  117. data/lib/polaris/view_components/engine.rb +6 -1
  118. data/lib/polaris/view_components/version.rb +1 -1
  119. data/lib/polaris_view_components.rb +1 -1
  120. metadata +45 -6
  121. data/app/components/polaris/choice_list/component.html.erb +0 -34
  122. data/app/components/polaris/choice_list/component.rb +0 -65
  123. data/app/helpers/polaris/action_helper.rb +0 -14
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class ScrollableComponent < Polaris::NewComponent
5
+ def initialize(
6
+ height: nil,
7
+ width: nil,
8
+ vertical: true,
9
+ horizontal: false,
10
+ shadow: false,
11
+ focusable: false,
12
+ **system_arguments
13
+ )
14
+ @height = height
15
+ @width = width
16
+ @vertical = vertical
17
+ @horizontal = horizontal
18
+ @shadow = shadow
19
+ @focusable = focusable
20
+ @system_arguments = system_arguments
21
+ end
22
+
23
+ def system_arguments
24
+ {
25
+ tag: "div",
26
+ data: {
27
+ polaris_scrollable_shadow_value: @shadow,
28
+ polaris_scrollable_top_shadow_class: "Polaris-Scrollable--hasTopShadow",
29
+ polaris_scrollable_bottom_shadow_class: "Polaris-Scrollable--hasBottomShadow"
30
+ }
31
+ }.deep_merge(@system_arguments).tap do |opts|
32
+ prepend_option(opts[:data], :controller, "polaris-scrollable")
33
+ opts[:tabindex] = "0" if @focusable
34
+ opts[:classes] = class_names(
35
+ @system_arguments[:classes],
36
+ "Polaris-Scrollable",
37
+ "Polaris-Scrollable--horizontal" => @horizontal,
38
+ "Polaris-Scrollable--vertical" => @vertical
39
+ )
40
+ opts[:style] = class_names(
41
+ @system_arguments[:style],
42
+ "height: #{@height};" => @height.present?,
43
+ "width: #{@width};" => @width.present?
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
@@ -3,10 +3,10 @@
3
3
  module Polaris
4
4
  class SelectComponent < Polaris::NewComponent
5
5
  def initialize(
6
+ options:,
6
7
  form: nil,
7
8
  attribute: nil,
8
9
  name: nil,
9
- options:,
10
10
  selected: nil,
11
11
  disabled_options: nil,
12
12
  label: nil,
@@ -37,11 +37,12 @@ module Polaris
37
37
  @system_arguments[:tag] = "div"
38
38
  @system_arguments[:data] ||= {}
39
39
  prepend_option(@system_arguments[:data], :controller, "polaris-select")
40
+ prepend_option(@system_arguments[:data], :selected_value, @selected)
40
41
  @system_arguments[:classes] = class_names(
41
42
  @system_arguments[:classes],
42
43
  "Polaris-Select",
43
44
  "Polaris-Select--disabled": disabled,
44
- "Polaris-Select--error": error,
45
+ "Polaris-Select--error": error
45
46
  )
46
47
 
47
48
  @wrapper_arguments = {
@@ -53,15 +54,17 @@ module Polaris
53
54
  label_action: label_action,
54
55
  required: required,
55
56
  help_text: help_text,
56
- error: error,
57
+ error: error
57
58
  }.merge(wrapper_arguments)
58
59
 
59
- @select_options = {}
60
+ @select_options = select_options
60
61
 
61
62
  @input_options = input_options
63
+ @input_options.deep_merge!(select_options) unless @form
62
64
  @input_options[:class] = class_names(@input_options[:classes], "Polaris-Select__Input")
63
65
  @input_options[:disabled] = disabled
64
66
  @input_options[:data] ||= {}
67
+ prepend_option(@input_options[:data], :polaris_select_target, "select")
65
68
  prepend_option(@input_options[:data], :action, "polaris-select#update")
66
69
  end
67
70
 
@@ -71,7 +74,9 @@ module Polaris
71
74
 
72
75
  def selected_option
73
76
  option = @options.to_a.find { |i| i.last.to_s == @selected.to_s }
74
- option ? option.first : @options.first.first
77
+ return unless option
78
+
79
+ option.first
75
80
  end
76
81
  end
77
82
  end
@@ -0,0 +1,10 @@
1
+ <%= polaris_card do %>
2
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
3
+ <div class="Polaris-SettingAction__Setting">
4
+ <%= content %>
5
+ </div>
6
+ <div class="Polaris-SettingAction__Action">
7
+ <%= action %>
8
+ </div>
9
+ <% end %>
10
+ <% end %>
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class SettingToggleComponent < Polaris::NewComponent
5
+ renders_one :action, ->(**system_arguments) do
6
+ Polaris::ButtonComponent.new(primary: !@enabled, **system_arguments)
7
+ end
8
+
9
+ def initialize(enabled: false, **system_arguments)
10
+ @enabled = enabled
11
+ @system_arguments = system_arguments
12
+ end
13
+
14
+ def system_arguments
15
+ @system_arguments.tap do |opts|
16
+ opts[:tag] = "div"
17
+ opts[:classes] = class_names(
18
+ @system_arguments[:classes],
19
+ "Polaris-SettingAction"
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Polaris
4
4
  class ShopifyNavigationComponent < Polaris::NewComponent
5
- renders_many :links, -> (**system_arguments) do
5
+ renders_many :links, ->(**system_arguments) do
6
6
  ShopifyNavigationLinkComponent.new(auto_detect_active: @auto_detect_active, **system_arguments)
7
7
  end
8
8
 
@@ -13,7 +13,7 @@ module Polaris
13
13
  @system_arguments[:tag] = "div"
14
14
  @system_arguments[:classes] = class_names(
15
15
  @system_arguments[:classes],
16
- "shp-Navigation",
16
+ "shp-Navigation"
17
17
  )
18
18
  end
19
19
 
@@ -42,13 +42,13 @@ module Polaris
42
42
  tag: "a",
43
43
  href: @url,
44
44
  role: "tab",
45
- data: { polaris_unstyled: true },
46
- aria: {},
45
+ data: {polaris_unstyled: true},
46
+ aria: {}
47
47
  }.deep_merge(@system_arguments).tap do |args|
48
48
  args[:aria][:selected] = @active || detect_active(@url)
49
49
  args[:classes] = class_names(
50
50
  args[:classes],
51
- "shp-Navigation_Link",
51
+ "shp-Navigation_Link"
52
52
  )
53
53
  end
54
54
  end
@@ -56,7 +56,7 @@ module Polaris
56
56
  def detect_active(url)
57
57
  return unless @auto_detect_active
58
58
 
59
- request.path.include?(url.split('?').first)
59
+ request.path.include?(url.split("?").first)
60
60
  end
61
61
  end
62
62
  end
@@ -8,7 +8,7 @@ module Polaris
8
8
  @system_arguments[:tag] = "div"
9
9
  @system_arguments[:classes] = class_names(
10
10
  @system_arguments[:classes],
11
- "Polaris-SkeletonBodyText__SkeletonBodyTextContainer",
11
+ "Polaris-SkeletonBodyText__SkeletonBodyTextContainer"
12
12
  )
13
13
  end
14
14
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class SpacerComponent < Polaris::NewComponent
5
+ VERTICAL_SPACING_DEFAULT = :default
6
+ VERTICAL_SPACING_MAPPINGS = {
7
+ VERTICAL_SPACING_DEFAULT => "",
8
+ :extra_tight => "Polaris-Spacer--verticalSpacingExtraTight",
9
+ :tight => "Polaris-Spacer--verticalSpacingTight",
10
+ :base_tight => "Polaris-Spacer--verticalSpacingBaseTight",
11
+ :base => "Polaris-Spacer--verticalSpacingBase",
12
+ :loose => "Polaris-Spacer--verticalSpacingLoose",
13
+ :extra_loose => "Polaris-Spacer--verticalSpacingExtraLoose"
14
+ }
15
+ VERTICAL_SPACING_OPTIONS = VERTICAL_SPACING_MAPPINGS.keys
16
+
17
+ HORIZONTAL_SPACING_DEFAULT = :default
18
+ HORIZONTAL_SPACING_MAPPINGS = {
19
+ HORIZONTAL_SPACING_DEFAULT => "",
20
+ :extra_tight => "Polaris-Spacer--horizontalSpacingExtraTight",
21
+ :tight => "Polaris-Spacer--horizontalSpacingTight",
22
+ :base_tight => "Polaris-Spacer--horizontalSpacingBaseTight",
23
+ :base => "Polaris-Spacer--horizontalSpacingBase",
24
+ :loose => "Polaris-Spacer--horizontalSpacingLoose",
25
+ :extra_loose => "Polaris-Spacer--horizontalSpacingExtraLoose"
26
+ }
27
+ HORIZONTAL_SPACING_OPTIONS = HORIZONTAL_SPACING_MAPPINGS.keys
28
+
29
+ def initialize(
30
+ vertical: VERTICAL_SPACING_DEFAULT,
31
+ horizontal: HORIZONTAL_SPACING_DEFAULT,
32
+ **system_arguments
33
+ )
34
+ @system_arguments = system_arguments
35
+ @system_arguments[:tag] = "div"
36
+ @system_arguments[:classes] = class_names(
37
+ @system_arguments[:classes],
38
+ "Polaris-Spacer",
39
+ VERTICAL_SPACING_MAPPINGS[fetch_or_fallback(VERTICAL_SPACING_OPTIONS, vertical, VERTICAL_SPACING_DEFAULT)],
40
+ HORIZONTAL_SPACING_MAPPINGS[fetch_or_fallback(HORIZONTAL_SPACING_OPTIONS, horizontal, HORIZONTAL_SPACING_DEFAULT)]
41
+ )
42
+ end
43
+
44
+ def call
45
+ render(Polaris::BaseComponent.new(**@system_arguments)) do
46
+ content
47
+ end
48
+ end
49
+ end
50
+ end
@@ -5,7 +5,7 @@ module Polaris
5
5
  SIZE_DEFAULT = :large
6
6
  SIZE_MAPPINGS = {
7
7
  small: "Polaris-Spinner--sizeSmall",
8
- large: "Polaris-Spinner--sizeLarge",
8
+ large: "Polaris-Spinner--sizeLarge"
9
9
  }
10
10
  SIZE_OPTIONS = SIZE_MAPPINGS.keys
11
11
 
@@ -18,7 +18,7 @@ module Polaris
18
18
  @system_arguments[:classes] = class_names(
19
19
  @system_arguments[:classes],
20
20
  "Polaris-Spinner",
21
- SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
21
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
22
22
  )
23
23
  end
24
24
  end
@@ -9,7 +9,7 @@ module Polaris
9
9
  :trailing => "Polaris-Stack--alignmentTrailing",
10
10
  :center => "Polaris-Stack--alignmentCenter",
11
11
  :fill => "Polaris-Stack--alignmentFill",
12
- :baseline => "Polaris-Stack--alignmentBaseline",
12
+ :baseline => "Polaris-Stack--alignmentBaseline"
13
13
  }
14
14
  ALIGNMENT_OPTIONS = ALIGNMENT_MAPPINGS.keys
15
15
 
@@ -21,7 +21,7 @@ module Polaris
21
21
  :trailing => "Polaris-Stack--distributionTrailing",
22
22
  :center => "Polaris-Stack--distributionCenter",
23
23
  :fill => "Polaris-Stack--distributionFill",
24
- :fill_evently => "Polaris-Stack--distributionFillEvenly",
24
+ :fill_evenly => "Polaris-Stack--distributionFillEvenly"
25
25
  }
26
26
  DISTRIBUTION_OPTIONS = DISTRIBUTION_MAPPINGS.keys
27
27
 
@@ -33,7 +33,7 @@ module Polaris
33
33
  :base_tight => "Polaris-Stack--spacingBaseTight",
34
34
  :loose => "Polaris-Stack--spacingLoose",
35
35
  :extra_loose => "Polaris-Stack--spacingExtraLoose",
36
- :none => "Polaris-Stack--spacingNone",
36
+ :none => "Polaris-Stack--spacingNone"
37
37
  }
38
38
  SPACING_OPTIONS = SPACING_MAPPINGS.keys
39
39
 
@@ -56,7 +56,7 @@ module Polaris
56
56
  DISTRIBUTION_MAPPINGS[fetch_or_fallback(DISTRIBUTION_OPTIONS, distribution, DISTRIBUTION_DEFAULT)],
57
57
  SPACING_MAPPINGS[fetch_or_fallback(SPACING_OPTIONS, spacing, SPACING_DEFAULT)],
58
58
  "Polaris-Stack--vertical": vertical,
59
- "Polaris-Stack--noWrap": !wrap,
59
+ "Polaris-Stack--noWrap": !wrap
60
60
  )
61
61
  end
62
62
 
@@ -67,7 +67,7 @@ module Polaris
67
67
  @system_arguments[:classes] = class_names(
68
68
  @system_arguments[:classes],
69
69
  "Polaris-Stack__Item",
70
- "Polaris-Stack__Item--fill": fill,
70
+ "Polaris-Stack__Item--fill": fill
71
71
  )
72
72
  end
73
73
 
@@ -13,7 +13,7 @@ module Polaris
13
13
  @system_arguments[:tag] = element
14
14
  @system_arguments[:classes] = class_names(
15
15
  @system_arguments[:classes],
16
- 'Polaris-Subheading'
16
+ "Polaris-Subheading"
17
17
  )
18
18
  end
19
19
 
@@ -0,0 +1,10 @@
1
+ <li class="Polaris-Tabs__TabContainer" role="presentation">
2
+ <%= render(Polaris::BaseComponent.new(**system_arguments)) do %>
3
+ <span class="Polaris-Tabs__Title">
4
+ <%= @title %>
5
+ <% if badge.present? %>
6
+ <%= badge %>
7
+ <% end %>
8
+ </span>
9
+ <% end %>
10
+ </li>
@@ -0,0 +1,34 @@
1
+ class Polaris::Tabs::TabComponent < Polaris::NewComponent
2
+ renders_one :badge, Polaris::BadgeComponent
3
+
4
+ def initialize(
5
+ title:,
6
+ url: nil,
7
+ active: false,
8
+ **system_arguments
9
+ )
10
+ @title = title
11
+ @url = url
12
+ @active = active
13
+ @system_arguments = system_arguments
14
+ end
15
+
16
+ def system_arguments
17
+ @system_arguments.tap do |opts|
18
+ opts[:rol] = "tab"
19
+ opts[:tabindex] = "0"
20
+ if @url.present?
21
+ opts[:tag] = "a"
22
+ opts[:href] = @url
23
+ else
24
+ opts[:tag] = "button"
25
+ opts[:type] = "button"
26
+ end
27
+ opts[:classes] = class_names(
28
+ @system_arguments[:classes],
29
+ "Polaris-Tabs__Tab",
30
+ "Polaris-Tabs__Tab--selected": @active
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ <%= render(Polaris::BaseComponent.new(**wrapper_arguments)) do %>
2
+ <%= render(Polaris::BaseComponent.new(**system_arguments)) do %>
3
+ <% tabs.each do |tab| %>
4
+ <%= tab %>
5
+ <% end %>
6
+ <% end %>
7
+ <% end %>
@@ -0,0 +1,37 @@
1
+ module Polaris
2
+ class TabsComponent < Polaris::NewComponent
3
+ renders_many :tabs, Polaris::Tabs::TabComponent
4
+
5
+ def initialize(fitted: false, wrapper_arguments: {}, **system_arguments)
6
+ @fitted = fitted
7
+ @wrapper_arguments = wrapper_arguments
8
+ @system_arguments = system_arguments
9
+ end
10
+
11
+ def wrapper_arguments
12
+ @wrapper_arguments.tap do |opts|
13
+ opts[:tag] = "div"
14
+ opts[:classes] = class_names(
15
+ @wrapper_arguments[:classes],
16
+ "Polaris-Tabs__Wrapper"
17
+ )
18
+ end
19
+ end
20
+
21
+ def system_arguments
22
+ @system_arguments.tap do |opts|
23
+ opts[:tag] = "ul"
24
+ opts[:role] = "tablist"
25
+ opts[:classes] = class_names(
26
+ @system_arguments[:classes],
27
+ "Polaris-Tabs",
28
+ "Polaris-Tabs--fitted": @fitted
29
+ )
30
+ end
31
+ end
32
+
33
+ def renders?
34
+ tabs.present?
35
+ end
36
+ end
37
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Polaris
4
4
  class TagComponent < Polaris::NewComponent
5
- renders_one :remove_button, lambda { |**system_arguments|
5
+ renders_one :remove_button, ->(**system_arguments) do
6
6
  render Polaris::BaseButton.new(
7
7
  classes: "Polaris-Tag__Button",
8
8
  disabled: @disabled,
@@ -10,7 +10,7 @@ module Polaris
10
10
  ) do |button|
11
11
  polaris_icon(name: "CancelSmallMinor")
12
12
  end
13
- }
13
+ end
14
14
 
15
15
  def initialize(clickable: false, disabled: false, **system_arguments)
16
16
  @clickable = clickable
@@ -6,7 +6,7 @@ module Polaris
6
6
  SPACING_MAPPINGS = {
7
7
  SPACING_DEFAULT => "",
8
8
  :tight => "Polaris-TextContainer--spacingTight",
9
- :loose => "Polaris-TextContainer--spacingLoose",
9
+ :loose => "Polaris-TextContainer--spacingLoose"
10
10
  }
11
11
  SPACING_OPTIONS = SPACING_MAPPINGS.keys
12
12
 
@@ -19,7 +19,7 @@ module Polaris
19
19
  @system_arguments[:classes] = class_names(
20
20
  @system_arguments[:classes],
21
21
  "Polaris-TextContainer",
22
- SPACING_MAPPINGS[fetch_or_fallback(SPACING_OPTIONS, spacing, SPACING_DEFAULT)],
22
+ SPACING_MAPPINGS[fetch_or_fallback(SPACING_OPTIONS, spacing, SPACING_DEFAULT)]
23
23
  )
24
24
  end
25
25
 
@@ -13,7 +13,7 @@ module Polaris
13
13
  ALIGN_DEFAULT => "",
14
14
  :left => "Polaris-TextField__Input--alignLeft",
15
15
  :center => "Polaris-TextField__Input--alignCenter",
16
- :right => "Polaris-TextField__Input--alignRight",
16
+ :right => "Polaris-TextField__Input--alignRight"
17
17
  }
18
18
  ALIGN_OPTIONS = ALIGN_MAPPINGS.keys
19
19
 
@@ -96,7 +96,7 @@ module Polaris
96
96
  label_action: @label_action,
97
97
  required: @required,
98
98
  help_text: @help_text,
99
- error: @error,
99
+ error: @error
100
100
  }.deep_merge(@wrapper_arguments)
101
101
  end
102
102
 
@@ -105,8 +105,8 @@ module Polaris
105
105
  tag: "div",
106
106
  data: {
107
107
  polaris_text_field_has_value_class: "Polaris-TextField--hasValue",
108
- polaris_text_field_clear_button_hidden_class: "Polaris-TextField__ClearButton--hidden",
109
- },
108
+ polaris_text_field_clear_button_hidden_class: "Polaris-TextField__ClearButton--hidden"
109
+ }
110
110
  }.deep_merge(@system_arguments).tap do |opts|
111
111
  opts[:classes] = class_names(
112
112
  opts[:classes],
@@ -114,7 +114,7 @@ module Polaris
114
114
  "Polaris-TextField--disabled": @disabled,
115
115
  "Polaris-TextField--error": @error,
116
116
  "Polaris-TextField--hasValue": @value.present?,
117
- "Polaris-TextField--multiline": @multiline,
117
+ "Polaris-TextField--multiline": @multiline
118
118
  )
119
119
  prepend_option(opts[:data], :controller, "polaris-text-field")
120
120
  if @show_character_count
@@ -132,13 +132,13 @@ module Polaris
132
132
  placeholder: @placeholder,
133
133
  maxlength: @maxlength,
134
134
  minlength: @minlength,
135
- data: { polaris_text_field_target: "input" },
135
+ data: {polaris_text_field_target: "input"}
136
136
  }
137
137
  if @type == :number
138
138
  default_options.merge!({
139
139
  step: @step,
140
140
  min: @min,
141
- max: @max,
141
+ max: @max
142
142
  })
143
143
  end
144
144
  if @multiline
@@ -151,7 +151,7 @@ module Polaris
151
151
  "Polaris-TextField__Input",
152
152
  @align_class,
153
153
  "Polaris-TextField--monospaced": @monospaced,
154
- "Polaris-TextField__Input--suffixed": @suffix.present?,
154
+ "Polaris-TextField__Input--suffixed": @suffix.present?
155
155
  )
156
156
  prepend_option(opts[:data], :action, "polaris-text-field#syncValue")
157
157
  end
@@ -9,19 +9,28 @@ module Polaris
9
9
  :negative => "Polaris-TextStyle--variationNegative",
10
10
  :strong => "Polaris-TextStyle--variationStrong",
11
11
  :subdued => "Polaris-TextStyle--variationSubdued",
12
- :code => "Polaris-TextStyle--variationCode",
12
+ :code => "Polaris-TextStyle--variationCode"
13
13
  }
14
14
  VARIATION_OPTIONS = VARIATION_MAPPINGS.keys
15
15
 
16
+ SIZE_DEFAULT = :default
17
+ SIZE_MAPPINGS = {
18
+ SIZE_DEFAULT => "",
19
+ :small => "Polaris-TextStyle--sizeSmall"
20
+ }
21
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
22
+
16
23
  def initialize(
17
24
  variation: VARIATION_DEFAULT,
25
+ size: SIZE_DEFAULT,
18
26
  **system_arguments
19
27
  )
20
28
  @system_arguments = system_arguments
21
- @system_arguments[:tag] = 'span'
29
+ @system_arguments[:tag] = "span"
22
30
  @system_arguments[:classes] = class_names(
23
31
  @system_arguments[:classes],
24
32
  VARIATION_MAPPINGS[fetch_or_fallback(VARIATION_OPTIONS, variation, VARIATION_DEFAULT)],
33
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
25
34
  )
26
35
  end
27
36
 
@@ -6,7 +6,7 @@ module Polaris
6
6
  SIZE_MAPPINGS = {
7
7
  small: "Polaris-Thumbnail--sizeSmall",
8
8
  medium: "Polaris-Thumbnail--sizeMedium",
9
- large: "Polaris-Thumbnail--sizeLarge",
9
+ large: "Polaris-Thumbnail--sizeLarge"
10
10
  }
11
11
  SIZE_OPTIONS = SIZE_MAPPINGS.keys
12
12
 
@@ -26,7 +26,7 @@ module Polaris
26
26
  @system_arguments[:classes] = class_names(
27
27
  @system_arguments[:classes],
28
28
  "Polaris-Thumbnail",
29
- SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
29
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
30
30
  )
31
31
  end
32
32
 
@@ -1,5 +1,7 @@
1
1
  module Polaris
2
2
  class FormBuilder < ActionView::Helpers::FormBuilder
3
+ include ActionView::Helpers::OutputSafetyHelper
4
+
3
5
  attr_reader :template
4
6
 
5
7
  delegate :render, :pluralize, to: :template
@@ -12,11 +14,11 @@ module Polaris
12
14
 
13
15
  render Polaris::BannerComponent.new(
14
16
  title: "There's #{pluralize(object.errors.count, "error")} with this #{model_name}:",
15
- status: :critical,
17
+ status: :critical
16
18
  ) do
17
19
  render(Polaris::ListComponent.new) do |list|
18
20
  object.errors.each do |error|
19
- list.item { error.full_message }
21
+ list.item { error.full_message.html_safe }
20
22
  end
21
23
  end
22
24
  end
@@ -26,7 +28,16 @@ module Polaris
26
28
  return if object.blank?
27
29
  return unless object.errors.key?(method)
28
30
 
29
- object.errors.full_messages_for(method)&.first
31
+ raw object.errors.full_messages_for(method)&.first
32
+ end
33
+
34
+ def polaris_inline_error_for(method, **options, &block)
35
+ error_message = error_for(method)
36
+ return unless error_message
37
+
38
+ render(Polaris::InlineErrorComponent.new(**options, &block)) do
39
+ error_message
40
+ end
30
41
  end
31
42
 
32
43
  def polaris_text_field(method, **options, &block)
@@ -48,5 +59,21 @@ module Polaris
48
59
  end
49
60
  render Polaris::SelectComponent.new(form: self, attribute: method, **options, &block)
50
61
  end
62
+
63
+ def polaris_check_box(method, **options, &block)
64
+ options[:error] ||= error_for(method)
65
+ if options[:error_hidden] && options[:error]
66
+ options[:error] = !!options[:error]
67
+ end
68
+ render Polaris::CheckboxComponent.new(form: self, attribute: method, **options, &block)
69
+ end
70
+
71
+ def polaris_radio_button(method, **options, &block)
72
+ options[:error] ||= error_for(method)
73
+ if options[:error_hidden] && options[:error]
74
+ options[:error] = !!options[:error]
75
+ end
76
+ render Polaris::RadioButtonComponent.new(form: self, attribute: method, **options, &block)
77
+ end
51
78
  end
52
79
  end
@@ -1,14 +1,14 @@
1
1
  module Polaris
2
2
  module UrlHelper
3
3
  def polaris_button_to(name = nil, options = nil, html_options = nil, &block)
4
- html_options, options = options, name if block_given?
5
- options ||= {}
4
+ html_options, options = options, name if block
5
+ options ||= {}
6
6
  html_options ||= {}
7
7
  html_options[:classes] = html_options[:class]
8
8
  html_options.delete(:class)
9
9
 
10
10
  button = Polaris::HeadlessButton.new(submit: true, **html_options)
11
- button = button.with_content(name) unless block_given?
11
+ button = button.with_content(name) unless block
12
12
  content = render(button, &block)
13
13
 
14
14
  button_to(options, button.html_options) do