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
@@ -0,0 +1,56 @@
|
|
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
|
+
this.popper = 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
|
+
name: 'flip',
|
24
|
+
options: {
|
25
|
+
allowedAutoPlacements: ['top-start', 'bottom-start', 'top-end', 'bottom-end']
|
26
|
+
},
|
27
|
+
}
|
28
|
+
]
|
29
|
+
})
|
30
|
+
if (this.activeValue) {
|
31
|
+
this.show()
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
toggle() {
|
36
|
+
this.popoverTarget.classList.toggle(this.closedClass)
|
37
|
+
this.popoverTarget.classList.toggle(this.openClass)
|
38
|
+
}
|
39
|
+
|
40
|
+
async show() {
|
41
|
+
this.popoverTarget.classList.remove(this.closedClass)
|
42
|
+
this.popoverTarget.classList.add(this.openClass)
|
43
|
+
await this.popper.update()
|
44
|
+
}
|
45
|
+
|
46
|
+
hide(event) {
|
47
|
+
if (!this.element.contains(event.target) && !this.popoverTarget.classList.contains(this.closedClass)) {
|
48
|
+
this.forceHide()
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
forceHide() {
|
53
|
+
this.popoverTarget.classList.remove(this.openClass)
|
54
|
+
this.popoverTarget.classList.add(this.closedClass)
|
55
|
+
}
|
56
|
+
}
|
@@ -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
|
+
}
|
@@ -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
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* @param {Function} fn
|
3
|
+
* @param {number} wait
|
4
|
+
*
|
5
|
+
* @return {Function}
|
6
|
+
*/
|
7
|
+
export function debounce (fn, wait) {
|
8
|
+
let timeoutId
|
9
|
+
|
10
|
+
return (...args) => {
|
11
|
+
clearTimeout(timeoutId)
|
12
|
+
timeoutId = setTimeout(() => fn.apply(this, args), wait)
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
export function formatBytes (bytes, decimals) {
|
17
|
+
if (bytes == 0) return '0 Bytes'
|
18
|
+
const k = 1024,
|
19
|
+
dm = decimals || 2,
|
20
|
+
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
21
|
+
i = Math.floor(Math.log(bytes) / Math.log(k))
|
22
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
|
23
|
+
}
|