polaris_view_components 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/polaris_view_components/button_controller.js +48 -0
  3. data/app/assets/javascripts/polaris_view_components/index.js +11 -1
  4. data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
  5. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +24 -0
  6. data/app/assets/javascripts/polaris_view_components/popover_controller.js +45 -0
  7. data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
  8. data/app/assets/javascripts/polaris_view_components.js +1533 -1
  9. data/app/assets/stylesheets/polaris_view_components/custom.css +26 -1
  10. data/app/assets/stylesheets/polaris_view_components.css +21 -1
  11. data/app/components/polaris/action.rb +3 -3
  12. data/app/components/polaris/action_list/item_component.html.erb +35 -0
  13. data/app/components/polaris/action_list/item_component.rb +41 -0
  14. data/app/components/polaris/action_list/section_component.html.erb +16 -0
  15. data/app/components/polaris/action_list/section_component.rb +26 -0
  16. data/app/components/polaris/action_list_component.html.erb +13 -0
  17. data/app/components/polaris/action_list_component.rb +25 -0
  18. data/app/components/polaris/application_component.rb +19 -19
  19. data/app/components/polaris/avatar_component.rb +1 -1
  20. data/app/components/polaris/badge_component.rb +1 -1
  21. data/app/components/polaris/banner_component.rb +6 -6
  22. data/app/components/polaris/base_button.rb +1 -1
  23. data/app/components/polaris/button_component.html.erb +13 -0
  24. data/app/components/polaris/button_group_component.rb +5 -5
  25. data/app/components/polaris/callout_card_component.rb +5 -5
  26. data/app/components/polaris/caption_component.rb +2 -2
  27. data/app/components/polaris/card/header_component.rb +1 -1
  28. data/app/components/polaris/card/section_component.rb +2 -2
  29. data/app/components/polaris/card_component.html.erb +4 -0
  30. data/app/components/polaris/card_component.rb +5 -4
  31. data/app/components/polaris/character_count.rb +10 -10
  32. data/app/components/polaris/checkbox_component.rb +4 -4
  33. data/app/components/polaris/choice_component.rb +1 -1
  34. data/app/components/polaris/choice_list_component.rb +4 -4
  35. data/app/components/polaris/data_table/cell_component.rb +3 -3
  36. data/app/components/polaris/data_table_component.rb +3 -3
  37. data/app/components/polaris/description_list_component.rb +3 -3
  38. data/app/components/polaris/display_text_component.rb +2 -2
  39. data/app/components/polaris/dropzone/component.rb +36 -36
  40. data/app/components/polaris/empty_state_component.rb +3 -3
  41. data/app/components/polaris/exception_list/item_component.rb +2 -2
  42. data/app/components/polaris/exception_list_component.rb +1 -1
  43. data/app/components/polaris/filters_component.rb +2 -2
  44. data/app/components/polaris/footer_help_component.rb +1 -1
  45. data/app/components/polaris/form_layout/group_component.rb +3 -3
  46. data/app/components/polaris/form_layout/item_component.rb +1 -1
  47. data/app/components/polaris/form_layout_component.rb +3 -3
  48. data/app/components/polaris/heading_component.rb +1 -1
  49. data/app/components/polaris/headless_button.html.erb +13 -0
  50. data/app/components/polaris/headless_button.rb +17 -5
  51. data/app/components/polaris/icon_component.rb +2 -2
  52. data/app/components/polaris/index_table/cell_component.rb +2 -2
  53. data/app/components/polaris/index_table_component.rb +3 -3
  54. data/app/components/polaris/inline_error_component.rb +1 -1
  55. data/app/components/polaris/label_component.rb +2 -2
  56. data/app/components/polaris/labelled_component.rb +2 -2
  57. data/app/components/polaris/layout/annotated_section.rb +1 -1
  58. data/app/components/polaris/layout/section.rb +1 -1
  59. data/app/components/polaris/layout_component.rb +3 -3
  60. data/app/components/polaris/link_component.rb +3 -3
  61. data/app/components/polaris/list_component.rb +3 -3
  62. data/app/components/polaris/modal/section_component.rb +19 -0
  63. data/app/components/polaris/modal_component.html.erb +79 -0
  64. data/app/components/polaris/modal_component.rb +98 -0
  65. data/app/components/polaris/page_actions_component.rb +8 -7
  66. data/app/components/polaris/page_component.rb +4 -4
  67. data/app/components/polaris/pagination_component.rb +1 -5
  68. data/app/components/polaris/popover/pane_component.html.erb +25 -0
  69. data/app/components/polaris/popover/pane_component.rb +20 -0
  70. data/app/components/polaris/popover/section_component.rb +19 -0
  71. data/app/components/polaris/popover_component.html.erb +38 -0
  72. data/app/components/polaris/popover_component.rb +90 -0
  73. data/app/components/polaris/progress_bar_component.rb +5 -5
  74. data/app/components/polaris/radio_button_component.rb +3 -3
  75. data/app/components/polaris/resource_item_component.html.erb +16 -6
  76. data/app/components/polaris/resource_item_component.rb +42 -9
  77. data/app/components/polaris/resource_list_component.rb +2 -2
  78. data/app/components/polaris/scrollable_component.html.erb +5 -0
  79. data/app/components/polaris/scrollable_component.rb +48 -0
  80. data/app/components/polaris/select_component.rb +3 -3
  81. data/app/components/polaris/setting_toggle_component.html.erb +10 -0
  82. data/app/components/polaris/setting_toggle_component.rb +24 -0
  83. data/app/components/polaris/shopify_navigation_component.rb +6 -6
  84. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  85. data/app/components/polaris/spacer_component.rb +3 -3
  86. data/app/components/polaris/spinner_component.rb +2 -2
  87. data/app/components/polaris/stack_component.rb +5 -5
  88. data/app/components/polaris/subheading_component.rb +1 -1
  89. data/app/components/polaris/tabs/tab_component.html.erb +10 -0
  90. data/app/components/polaris/tabs/tab_component.rb +34 -0
  91. data/app/components/polaris/tabs_component.html.erb +7 -0
  92. data/app/components/polaris/tabs_component.rb +37 -0
  93. data/app/components/polaris/tag_component.rb +1 -1
  94. data/app/components/polaris/text_container_component.rb +2 -2
  95. data/app/components/polaris/text_field_component.rb +8 -8
  96. data/app/components/polaris/text_style_component.rb +4 -4
  97. data/app/components/polaris/thumbnail_component.rb +2 -2
  98. data/app/helpers/polaris/form_builder.rb +4 -2
  99. data/app/helpers/polaris/url_helper.rb +3 -3
  100. data/app/helpers/polaris/view_helper.rb +11 -3
  101. data/app/validators/type_validator.rb +2 -2
  102. data/lib/generators/polaris_view_components/install_generator.rb +5 -5
  103. data/lib/polaris/view_components/engine.rb +6 -0
  104. data/lib/polaris/view_components/version.rb +1 -1
  105. data/lib/polaris_view_components.rb +1 -1
  106. metadata +30 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4ecf6c373c0c3a1188d677df7da49034a9094392ce74b0bac9e72780b1a851a
4
- data.tar.gz: 836ebef4a9e97c359d4bf36e4ae497d673a6579de232c0a82f6cf12d4f33e3d9
3
+ metadata.gz: 3ba771806fadd6b419c7ab4ca160d21199a4634e34c1c6382aeeac8d1908d728
4
+ data.tar.gz: 65a6782283ea638ed596e0f75e6125feb2efff9dbdd0169428bbcdb522797ebf
5
5
  SHA512:
6
- metadata.gz: add02e909f36a997d49d261b3960ad41636001dbb4a6beea5f1652a7bfadab94d9bb2e07cefc5618f652bbdd431934ceb11da59388d0523d75686bbdddc7723e
7
- data.tar.gz: cdd86e17c2a970aae8e5fec22cb296eae4cd1df572dee371978d0b02450cf6185c30c5a891db0943b62f1f114b593a2a3e890840362c1c1efc9da6087c663dd7
6
+ metadata.gz: d77337905ac8bfc591a5957546de20b5ff89478d2dca37be41eeddfc1e8053e9623ba452d96c6b8198e0ab185d58b416553319db14d44ad74f30532664c5c4d2
7
+ data.tar.gz: 7c69e38fc42ebf27c6f121c9a741b21414c026210e27187aa55cfecc11a7f9cdd60ce511a954e4e2fd94a34b71519104de80c217cff952fe0ce5f802bbf1dfc0
@@ -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
+ }