polaris_view_components 0.10.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -62
  3. data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +9 -3
  4. data/app/assets/javascripts/polaris_view_components/dropzone_controller.js +18 -8
  5. data/app/assets/javascripts/polaris_view_components/popover_controller.js +39 -13
  6. data/app/assets/javascripts/polaris_view_components.js +112 -59
  7. data/app/assets/stylesheets/polaris_view_components/custom.css +27 -8
  8. data/app/assets/stylesheets/polaris_view_components.css +21 -9
  9. data/app/components/polaris/autocomplete_component.html.erb +3 -0
  10. data/app/components/polaris/autocomplete_component.rb +3 -0
  11. data/app/components/polaris/button_component.html.erb +2 -0
  12. data/app/components/polaris/card/header_component.html.erb +4 -2
  13. data/app/components/polaris/data_table/column_component.rb +2 -1
  14. data/app/components/polaris/data_table_component.html.erb +6 -2
  15. data/app/components/polaris/data_table_component.rb +10 -0
  16. data/app/components/polaris/dropzone_component.html.erb +38 -32
  17. data/app/components/polaris/dropzone_component.rb +4 -1
  18. data/app/components/polaris/empty_search_results_component.html.erb +15 -0
  19. data/app/components/polaris/empty_search_results_component.rb +21 -0
  20. data/app/components/polaris/headless_button.html.erb +2 -0
  21. data/app/components/polaris/headless_button.rb +1 -1
  22. data/app/components/polaris/index_table/column_component.rb +2 -1
  23. data/app/components/polaris/index_table_component.html.erb +3 -5
  24. data/app/components/polaris/index_table_component.rb +10 -0
  25. data/app/components/polaris/page_component.html.erb +4 -4
  26. data/app/components/polaris/page_component.rb +7 -2
  27. data/app/components/polaris/popover_component.html.erb +26 -16
  28. data/app/components/polaris/popover_component.rb +6 -1
  29. data/app/components/polaris/resource_item/shortcut_actions_component.html.erb +21 -0
  30. data/app/components/polaris/resource_item/shortcut_actions_component.rb +88 -0
  31. data/app/components/polaris/resource_item_component.html.erb +3 -0
  32. data/app/components/polaris/resource_item_component.rb +11 -1
  33. data/app/components/polaris/resource_list_component.html.erb +11 -0
  34. data/app/components/polaris/resource_list_component.rb +21 -0
  35. data/app/components/polaris/skeleton_page_component.html.erb +23 -0
  36. data/app/components/polaris/skeleton_page_component.rb +22 -0
  37. data/app/helpers/polaris/url_helper.rb +37 -0
  38. data/app/helpers/polaris/view_helper.rb +2 -0
  39. data/lib/install/install.rb +57 -0
  40. data/lib/polaris/view_components/version.rb +1 -1
  41. data/lib/tasks/polaris_view_components_tasks.rake +6 -0
  42. metadata +10 -6
  43. data/lib/generators/polaris_view_components/USAGE +0 -5
  44. data/lib/generators/polaris_view_components/install_generator.rb +0 -35
  45. data/lib/generators/polaris_view_components/templates/README +0 -14
  46. data/lib/generators/polaris_view_components/templates/stimulus_index.js +0 -6
@@ -0,0 +1,88 @@
1
+ class Polaris::ResourceItem::ShortcutActionsComponent < Polaris::Component
2
+ renders_many :buttons, ->(**system_arguments) do
3
+ ShortcutActionsButtonComponent.new(
4
+ persist_actions: @persist_actions,
5
+ **system_arguments
6
+ )
7
+ end
8
+
9
+ def initialize(
10
+ persist_actions: false,
11
+ wrapper_arguments: {},
12
+ disclosure_arguments: {},
13
+ popover_arguments: {},
14
+ **system_arguments
15
+ )
16
+ @persist_actions = persist_actions
17
+ @wrapper_arguments = wrapper_arguments
18
+ @disclosure_arguments = disclosure_arguments
19
+ @popover_arguments = popover_arguments
20
+ @system_arguments = system_arguments
21
+ end
22
+
23
+ def wrapper_arguments
24
+ @wrapper_arguments.tap do |opts|
25
+ opts[:tag] = "div"
26
+ opts[:classes] = class_names(
27
+ @wrapper_arguments[:classes],
28
+ "Polaris-ResourceItem__Actions"
29
+ )
30
+ end
31
+ end
32
+
33
+ def disclosure_arguments
34
+ @disclosure_arguments.tap do |opts|
35
+ opts[:tag] = "div"
36
+ opts[:classes] = class_names(
37
+ @disclosure_arguments[:classes],
38
+ "Polaris-ResourceItem__Disclosure"
39
+ )
40
+ end
41
+ end
42
+
43
+ def popover_arguments
44
+ {
45
+ alignment: :right,
46
+ position: :below,
47
+ append_to_body: true
48
+ }.deep_merge(@popover_arguments)
49
+ end
50
+
51
+ def system_arguments
52
+ @system_arguments.tap do |opts|
53
+ opts[:segmented] = !@persist_actions
54
+ end
55
+ end
56
+
57
+ class ShortcutActionsButtonComponent < Polaris::Component
58
+ attr_reader :content
59
+
60
+ def initialize(
61
+ url:,
62
+ content:,
63
+ persist_actions:,
64
+ action_list_item_arguments: {},
65
+ **system_arguments
66
+ )
67
+ @url = url
68
+ @content = content
69
+ @persist_actions = persist_actions
70
+ @action_list_item_arguments = action_list_item_arguments
71
+ @system_arguments = system_arguments
72
+ end
73
+
74
+ def system_arguments
75
+ @system_arguments.tap do |opts|
76
+ opts[:url] = @url
77
+ opts[:size] = :slim unless @persist_actions
78
+ opts[:plain] = true if @persist_actions
79
+ end
80
+ end
81
+
82
+ def action_list_item_arguments
83
+ @action_list_item_arguments.tap do |opts|
84
+ opts[:url] = @url
85
+ end
86
+ end
87
+ end
88
+ end
@@ -31,6 +31,9 @@
31
31
  <div class="Polaris-ResourceItem__Content">
32
32
  <%= content %>
33
33
  </div>
34
+ <% if shortcut_actions.present? %>
35
+ <%= shortcut_actions %>
36
+ <% end %>
34
37
  <% end %>
35
38
  <% end %>
36
39
  </div>
@@ -26,12 +26,20 @@ module Polaris
26
26
  end
27
27
  renders_one :media
28
28
 
29
+ renders_one :shortcut_actions, ->(**system_arguments) do
30
+ Polaris::ResourceItem::ShortcutActionsComponent.new(
31
+ persist_actions: @persist_actions,
32
+ **system_arguments
33
+ )
34
+ end
35
+
29
36
  def initialize(
30
37
  url: nil,
31
38
  vertical_alignment: ALIGNMENT_DEFAULT,
32
39
  cursor: CURSOR_DEFAULT,
33
40
  selectable: false,
34
41
  selected: false,
42
+ persist_actions: false,
35
43
  offset: false,
36
44
  wrapper_arguments: {},
37
45
  container_arguments: {},
@@ -42,6 +50,7 @@ module Polaris
42
50
  @cursor = fetch_or_fallback(CURSOR_OPTIONS, cursor, CURSOR_DEFAULT)
43
51
  @selectable = selectable
44
52
  @selected = selected
53
+ @persist_actions = persist_actions
45
54
  @offset = offset
46
55
  @wrapper_arguments = wrapper_arguments
47
56
  @container_arguments = container_arguments
@@ -82,7 +91,8 @@ module Polaris
82
91
  args[:classes],
83
92
  "Polaris-ResourceItem",
84
93
  "Polaris-ResourceItem--selectable": @selectable,
85
- "Polaris-ResourceItem--selected": @selected
94
+ "Polaris-ResourceItem--selected": @selected,
95
+ "Polaris-ResourceItem--persistActions": @persist_actions
86
96
  )
87
97
  prepend_option(args, :style, "cursor: #{@cursor};")
88
98
  prepend_option(args[:data], :action, "click->polaris-resource-item#open")
@@ -4,6 +4,17 @@
4
4
  <%= filters %>
5
5
  </div>
6
6
  <% end %>
7
+
8
+ <% if header_title.present? %>
9
+ <div class="Polaris-ResourceList__HeaderOuterWrapper">
10
+ <div class="Polaris-ResourceList__HeaderWrapper">
11
+ <div class="Polaris-ResourceList__HeaderContentWrapper">
12
+ <div class="Polaris-ResourceList__HeaderTitleWrapper"><%= header_title %></div>
13
+ </div>
14
+ </div>
15
+ </div>
16
+ <% end %>
17
+
7
18
  <%= render(Polaris::BaseComponent.new(**@system_arguments)) do %>
8
19
  <%= content %>
9
20
  <% end %>
@@ -5,9 +5,16 @@ module Polaris
5
5
  renders_one :filters, Polaris::FiltersComponent
6
6
 
7
7
  def initialize(
8
+ items: [],
9
+ resource_name: nil,
10
+ total_items_count: nil,
8
11
  wrapper_arguments: {},
9
12
  **system_arguments
10
13
  )
14
+ @items = items
15
+ @resource_name = resource_name
16
+ @total_items_count = total_items_count
17
+
11
18
  @wrapper_arguments = wrapper_arguments
12
19
  @wrapper_arguments[:tag] = "div"
13
20
  @wrapper_arguments[:classes] = class_names(
@@ -22,5 +29,19 @@ module Polaris
22
29
  "Polaris-ResourceList"
23
30
  )
24
31
  end
32
+
33
+ def header_title
34
+ count unless @total_items_count.nil?
35
+ end
36
+
37
+ def resource_string
38
+ return @resource_name[:singular] if @items.size === 1 && !@total_items_count
39
+
40
+ @resource_name[:plural]
41
+ end
42
+
43
+ def count
44
+ "Showing #{@items.size} of #{@total_items_count} #{resource_string}"
45
+ end
25
46
  end
26
47
  end
@@ -0,0 +1,23 @@
1
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
2
+ <div class="Polaris-SkeletonPage__Header">
3
+ <div class="Polaris-SkeletonPage__TitleAndPrimaryAction">
4
+ <div class="Polaris-SkeletonPage__TitleWrapper">
5
+ <% if @title.present? %>
6
+ <h1 class="Polaris-SkeletonPage__Title">
7
+ <%= @title %>
8
+ </h1>
9
+ <% else %>
10
+ <div class="Polaris-SkeletonPage__SkeletonTitle"></div>
11
+ <% end %>
12
+ </div>
13
+ <% if @primary_action %>
14
+ <div class="Polaris-SkeletonPage__PrimaryAction">
15
+ <%= polaris_skeleton_display_text(size: :large) %>
16
+ </div>
17
+ <% end %>
18
+ </div>
19
+ </div>
20
+ <div class="Polaris-SkeletonPage__Content">
21
+ <%= content %>
22
+ </div>
23
+ <% end %>
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class SkeletonPageComponent < Polaris::Component
5
+ def initialize(title: nil, primary_action: false, **system_arguments)
6
+ @title = title
7
+ @primary_action = primary_action
8
+ @system_arguments = system_arguments
9
+ end
10
+
11
+ def system_arguments
12
+ @system_arguments.tap do |opts|
13
+ opts[:tag] = "div"
14
+ opts[:role] = "status"
15
+ opts[:classes] = class_names(
16
+ @system_arguments[:classes],
17
+ "Polaris-SkeletonPage__Page"
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -15,5 +15,42 @@ module Polaris
15
15
  content
16
16
  end
17
17
  end
18
+
19
+ def polaris_link_to(name = nil, options = nil, html_options = nil, &block)
20
+ html_options, options, name = options, name, block if block
21
+ options ||= {}
22
+
23
+ html_options = convert_options_to_data_attributes(options, html_options)
24
+ html_options[:classes] = html_options[:class]
25
+ html_options.delete(:class)
26
+
27
+ url = url_target(name, options)
28
+
29
+ link = Polaris::LinkComponent.new(url: url, **html_options)
30
+ link = link.with_content(name) unless block
31
+
32
+ render(link, &block)
33
+ end
34
+
35
+ def polaris_mail_to(email_address, name = nil, html_options = {}, &block)
36
+ html_options, name = name, nil if name.is_a?(Hash)
37
+ html_options = (html_options || {}).stringify_keys
38
+ html_options[:classes] = html_options[:class]
39
+ html_options.delete(:class)
40
+
41
+ extras = %w[cc bcc body subject reply_to].map! { |item|
42
+ option = html_options.delete(item).presence || next
43
+ "#{item.dasherize}=#{ERB::Util.url_encode(option)}"
44
+ }.compact
45
+ extras = extras.empty? ? "" : "?" + extras.join("&")
46
+
47
+ encoded_email_address = ERB::Util.url_encode(email_address).gsub("%40", "@")
48
+ url = "mailto:#{encoded_email_address}#{extras}"
49
+
50
+ link = Polaris::LinkComponent.new(url: url, **html_options)
51
+ link = link.with_content(name || email_address) unless block
52
+
53
+ render(link, &block)
54
+ end
18
55
  end
19
56
  end
@@ -24,6 +24,7 @@ module Polaris
24
24
  description_list: "Polaris::DescriptionListComponent",
25
25
  display_text: "Polaris::DisplayTextComponent",
26
26
  dropzone: "Polaris::DropzoneComponent",
27
+ empty_search_results: "Polaris::EmptySearchResultsComponent",
27
28
  empty_state: "Polaris::EmptyStateComponent",
28
29
  exception_list: "Polaris::ExceptionListComponent",
29
30
  footer_help: "Polaris::FooterHelpComponent",
@@ -59,6 +60,7 @@ module Polaris
59
60
  spinner: "Polaris::SpinnerComponent",
60
61
  skeleton_body_text: "Polaris::SkeletonBodyTextComponent",
61
62
  skeleton_display_text: "Polaris::SkeletonDisplayTextComponent",
63
+ skeleton_page: "Polaris::SkeletonPageComponent",
62
64
  skeleton_thumbnail: "Polaris::SkeletonThumbnailComponent",
63
65
  spacer: "Polaris::SpacerComponent",
64
66
  tabs: "Polaris::TabsComponent",
@@ -0,0 +1,57 @@
1
+ APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
2
+ IMPORTMAP_BINSTUB = Rails.root.join("bin/importmap")
3
+ IMPORTMAP_CONFIG_PATH = Rails.root.join("config/importmap.rb")
4
+ STIMULUS_PATH = Rails.root.join("app/javascript/controllers/index.js")
5
+
6
+ if APPLICATION_LAYOUT_PATH.exist?
7
+ say "Add Polaris styles in application layout"
8
+ insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n <%= stylesheet_link_tag \"polaris_view_components\" %>", before: /\s*<\/head>/
9
+
10
+ if File.read(APPLICATION_LAYOUT_PATH).include?("<body>")
11
+ say "Add Polaris inline styles for <body> in application layout"
12
+ gsub_file APPLICATION_LAYOUT_PATH.to_s, "<body>", "<body style=\"<%= polaris_body_styles %>\">"
13
+ else
14
+ say "<body> tag is not found in application layout.", :red
15
+ say " Replace <body> with <body style=\"<%= polaris_body_styles %>\"> in your custom layour."
16
+ end
17
+ else
18
+ say "Default application.html.erb is missing!", :red
19
+ say " 1. Add <%= stylesheet_link_tag \"polaris_view_components\" %> within the <head> tag in your custom layout."
20
+ say " 2. Replace <body> with <body style=\"<%= polaris_body_styles %>\"> in your custom layour."
21
+ end
22
+
23
+ if IMPORTMAP_BINSTUB.exist?
24
+ importmaps = File.read(IMPORTMAP_CONFIG_PATH)
25
+
26
+ unless importmaps.include?("@rails/request.js")
27
+ say "Pin @rails/request.js dependency"
28
+ run "bin/importmap pin @rails/request.js --download"
29
+ end
30
+
31
+ say "Pin polaris_view_components"
32
+ append_to_file IMPORTMAP_CONFIG_PATH do
33
+ 'pin "polaris-view-components", to: "polaris_view_components.js"\n'
34
+ end
35
+ else
36
+ package_json = File.read(Rails.root.join("package.json"))
37
+
38
+ unless package_json.include?("@rails/request.js")
39
+ say "Add @rails/request.js dependency"
40
+ run "yarn add @rails/request.js"
41
+ end
42
+
43
+ say "Add polaris-view-components package"
44
+ run "yarn add polaris-view-components"
45
+ end
46
+
47
+ if STIMULUS_PATH.exist?
48
+ say "Add Polaris Stimulus controllers"
49
+ append_to_file STIMULUS_PATH do
50
+ "\nimport { registerPolarisControllers } from \"polaris-view-components\"\nregisterPolarisControllers(Stimulus)\n"
51
+ end
52
+ else
53
+ say "Default Stimulus location is missing: app/javascript/controllers/index.js", :red
54
+ say " Add to your Stimulus index.js:"
55
+ say " import { registerPolarisControllers } from \"polaris-view-components\""
56
+ say " registerPolarisControllers(Stimulus)"
57
+ end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "0.10.1"
3
+ VERSION = "0.12.0"
4
4
  end
5
5
  end
@@ -0,0 +1,6 @@
1
+ namespace :polaris_view_components do
2
+ desc "Setup Polaris::ViewComponents for the app"
3
+ task :install do
4
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
5
+ end
6
+ end
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.10.1
4
+ version: 0.12.0
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: 2022-06-04 00:00:00.000000000 Z
12
+ date: 2022-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -615,6 +615,8 @@ files:
615
615
  - app/components/polaris/display_text_component.rb
616
616
  - app/components/polaris/dropzone_component.html.erb
617
617
  - app/components/polaris/dropzone_component.rb
618
+ - app/components/polaris/empty_search_results_component.html.erb
619
+ - app/components/polaris/empty_search_results_component.rb
618
620
  - app/components/polaris/empty_state_component.html.erb
619
621
  - app/components/polaris/empty_state_component.rb
620
622
  - app/components/polaris/exception_list/item_component.html.erb
@@ -693,6 +695,8 @@ files:
693
695
  - app/components/polaris/progress_bar_component.rb
694
696
  - app/components/polaris/radio_button_component.html.erb
695
697
  - app/components/polaris/radio_button_component.rb
698
+ - app/components/polaris/resource_item/shortcut_actions_component.html.erb
699
+ - app/components/polaris/resource_item/shortcut_actions_component.rb
696
700
  - app/components/polaris/resource_item_component.html.erb
697
701
  - app/components/polaris/resource_item_component.rb
698
702
  - app/components/polaris/resource_list_component.html.erb
@@ -708,6 +712,8 @@ files:
708
712
  - app/components/polaris/skeleton_body_text_component.html.erb
709
713
  - app/components/polaris/skeleton_body_text_component.rb
710
714
  - app/components/polaris/skeleton_display_text_component.rb
715
+ - app/components/polaris/skeleton_page_component.html.erb
716
+ - app/components/polaris/skeleton_page_component.rb
711
717
  - app/components/polaris/skeleton_thumbnail_component.rb
712
718
  - app/components/polaris/spacer_component.rb
713
719
  - app/components/polaris/spinner_component.html.erb
@@ -741,14 +747,12 @@ files:
741
747
  - app/helpers/polaris/view_helper.rb
742
748
  - app/validators/type_validator.rb
743
749
  - config/locales/en.yml
744
- - lib/generators/polaris_view_components/USAGE
745
- - lib/generators/polaris_view_components/install_generator.rb
746
- - lib/generators/polaris_view_components/templates/README
747
- - lib/generators/polaris_view_components/templates/stimulus_index.js
750
+ - lib/install/install.rb
748
751
  - lib/polaris/view_components.rb
749
752
  - lib/polaris/view_components/engine.rb
750
753
  - lib/polaris/view_components/version.rb
751
754
  - lib/polaris_view_components.rb
755
+ - lib/tasks/polaris_view_components_tasks.rake
752
756
  homepage: https://github.com/baoagency/polaris-view-components
753
757
  licenses:
754
758
  - MIT
@@ -1,5 +0,0 @@
1
- Description:
2
- Creates or adds import of NPM package to your application + additional installation steps.
3
-
4
- Example:
5
- rails generate polaris_view_components:install
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/active_record"
4
-
5
- module PolarisViewComponents
6
- class InstallGenerator < Rails::Generators::Base
7
- source_root File.expand_path("templates", __dir__)
8
-
9
- def add_npm_package
10
- say "Adding NPM package", :green
11
- run "yarn add polaris-view-components"
12
- end
13
-
14
- def add_to_stimulus_controller
15
- say "Adding import to to Stimulus controller", :green
16
- dir_path = "app/javascript/controllers"
17
- empty_directory("app/javascript")
18
- empty_directory(dir_path)
19
-
20
- file_path = "#{dir_path}/index.js"
21
-
22
- unless File.exist?(file_path)
23
- copy_file "stimulus_index.js", file_path
24
- end
25
-
26
- append_to_file file_path do
27
- "import { registerPolarisControllers } from \"polaris-view-components\"\nregisterPolarisControllers(Stimulus)"
28
- end
29
- end
30
-
31
- def show_readme
32
- readme "README"
33
- end
34
- end
35
- end
@@ -1,14 +0,0 @@
1
- ===============================================================================
2
-
3
- Some manual setup is still required:
4
-
5
- 1. Setup Polaris styles in your layouts <head> tag:
6
-
7
- <link rel="stylesheet" href="https://unpkg.com/@shopify/polaris@6.6.0/dist/styles.css" />
8
- <%= stylesheet_link_tag 'polaris_view_components' %>
9
-
10
- 2. Define Polaris style on your <body> tag:
11
-
12
- <body style="<%= polaris_body_styles %>">
13
-
14
- ===============================================================================
@@ -1,6 +0,0 @@
1
- import { Application } from "@hotwired/stimulus"
2
- import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"
3
-
4
- window.Stimulus = Application.start()
5
- const context = require.context("./", true, /\.js$/)
6
- Stimulus.load(definitionsFromContext(context))