polaris_view_components 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/{javascript → assets/javascripts}/polaris_view_components/index.js +0 -0
  4. data/app/{javascript → assets/javascripts}/polaris_view_components/resource_item_controller.js +0 -0
  5. data/app/assets/javascripts/polaris_view_components/select_controller.js +14 -0
  6. data/app/{javascript → assets/javascripts}/polaris_view_components/text_field_controller.js +0 -0
  7. data/app/assets/javascripts/polaris_view_components.js +6 -4
  8. data/app/assets/stylesheets/polaris_view_components/custom.css +43 -0
  9. data/app/assets/stylesheets/{shopify_navigation.css → polaris_view_components/shopify_navigation.css} +0 -4
  10. data/app/assets/stylesheets/polaris_view_components/spacer_component.css +39 -0
  11. data/app/assets/stylesheets/polaris_view_components.css +2214 -3
  12. data/app/assets/stylesheets/polaris_view_components.postcss.css +4 -0
  13. data/app/components/polaris/card/header_component.rb +0 -2
  14. data/app/components/polaris/card/section_component.rb +5 -1
  15. data/app/components/polaris/card_component.rb +0 -2
  16. data/app/components/polaris/data_table/cell_component.html.erb +18 -0
  17. data/app/components/polaris/data_table/cell_component.rb +49 -0
  18. data/app/components/polaris/data_table/column_component.rb +19 -0
  19. data/app/components/polaris/data_table_component.html.erb +77 -0
  20. data/app/components/polaris/data_table_component.rb +42 -0
  21. data/app/components/polaris/dropzone/component.rb +0 -2
  22. data/app/components/polaris/empty_state_component.html.erb +16 -11
  23. data/app/components/polaris/empty_state_component.rb +1 -0
  24. data/app/components/polaris/filters_component.html.erb +13 -0
  25. data/app/components/polaris/filters_component.rb +38 -0
  26. data/app/components/polaris/index_table/cell_component.rb +22 -0
  27. data/app/components/polaris/index_table/column_component.rb +13 -0
  28. data/app/components/polaris/index_table_component.html.erb +28 -0
  29. data/app/components/polaris/index_table_component.rb +25 -0
  30. data/app/components/polaris/inline_error_component.html.erb +2 -2
  31. data/app/components/polaris/inline_error_component.rb +7 -1
  32. data/app/components/polaris/layout/section.rb +2 -0
  33. data/app/components/polaris/link_component.rb +3 -1
  34. data/app/components/polaris/page_actions_component.rb +15 -1
  35. data/app/components/polaris/resource_list_component.html.erb +10 -0
  36. data/app/components/polaris/resource_list_component.rb +2 -8
  37. data/app/components/polaris/select_component.rb +7 -2
  38. data/app/components/polaris/spacer_component.rb +50 -0
  39. data/app/components/polaris/stack_component.rb +1 -1
  40. data/app/components/polaris/tag_component.rb +2 -2
  41. data/app/components/polaris/text_style_component.rb +9 -0
  42. data/app/helpers/polaris/form_builder.rb +27 -2
  43. data/app/helpers/polaris/view_helper.rb +15 -3
  44. data/lib/polaris/view_components/engine.rb +0 -1
  45. data/lib/polaris/view_components/version.rb +1 -1
  46. metadata +23 -11
  47. data/app/assets/stylesheets/polaris@6.6.0.css +0 -4104
  48. data/app/components/polaris/choice_list/component.html.erb +0 -34
  49. data/app/components/polaris/choice_list/component.rb +0 -65
  50. data/app/helpers/polaris/action_helper.rb +0 -14
  51. data/app/javascript/polaris_view_components/select_controller.js +0 -12
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polaris
4
+ class SpacerComponent < Polaris::NewComponent
5
+ VERTICAL_SPACING_DEFAULT = :default
6
+ VERTICAL_SPACING_MAPPINGS = {
7
+ VERTICAL_SPACING_DEFAULT => "",
8
+ :extra_tight => "Polaris-Spacer--verticalSpacingExtraTight",
9
+ :tight => "Polaris-Spacer--verticalSpacingTight",
10
+ :base_tight => "Polaris-Spacer--verticalSpacingBaseTight",
11
+ :base => "Polaris-Spacer--verticalSpacingBase",
12
+ :loose => "Polaris-Spacer--verticalSpacingLoose",
13
+ :extra_loose => "Polaris-Spacer--verticalSpacingExtraLoose",
14
+ }
15
+ VERTICAL_SPACING_OPTIONS = VERTICAL_SPACING_MAPPINGS.keys
16
+
17
+ HORIZONTAL_SPACING_DEFAULT = :default
18
+ HORIZONTAL_SPACING_MAPPINGS = {
19
+ HORIZONTAL_SPACING_DEFAULT => "",
20
+ :extra_tight => "Polaris-Spacer--horizontalSpacingExtraTight",
21
+ :tight => "Polaris-Spacer--horizontalSpacingTight",
22
+ :base_tight => "Polaris-Spacer--horizontalSpacingBaseTight",
23
+ :base => "Polaris-Spacer--horizontalSpacingBase",
24
+ :loose => "Polaris-Spacer--horizontalSpacingLoose",
25
+ :extra_loose => "Polaris-Spacer--horizontalSpacingExtraLoose",
26
+ }
27
+ HORIZONTAL_SPACING_OPTIONS = HORIZONTAL_SPACING_MAPPINGS.keys
28
+
29
+ def initialize(
30
+ vertical: VERTICAL_SPACING_DEFAULT,
31
+ horizontal: HORIZONTAL_SPACING_DEFAULT,
32
+ **system_arguments
33
+ )
34
+ @system_arguments = system_arguments
35
+ @system_arguments[:tag] = "div"
36
+ @system_arguments[:classes] = class_names(
37
+ @system_arguments[:classes],
38
+ "Polaris-Spacer",
39
+ VERTICAL_SPACING_MAPPINGS[fetch_or_fallback(VERTICAL_SPACING_OPTIONS, vertical, VERTICAL_SPACING_DEFAULT)],
40
+ HORIZONTAL_SPACING_MAPPINGS[fetch_or_fallback(HORIZONTAL_SPACING_OPTIONS, horizontal, HORIZONTAL_SPACING_DEFAULT)],
41
+ )
42
+ end
43
+
44
+ def call
45
+ render(Polaris::BaseComponent.new(**@system_arguments)) do
46
+ content
47
+ end
48
+ end
49
+ end
50
+ end
@@ -21,7 +21,7 @@ module Polaris
21
21
  :trailing => "Polaris-Stack--distributionTrailing",
22
22
  :center => "Polaris-Stack--distributionCenter",
23
23
  :fill => "Polaris-Stack--distributionFill",
24
- :fill_evently => "Polaris-Stack--distributionFillEvenly",
24
+ :fill_evenly => "Polaris-Stack--distributionFillEvenly",
25
25
  }
26
26
  DISTRIBUTION_OPTIONS = DISTRIBUTION_MAPPINGS.keys
27
27
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Polaris
4
4
  class TagComponent < Polaris::NewComponent
5
- renders_one :remove_button, lambda { |**system_arguments|
5
+ renders_one :remove_button, -> (**system_arguments) do
6
6
  render Polaris::BaseButton.new(
7
7
  classes: "Polaris-Tag__Button",
8
8
  disabled: @disabled,
@@ -10,7 +10,7 @@ module Polaris
10
10
  ) do |button|
11
11
  polaris_icon(name: "CancelSmallMinor")
12
12
  end
13
- }
13
+ end
14
14
 
15
15
  def initialize(clickable: false, disabled: false, **system_arguments)
16
16
  @clickable = clickable
@@ -13,8 +13,16 @@ module Polaris
13
13
  }
14
14
  VARIATION_OPTIONS = VARIATION_MAPPINGS.keys
15
15
 
16
+ SIZE_DEFAULT = :default
17
+ SIZE_MAPPINGS = {
18
+ SIZE_DEFAULT => "",
19
+ small: "Polaris-TextStyle--sizeSmall",
20
+ }
21
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
22
+
16
23
  def initialize(
17
24
  variation: VARIATION_DEFAULT,
25
+ size: SIZE_DEFAULT,
18
26
  **system_arguments
19
27
  )
20
28
  @system_arguments = system_arguments
@@ -22,6 +30,7 @@ module Polaris
22
30
  @system_arguments[:classes] = class_names(
23
31
  @system_arguments[:classes],
24
32
  VARIATION_MAPPINGS[fetch_or_fallback(VARIATION_OPTIONS, variation, VARIATION_DEFAULT)],
33
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)],
25
34
  )
26
35
  end
27
36
 
@@ -16,7 +16,7 @@ module Polaris
16
16
  ) do
17
17
  render(Polaris::ListComponent.new) do |list|
18
18
  object.errors.each do |error|
19
- list.item { error.full_message }
19
+ list.item { error.full_message.html_safe }
20
20
  end
21
21
  end
22
22
  end
@@ -26,7 +26,16 @@ module Polaris
26
26
  return if object.blank?
27
27
  return unless object.errors.key?(method)
28
28
 
29
- object.errors.full_messages_for(method)&.first
29
+ object.errors.full_messages_for(method)&.first.html_safe
30
+ end
31
+
32
+ def polaris_inline_error_for(method, **options, &block)
33
+ error_message = error_for(method)
34
+ return unless error_message
35
+
36
+ render(Polaris::InlineErrorComponent.new(**options, &block)) do
37
+ error_message
38
+ end
30
39
  end
31
40
 
32
41
  def polaris_text_field(method, **options, &block)
@@ -48,5 +57,21 @@ module Polaris
48
57
  end
49
58
  render Polaris::SelectComponent.new(form: self, attribute: method, **options, &block)
50
59
  end
60
+
61
+ def polaris_check_box(method, **options, &block)
62
+ options[:error] ||= error_for(method)
63
+ if options[:error_hidden] && options[:error]
64
+ options[:error] = !!options[:error]
65
+ end
66
+ render Polaris::CheckboxComponent.new(form: self, attribute: method, **options, &block)
67
+ end
68
+
69
+ def polaris_radio_button(method, **options, &block)
70
+ options[:error] ||= error_for(method)
71
+ if options[:error_hidden] && options[:error]
72
+ options[:error] = !!options[:error]
73
+ end
74
+ render Polaris::RadioButtonComponent.new(form: self, attribute: method, **options, &block)
75
+ end
51
76
  end
52
77
  end
@@ -1,7 +1,7 @@
1
1
  module Polaris
2
2
  # Module to allow shorthand calls for Polaris components
3
3
  module ViewHelper
4
- HELPERS = {
4
+ POLARIS_HELPERS = {
5
5
  avatar: "Polaris::AvatarComponent",
6
6
  badge: "Polaris::BadgeComponent",
7
7
  banner: "Polaris::BannerComponent",
@@ -10,8 +10,11 @@ module Polaris
10
10
  callout_card: "Polaris::CalloutCardComponent",
11
11
  caption: "Polaris::CaptionComponent",
12
12
  card: "Polaris::CardComponent",
13
+ card_section: "Polaris::Card::SectionComponent",
13
14
  checkbox: "Polaris::CheckboxComponent",
15
+ check_box: "Polaris::CheckboxComponent",
14
16
  choice_list: "Polaris::ChoiceListComponent",
17
+ data_table: "Polaris::DataTableComponent",
15
18
  description_list: "Polaris::DescriptionListComponent",
16
19
  display_text: "Polaris::DisplayTextComponent",
17
20
  dropzone: "Polaris::Dropzone::Component",
@@ -19,8 +22,10 @@ module Polaris
19
22
  exception_list: "Polaris::ExceptionListComponent",
20
23
  footer_help: "Polaris::FooterHelpComponent",
21
24
  form_layout: "Polaris::FormLayoutComponent",
25
+ filters: "Polaris::FiltersComponent",
22
26
  heading: "Polaris::HeadingComponent",
23
27
  icon: "Polaris::IconComponent",
28
+ index_table: "Polaris::IndexTableComponent",
24
29
  inline_error: "Polaris::InlineErrorComponent",
25
30
  layout: "Polaris::LayoutComponent",
26
31
  link: "Polaris::LinkComponent",
@@ -38,6 +43,7 @@ module Polaris
38
43
  subheading: "Polaris::SubheadingComponent",
39
44
  spinner: "Polaris::SpinnerComponent",
40
45
  skeleton_body_text: "Polaris::SkeletonBodyTextComponent",
46
+ spacer: "Polaris::SpacerComponent",
41
47
  tag: "Polaris::TagComponent",
42
48
  text_container: "Polaris::TextContainerComponent",
43
49
  text_field: "Polaris::TextFieldComponent",
@@ -45,13 +51,19 @@ module Polaris
45
51
  thumbnail: "Polaris::ThumbnailComponent",
46
52
  visually_hidden: "Polaris::VisuallyHiddenComponent",
47
53
  }.freeze
48
-
49
- HELPERS.each do |name, component|
54
+ POLARIS_HELPERS.each do |name, component|
50
55
  define_method "polaris_#{name}" do |*args, **kwargs, &block|
51
56
  render component.constantize.new(*args, **kwargs), &block
52
57
  end
53
58
  end
54
59
 
60
+ POLARIS_TEXT_STYLES = %i[subdued strong positive negative code].freeze
61
+ POLARIS_TEXT_STYLES.each do |name|
62
+ define_method "polaris_text_#{name}" do |**kwargs, &block|
63
+ polaris_text_style(variation: name, **kwargs, &block)
64
+ end
65
+ end
66
+
55
67
  def polaris_icon_source(name)
56
68
  path = ViewComponents::Engine.root.join("app", "assets", "icons", "polaris", "#{name}.svg")
57
69
  file = File.read(path)
@@ -23,7 +23,6 @@ module Polaris
23
23
  ActiveSupport.on_load(:action_controller_base) do
24
24
  helper Polaris::ViewHelper
25
25
  helper Polaris::UrlHelper
26
- helper Polaris::ActionHelper
27
26
  helper Polaris::ConditionalHelper
28
27
  end
29
28
  end
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "0.3.1"
3
+ VERSION = "0.5.0"
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.3.1
4
+ version: 0.5.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: 2021-10-06 00:00:00.000000000 Z
12
+ date: 2021-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -448,9 +448,15 @@ files:
448
448
  - app/assets/icons/polaris/WholesaleMajor.svg
449
449
  - app/assets/icons/polaris/WifiMajor.svg
450
450
  - app/assets/javascripts/polaris_view_components.js
451
- - app/assets/stylesheets/polaris@6.6.0.css
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
452
455
  - app/assets/stylesheets/polaris_view_components.css
453
- - app/assets/stylesheets/shopify_navigation.css
456
+ - app/assets/stylesheets/polaris_view_components.postcss.css
457
+ - app/assets/stylesheets/polaris_view_components/custom.css
458
+ - app/assets/stylesheets/polaris_view_components/shopify_navigation.css
459
+ - app/assets/stylesheets/polaris_view_components/spacer_component.css
454
460
  - app/components/polaris/action.rb
455
461
  - app/components/polaris/application_component.rb
456
462
  - app/components/polaris/avatar_component.html.erb
@@ -479,11 +485,14 @@ files:
479
485
  - app/components/polaris/checkbox_component.rb
480
486
  - app/components/polaris/choice_component.html.erb
481
487
  - app/components/polaris/choice_component.rb
482
- - app/components/polaris/choice_list/component.html.erb
483
- - app/components/polaris/choice_list/component.rb
484
488
  - app/components/polaris/choice_list_component.html.erb
485
489
  - app/components/polaris/choice_list_component.rb
486
490
  - app/components/polaris/component.rb
491
+ - app/components/polaris/data_table/cell_component.html.erb
492
+ - app/components/polaris/data_table/cell_component.rb
493
+ - app/components/polaris/data_table/column_component.rb
494
+ - app/components/polaris/data_table_component.html.erb
495
+ - app/components/polaris/data_table_component.rb
487
496
  - app/components/polaris/description_list_component.html.erb
488
497
  - app/components/polaris/description_list_component.rb
489
498
  - app/components/polaris/display_text_component.rb
@@ -497,6 +506,8 @@ files:
497
506
  - app/components/polaris/exception_list/item_component.rb
498
507
  - app/components/polaris/exception_list_component.html.erb
499
508
  - app/components/polaris/exception_list_component.rb
509
+ - app/components/polaris/filters_component.html.erb
510
+ - app/components/polaris/filters_component.rb
500
511
  - app/components/polaris/footer_help_component.html.erb
501
512
  - app/components/polaris/footer_help_component.rb
502
513
  - app/components/polaris/form_layout/group_component.html.erb
@@ -509,6 +520,10 @@ files:
509
520
  - app/components/polaris/headless_button.rb
510
521
  - app/components/polaris/icon_component.html.erb
511
522
  - app/components/polaris/icon_component.rb
523
+ - app/components/polaris/index_table/cell_component.rb
524
+ - app/components/polaris/index_table/column_component.rb
525
+ - app/components/polaris/index_table_component.html.erb
526
+ - app/components/polaris/index_table_component.rb
512
527
  - app/components/polaris/inline_error_component.html.erb
513
528
  - app/components/polaris/inline_error_component.rb
514
529
  - app/components/polaris/label_component.html.erb
@@ -536,6 +551,7 @@ files:
536
551
  - app/components/polaris/radio_button_component.rb
537
552
  - app/components/polaris/resource_item_component.html.erb
538
553
  - app/components/polaris/resource_item_component.rb
554
+ - app/components/polaris/resource_list_component.html.erb
539
555
  - app/components/polaris/resource_list_component.rb
540
556
  - app/components/polaris/select_component.html.erb
541
557
  - app/components/polaris/select_component.rb
@@ -543,6 +559,7 @@ files:
543
559
  - app/components/polaris/shopify_navigation_component.rb
544
560
  - app/components/polaris/skeleton_body_text_component.html.erb
545
561
  - app/components/polaris/skeleton_body_text_component.rb
562
+ - app/components/polaris/spacer_component.rb
546
563
  - app/components/polaris/spinner_component.html.erb
547
564
  - app/components/polaris/spinner_component.rb
548
565
  - app/components/polaris/stack_component.html.erb
@@ -557,7 +574,6 @@ files:
557
574
  - app/components/polaris/thumbnail_component.html.erb
558
575
  - app/components/polaris/thumbnail_component.rb
559
576
  - app/components/polaris/visually_hidden_component.rb
560
- - app/helpers/polaris/action_helper.rb
561
577
  - app/helpers/polaris/class_name_helper.rb
562
578
  - app/helpers/polaris/conditional_helper.rb
563
579
  - app/helpers/polaris/fetch_or_fallback_helper.rb
@@ -565,10 +581,6 @@ files:
565
581
  - app/helpers/polaris/option_helper.rb
566
582
  - app/helpers/polaris/url_helper.rb
567
583
  - app/helpers/polaris/view_helper.rb
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
572
584
  - app/validators/type_validator.rb
573
585
  - lib/generators/polaris_view_components/USAGE
574
586
  - lib/generators/polaris_view_components/install_generator.rb