polaris_view_components 0.3.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -3
  3. data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +119 -0
  4. data/app/assets/javascripts/polaris_view_components/button_controller.js +47 -0
  5. data/app/assets/javascripts/polaris_view_components/frame_controller.js +41 -0
  6. data/app/assets/javascripts/polaris_view_components/index.js +19 -1
  7. data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
  8. data/app/assets/javascripts/polaris_view_components/option_list_controller.js +41 -0
  9. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +28 -0
  10. data/app/assets/javascripts/polaris_view_components/popover_controller.js +49 -0
  11. data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
  12. data/app/assets/javascripts/polaris_view_components/select_controller.js +6 -4
  13. data/app/assets/javascripts/polaris_view_components/text_field_controller.js +4 -0
  14. data/app/assets/javascripts/polaris_view_components/toast_controller.js +68 -0
  15. data/app/assets/javascripts/polaris_view_components.js +1936 -5
  16. data/app/assets/stylesheets/polaris_view_components/custom.css +109 -0
  17. data/app/assets/stylesheets/polaris_view_components/shopify_navigation.css +0 -4
  18. data/app/assets/stylesheets/polaris_view_components/spacer_component.css +39 -0
  19. data/app/assets/stylesheets/polaris_view_components.css +118 -3
  20. data/app/assets/stylesheets/polaris_view_components.postcss.css +2 -0
  21. data/app/components/polaris/action.rb +3 -3
  22. data/app/components/polaris/action_list/item_component.html.erb +35 -0
  23. data/app/components/polaris/action_list/item_component.rb +41 -0
  24. data/app/components/polaris/action_list/section_component.html.erb +16 -0
  25. data/app/components/polaris/action_list/section_component.rb +26 -0
  26. data/app/components/polaris/action_list_component.html.erb +13 -0
  27. data/app/components/polaris/action_list_component.rb +25 -0
  28. data/app/components/polaris/application_component.rb +19 -19
  29. data/app/components/polaris/autocomplete/action_component.rb +7 -0
  30. data/app/components/polaris/autocomplete/option_component.rb +35 -0
  31. data/app/components/polaris/autocomplete/section_component.html.erb +9 -0
  32. data/app/components/polaris/autocomplete/section_component.rb +12 -0
  33. data/app/components/polaris/autocomplete_component.html.erb +30 -0
  34. data/app/components/polaris/autocomplete_component.rb +58 -0
  35. data/app/components/polaris/avatar_component.rb +1 -1
  36. data/app/components/polaris/badge_component.rb +1 -1
  37. data/app/components/polaris/banner_component.rb +6 -6
  38. data/app/components/polaris/base_button.rb +1 -1
  39. data/app/components/polaris/base_checkbox.rb +48 -0
  40. data/app/components/polaris/base_radio_button.rb +38 -0
  41. data/app/components/polaris/button_component.html.erb +13 -0
  42. data/app/components/polaris/button_group_component.rb +5 -5
  43. data/app/components/polaris/callout_card_component.rb +5 -5
  44. data/app/components/polaris/caption_component.rb +2 -2
  45. data/app/components/polaris/card/header_component.rb +1 -3
  46. data/app/components/polaris/card/section_component.rb +6 -2
  47. data/app/components/polaris/card_component.html.erb +4 -0
  48. data/app/components/polaris/card_component.rb +5 -6
  49. data/app/components/polaris/character_count.rb +10 -10
  50. data/app/components/polaris/checkbox_component.html.erb +1 -5
  51. data/app/components/polaris/checkbox_component.rb +19 -12
  52. data/app/components/polaris/choice_component.rb +1 -1
  53. data/app/components/polaris/choice_list_component.rb +5 -5
  54. data/app/components/polaris/data_table/cell_component.html.erb +18 -0
  55. data/app/components/polaris/data_table/cell_component.rb +49 -0
  56. data/app/components/polaris/data_table/column_component.rb +19 -0
  57. data/app/components/polaris/data_table_component.html.erb +77 -0
  58. data/app/components/polaris/data_table_component.rb +42 -0
  59. data/app/components/polaris/description_list_component.rb +3 -3
  60. data/app/components/polaris/display_text_component.rb +2 -2
  61. data/app/components/polaris/dropzone/component.rb +36 -38
  62. data/app/components/polaris/empty_state_component.html.erb +16 -11
  63. data/app/components/polaris/empty_state_component.rb +4 -3
  64. data/app/components/polaris/exception_list/item_component.rb +2 -2
  65. data/app/components/polaris/exception_list_component.rb +1 -1
  66. data/app/components/polaris/filters_component.html.erb +35 -0
  67. data/app/components/polaris/filters_component.rb +91 -0
  68. data/app/components/polaris/footer_help_component.rb +1 -1
  69. data/app/components/polaris/form_layout/group_component.rb +3 -3
  70. data/app/components/polaris/form_layout/item_component.rb +1 -1
  71. data/app/components/polaris/form_layout_component.rb +3 -3
  72. data/app/components/polaris/frame/save_bar_component.html.erb +23 -0
  73. data/app/components/polaris/frame/save_bar_component.rb +31 -0
  74. data/app/components/polaris/frame/top_bar_component.html.erb +30 -0
  75. data/app/components/polaris/frame/top_bar_component.rb +18 -0
  76. data/app/components/polaris/frame_component.html.erb +44 -0
  77. data/app/components/polaris/frame_component.rb +33 -0
  78. data/app/components/polaris/heading_component.rb +1 -1
  79. data/app/components/polaris/headless_button.html.erb +13 -0
  80. data/app/components/polaris/headless_button.rb +17 -5
  81. data/app/components/polaris/icon_component.rb +2 -2
  82. data/app/components/polaris/index_table/cell_component.rb +22 -0
  83. data/app/components/polaris/index_table/column_component.rb +13 -0
  84. data/app/components/polaris/index_table_component.html.erb +28 -0
  85. data/app/components/polaris/index_table_component.rb +25 -0
  86. data/app/components/polaris/inline_error_component.html.erb +2 -2
  87. data/app/components/polaris/inline_error_component.rb +7 -1
  88. data/app/components/polaris/label_component.rb +2 -2
  89. data/app/components/polaris/labelled_component.rb +2 -2
  90. data/app/components/polaris/layout/annotated_section.rb +1 -1
  91. data/app/components/polaris/layout/section.rb +2 -0
  92. data/app/components/polaris/layout_component.rb +3 -3
  93. data/app/components/polaris/link_component.rb +5 -3
  94. data/app/components/polaris/list_component.rb +3 -3
  95. data/app/components/polaris/logo.rb +13 -0
  96. data/app/components/polaris/modal/section_component.rb +19 -0
  97. data/app/components/polaris/modal_component.html.erb +79 -0
  98. data/app/components/polaris/modal_component.rb +98 -0
  99. data/app/components/polaris/navigation/item_component.html.erb +31 -0
  100. data/app/components/polaris/navigation/item_component.rb +85 -0
  101. data/app/components/polaris/navigation/section_component.html.erb +17 -0
  102. data/app/components/polaris/navigation/section_component.rb +64 -0
  103. data/app/components/polaris/navigation_component.html.erb +29 -0
  104. data/app/components/polaris/navigation_component.rb +15 -0
  105. data/app/components/polaris/option_list/checkbox_component.html.erb +14 -0
  106. data/app/components/polaris/option_list/checkbox_component.rb +37 -0
  107. data/app/components/polaris/option_list/option_component.rb +24 -0
  108. data/app/components/polaris/option_list/radio_button_component.rb +54 -0
  109. data/app/components/polaris/option_list/section_component.html.erb +14 -0
  110. data/app/components/polaris/option_list/section_component.rb +53 -0
  111. data/app/components/polaris/option_list_component.html.erb +15 -0
  112. data/app/components/polaris/option_list_component.rb +67 -0
  113. data/app/components/polaris/page_actions_component.rb +21 -6
  114. data/app/components/polaris/page_component.rb +4 -4
  115. data/app/components/polaris/pagination_component.rb +1 -5
  116. data/app/components/polaris/popover/pane_component.html.erb +25 -0
  117. data/app/components/polaris/popover/pane_component.rb +20 -0
  118. data/app/components/polaris/popover/section_component.rb +19 -0
  119. data/app/components/polaris/popover_component.html.erb +31 -0
  120. data/app/components/polaris/popover_component.rb +107 -0
  121. data/app/components/polaris/progress_bar_component.rb +5 -5
  122. data/app/components/polaris/radio_button_component.html.erb +1 -6
  123. data/app/components/polaris/radio_button_component.rb +17 -7
  124. data/app/components/polaris/resource_item_component.html.erb +16 -6
  125. data/app/components/polaris/resource_item_component.rb +42 -9
  126. data/app/components/polaris/resource_list_component.html.erb +10 -0
  127. data/app/components/polaris/resource_list_component.rb +4 -10
  128. data/app/components/polaris/scrollable_component.html.erb +5 -0
  129. data/app/components/polaris/scrollable_component.rb +48 -0
  130. data/app/components/polaris/select_component.rb +10 -5
  131. data/app/components/polaris/setting_toggle_component.html.erb +10 -0
  132. data/app/components/polaris/setting_toggle_component.rb +24 -0
  133. data/app/components/polaris/shopify_navigation_component.rb +6 -6
  134. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  135. data/app/components/polaris/spacer_component.rb +50 -0
  136. data/app/components/polaris/spinner_component.rb +2 -2
  137. data/app/components/polaris/stack_component.rb +5 -5
  138. data/app/components/polaris/subheading_component.rb +1 -1
  139. data/app/components/polaris/tabs/tab_component.html.erb +10 -0
  140. data/app/components/polaris/tabs/tab_component.rb +34 -0
  141. data/app/components/polaris/tabs_component.html.erb +7 -0
  142. data/app/components/polaris/tabs_component.rb +37 -0
  143. data/app/components/polaris/tag_component.rb +2 -2
  144. data/app/components/polaris/text_container_component.rb +2 -2
  145. data/app/components/polaris/text_field_component.rb +24 -10
  146. data/app/components/polaris/text_style_component.rb +11 -2
  147. data/app/components/polaris/thumbnail_component.rb +2 -2
  148. data/app/components/polaris/toast_component.html.erb +21 -0
  149. data/app/components/polaris/toast_component.rb +40 -0
  150. data/app/components/polaris/top_bar/user_menu_component.html.erb +19 -0
  151. data/app/components/polaris/top_bar/user_menu_component.rb +9 -0
  152. data/app/helpers/polaris/form_builder.rb +31 -4
  153. data/app/helpers/polaris/url_helper.rb +3 -3
  154. data/app/helpers/polaris/view_helper.rb +37 -6
  155. data/app/validators/type_validator.rb +2 -2
  156. data/lib/generators/polaris_view_components/install_generator.rb +5 -5
  157. data/lib/polaris/view_components/engine.rb +11 -2
  158. data/lib/polaris/view_components/version.rb +1 -1
  159. data/lib/polaris_view_components.rb +1 -1
  160. metadata +88 -12
  161. data/app/components/polaris/choice_list/component.html.erb +0 -34
  162. data/app/components/polaris/choice_list/component.rb +0 -65
  163. data/app/helpers/polaris/action_helper.rb +0 -14
@@ -0,0 +1,31 @@
1
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
2
+ <div class="Polaris-Navigation__ItemWrapper">
3
+ <%= link_to @url, class: link_classes, tabindex: "0" do %>
4
+ <% if @icon.present? %>
5
+ <div class="Polaris-Navigation__Icon">
6
+ <%= polaris_icon(name: @icon) %>
7
+ </div>
8
+ <% end %>
9
+ <span class="Polaris-Navigation__Text">
10
+ <%= @label %>
11
+ </span>
12
+ <% if @badge.present? %>
13
+ <div class="Polaris-Navigation__Badge">
14
+ <%= polaris_badge { @badge } %>
15
+ </div>
16
+ <% end %>
17
+ <% end %>
18
+ <%= secondary_action %>
19
+ </div>
20
+ <% if sub_items.present? %>
21
+ <div class="Polaris-Navigation__SecondaryNavigation Polaris-Navigation--isExpanded">
22
+ <div class="Polaris-Collapsible" style="max-height: none; overflow: visible;">
23
+ <ul class="Polaris-Navigation__List">
24
+ <% sub_items.each do |sub_item| %>
25
+ <%= sub_item %>
26
+ <% end %>
27
+ </ul>
28
+ </div>
29
+ </div>
30
+ <% end %>
31
+ <% end %>
@@ -0,0 +1,85 @@
1
+ class Polaris::Navigation::ItemComponent < Polaris::NewComponent
2
+ renders_many :sub_items, Polaris::Navigation::ItemComponent
3
+ renders_one :secondary_action, "SecondaryActionComponent"
4
+
5
+ attr_reader :selected
6
+
7
+ def initialize(
8
+ url:,
9
+ label:,
10
+ icon: nil,
11
+ badge: nil,
12
+ selected: false,
13
+ disabled: false,
14
+ **system_arguments
15
+ )
16
+ @url = url
17
+ @label = label
18
+ @icon = icon
19
+ @badge = badge
20
+ @selected = selected
21
+ @disabled = disabled
22
+ @system_arguments = system_arguments
23
+ end
24
+
25
+ def system_arguments
26
+ @system_arguments.tap do |opts|
27
+ opts[:tag] = "li"
28
+ opts[:classes] = class_names(
29
+ @system_arguments[:classes],
30
+ "Polaris-Navigation__ListItem"
31
+ )
32
+ end
33
+ end
34
+
35
+ def link_classes
36
+ class_names(
37
+ "Polaris-Navigation__Item",
38
+ "Polaris-Navigation__Item--selected": @selected,
39
+ "Polaris-Navigation--subNavigationActive": @selected || selected_sub_items?,
40
+ "Polaris-Navigation__Item--disabled": @disabled
41
+ )
42
+ end
43
+
44
+ def selected_sub_items?
45
+ return unless sub_items.present?
46
+
47
+ sub_items.any?(&:selected)
48
+ end
49
+
50
+ class SecondaryActionComponent < Polaris::NewComponent
51
+ def initialize(url: nil, external: false, icon: nil, **system_arguments)
52
+ @url = url
53
+ @external = external
54
+ @icon = icon
55
+ @system_arguments = system_arguments
56
+ end
57
+
58
+ def system_arguments
59
+ @system_arguments.tap do |opts|
60
+ if @url.present?
61
+ opts[:tag] = "a"
62
+ opts[:href] = @url
63
+ opts[:target] = "_blank" if @external
64
+ else
65
+ opts[:tag] = "button"
66
+ opts[:type] = "button"
67
+ end
68
+ opts[:classes] = class_names(
69
+ @system_arguments[:classes],
70
+ "Polaris-Navigation__SecondaryAction"
71
+ )
72
+ end
73
+ end
74
+
75
+ def call
76
+ render(Polaris::BaseComponent.new(**system_arguments)) do
77
+ if @icon.present?
78
+ render(Polaris::IconComponent.new(name: @icon))
79
+ else
80
+ content
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,17 @@
1
+ <%= render(Polaris::BaseComponent.new(**system_arguments)) do %>
2
+ <% if items.present? %>
3
+ <% if @title.present? %>
4
+ <li class="Polaris-Navigation__SectionHeading">
5
+ <span class="Polaris-Navigation__Text">
6
+ <%= @title %>
7
+ </span>
8
+ <%= action %>
9
+ </li>
10
+ <% end %>
11
+ <% items.each do |item| %>
12
+ <%= item %>
13
+ <% end %>
14
+ <% else %>
15
+ <%= content %>
16
+ <% end %>
17
+ <% end %>
@@ -0,0 +1,64 @@
1
+ class Polaris::Navigation::SectionComponent < Polaris::NewComponent
2
+ renders_many :items, Polaris::Navigation::ItemComponent
3
+ renders_one :action, "ActionComponent"
4
+
5
+ def initialize(
6
+ title: nil,
7
+ separator: false,
8
+ fill: false,
9
+ **system_arguments
10
+ )
11
+ @title = title
12
+ @separator = separator
13
+ @fill = fill
14
+ @system_arguments = system_arguments
15
+ end
16
+
17
+ def system_arguments
18
+ @system_arguments.tap do |opts|
19
+ opts[:tag] = "ul"
20
+ opts[:classes] = class_names(
21
+ @system_arguments[:classes],
22
+ "Polaris-Navigation__Section",
23
+ "Polaris-Navigation__Section--fill": @fill,
24
+ "Polaris-Navigation__Section--withSeparator": @separator
25
+ )
26
+ end
27
+ end
28
+
29
+ class ActionComponent < Polaris::NewComponent
30
+ def initialize(url: nil, external: false, icon: nil, **system_arguments)
31
+ @url = url
32
+ @external = external
33
+ @icon = icon
34
+ @system_arguments = system_arguments
35
+ end
36
+
37
+ def system_arguments
38
+ @system_arguments.tap do |opts|
39
+ if @url.present?
40
+ opts[:tag] = "a"
41
+ opts[:href] = @url
42
+ opts[:target] = "_blank" if @external
43
+ else
44
+ opts[:tag] = "button"
45
+ opts[:type] = "button"
46
+ end
47
+ opts[:classes] = class_names(
48
+ @system_arguments[:classes],
49
+ "Polaris-Navigation__Action"
50
+ )
51
+ end
52
+ end
53
+
54
+ def call
55
+ render(Polaris::BaseComponent.new(**system_arguments)) do
56
+ if @icon.present?
57
+ render(Polaris::IconComponent.new(name: @icon))
58
+ else
59
+ content
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,29 @@
1
+ <nav class="Polaris-Navigation">
2
+ <% if @logo.present? %>
3
+ <div class="Polaris-Navigation__LogoContainer">
4
+ <%= link_to(@logo.url,
5
+ class: "Polaris-Navigation__LogoLink",
6
+ style: "width: #{@logo.width}"
7
+ ) do %>
8
+ <%= image_tag @logo.src,
9
+ class: "Polaris-Navigation__Logo",
10
+ style: "width: #{@logo.width}",
11
+ alt: @logo.alt %>
12
+ <% end %>
13
+ </div>
14
+ <% end %>
15
+
16
+ <%= polaris_scrollable(classes: "Polaris-Navigation__PrimaryNavigation") do %>
17
+ <% if sections.present? %>
18
+ <% sections.each do |section| %>
19
+ <%= section %>
20
+ <% end %>
21
+ <% else %>
22
+ <%= render(Polaris::Navigation::SectionComponent.new) do %>
23
+ <% items.each do |item| %>
24
+ <%= item %>
25
+ <% end %>
26
+ <% end %>
27
+ <% end %>
28
+ <% end %>
29
+ </nav>
@@ -0,0 +1,15 @@
1
+ module Polaris
2
+ class NavigationComponent < Polaris::NewComponent
3
+ renders_many :sections, Polaris::Navigation::SectionComponent
4
+ renders_many :items, Polaris::Navigation::ItemComponent
5
+
6
+ def initialize(logo: nil, **system_arguments)
7
+ @logo = logo.is_a?(Hash) ? Polaris::Logo.new(**logo) : logo
8
+ @system_arguments = system_arguments
9
+ end
10
+
11
+ def renders?
12
+ sections.any? || items.any?
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ <%= render(Polaris::BaseComponent.new(**wrapper_arguments)) do %>
2
+ <label class="Polaris-OptionList-Option__Label">
3
+ <div class="Polaris-OptionList-Option__Checkbox">
4
+ <div class="Polaris-OptionList-Checkbox">
5
+ <%= checkbox %>
6
+ <div class="Polaris-OptionList-Checkbox__Backdrop"></div>
7
+ <div class="Polaris-OptionList-Checkbox__Icon">
8
+ <%= polaris_icon(name: "TickMinor") %>
9
+ </div>
10
+ </div>
11
+ </div>
12
+ <%= @label %>
13
+ </label>
14
+ <% end %>
@@ -0,0 +1,37 @@
1
+ class Polaris::OptionList::CheckboxComponent < Polaris::NewComponent
2
+ def initialize(
3
+ label:,
4
+ value:,
5
+ wrapper_arguments: {},
6
+ **system_arguments
7
+ )
8
+ @label = label
9
+ @value = value
10
+ @wrapper_arguments = wrapper_arguments
11
+ @system_arguments = system_arguments
12
+ end
13
+
14
+ def wrapper_arguments
15
+ @wrapper_arguments.tap do |opts|
16
+ opts[:tag] = "li"
17
+ opts[:tabindex] = "-1"
18
+ opts[:classes] = class_names(
19
+ @wrapper_arguments[:classes],
20
+ "Polaris-OptionList-Option"
21
+ )
22
+ end
23
+ end
24
+
25
+ def system_arguments
26
+ @system_arguments.tap do |opts|
27
+ opts[:classes] = class_names(
28
+ @system_arguments[:classes],
29
+ "Polaris-OptionList-Checkbox__Input"
30
+ )
31
+ end
32
+ end
33
+
34
+ def checkbox
35
+ render Polaris::BaseCheckbox.new(value: @value, **system_arguments)
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ class Polaris::OptionList::OptionComponent < Polaris::NewComponent
2
+ def initialize(**system_arguments)
3
+ @system_arguments = system_arguments
4
+ end
5
+
6
+ def system_arguments
7
+ @system_arguments.tap do |opts|
8
+ opts[:tag] = "li"
9
+ opts[:tabindex] = "-1"
10
+ opts[:classes] = class_names(
11
+ @system_arguments[:classes],
12
+ "Polaris-OptionList-Option"
13
+ )
14
+ end
15
+ end
16
+
17
+ def call
18
+ render(Polaris::BaseComponent.new(**system_arguments)) do
19
+ tag.label(class: "Polaris-OptionList-Option__Label") do
20
+ content
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ class Polaris::OptionList::RadioButtonComponent < Polaris::NewComponent
2
+ def initialize(
3
+ label:,
4
+ value:,
5
+ wrapper_arguments: {},
6
+ **system_arguments
7
+ )
8
+ @label = label
9
+ @value = value
10
+ @wrapper_arguments = wrapper_arguments
11
+ @system_arguments = system_arguments
12
+ end
13
+
14
+ def wrapper_arguments
15
+ @wrapper_arguments.tap do |opts|
16
+ opts[:tag] = "li"
17
+ opts[:tabindex] = "-1"
18
+ opts[:classes] = class_names(
19
+ @wrapper_arguments[:classes],
20
+ "Polaris-OptionList-Option"
21
+ )
22
+ end
23
+ end
24
+
25
+ def system_arguments
26
+ @system_arguments.tap do |opts|
27
+ opts[:classes] = class_names(
28
+ @system_arguments[:classes],
29
+ "Polaris--hidden"
30
+ )
31
+ end
32
+ end
33
+
34
+ def call
35
+ render(Polaris::BaseComponent.new(**wrapper_arguments)) do
36
+ tag.label(
37
+ class: "Polaris-OptionList-Option__SingleSelectOption",
38
+ data: {
39
+ polaris_option_list_target: "radioButton",
40
+ action: "click->polaris-option-list#update"
41
+ }
42
+ ) do
43
+ safe_join [
44
+ radio_button,
45
+ @label
46
+ ]
47
+ end
48
+ end
49
+ end
50
+
51
+ def radio_button
52
+ render Polaris::BaseRadioButton.new(value: @value, **system_arguments)
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ <li>
2
+ <% if @title.present? %>
3
+ <p class="Polaris-OptionList__Title"><%= @title %></p>
4
+ <% end %>
5
+ <ul class="Polaris-OptionList__Options">
6
+ <% if items.present? %>
7
+ <% items.each do |item| %>
8
+ <%= item %>
9
+ <% end %>
10
+ <% else %>
11
+ <%= content %>
12
+ <% end %>
13
+ </ul>
14
+ </li>
@@ -0,0 +1,53 @@
1
+ class Polaris::OptionList::SectionComponent < Polaris::NewComponent
2
+ renders_many :options, Polaris::OptionList::OptionComponent
3
+ renders_many :radio_buttons, ->(value:, **system_arguments) do
4
+ Polaris::OptionList::RadioButtonComponent.new(
5
+ form: @form,
6
+ attribute: @attribute,
7
+ name: @name,
8
+ value: value,
9
+ checked: @selected.include?(value),
10
+ **system_arguments
11
+ )
12
+ end
13
+ renders_many :checkboxes, ->(value:, **system_arguments) do
14
+ Polaris::OptionList::CheckboxComponent.new(
15
+ form: @form,
16
+ attribute: @attribute,
17
+ name: @name && "#{@name}[]",
18
+ value: value,
19
+ checked: @selected.include?(value),
20
+ **system_arguments
21
+ )
22
+ end
23
+
24
+ def initialize(
25
+ title: nil,
26
+ form: nil,
27
+ attribute: nil,
28
+ name: nil,
29
+ selected: [],
30
+ **system_arguments
31
+ )
32
+ @title = title
33
+ @form = form
34
+ @attribute = attribute
35
+ @name = name
36
+ @selected = selected
37
+ @system_arguments = system_arguments
38
+ end
39
+
40
+ def system_arguments
41
+ @system_arguments.tap do |opts|
42
+ opts[:tag] = "ul"
43
+ opts[:classes] = class_names(
44
+ @system_arguments[:classes],
45
+ "Polaris-OptionList__Options"
46
+ )
47
+ end
48
+ end
49
+
50
+ def items
51
+ radio_buttons.presence || checkboxes.presence || options
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ <%= render(Polaris::BaseComponent.new(**system_arguments)) do %>
2
+ <% if sections.present? %>
3
+ <% sections.each do |section| %>
4
+ <%= section %>
5
+ <% end %>
6
+ <% elsif items.present? %>
7
+ <%= render(Polaris::OptionList::SectionComponent.new(title: @title)) do %>
8
+ <% items.each do |item| %>
9
+ <%= item %>
10
+ <% end %>
11
+ <% end %>
12
+ <% else %>
13
+ <%= content %>
14
+ <% end %>
15
+ <% end %>
@@ -0,0 +1,67 @@
1
+ module Polaris
2
+ class OptionListComponent < Polaris::NewComponent
3
+ renders_many :sections, ->(**system_arguments) do
4
+ Polaris::OptionList::SectionComponent.new(
5
+ form: @form,
6
+ attribute: @attribute,
7
+ name: @name,
8
+ selected: @selected,
9
+ **system_arguments
10
+ )
11
+ end
12
+ renders_many :options, Polaris::OptionList::OptionComponent
13
+ renders_many :radio_buttons, ->(value:, **system_arguments) do
14
+ Polaris::OptionList::RadioButtonComponent.new(
15
+ form: @form,
16
+ attribute: @attribute,
17
+ name: @name,
18
+ value: value,
19
+ checked: @selected.include?(value),
20
+ **system_arguments
21
+ )
22
+ end
23
+ renders_many :checkboxes, ->(value:, **system_arguments) do
24
+ Polaris::OptionList::CheckboxComponent.new(
25
+ form: @form,
26
+ attribute: @attribute,
27
+ name: @name && "#{@name}[]",
28
+ value: value,
29
+ checked: @selected.include?(value),
30
+ **system_arguments
31
+ )
32
+ end
33
+
34
+ def initialize(
35
+ title: nil,
36
+ form: nil,
37
+ attribute: nil,
38
+ name: nil,
39
+ selected: [],
40
+ **system_arguments
41
+ )
42
+ @title = title
43
+ @form = form
44
+ @attribute = attribute
45
+ @name = name
46
+ @selected = selected
47
+ @system_arguments = system_arguments
48
+ end
49
+
50
+ def system_arguments
51
+ @system_arguments.tap do |opts|
52
+ opts[:tag] = "ul"
53
+ opts[:data] ||= {}
54
+ prepend_option(opts[:data], :controller, "polaris-option-list")
55
+ opts[:data][:polaris_option_list_selected_class] = "Polaris-OptionList-Option--select"
56
+ opts[:classes] = class_names(
57
+ @system_arguments[:classes],
58
+ "Polaris-OptionList"
59
+ )
60
+ end
61
+ end
62
+
63
+ def items
64
+ radio_buttons.presence || checkboxes.presence || options
65
+ end
66
+ end
67
+ end
@@ -2,23 +2,38 @@
2
2
 
3
3
  module Polaris
4
4
  class PageActionsComponent < Polaris::NewComponent
5
- renders_one :primary_action, -> (primary: true, **system_arguments) do
5
+ DISTRIBUTION_DEFAULT = nil
6
+ DISTRIBUTION_OPTIONS = [
7
+ DISTRIBUTION_DEFAULT,
8
+ :equal_spacing,
9
+ :leading,
10
+ :trailing,
11
+ :center,
12
+ :fill,
13
+ :fill_evenly
14
+ ]
15
+
16
+ renders_one :primary_action, ->(primary: true, **system_arguments) do
6
17
  Polaris::ButtonComponent.new(primary: primary, **system_arguments)
7
18
  end
8
19
  renders_many :secondary_actions, Polaris::ButtonComponent
9
20
 
10
- def initialize(**system_arguments)
21
+ def initialize(distribution: DISTRIBUTION_DEFAULT, **system_arguments)
22
+ @distribution = fetch_or_fallback(DISTRIBUTION_OPTIONS, distribution, DISTRIBUTION_DEFAULT)
11
23
  @system_arguments = system_arguments
12
24
  @system_arguments[:tag] = "div"
13
25
  @system_arguments[:classes] = class_names(
14
26
  @system_arguments[:classes],
15
- "Polaris-PageActions",
27
+ "Polaris-PageActions"
16
28
  )
17
29
  end
18
30
 
19
31
  private
20
- def stack_distribution
21
- (primary_action.present? && secondary_actions.any?) ? :equal_spacing : :trailing
22
- end
32
+
33
+ def stack_distribution
34
+ return @distribution if @distribution.present?
35
+
36
+ primary_action.present? && secondary_actions.any? ? :equal_spacing : :trailing
37
+ end
23
38
  end
24
39
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Polaris
4
4
  class PageComponent < Polaris::NewComponent
5
- renders_one :primary_action, -> (primary: true, **system_arguments) do
5
+ renders_one :primary_action, ->(primary: true, **system_arguments) do
6
6
  Polaris::ButtonComponent.new(primary: primary, **system_arguments)
7
7
  end
8
8
  # renders_many :secondary_actions, Polaris::ButtonComponent
@@ -28,7 +28,7 @@ module Polaris
28
28
  @system_arguments[:classes],
29
29
  "Polaris-Page",
30
30
  "Polaris-Page--narrowWidth": narrow_width,
31
- "Polaris-Page--fullWidth": full_width,
31
+ "Polaris-Page--fullWidth": full_width
32
32
  )
33
33
 
34
34
  @header_arguments = {}
@@ -38,14 +38,14 @@ module Polaris
38
38
  "Polaris-Page-Header--mobileView",
39
39
  "Polaris-Page-Header--mediumTitle",
40
40
  "Polaris-Page-Header--hasNavigation": back_url.present?,
41
- "Polaris-Page-Header--noBreadcrumbs": back_url.blank?,
41
+ "Polaris-Page-Header--noBreadcrumbs": back_url.blank?
42
42
  )
43
43
 
44
44
  @content_arguments = {}
45
45
  @content_arguments[:tag] = "div"
46
46
  @content_arguments[:classes] = class_names(
47
47
  "Polaris-Page__Content",
48
- "Polaris-Page--divider": divider,
48
+ "Polaris-Page--divider": divider
49
49
  )
50
50
  end
51
51
 
@@ -16,11 +16,7 @@ module Polaris
16
16
  @system_arguments["aria-label"] = "Pagination"
17
17
 
18
18
  @button_group_arguments = {}
19
- if label.present?
20
- @button_group_arguments[:segmented] = false
21
- else
22
- @button_group_arguments[:segmented] = true
23
- end
19
+ @button_group_arguments[:segmented] = !label.present?
24
20
  end
25
21
  end
26
22
  end
@@ -0,0 +1,25 @@
1
+ <% pane_content = capture do %>
2
+ <% if sections.present? %>
3
+ <% sections.each do |section| %>
4
+ <%= section %>
5
+ <% end %>
6
+ <% end %>
7
+
8
+ <% if @sectioned %>
9
+ <%= render Polaris::Popover::SectionComponent.new do %>
10
+ <%= content %>
11
+ <% end %>
12
+ <% else %>
13
+ <%= content %>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <% if @fixed %>
18
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
19
+ <%= pane_content %>
20
+ <% end %>
21
+ <% else %>
22
+ <%= render Polaris::ScrollableComponent.new(shadow: true, **system_arguments) do %>
23
+ <%= pane_content %>
24
+ <% end %>
25
+ <% end %>
@@ -0,0 +1,20 @@
1
+ class Polaris::Popover::PaneComponent < Polaris::NewComponent
2
+ renders_many :sections, Polaris::Popover::SectionComponent
3
+
4
+ def initialize(fixed: false, sectioned: false, **system_arguments)
5
+ @fixed = fixed
6
+ @sectioned = sectioned
7
+ @system_arguments = system_arguments
8
+ end
9
+
10
+ def system_arguments
11
+ @system_arguments.tap do |opts|
12
+ opts[:tag] = "div"
13
+ opts[:classes] = class_names(
14
+ @system_arguments[:classes],
15
+ "Polaris-Popover__Pane",
16
+ "Polaris-Popover__Pane--fixed": @fixed
17
+ )
18
+ end
19
+ end
20
+ end