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
@@ -6,7 +6,7 @@ module Polaris
6
6
  SIZE_MAPPINGS = {
7
7
  small: "Polaris-Avatar--sizeSmall",
8
8
  medium: "Polaris-Avatar--sizeMedium",
9
- large: "Polaris-Avatar--sizeLarge",
9
+ large: "Polaris-Avatar--sizeLarge"
10
10
  }
11
11
  SIZE_OPTIONS = SIZE_MAPPINGS.keys
12
12
 
@@ -44,7 +44,7 @@ module Polaris
44
44
  "Polaris-Badge",
45
45
  PROGRESS_MAPPINGS[fetch_or_fallback(PROGRESS_OPTIONS, progress, PROGRESS_DEFAULT)],
46
46
  SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
47
- STATUS_MAPPINGS[fetch_or_fallback(STATUS_OPTIONS, status, STATUS_DEFAULT)],
47
+ STATUS_MAPPINGS[fetch_or_fallback(STATUS_OPTIONS, status, STATUS_DEFAULT)]
48
48
  )
49
49
  end
50
50
  end
@@ -8,14 +8,14 @@ module Polaris
8
8
  :success => "Polaris-Banner--statusSuccess",
9
9
  :info => "Polaris-Banner--statusInfo",
10
10
  :warning => "Polaris-Banner--statusWarning",
11
- :critical => "Polaris-Banner--statusCritical",
11
+ :critical => "Polaris-Banner--statusCritical"
12
12
  }
13
13
  STATUS_OPTIONS = STATUS_MAPPINGS.keys
14
14
 
15
15
  WITHIN_DEFAULT = :page
16
16
  WITHIN_MAPPINGS = {
17
17
  page: "Polaris-Banner--withinPage",
18
- container: "Polaris-Banner--withinContentContainer",
18
+ container: "Polaris-Banner--withinContentContainer"
19
19
  }
20
20
  WITHIN_OPTIONS = WITHIN_MAPPINGS.keys
21
21
 
@@ -24,14 +24,14 @@ module Polaris
24
24
  success: :success,
25
25
  info: :highlight,
26
26
  warning: :warning,
27
- critical: :critical,
27
+ critical: :critical
28
28
  }
29
29
 
30
- renders_one :action, -> (**system_arguments) do
30
+ renders_one :action, ->(**system_arguments) do
31
31
  Polaris::ButtonComponent.new(classes: "Polaris-Banner__Button", **system_arguments)
32
32
  end
33
33
  renders_one :secondary_action, "SecondaryAction"
34
- renders_one :dismiss_button, -> (**system_arguments) do
34
+ renders_one :dismiss_button, ->(**system_arguments) do
35
35
  render Polaris::ButtonComponent.new(plain: true, **system_arguments) do |button|
36
36
  button.icon(name: "CancelSmallMinor")
37
37
  end
@@ -55,7 +55,7 @@ module Polaris
55
55
  @system_arguments[:classes],
56
56
  "Polaris-Banner",
57
57
  STATUS_MAPPINGS[fetch_or_fallback(STATUS_OPTIONS, status, STATUS_DEFAULT)],
58
- WITHIN_MAPPINGS[fetch_or_fallback(WITHIN_OPTIONS, within, WITHIN_DEFAULT)],
58
+ WITHIN_MAPPINGS[fetch_or_fallback(WITHIN_OPTIONS, within, WITHIN_DEFAULT)]
59
59
  )
60
60
  end
61
61
 
@@ -10,7 +10,7 @@ module Polaris
10
10
  **system_arguments
11
11
  )
12
12
  @system_arguments = system_arguments
13
- @system_arguments[:tag] = url.present? ? 'a' : 'button'
13
+ @system_arguments[:tag] = url.present? ? "a" : "button"
14
14
  if loading
15
15
  @system_arguments[:disabled] = true
16
16
  end
@@ -0,0 +1,48 @@
1
+ module Polaris
2
+ class BaseCheckbox < Polaris::NewComponent
3
+ def initialize(
4
+ form: nil,
5
+ attribute: nil,
6
+ name: nil,
7
+ checked: false,
8
+ disabled: false,
9
+ value: "1",
10
+ unchecked_value: "0",
11
+ **system_arguments
12
+ )
13
+ @form = form
14
+ @attribute = attribute
15
+ @name = name
16
+ @checked = checked
17
+ @disabled = disabled
18
+ @value = value
19
+ @unchecked_value = unchecked_value
20
+ @system_arguments = system_arguments
21
+ end
22
+
23
+ def system_arguments
24
+ @system_arguments.tap do |opts|
25
+ opts[:disabled] = true if @disabled
26
+ opts[:aria] ||= {}
27
+ opts[:aria][:checked] = @checked
28
+ if indeterminate?
29
+ @system_arguments[:indeterminate] = true
30
+ @system_arguments[:aria][:checked] = "mixed"
31
+ end
32
+ opts[:class] = opts.delete(:classes)
33
+ end
34
+ end
35
+
36
+ def indeterminate?
37
+ @checked == :indeterminate
38
+ end
39
+
40
+ def call
41
+ if @form.present? && @attribute.present?
42
+ @form.check_box(@attribute, system_arguments, @value, @unchecked_value)
43
+ else
44
+ check_box_tag(@name, @value, @checked, system_arguments)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ module Polaris
2
+ class BaseRadioButton < Polaris::NewComponent
3
+ def initialize(
4
+ form: nil,
5
+ attribute: nil,
6
+ name: nil,
7
+ checked: false,
8
+ disabled: false,
9
+ value: nil,
10
+ **system_arguments
11
+ )
12
+ @form = form
13
+ @attribute = attribute
14
+ @name = name
15
+ @checked = checked
16
+ @disabled = disabled
17
+ @value = value
18
+ @system_arguments = system_arguments
19
+ end
20
+
21
+ def system_arguments
22
+ @system_arguments.tap do |opts|
23
+ opts[:disabled] = true if @disabled
24
+ opts[:aria] ||= {}
25
+ opts[:aria][:checked] = @checked
26
+ opts[:class] = opts.delete(:classes)
27
+ end
28
+ end
29
+
30
+ def call
31
+ if @form.present? && @attribute.present?
32
+ @form.radio_button(@attribute, @value, system_arguments)
33
+ else
34
+ radio_button_tag(@name, @value, @checked, system_arguments)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -20,5 +20,18 @@
20
20
  <%= content %>
21
21
  </div>
22
22
  <% end %>
23
+
24
+ <% if @disclosure.present? %>
25
+ <div class="Polaris-Button__Icon">
26
+ <% case @disclosure %>
27
+ <% when :down %>
28
+ <%= polaris_icon(name: "CaretDownMinor") %>
29
+ <% when :up %>
30
+ <%= polaris_icon(name: "CaretUpMinor") %>
31
+ <% when :select %>
32
+ <%= polaris_icon(name: "SelectMinor") %>
33
+ <% end %>
34
+ </div>
35
+ <% end %>
23
36
  </span>
24
37
  <% end %>
@@ -7,17 +7,17 @@ module Polaris
7
7
  SPACING_DEFAULT => "",
8
8
  :extra_tight => "Polaris-ButtonGroup--extraTight",
9
9
  :tight => "Polaris-ButtonGroup--tight",
10
- :loose => "Polaris-ButtonGroup--loose",
10
+ :loose => "Polaris-ButtonGroup--loose"
11
11
  }
12
12
  SPACING_OPTIONS = SPACING_MAPPINGS.keys
13
13
 
14
- renders_many :buttons, -> (**system_arguments) do
14
+ renders_many :buttons, ->(**system_arguments) do
15
15
  @counter += 1
16
16
 
17
17
  ButtonGroupItemButtonComponent.new(position: @counter, **system_arguments)
18
18
  end
19
19
 
20
- renders_many :items, -> (**system_arguments) do
20
+ renders_many :items, ->(**system_arguments) do
21
21
  @counter += 1
22
22
 
23
23
  ButtonGroupItemComponent.new(position: @counter, **system_arguments)
@@ -47,7 +47,7 @@ module Polaris
47
47
  "Polaris-ButtonGroup",
48
48
  SPACING_MAPPINGS[fetch_or_fallback(SPACING_OPTIONS, spacing, SPACING_DEFAULT)],
49
49
  "Polaris-ButtonGroup--fullWidth": full_width,
50
- "Polaris-ButtonGroup--segmented": segmented,
50
+ "Polaris-ButtonGroup--segmented": segmented
51
51
  )
52
52
  end
53
53
 
@@ -97,7 +97,7 @@ module Polaris
97
97
  @system_arguments[:tag] = :div
98
98
  @system_arguments[:classes] = class_names(
99
99
  @system_arguments[:classes],
100
- "Polaris-ButtonGroup__Item",
100
+ "Polaris-ButtonGroup__Item"
101
101
  )
102
102
  end
103
103
 
@@ -3,10 +3,10 @@
3
3
  module Polaris
4
4
  class CalloutCardComponent < Polaris::NewComponent
5
5
  renders_one :primary_action, Polaris::ButtonComponent
6
- renders_one :secondary_action, -> (plain: true, **system_arguments) do
6
+ renders_one :secondary_action, ->(plain: true, **system_arguments) do
7
7
  Polaris::ButtonComponent.new(plain: plain, **system_arguments)
8
8
  end
9
- renders_one :dismiss_button, -> (**system_arguments) do
9
+ renders_one :dismiss_button, ->(**system_arguments) do
10
10
  render Polaris::ButtonComponent.new(plain: true, **system_arguments) do |button|
11
11
  button.icon(name: "CancelSmallMinor")
12
12
  end
@@ -24,21 +24,21 @@ module Polaris
24
24
  @system_arguments[:tag] = "div"
25
25
  @system_arguments[:classes] = class_names(
26
26
  @system_arguments[:classes],
27
- "Polaris-Card",
27
+ "Polaris-Card"
28
28
  )
29
29
  end
30
30
 
31
31
  def container_classes
32
32
  class_names(
33
33
  "Polaris-CalloutCard__Container",
34
- "Polaris-CalloutCard--hasDismiss": dismiss_button.present?,
34
+ "Polaris-CalloutCard--hasDismiss": dismiss_button.present?
35
35
  )
36
36
  end
37
37
 
38
38
  def image_classes
39
39
  class_names(
40
40
  "Polaris-CalloutCard__Image",
41
- "Polaris-CalloutCard__DismissImage": dismiss_button.present?,
41
+ "Polaris-CalloutCard__DismissImage": dismiss_button.present?
42
42
  )
43
43
  end
44
44
  end
@@ -4,10 +4,10 @@ module Polaris
4
4
  class CaptionComponent < Polaris::NewComponent
5
5
  def initialize(**system_arguments)
6
6
  @system_arguments = system_arguments
7
- @system_arguments[:tag] = 'p'
7
+ @system_arguments[:tag] = "p"
8
8
  @system_arguments[:classes] = class_names(
9
9
  @system_arguments[:classes],
10
- "Polaris-Caption",
10
+ "Polaris-Caption"
11
11
  )
12
12
  end
13
13
 
@@ -1,6 +1,4 @@
1
1
  class Polaris::Card::HeaderComponent < Polaris::NewComponent
2
- include Polaris::ActionHelper
3
-
4
2
  def initialize(
5
3
  title: "",
6
4
  actions: [],
@@ -10,7 +8,7 @@ class Polaris::Card::HeaderComponent < Polaris::NewComponent
10
8
  @system_arguments[:tag] = :div
11
9
  @system_arguments[:classes] = class_names(
12
10
  @system_arguments[:classes],
13
- "Polaris-Card__Header",
11
+ "Polaris-Card__Header"
14
12
  )
15
13
 
16
14
  @title = title
@@ -7,6 +7,8 @@ class Polaris::Card::SectionComponent < Polaris::NewComponent
7
7
  flush: false,
8
8
  full_width: false,
9
9
  unstyled: false,
10
+ border_top: false,
11
+ border_bottom: false,
10
12
  actions: [],
11
13
  **system_arguments
12
14
  )
@@ -14,10 +16,12 @@ class Polaris::Card::SectionComponent < Polaris::NewComponent
14
16
  @system_arguments[:tag] = :div
15
17
  @system_arguments[:classes] = class_names(
16
18
  @system_arguments[:classes],
19
+ "Polaris-Card__Section": !unstyled,
17
20
  "Polaris-Card__Section--flush": flush,
18
21
  "Polaris-Card__Section--subdued": subdued,
19
22
  "Polaris-Card__Section--fullWidth": full_width,
20
- "Polaris-Card__Section": !unstyled,
23
+ "Polaris-Card__Section--borderTop": border_top,
24
+ "Polaris-Card__Section--borderBottom": border_bottom
21
25
  )
22
26
 
23
27
  @title = title
@@ -30,7 +34,7 @@ class Polaris::Card::SectionComponent < Polaris::NewComponent
30
34
  @system_arguments[:tag] = :div
31
35
  @system_arguments[:classes] = class_names(
32
36
  @system_arguments[:classes],
33
- "Polaris-Card__Subsection",
37
+ "Polaris-Card__Subsection"
34
38
  )
35
39
  end
36
40
 
@@ -1,4 +1,8 @@
1
1
  <%= render Polaris::BaseComponent.new(**@system_arguments) do %>
2
+ <% if tabs.present? %>
3
+ <%= tabs %>
4
+ <% end %>
5
+
2
6
  <% if header.present? %>
3
7
  <%= header %>
4
8
  <% end %>
@@ -2,18 +2,17 @@
2
2
 
3
3
  module Polaris
4
4
  class CardComponent < Polaris::NewComponent
5
- include Polaris::ActionHelper
6
-
7
5
  FOOTER_ACTION_ALIGNMENT_DEFAULT = :right
8
6
  FOOTER_ACTION_ALIGNMENT_MAPPINGS = {
9
7
  FOOTER_ACTION_ALIGNMENT_DEFAULT => "",
10
- :left => "Polaris-Card__LeftJustified",
8
+ :left => "Polaris-Card__LeftJustified"
11
9
  }
12
10
  FOOTER_ACTION_ALIGNMENT_OPTIONS = FOOTER_ACTION_ALIGNMENT_MAPPINGS.keys
13
11
 
12
+ renders_one :tabs, Polaris::TabsComponent
14
13
  renders_one :header, Polaris::Card::HeaderComponent
15
14
  renders_many :sections, Polaris::Card::SectionComponent
16
- renders_one :primary_footer_action, -> (primary: true, **system_arguments) do
15
+ renders_one :primary_footer_action, ->(primary: true, **system_arguments) do
17
16
  Polaris::ButtonComponent.new(primary: primary, **system_arguments)
18
17
  end
19
18
  renders_many :secondary_footer_actions, Polaris::ButtonComponent
@@ -36,7 +35,7 @@ module Polaris
36
35
  @system_arguments[:classes] = class_names(
37
36
  @system_arguments[:classes],
38
37
  "Polaris-Card",
39
- "Polaris-Card--subdued": subdued,
38
+ "Polaris-Card--subdued": subdued
40
39
  )
41
40
  end
42
41
 
@@ -47,7 +46,7 @@ module Polaris
47
46
  def footer_classes
48
47
  class_names(
49
48
  "Polaris-Card__Footer",
50
- FOOTER_ACTION_ALIGNMENT_MAPPINGS[fetch_or_fallback(FOOTER_ACTION_ALIGNMENT_OPTIONS, @footer_action_alignment, FOOTER_ACTION_ALIGNMENT_DEFAULT)],
49
+ FOOTER_ACTION_ALIGNMENT_MAPPINGS[fetch_or_fallback(FOOTER_ACTION_ALIGNMENT_OPTIONS, @footer_action_alignment, FOOTER_ACTION_ALIGNMENT_DEFAULT)]
51
50
  )
52
51
  end
53
52
  end
@@ -16,7 +16,7 @@ module Polaris
16
16
  def text
17
17
  return "#{count}/#{@max_length}" if max_length?
18
18
 
19
- "#{count}"
19
+ count.to_s
20
20
  end
21
21
 
22
22
  def label_template
@@ -35,16 +35,16 @@ module Polaris
35
35
 
36
36
  private
37
37
 
38
- def max_length?
39
- @max_length.present?
40
- end
38
+ def max_length?
39
+ @max_length.present?
40
+ end
41
41
 
42
- def normalized_value
43
- @text_field.value.to_s || ''
44
- end
42
+ def normalized_value
43
+ @text_field.value.to_s || ""
44
+ end
45
45
 
46
- def count
47
- normalized_value.length
48
- end
46
+ def count
47
+ normalized_value.length
48
+ end
49
49
  end
50
50
  end
@@ -1,10 +1,6 @@
1
1
  <%= render Polaris::ChoiceComponent.new(**@wrapper_arguments) do %>
2
2
  <%= render Polaris::BaseComponent.new(**@system_arguments) do %>
3
- <% if @form.present? && @attribute.present? %>
4
- <%= @form.check_box(@attribute, @input_options, @value, @unchecked_value) %>
5
- <% else %>
6
- <%= check_box_tag(@name, @value, @checked, @input_options) %>
7
- <% end %>
3
+ <%= checkbox %>
8
4
 
9
5
  <span class="Polaris-Checkbox__Backdrop"></span>
10
6
 
@@ -6,7 +6,7 @@ module Polaris
6
6
 
7
7
  attr_reader :checked
8
8
 
9
- validates :checked, inclusion: { in: [true, false, :indeterminate] }
9
+ validates :checked, inclusion: {in: [true, false, :indeterminate]}
10
10
 
11
11
  def initialize(
12
12
  form: nil,
@@ -28,6 +28,7 @@ module Polaris
28
28
  @attribute = attribute
29
29
  @name = name
30
30
  @checked = checked
31
+ @disabled = disabled
31
32
  @value = value
32
33
  @unchecked_value = unchecked_value
33
34
 
@@ -37,7 +38,7 @@ module Polaris
37
38
  @system_arguments[:classes],
38
39
  "Polaris-Checkbox",
39
40
  "Polaris-Checkbox--labelHidden": label_hidden,
40
- "Polaris-Checkbox--error": error.present?,
41
+ "Polaris-Checkbox--error": error.present?
41
42
  )
42
43
 
43
44
  @wrapper_arguments = {
@@ -45,21 +46,14 @@ module Polaris
45
46
  label_hidden: label_hidden,
46
47
  disabled: disabled,
47
48
  help_text: help_text,
48
- error: error,
49
+ error: error
49
50
  }.merge(wrapper_arguments)
50
51
 
51
52
  @input_options = input_options
52
- @input_options[:aria] ||= {}
53
- @input_options[:disabled] = true if disabled
54
- @input_options[:aria][:checked] = checked
55
- if indeterminate?
56
- @input_options[:indeterminate] = true
57
- @input_options[:aria][:checked] = "mixed"
58
- end
59
- @input_options[:class] = class_names(
53
+ @input_options[:classes] = class_names(
60
54
  @input_options[:classes],
61
55
  "Polaris-Checkbox__Input",
62
- "Polaris-Checkbox__Input--indeterminate": indeterminate?,
56
+ "Polaris-Checkbox__Input--indeterminate": indeterminate?
63
57
  )
64
58
  end
65
59
 
@@ -74,5 +68,18 @@ module Polaris
74
68
  def before_render
75
69
  validate!
76
70
  end
71
+
72
+ def checkbox
73
+ render Polaris::BaseCheckbox.new(
74
+ form: @form,
75
+ attribute: @attribute,
76
+ name: @name,
77
+ checked: @checked,
78
+ disabled: @disabled,
79
+ value: @value,
80
+ unchecked_value: @unchecked_value,
81
+ **@input_options
82
+ )
83
+ end
77
84
  end
78
85
  end
@@ -22,7 +22,7 @@ module Polaris
22
22
  @system_arguments[:classes],
23
23
  "Polaris-Choice",
24
24
  "Polaris-Choice--labelHidden": label_hidden,
25
- "Polaris-Choice--disabled": disabled,
25
+ "Polaris-Choice--disabled": disabled
26
26
  )
27
27
  end
28
28
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Polaris
4
4
  class ChoiceListComponent < Polaris::NewComponent
5
- renders_many :checkboxes, -> (value:, disabled: false, **system_arguments) do
5
+ renders_many :checkboxes, ->(value:, disabled: false, **system_arguments) do
6
6
  Polaris::CheckboxComponent.new(
7
7
  form: @form,
8
8
  attribute: @attribute,
@@ -13,7 +13,7 @@ module Polaris
13
13
  **system_arguments
14
14
  )
15
15
  end
16
- renders_many :radio_buttons, -> (value:, disabled: false, **system_arguments) do
16
+ renders_many :radio_buttons, ->(value:, disabled: false, **system_arguments) do
17
17
  Polaris::RadioButtonComponent.new(
18
18
  form: @form,
19
19
  attribute: @attribute,
@@ -21,12 +21,12 @@ module Polaris
21
21
  value: value,
22
22
  checked: @selected.include?(value),
23
23
  disabled: disabled || @disabled,
24
- **system_arguments,
24
+ **system_arguments
25
25
  )
26
26
  end
27
27
 
28
28
  def initialize(
29
- title:,
29
+ title: nil,
30
30
  title_hidden: false,
31
31
  form: nil,
32
32
  attribute: nil,
@@ -49,7 +49,7 @@ module Polaris
49
49
  @system_arguments[:classes] = class_names(
50
50
  @system_arguments[:classes],
51
51
  "Polaris-ChoiceList",
52
- "Polaris-ChoiceList--titleHidden": title_hidden,
52
+ "Polaris-ChoiceList--titleHidden": title_hidden
53
53
  )
54
54
  end
55
55
 
@@ -0,0 +1,18 @@
1
+ <% if @sort_url %>
2
+ <%= render(Polaris::BaseComponent.new(**system_arguments)) do %>
3
+ <%= link_to @sort_url, class: "Polaris-DataTable__Heading" do %>
4
+ <span class="Polaris-DataTable__Icon">
5
+ <% if @sorted == :asc %>
6
+ <%= polaris_icon(name: "CaretUpMinor") %>
7
+ <% else %>
8
+ <%= polaris_icon(name: "CaretDownMinor") %>
9
+ <% end %>
10
+ </span>
11
+ <%= content %>
12
+ <% end %>
13
+ <% end %>
14
+ <% else %>
15
+ <%= render(Polaris::BaseComponent.new(**system_arguments)) do %>
16
+ <%= content %>
17
+ <% end %>
18
+ <% end %>
@@ -0,0 +1,49 @@
1
+ class Polaris::DataTable::CellComponent < Polaris::NewComponent
2
+ ALIGNMENT_DEFAULT = :top
3
+ ALIGNMENT_MAPPINGS = {
4
+ top: "Polaris-DataTable__Cell--verticalAlignTop",
5
+ bottom: "Polaris-DataTable__Cell--verticalAlignBottom",
6
+ middle: "Polaris-DataTable__Cell--verticalAlignMiddle",
7
+ baseline: "Polaris-DataTable__Cell--verticalAlignBaseline"
8
+ }
9
+ ALIGNMENT_OPTIONS = ALIGNMENT_MAPPINGS.keys
10
+
11
+ def initialize(
12
+ vertical_alignment:,
13
+ first: false,
14
+ numeric: false,
15
+ header: false,
16
+ total: false,
17
+ total_footer: false,
18
+ sorted: false,
19
+ sort_url: nil,
20
+ **system_arguments
21
+ )
22
+ @vertical_alignment = vertical_alignment
23
+ @numeric = numeric
24
+ @first = first
25
+ @header = header
26
+ @total = total
27
+ @total_footer = total_footer
28
+ @sorted = sorted
29
+ @sort_url = sort_url
30
+ @system_arguments = system_arguments
31
+ end
32
+
33
+ def system_arguments
34
+ {tag: "td"}.deep_merge(@system_arguments).tap do |args|
35
+ args[:classes] = class_names(
36
+ args[:classes],
37
+ "Polaris-DataTable__Cell",
38
+ ALIGNMENT_MAPPINGS[@vertical_alignment],
39
+ "Polaris-DataTable__Cell--firstColumn": @first,
40
+ "Polaris-DataTable__Cell--numeric": @numeric,
41
+ "Polaris-DataTable__Cell--header": @header,
42
+ "Polaris-DataTable__Cell--total": @total,
43
+ "Polaris-DataTable__Cell--sortable": @sort_url.present?,
44
+ "Polaris-DataTable__Cell--sorted": @sorted,
45
+ "Polaris-DataTable--cellTotalFooter": @total_footer
46
+ )
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,19 @@
1
+ class Polaris::DataTable::ColumnComponent < Polaris::NewComponent
2
+ SORT_DEFAULT = false
3
+ SORT_OPTIONS = [false, :asc, :desc]
4
+
5
+ attr_reader :title, :numeric, :total, :sorted, :sort_url
6
+
7
+ def initialize(title, numeric: false, total: nil, sorted: SORT_DEFAULT, sort_url: nil, **system_arguments, &block)
8
+ @title = title
9
+ @numeric = numeric
10
+ @total = total
11
+ @sorted = fetch_or_fallback(SORT_OPTIONS, sorted, SORT_DEFAULT)
12
+ @sort_url = sort_url
13
+ @block = block
14
+ end
15
+
16
+ def call(row)
17
+ @block.call(row)
18
+ end
19
+ end