polaris_view_components 0.3.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/polaris_view_components/button_controller.js +48 -0
  4. data/app/assets/javascripts/polaris_view_components/index.js +11 -1
  5. data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
  6. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +24 -0
  7. data/app/assets/javascripts/polaris_view_components/popover_controller.js +45 -0
  8. data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
  9. data/app/assets/javascripts/polaris_view_components/select_controller.js +6 -4
  10. data/app/assets/javascripts/polaris_view_components.js +1539 -5
  11. data/app/assets/stylesheets/polaris_view_components/custom.css +68 -0
  12. data/app/assets/stylesheets/polaris_view_components/shopify_navigation.css +0 -4
  13. data/app/assets/stylesheets/polaris_view_components/spacer_component.css +39 -0
  14. data/app/assets/stylesheets/polaris_view_components.css +93 -3
  15. data/app/assets/stylesheets/polaris_view_components.postcss.css +2 -0
  16. data/app/components/polaris/action.rb +3 -3
  17. data/app/components/polaris/action_list/item_component.html.erb +35 -0
  18. data/app/components/polaris/action_list/item_component.rb +41 -0
  19. data/app/components/polaris/action_list/section_component.html.erb +16 -0
  20. data/app/components/polaris/action_list/section_component.rb +26 -0
  21. data/app/components/polaris/action_list_component.html.erb +13 -0
  22. data/app/components/polaris/action_list_component.rb +25 -0
  23. data/app/components/polaris/application_component.rb +19 -19
  24. data/app/components/polaris/avatar_component.rb +1 -1
  25. data/app/components/polaris/badge_component.rb +1 -1
  26. data/app/components/polaris/banner_component.rb +6 -6
  27. data/app/components/polaris/base_button.rb +1 -1
  28. data/app/components/polaris/button_component.html.erb +13 -0
  29. data/app/components/polaris/button_group_component.rb +5 -5
  30. data/app/components/polaris/callout_card_component.rb +5 -5
  31. data/app/components/polaris/caption_component.rb +2 -2
  32. data/app/components/polaris/card/header_component.rb +1 -3
  33. data/app/components/polaris/card/section_component.rb +6 -2
  34. data/app/components/polaris/card_component.html.erb +4 -0
  35. data/app/components/polaris/card_component.rb +5 -6
  36. data/app/components/polaris/character_count.rb +10 -10
  37. data/app/components/polaris/checkbox_component.rb +4 -4
  38. data/app/components/polaris/choice_component.rb +1 -1
  39. data/app/components/polaris/choice_list_component.rb +4 -4
  40. data/app/components/polaris/data_table/cell_component.html.erb +18 -0
  41. data/app/components/polaris/data_table/cell_component.rb +49 -0
  42. data/app/components/polaris/data_table/column_component.rb +19 -0
  43. data/app/components/polaris/data_table_component.html.erb +77 -0
  44. data/app/components/polaris/data_table_component.rb +42 -0
  45. data/app/components/polaris/description_list_component.rb +3 -3
  46. data/app/components/polaris/display_text_component.rb +2 -2
  47. data/app/components/polaris/dropzone/component.rb +36 -38
  48. data/app/components/polaris/empty_state_component.html.erb +16 -11
  49. data/app/components/polaris/empty_state_component.rb +4 -3
  50. data/app/components/polaris/exception_list/item_component.rb +2 -2
  51. data/app/components/polaris/exception_list_component.rb +1 -1
  52. data/app/components/polaris/filters_component.html.erb +13 -0
  53. data/app/components/polaris/filters_component.rb +38 -0
  54. data/app/components/polaris/footer_help_component.rb +1 -1
  55. data/app/components/polaris/form_layout/group_component.rb +3 -3
  56. data/app/components/polaris/form_layout/item_component.rb +1 -1
  57. data/app/components/polaris/form_layout_component.rb +3 -3
  58. data/app/components/polaris/heading_component.rb +1 -1
  59. data/app/components/polaris/headless_button.html.erb +13 -0
  60. data/app/components/polaris/headless_button.rb +17 -5
  61. data/app/components/polaris/icon_component.rb +2 -2
  62. data/app/components/polaris/index_table/cell_component.rb +22 -0
  63. data/app/components/polaris/index_table/column_component.rb +13 -0
  64. data/app/components/polaris/index_table_component.html.erb +28 -0
  65. data/app/components/polaris/index_table_component.rb +25 -0
  66. data/app/components/polaris/inline_error_component.html.erb +2 -2
  67. data/app/components/polaris/inline_error_component.rb +7 -1
  68. data/app/components/polaris/label_component.rb +2 -2
  69. data/app/components/polaris/labelled_component.rb +2 -2
  70. data/app/components/polaris/layout/annotated_section.rb +1 -1
  71. data/app/components/polaris/layout/section.rb +2 -0
  72. data/app/components/polaris/layout_component.rb +3 -3
  73. data/app/components/polaris/link_component.rb +5 -3
  74. data/app/components/polaris/list_component.rb +3 -3
  75. data/app/components/polaris/modal/section_component.rb +19 -0
  76. data/app/components/polaris/modal_component.html.erb +79 -0
  77. data/app/components/polaris/modal_component.rb +98 -0
  78. data/app/components/polaris/page_actions_component.rb +21 -6
  79. data/app/components/polaris/page_component.rb +4 -4
  80. data/app/components/polaris/pagination_component.rb +1 -5
  81. data/app/components/polaris/popover/pane_component.html.erb +25 -0
  82. data/app/components/polaris/popover/pane_component.rb +20 -0
  83. data/app/components/polaris/popover/section_component.rb +19 -0
  84. data/app/components/polaris/popover_component.html.erb +38 -0
  85. data/app/components/polaris/popover_component.rb +90 -0
  86. data/app/components/polaris/progress_bar_component.rb +5 -5
  87. data/app/components/polaris/radio_button_component.rb +3 -3
  88. data/app/components/polaris/resource_item_component.html.erb +16 -6
  89. data/app/components/polaris/resource_item_component.rb +42 -9
  90. data/app/components/polaris/resource_list_component.html.erb +10 -0
  91. data/app/components/polaris/resource_list_component.rb +4 -10
  92. data/app/components/polaris/scrollable_component.html.erb +5 -0
  93. data/app/components/polaris/scrollable_component.rb +48 -0
  94. data/app/components/polaris/select_component.rb +10 -5
  95. data/app/components/polaris/setting_toggle_component.html.erb +10 -0
  96. data/app/components/polaris/setting_toggle_component.rb +24 -0
  97. data/app/components/polaris/shopify_navigation_component.rb +6 -6
  98. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  99. data/app/components/polaris/spacer_component.rb +50 -0
  100. data/app/components/polaris/spinner_component.rb +2 -2
  101. data/app/components/polaris/stack_component.rb +5 -5
  102. data/app/components/polaris/subheading_component.rb +1 -1
  103. data/app/components/polaris/tabs/tab_component.html.erb +10 -0
  104. data/app/components/polaris/tabs/tab_component.rb +34 -0
  105. data/app/components/polaris/tabs_component.html.erb +7 -0
  106. data/app/components/polaris/tabs_component.rb +37 -0
  107. data/app/components/polaris/tag_component.rb +2 -2
  108. data/app/components/polaris/text_container_component.rb +2 -2
  109. data/app/components/polaris/text_field_component.rb +8 -8
  110. data/app/components/polaris/text_style_component.rb +11 -2
  111. data/app/components/polaris/thumbnail_component.rb +2 -2
  112. data/app/helpers/polaris/form_builder.rb +30 -3
  113. data/app/helpers/polaris/url_helper.rb +3 -3
  114. data/app/helpers/polaris/view_helper.rb +26 -6
  115. data/app/validators/type_validator.rb +2 -2
  116. data/lib/generators/polaris_view_components/install_generator.rb +5 -5
  117. data/lib/polaris/view_components/engine.rb +6 -1
  118. data/lib/polaris/view_components/version.rb +1 -1
  119. data/lib/polaris_view_components.rb +1 -1
  120. metadata +45 -6
  121. data/app/components/polaris/choice_list/component.html.erb +0 -34
  122. data/app/components/polaris/choice_list/component.rb +0 -65
  123. data/app/helpers/polaris/action_helper.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf2cc17a4b9d919cd1855c419b2543cdd2ce8461deccf6077dfa42e1319cb775
4
- data.tar.gz: d0e85ab7f44695d32ceff2bf8b73843dbf887844ce4b0e2370151f79622c919f
3
+ metadata.gz: 3ba771806fadd6b419c7ab4ca160d21199a4634e34c1c6382aeeac8d1908d728
4
+ data.tar.gz: 65a6782283ea638ed596e0f75e6125feb2efff9dbdd0169428bbcdb522797ebf
5
5
  SHA512:
6
- metadata.gz: d20d75ce88498c2c49bf978768aa8dd17c761924d59f5e68d6a80257b2de1e0675b03c443e11d48f37fada7999ec8d6129395d33cf29620ef9cac741b99ce200
7
- data.tar.gz: e5d313afc34de67c9d61b207a45c6138925ca5f33303d750b021fc880c7de4c9b2d418d606a4f105d05848ff72490076de8cc5affd28476dbec61c3c1f119d72
6
+ metadata.gz: d77337905ac8bfc591a5957546de20b5ff89478d2dca37be41eeddfc1e8053e9623ba452d96c6b8198e0ab185d58b416553319db14d44ad74f30532664c5c4d2
7
+ data.tar.gz: 7c69e38fc42ebf27c6f121c9a741b21414c026210e27187aa55cfecc11a7f9cdd60ce511a954e4e2fd94a34b71519104de80c217cff952fe0ce5f802bbf1dfc0
data/README.md CHANGED
@@ -85,7 +85,7 @@ In addition to the dependencies declared in the `gemspec`, Polaris ViewComponent
85
85
  To get started:
86
86
 
87
87
  1. Run: `bundle install`
88
- 2. Run: `foreman start`
88
+ 2. Run: `bin/dev`
89
89
 
90
90
  It will open demo app with component previews on `localhost:4000`. You can change components and they will be updated on page reload. Component previews located in `demo/test/components/previews`.
91
91
 
@@ -0,0 +1,48 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ disable(event) {
5
+ if (this.button.dataset.disabled) {
6
+ event.preventDefault()
7
+ } else {
8
+ this.button.dataset.disabled = true
9
+ this.button.classList.add("Polaris-Button--disabled", "Polaris-Button--loading")
10
+ this.buttonContent.insertAdjacentHTML("afterbegin", this.spinnerHTML)
11
+ }
12
+ }
13
+
14
+ enable() {
15
+ if (this.button.dataset.disabled) {
16
+ this.button.disabled = false
17
+ delete this.button.dataset.disabled
18
+ this.button.classList.remove("Polaris-Button--disabled", "Polaris-Button--loading")
19
+ this.spinner.remove()
20
+ }
21
+ }
22
+
23
+ // Private
24
+
25
+ get button() {
26
+ return this.element
27
+ }
28
+
29
+ get buttonContent() {
30
+ return this.button.querySelector(".Polaris-Button__Content")
31
+ }
32
+
33
+ get spinner() {
34
+ return this.button.querySelector(".Polaris-Button__Spinner")
35
+ }
36
+
37
+ get spinnerHTML() {
38
+ return `
39
+ <span class="Polaris-Button__Spinner">
40
+ <span class="Polaris-Spinner Polaris-Spinner--sizeSmall">
41
+ <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
42
+ <path d="M7.229 1.173a9.25 9.25 0 1011.655 11.412 1.25 1.25 0 10-2.4-.698 6.75 6.75 0 11-8.506-8.329 1.25 1.25 0 10-.75-2.385z"></path>
43
+ </svg>
44
+ </span>
45
+ </span>
46
+ `
47
+ }
48
+ }
@@ -1,11 +1,21 @@
1
+ import Button from './button_controller'
2
+ import Modal from './modal_controller'
3
+ import Polaris from './polaris_controller'
4
+ import Popover from './popover_controller'
1
5
  import ResourceItem from './resource_item_controller'
6
+ import Scrollable from './scrollable_controller'
2
7
  import Select from './select_controller'
3
8
  import TextField from './text_field_controller'
4
9
 
5
- export { ResourceItem, Select, TextField }
10
+ export { Modal, Polaris, Popover, ResourceItem, Scrollable, Select, TextField }
6
11
 
7
12
  export function registerPolarisControllers(application) {
13
+ application.register('polaris-button', Button)
14
+ application.register('polaris-modal', Modal)
15
+ application.register('polaris', Polaris)
16
+ application.register('polaris-popover', Popover)
8
17
  application.register('polaris-resource-item', ResourceItem)
18
+ application.register('polaris-scrollable', Scrollable)
9
19
  application.register('polaris-select', Select)
10
20
  application.register('polaris-text-field', TextField)
11
21
  }
@@ -0,0 +1,25 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static classes = ["hidden", "backdrop"]
5
+ static values = {
6
+ open: Boolean
7
+ }
8
+
9
+ connect() {
10
+ if (this.openValue) {
11
+ this.open()
12
+ }
13
+ }
14
+
15
+ open() {
16
+ this.element.classList.remove(this.hiddenClass)
17
+ this.element.insertAdjacentHTML('afterend', `<div class="${this.backdropClass}"></div>`)
18
+ this.backdrop = this.element.nextElementSibling
19
+ }
20
+
21
+ close() {
22
+ this.element.classList.add(this.hiddenClass)
23
+ this.backdrop.remove()
24
+ }
25
+ }
@@ -0,0 +1,24 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ openModal() {
5
+ this.findElement("modal").open()
6
+ }
7
+
8
+ disableButton() {
9
+ this.findElement("button").disable()
10
+ }
11
+
12
+ enableButton() {
13
+ this.findElement("button").enable()
14
+ }
15
+
16
+ // Private
17
+
18
+ findElement(type) {
19
+ const targetId = this.element.dataset.target.replace("#", "")
20
+ const target = document.getElementById(targetId)
21
+ const controllerName = `polaris-${type}`
22
+ return this.application.getControllerForElementAndIdentifier(target, controllerName)
23
+ }
24
+ }
@@ -0,0 +1,45 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { createPopper } from "@popperjs/core/dist/esm"
3
+
4
+ export default class extends Controller {
5
+ static targets = ["activator", "popover"]
6
+ static classes = ["open", "closed"]
7
+ static values = {
8
+ placement: String,
9
+ active: Boolean
10
+ }
11
+
12
+ connect() {
13
+ createPopper(this.activatorTarget, this.popoverTarget, {
14
+ placement: this.placementValue,
15
+ modifiers: [
16
+ {
17
+ name: 'offset',
18
+ options: {
19
+ offset: [0, 5],
20
+ },
21
+ },
22
+ ]
23
+ })
24
+ if (this.activeValue) {
25
+ this.show()
26
+ }
27
+ }
28
+
29
+ toggle() {
30
+ this.popoverTarget.classList.toggle(this.closedClass)
31
+ this.popoverTarget.classList.toggle(this.openClass)
32
+ }
33
+
34
+ show() {
35
+ this.popoverTarget.classList.remove(this.closedClass)
36
+ this.popoverTarget.classList.add(this.openClass)
37
+ }
38
+
39
+ hide(event) {
40
+ if (!this.element.contains(event.target) && !this.popoverTarget.classList.contains(this.closedClass)) {
41
+ this.popoverTarget.classList.remove(this.openClass)
42
+ this.popoverTarget.classList.add(this.closedClass)
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,60 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ["topEdge", "bottomEdge"]
5
+ static classes = ["topShadow", "bottomShadow"]
6
+ static values = {
7
+ shadow: Boolean,
8
+ }
9
+
10
+ initialize() {
11
+ this.topEdgeReached = false
12
+ this.bottomEdgeReached = true
13
+ }
14
+
15
+ connect() {
16
+ if (this.shadowValue) {
17
+ this.observer = new IntersectionObserver(this.handleIntersection)
18
+ this.observer.observe(this.topEdgeTarget)
19
+ this.observer.observe(this.bottomEdgeTarget)
20
+ }
21
+ }
22
+
23
+ disconnect() {
24
+ if (this.shadowValue) {
25
+ this.observer.disconnect()
26
+ }
27
+ }
28
+
29
+ // Private
30
+
31
+ handleIntersection = (entries) => {
32
+ entries.forEach(entry => {
33
+ const target = entry.target.dataset.polarisScrollableTarget
34
+
35
+ switch (target) {
36
+ case "topEdge":
37
+ this.topEdgeReached = entry.isIntersecting
38
+ break
39
+ case "bottomEdge":
40
+ this.bottomEdgeReached = entry.isIntersecting
41
+ break
42
+ }
43
+ })
44
+ this.updateShadows()
45
+ }
46
+
47
+ updateShadows() {
48
+ if (!this.topEdgeReached && !this.bottomEdgeReached) {
49
+ this.element.classList.add(this.topShadowClass, this.bottomShadowClass)
50
+ } else if (this.topEdgeReached && this.bottomEdgeReached) {
51
+ this.element.classList.remove(this.topShadowClass, this.bottomShadowClass)
52
+ } else if (this.topEdgeReached) {
53
+ this.element.classList.remove(this.topShadowClass)
54
+ this.element.classList.add(this.bottomShadowClass)
55
+ } else if (this.bottomEdgeReached) {
56
+ this.element.classList.add(this.topShadowClass)
57
+ this.element.classList.remove(this.bottomShadowClass)
58
+ }
59
+ }
60
+ }
@@ -1,12 +1,14 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
- static targets = ['selectedOption']
4
+ static targets = ["select", "selectedOption"]
5
5
 
6
- update(event) {
7
- const select = event.currentTarget
8
- const option = select.options[select.selectedIndex]
6
+ connect() {
7
+ this.update()
8
+ }
9
9
 
10
+ update() {
11
+ const option = this.selectTarget.options[this.selectTarget.selectedIndex]
10
12
  this.selectedOptionTarget.innerText = option.text
11
13
  }
12
14
  }