polaris_view_components 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +32 -15
  3. data/app/assets/javascripts/polaris_view_components/dropzone_controller.js +495 -0
  4. data/app/assets/javascripts/polaris_view_components/index.js +2 -0
  5. data/app/assets/javascripts/polaris_view_components/popover_controller.js +9 -2
  6. data/app/assets/javascripts/polaris_view_components/utils.js +23 -0
  7. data/app/assets/javascripts/polaris_view_components.js +533 -63
  8. data/app/assets/stylesheets/polaris_view_components/custom.css +38 -6
  9. data/app/assets/stylesheets/polaris_view_components.css +2102 -2021
  10. data/app/assets/stylesheets/polaris_view_components.postcss.css +1 -1
  11. data/app/components/polaris/action_list/item_component.rb +1 -1
  12. data/app/components/polaris/action_list/section_component.rb +1 -1
  13. data/app/components/polaris/action_list_component.rb +1 -1
  14. data/app/components/polaris/autocomplete/action_component.rb +1 -1
  15. data/app/components/polaris/autocomplete/option_component.rb +1 -1
  16. data/app/components/polaris/autocomplete/section_component.rb +1 -1
  17. data/app/components/polaris/autocomplete_component.rb +9 -2
  18. data/app/components/polaris/avatar_component.rb +1 -1
  19. data/app/components/polaris/badge_component.rb +1 -1
  20. data/app/components/polaris/banner_component.rb +2 -2
  21. data/app/components/polaris/base_button.rb +1 -1
  22. data/app/components/polaris/base_checkbox.rb +1 -1
  23. data/app/components/polaris/base_component.rb +1 -1
  24. data/app/components/polaris/base_radio_button.rb +1 -1
  25. data/app/components/polaris/button_group_component.rb +3 -3
  26. data/app/components/polaris/callout_card_component.rb +1 -1
  27. data/app/components/polaris/caption_component.rb +1 -1
  28. data/app/components/polaris/card/header_component.rb +1 -1
  29. data/app/components/polaris/card/section_component.rb +2 -2
  30. data/app/components/polaris/card_component.rb +1 -1
  31. data/app/components/polaris/checkbox_component.rb +1 -1
  32. data/app/components/polaris/choice_component.rb +1 -1
  33. data/app/components/polaris/choice_list_component.rb +1 -1
  34. data/app/components/polaris/component.rb +6 -1
  35. data/app/components/polaris/data_table/cell_component.rb +1 -1
  36. data/app/components/polaris/data_table/column_component.rb +1 -1
  37. data/app/components/polaris/data_table_component.rb +1 -1
  38. data/app/components/polaris/description_list_component.rb +2 -2
  39. data/app/components/polaris/display_text_component.rb +1 -1
  40. data/app/components/polaris/dropzone_component.html.erb +156 -0
  41. data/app/components/polaris/dropzone_component.rb +150 -0
  42. data/app/components/polaris/empty_state_component.rb +1 -1
  43. data/app/components/polaris/exception_list/item_component.rb +1 -1
  44. data/app/components/polaris/exception_list_component.rb +1 -1
  45. data/app/components/polaris/filters_component.rb +3 -3
  46. data/app/components/polaris/footer_help_component.rb +1 -1
  47. data/app/components/polaris/form_layout/group_component.rb +2 -2
  48. data/app/components/polaris/form_layout/item_component.rb +1 -1
  49. data/app/components/polaris/form_layout_component.rb +1 -1
  50. data/app/components/polaris/frame/save_bar_component.rb +1 -1
  51. data/app/components/polaris/frame/top_bar_component.rb +1 -1
  52. data/app/components/polaris/frame_component.rb +1 -1
  53. data/app/components/polaris/heading_component.rb +1 -1
  54. data/app/components/polaris/headless_button.rb +1 -1
  55. data/app/components/polaris/icon_component.rb +1 -1
  56. data/app/components/polaris/index_table/cell_component.rb +1 -1
  57. data/app/components/polaris/index_table/column_component.rb +1 -1
  58. data/app/components/polaris/index_table_component.rb +1 -1
  59. data/app/components/polaris/inline_error_component.rb +1 -1
  60. data/app/components/polaris/label_component.rb +1 -1
  61. data/app/components/polaris/labelled_component.rb +1 -1
  62. data/app/components/polaris/layout/annotated_section.rb +1 -1
  63. data/app/components/polaris/layout/section.rb +1 -1
  64. data/app/components/polaris/layout_component.rb +1 -1
  65. data/app/components/polaris/link_component.rb +1 -1
  66. data/app/components/polaris/list_component.rb +2 -2
  67. data/app/components/polaris/modal/section_component.rb +1 -1
  68. data/app/components/polaris/modal_component.rb +1 -1
  69. data/app/components/polaris/navigation/item_component.rb +2 -2
  70. data/app/components/polaris/navigation/section_component.rb +2 -2
  71. data/app/components/polaris/navigation_component.rb +1 -1
  72. data/app/components/polaris/option_list/checkbox_component.rb +1 -1
  73. data/app/components/polaris/option_list/option_component.rb +1 -1
  74. data/app/components/polaris/option_list/radio_button_component.rb +1 -1
  75. data/app/components/polaris/option_list/section_component.rb +1 -1
  76. data/app/components/polaris/option_list_component.rb +1 -1
  77. data/app/components/polaris/page_actions_component.rb +1 -1
  78. data/app/components/polaris/page_component.rb +1 -1
  79. data/app/components/polaris/pagination_component.rb +1 -1
  80. data/app/components/polaris/popover/pane_component.rb +1 -1
  81. data/app/components/polaris/popover/section_component.rb +1 -1
  82. data/app/components/polaris/popover_component.rb +10 -4
  83. data/app/components/polaris/progress_bar_component.rb +1 -1
  84. data/app/components/polaris/radio_button_component.rb +1 -1
  85. data/app/components/polaris/resource_item_component.rb +1 -1
  86. data/app/components/polaris/resource_list_component.rb +1 -1
  87. data/app/components/polaris/scrollable_component.rb +1 -1
  88. data/app/components/polaris/select_component.rb +1 -1
  89. data/app/components/polaris/setting_toggle_component.rb +1 -1
  90. data/app/components/polaris/shopify_navigation_component.rb +2 -2
  91. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  92. data/app/components/polaris/spacer_component.rb +1 -1
  93. data/app/components/polaris/spinner_component.rb +1 -1
  94. data/app/components/polaris/stack/item_component.rb +15 -0
  95. data/app/components/polaris/stack_component.rb +2 -18
  96. data/app/components/polaris/subheading_component.rb +1 -1
  97. data/app/components/polaris/tabs/tab_component.rb +1 -1
  98. data/app/components/polaris/tabs_component.rb +1 -1
  99. data/app/components/polaris/tag_component.rb +3 -2
  100. data/app/components/polaris/text_container_component.rb +1 -1
  101. data/app/components/polaris/text_field_component.rb +2 -2
  102. data/app/components/polaris/text_style_component.rb +1 -1
  103. data/app/components/polaris/thumbnail_component.rb +1 -1
  104. data/app/components/polaris/toast_component.rb +1 -1
  105. data/app/components/polaris/top_bar/user_menu_component.rb +1 -1
  106. data/app/components/polaris/visually_hidden_component.rb +1 -1
  107. data/app/helpers/polaris/form_builder.rb +14 -5
  108. data/app/helpers/polaris/view_helper.rb +2 -1
  109. data/lib/polaris/view_components/engine.rb +5 -1
  110. data/lib/polaris/view_components/version.rb +1 -1
  111. metadata +7 -9
  112. data/app/components/polaris/application_component.rb +0 -35
  113. data/app/components/polaris/dropzone/component.html.erb +0 -72
  114. data/app/components/polaris/dropzone/component.rb +0 -128
  115. data/app/components/polaris/dropzone/controller.js +0 -226
  116. data/app/components/polaris/dropzone/utils.js +0 -57
  117. data/app/components/polaris/new_component.rb +0 -10
  118. data/app/helpers/polaris/conditional_helper.rb +0 -11
@@ -1,4 +1,4 @@
1
- @import "@shopify/polaris/dist/styles.css";
1
+ @import "@shopify/polaris/build/esm/styles.css";
2
2
  @import "./polaris_view_components/shopify_navigation.css";
3
3
  @import "./polaris_view_components/spacer_component.css";
4
4
  @import "./polaris_view_components/custom.css";
@@ -1,4 +1,4 @@
1
- class Polaris::ActionList::ItemComponent < Polaris::NewComponent
1
+ class Polaris::ActionList::ItemComponent < Polaris::Component
2
2
  renders_one :prefix
3
3
  renders_one :suffix
4
4
 
@@ -1,4 +1,4 @@
1
- class Polaris::ActionList::SectionComponent < Polaris::NewComponent
1
+ class Polaris::ActionList::SectionComponent < Polaris::Component
2
2
  renders_many :items, Polaris::ActionList::ItemComponent
3
3
 
4
4
  def initialize(position: 1, title: nil, **system_arguments)
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
- class ActionListComponent < Polaris::NewComponent
2
+ class ActionListComponent < Polaris::Component
3
3
  renders_many :items, Polaris::ActionList::ItemComponent
4
4
  renders_many :sections, ->(**system_arguments) do
5
5
  @counter += 1
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
- class Autocomplete::ActionComponent < NewComponent
2
+ class Autocomplete::ActionComponent < Component
3
3
  def initialize(**system_arguments)
4
4
  @system_arguments = system_arguments
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
- class Autocomplete::OptionComponent < NewComponent
2
+ class Autocomplete::OptionComponent < Component
3
3
  def initialize(
4
4
  label:,
5
5
  multiple: false,
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
- class Autocomplete::SectionComponent < NewComponent
2
+ class Autocomplete::SectionComponent < Component
3
3
  renders_many :options, ->(**system_arguments) do
4
4
  Autocomplete::OptionComponent.new(multiple: @multiple, **system_arguments)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
- class AutocompleteComponent < NewComponent
2
+ class AutocompleteComponent < Component
3
3
  renders_one :text_field, ->(**system_arguments) do
4
4
  system_arguments[:data] ||= {}
5
5
  prepend_option(system_arguments[:data], :action, %w[
@@ -21,9 +21,15 @@ module Polaris
21
21
  end
22
22
  renders_one :empty_state
23
23
 
24
- def initialize(multiple: false, url: nil, **system_arguments)
24
+ def initialize(
25
+ multiple: false,
26
+ url: nil,
27
+ selected: [],
28
+ **system_arguments
29
+ )
25
30
  @multiple = multiple
26
31
  @url = url
32
+ @selected = selected
27
33
  @system_arguments = system_arguments
28
34
  end
29
35
 
@@ -35,6 +41,7 @@ module Polaris
35
41
  if @url.present?
36
42
  opts[:data][:polaris_autocomplete_url_value] = @url
37
43
  end
44
+ opts[:data][:polaris_autocomplete_selected_value] = @selected
38
45
  end
39
46
  end
40
47
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class AvatarComponent < Polaris::NewComponent
4
+ class AvatarComponent < Polaris::Component
5
5
  SIZE_DEFAULT = :medium
6
6
  SIZE_MAPPINGS = {
7
7
  small: "Polaris-Avatar--sizeSmall",
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class BadgeComponent < Polaris::NewComponent
4
+ class BadgeComponent < Polaris::Component
5
5
  PROGRESS_DEFAULT = :default
6
6
  PROGRESS_MAPPINGS = {
7
7
  PROGRESS_DEFAULT => "",
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class BannerComponent < Polaris::NewComponent
4
+ class BannerComponent < Polaris::Component
5
5
  STATUS_DEFAULT = :default
6
6
  STATUS_MAPPINGS = {
7
7
  STATUS_DEFAULT => "",
@@ -72,7 +72,7 @@ module Polaris
72
72
  end
73
73
  end
74
74
 
75
- class SecondaryAction < Polaris::NewComponent
75
+ class SecondaryAction < Polaris::Component
76
76
  def initialize(**system_arguments)
77
77
  @system_arguments = system_arguments
78
78
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class BaseButton < Polaris::NewComponent
4
+ class BaseButton < Polaris::Component
5
5
  def initialize(
6
6
  url: nil,
7
7
  external: false,
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
- class BaseCheckbox < Polaris::NewComponent
2
+ class BaseCheckbox < Polaris::Component
3
3
  def initialize(
4
4
  form: nil,
5
5
  attribute: nil,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class BaseComponent < Polaris::NewComponent
4
+ class BaseComponent < Polaris::Component
5
5
  def initialize(tag:, classes: nil, **system_arguments)
6
6
  @tag = tag
7
7
  @system_arguments = system_arguments
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
- class BaseRadioButton < Polaris::NewComponent
2
+ class BaseRadioButton < Polaris::Component
3
3
  def initialize(
4
4
  form: nil,
5
5
  attribute: nil,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class ButtonGroupComponent < Polaris::NewComponent
4
+ class ButtonGroupComponent < Polaris::Component
5
5
  SPACING_DEFAULT = :default
6
6
  SPACING_MAPPINGS = {
7
7
  SPACING_DEFAULT => "",
@@ -63,7 +63,7 @@ module Polaris
63
63
  all_items.sort_by(&:position)
64
64
  end
65
65
 
66
- class ButtonGroupItemButtonComponent < Polaris::NewComponent
66
+ class ButtonGroupItemButtonComponent < Polaris::Component
67
67
  attr_reader :position
68
68
 
69
69
  def initialize(position:, **system_arguments)
@@ -87,7 +87,7 @@ module Polaris
87
87
  end
88
88
  end
89
89
 
90
- class ButtonGroupItemComponent < Polaris::NewComponent
90
+ class ButtonGroupItemComponent < Polaris::Component
91
91
  attr_reader :position
92
92
 
93
93
  def initialize(position:, **system_arguments)
@@ -1,7 +1,7 @@
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
6
  renders_one :secondary_action, ->(plain: true, **system_arguments) do
7
7
  Polaris::ButtonComponent.new(plain: plain, **system_arguments)
@@ -1,7 +1,7 @@
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
7
  @system_arguments[:tag] = "p"
@@ -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: [],
@@ -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(
@@ -28,7 +28,7 @@ class Polaris::Card::SectionComponent < Polaris::NewComponent
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
@@ -1,7 +1,7 @@
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 => "",
@@ -1,7 +1,7 @@
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
@@ -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:,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class ChoiceListComponent < Polaris::NewComponent
4
+ class ChoiceListComponent < Polaris::Component
5
5
  renders_many :checkboxes, ->(value:, disabled: false, **system_arguments) do
6
6
  Polaris::CheckboxComponent.new(
7
7
  form: @form,
@@ -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,4 +1,4 @@
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",
@@ -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,7 +1,7 @@
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
 
@@ -1,7 +1,7 @@
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 => "",
@@ -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
@@ -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
 
@@ -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 %>
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ # Lets users upload files by dragging and dropping the files into an area on a page, or activating a button.
5
+ class DropzoneComponent < Polaris::Component
6
+ include ActiveModel::Validations
7
+
8
+ SIZE_DEFAULT = :extra_large
9
+ SIZE_MAPPINGS = {
10
+ small: "Polaris-DropZone--sizeSmall",
11
+ medium: "Polaris-DropZone--sizeMedium",
12
+ large: "Polaris-DropZone--sizeLarge",
13
+ extra_large: "Polaris-DropZone--sizeExtraLarge"
14
+ }
15
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
16
+
17
+ attr_reader :label_action
18
+
19
+ validates :label_action, type: Action, allow_nil: true
20
+
21
+ def initialize(
22
+ form: nil,
23
+ attribute: nil,
24
+ name: nil,
25
+ accept: "",
26
+ direct_upload: false,
27
+ multiple: true,
28
+ size: SIZE_DEFAULT,
29
+ drop_on_page: false,
30
+ preview: true,
31
+ outline: true,
32
+ overlay_text: "Drop files to upload",
33
+ error_overlay_text: "This file type isn't accepted",
34
+ upload_error_text: "File upload failed",
35
+ label: nil,
36
+ label_hidden: true,
37
+ label_action: nil,
38
+ disabled: false,
39
+ error: false,
40
+ file_upload_button: nil,
41
+ file_upload_help: "or drop files to upload",
42
+ file_upload_arguments: {},
43
+ wrapper_arguments: {},
44
+ input_options: {},
45
+ **system_arguments
46
+ )
47
+ @form = form
48
+ @attribute = attribute
49
+ @name = name
50
+ @accept = accept
51
+ @direct_upload = direct_upload
52
+ @multiple = multiple
53
+ @size = size
54
+ @drop_on_page = drop_on_page
55
+ @preview = preview
56
+ @outline = outline
57
+ @overlay_text = overlay_text
58
+ @error_overlay_text = error_overlay_text
59
+ @upload_error_text = upload_error_text
60
+ @label = label
61
+ @label_hidden = label_hidden
62
+ @label_action = label_action
63
+ @disabled = disabled
64
+ @error = error
65
+ @file_upload_button = file_upload_button
66
+ @file_upload_button ||= "Add #{multiple ? "files" : "file"}"
67
+ @file_upload_help = file_upload_help
68
+ @file_upload_arguments = file_upload_arguments
69
+ @wrapper_arguments = wrapper_arguments
70
+ @input_options = input_options
71
+ @system_arguments = system_arguments
72
+ end
73
+
74
+ def system_arguments
75
+ {
76
+ tag: "div",
77
+ data: {
78
+ polaris_dropzone_accept_value: @accept,
79
+ polaris_dropzone_allow_multiple_value: @multiple.to_s,
80
+ polaris_dropzone_disabled_value: @disabled.to_s,
81
+ polaris_dropzone_disabled_class: "Polaris-DropZone--isDisabled",
82
+ polaris_dropzone_focused_value: "false",
83
+ polaris_dropzone_drop_on_page_value: @drop_on_page,
84
+ polaris_dropzone_render_preview_value: @preview,
85
+ polaris_dropzone_size_value: @size
86
+ }
87
+ }.deep_merge(@system_arguments).tap do |opts|
88
+ prepend_option(opts[:data], :controller, "polaris-dropzone")
89
+ prepend_option(opts[:data], :action, "click->polaris-dropzone#onClick #{drop_actions}")
90
+ opts[:classes] = class_names(
91
+ opts[:classes],
92
+ "Polaris-DropZone",
93
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, SIZE_DEFAULT)],
94
+ "Polaris-DropZone--hasOutline": @outline,
95
+ "Polaris-DropZone--isDisabled": @disabled,
96
+ "Polaris-DropZone--hasError": @error
97
+ )
98
+ end
99
+ end
100
+
101
+ def wrapper_arguments
102
+ {
103
+ form: @form,
104
+ attribute: @attribute,
105
+ name: @name,
106
+ label: @label,
107
+ label_hidden: @label_hidden,
108
+ label_action: @label_action,
109
+ error: @error
110
+ }.deep_merge(@wrapper_arguments)
111
+ end
112
+
113
+ def input_options
114
+ {
115
+ accept: @accept,
116
+ direct_upload: @direct_upload,
117
+ disabled: @disabled,
118
+ multiple: @multiple,
119
+ data: {polaris_dropzone_target: "input"}
120
+ }.deep_merge(@input_options).tap do |opts|
121
+ prepend_option(opts[:data], :action, "focus->polaris-dropzone#onFocus blur->polaris-dropzone#onBlur change->polaris-dropzone#onChange")
122
+ end
123
+ end
124
+
125
+ def file_upload_arguments
126
+ {
127
+ tag: "div",
128
+ classes: class_names(
129
+ "Polaris-DropZone-FileUpload",
130
+ "Polaris-DropZone-FileUpload--large": @size.in?(%i[large extra_large]),
131
+ "Polaris-DropZone-FileUpload--small": @size == :small
132
+ ),
133
+ data: {
134
+ polaris_dropzone_target: "fileUpload"
135
+ }
136
+ }.deep_merge(@file_upload_arguments.except(:language))
137
+ end
138
+
139
+ def drop_actions
140
+ event_scope = @drop_on_page ? "@document" : ""
141
+
142
+ [
143
+ "drop#{event_scope}->polaris-dropzone#onDrop",
144
+ "dragover#{event_scope}->polaris-dropzone#onDragOver",
145
+ "dragenter#{event_scope}->polaris-dropzone#onDragEnter",
146
+ "dragleave#{event_scope}->polaris-dropzone#onDragLeave"
147
+ ].join(" ")
148
+ end
149
+ end
150
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class EmptyStateComponent < Polaris::NewComponent
4
+ class EmptyStateComponent < Polaris::Component
5
5
  WITHIN_DEFAULT = :page
6
6
  WITHIN_MAPPINGS = {
7
7
  WITHIN_DEFAULT => "",
@@ -1,4 +1,4 @@
1
- class Polaris::ExceptionList::ItemComponent < Polaris::NewComponent
1
+ class Polaris::ExceptionList::ItemComponent < Polaris::Component
2
2
  STATUS_DEFAULT = :default
3
3
  STATUS_MAPPINGS = {
4
4
  STATUS_DEFAULT => "",