polaris_view_components 0.5.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -2
  3. data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +136 -0
  4. data/app/assets/javascripts/polaris_view_components/button_controller.js +47 -0
  5. data/app/assets/javascripts/polaris_view_components/dropzone_controller.js +495 -0
  6. data/app/assets/javascripts/polaris_view_components/frame_controller.js +41 -0
  7. data/app/assets/javascripts/polaris_view_components/index.js +21 -1
  8. data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
  9. data/app/assets/javascripts/polaris_view_components/option_list_controller.js +41 -0
  10. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +28 -0
  11. data/app/assets/javascripts/polaris_view_components/popover_controller.js +56 -0
  12. data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
  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/utils.js +23 -0
  16. data/app/assets/javascripts/polaris_view_components.js +2400 -1
  17. data/app/assets/stylesheets/polaris_view_components/custom.css +104 -6
  18. data/app/assets/stylesheets/polaris_view_components.css +2147 -2021
  19. data/app/assets/stylesheets/polaris_view_components.postcss.css +1 -1
  20. data/app/components/polaris/action.rb +3 -3
  21. data/app/components/polaris/action_list/item_component.html.erb +35 -0
  22. data/app/components/polaris/action_list/item_component.rb +41 -0
  23. data/app/components/polaris/action_list/section_component.html.erb +16 -0
  24. data/app/components/polaris/action_list/section_component.rb +26 -0
  25. data/app/components/polaris/action_list_component.html.erb +13 -0
  26. data/app/components/polaris/action_list_component.rb +25 -0
  27. data/app/components/polaris/autocomplete/action_component.rb +7 -0
  28. data/app/components/polaris/autocomplete/option_component.rb +35 -0
  29. data/app/components/polaris/autocomplete/section_component.html.erb +9 -0
  30. data/app/components/polaris/autocomplete/section_component.rb +12 -0
  31. data/app/components/polaris/autocomplete_component.html.erb +30 -0
  32. data/app/components/polaris/autocomplete_component.rb +65 -0
  33. data/app/components/polaris/avatar_component.rb +2 -2
  34. data/app/components/polaris/badge_component.rb +2 -2
  35. data/app/components/polaris/banner_component.rb +8 -8
  36. data/app/components/polaris/base_button.rb +2 -2
  37. data/app/components/polaris/base_checkbox.rb +48 -0
  38. data/app/components/polaris/base_component.rb +1 -1
  39. data/app/components/polaris/base_radio_button.rb +38 -0
  40. data/app/components/polaris/button_component.html.erb +13 -0
  41. data/app/components/polaris/button_group_component.rb +8 -8
  42. data/app/components/polaris/callout_card_component.rb +6 -6
  43. data/app/components/polaris/caption_component.rb +3 -3
  44. data/app/components/polaris/card/header_component.rb +2 -2
  45. data/app/components/polaris/card/section_component.rb +4 -4
  46. data/app/components/polaris/card_component.html.erb +4 -0
  47. data/app/components/polaris/card_component.rb +6 -5
  48. data/app/components/polaris/character_count.rb +10 -10
  49. data/app/components/polaris/checkbox_component.html.erb +1 -5
  50. data/app/components/polaris/checkbox_component.rb +20 -13
  51. data/app/components/polaris/choice_component.rb +2 -2
  52. data/app/components/polaris/choice_list_component.rb +6 -6
  53. data/app/components/polaris/component.rb +6 -1
  54. data/app/components/polaris/data_table/cell_component.rb +4 -4
  55. data/app/components/polaris/data_table/column_component.rb +1 -1
  56. data/app/components/polaris/data_table_component.rb +4 -4
  57. data/app/components/polaris/description_list_component.rb +5 -5
  58. data/app/components/polaris/display_text_component.rb +3 -3
  59. data/app/components/polaris/dropzone_component.html.erb +156 -0
  60. data/app/components/polaris/dropzone_component.rb +150 -0
  61. data/app/components/polaris/empty_state_component.rb +4 -4
  62. data/app/components/polaris/exception_list/item_component.rb +3 -3
  63. data/app/components/polaris/exception_list_component.rb +2 -2
  64. data/app/components/polaris/filters_component.html.erb +22 -0
  65. data/app/components/polaris/filters_component.rb +61 -8
  66. data/app/components/polaris/footer_help_component.rb +2 -2
  67. data/app/components/polaris/form_layout/group_component.rb +5 -5
  68. data/app/components/polaris/form_layout/item_component.rb +2 -2
  69. data/app/components/polaris/form_layout_component.rb +4 -4
  70. data/app/components/polaris/frame/save_bar_component.html.erb +23 -0
  71. data/app/components/polaris/frame/save_bar_component.rb +31 -0
  72. data/app/components/polaris/frame/top_bar_component.html.erb +30 -0
  73. data/app/components/polaris/frame/top_bar_component.rb +18 -0
  74. data/app/components/polaris/frame_component.html.erb +44 -0
  75. data/app/components/polaris/frame_component.rb +33 -0
  76. data/app/components/polaris/heading_component.rb +2 -2
  77. data/app/components/polaris/headless_button.html.erb +13 -0
  78. data/app/components/polaris/headless_button.rb +18 -6
  79. data/app/components/polaris/icon_component.rb +3 -3
  80. data/app/components/polaris/index_table/cell_component.rb +3 -3
  81. data/app/components/polaris/index_table/column_component.rb +1 -1
  82. data/app/components/polaris/index_table_component.rb +4 -4
  83. data/app/components/polaris/inline_error_component.rb +2 -2
  84. data/app/components/polaris/label_component.rb +3 -3
  85. data/app/components/polaris/labelled_component.rb +3 -3
  86. data/app/components/polaris/layout/annotated_section.rb +2 -2
  87. data/app/components/polaris/layout/section.rb +2 -2
  88. data/app/components/polaris/layout_component.rb +4 -4
  89. data/app/components/polaris/link_component.rb +4 -4
  90. data/app/components/polaris/list_component.rb +5 -5
  91. data/app/components/polaris/logo.rb +13 -0
  92. data/app/components/polaris/modal/section_component.rb +19 -0
  93. data/app/components/polaris/modal_component.html.erb +79 -0
  94. data/app/components/polaris/modal_component.rb +98 -0
  95. data/app/components/polaris/navigation/item_component.html.erb +31 -0
  96. data/app/components/polaris/navigation/item_component.rb +85 -0
  97. data/app/components/polaris/navigation/section_component.html.erb +17 -0
  98. data/app/components/polaris/navigation/section_component.rb +64 -0
  99. data/app/components/polaris/navigation_component.html.erb +29 -0
  100. data/app/components/polaris/navigation_component.rb +15 -0
  101. data/app/components/polaris/option_list/checkbox_component.html.erb +14 -0
  102. data/app/components/polaris/option_list/checkbox_component.rb +37 -0
  103. data/app/components/polaris/option_list/option_component.rb +24 -0
  104. data/app/components/polaris/option_list/radio_button_component.rb +54 -0
  105. data/app/components/polaris/option_list/section_component.html.erb +14 -0
  106. data/app/components/polaris/option_list/section_component.rb +53 -0
  107. data/app/components/polaris/option_list_component.html.erb +15 -0
  108. data/app/components/polaris/option_list_component.rb +67 -0
  109. data/app/components/polaris/page_actions_component.rb +9 -8
  110. data/app/components/polaris/page_component.rb +5 -5
  111. data/app/components/polaris/pagination_component.rb +2 -6
  112. data/app/components/polaris/popover/pane_component.html.erb +25 -0
  113. data/app/components/polaris/popover/pane_component.rb +20 -0
  114. data/app/components/polaris/popover/section_component.rb +19 -0
  115. data/app/components/polaris/popover_component.html.erb +31 -0
  116. data/app/components/polaris/popover_component.rb +113 -0
  117. data/app/components/polaris/progress_bar_component.rb +6 -6
  118. data/app/components/polaris/radio_button_component.html.erb +1 -6
  119. data/app/components/polaris/radio_button_component.rb +18 -8
  120. data/app/components/polaris/resource_item_component.html.erb +16 -6
  121. data/app/components/polaris/resource_item_component.rb +43 -10
  122. data/app/components/polaris/resource_list_component.rb +3 -3
  123. data/app/components/polaris/scrollable_component.html.erb +5 -0
  124. data/app/components/polaris/scrollable_component.rb +48 -0
  125. data/app/components/polaris/select_component.rb +4 -4
  126. data/app/components/polaris/setting_toggle_component.html.erb +10 -0
  127. data/app/components/polaris/setting_toggle_component.rb +24 -0
  128. data/app/components/polaris/shopify_navigation_component.rb +8 -8
  129. data/app/components/polaris/skeleton_body_text_component.rb +2 -2
  130. data/app/components/polaris/spacer_component.rb +4 -4
  131. data/app/components/polaris/spinner_component.rb +3 -3
  132. data/app/components/polaris/stack/item_component.rb +15 -0
  133. data/app/components/polaris/stack_component.rb +6 -22
  134. data/app/components/polaris/subheading_component.rb +2 -2
  135. data/app/components/polaris/tabs/tab_component.html.erb +10 -0
  136. data/app/components/polaris/tabs/tab_component.rb +34 -0
  137. data/app/components/polaris/tabs_component.html.erb +7 -0
  138. data/app/components/polaris/tabs_component.rb +37 -0
  139. data/app/components/polaris/tag_component.rb +3 -2
  140. data/app/components/polaris/text_container_component.rb +3 -3
  141. data/app/components/polaris/text_field_component.rb +25 -11
  142. data/app/components/polaris/text_style_component.rb +5 -5
  143. data/app/components/polaris/thumbnail_component.rb +3 -3
  144. data/app/components/polaris/toast_component.html.erb +21 -0
  145. data/app/components/polaris/toast_component.rb +40 -0
  146. data/app/components/polaris/top_bar/user_menu_component.html.erb +19 -0
  147. data/app/components/polaris/top_bar/user_menu_component.rb +9 -0
  148. data/app/components/polaris/visually_hidden_component.rb +1 -1
  149. data/app/helpers/polaris/form_builder.rb +19 -8
  150. data/app/helpers/polaris/url_helper.rb +3 -3
  151. data/app/helpers/polaris/view_helper.rb +24 -4
  152. data/app/validators/type_validator.rb +2 -2
  153. data/config/locales/en.yml +6 -0
  154. data/lib/generators/polaris_view_components/install_generator.rb +5 -5
  155. data/lib/polaris/view_components/engine.rb +16 -2
  156. data/lib/polaris/view_components/version.rb +1 -1
  157. data/lib/polaris_view_components.rb +1 -1
  158. metadata +79 -16
  159. data/app/components/polaris/application_component.rb +0 -35
  160. data/app/components/polaris/dropzone/component.html.erb +0 -72
  161. data/app/components/polaris/dropzone/component.rb +0 -128
  162. data/app/components/polaris/dropzone/controller.js +0 -226
  163. data/app/components/polaris/dropzone/utils.js +0 -57
  164. data/app/components/polaris/new_component.rb +0 -10
  165. data/app/helpers/polaris/conditional_helper.rb +0 -11
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class CalloutCardComponent < Polaris::NewComponent
4
+ class CalloutCardComponent < Polaris::Component
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
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class CaptionComponent < Polaris::NewComponent
4
+ class CaptionComponent < Polaris::Component
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,4 +1,4 @@
1
- class Polaris::Card::HeaderComponent < Polaris::NewComponent
1
+ class Polaris::Card::HeaderComponent < Polaris::Component
2
2
  def initialize(
3
3
  title: "",
4
4
  actions: [],
@@ -8,7 +8,7 @@ class Polaris::Card::HeaderComponent < Polaris::NewComponent
8
8
  @system_arguments[:tag] = :div
9
9
  @system_arguments[:classes] = class_names(
10
10
  @system_arguments[:classes],
11
- "Polaris-Card__Header",
11
+ "Polaris-Card__Header"
12
12
  )
13
13
 
14
14
  @title = title
@@ -1,4 +1,4 @@
1
- class Polaris::Card::SectionComponent < Polaris::NewComponent
1
+ class Polaris::Card::SectionComponent < Polaris::Component
2
2
  renders_many :subsections, "Polaris::Card::SubsectionComponent"
3
3
 
4
4
  def initialize(
@@ -21,20 +21,20 @@ class Polaris::Card::SectionComponent < Polaris::NewComponent
21
21
  "Polaris-Card__Section--subdued": subdued,
22
22
  "Polaris-Card__Section--fullWidth": full_width,
23
23
  "Polaris-Card__Section--borderTop": border_top,
24
- "Polaris-Card__Section--borderBottom": border_bottom,
24
+ "Polaris-Card__Section--borderBottom": border_bottom
25
25
  )
26
26
 
27
27
  @title = title
28
28
  @actions = actions.map { |a| a.merge(plain: true) }
29
29
  end
30
30
 
31
- class Polaris::Card::SubsectionComponent < Polaris::NewComponent
31
+ class Polaris::Card::SubsectionComponent < Polaris::Component
32
32
  def initialize(**system_arguments)
33
33
  @system_arguments = system_arguments
34
34
  @system_arguments[:tag] = :div
35
35
  @system_arguments[:classes] = class_names(
36
36
  @system_arguments[:classes],
37
- "Polaris-Card__Subsection",
37
+ "Polaris-Card__Subsection"
38
38
  )
39
39
  end
40
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 %>
@@ -1,17 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class CardComponent < Polaris::NewComponent
4
+ class CardComponent < Polaris::Component
5
5
  FOOTER_ACTION_ALIGNMENT_DEFAULT = :right
6
6
  FOOTER_ACTION_ALIGNMENT_MAPPINGS = {
7
7
  FOOTER_ACTION_ALIGNMENT_DEFAULT => "",
8
- :left => "Polaris-Card__LeftJustified",
8
+ :left => "Polaris-Card__LeftJustified"
9
9
  }
10
10
  FOOTER_ACTION_ALIGNMENT_OPTIONS = FOOTER_ACTION_ALIGNMENT_MAPPINGS.keys
11
11
 
12
+ renders_one :tabs, Polaris::TabsComponent
12
13
  renders_one :header, Polaris::Card::HeaderComponent
13
14
  renders_many :sections, Polaris::Card::SectionComponent
14
- renders_one :primary_footer_action, -> (primary: true, **system_arguments) do
15
+ renders_one :primary_footer_action, ->(primary: true, **system_arguments) do
15
16
  Polaris::ButtonComponent.new(primary: primary, **system_arguments)
16
17
  end
17
18
  renders_many :secondary_footer_actions, Polaris::ButtonComponent
@@ -34,7 +35,7 @@ module Polaris
34
35
  @system_arguments[:classes] = class_names(
35
36
  @system_arguments[:classes],
36
37
  "Polaris-Card",
37
- "Polaris-Card--subdued": subdued,
38
+ "Polaris-Card--subdued": subdued
38
39
  )
39
40
  end
40
41
 
@@ -45,7 +46,7 @@ module Polaris
45
46
  def footer_classes
46
47
  class_names(
47
48
  "Polaris-Card__Footer",
48
- 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)]
49
50
  )
50
51
  end
51
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
 
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class CheckboxComponent < Polaris::NewComponent
4
+ class CheckboxComponent < Polaris::Component
5
5
  include ActiveModel::Validations
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class ChoiceComponent < Polaris::NewComponent
4
+ class ChoiceComponent < Polaris::Component
5
5
  def initialize(
6
6
  label:,
7
7
  label_hidden:,
@@ -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
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class ChoiceListComponent < Polaris::NewComponent
5
- renders_many :checkboxes, -> (value:, disabled: false, **system_arguments) do
4
+ class ChoiceListComponent < Polaris::Component
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
 
@@ -1,5 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Polaris
2
- class Component < ApplicationComponent
4
+ class Component < ViewComponent::Base
5
+ include ClassNameHelper
6
+ include FetchOrFallbackHelper
7
+ include OptionHelper
3
8
  include ViewHelper
4
9
  end
5
10
  end
@@ -1,10 +1,10 @@
1
- class Polaris::DataTable::CellComponent < Polaris::NewComponent
1
+ class Polaris::DataTable::CellComponent < Polaris::Component
2
2
  ALIGNMENT_DEFAULT = :top
3
3
  ALIGNMENT_MAPPINGS = {
4
4
  top: "Polaris-DataTable__Cell--verticalAlignTop",
5
5
  bottom: "Polaris-DataTable__Cell--verticalAlignBottom",
6
6
  middle: "Polaris-DataTable__Cell--verticalAlignMiddle",
7
- baseline: "Polaris-DataTable__Cell--verticalAlignBaseline",
7
+ baseline: "Polaris-DataTable__Cell--verticalAlignBaseline"
8
8
  }
9
9
  ALIGNMENT_OPTIONS = ALIGNMENT_MAPPINGS.keys
10
10
 
@@ -31,7 +31,7 @@ class Polaris::DataTable::CellComponent < Polaris::NewComponent
31
31
  end
32
32
 
33
33
  def system_arguments
34
- { tag: "td" }.deep_merge(@system_arguments).tap do |args|
34
+ {tag: "td"}.deep_merge(@system_arguments).tap do |args|
35
35
  args[:classes] = class_names(
36
36
  args[:classes],
37
37
  "Polaris-DataTable__Cell",
@@ -42,7 +42,7 @@ class Polaris::DataTable::CellComponent < Polaris::NewComponent
42
42
  "Polaris-DataTable__Cell--total": @total,
43
43
  "Polaris-DataTable__Cell--sortable": @sort_url.present?,
44
44
  "Polaris-DataTable__Cell--sorted": @sorted,
45
- "Polaris-DataTable--cellTotalFooter": @total_footer,
45
+ "Polaris-DataTable--cellTotalFooter": @total_footer
46
46
  )
47
47
  end
48
48
  end
@@ -1,4 +1,4 @@
1
- class Polaris::DataTable::ColumnComponent < Polaris::NewComponent
1
+ class Polaris::DataTable::ColumnComponent < Polaris::Component
2
2
  SORT_DEFAULT = false
3
3
  SORT_OPTIONS = [false, :asc, :desc]
4
4
 
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class DataTableComponent < Polaris::NewComponent
4
+ class DataTableComponent < Polaris::Component
5
5
  ALIGNMENT_DEFAULT = :top
6
6
  ALIGNMENT_OPTIONS = [:top, :bottom, :middle, :baseline]
7
7
 
8
- renders_many :columns, -> (title, **system_arguments, &block) do
8
+ renders_many :columns, ->(title, **system_arguments, &block) do
9
9
  DataTable::ColumnComponent.new(title, **system_arguments, &block)
10
10
  end
11
11
  renders_one :footer
@@ -27,10 +27,10 @@ module Polaris
27
27
  end
28
28
 
29
29
  def system_arguments
30
- { tag: "div" }.deep_merge(@system_arguments).tap do |args|
30
+ {tag: "div"}.deep_merge(@system_arguments).tap do |args|
31
31
  args[:classes] = class_names(
32
32
  args[:classes],
33
- "Polaris-DataTable",
33
+ "Polaris-DataTable"
34
34
  )
35
35
  end
36
36
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class DescriptionListComponent < Polaris::NewComponent
4
+ class DescriptionListComponent < Polaris::Component
5
5
  SPACING_DEFAULT = :loose
6
6
  SPACING_MAPPINGS = {
7
7
  SPACING_DEFAULT => "",
8
- :tight => "Polaris-DescriptionList--spacingTight",
8
+ :tight => "Polaris-DescriptionList--spacingTight"
9
9
  }
10
10
  SPACING_OPTIONS = SPACING_MAPPINGS.keys
11
11
 
@@ -17,7 +17,7 @@ module Polaris
17
17
  @system_arguments[:classes] = class_names(
18
18
  @system_arguments[:classes],
19
19
  "Polaris-DescriptionList",
20
- SPACING_MAPPINGS[fetch_or_fallback(SPACING_OPTIONS, spacing, SPACING_DEFAULT)],
20
+ SPACING_MAPPINGS[fetch_or_fallback(SPACING_OPTIONS, spacing, SPACING_DEFAULT)]
21
21
  )
22
22
  end
23
23
 
@@ -25,7 +25,7 @@ module Polaris
25
25
  items.any?
26
26
  end
27
27
 
28
- class DescriptionListItemComponent < Polaris::NewComponent
28
+ class DescriptionListItemComponent < Polaris::Component
29
29
  def initialize(term:)
30
30
  @term = term
31
31
  end
@@ -33,7 +33,7 @@ module Polaris
33
33
  def call
34
34
  safe_join [
35
35
  tag.dt(class: "Polaris-DescriptionList__Term") { @term },
36
- tag.dd(class: "Polaris-DescriptionList__Description") { content },
36
+ tag.dd(class: "Polaris-DescriptionList__Description") { content }
37
37
  ]
38
38
  end
39
39
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class DisplayTextComponent < Polaris::NewComponent
4
+ class DisplayTextComponent < Polaris::Component
5
5
  ELEMENT_DEFAULT = :p
6
6
  ELEMENT_OPTIONS = %i[p h1 h2 h3 h4 h5 h6]
7
7
 
@@ -10,7 +10,7 @@ module Polaris
10
10
  small: "Polaris-DisplayText--sizeSmall",
11
11
  medium: "Polaris-DisplayText--sizeMedium",
12
12
  large: "Polaris-DisplayText--sizeLarge",
13
- extra_large: "Polaris-DisplayText--sizeExtraLarge",
13
+ extra_large: "Polaris-DisplayText--sizeExtraLarge"
14
14
  }
15
15
  SIZE_OPTIONS = SIZE_MAPPINGS.keys
16
16
 
@@ -24,7 +24,7 @@ module Polaris
24
24
  @system_arguments[:classes] = class_names(
25
25
  @system_arguments[:classes],
26
26
  "Polaris-DisplayText",
27
- SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
27
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
28
28
  )
29
29
  end
30
30
 
@@ -0,0 +1,156 @@
1
+ <%= render Polaris::LabelledComponent.new(**wrapper_arguments) do %>
2
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
3
+ <div
4
+ class="Polaris-DropZone__Overlay Polaris-VisuallyHidden"
5
+ data-polaris-dropzone-target="overlay"
6
+ >
7
+ <%= render Polaris::StackComponent.new(vertical: true, spacing: :tight) do |stack| %>
8
+ <% stack.item do %>
9
+ <%= render Polaris::DisplayTextComponent.new(size: :small) do %>
10
+ <%= @overlay_text %>
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
14
+ </div>
15
+
16
+ <div
17
+ class="Polaris-DropZone__Overlay Polaris-VisuallyHidden"
18
+ data-polaris-dropzone-target="errorOverlay"
19
+ >
20
+ <%= render Polaris::StackComponent.new(vertical: true, spacing: :tight) do |stack| %>
21
+ <% stack.item do %>
22
+ <%= render Polaris::DisplayTextComponent.new(size: :small) do %>
23
+ <%= @error_overlay_text %>
24
+ <% end %>
25
+ <% end %>
26
+ <% end %>
27
+ </div>
28
+
29
+ <div class="Polaris-DropZone__Container" data-polaris-dropzone-target="container">
30
+ <%= render Polaris::BaseComponent.new(**file_upload_arguments) do %>
31
+ <%= render Polaris::StackComponent.new(vertical: true, spacing: :tight) do |stack| %>
32
+ <% unless @size == :medium %>
33
+ <% stack.item do %>
34
+ <img width="<%= @size == :small ? 20 : 40 %>" src="data:image/svg+xml,%3csvg fill='none' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill-rule='evenodd' clip-rule='evenodd' d='M20 10a10 10 0 11-20 0 10 10 0 0120 0zM5.3 8.3l4-4a1 1 0 011.4 0l4 4a1 1 0 01-1.4 1.4L11 7.4V15a1 1 0 11-2 0V7.4L6.7 9.7a1 1 0 01-1.4-1.4z' fill='%235C5F62'/%3e%3c/svg%3e" alt="">
35
+ <% end %>
36
+ <% end %>
37
+
38
+ <% unless @size == :small %>
39
+ <% stack.item do %>
40
+ <% if @size == :medium %>
41
+ <div class="Polaris-DropZone-FileUpload__ActionTitle">
42
+ <%= @file_upload_button %>
43
+ </div>
44
+ <% else %>
45
+ <div class="Polaris-DropZone-FileUpload__Button">
46
+ <%= @file_upload_button %>
47
+ </div>
48
+ <% end %>
49
+ <% end %>
50
+ <% end %>
51
+
52
+ <% unless @size == :small %>
53
+ <% stack.item do %>
54
+ <% help_text = capture do %>
55
+ <%= render Polaris::TextStyleComponent.new(variation: :subdued) do %>
56
+ <%= @file_upload_help %>
57
+ <% end %>
58
+ <% end %>
59
+
60
+ <% if @size == :medium %>
61
+ <%= polaris_caption { help_text } %>
62
+ <% else %>
63
+ <%= help_text %>
64
+ <% end %>
65
+ <% end %>
66
+ <% end %>
67
+ <% end %>
68
+ <% end %>
69
+
70
+ <div class="Polaris-DropZone__Loader Polaris--hidden" data-polaris-dropzone-target="loader">
71
+ <%= polaris_spinner %>
72
+ </div>
73
+ </div>
74
+
75
+ <%= render Polaris::VisuallyHiddenComponent.new do %>
76
+ <% if @form.present? && @attribute.present? %>
77
+ <%= @form.file_field(@attribute, **input_options) %>
78
+ <% else %>
79
+ <%= file_field_tag(@name, **input_options) %>
80
+ <% end %>
81
+ <% end %>
82
+
83
+ <template data-polaris-dropzone-target="previewTemplate">
84
+ <%= tag.div(
85
+ data: { polaris_dropzone_target: "preview" },
86
+ class: [
87
+ "Polaris-DropZone__Preview",
88
+ "Polaris-DropZone__Preview--singleFile": !@multiple,
89
+ "Polaris-DropZone__Preview--sizeSmall": @size == :small
90
+ ]
91
+ ) do %>
92
+ <% if @size.in?(%i[small]) %>
93
+ <span class="target"></span>
94
+ <% else %>
95
+ <%= polaris_stack(vertical: true) do %>
96
+ <span class="target"></span>
97
+ <% end %>
98
+ <% end %>
99
+ <% end %>
100
+ </template>
101
+
102
+ <template data-polaris-dropzone-target="itemTemplate">
103
+ <% if @size.in?(%i[small]) %>
104
+ <%= polaris_thumbnail(
105
+ size: :small,
106
+ data: { target: "icon" },
107
+ style: "border: none; background: none;"
108
+ ) do |thumbnail| %>
109
+ <%= thumbnail.icon(name: "TimelineAttachmentMajor") %>
110
+ <% end %>
111
+ <%= polaris_thumbnail(source: "#", size: :small, data: { target: "thumbnail" }) %>
112
+ <% else %>
113
+ <%= polaris_stack_item do %>
114
+ <%= polaris_stack(
115
+ alignment: :center,
116
+ vertical: !@multiple,
117
+ spacing: @multiple ? :default : :tight,
118
+ ) do |stack| %>
119
+ <% stack.item do %>
120
+ <%= polaris_thumbnail(
121
+ size: :small,
122
+ data: { target: "icon" },
123
+ style: "border: none; background: none;"
124
+ ) do |thumbnail| %>
125
+ <%= thumbnail.icon(name: "TimelineAttachmentMajor") %>
126
+ <% end %>
127
+ <%= polaris_thumbnail(source: "#", size: :small, data: { target: "thumbnail" }) %>
128
+ <% end %>
129
+
130
+ <% stack.item(fill: true) do %>
131
+ <div data-target="content">
132
+ <%= polaris_caption do %>
133
+ <%= polaris_text_subdued(data: { target: "file-size" }) { "SIZE" } %>
134
+ <% end %>
135
+ </div>
136
+
137
+ <%= polaris_progress_bar(
138
+ progress: 0,
139
+ size: :small,
140
+ data: { target: "progress-bar" },
141
+ classes: "Polaris--hidden",
142
+ style: "margin-top: 4px;"
143
+ ) %>
144
+
145
+ <%= polaris_inline_error(
146
+ data: { target: "upload-error" },
147
+ classes: "Polaris--hidden",
148
+ style: "margin-top: 4px;"
149
+ ) { @upload_error_text } %>
150
+ <% end %>
151
+ <% end %>
152
+ <% end %>
153
+ <% end %>
154
+ </template>
155
+ <% end %>
156
+ <% end %>