polaris_view_components 0.1.2 → 0.3.1

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -3
  3. data/app/assets/javascripts/{polaris.js → polaris_view_components.js} +27 -33
  4. data/app/assets/stylesheets/polaris@6.6.0.css +4104 -0
  5. data/app/assets/stylesheets/polaris_view_components.css +3 -136
  6. data/app/assets/stylesheets/shopify_navigation.css +136 -0
  7. data/app/components/polaris/button_component.html.erb +1 -1
  8. data/app/components/polaris/button_component.rb +1 -85
  9. data/app/components/polaris/dropzone/controller.js +1 -1
  10. data/app/components/polaris/headless_button.html.erb +22 -0
  11. data/app/components/polaris/headless_button.rb +95 -0
  12. data/app/components/polaris/resource_item_component.html.erb +6 -5
  13. data/app/components/polaris/resource_item_component.rb +45 -12
  14. data/app/components/polaris/select_component.html.erb +11 -2
  15. data/app/components/polaris/select_component.rb +2 -0
  16. data/app/components/polaris/skeleton_body_text_component.html.erb +5 -0
  17. data/app/components/polaris/skeleton_body_text_component.rb +15 -0
  18. data/app/components/polaris/tag_component.html.erb +6 -0
  19. data/app/components/polaris/tag_component.rb +35 -0
  20. data/app/helpers/polaris/form_builder.rb +4 -0
  21. data/app/helpers/polaris/url_helper.rb +19 -0
  22. data/app/helpers/polaris/view_helper.rb +2 -0
  23. data/app/javascript/{polaris → polaris_view_components}/index.js +3 -1
  24. data/app/javascript/polaris_view_components/resource_item_controller.js +15 -0
  25. data/app/javascript/{polaris → polaris_view_components}/select_controller.js +1 -1
  26. data/app/javascript/{polaris → polaris_view_components}/text_field_controller.js +1 -2
  27. data/lib/generators/polaris_view_components/USAGE +5 -0
  28. data/lib/generators/polaris_view_components/install_generator.rb +35 -0
  29. data/lib/generators/polaris_view_components/templates/README +14 -0
  30. data/lib/generators/polaris_view_components/templates/stimulus_index.js +6 -0
  31. data/lib/polaris/view_components/engine.rb +4 -1
  32. data/lib/polaris/view_components/version.rb +1 -1
  33. metadata +22 -8
@@ -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
@@ -0,0 +1,19 @@
1
+ module Polaris
2
+ module UrlHelper
3
+ def polaris_button_to(name = nil, options = nil, html_options = nil, &block)
4
+ html_options, options = options, name if block_given?
5
+ options ||= {}
6
+ html_options ||= {}
7
+ html_options[:classes] = html_options[:class]
8
+ html_options.delete(:class)
9
+
10
+ button = Polaris::HeadlessButton.new(submit: true, **html_options)
11
+ button = button.with_content(name) unless block_given?
12
+ content = render(button, &block)
13
+
14
+ button_to(options, button.html_options) do
15
+ content
16
+ end
17
+ end
18
+ end
19
+ 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",
@@ -1,9 +1,11 @@
1
+ import ResourceItem from './resource_item_controller'
1
2
  import Select from './select_controller'
2
3
  import TextField from './text_field_controller'
3
4
 
4
- export { Select, TextField }
5
+ export { ResourceItem, Select, TextField }
5
6
 
6
7
  export function registerPolarisControllers(application) {
8
+ application.register('polaris-resource-item', ResourceItem)
7
9
  application.register('polaris-select', Select)
8
10
  application.register('polaris-text-field', TextField)
9
11
  }
@@ -0,0 +1,15 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ['link']
5
+
6
+ open(event) {
7
+ if (this.hasLinkTarget && this.targetNotClickable(event.target)) {
8
+ this.linkTarget.click()
9
+ }
10
+ }
11
+
12
+ targetNotClickable(element) {
13
+ return !element.closest('a') && !element.closest('button') && element.nodeName !== "INPUT"
14
+ }
15
+ }
@@ -1,4 +1,4 @@
1
- import { Controller } from 'stimulus'
1
+ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
4
  static targets = ['selectedOption']
@@ -1,4 +1,4 @@
1
- import { Controller } from 'stimulus'
1
+ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
4
  static targets = ['input', 'clearButton', 'characterCount']
@@ -99,7 +99,6 @@ export default class extends Controller {
99
99
 
100
100
  // Making sure the new value has the same length of decimal places as the
101
101
  // step / value has.
102
- console.log(numericValue, this.stepValue)
103
102
  const decimalPlaces = Math.max(dpl(numericValue), dpl(this.stepValue))
104
103
 
105
104
  const newValue = Math.min(
@@ -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,13 +13,16 @@ 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
 
20
22
  initializer "polaris_view_components.helpers" do
21
23
  ActiveSupport.on_load(:action_controller_base) do
22
24
  helper Polaris::ViewHelper
25
+ helper Polaris::UrlHelper
23
26
  helper Polaris::ActionHelper
24
27
  helper Polaris::ConditionalHelper
25
28
  end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "0.1.2"
3
+ VERSION = "0.3.1"
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.2
4
+ version: 0.3.1
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 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,10 @@ 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/stylesheets/polaris@6.6.0.css
451
452
  - app/assets/stylesheets/polaris_view_components.css
453
+ - app/assets/stylesheets/shopify_navigation.css
452
454
  - app/components/polaris/action.rb
453
455
  - app/components/polaris/application_component.rb
454
456
  - app/components/polaris/avatar_component.html.erb
@@ -503,6 +505,8 @@ files:
503
505
  - app/components/polaris/form_layout_component.html.erb
504
506
  - app/components/polaris/form_layout_component.rb
505
507
  - app/components/polaris/heading_component.rb
508
+ - app/components/polaris/headless_button.html.erb
509
+ - app/components/polaris/headless_button.rb
506
510
  - app/components/polaris/icon_component.html.erb
507
511
  - app/components/polaris/icon_component.rb
508
512
  - app/components/polaris/inline_error_component.html.erb
@@ -537,11 +541,15 @@ files:
537
541
  - app/components/polaris/select_component.rb
538
542
  - app/components/polaris/shopify_navigation_component.html.erb
539
543
  - app/components/polaris/shopify_navigation_component.rb
544
+ - app/components/polaris/skeleton_body_text_component.html.erb
545
+ - app/components/polaris/skeleton_body_text_component.rb
540
546
  - app/components/polaris/spinner_component.html.erb
541
547
  - app/components/polaris/spinner_component.rb
542
548
  - app/components/polaris/stack_component.html.erb
543
549
  - app/components/polaris/stack_component.rb
544
550
  - app/components/polaris/subheading_component.rb
551
+ - app/components/polaris/tag_component.html.erb
552
+ - app/components/polaris/tag_component.rb
545
553
  - app/components/polaris/text_container_component.rb
546
554
  - app/components/polaris/text_field_component.html.erb
547
555
  - app/components/polaris/text_field_component.rb
@@ -555,11 +563,17 @@ files:
555
563
  - app/helpers/polaris/fetch_or_fallback_helper.rb
556
564
  - app/helpers/polaris/form_builder.rb
557
565
  - app/helpers/polaris/option_helper.rb
566
+ - app/helpers/polaris/url_helper.rb
558
567
  - app/helpers/polaris/view_helper.rb
559
- - app/javascript/polaris/index.js
560
- - app/javascript/polaris/select_controller.js
561
- - app/javascript/polaris/text_field_controller.js
568
+ - app/javascript/polaris_view_components/index.js
569
+ - app/javascript/polaris_view_components/resource_item_controller.js
570
+ - app/javascript/polaris_view_components/select_controller.js
571
+ - app/javascript/polaris_view_components/text_field_controller.js
562
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
563
577
  - lib/polaris/view_components.rb
564
578
  - lib/polaris/view_components/engine.rb
565
579
  - lib/polaris/view_components/version.rb