polaris_view_components 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/polaris/card/section_component.rb +2 -1
- data/app/components/polaris/card_component.html.erb +8 -2
- data/app/components/polaris/card_component.rb +2 -0
- data/app/components/polaris/resource_item_component.html.erb +26 -0
- data/app/components/polaris/resource_item_component.rb +42 -0
- data/app/components/polaris/resource_list_component.rb +32 -0
- data/app/components/polaris/text_field_component.html.erb +4 -4
- data/app/components/polaris/text_field_component.rb +3 -1
- data/app/helpers/polaris/form_builder.rb +39 -7
- data/app/helpers/polaris/view_helper.rb +2 -0
- data/lib/polaris/view_components/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b8966c0866f8b002c720f0dd8578f825a9abf64753ead41dcdf84150dd24f8c
|
4
|
+
data.tar.gz: 9fb7b270e5fbe102a79342462795b472ac4849d412431d5990fc0bf17ab9aef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5078ffd0ee20e1df92e5373ab423fb740ae046596b960322b263ec02a2938a082db91ce92b96639257cc7702de321c561f3c8621caa404bdc0246f0de837e021
|
7
|
+
data.tar.gz: 6568cc0c13ccee2a3a94a2b3308bd546d5fe32c20e1742699999698ef02db79938f717e20fc64ad71867ff1eba8720b4be2d88682ecff459f13221e6ecda107d
|
@@ -6,6 +6,7 @@ class Polaris::Card::SectionComponent < Polaris::NewComponent
|
|
6
6
|
subdued: false,
|
7
7
|
flush: false,
|
8
8
|
full_width: false,
|
9
|
+
unstyled: false,
|
9
10
|
actions: [],
|
10
11
|
**system_arguments
|
11
12
|
)
|
@@ -13,10 +14,10 @@ class Polaris::Card::SectionComponent < Polaris::NewComponent
|
|
13
14
|
@system_arguments[:tag] = :div
|
14
15
|
@system_arguments[:classes] = class_names(
|
15
16
|
@system_arguments[:classes],
|
16
|
-
"Polaris-Card__Section",
|
17
17
|
"Polaris-Card__Section--flush": flush,
|
18
18
|
"Polaris-Card__Section--subdued": subdued,
|
19
19
|
"Polaris-Card__Section--fullWidth": full_width,
|
20
|
+
"Polaris-Card__Section": !unstyled,
|
20
21
|
)
|
21
22
|
|
22
23
|
@title = title
|
@@ -11,8 +11,14 @@
|
|
11
11
|
<% sections.each do |section| %>
|
12
12
|
<%= section %>
|
13
13
|
<% end %>
|
14
|
-
<%
|
15
|
-
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<% if content.present? %>
|
17
|
+
<% if @sectioned %>
|
18
|
+
<%= render Polaris::Card::SectionComponent.new do %>
|
19
|
+
<%= content %>
|
20
|
+
<% end %>
|
21
|
+
<% else %>
|
16
22
|
<%= content %>
|
17
23
|
<% end %>
|
18
24
|
<% end %>
|
@@ -21,12 +21,14 @@ module Polaris
|
|
21
21
|
def initialize(
|
22
22
|
title: "",
|
23
23
|
actions: [],
|
24
|
+
sectioned: true,
|
24
25
|
subdued: false,
|
25
26
|
footer_action_alignment: FOOTER_ACTION_ALIGNMENT_DEFAULT,
|
26
27
|
**system_arguments
|
27
28
|
)
|
28
29
|
@title = title
|
29
30
|
@actions = actions
|
31
|
+
@sectioned = sectioned
|
30
32
|
@footer_action_alignment = footer_action_alignment
|
31
33
|
|
32
34
|
@system_arguments = system_arguments
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<%= render(Polaris::BaseComponent.new(**@system_arguments)) do %>
|
2
|
+
<div class="Polaris-ResourceItem__ItemWrapper">
|
3
|
+
<div class="Polaris-ResourceItem" style="cursor: <%= @cursor %>;">
|
4
|
+
<% if @url %>
|
5
|
+
<a
|
6
|
+
class="Polaris-ResourceItem__Link"
|
7
|
+
tabindex="0"
|
8
|
+
href="<%= @url %>"
|
9
|
+
data-polaris-unstyled="true"></a>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= render(Polaris::BaseComponent.new(**@container_arguments)) do %>
|
13
|
+
<% if media.present? %>
|
14
|
+
<div class="Polaris-ResourceItem__Owned">
|
15
|
+
<div class="Polaris-ResourceItem__Media">
|
16
|
+
<%= media %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
<% end %>
|
20
|
+
<div class="Polaris-ResourceItem__Content">
|
21
|
+
<%= content %>
|
22
|
+
</div>
|
23
|
+
<% end %>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
<% end %>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Polaris
|
4
|
+
class ResourceItemComponent < Polaris::NewComponent
|
5
|
+
CURSOR_DEFAULT = :default
|
6
|
+
CURSOR_OPTIONS = %i[default pointer]
|
7
|
+
|
8
|
+
ALIGNMENT_DEFAULT = :default
|
9
|
+
ALIGNMENT_MAPPINGS = {
|
10
|
+
ALIGNMENT_DEFAULT => "",
|
11
|
+
center: "Polaris-ResourceItem--alignmentCenter",
|
12
|
+
}
|
13
|
+
ALIGNMENT_OPTIONS = ALIGNMENT_MAPPINGS.keys
|
14
|
+
|
15
|
+
renders_one :media
|
16
|
+
|
17
|
+
def initialize(
|
18
|
+
url: nil,
|
19
|
+
cursor: CURSOR_DEFAULT,
|
20
|
+
vertical_alignment: ALIGNMENT_DEFAULT,
|
21
|
+
**system_arguments
|
22
|
+
)
|
23
|
+
@url = url
|
24
|
+
@cursor = fetch_or_fallback(CURSOR_OPTIONS, cursor, CURSOR_DEFAULT)
|
25
|
+
|
26
|
+
@system_arguments = system_arguments
|
27
|
+
@system_arguments[:tag] = "li"
|
28
|
+
@system_arguments[:classes] = class_names(
|
29
|
+
@system_arguments[:classes],
|
30
|
+
"Polaris-ResourceItem__ListItem",
|
31
|
+
)
|
32
|
+
|
33
|
+
@container_arguments = {
|
34
|
+
tag: "div",
|
35
|
+
classes: class_names(
|
36
|
+
"Polaris-ResourceItem__Container",
|
37
|
+
ALIGNMENT_MAPPINGS[fetch_or_fallback(ALIGNMENT_OPTIONS, vertical_alignment, ALIGNMENT_DEFAULT)],
|
38
|
+
)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Polaris
|
4
|
+
class ResourceListComponent < Polaris::NewComponent
|
5
|
+
def initialize(
|
6
|
+
wrapper_arguments: {},
|
7
|
+
**system_arguments
|
8
|
+
)
|
9
|
+
@wrapper_arguments = wrapper_arguments
|
10
|
+
@wrapper_arguments[:tag] = "div"
|
11
|
+
@wrapper_arguments[:classes] = class_names(
|
12
|
+
@wrapper_arguments[:classes],
|
13
|
+
"Polaris-ResourceList__ResourceListWrapper",
|
14
|
+
)
|
15
|
+
|
16
|
+
@system_arguments = system_arguments
|
17
|
+
@system_arguments[:tag] = "ul"
|
18
|
+
@system_arguments[:classes] = class_names(
|
19
|
+
@system_arguments[:classes],
|
20
|
+
"Polaris-ResourceList",
|
21
|
+
)
|
22
|
+
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
|
+
end
|
32
|
+
end
|
@@ -8,9 +8,9 @@
|
|
8
8
|
|
9
9
|
<div class="Polaris-Connected__Item Polaris-Connected__Item--primary">
|
10
10
|
<%= render Polaris::BaseComponent.new(**system_arguments) do %>
|
11
|
-
<% if @prefix.present? %>
|
11
|
+
<% if prefix.present? || @prefix.present? %>
|
12
12
|
<div class="Polaris-TextField__Prefix">
|
13
|
-
<%= @prefix %>
|
13
|
+
<%= prefix || @prefix %>
|
14
14
|
</div>
|
15
15
|
<% end %>
|
16
16
|
|
@@ -20,9 +20,9 @@
|
|
20
20
|
<%= public_send(input_tag, @name, @value, input_options) %>
|
21
21
|
<% end %>
|
22
22
|
|
23
|
-
<% if @suffix.present? %>
|
23
|
+
<% if suffix.present? || @suffix.present? %>
|
24
24
|
<div class="Polaris-TextField__Suffix">
|
25
|
-
<%= @suffix %>
|
25
|
+
<%= suffix || @suffix %>
|
26
26
|
</div>
|
27
27
|
<% end %>
|
28
28
|
|
@@ -19,6 +19,8 @@ module Polaris
|
|
19
19
|
|
20
20
|
attr_reader :value
|
21
21
|
|
22
|
+
renders_one :prefix
|
23
|
+
renders_one :suffix
|
22
24
|
renders_one :connected_left
|
23
25
|
renders_one :connected_right
|
24
26
|
|
@@ -143,7 +145,7 @@ module Polaris
|
|
143
145
|
default_options[:rows] = @rows
|
144
146
|
end
|
145
147
|
|
146
|
-
default_options.deep_merge(@input_options).tap do |opts|
|
148
|
+
default_options.deep_merge(@input_options).compact.tap do |opts|
|
147
149
|
opts[:class] = class_names(
|
148
150
|
opts[:class],
|
149
151
|
"Polaris-TextField__Input",
|
@@ -1,16 +1,48 @@
|
|
1
1
|
module Polaris
|
2
2
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
attr_reader :template
|
4
|
+
|
5
|
+
delegate :render, :pluralize, to: :template
|
6
|
+
|
7
|
+
def errors_summary
|
8
|
+
return if object.blank?
|
9
|
+
return unless object.errors.any?
|
10
|
+
|
11
|
+
model_name = object.class.model_name.human.downcase
|
12
|
+
|
13
|
+
render Polaris::BannerComponent.new(
|
14
|
+
title: "There's #{pluralize(object.errors.count, "error")} with this #{model_name}:",
|
15
|
+
status: :critical,
|
16
|
+
) do
|
17
|
+
render(Polaris::ListComponent.new) do |list|
|
18
|
+
object.errors.each do |error|
|
19
|
+
list.item { error.full_message }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
8
23
|
end
|
9
24
|
|
10
|
-
def
|
25
|
+
def error_for(method)
|
11
26
|
return if object.blank?
|
12
27
|
return unless object.errors.key?(method)
|
13
|
-
|
28
|
+
|
29
|
+
object.errors.full_messages_for(method)&.first
|
30
|
+
end
|
31
|
+
|
32
|
+
def polaris_text_field(method, **options, &block)
|
33
|
+
options[:error] ||= error_for(method)
|
34
|
+
if options[:error_hidden] && options[:error]
|
35
|
+
options[:error] = !!options[:error]
|
36
|
+
end
|
37
|
+
render Polaris::TextFieldComponent.new(form: self, attribute: method, **options, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def polaris_select(method, **options, &block)
|
41
|
+
options[:error] ||= error_for(method)
|
42
|
+
if options[:error_hidden] && options[:error]
|
43
|
+
options[:error] = !!options[:error]
|
44
|
+
end
|
45
|
+
render Polaris::SelectComponent.new(form: self, attribute: method, **options, &block)
|
14
46
|
end
|
15
47
|
end
|
16
48
|
end
|
@@ -30,6 +30,8 @@ module Polaris
|
|
30
30
|
pagination: "Polaris::PaginationComponent",
|
31
31
|
progress_bar: "Polaris::ProgressBarComponent",
|
32
32
|
radio_button: "Polaris::RadioButtonComponent",
|
33
|
+
resource_list: "Polaris::ResourceListComponent",
|
34
|
+
resource_item: "Polaris::ResourceItemComponent",
|
33
35
|
select: "Polaris::SelectComponent",
|
34
36
|
shopify_navigation: "Polaris::ShopifyNavigationComponent",
|
35
37
|
stack: "Polaris::StackComponent",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polaris_view_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gamble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-08-
|
12
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -530,6 +530,9 @@ files:
|
|
530
530
|
- app/components/polaris/progress_bar_component.rb
|
531
531
|
- app/components/polaris/radio_button_component.html.erb
|
532
532
|
- app/components/polaris/radio_button_component.rb
|
533
|
+
- app/components/polaris/resource_item_component.html.erb
|
534
|
+
- app/components/polaris/resource_item_component.rb
|
535
|
+
- app/components/polaris/resource_list_component.rb
|
533
536
|
- app/components/polaris/select_component.html.erb
|
534
537
|
- app/components/polaris/select_component.rb
|
535
538
|
- app/components/polaris/shopify_navigation_component.html.erb
|