polaris_view_components 0.1.3 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -3
  3. data/app/{javascript/polaris → assets/javascripts/polaris_view_components}/index.js +0 -0
  4. data/app/{javascript/polaris → assets/javascripts/polaris_view_components}/resource_item_controller.js +1 -1
  5. data/app/{javascript/polaris → assets/javascripts/polaris_view_components}/select_controller.js +1 -1
  6. data/app/{javascript/polaris → assets/javascripts/polaris_view_components}/text_field_controller.js +1 -1
  7. data/app/assets/javascripts/{polaris.js → polaris_view_components.js} +20 -40
  8. data/app/assets/stylesheets/polaris_view_components/shopify_navigation.css +136 -0
  9. data/app/assets/stylesheets/polaris_view_components.css +2029 -21
  10. data/app/assets/stylesheets/polaris_view_components.postcss.css +2 -0
  11. data/app/components/polaris/dropzone/controller.js +1 -1
  12. data/app/components/polaris/select_component.html.erb +11 -2
  13. data/app/components/polaris/select_component.rb +2 -0
  14. data/app/components/polaris/skeleton_body_text_component.html.erb +5 -0
  15. data/app/components/polaris/skeleton_body_text_component.rb +15 -0
  16. data/app/components/polaris/tag_component.html.erb +6 -0
  17. data/app/components/polaris/tag_component.rb +35 -0
  18. data/app/helpers/polaris/form_builder.rb +4 -0
  19. data/app/helpers/polaris/view_helper.rb +2 -0
  20. data/lib/generators/polaris_view_components/USAGE +5 -0
  21. data/lib/generators/polaris_view_components/install_generator.rb +35 -0
  22. data/lib/generators/polaris_view_components/templates/README +14 -0
  23. data/lib/generators/polaris_view_components/templates/stimulus_index.js +6 -0
  24. data/lib/polaris/view_components/engine.rb +3 -1
  25. data/lib/polaris/view_components/version.rb +1 -1
  26. metadata +19 -9
@@ -0,0 +1,2 @@
1
+ @import "@shopify/polaris/dist/styles.css";
2
+ @import "./polaris_view_components/shopify_navigation.css";
@@ -1,4 +1,4 @@
1
- import { Controller } from 'stimulus'
1
+ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  import { fileAccepted, getDataTransferFiles } from './utils'
4
4
 
@@ -1,9 +1,18 @@
1
1
  <%= render Polaris::LabelledComponent.new(**@wrapper_arguments) do %>
2
2
  <%= render Polaris::BaseComponent.new(**@system_arguments) do %>
3
3
  <% if @form.present? && @attribute.present? %>
4
- <%= @form.select(@attribute, options_for_select(@options, @selected), @select_options, @input_options) %>
4
+ <%= @form.select(
5
+ @attribute,
6
+ options_for_select(@options, selected: @selected, disabled: @disabled_options),
7
+ @select_options,
8
+ @input_options,
9
+ ) %>
5
10
  <% else %>
6
- <%= select_tag(@name, options_for_select(@options, @selected), @input_options) %>
11
+ <%= select_tag(
12
+ @name,
13
+ options_for_select(@options, selected: @selected, disabled: @disabled_options),
14
+ @input_options,
15
+ ) %>
7
16
  <% end %>
8
17
 
9
18
  <div
@@ -8,6 +8,7 @@ module Polaris
8
8
  name: nil,
9
9
  options:,
10
10
  selected: nil,
11
+ disabled_options: nil,
11
12
  label: nil,
12
13
  label_hidden: false,
13
14
  label_inline: false,
@@ -26,6 +27,7 @@ module Polaris
26
27
  @name = name
27
28
  @options = options
28
29
  @selected = selected
30
+ @disabled_options = disabled_options
29
31
  @label = label
30
32
  @label_hidden = label_hidden
31
33
  @label_inline = label_inline
@@ -0,0 +1,5 @@
1
+ <%= render Polaris::BaseComponent.new(**@system_arguments) do %>
2
+ <% @lines.times do %>
3
+ <div class="Polaris-SkeletonBodyText"></div>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class SkeletonBodyTextComponent < Polaris::NewComponent
5
+ def initialize(lines: 3, **system_arguments)
6
+ @lines = lines
7
+ @system_arguments = system_arguments
8
+ @system_arguments[:tag] = "div"
9
+ @system_arguments[:classes] = class_names(
10
+ @system_arguments[:classes],
11
+ "Polaris-SkeletonBodyText__SkeletonBodyTextContainer",
12
+ )
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ <%= render Polaris::BaseComponent.new(**system_arguments) do %>
2
+ <span class="Polaris-TagText">
3
+ <%= content %>
4
+ </span>
5
+ <%= remove_button %>
6
+ <% end %>
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class TagComponent < Polaris::NewComponent
5
+ renders_one :remove_button, lambda { |**system_arguments|
6
+ render Polaris::BaseButton.new(
7
+ classes: "Polaris-Tag__Button",
8
+ disabled: @disabled,
9
+ **system_arguments
10
+ ) do |button|
11
+ polaris_icon(name: "CancelSmallMinor")
12
+ end
13
+ }
14
+
15
+ def initialize(clickable: false, disabled: false, **system_arguments)
16
+ @clickable = clickable
17
+ @disabled = disabled
18
+
19
+ @system_arguments = system_arguments
20
+ end
21
+
22
+ def system_arguments
23
+ @system_arguments.tap do |opts|
24
+ opts[:tag] = @clickable ? "button" : "span"
25
+ opts[:classes] = class_names(
26
+ @system_arguments[:classes],
27
+ "Polaris-Tag",
28
+ "Polaris-Tag--clickable" => @clickable,
29
+ "Polaris-Tag--disabled" => @disabled,
30
+ "Polaris-Tag--removable" => remove_button.present?
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -42,6 +42,10 @@ module Polaris
42
42
  if options[:error_hidden] && options[:error]
43
43
  options[:error] = !!options[:error]
44
44
  end
45
+ value = object&.public_send(method)
46
+ if value.present?
47
+ options[:selected] = value
48
+ end
45
49
  render Polaris::SelectComponent.new(form: self, attribute: method, **options, &block)
46
50
  end
47
51
  end
@@ -37,6 +37,8 @@ module Polaris
37
37
  stack: "Polaris::StackComponent",
38
38
  subheading: "Polaris::SubheadingComponent",
39
39
  spinner: "Polaris::SpinnerComponent",
40
+ skeleton_body_text: "Polaris::SkeletonBodyTextComponent",
41
+ tag: "Polaris::TagComponent",
40
42
  text_container: "Polaris::TextContainerComponent",
41
43
  text_field: "Polaris::TextFieldComponent",
42
44
  text_style: "Polaris::TextStyleComponent",
@@ -0,0 +1,5 @@
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
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,14 @@
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
+ ===============================================================================
@@ -0,0 +1,6 @@
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))
@@ -13,7 +13,9 @@ module Polaris
13
13
 
14
14
  initializer "polaris_view_components.assets" do |app|
15
15
  if app.config.respond_to?(:assets)
16
- app.config.assets.precompile += %w[polaris_view_components.css]
16
+ app.config.assets.precompile += %w[
17
+ polaris_view_components.js polaris_view_components.css
18
+ ]
17
19
  end
18
20
  end
19
21
 
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "0.1.3"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  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.1.3
4
+ version: 0.3.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-16 00:00:00.000000000 Z
12
+ date: 2021-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: 5.0.0
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: 7.0.0
23
+ version: 8.0.0
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: 5.0.0
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: 7.0.0
33
+ version: 8.0.0
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: view_component
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -447,8 +447,14 @@ files:
447
447
  - app/assets/icons/polaris/WearableMajor.svg
448
448
  - app/assets/icons/polaris/WholesaleMajor.svg
449
449
  - app/assets/icons/polaris/WifiMajor.svg
450
- - app/assets/javascripts/polaris.js
450
+ - app/assets/javascripts/polaris_view_components.js
451
+ - app/assets/javascripts/polaris_view_components/index.js
452
+ - app/assets/javascripts/polaris_view_components/resource_item_controller.js
453
+ - app/assets/javascripts/polaris_view_components/select_controller.js
454
+ - app/assets/javascripts/polaris_view_components/text_field_controller.js
451
455
  - app/assets/stylesheets/polaris_view_components.css
456
+ - app/assets/stylesheets/polaris_view_components.postcss.css
457
+ - app/assets/stylesheets/polaris_view_components/shopify_navigation.css
452
458
  - app/components/polaris/action.rb
453
459
  - app/components/polaris/application_component.rb
454
460
  - app/components/polaris/avatar_component.html.erb
@@ -539,11 +545,15 @@ files:
539
545
  - app/components/polaris/select_component.rb
540
546
  - app/components/polaris/shopify_navigation_component.html.erb
541
547
  - app/components/polaris/shopify_navigation_component.rb
548
+ - app/components/polaris/skeleton_body_text_component.html.erb
549
+ - app/components/polaris/skeleton_body_text_component.rb
542
550
  - app/components/polaris/spinner_component.html.erb
543
551
  - app/components/polaris/spinner_component.rb
544
552
  - app/components/polaris/stack_component.html.erb
545
553
  - app/components/polaris/stack_component.rb
546
554
  - app/components/polaris/subheading_component.rb
555
+ - app/components/polaris/tag_component.html.erb
556
+ - app/components/polaris/tag_component.rb
547
557
  - app/components/polaris/text_container_component.rb
548
558
  - app/components/polaris/text_field_component.html.erb
549
559
  - app/components/polaris/text_field_component.rb
@@ -559,11 +569,11 @@ files:
559
569
  - app/helpers/polaris/option_helper.rb
560
570
  - app/helpers/polaris/url_helper.rb
561
571
  - app/helpers/polaris/view_helper.rb
562
- - app/javascript/polaris/index.js
563
- - app/javascript/polaris/resource_item_controller.js
564
- - app/javascript/polaris/select_controller.js
565
- - app/javascript/polaris/text_field_controller.js
566
572
  - app/validators/type_validator.rb
573
+ - lib/generators/polaris_view_components/USAGE
574
+ - lib/generators/polaris_view_components/install_generator.rb
575
+ - lib/generators/polaris_view_components/templates/README
576
+ - lib/generators/polaris_view_components/templates/stimulus_index.js
567
577
  - lib/polaris/view_components.rb
568
578
  - lib/polaris/view_components/engine.rb
569
579
  - lib/polaris/view_components/version.rb