polaris_view_components 0.3.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -3
  3. data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +119 -0
  4. data/app/assets/javascripts/polaris_view_components/button_controller.js +47 -0
  5. data/app/assets/javascripts/polaris_view_components/frame_controller.js +41 -0
  6. data/app/assets/javascripts/polaris_view_components/index.js +19 -1
  7. data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
  8. data/app/assets/javascripts/polaris_view_components/option_list_controller.js +41 -0
  9. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +28 -0
  10. data/app/assets/javascripts/polaris_view_components/popover_controller.js +49 -0
  11. data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
  12. data/app/assets/javascripts/polaris_view_components/select_controller.js +6 -4
  13. data/app/assets/javascripts/polaris_view_components/text_field_controller.js +4 -0
  14. data/app/assets/javascripts/polaris_view_components/toast_controller.js +68 -0
  15. data/app/assets/javascripts/polaris_view_components.js +1936 -5
  16. data/app/assets/stylesheets/polaris_view_components/custom.css +109 -0
  17. data/app/assets/stylesheets/polaris_view_components/shopify_navigation.css +0 -4
  18. data/app/assets/stylesheets/polaris_view_components/spacer_component.css +39 -0
  19. data/app/assets/stylesheets/polaris_view_components.css +118 -3
  20. data/app/assets/stylesheets/polaris_view_components.postcss.css +2 -0
  21. data/app/components/polaris/action.rb +3 -3
  22. data/app/components/polaris/action_list/item_component.html.erb +35 -0
  23. data/app/components/polaris/action_list/item_component.rb +41 -0
  24. data/app/components/polaris/action_list/section_component.html.erb +16 -0
  25. data/app/components/polaris/action_list/section_component.rb +26 -0
  26. data/app/components/polaris/action_list_component.html.erb +13 -0
  27. data/app/components/polaris/action_list_component.rb +25 -0
  28. data/app/components/polaris/application_component.rb +19 -19
  29. data/app/components/polaris/autocomplete/action_component.rb +7 -0
  30. data/app/components/polaris/autocomplete/option_component.rb +35 -0
  31. data/app/components/polaris/autocomplete/section_component.html.erb +9 -0
  32. data/app/components/polaris/autocomplete/section_component.rb +12 -0
  33. data/app/components/polaris/autocomplete_component.html.erb +30 -0
  34. data/app/components/polaris/autocomplete_component.rb +58 -0
  35. data/app/components/polaris/avatar_component.rb +1 -1
  36. data/app/components/polaris/badge_component.rb +1 -1
  37. data/app/components/polaris/banner_component.rb +6 -6
  38. data/app/components/polaris/base_button.rb +1 -1
  39. data/app/components/polaris/base_checkbox.rb +48 -0
  40. data/app/components/polaris/base_radio_button.rb +38 -0
  41. data/app/components/polaris/button_component.html.erb +13 -0
  42. data/app/components/polaris/button_group_component.rb +5 -5
  43. data/app/components/polaris/callout_card_component.rb +5 -5
  44. data/app/components/polaris/caption_component.rb +2 -2
  45. data/app/components/polaris/card/header_component.rb +1 -3
  46. data/app/components/polaris/card/section_component.rb +6 -2
  47. data/app/components/polaris/card_component.html.erb +4 -0
  48. data/app/components/polaris/card_component.rb +5 -6
  49. data/app/components/polaris/character_count.rb +10 -10
  50. data/app/components/polaris/checkbox_component.html.erb +1 -5
  51. data/app/components/polaris/checkbox_component.rb +19 -12
  52. data/app/components/polaris/choice_component.rb +1 -1
  53. data/app/components/polaris/choice_list_component.rb +5 -5
  54. data/app/components/polaris/data_table/cell_component.html.erb +18 -0
  55. data/app/components/polaris/data_table/cell_component.rb +49 -0
  56. data/app/components/polaris/data_table/column_component.rb +19 -0
  57. data/app/components/polaris/data_table_component.html.erb +77 -0
  58. data/app/components/polaris/data_table_component.rb +42 -0
  59. data/app/components/polaris/description_list_component.rb +3 -3
  60. data/app/components/polaris/display_text_component.rb +2 -2
  61. data/app/components/polaris/dropzone/component.rb +36 -38
  62. data/app/components/polaris/empty_state_component.html.erb +16 -11
  63. data/app/components/polaris/empty_state_component.rb +4 -3
  64. data/app/components/polaris/exception_list/item_component.rb +2 -2
  65. data/app/components/polaris/exception_list_component.rb +1 -1
  66. data/app/components/polaris/filters_component.html.erb +35 -0
  67. data/app/components/polaris/filters_component.rb +91 -0
  68. data/app/components/polaris/footer_help_component.rb +1 -1
  69. data/app/components/polaris/form_layout/group_component.rb +3 -3
  70. data/app/components/polaris/form_layout/item_component.rb +1 -1
  71. data/app/components/polaris/form_layout_component.rb +3 -3
  72. data/app/components/polaris/frame/save_bar_component.html.erb +23 -0
  73. data/app/components/polaris/frame/save_bar_component.rb +31 -0
  74. data/app/components/polaris/frame/top_bar_component.html.erb +30 -0
  75. data/app/components/polaris/frame/top_bar_component.rb +18 -0
  76. data/app/components/polaris/frame_component.html.erb +44 -0
  77. data/app/components/polaris/frame_component.rb +33 -0
  78. data/app/components/polaris/heading_component.rb +1 -1
  79. data/app/components/polaris/headless_button.html.erb +13 -0
  80. data/app/components/polaris/headless_button.rb +17 -5
  81. data/app/components/polaris/icon_component.rb +2 -2
  82. data/app/components/polaris/index_table/cell_component.rb +22 -0
  83. data/app/components/polaris/index_table/column_component.rb +13 -0
  84. data/app/components/polaris/index_table_component.html.erb +28 -0
  85. data/app/components/polaris/index_table_component.rb +25 -0
  86. data/app/components/polaris/inline_error_component.html.erb +2 -2
  87. data/app/components/polaris/inline_error_component.rb +7 -1
  88. data/app/components/polaris/label_component.rb +2 -2
  89. data/app/components/polaris/labelled_component.rb +2 -2
  90. data/app/components/polaris/layout/annotated_section.rb +1 -1
  91. data/app/components/polaris/layout/section.rb +2 -0
  92. data/app/components/polaris/layout_component.rb +3 -3
  93. data/app/components/polaris/link_component.rb +5 -3
  94. data/app/components/polaris/list_component.rb +3 -3
  95. data/app/components/polaris/logo.rb +13 -0
  96. data/app/components/polaris/modal/section_component.rb +19 -0
  97. data/app/components/polaris/modal_component.html.erb +79 -0
  98. data/app/components/polaris/modal_component.rb +98 -0
  99. data/app/components/polaris/navigation/item_component.html.erb +31 -0
  100. data/app/components/polaris/navigation/item_component.rb +85 -0
  101. data/app/components/polaris/navigation/section_component.html.erb +17 -0
  102. data/app/components/polaris/navigation/section_component.rb +64 -0
  103. data/app/components/polaris/navigation_component.html.erb +29 -0
  104. data/app/components/polaris/navigation_component.rb +15 -0
  105. data/app/components/polaris/option_list/checkbox_component.html.erb +14 -0
  106. data/app/components/polaris/option_list/checkbox_component.rb +37 -0
  107. data/app/components/polaris/option_list/option_component.rb +24 -0
  108. data/app/components/polaris/option_list/radio_button_component.rb +54 -0
  109. data/app/components/polaris/option_list/section_component.html.erb +14 -0
  110. data/app/components/polaris/option_list/section_component.rb +53 -0
  111. data/app/components/polaris/option_list_component.html.erb +15 -0
  112. data/app/components/polaris/option_list_component.rb +67 -0
  113. data/app/components/polaris/page_actions_component.rb +21 -6
  114. data/app/components/polaris/page_component.rb +4 -4
  115. data/app/components/polaris/pagination_component.rb +1 -5
  116. data/app/components/polaris/popover/pane_component.html.erb +25 -0
  117. data/app/components/polaris/popover/pane_component.rb +20 -0
  118. data/app/components/polaris/popover/section_component.rb +19 -0
  119. data/app/components/polaris/popover_component.html.erb +31 -0
  120. data/app/components/polaris/popover_component.rb +107 -0
  121. data/app/components/polaris/progress_bar_component.rb +5 -5
  122. data/app/components/polaris/radio_button_component.html.erb +1 -6
  123. data/app/components/polaris/radio_button_component.rb +17 -7
  124. data/app/components/polaris/resource_item_component.html.erb +16 -6
  125. data/app/components/polaris/resource_item_component.rb +42 -9
  126. data/app/components/polaris/resource_list_component.html.erb +10 -0
  127. data/app/components/polaris/resource_list_component.rb +4 -10
  128. data/app/components/polaris/scrollable_component.html.erb +5 -0
  129. data/app/components/polaris/scrollable_component.rb +48 -0
  130. data/app/components/polaris/select_component.rb +10 -5
  131. data/app/components/polaris/setting_toggle_component.html.erb +10 -0
  132. data/app/components/polaris/setting_toggle_component.rb +24 -0
  133. data/app/components/polaris/shopify_navigation_component.rb +6 -6
  134. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  135. data/app/components/polaris/spacer_component.rb +50 -0
  136. data/app/components/polaris/spinner_component.rb +2 -2
  137. data/app/components/polaris/stack_component.rb +5 -5
  138. data/app/components/polaris/subheading_component.rb +1 -1
  139. data/app/components/polaris/tabs/tab_component.html.erb +10 -0
  140. data/app/components/polaris/tabs/tab_component.rb +34 -0
  141. data/app/components/polaris/tabs_component.html.erb +7 -0
  142. data/app/components/polaris/tabs_component.rb +37 -0
  143. data/app/components/polaris/tag_component.rb +2 -2
  144. data/app/components/polaris/text_container_component.rb +2 -2
  145. data/app/components/polaris/text_field_component.rb +24 -10
  146. data/app/components/polaris/text_style_component.rb +11 -2
  147. data/app/components/polaris/thumbnail_component.rb +2 -2
  148. data/app/components/polaris/toast_component.html.erb +21 -0
  149. data/app/components/polaris/toast_component.rb +40 -0
  150. data/app/components/polaris/top_bar/user_menu_component.html.erb +19 -0
  151. data/app/components/polaris/top_bar/user_menu_component.rb +9 -0
  152. data/app/helpers/polaris/form_builder.rb +31 -4
  153. data/app/helpers/polaris/url_helper.rb +3 -3
  154. data/app/helpers/polaris/view_helper.rb +37 -6
  155. data/app/validators/type_validator.rb +2 -2
  156. data/lib/generators/polaris_view_components/install_generator.rb +5 -5
  157. data/lib/polaris/view_components/engine.rb +11 -2
  158. data/lib/polaris/view_components/version.rb +1 -1
  159. data/lib/polaris_view_components.rb +1 -1
  160. metadata +88 -12
  161. data/app/components/polaris/choice_list/component.html.erb +0 -34
  162. data/app/components/polaris/choice_list/component.rb +0 -65
  163. data/app/helpers/polaris/action_helper.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '03953b29a4439bfe7f6a8421b5db5a6627b50eea36bc62a4e07bf5aba1495811'
4
- data.tar.gz: 11e7d05ca4462d30c986e5f9e5134c82a6d7ca99ab9a1dba8626507b1a62173e
3
+ metadata.gz: b9e5671bf20a8c0aec20920be9fcea01ba39b902057eec479f30b9d621bdbf50
4
+ data.tar.gz: 21bb979fd293cd8379e0e012e9ef2ee9ae06cf62bfdd226fc1ae90ff3b65e9c3
5
5
  SHA512:
6
- metadata.gz: 61da6868d6d615a55c6edb7e8d3d55da80292bb9f91efb8a8dfb73287b6d1f6e67be05df1e0a06a3ea7656bf7120b1acca56a42ef22696f84ac463f721a90528
7
- data.tar.gz: ec345be1a960e3b9cbab5172dbcf9af8bb4baf533574833ff186fbb4a060e89ebe5e652081db51f568b67ebf8fed219c72d99c7984a45a201f6231604f6a8456
6
+ metadata.gz: 638f5ef1f9c7be3d41b1f1b9016f3a8f14f13c3fbc65c5df6ab8f02b7e903f7456a01514f1d5297c3ecbc022bf66d4283a014a602a9a49662b9d99a368d1a88a
7
+ data.tar.gz: f482994119dd2a2334bf633eae54cb8998d39d38821efc9d16bd88af92869f7f9e18f418cc1f71e2fdf7bbb0d6558cd449c24ae61f93dd660950104b192f4427
data/README.md CHANGED
@@ -8,7 +8,7 @@ Polaris ViewComponents is an implementation of the Polaris Design System using [
8
8
 
9
9
  ## Preview
10
10
 
11
- https://polaris-view-components.herokuapp.com/lookbook
11
+ https://polarisviewcomponents.org
12
12
 
13
13
  ## Usage
14
14
 
@@ -47,6 +47,16 @@ Define Polaris style on your `<body>` tag:
47
47
 
48
48
  ### Importmaps
49
49
 
50
+ Install dependencies:
51
+ ```
52
+ bin/importmap pin @rails/request.js --download
53
+ ```
54
+
55
+ If you use sprockets make sure the vendor folder is loaded in `app/assets/config/manifest.js`:
56
+ ```js
57
+ //= link_tree ../../../vendor/assets/javascripts .js
58
+ ```
59
+
50
60
  Add to `config/importmap.rb`:
51
61
 
52
62
  ```rb
@@ -65,7 +75,7 @@ registerPolarisControllers(Stimulus)
65
75
 
66
76
  Install NPM package:
67
77
  ```bash
68
- yarn add polaris-view-components
78
+ yarn add polaris-view-components @rails/request.js
69
79
  ```
70
80
 
71
81
  Add to `app/javascript/controllers/index.js`:
@@ -85,7 +95,7 @@ In addition to the dependencies declared in the `gemspec`, Polaris ViewComponent
85
95
  To get started:
86
96
 
87
97
  1. Run: `bundle install`
88
- 2. Run: `foreman start`
98
+ 2. Run: `bin/dev`
89
99
 
90
100
  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
101
 
@@ -0,0 +1,119 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+ import { get } from '@rails/request.js'
3
+
4
+ export default class extends Controller {
5
+ static targets = ['popover', 'input', 'results', 'option', 'emptyState']
6
+ static values = { url: String }
7
+
8
+ connect() {
9
+ this.inputTarget.addEventListener("input", this.onInputChange)
10
+ }
11
+
12
+ disconnect() {
13
+ this.inputTarget.removeEventListener("input", this.onInputChange)
14
+ }
15
+
16
+ // Actions
17
+
18
+ toggle() {
19
+ if (this.visibleOptions.length > 0) {
20
+ this.hideEmptyState()
21
+ this.popoverController.show()
22
+ } else if (this.value.length > 0 && this.hasEmptyStateTarget) {
23
+ this.showEmptyState()
24
+ } else {
25
+ this.popoverController.forceHide()
26
+ }
27
+ }
28
+
29
+ select(event) {
30
+ const input = event.currentTarget
31
+ const label = input.closest('li').dataset.label
32
+ const changeEvent = new CustomEvent('polaris-autocomplete:change', {
33
+ detail: { value: input.value, label, selected: input.checked }
34
+ })
35
+
36
+ this.element.dispatchEvent(changeEvent)
37
+ }
38
+
39
+ onInputChange = debounce(() => {
40
+ if (this.isRemote) {
41
+ this.fetchResults()
42
+ } else {
43
+ this.filterOptions()
44
+ }
45
+ }, 200)
46
+
47
+
48
+ // Private
49
+
50
+ get isRemote() {
51
+ return this.urlValue.length > 0
52
+ }
53
+
54
+ get popoverController() {
55
+ return this.application.getControllerForElementAndIdentifier(this.popoverTarget, 'polaris-popover')
56
+ }
57
+
58
+ get value() {
59
+ return this.inputTarget.value
60
+ }
61
+
62
+ get visibleOptions() {
63
+ return this.optionTargets.filter(option => {
64
+ return !option.classList.contains('Polaris--hidden')
65
+ })
66
+ }
67
+
68
+ filterOptions() {
69
+ if (this.value === '') {
70
+ this.optionTargets.forEach(option => {
71
+ option.classList.remove('Polaris--hidden')
72
+ })
73
+ } else {
74
+ const filterRegex = new RegExp(this.value, 'i')
75
+ this.optionTargets.forEach(option => {
76
+ if (option.dataset.label.match(filterRegex)) {
77
+ option.classList.remove('Polaris--hidden')
78
+ } else {
79
+ option.classList.add('Polaris--hidden')
80
+ }
81
+ })
82
+ }
83
+ this.toggle()
84
+ }
85
+
86
+ async fetchResults() {
87
+ const response = await get(this.urlValue, {
88
+ query: { q: this.value }
89
+ })
90
+ if (response.ok) {
91
+ const results = await response.html
92
+ this.resultsTarget.innerHTML = results
93
+ this.toggle()
94
+ }
95
+ }
96
+
97
+ showEmptyState() {
98
+ if (this.hasEmptyStateTarget) {
99
+ this.resultsTarget.classList.add('Polaris--hidden')
100
+ this.emptyStateTarget.classList.remove('Polaris--hidden')
101
+ }
102
+ }
103
+
104
+ hideEmptyState() {
105
+ if (this.hasEmptyStateTarget) {
106
+ this.emptyStateTarget.classList.add('Polaris--hidden')
107
+ this.resultsTarget.classList.remove('Polaris--hidden')
108
+ }
109
+ }
110
+ }
111
+
112
+ const debounce = (fn, delay = 10) => {
113
+ let timeoutId = null
114
+
115
+ return (...args) => {
116
+ clearTimeout(timeoutId)
117
+ timeoutId = setTimeout(fn, delay)
118
+ }
119
+ }
@@ -0,0 +1,47 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ disable(event) {
5
+ if (this.button.disabled) {
6
+ event.preventDefault()
7
+ } else {
8
+ this.button.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.disabled) {
16
+ this.button.disabled = false
17
+ this.button.classList.remove("Polaris-Button--disabled", "Polaris-Button--loading")
18
+ if (this.spinner) this.spinner.remove()
19
+ }
20
+ }
21
+
22
+ // Private
23
+
24
+ get button() {
25
+ return this.element
26
+ }
27
+
28
+ get buttonContent() {
29
+ return this.button.querySelector(".Polaris-Button__Content")
30
+ }
31
+
32
+ get spinner() {
33
+ return this.button.querySelector(".Polaris-Button__Spinner")
34
+ }
35
+
36
+ get spinnerHTML() {
37
+ return `
38
+ <span class="Polaris-Button__Spinner">
39
+ <span class="Polaris-Spinner Polaris-Spinner--sizeSmall">
40
+ <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
41
+ <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>
42
+ </svg>
43
+ </span>
44
+ </span>
45
+ `
46
+ }
47
+ }
@@ -0,0 +1,41 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { useTransition } from "stimulus-use"
3
+
4
+ export default class extends Controller {
5
+ static targets = ["navigationOverlay", "navigation", "saveBar"]
6
+
7
+ connect() {
8
+ if (!this.hasNavigationTarget) { return }
9
+
10
+ useTransition(this, {
11
+ element: this.navigationTarget,
12
+ enterFrom: "Polaris-Frame__Navigation--enter",
13
+ enterTo: "Polaris-Frame__Navigation--visible Polaris-Frame__Navigation--enterActive",
14
+ leaveActive: "Polaris-Frame__Navigation--exitActive",
15
+ leaveFrom: "Polaris-Frame__Navigation--exit",
16
+ leaveTo: "",
17
+ removeToClasses: false,
18
+ hiddenClass: false,
19
+ })
20
+ }
21
+
22
+ // Actions
23
+
24
+ openMenu() {
25
+ this.enter()
26
+ this.navigationOverlayTarget.classList.add("Polaris-Backdrop", "Polaris-Backdrop--belowNavigation")
27
+ }
28
+
29
+ closeMenu() {
30
+ this.leave()
31
+ this.navigationOverlayTarget.classList.remove("Polaris-Backdrop", "Polaris-Backdrop--belowNavigation")
32
+ }
33
+
34
+ showSaveBar() {
35
+ this.saveBarTarget.classList.add("Polaris-Frame-CSSAnimation--endFade")
36
+ }
37
+
38
+ hideSaveBar() {
39
+ this.saveBarTarget.classList.remove("Polaris-Frame-CSSAnimation--endFade")
40
+ }
41
+ }
@@ -1,11 +1,29 @@
1
+ import Autocomplete from './autocomplete_controller'
2
+ import Button from './button_controller'
3
+ import Frame from './frame_controller'
4
+ import Modal from './modal_controller'
5
+ import OptionList from './option_list_controller'
6
+ import Polaris from './polaris_controller'
7
+ import Popover from './popover_controller'
1
8
  import ResourceItem from './resource_item_controller'
9
+ import Scrollable from './scrollable_controller'
2
10
  import Select from './select_controller'
3
11
  import TextField from './text_field_controller'
12
+ import Toast from './toast_controller'
4
13
 
5
- export { ResourceItem, Select, TextField }
14
+ export { Frame, Modal, Polaris, Popover, ResourceItem, Scrollable, Select, TextField }
6
15
 
7
16
  export function registerPolarisControllers(application) {
17
+ application.register('polaris-autocomplete', Autocomplete)
18
+ application.register('polaris-button', Button)
19
+ application.register('polaris-frame', Frame)
20
+ application.register('polaris-modal', Modal)
21
+ application.register('polaris-option-list', OptionList)
22
+ application.register('polaris', Polaris)
23
+ application.register('polaris-popover', Popover)
8
24
  application.register('polaris-resource-item', ResourceItem)
25
+ application.register('polaris-scrollable', Scrollable)
9
26
  application.register('polaris-select', Select)
10
27
  application.register('polaris-text-field', TextField)
28
+ application.register('polaris-toast', Toast)
11
29
  }
@@ -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,41 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ["radioButton"]
5
+ static classes = ["selected"]
6
+
7
+ connect() {
8
+ this.updateSelected()
9
+ }
10
+
11
+ // Actions
12
+
13
+ update(event) {
14
+ const target = event.currentTarget
15
+ target.classList.add(this.selectedClass)
16
+ this.deselectAll(target)
17
+ }
18
+
19
+ // Private
20
+
21
+ updateSelected() {
22
+ this.radioButtonTargets.forEach(element => {
23
+ const input = element.querySelector('input[type=radio]')
24
+ if (input.checked) {
25
+ element.classList.add(this.selectedClass)
26
+ } else {
27
+ element.classList.remove(this.selectedClass)
28
+ }
29
+ })
30
+ }
31
+
32
+ deselectAll(target) {
33
+ this.radioButtonTargets.forEach(element => {
34
+ if (!element.isEqualNode(target)) {
35
+ const input = element.querySelector('input[type=radio]')
36
+ input.checked = false
37
+ element.classList.remove(this.selectedClass)
38
+ }
39
+ })
40
+ }
41
+ }
@@ -0,0 +1,28 @@
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
+ showToast() {
17
+ this.findElement("toast").show()
18
+ }
19
+
20
+ // Private
21
+
22
+ findElement(type) {
23
+ const targetId = this.element.dataset.target.replace("#", "")
24
+ const target = document.getElementById(targetId)
25
+ const controllerName = `polaris-${type}`
26
+ return this.application.getControllerForElementAndIdentifier(target, controllerName)
27
+ }
28
+ }
@@ -0,0 +1,49 @@
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.forceHide()
42
+ }
43
+ }
44
+
45
+ forceHide() {
46
+ this.popoverTarget.classList.remove(this.openClass)
47
+ this.popoverTarget.classList.add(this.closedClass)
48
+ }
49
+ }
@@ -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
  }
@@ -101,11 +101,15 @@ export default class extends Controller {
101
101
  // step / value has.
102
102
  const decimalPlaces = Math.max(dpl(numericValue), dpl(this.stepValue))
103
103
 
104
+ const oldValue = this.value
104
105
  const newValue = Math.min(
105
106
  Number(this.maxValue),
106
107
  Math.max(numericValue + steps * this.stepValue, Number(this.minValue)),
107
108
  )
108
109
 
109
110
  this.value = String(newValue.toFixed(decimalPlaces))
111
+ if (this.value != oldValue) {
112
+ this.inputTarget.dispatchEvent(new Event('change'))
113
+ }
110
114
  }
111
115
  }
@@ -0,0 +1,68 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ static activeClass = 'Polaris-Frame-ToastManager--toastWrapperEnterDone'
5
+ static defaultDuration = 5000
6
+ static defaultDurationWithAction = 10000
7
+ static values = { hidden: Boolean, duration: Number, hasAction: Boolean }
8
+
9
+ connect() {
10
+ if (!this.hiddenValue) {
11
+ this.show()
12
+ }
13
+ }
14
+
15
+ show = () => {
16
+ this.element.dataset.position = this.position
17
+ this.element.style.cssText = this.getStyle(this.position)
18
+ this.element.classList.add(this.constructor.activeClass)
19
+ setTimeout(this.close, this.timeoutDuration)
20
+ }
21
+
22
+ close = () => {
23
+ this.element.classList.remove(this.constructor.activeClass)
24
+ this.element.addEventListener('transitionend', this.updatePositions, false)
25
+ }
26
+
27
+ updatePositions = () => {
28
+ this.visibleToasts
29
+ .sort((a, b) => parseInt(a.dataset.position) - parseInt(b.dataset.position))
30
+ .forEach((toast, index) => {
31
+ const position = index + 1
32
+ toast.dataset.position = position
33
+ toast.style.cssText = this.getStyle(position)
34
+ })
35
+
36
+ this.element.removeEventListener('transitionend', this.updatePositions, false)
37
+ }
38
+
39
+ getStyle(position) {
40
+ const translateIn = -80 * position
41
+ const translateOut = 150 - (80 * position)
42
+ return `--toast-translate-y-in: ${translateIn}px; --toast-translate-y-out: ${translateOut}px;`
43
+ }
44
+
45
+ get timeoutDuration() {
46
+ if (this.durationValue > 0) {
47
+ return this.durationValue
48
+ } else if (this.hasActionValue) {
49
+ return this.constructor.defaultDurationWithAction
50
+ } else {
51
+ return this.constructor.defaultDuration
52
+ }
53
+ }
54
+
55
+ get toastManager() {
56
+ return this.element.closest('.Polaris-Frame-ToastManager')
57
+ }
58
+
59
+ get visibleToasts() {
60
+ return [
61
+ ...this.toastManager.querySelectorAll(`.${this.constructor.activeClass}`)
62
+ ]
63
+ }
64
+
65
+ get position() {
66
+ return this.visibleToasts.filter(el => !this.element.isEqualNode(el)).length + 1
67
+ }
68
+ }