polaris_view_components 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b8966c0866f8b002c720f0dd8578f825a9abf64753ead41dcdf84150dd24f8c
4
- data.tar.gz: 9fb7b270e5fbe102a79342462795b472ac4849d412431d5990fc0bf17ab9aef1
3
+ metadata.gz: 5fa1e7b371df5781aea68bbf2be3d7872fc4d704076c48473039b23850440332
4
+ data.tar.gz: 647c10b9000fd7de97977497aaf910d02abb3f692fb563e3f1166b73c88a02e8
5
5
  SHA512:
6
- metadata.gz: 5078ffd0ee20e1df92e5373ab423fb740ae046596b960322b263ec02a2938a082db91ce92b96639257cc7702de321c561f3c8621caa404bdc0246f0de837e021
7
- data.tar.gz: 6568cc0c13ccee2a3a94a2b3308bd546d5fe32c20e1742699999698ef02db79938f717e20fc64ad71867ff1eba8720b4be2d88682ecff459f13221e6ecda107d
6
+ metadata.gz: 6364ad7a248ef54858f7f8700360468ffc7954bf7035907227c0acb666ff1f0cc554c02bebbba961d57a4c30581b576035221b34a1345c639e18d6b46c1a10be
7
+ data.tar.gz: 249ff1b9089d7907d6ef290801a410dbf7e37aaf1fe238750e3cb5283d9b0bb1b157642bae870f8a8599e383a332aca20df630f9411a06404a37530ab7176181
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Polaris ViewComponents is an implementation of the Polaris Design System using [ViewComponent](https://github.com/github/view_component).
4
4
 
5
+ ![Polaris ViewComponents](.github/assets/preview.png)
6
+
5
7
  > **This library is under active development. Breaking changes are likely until stable release.**
6
8
 
7
9
  ## Preview
@@ -14,6 +14,19 @@ function _defineProperty(obj, key, value) {
14
14
  return obj;
15
15
  }
16
16
 
17
+ class _class$2 extends Controller {
18
+ open(event) {
19
+ if (this.hasLinkTarget && this.targetNotClickable(event.target)) {
20
+ this.linkTarget.click();
21
+ }
22
+ }
23
+ targetNotClickable(element) {
24
+ return !element.closest("a") && !element.closest("button") && element.nodeName !== "INPUT";
25
+ }
26
+ }
27
+
28
+ _defineProperty(_class$2, "targets", [ "link" ]);
29
+
17
30
  class _class$1 extends Controller {
18
31
  update(event) {
19
32
  const select = event.currentTarget;
@@ -106,8 +119,9 @@ _defineProperty(_class, "values", {
106
119
  });
107
120
 
108
121
  function registerPolarisControllers(application) {
122
+ application.register("polaris-resource-item", _class$2);
109
123
  application.register("polaris-select", _class$1);
110
124
  application.register("polaris-text-field", _class);
111
125
  }
112
126
 
113
- export { _class$1 as Select, _class as TextField, registerPolarisControllers };
127
+ export { _class$2 as ResourceItem, _class$1 as Select, _class as TextField, registerPolarisControllers };
@@ -1,4 +1,4 @@
1
- <%= render Polaris::BaseComponent.new(tag: @tag, **dynamic_arguments) do %>
1
+ <%= render Polaris::BaseComponent.new(tag: @tag, **system_arguments) do %>
2
2
  <span class="Polaris-Button__Content">
3
3
  <% if @loading %>
4
4
  <span class="Polaris-Button__Spinner">
@@ -1,90 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polaris
4
- class ButtonComponent < Polaris::NewComponent
5
- SIZE_DEFAULT = :medium
6
- SIZE_MAPPINGS = {
7
- SIZE_DEFAULT => "",
8
- :slim => "Polaris-Button--sizeSlim",
9
- :large => "Polaris-Button--sizeLarge",
10
- }
11
- SIZE_OPTIONS = SIZE_MAPPINGS.keys
12
-
13
- TEXT_ALIGN_DEFAULT = :default
14
- TEXT_ALIGN_MAPPINGS = {
15
- TEXT_ALIGN_DEFAULT => "",
16
- :left => "Polaris-Button--textAlignLeft",
17
- :center => "Polaris-Button--textAlignCenter",
18
- :right => "Polaris-Button--textAlignRight",
19
- }
20
- TEXT_ALIGN_OPTIONS = TEXT_ALIGN_MAPPINGS.keys
21
-
22
- renders_one :icon, IconComponent
23
-
24
- def initialize(
25
- url: nil,
26
- outline: false,
27
- plain: false,
28
- primary: false,
29
- pressed: false,
30
- monochrome: false,
31
- loading: false,
32
- destructive: false,
33
- disabled: false,
34
- external: false,
35
- full_width: false,
36
- submit: false,
37
- remove_underline: false,
38
- size: SIZE_DEFAULT,
39
- text_align: TEXT_ALIGN_DEFAULT,
40
- **system_arguments
41
- )
42
- @tag = url.present? ? 'a' : 'button'
43
- @text_classes = class_names(
44
- "Polaris-Button__Text",
45
- "Polaris-Button--removeUnderline": plain && monochrome && remove_underline
46
- )
47
- @loading = loading
48
-
49
- @system_arguments = system_arguments
50
- @system_arguments[:type] = submit ? 'submit' : 'button'
51
- if loading
52
- @system_arguments[:disabled] = true
53
- end
54
- if url.present?
55
- @system_arguments.delete(:type)
56
- @system_arguments[:href] = url
57
- @system_arguments[:target] = "_blank" if external
58
- end
59
- if disabled
60
- @system_arguments[:disabled] = disabled
61
- end
62
- @system_arguments[:classes] = class_names(
63
- @system_arguments[:classes],
64
- "Polaris-Button",
65
- SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
66
- TEXT_ALIGN_MAPPINGS[fetch_or_fallback(TEXT_ALIGN_OPTIONS, text_align, TEXT_ALIGN_DEFAULT)],
67
- "Polaris-Button--destructive": destructive,
68
- "Polaris-Button--disabled": disabled || loading,
69
- "Polaris-Button--loading": loading,
70
- "Polaris-Button--fullWidth": full_width,
71
- "Polaris-Button--monochrome": monochrome,
72
- "Polaris-Button--outline": outline,
73
- "Polaris-Button--plain": plain,
74
- "Polaris-Button--primary": primary,
75
- "Polaris-Button--pressed": pressed,
76
- "Polaris-Button--removeUnderline": (plain && monochrome && remove_underline)
77
- )
78
- end
79
-
80
- private
81
-
82
- def dynamic_arguments
83
- @system_arguments[:classes] = class_names(
84
- @system_arguments[:classes],
85
- "Polaris-Button--iconOnly": icon.present? && content.blank?,
86
- )
87
- @system_arguments
88
- end
4
+ class ButtonComponent < HeadlessButton
89
5
  end
90
6
  end
@@ -0,0 +1,22 @@
1
+ <span class="Polaris-Button__Content">
2
+ <% if @loading %>
3
+ <span class="Polaris-Button__Spinner">
4
+ <%= polaris_spinner(size: :small) %>
5
+ </span>
6
+ <% end %>
7
+
8
+ <% if icon.present? %>
9
+ <div class="Polaris-Button__Icon">
10
+ <%= icon %>
11
+ </div>
12
+ <% if content.present? %>
13
+ &nbsp;
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <% if content.present? %>
18
+ <div class="<%= @text_classes %>">
19
+ <%= content %>
20
+ </div>
21
+ <% end %>
22
+ </span>
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class HeadlessButton < Polaris::NewComponent
5
+ SIZE_DEFAULT = :medium
6
+ SIZE_MAPPINGS = {
7
+ SIZE_DEFAULT => "",
8
+ :slim => "Polaris-Button--sizeSlim",
9
+ :large => "Polaris-Button--sizeLarge",
10
+ }
11
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
12
+
13
+ TEXT_ALIGN_DEFAULT = :default
14
+ TEXT_ALIGN_MAPPINGS = {
15
+ TEXT_ALIGN_DEFAULT => "",
16
+ :left => "Polaris-Button--textAlignLeft",
17
+ :center => "Polaris-Button--textAlignCenter",
18
+ :right => "Polaris-Button--textAlignRight",
19
+ }
20
+ TEXT_ALIGN_OPTIONS = TEXT_ALIGN_MAPPINGS.keys
21
+
22
+ renders_one :icon, IconComponent
23
+
24
+ def initialize(
25
+ url: nil,
26
+ outline: false,
27
+ plain: false,
28
+ primary: false,
29
+ pressed: false,
30
+ monochrome: false,
31
+ loading: false,
32
+ destructive: false,
33
+ disabled: false,
34
+ external: false,
35
+ full_width: false,
36
+ submit: false,
37
+ remove_underline: false,
38
+ size: SIZE_DEFAULT,
39
+ text_align: TEXT_ALIGN_DEFAULT,
40
+ **system_arguments
41
+ )
42
+ @tag = url.present? ? 'a' : 'button'
43
+ @text_classes = class_names(
44
+ "Polaris-Button__Text",
45
+ "Polaris-Button--removeUnderline": plain && monochrome && remove_underline
46
+ )
47
+ @loading = loading
48
+
49
+ @system_arguments = system_arguments
50
+ @system_arguments[:type] = submit ? 'submit' : 'button'
51
+ if loading
52
+ @system_arguments[:disabled] = true
53
+ end
54
+ if url.present?
55
+ @system_arguments.delete(:type)
56
+ @system_arguments[:href] = url
57
+ @system_arguments[:target] = "_blank" if external
58
+ end
59
+ if disabled
60
+ @system_arguments[:disabled] = disabled
61
+ end
62
+ @system_arguments[:classes] = class_names(
63
+ @system_arguments[:classes],
64
+ "Polaris-Button",
65
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
66
+ TEXT_ALIGN_MAPPINGS[fetch_or_fallback(TEXT_ALIGN_OPTIONS, text_align, TEXT_ALIGN_DEFAULT)],
67
+ "Polaris-Button--destructive": destructive,
68
+ "Polaris-Button--disabled": disabled || loading,
69
+ "Polaris-Button--loading": loading,
70
+ "Polaris-Button--fullWidth": full_width,
71
+ "Polaris-Button--monochrome": monochrome,
72
+ "Polaris-Button--outline": outline,
73
+ "Polaris-Button--plain": plain,
74
+ "Polaris-Button--primary": primary,
75
+ "Polaris-Button--pressed": pressed,
76
+ "Polaris-Button--removeUnderline": (plain && monochrome && remove_underline)
77
+ )
78
+ end
79
+
80
+ def system_arguments
81
+ @system_arguments[:classes] = class_names(
82
+ @system_arguments[:classes],
83
+ "Polaris-Button--iconOnly": icon.present? && content.blank?,
84
+ )
85
+ @system_arguments
86
+ end
87
+
88
+ def html_options
89
+ options = system_arguments
90
+ options[:class] = options[:classes]
91
+ options.delete(:classes)
92
+ options
93
+ end
94
+ end
95
+ end
@@ -1,15 +1,16 @@
1
- <%= render(Polaris::BaseComponent.new(**@system_arguments)) do %>
1
+ <%= render(Polaris::BaseComponent.new(**wrapper_arguments)) do %>
2
2
  <div class="Polaris-ResourceItem__ItemWrapper">
3
- <div class="Polaris-ResourceItem" style="cursor: <%= @cursor %>;">
3
+ <%= render(Polaris::BaseComponent.new(**system_arguments)) do %>
4
4
  <% if @url %>
5
5
  <a
6
6
  class="Polaris-ResourceItem__Link"
7
7
  tabindex="0"
8
8
  href="<%= @url %>"
9
- data-polaris-unstyled="true"></a>
9
+ data-polaris-unstyled="true"
10
+ data-polaris-resource-item-target="link"></a>
10
11
  <% end %>
11
12
 
12
- <%= render(Polaris::BaseComponent.new(**@container_arguments)) do %>
13
+ <%= render(Polaris::BaseComponent.new(**container_arguments)) do %>
13
14
  <% if media.present? %>
14
15
  <div class="Polaris-ResourceItem__Owned">
15
16
  <div class="Polaris-ResourceItem__Media">
@@ -21,6 +22,6 @@
21
22
  <%= content %>
22
23
  </div>
23
24
  <% end %>
24
- </div>
25
+ <% end %>
25
26
  </div>
26
27
  <% end %>
@@ -16,27 +16,60 @@ module Polaris
16
16
 
17
17
  def initialize(
18
18
  url: nil,
19
- cursor: CURSOR_DEFAULT,
20
19
  vertical_alignment: ALIGNMENT_DEFAULT,
20
+ wrapper_arguments: {},
21
+ container_arguments: {},
21
22
  **system_arguments
22
23
  )
23
24
  @url = url
24
- @cursor = fetch_or_fallback(CURSOR_OPTIONS, cursor, CURSOR_DEFAULT)
25
-
25
+ @vertical_alignment = vertical_alignment
26
+ @wrapper_arguments = wrapper_arguments
27
+ @container_arguments = container_arguments
26
28
  @system_arguments = system_arguments
27
- @system_arguments[:tag] = "li"
28
- @system_arguments[:classes] = class_names(
29
- @system_arguments[:classes],
30
- "Polaris-ResourceItem__ListItem",
31
- )
29
+ end
30
+
31
+ def wrapper_arguments
32
+ {
33
+ tag: "li",
34
+ data: {},
35
+ }.deep_merge(@wrapper_arguments).tap do |args|
36
+ args[:classes] = class_names(
37
+ args[:classes],
38
+ "Polaris-ResourceItem__ListItem",
39
+ )
40
+ prepend_option(args[:data], :controller, "polaris-resource-item")
41
+ end
42
+ end
32
43
 
33
- @container_arguments = {
44
+ def container_arguments
45
+ {
34
46
  tag: "div",
35
- classes: class_names(
47
+ }.deep_merge(@container_arguments).tap do |args|
48
+ args[:classes] = class_names(
49
+ args[:classes],
36
50
  "Polaris-ResourceItem__Container",
37
- ALIGNMENT_MAPPINGS[fetch_or_fallback(ALIGNMENT_OPTIONS, vertical_alignment, ALIGNMENT_DEFAULT)],
51
+ ALIGNMENT_MAPPINGS[fetch_or_fallback(ALIGNMENT_OPTIONS, @vertical_alignment, ALIGNMENT_DEFAULT)],
38
52
  )
39
- }
53
+ end
40
54
  end
55
+
56
+ def system_arguments
57
+ {
58
+ tag: "div",
59
+ data: {},
60
+ }.deep_merge(@system_arguments).tap do |args|
61
+ args[:classes] = class_names(
62
+ args[:classes],
63
+ "Polaris-ResourceItem",
64
+ )
65
+ prepend_option(args, :style, "cursor: #{cursor};")
66
+ prepend_option(args[:data], :action, "click->polaris-resource-item#open")
67
+ end
68
+ end
69
+
70
+ private
71
+ def cursor
72
+ @url.present? ? "pointer" : "default"
73
+ end
41
74
  end
42
75
  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
@@ -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 '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
+ }
@@ -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(
@@ -20,6 +20,7 @@ module Polaris
20
20
  initializer "polaris_view_components.helpers" do
21
21
  ActiveSupport.on_load(:action_controller_base) do
22
22
  helper Polaris::ViewHelper
23
+ helper Polaris::UrlHelper
23
24
  helper Polaris::ActionHelper
24
25
  helper Polaris::ConditionalHelper
25
26
  end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
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.1.3
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-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -503,6 +503,8 @@ files:
503
503
  - app/components/polaris/form_layout_component.html.erb
504
504
  - app/components/polaris/form_layout_component.rb
505
505
  - app/components/polaris/heading_component.rb
506
+ - app/components/polaris/headless_button.html.erb
507
+ - app/components/polaris/headless_button.rb
506
508
  - app/components/polaris/icon_component.html.erb
507
509
  - app/components/polaris/icon_component.rb
508
510
  - app/components/polaris/inline_error_component.html.erb
@@ -555,8 +557,10 @@ files:
555
557
  - app/helpers/polaris/fetch_or_fallback_helper.rb
556
558
  - app/helpers/polaris/form_builder.rb
557
559
  - app/helpers/polaris/option_helper.rb
560
+ - app/helpers/polaris/url_helper.rb
558
561
  - app/helpers/polaris/view_helper.rb
559
562
  - app/javascript/polaris/index.js
563
+ - app/javascript/polaris/resource_item_controller.js
560
564
  - app/javascript/polaris/select_controller.js
561
565
  - app/javascript/polaris/text_field_controller.js
562
566
  - app/validators/type_validator.rb