polaris_view_components 0.5.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +136 -0
- data/app/assets/javascripts/polaris_view_components/button_controller.js +47 -0
- data/app/assets/javascripts/polaris_view_components/dropzone_controller.js +495 -0
- data/app/assets/javascripts/polaris_view_components/frame_controller.js +41 -0
- data/app/assets/javascripts/polaris_view_components/index.js +21 -1
- data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
- data/app/assets/javascripts/polaris_view_components/option_list_controller.js +41 -0
- data/app/assets/javascripts/polaris_view_components/polaris_controller.js +28 -0
- data/app/assets/javascripts/polaris_view_components/popover_controller.js +56 -0
- data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
- data/app/assets/javascripts/polaris_view_components/text_field_controller.js +4 -0
- data/app/assets/javascripts/polaris_view_components/toast_controller.js +68 -0
- data/app/assets/javascripts/polaris_view_components/utils.js +23 -0
- data/app/assets/javascripts/polaris_view_components.js +2400 -1
- data/app/assets/stylesheets/polaris_view_components/custom.css +104 -6
- data/app/assets/stylesheets/polaris_view_components.css +2147 -2021
- data/app/assets/stylesheets/polaris_view_components.postcss.css +1 -1
- data/app/components/polaris/action.rb +3 -3
- data/app/components/polaris/action_list/item_component.html.erb +35 -0
- data/app/components/polaris/action_list/item_component.rb +41 -0
- data/app/components/polaris/action_list/section_component.html.erb +16 -0
- data/app/components/polaris/action_list/section_component.rb +26 -0
- data/app/components/polaris/action_list_component.html.erb +13 -0
- data/app/components/polaris/action_list_component.rb +25 -0
- data/app/components/polaris/autocomplete/action_component.rb +7 -0
- data/app/components/polaris/autocomplete/option_component.rb +35 -0
- data/app/components/polaris/autocomplete/section_component.html.erb +9 -0
- data/app/components/polaris/autocomplete/section_component.rb +12 -0
- data/app/components/polaris/autocomplete_component.html.erb +30 -0
- data/app/components/polaris/autocomplete_component.rb +65 -0
- data/app/components/polaris/avatar_component.rb +2 -2
- data/app/components/polaris/badge_component.rb +2 -2
- data/app/components/polaris/banner_component.rb +8 -8
- data/app/components/polaris/base_button.rb +2 -2
- data/app/components/polaris/base_checkbox.rb +48 -0
- data/app/components/polaris/base_component.rb +1 -1
- data/app/components/polaris/base_radio_button.rb +38 -0
- data/app/components/polaris/button_component.html.erb +13 -0
- data/app/components/polaris/button_group_component.rb +8 -8
- data/app/components/polaris/callout_card_component.rb +6 -6
- data/app/components/polaris/caption_component.rb +3 -3
- data/app/components/polaris/card/header_component.rb +2 -2
- data/app/components/polaris/card/section_component.rb +4 -4
- data/app/components/polaris/card_component.html.erb +4 -0
- data/app/components/polaris/card_component.rb +6 -5
- data/app/components/polaris/character_count.rb +10 -10
- data/app/components/polaris/checkbox_component.html.erb +1 -5
- data/app/components/polaris/checkbox_component.rb +20 -13
- data/app/components/polaris/choice_component.rb +2 -2
- data/app/components/polaris/choice_list_component.rb +6 -6
- data/app/components/polaris/component.rb +6 -1
- data/app/components/polaris/data_table/cell_component.rb +4 -4
- data/app/components/polaris/data_table/column_component.rb +1 -1
- data/app/components/polaris/data_table_component.rb +4 -4
- data/app/components/polaris/description_list_component.rb +5 -5
- data/app/components/polaris/display_text_component.rb +3 -3
- data/app/components/polaris/dropzone_component.html.erb +156 -0
- data/app/components/polaris/dropzone_component.rb +150 -0
- data/app/components/polaris/empty_state_component.rb +4 -4
- data/app/components/polaris/exception_list/item_component.rb +3 -3
- data/app/components/polaris/exception_list_component.rb +2 -2
- data/app/components/polaris/filters_component.html.erb +22 -0
- data/app/components/polaris/filters_component.rb +61 -8
- data/app/components/polaris/footer_help_component.rb +2 -2
- data/app/components/polaris/form_layout/group_component.rb +5 -5
- data/app/components/polaris/form_layout/item_component.rb +2 -2
- data/app/components/polaris/form_layout_component.rb +4 -4
- data/app/components/polaris/frame/save_bar_component.html.erb +23 -0
- data/app/components/polaris/frame/save_bar_component.rb +31 -0
- data/app/components/polaris/frame/top_bar_component.html.erb +30 -0
- data/app/components/polaris/frame/top_bar_component.rb +18 -0
- data/app/components/polaris/frame_component.html.erb +44 -0
- data/app/components/polaris/frame_component.rb +33 -0
- data/app/components/polaris/heading_component.rb +2 -2
- data/app/components/polaris/headless_button.html.erb +13 -0
- data/app/components/polaris/headless_button.rb +18 -6
- data/app/components/polaris/icon_component.rb +3 -3
- data/app/components/polaris/index_table/cell_component.rb +3 -3
- data/app/components/polaris/index_table/column_component.rb +1 -1
- data/app/components/polaris/index_table_component.rb +4 -4
- data/app/components/polaris/inline_error_component.rb +2 -2
- data/app/components/polaris/label_component.rb +3 -3
- data/app/components/polaris/labelled_component.rb +3 -3
- data/app/components/polaris/layout/annotated_section.rb +2 -2
- data/app/components/polaris/layout/section.rb +2 -2
- data/app/components/polaris/layout_component.rb +4 -4
- data/app/components/polaris/link_component.rb +4 -4
- data/app/components/polaris/list_component.rb +5 -5
- data/app/components/polaris/logo.rb +13 -0
- data/app/components/polaris/modal/section_component.rb +19 -0
- data/app/components/polaris/modal_component.html.erb +79 -0
- data/app/components/polaris/modal_component.rb +98 -0
- data/app/components/polaris/navigation/item_component.html.erb +31 -0
- data/app/components/polaris/navigation/item_component.rb +85 -0
- data/app/components/polaris/navigation/section_component.html.erb +17 -0
- data/app/components/polaris/navigation/section_component.rb +64 -0
- data/app/components/polaris/navigation_component.html.erb +29 -0
- data/app/components/polaris/navigation_component.rb +15 -0
- data/app/components/polaris/option_list/checkbox_component.html.erb +14 -0
- data/app/components/polaris/option_list/checkbox_component.rb +37 -0
- data/app/components/polaris/option_list/option_component.rb +24 -0
- data/app/components/polaris/option_list/radio_button_component.rb +54 -0
- data/app/components/polaris/option_list/section_component.html.erb +14 -0
- data/app/components/polaris/option_list/section_component.rb +53 -0
- data/app/components/polaris/option_list_component.html.erb +15 -0
- data/app/components/polaris/option_list_component.rb +67 -0
- data/app/components/polaris/page_actions_component.rb +9 -8
- data/app/components/polaris/page_component.rb +5 -5
- data/app/components/polaris/pagination_component.rb +2 -6
- data/app/components/polaris/popover/pane_component.html.erb +25 -0
- data/app/components/polaris/popover/pane_component.rb +20 -0
- data/app/components/polaris/popover/section_component.rb +19 -0
- data/app/components/polaris/popover_component.html.erb +31 -0
- data/app/components/polaris/popover_component.rb +113 -0
- data/app/components/polaris/progress_bar_component.rb +6 -6
- data/app/components/polaris/radio_button_component.html.erb +1 -6
- data/app/components/polaris/radio_button_component.rb +18 -8
- data/app/components/polaris/resource_item_component.html.erb +16 -6
- data/app/components/polaris/resource_item_component.rb +43 -10
- data/app/components/polaris/resource_list_component.rb +3 -3
- data/app/components/polaris/scrollable_component.html.erb +5 -0
- data/app/components/polaris/scrollable_component.rb +48 -0
- data/app/components/polaris/select_component.rb +4 -4
- data/app/components/polaris/setting_toggle_component.html.erb +10 -0
- data/app/components/polaris/setting_toggle_component.rb +24 -0
- data/app/components/polaris/shopify_navigation_component.rb +8 -8
- data/app/components/polaris/skeleton_body_text_component.rb +2 -2
- data/app/components/polaris/spacer_component.rb +4 -4
- data/app/components/polaris/spinner_component.rb +3 -3
- data/app/components/polaris/stack/item_component.rb +15 -0
- data/app/components/polaris/stack_component.rb +6 -22
- data/app/components/polaris/subheading_component.rb +2 -2
- data/app/components/polaris/tabs/tab_component.html.erb +10 -0
- data/app/components/polaris/tabs/tab_component.rb +34 -0
- data/app/components/polaris/tabs_component.html.erb +7 -0
- data/app/components/polaris/tabs_component.rb +37 -0
- data/app/components/polaris/tag_component.rb +3 -2
- data/app/components/polaris/text_container_component.rb +3 -3
- data/app/components/polaris/text_field_component.rb +25 -11
- data/app/components/polaris/text_style_component.rb +5 -5
- data/app/components/polaris/thumbnail_component.rb +3 -3
- data/app/components/polaris/toast_component.html.erb +21 -0
- data/app/components/polaris/toast_component.rb +40 -0
- data/app/components/polaris/top_bar/user_menu_component.html.erb +19 -0
- data/app/components/polaris/top_bar/user_menu_component.rb +9 -0
- data/app/components/polaris/visually_hidden_component.rb +1 -1
- data/app/helpers/polaris/form_builder.rb +19 -8
- data/app/helpers/polaris/url_helper.rb +3 -3
- data/app/helpers/polaris/view_helper.rb +24 -4
- data/app/validators/type_validator.rb +2 -2
- data/config/locales/en.yml +6 -0
- data/lib/generators/polaris_view_components/install_generator.rb +5 -5
- data/lib/polaris/view_components/engine.rb +16 -2
- data/lib/polaris/view_components/version.rb +1 -1
- data/lib/polaris_view_components.rb +1 -1
- metadata +79 -16
- data/app/components/polaris/application_component.rb +0 -35
- data/app/components/polaris/dropzone/component.html.erb +0 -72
- data/app/components/polaris/dropzone/component.rb +0 -128
- data/app/components/polaris/dropzone/controller.js +0 -226
- data/app/components/polaris/dropzone/utils.js +0 -57
- data/app/components/polaris/new_component.rb +0 -10
- data/app/helpers/polaris/conditional_helper.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d4484aea870437d2c04e9962e86b40d7ebfcfd78119900fd9e5fde4cf225301
|
4
|
+
data.tar.gz: 8afb88abb96c45259eebbf58af6229faa543afae16c38f96858eaa92e9944795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 763b2fef888918919bf55c8e3fad976d60727b79b432683d72b4227a178ee6c3ec3f048bc27c6b8b29107b6f8fec5720f07136b16c21202e9e0a427c4bce6955
|
7
|
+
data.tar.gz: 0b5fdf681d13bab109bf60231bcf9b1fdbd79d86d87859d8df41bd426b1daaf2f779ef38d445806598c3ab974139edda3486514d917d8280eabff654507a021e
|
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://
|
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`:
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
2
|
+
import { get } from '@rails/request.js'
|
3
|
+
import { debounce } from './utils'
|
4
|
+
|
5
|
+
export default class extends Controller {
|
6
|
+
static targets = ['popover', 'input', 'results', 'option', 'emptyState']
|
7
|
+
static values = { url: String, selected: Array }
|
8
|
+
|
9
|
+
connect() {
|
10
|
+
this.inputTarget.addEventListener("input", this.onInputChange)
|
11
|
+
}
|
12
|
+
|
13
|
+
disconnect() {
|
14
|
+
this.inputTarget.removeEventListener("input", this.onInputChange)
|
15
|
+
}
|
16
|
+
|
17
|
+
// Actions
|
18
|
+
|
19
|
+
toggle() {
|
20
|
+
if (this.isRemote && this.visibleOptions.length == 0 && this.value.length == 0) {
|
21
|
+
this.fetchResults()
|
22
|
+
} else {
|
23
|
+
this.handleResults()
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
select(event) {
|
28
|
+
const input = event.currentTarget
|
29
|
+
const label = input.closest('li').dataset.label
|
30
|
+
const changeEvent = new CustomEvent('polaris-autocomplete:change', {
|
31
|
+
detail: { value: input.value, label, selected: input.checked }
|
32
|
+
})
|
33
|
+
|
34
|
+
this.element.dispatchEvent(changeEvent)
|
35
|
+
}
|
36
|
+
|
37
|
+
onInputChange = debounce(() => {
|
38
|
+
if (this.isRemote) {
|
39
|
+
this.fetchResults()
|
40
|
+
} else {
|
41
|
+
this.filterOptions()
|
42
|
+
}
|
43
|
+
}, 200)
|
44
|
+
|
45
|
+
reset() {
|
46
|
+
this.inputTarget.value = ''
|
47
|
+
this.optionTargets.forEach(option => {
|
48
|
+
option.classList.add('Polaris--hidden')
|
49
|
+
})
|
50
|
+
this.handleResults()
|
51
|
+
}
|
52
|
+
|
53
|
+
// Private
|
54
|
+
|
55
|
+
get isRemote() {
|
56
|
+
return this.urlValue.length > 0
|
57
|
+
}
|
58
|
+
|
59
|
+
get popoverController() {
|
60
|
+
return this.application.getControllerForElementAndIdentifier(this.popoverTarget, 'polaris-popover')
|
61
|
+
}
|
62
|
+
|
63
|
+
get value() {
|
64
|
+
return this.inputTarget.value
|
65
|
+
}
|
66
|
+
|
67
|
+
get visibleOptions() {
|
68
|
+
return this.optionTargets.filter(option => {
|
69
|
+
return !option.classList.contains('Polaris--hidden')
|
70
|
+
})
|
71
|
+
}
|
72
|
+
|
73
|
+
handleResults() {
|
74
|
+
if (this.visibleOptions.length > 0) {
|
75
|
+
this.hideEmptyState()
|
76
|
+
this.popoverController.show()
|
77
|
+
this.checkSelected()
|
78
|
+
} else if (this.value.length > 0 && this.hasEmptyStateTarget) {
|
79
|
+
this.showEmptyState()
|
80
|
+
} else {
|
81
|
+
this.popoverController.forceHide()
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
filterOptions() {
|
86
|
+
if (this.value === '') {
|
87
|
+
this.optionTargets.forEach(option => {
|
88
|
+
option.classList.remove('Polaris--hidden')
|
89
|
+
})
|
90
|
+
} else {
|
91
|
+
const filterRegex = new RegExp(this.value, 'i')
|
92
|
+
this.optionTargets.forEach(option => {
|
93
|
+
if (option.dataset.label.match(filterRegex)) {
|
94
|
+
option.classList.remove('Polaris--hidden')
|
95
|
+
} else {
|
96
|
+
option.classList.add('Polaris--hidden')
|
97
|
+
}
|
98
|
+
})
|
99
|
+
}
|
100
|
+
this.handleResults()
|
101
|
+
}
|
102
|
+
|
103
|
+
async fetchResults() {
|
104
|
+
const response = await get(this.urlValue, {
|
105
|
+
query: { q: this.value }
|
106
|
+
})
|
107
|
+
if (response.ok) {
|
108
|
+
const results = await response.html
|
109
|
+
this.resultsTarget.innerHTML = results
|
110
|
+
this.handleResults()
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
showEmptyState() {
|
115
|
+
if (this.hasEmptyStateTarget) {
|
116
|
+
this.resultsTarget.classList.add('Polaris--hidden')
|
117
|
+
this.emptyStateTarget.classList.remove('Polaris--hidden')
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
hideEmptyState() {
|
122
|
+
if (this.hasEmptyStateTarget) {
|
123
|
+
this.emptyStateTarget.classList.add('Polaris--hidden')
|
124
|
+
this.resultsTarget.classList.remove('Polaris--hidden')
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
checkSelected() {
|
129
|
+
this.visibleOptions.forEach(option => {
|
130
|
+
const input = option.querySelector('input')
|
131
|
+
if (!input) return
|
132
|
+
|
133
|
+
input.checked = this.selectedValue.includes(input.value)
|
134
|
+
})
|
135
|
+
}
|
136
|
+
}
|
@@ -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
|
+
}
|