polaris_view_components 0.3.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/polaris_view_components/button_controller.js +48 -0
  4. data/app/assets/javascripts/polaris_view_components/index.js +11 -1
  5. data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
  6. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +24 -0
  7. data/app/assets/javascripts/polaris_view_components/popover_controller.js +45 -0
  8. data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
  9. data/app/assets/javascripts/polaris_view_components/select_controller.js +6 -4
  10. data/app/assets/javascripts/polaris_view_components.js +1539 -5
  11. data/app/assets/stylesheets/polaris_view_components/custom.css +68 -0
  12. data/app/assets/stylesheets/polaris_view_components/shopify_navigation.css +0 -4
  13. data/app/assets/stylesheets/polaris_view_components/spacer_component.css +39 -0
  14. data/app/assets/stylesheets/polaris_view_components.css +93 -3
  15. data/app/assets/stylesheets/polaris_view_components.postcss.css +2 -0
  16. data/app/components/polaris/action.rb +3 -3
  17. data/app/components/polaris/action_list/item_component.html.erb +35 -0
  18. data/app/components/polaris/action_list/item_component.rb +41 -0
  19. data/app/components/polaris/action_list/section_component.html.erb +16 -0
  20. data/app/components/polaris/action_list/section_component.rb +26 -0
  21. data/app/components/polaris/action_list_component.html.erb +13 -0
  22. data/app/components/polaris/action_list_component.rb +25 -0
  23. data/app/components/polaris/application_component.rb +19 -19
  24. data/app/components/polaris/avatar_component.rb +1 -1
  25. data/app/components/polaris/badge_component.rb +1 -1
  26. data/app/components/polaris/banner_component.rb +6 -6
  27. data/app/components/polaris/base_button.rb +1 -1
  28. data/app/components/polaris/button_component.html.erb +13 -0
  29. data/app/components/polaris/button_group_component.rb +5 -5
  30. data/app/components/polaris/callout_card_component.rb +5 -5
  31. data/app/components/polaris/caption_component.rb +2 -2
  32. data/app/components/polaris/card/header_component.rb +1 -3
  33. data/app/components/polaris/card/section_component.rb +6 -2
  34. data/app/components/polaris/card_component.html.erb +4 -0
  35. data/app/components/polaris/card_component.rb +5 -6
  36. data/app/components/polaris/character_count.rb +10 -10
  37. data/app/components/polaris/checkbox_component.rb +4 -4
  38. data/app/components/polaris/choice_component.rb +1 -1
  39. data/app/components/polaris/choice_list_component.rb +4 -4
  40. data/app/components/polaris/data_table/cell_component.html.erb +18 -0
  41. data/app/components/polaris/data_table/cell_component.rb +49 -0
  42. data/app/components/polaris/data_table/column_component.rb +19 -0
  43. data/app/components/polaris/data_table_component.html.erb +77 -0
  44. data/app/components/polaris/data_table_component.rb +42 -0
  45. data/app/components/polaris/description_list_component.rb +3 -3
  46. data/app/components/polaris/display_text_component.rb +2 -2
  47. data/app/components/polaris/dropzone/component.rb +36 -38
  48. data/app/components/polaris/empty_state_component.html.erb +16 -11
  49. data/app/components/polaris/empty_state_component.rb +4 -3
  50. data/app/components/polaris/exception_list/item_component.rb +2 -2
  51. data/app/components/polaris/exception_list_component.rb +1 -1
  52. data/app/components/polaris/filters_component.html.erb +13 -0
  53. data/app/components/polaris/filters_component.rb +38 -0
  54. data/app/components/polaris/footer_help_component.rb +1 -1
  55. data/app/components/polaris/form_layout/group_component.rb +3 -3
  56. data/app/components/polaris/form_layout/item_component.rb +1 -1
  57. data/app/components/polaris/form_layout_component.rb +3 -3
  58. data/app/components/polaris/heading_component.rb +1 -1
  59. data/app/components/polaris/headless_button.html.erb +13 -0
  60. data/app/components/polaris/headless_button.rb +17 -5
  61. data/app/components/polaris/icon_component.rb +2 -2
  62. data/app/components/polaris/index_table/cell_component.rb +22 -0
  63. data/app/components/polaris/index_table/column_component.rb +13 -0
  64. data/app/components/polaris/index_table_component.html.erb +28 -0
  65. data/app/components/polaris/index_table_component.rb +25 -0
  66. data/app/components/polaris/inline_error_component.html.erb +2 -2
  67. data/app/components/polaris/inline_error_component.rb +7 -1
  68. data/app/components/polaris/label_component.rb +2 -2
  69. data/app/components/polaris/labelled_component.rb +2 -2
  70. data/app/components/polaris/layout/annotated_section.rb +1 -1
  71. data/app/components/polaris/layout/section.rb +2 -0
  72. data/app/components/polaris/layout_component.rb +3 -3
  73. data/app/components/polaris/link_component.rb +5 -3
  74. data/app/components/polaris/list_component.rb +3 -3
  75. data/app/components/polaris/modal/section_component.rb +19 -0
  76. data/app/components/polaris/modal_component.html.erb +79 -0
  77. data/app/components/polaris/modal_component.rb +98 -0
  78. data/app/components/polaris/page_actions_component.rb +21 -6
  79. data/app/components/polaris/page_component.rb +4 -4
  80. data/app/components/polaris/pagination_component.rb +1 -5
  81. data/app/components/polaris/popover/pane_component.html.erb +25 -0
  82. data/app/components/polaris/popover/pane_component.rb +20 -0
  83. data/app/components/polaris/popover/section_component.rb +19 -0
  84. data/app/components/polaris/popover_component.html.erb +38 -0
  85. data/app/components/polaris/popover_component.rb +90 -0
  86. data/app/components/polaris/progress_bar_component.rb +5 -5
  87. data/app/components/polaris/radio_button_component.rb +3 -3
  88. data/app/components/polaris/resource_item_component.html.erb +16 -6
  89. data/app/components/polaris/resource_item_component.rb +42 -9
  90. data/app/components/polaris/resource_list_component.html.erb +10 -0
  91. data/app/components/polaris/resource_list_component.rb +4 -10
  92. data/app/components/polaris/scrollable_component.html.erb +5 -0
  93. data/app/components/polaris/scrollable_component.rb +48 -0
  94. data/app/components/polaris/select_component.rb +10 -5
  95. data/app/components/polaris/setting_toggle_component.html.erb +10 -0
  96. data/app/components/polaris/setting_toggle_component.rb +24 -0
  97. data/app/components/polaris/shopify_navigation_component.rb +6 -6
  98. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  99. data/app/components/polaris/spacer_component.rb +50 -0
  100. data/app/components/polaris/spinner_component.rb +2 -2
  101. data/app/components/polaris/stack_component.rb +5 -5
  102. data/app/components/polaris/subheading_component.rb +1 -1
  103. data/app/components/polaris/tabs/tab_component.html.erb +10 -0
  104. data/app/components/polaris/tabs/tab_component.rb +34 -0
  105. data/app/components/polaris/tabs_component.html.erb +7 -0
  106. data/app/components/polaris/tabs_component.rb +37 -0
  107. data/app/components/polaris/tag_component.rb +2 -2
  108. data/app/components/polaris/text_container_component.rb +2 -2
  109. data/app/components/polaris/text_field_component.rb +8 -8
  110. data/app/components/polaris/text_style_component.rb +11 -2
  111. data/app/components/polaris/thumbnail_component.rb +2 -2
  112. data/app/helpers/polaris/form_builder.rb +30 -3
  113. data/app/helpers/polaris/url_helper.rb +3 -3
  114. data/app/helpers/polaris/view_helper.rb +26 -6
  115. data/app/validators/type_validator.rb +2 -2
  116. data/lib/generators/polaris_view_components/install_generator.rb +5 -5
  117. data/lib/polaris/view_components/engine.rb +6 -1
  118. data/lib/polaris/view_components/version.rb +1 -1
  119. data/lib/polaris_view_components.rb +1 -1
  120. metadata +45 -6
  121. data/app/components/polaris/choice_list/component.html.erb +0 -34
  122. data/app/components/polaris/choice_list/component.rb +0 -65
  123. data/app/helpers/polaris/action_helper.rb +0 -14
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class ModalComponent < Polaris::NewComponent
5
+ renders_one :close_button, ->(**system_arguments) do
6
+ button_arguments = @close_button_arguments.deep_merge(system_arguments)
7
+ render(Polaris::BaseComponent.new(**button_arguments)) do
8
+ polaris_icon(name: "MobileCancelMajor", color: :base)
9
+ end
10
+ end
11
+ renders_many :sections, Polaris::Modal::SectionComponent
12
+ renders_one :primary_action, ->(primary: true, **system_arguments) do
13
+ Polaris::ButtonComponent.new(primary: primary, **system_arguments)
14
+ end
15
+ renders_many :secondary_actions, Polaris::ButtonComponent
16
+
17
+ def initialize(
18
+ title:,
19
+ open: false,
20
+ sectioned: true,
21
+ scrollable: true,
22
+ large: false,
23
+ small: false,
24
+ limit_height: false,
25
+ dialog_arguments: {},
26
+ **system_arguments
27
+ )
28
+ @title = title
29
+ @open = open
30
+ @sectioned = sectioned
31
+ @scrollable = scrollable
32
+ @large = large
33
+ @small = small
34
+ @limit_height = limit_height
35
+ @dialog_arguments = dialog_arguments
36
+ @system_arguments = system_arguments
37
+ @close_button_arguments = {
38
+ tag: "button",
39
+ type: "button",
40
+ classes: "Polaris-Modal-CloseButton",
41
+ aria: {label: "Close"}
42
+ }
43
+ end
44
+
45
+ def system_arguments
46
+ @system_arguments.tap do |opts|
47
+ opts[:tag] = "div"
48
+ opts[:data] ||= {}
49
+ prepend_option(opts[:data], :controller, "polaris-modal")
50
+ opts[:data][:polaris_modal_open_value] = @open
51
+ opts[:data][:polaris_modal_hidden_class] = "Polaris--hidden"
52
+ opts[:data][:polaris_modal_backdrop_class] = "Polaris-Backdrop"
53
+ opts[:classes] = class_names(
54
+ @system_arguments[:classes],
55
+ "Polaris-Modal-Dialog__Container",
56
+ "Polaris--hidden"
57
+ )
58
+ end
59
+ end
60
+
61
+ def dialog_arguments
62
+ @dialog_arguments.tap do |opts|
63
+ opts[:tag] = "div"
64
+ opts[:role] = "dialog"
65
+ opts[:aria] ||= {}
66
+ opts[:aria][:modal] = "true"
67
+ opts[:tabindex] = "-1"
68
+ opts[:classes] = class_names(
69
+ @dialog_arguments[:classes],
70
+ "Polaris-Modal-Dialog"
71
+ )
72
+ end
73
+ end
74
+
75
+ def close_button_arguments
76
+ @close_button_arguments.deep_merge({
77
+ data: {action: "polaris-modal#close"}
78
+ })
79
+ end
80
+
81
+ def modal_classes
82
+ class_names(
83
+ "Polaris-Modal-Dialog__Modal",
84
+ "Polaris-Modal-Dialog--sizeLarge": @large,
85
+ "Polaris-Modal-Dialog--sizeSmall": @small,
86
+ "Polaris-Modal-Dialog--limitHeight": @limit_height
87
+ )
88
+ end
89
+
90
+ def header_classes
91
+ @title.present? ? "Polaris-Modal-Header" : "Polaris-Modal-Header--titleHidden"
92
+ end
93
+
94
+ def render_footer?
95
+ primary_action.present? || secondary_actions.any?
96
+ end
97
+ end
98
+ 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
@@ -0,0 +1,19 @@
1
+ class Polaris::Popover::SectionComponent < 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] = "div"
9
+ opts[:classes] = class_names(
10
+ @system_arguments[:classes],
11
+ "Polaris-Popover__Section"
12
+ )
13
+ end
14
+ end
15
+
16
+ def call
17
+ render(Polaris::BaseComponent.new(**system_arguments)) { content }
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ <div
2
+ data-controller="polaris-popover"
3
+ data-polaris-popover-active-value="<%= @active %>"
4
+ data-polaris-popover-placement-value="<%= popperjs_placement %>"
5
+ data-polaris-popover-open-class="Polaris-Popover__PopoverOverlay--open"
6
+ data-polaris-popover-closed-class="Polaris-Popover__PopoverOverlay--closed"
7
+ style="<%= "display: inline-block;" if @inline %>"
8
+ >
9
+ <div data-polaris-popover-target="activator">
10
+ <% if activator.present? %>
11
+ <%= activator %>
12
+ <% elsif button.present? %>
13
+ <%= button %>
14
+ <% end %>
15
+ </div>
16
+
17
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
18
+ <%= render Polaris::BaseComponent.new(**popover_arguments) do %>
19
+ <div class="Polaris-Popover__FocusTracker" tabindex="0"></div>
20
+ <div style="">
21
+ <div class="Polaris-Popover__Wrapper">
22
+ <%= render Polaris::BaseComponent.new(**content_arguments) do %>
23
+ <% if panes.present? %>
24
+ <% panes.each do |pane| %>
25
+ <%= pane %>
26
+ <% end %>
27
+ <% else %>
28
+ <%= render Polaris::Popover::PaneComponent.new(sectioned: @sectioned) do %>
29
+ <%= content %>
30
+ <% end %>
31
+ <% end %>
32
+ <% end %>
33
+ </div>
34
+ </div>
35
+ <div class="Polaris-Popover__FocusTracker" tabindex="0"></div>
36
+ <% end %>
37
+ <% end %>
38
+ </div>
@@ -0,0 +1,90 @@
1
+ module Polaris
2
+ class PopoverComponent < Polaris::NewComponent
3
+ ALIGNMENT_DEFAULT = :center
4
+ ALIGNMENT_OPTIONS = [:left, :right, :center]
5
+
6
+ POSITION_DEFAULT = :below
7
+ POSITION_OPTIONS = [:above, :below]
8
+
9
+ renders_one :button, ->(**system_arguments) do
10
+ system_arguments[:data] ||= {}
11
+ prepend_option(system_arguments[:data], :action, "polaris-popover#toggle click@window->polaris-popover#hide")
12
+ Polaris::ButtonComponent.new(**system_arguments)
13
+ end
14
+ renders_one :activator
15
+ renders_many :panes, Polaris::Popover::PaneComponent
16
+
17
+ def initialize(
18
+ active: false,
19
+ inline: true,
20
+ fixed: false,
21
+ fluid_content: false,
22
+ full_height: false,
23
+ full_width: false,
24
+ sectioned: false,
25
+ alignment: ALIGNMENT_DEFAULT,
26
+ position: POSITION_DEFAULT,
27
+ **system_arguments
28
+ )
29
+ @active = active
30
+ @inline = inline
31
+ @fixed = fixed
32
+ @fluid_content = fluid_content
33
+ @full_height = full_height
34
+ @full_width = full_width
35
+ @sectioned = sectioned
36
+ @alignment = fetch_or_fallback(ALIGNMENT_OPTIONS, alignment, ALIGNMENT_DEFAULT)
37
+ @position = fetch_or_fallback(POSITION_OPTIONS, position, POSITION_DEFAULT)
38
+ @system_arguments = system_arguments
39
+ @popover_arguments = {}
40
+ @content_arguments = {}
41
+ end
42
+
43
+ def system_arguments
44
+ @system_arguments.tap do |opts|
45
+ opts[:tag] = "div"
46
+ opts[:data] ||= {}
47
+ opts[:data]["polaris_popover_target"] = "popover"
48
+ opts[:classes] = class_names(
49
+ @system_arguments[:classes],
50
+ "Polaris-PositionedOverlay",
51
+ "Polaris-Popover__PopoverOverlay",
52
+ "Polaris-Popover__PopoverOverlay--closed",
53
+ "Polaris-Popover__PopoverOverlay--fixed": @fixed
54
+ )
55
+ end
56
+ end
57
+
58
+ def popover_arguments
59
+ @popover_arguments.tap do |opts|
60
+ opts[:tag] = "div"
61
+ opts[:classes] = class_names(
62
+ @content_arguments[:classes],
63
+ "Polaris-Popover",
64
+ "Polaris-Popover--fullWidth": @full_width,
65
+ "Polaris-Popover--positionedAbove": @position == :above
66
+ )
67
+ end
68
+ end
69
+
70
+ def content_arguments
71
+ @content_arguments.tap do |opts|
72
+ opts[:tag] = "div"
73
+ opts[:tabindex] ||= "-1"
74
+ opts[:classes] = class_names(
75
+ @content_arguments[:classes],
76
+ "Polaris-Popover__Content",
77
+ "Polaris-Popover__Content--fluidContent": @fluid_content,
78
+ "Polaris-Popover__Content--fullHeight": @full_height
79
+ )
80
+ end
81
+ end
82
+
83
+ def popperjs_placement
84
+ placement = @position == :above ? "top" : "bottom"
85
+ placement += "-start" if @alignment == :left
86
+ placement += "-end" if @alignment == :right
87
+ placement
88
+ end
89
+ end
90
+ end
@@ -5,16 +5,16 @@ module Polaris
5
5
  COLOR_DEFAULT = :highlight
6
6
  COLOR_MAPPINGS = {
7
7
  COLOR_DEFAULT => "Polaris-ProgressBar--colorHighlight",
8
- primary: "Polaris-ProgressBar--colorPrimary",
9
- success: "Polaris-ProgressBar--colorSuccess",
8
+ :primary => "Polaris-ProgressBar--colorPrimary",
9
+ :success => "Polaris-ProgressBar--colorSuccess"
10
10
  }
11
11
  COLOR_OPTIONS = COLOR_MAPPINGS.keys
12
12
 
13
13
  SIZE_DEFAULT = :medium
14
14
  SIZE_MAPPINGS = {
15
15
  SIZE_DEFAULT => "Polaris-ProgressBar--sizeMedium",
16
- small: "Polaris-ProgressBar--sizeSmall",
17
- large: "Polaris-ProgressBar--sizeLarge",
16
+ :small => "Polaris-ProgressBar--sizeSmall",
17
+ :large => "Polaris-ProgressBar--sizeLarge"
18
18
  }
19
19
  SIZE_OPTIONS = SIZE_MAPPINGS.keys
20
20
 
@@ -31,7 +31,7 @@ module Polaris
31
31
  @system_arguments[:classes],
32
32
  "Polaris-ProgressBar",
33
33
  COLOR_MAPPINGS[fetch_or_fallback(COLOR_OPTIONS, color, COLOR_DEFAULT)],
34
- SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
34
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
35
35
  )
36
36
 
37
37
  @animated = animated
@@ -27,14 +27,14 @@ module Polaris
27
27
  @system_arguments[:classes] = class_names(
28
28
  @system_arguments[:classes],
29
29
  "Polaris-RadioButton",
30
- "Polaris-RadioButton--labelHidden": label_hidden,
30
+ "Polaris-RadioButton--labelHidden": label_hidden
31
31
  )
32
32
 
33
33
  @wrapper_arguments = {
34
34
  label: label,
35
35
  label_hidden: label_hidden,
36
36
  help_text: help_text,
37
- disabled: disabled,
37
+ disabled: disabled
38
38
  }.merge(wrapper_arguments)
39
39
 
40
40
  @input_options = input_options
@@ -43,7 +43,7 @@ module Polaris
43
43
  @input_options[:aria][:checked] = checked
44
44
  @input_options[:class] = class_names(
45
45
  @input_options[:classes],
46
- "Polaris-RadioButton__Input",
46
+ "Polaris-RadioButton__Input"
47
47
  )
48
48
  end
49
49
 
@@ -11,12 +11,22 @@
11
11
  <% end %>
12
12
 
13
13
  <%= render(Polaris::BaseComponent.new(**container_arguments)) do %>
14
- <% if media.present? %>
15
- <div class="Polaris-ResourceItem__Owned">
16
- <div class="Polaris-ResourceItem__Media">
17
- <%= media %>
18
- </div>
19
- </div>
14
+ <% if owned? %>
15
+ <%= render(Polaris::BaseComponent.new(**owned_arguments)) do %>
16
+ <% if checkbox.present? || radio_button.present? %>
17
+ <div class="Polaris-ResourceItem__Handle">
18
+ <div class="Polaris-ResourceItem__CheckboxWrapper">
19
+ <%= checkbox.presence || radio_button %>
20
+ </div>
21
+ </div>
22
+ <% end %>
23
+
24
+ <% if media.present? %>
25
+ <div class="Polaris-ResourceItem__Media">
26
+ <%= media %>
27
+ </div>
28
+ <% end %>
29
+ <% end %>
20
30
  <% end %>
21
31
  <div class="Polaris-ResourceItem__Content">
22
32
  <%= content %>
@@ -8,21 +8,37 @@ module Polaris
8
8
  ALIGNMENT_DEFAULT = :default
9
9
  ALIGNMENT_MAPPINGS = {
10
10
  ALIGNMENT_DEFAULT => "",
11
- center: "Polaris-ResourceItem--alignmentCenter",
11
+ :center => "Polaris-ResourceItem--alignmentCenter"
12
12
  }
13
13
  ALIGNMENT_OPTIONS = ALIGNMENT_MAPPINGS.keys
14
14
 
15
+ renders_one :checkbox, ->(**system_arguments) do
16
+ Polaris::CheckboxComponent.new(
17
+ label_hidden: true,
18
+ **system_arguments
19
+ )
20
+ end
21
+ renders_one :radio_button, ->(**system_arguments) do
22
+ Polaris::RadioButtonComponent.new(
23
+ label_hidden: true,
24
+ **system_arguments
25
+ )
26
+ end
15
27
  renders_one :media
16
28
 
17
29
  def initialize(
18
30
  url: nil,
19
31
  vertical_alignment: ALIGNMENT_DEFAULT,
32
+ selectable: false,
33
+ offset: false,
20
34
  wrapper_arguments: {},
21
35
  container_arguments: {},
22
36
  **system_arguments
23
37
  )
24
38
  @url = url
25
39
  @vertical_alignment = vertical_alignment
40
+ @selectable = selectable
41
+ @offset = offset
26
42
  @wrapper_arguments = wrapper_arguments
27
43
  @container_arguments = container_arguments
28
44
  @system_arguments = system_arguments
@@ -31,11 +47,11 @@ module Polaris
31
47
  def wrapper_arguments
32
48
  {
33
49
  tag: "li",
34
- data: {},
50
+ data: {}
35
51
  }.deep_merge(@wrapper_arguments).tap do |args|
36
52
  args[:classes] = class_names(
37
53
  args[:classes],
38
- "Polaris-ResourceItem__ListItem",
54
+ "Polaris-ResourceItem__ListItem"
39
55
  )
40
56
  prepend_option(args[:data], :controller, "polaris-resource-item")
41
57
  end
@@ -43,12 +59,12 @@ module Polaris
43
59
 
44
60
  def container_arguments
45
61
  {
46
- tag: "div",
62
+ tag: "div"
47
63
  }.deep_merge(@container_arguments).tap do |args|
48
64
  args[:classes] = class_names(
49
65
  args[:classes],
50
66
  "Polaris-ResourceItem__Container",
51
- ALIGNMENT_MAPPINGS[fetch_or_fallback(ALIGNMENT_OPTIONS, @vertical_alignment, ALIGNMENT_DEFAULT)],
67
+ ALIGNMENT_MAPPINGS[fetch_or_fallback(ALIGNMENT_OPTIONS, @vertical_alignment, ALIGNMENT_DEFAULT)]
52
68
  )
53
69
  end
54
70
  end
@@ -56,20 +72,37 @@ module Polaris
56
72
  def system_arguments
57
73
  {
58
74
  tag: "div",
59
- data: {},
75
+ data: {}
60
76
  }.deep_merge(@system_arguments).tap do |args|
61
77
  args[:classes] = class_names(
62
78
  args[:classes],
63
79
  "Polaris-ResourceItem",
80
+ "Polaris-ResourceItem--selectable": @selectable
64
81
  )
65
82
  prepend_option(args, :style, "cursor: #{cursor};")
66
83
  prepend_option(args[:data], :action, "click->polaris-resource-item#open")
67
84
  end
68
85
  end
69
86
 
87
+ def owned?
88
+ checkbox.present? || radio_button.present? || media.present?
89
+ end
90
+
91
+ def owned_arguments
92
+ {
93
+ tag: "div",
94
+ classes: class_names(
95
+ "Polaris-ResourceItem__Owned",
96
+ "Polaris-ResourceItem__OwnedNoMedia": media.blank?,
97
+ "Polaris-ResourceItem__Owned--offset": @offset
98
+ )
99
+ }
100
+ end
101
+
70
102
  private
71
- def cursor
72
- @url.present? ? "pointer" : "default"
73
- end
103
+
104
+ def cursor
105
+ @url.present? ? "pointer" : "default"
106
+ end
74
107
  end
75
108
  end
@@ -0,0 +1,10 @@
1
+ <%= render(Polaris::BaseComponent.new(**@wrapper_arguments)) do %>
2
+ <% if filters.present? %>
3
+ <div class="Polaris-ResourceList__FiltersWrapper">
4
+ <%= filters %>
5
+ </div>
6
+ <% end %>
7
+ <%= render(Polaris::BaseComponent.new(**@system_arguments)) do %>
8
+ <%= content %>
9
+ <% end %>
10
+ <% end %>
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Polaris
4
4
  class ResourceListComponent < Polaris::NewComponent
5
+ renders_one :filters, Polaris::FiltersComponent
6
+
5
7
  def initialize(
6
8
  wrapper_arguments: {},
7
9
  **system_arguments
@@ -10,23 +12,15 @@ module Polaris
10
12
  @wrapper_arguments[:tag] = "div"
11
13
  @wrapper_arguments[:classes] = class_names(
12
14
  @wrapper_arguments[:classes],
13
- "Polaris-ResourceList__ResourceListWrapper",
15
+ "Polaris-ResourceList__ResourceListWrapper"
14
16
  )
15
17
 
16
18
  @system_arguments = system_arguments
17
19
  @system_arguments[:tag] = "ul"
18
20
  @system_arguments[:classes] = class_names(
19
21
  @system_arguments[:classes],
20
- "Polaris-ResourceList",
22
+ "Polaris-ResourceList"
21
23
  )
22
24
  end
23
-
24
- def call
25
- render(Polaris::BaseComponent.new(**@wrapper_arguments)) do
26
- render(Polaris::BaseComponent.new(**@system_arguments)) do
27
- content
28
- end
29
- end
30
- end
31
25
  end
32
26
  end
@@ -0,0 +1,5 @@
1
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
2
+ <span data-polaris-scrollable-target="topEdge"></span>
3
+ <%= content %>
4
+ <span data-polaris-scrollable-target="bottomEdge"></span>
5
+ <% end %>