playbook_ui 14.17.0.pre.alpha.playcdntest7233 → 14.17.0.pre.rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Utilities/types.ts +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +0 -70
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +2 -83
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +7 -20
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +1 -2
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +1 -2
- data/app/pb_kits/playbook/pb_background/_background.scss +0 -26
- data/app/pb_kits/playbook/pb_background/_background.tsx +3 -5
- data/app/pb_kits/playbook/pb_background/background.test.js +0 -5
- data/app/pb_kits/playbook/pb_background/docs/example.yml +0 -1
- data/app/pb_kits/playbook/pb_background/docs/index.js +0 -1
- data/app/pb_kits/playbook/pb_collapsible/__snapshots__/collapsible.test.js.snap +7 -14
- data/app/pb_kits/playbook/pb_contact/contact.test.js +7 -7
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.tsx +34 -34
- data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +2 -2
- data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.ts +0 -16
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_inline.html.erb +11 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_inline.jsx +7 -0
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_inline_styles.scss +24 -28
- data/app/pb_kits/playbook/pb_date_range_inline/date_range_inline.test.js +2 -2
- data/app/pb_kits/playbook/pb_date_range_stacked/date_range_stacked.test.js +1 -1
- data/app/pb_kits/playbook/pb_draggable/_draggable.scss +20 -43
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +17 -58
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones.jsx +105 -102
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones.md +3 -3
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones_colors.jsx +48 -50
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones_colors.md +1 -1
- data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_table.jsx → _draggable_with_table_react.jsx} +1 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_with_table_react.md +1 -3
- data/app/pb_kits/playbook/pb_draggable/docs/example.yml +6 -9
- data/app/pb_kits/playbook/pb_draggable/docs/index.js +1 -4
- data/app/pb_kits/playbook/pb_draggable/draggable.test.jsx +3 -71
- data/app/pb_kits/playbook/pb_draggable/subcomponents/DraggableContainer.tsx +3 -4
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.jsx +6 -6
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.jsx +6 -6
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +6 -6
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display_rails.html.erb +8 -8
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +3 -3
- data/app/pb_kits/playbook/pb_filter/Filter/CurrentFilters.tsx +4 -3
- data/app/pb_kits/playbook/pb_filter/Filter/SortMenu.tsx +3 -2
- data/app/pb_kits/playbook/pb_form/pb_form_validation.js +1 -1
- data/app/pb_kits/playbook/pb_form_group/_form_group.scss +0 -22
- data/app/pb_kits/playbook/pb_icon/icon.test.js +9 -9
- data/app/pb_kits/playbook/pb_icon_circle/icon_circle.test.js +1 -1
- data/app/pb_kits/playbook/pb_icon_stat_value/icon_stat_value.test.js +1 -1
- data/app/pb_kits/playbook/pb_icon_value/icon_value.test.js +1 -1
- data/app/pb_kits/playbook/pb_label_value/label_value.test.js +1 -1
- data/app/pb_kits/playbook/pb_layout/_layout.scss +0 -58
- data/app/pb_kits/playbook/pb_layout/_layout.tsx +7 -20
- data/app/pb_kits/playbook/pb_layout/docs/example.yml +0 -1
- data/app/pb_kits/playbook/pb_layout/docs/index.js +0 -1
- data/app/pb_kits/playbook/pb_layout/layout.test.js +0 -4
- data/app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js +1 -1
- data/app/pb_kits/playbook/pb_link/link.test.jsx +2 -2
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +1 -2
- data/app/pb_kits/playbook/pb_nav/_nav_item.test.js +3 -5
- data/app/pb_kits/playbook/pb_stat_change/stat_change.test.js +4 -8
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_floating_react.md +1 -1
- data/app/pb_kits/playbook/pb_table/docs/example.yml +0 -2
- data/app/pb_kits/playbook/pb_table/styles/_headers.scss +7 -19
- data/app/pb_kits/playbook/pb_table/styles/_striped.scss +3 -3
- data/app/pb_kits/playbook/pb_table/table.rb +1 -13
- data/app/pb_kits/playbook/pb_table/table_header.rb +1 -13
- data/app/pb_kits/playbook/pb_tooltip/floating_ui.js +282 -0
- data/app/pb_kits/playbook/pb_tooltip/index.js +56 -183
- data/app/pb_kits/playbook/pb_tooltip/tooltip.html.erb +5 -2
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_highlight.jsx +4 -4
- data/app/pb_kits/playbook/pb_typeahead/index.ts +2 -2
- data/app/pb_kits/playbook/pb_typeahead/typeahead.html.erb +5 -2
- data/app/pb_kits/playbook/pb_user/user.html.erb +6 -1
- data/app/pb_kits/playbook/pb_user_badge/user_badge.html.erb +6 -1
- data/app/pb_kits/playbook/utilities/globalProps.ts +1 -1
- data/app/pb_kits/playbook/utilities/object.test.js +1 -149
- data/app/pb_kits/playbook/utilities/object.ts +42 -124
- data/dist/chunks/{_typeahead-C2GOKWtm.js → _typeahead-N-EFroAX.js} +3 -3
- data/dist/chunks/_weekday_stacked-Db780bKR.js +45 -0
- data/dist/chunks/lib-Co5y3V4K.js +29 -0
- data/dist/chunks/{pb_form_validation-BvNy9Bd6.js → pb_form_validation-DMajaRt3.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/kit_base.rb +4 -4
- data/lib/playbook/version.rb +2 -2
- metadata +19 -33
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_fullscreen.jsx +0 -90
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_fullscreen.md +0 -3
- data/app/pb_kits/playbook/pb_background/docs/_background_overlay.jsx +0 -35
- data/app/pb_kits/playbook/pb_background/docs/_background_overlay.md +0 -1
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones_line.jsx +0 -110
- data/app/pb_kits/playbook/pb_draggable/docs/_draggable_drop_zones_line.md +0 -5
- data/app/pb_kits/playbook/pb_layout/docs/_layout_bracket.jsx +0 -190
- data/app/pb_kits/playbook/pb_layout/docs/_layout_bracket.md +0 -5
- data/app/pb_kits/playbook/pb_layout/subcomponents/_game.tsx +0 -90
- data/app/pb_kits/playbook/pb_layout/subcomponents/_round.tsx +0 -57
- data/app/pb_kits/playbook/pb_section_separator/docs/_section_separator_vertical.md +0 -1
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_borderless.html.erb +0 -34
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_borderless_rails.md +0 -1
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_floating.html.erb +0 -36
- data/app/pb_kits/playbook/pb_table/docs/_table_with_header_style_floating_rails.md +0 -1
- data/dist/chunks/_weekday_stacked-CFGTPT0O.js +0 -45
- data/dist/chunks/lib-BGzBzFZX.js +0 -29
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_default_react.md → _draggable_default.md} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_default.html.erb → _draggable_default_rails.html.erb} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_multiple_containers_react.md → _draggable_multiple_containers.md} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_multiple_containers.html.erb → _draggable_multiple_containers_rails.html.erb} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_cards_react.md → _draggable_with_cards.md} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_cards.html.erb → _draggable_with_cards_rails.html.erb} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_list_react.md → _draggable_with_list.md} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_list.html.erb → _draggable_with_list_rails.html.erb} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_selectable_list_react.md → _draggable_with_selectable_list.md} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_selectable_list.html.erb → _draggable_with_selectable_list_rails.html.erb} +0 -0
- /data/app/pb_kits/playbook/pb_draggable/docs/{_draggable_with_table_rails.md → _draggable_with_table.md} +0 -0
@@ -0,0 +1,282 @@
|
|
1
|
+
import PbEnhancedElement from '../pb_enhanced_element'
|
2
|
+
import { computePosition, offset, flip, shift, arrow, autoUpdate } from '@floating-ui/dom'
|
3
|
+
|
4
|
+
const TOOLTIP_OFFSET = 20
|
5
|
+
const TOOLTIP_TIMEOUT = 250
|
6
|
+
const SAFE_ZONE_MARGIN = 1
|
7
|
+
|
8
|
+
export default class PbTooltipFloatingUi extends PbEnhancedElement {
|
9
|
+
static get selector() {
|
10
|
+
return '[data-pb-tooltip-kit="true"][data-pb-tooltip-delay-open], [data-pb-tooltip-kit="true"][data-pb-tooltip-delay-close], [data-pb-tooltip-kit="true"][data-pb-tooltip-interaction="true"]'
|
11
|
+
}
|
12
|
+
|
13
|
+
connect() {
|
14
|
+
if (this.tooltipInteraction) {
|
15
|
+
document.addEventListener('mousemove', (e) => {
|
16
|
+
this.lastMouseX = e.clientX
|
17
|
+
this.lastMouseY = e.clientY
|
18
|
+
})
|
19
|
+
}
|
20
|
+
|
21
|
+
this.triggerElements.forEach((trigger) => {
|
22
|
+
const method = this.triggerMethod
|
23
|
+
const interactionEnabled = this.tooltipInteraction
|
24
|
+
|
25
|
+
if (method === 'click') {
|
26
|
+
trigger.addEventListener('click', () => {
|
27
|
+
this.showTooltip(trigger)
|
28
|
+
})
|
29
|
+
} else {
|
30
|
+
trigger.addEventListener('mouseenter', () => {
|
31
|
+
clearSafeZoneListener(this)
|
32
|
+
clearTimeout(this.mouseleaveTimeout)
|
33
|
+
this.currentTrigger = trigger
|
34
|
+
const delayOpen = this.delayOpen ? parseInt(this.delayOpen) : TOOLTIP_TIMEOUT
|
35
|
+
this.mouseenterTimeout = setTimeout(() => {
|
36
|
+
this.showTooltip(trigger)
|
37
|
+
if (interactionEnabled) {
|
38
|
+
this.checkCloseTooltip(trigger)
|
39
|
+
}
|
40
|
+
}, delayOpen)
|
41
|
+
})
|
42
|
+
|
43
|
+
trigger.addEventListener('mouseleave', () => {
|
44
|
+
clearTimeout(this.mouseenterTimeout)
|
45
|
+
if (this.delayClose) {
|
46
|
+
const delayClose = parseInt(this.delayClose)
|
47
|
+
this.mouseleaveTimeout = setTimeout(() => {
|
48
|
+
if (interactionEnabled) {
|
49
|
+
this.attachSafeZoneListener()
|
50
|
+
} else {
|
51
|
+
this.hideTooltip()
|
52
|
+
}
|
53
|
+
}, delayClose)
|
54
|
+
} else {
|
55
|
+
if (interactionEnabled) {
|
56
|
+
this.attachSafeZoneListener()
|
57
|
+
} else {
|
58
|
+
this.hideTooltip()
|
59
|
+
}
|
60
|
+
}
|
61
|
+
})
|
62
|
+
|
63
|
+
if (interactionEnabled) {
|
64
|
+
this.tooltip.addEventListener('mouseenter', () => {
|
65
|
+
clearSafeZoneListener(this)
|
66
|
+
})
|
67
|
+
|
68
|
+
this.tooltip.addEventListener('mouseleave', () => {
|
69
|
+
this.attachSafeZoneListener()
|
70
|
+
})
|
71
|
+
}
|
72
|
+
}
|
73
|
+
})
|
74
|
+
}
|
75
|
+
|
76
|
+
attachSafeZoneListener() {
|
77
|
+
clearSafeZoneListener(this)
|
78
|
+
this.safeZoneHandler = (e) => {
|
79
|
+
if (!this.currentTrigger) return
|
80
|
+
const triggerRect = this.currentTrigger.getBoundingClientRect()
|
81
|
+
const tooltipRect = this.tooltip.getBoundingClientRect()
|
82
|
+
const safeRect = getSafeZone(triggerRect, tooltipRect, this.position, SAFE_ZONE_MARGIN)
|
83
|
+
if (!isPointInsideRect(e.clientX, e.clientY, safeRect)) {
|
84
|
+
this.hideTooltip()
|
85
|
+
clearSafeZoneListener(this)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
document.addEventListener('mousemove', this.safeZoneHandler)
|
89
|
+
}
|
90
|
+
|
91
|
+
checkCloseTooltip(trigger) {
|
92
|
+
document.querySelector('body').addEventListener('click', ({ target }) => {
|
93
|
+
const isTooltip = target.closest(`#${this.tooltipId}`) === this.tooltip
|
94
|
+
const isTrigger = target.closest(this.triggerElementSelector) === trigger
|
95
|
+
if (isTrigger || isTooltip) {
|
96
|
+
this.checkCloseTooltip(trigger)
|
97
|
+
} else {
|
98
|
+
this.hideTooltip()
|
99
|
+
}
|
100
|
+
}, { once: true })
|
101
|
+
}
|
102
|
+
|
103
|
+
showTooltip(trigger) {
|
104
|
+
if (this.shouldShowTooltip === 'false') return
|
105
|
+
|
106
|
+
clearSafeZoneListener(this)
|
107
|
+
|
108
|
+
this.tooltip.style.opacity = '1'
|
109
|
+
this.tooltip.style.visibility = 'visible'
|
110
|
+
this.tooltip.style.pointerEvents = 'auto'
|
111
|
+
|
112
|
+
if (this.cleanup) {
|
113
|
+
this.cleanup()
|
114
|
+
}
|
115
|
+
|
116
|
+
const arrowElement = document.querySelector(`#${this.tooltipId}-arrow`)
|
117
|
+
|
118
|
+
this.cleanup = autoUpdate(trigger, this.tooltip, () => {
|
119
|
+
computePosition(trigger, this.tooltip, {
|
120
|
+
placement: this.position,
|
121
|
+
strategy: 'fixed',
|
122
|
+
middleware: [
|
123
|
+
offset({ mainAxis: TOOLTIP_OFFSET, crossAxis: 0 }),
|
124
|
+
flip(),
|
125
|
+
shift(),
|
126
|
+
arrow({ element: arrowElement })
|
127
|
+
],
|
128
|
+
}).then(({ x, y, placement, middlewareData }) => {
|
129
|
+
Object.assign(this.tooltip.style, {
|
130
|
+
left: `${x}px`,
|
131
|
+
top: `${y}px`,
|
132
|
+
position: 'fixed'
|
133
|
+
})
|
134
|
+
this.tooltip.setAttribute('data-popper-placement', placement)
|
135
|
+
if (arrowElement && middlewareData.arrow) {
|
136
|
+
const { x: arrowX, y: arrowY } = middlewareData.arrow
|
137
|
+
Object.assign(arrowElement.style, {
|
138
|
+
left: arrowX != null ? `${arrowX}px` : '',
|
139
|
+
top: arrowY != null ? `${arrowY}px` : '',
|
140
|
+
position: 'absolute'
|
141
|
+
})
|
142
|
+
}
|
143
|
+
})
|
144
|
+
})
|
145
|
+
|
146
|
+
this.tooltip.classList.add('show')
|
147
|
+
|
148
|
+
if (this.triggerMethod === 'click') {
|
149
|
+
clearTimeout(this.autoHideTimeout)
|
150
|
+
this.autoHideTimeout = setTimeout(() => {
|
151
|
+
this.hideTooltip()
|
152
|
+
}, 1000)
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
hideTooltip() {
|
157
|
+
if (!this.tooltip) return
|
158
|
+
|
159
|
+
this.tooltip.classList.add('fade_out')
|
160
|
+
setTimeout(() => {
|
161
|
+
if (this.cleanup) {
|
162
|
+
this.cleanup()
|
163
|
+
this.cleanup = null
|
164
|
+
}
|
165
|
+
this.tooltip.classList.remove('show')
|
166
|
+
this.tooltip.classList.remove('fade_out')
|
167
|
+
this.tooltip.style.opacity = '0'
|
168
|
+
this.tooltip.style.visibility = 'hidden'
|
169
|
+
this.tooltip.style.pointerEvents = 'none'
|
170
|
+
this.tooltip.style.position = ''
|
171
|
+
this.tooltip.style.top = ''
|
172
|
+
this.tooltip.style.left = ''
|
173
|
+
this.tooltip.style.transform = ''
|
174
|
+
}, TOOLTIP_TIMEOUT)
|
175
|
+
}
|
176
|
+
|
177
|
+
get triggerElements() {
|
178
|
+
let triggerEl
|
179
|
+
if (this.triggerElementId) {
|
180
|
+
triggerEl = document.querySelector(`#${this.triggerElementId}`)
|
181
|
+
} else if (this.triggerElementSelector) {
|
182
|
+
const selectorIsId = this.triggerElementSelector.indexOf('#') > -1
|
183
|
+
triggerEl = selectorIsId
|
184
|
+
? document.querySelector(this.triggerElementSelector)
|
185
|
+
: document.querySelectorAll(this.triggerElementSelector)
|
186
|
+
} else {
|
187
|
+
triggerEl = this.element
|
188
|
+
}
|
189
|
+
if (!triggerEl) {
|
190
|
+
console.error('Tooltip Kit: No valid trigger element found!')
|
191
|
+
return []
|
192
|
+
}
|
193
|
+
if (triggerEl.length === undefined) {
|
194
|
+
triggerEl = [triggerEl]
|
195
|
+
}
|
196
|
+
return triggerEl
|
197
|
+
}
|
198
|
+
|
199
|
+
get tooltip() {
|
200
|
+
return (this._tooltip = this._tooltip || this.element.querySelector(`#${this.tooltipId}`))
|
201
|
+
}
|
202
|
+
|
203
|
+
get position() {
|
204
|
+
return this.element.dataset.pbTooltipPosition
|
205
|
+
}
|
206
|
+
|
207
|
+
get triggerElementId() {
|
208
|
+
return this.element.dataset.pbTooltipTriggerElementId
|
209
|
+
}
|
210
|
+
|
211
|
+
get tooltipId() {
|
212
|
+
return this.element.dataset.pbTooltipTooltipId
|
213
|
+
}
|
214
|
+
|
215
|
+
get triggerElementSelector() {
|
216
|
+
return this.element.dataset.pbTooltipTriggerElementSelector
|
217
|
+
}
|
218
|
+
|
219
|
+
get shouldShowTooltip() {
|
220
|
+
return this.element.dataset.pbTooltipShowTooltip
|
221
|
+
}
|
222
|
+
|
223
|
+
get triggerMethod() {
|
224
|
+
return this.element.dataset.pbTooltipTriggerMethod || 'hover'
|
225
|
+
}
|
226
|
+
|
227
|
+
get tooltipInteraction() {
|
228
|
+
return this.element.dataset.pbTooltipInteraction === 'true'
|
229
|
+
}
|
230
|
+
|
231
|
+
get delayOpen() {
|
232
|
+
return this.element.dataset.pbTooltipDelayOpen
|
233
|
+
}
|
234
|
+
|
235
|
+
get delayClose() {
|
236
|
+
return this.element.dataset.pbTooltipDelayClose
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
function clearSafeZoneListener(context) {
|
241
|
+
if (context.safeZoneHandler) {
|
242
|
+
document.removeEventListener('mousemove', context.safeZoneHandler)
|
243
|
+
context.safeZoneHandler = null
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
function getSafeZone(triggerRect, tooltipRect, placement, margin) {
|
248
|
+
let safeRect = {}
|
249
|
+
if (placement.startsWith('top')) {
|
250
|
+
safeRect.left = triggerRect.left - margin
|
251
|
+
safeRect.right = triggerRect.right + margin
|
252
|
+
safeRect.top = tooltipRect.bottom - margin
|
253
|
+
safeRect.bottom = triggerRect.top + margin
|
254
|
+
} else if (placement.startsWith('bottom')) {
|
255
|
+
safeRect.left = triggerRect.left - margin
|
256
|
+
safeRect.right = triggerRect.right + margin
|
257
|
+
safeRect.top = triggerRect.bottom - margin
|
258
|
+
safeRect.bottom = tooltipRect.top + margin
|
259
|
+
} else if (placement.startsWith('left')) {
|
260
|
+
safeRect.top = triggerRect.top - margin
|
261
|
+
safeRect.bottom = triggerRect.bottom + margin
|
262
|
+
safeRect.left = tooltipRect.right - margin
|
263
|
+
safeRect.right = triggerRect.left + margin
|
264
|
+
} else if (placement.startsWith('right')) {
|
265
|
+
safeRect.top = triggerRect.top - margin
|
266
|
+
safeRect.bottom = triggerRect.bottom + margin
|
267
|
+
safeRect.left = triggerRect.right - margin
|
268
|
+
safeRect.right = tooltipRect.left + margin
|
269
|
+
} else {
|
270
|
+
safeRect = {
|
271
|
+
left: triggerRect.left - margin,
|
272
|
+
right: triggerRect.right + margin,
|
273
|
+
top: triggerRect.top - margin,
|
274
|
+
bottom: triggerRect.bottom + margin,
|
275
|
+
}
|
276
|
+
}
|
277
|
+
return safeRect
|
278
|
+
}
|
279
|
+
|
280
|
+
function isPointInsideRect(x, y, rect) {
|
281
|
+
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom
|
282
|
+
}
|
@@ -1,26 +1,22 @@
|
|
1
1
|
import PbEnhancedElement from '../pb_enhanced_element'
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
2
|
+
import {
|
3
|
+
createPopperLite as createPopper,
|
4
|
+
flip,
|
5
|
+
offset,
|
6
|
+
preventOverflow,
|
7
|
+
} from '@popperjs/core'
|
8
|
+
|
9
|
+
const TOOLTIP_OFFSET = [0, 20]
|
5
10
|
const TOOLTIP_TIMEOUT = 250
|
6
|
-
const SAFE_ZONE_MARGIN = 1
|
7
11
|
|
8
12
|
export default class PbTooltip extends PbEnhancedElement {
|
9
13
|
static get selector() {
|
10
|
-
return '[data-pb-tooltip-kit]'
|
14
|
+
return '[data-pb-tooltip-kit="true"][data-pb-tooltip-interaction="false"]:not([data-pb-tooltip-delay-open]):not([data-pb-tooltip-delay-close])'
|
11
15
|
}
|
12
16
|
|
13
17
|
connect() {
|
14
|
-
if (this.tooltipInteraction) {
|
15
|
-
document.addEventListener('mousemove', (e) => {
|
16
|
-
this.lastMouseX = e.clientX
|
17
|
-
this.lastMouseY = e.clientY
|
18
|
-
})
|
19
|
-
}
|
20
|
-
|
21
18
|
this.triggerElements.forEach((trigger) => {
|
22
19
|
const method = this.triggerMethod
|
23
|
-
const interactionEnabled = this.tooltipInteraction
|
24
20
|
|
25
21
|
if (method === 'click') {
|
26
22
|
trigger.addEventListener('click', () => {
|
@@ -28,66 +24,29 @@ export default class PbTooltip extends PbEnhancedElement {
|
|
28
24
|
})
|
29
25
|
} else {
|
30
26
|
trigger.addEventListener('mouseenter', () => {
|
31
|
-
clearSafeZoneListener(this)
|
32
|
-
clearTimeout(this.mouseleaveTimeout)
|
33
|
-
this.currentTrigger = trigger
|
34
|
-
const delayOpen = this.delayOpen ? parseInt(this.delayOpen) : TOOLTIP_TIMEOUT
|
35
27
|
this.mouseenterTimeout = setTimeout(() => {
|
36
28
|
this.showTooltip(trigger)
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
}, delayOpen)
|
41
|
-
})
|
29
|
+
this.checkCloseTooltip(trigger)
|
30
|
+
}, TOOLTIP_TIMEOUT)
|
42
31
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
const delayClose = parseInt(this.delayClose)
|
47
|
-
this.mouseleaveTimeout = setTimeout(() => {
|
48
|
-
if (interactionEnabled) {
|
49
|
-
this.attachSafeZoneListener()
|
50
|
-
} else {
|
51
|
-
this.hideTooltip()
|
52
|
-
}
|
53
|
-
}, delayClose)
|
54
|
-
} else {
|
55
|
-
if (interactionEnabled) {
|
56
|
-
this.attachSafeZoneListener()
|
57
|
-
} else {
|
32
|
+
trigger.addEventListener('mouseleave', () => {
|
33
|
+
clearTimeout(this.mouseenterTimeout)
|
34
|
+
setTimeout(() => {
|
58
35
|
this.hideTooltip()
|
59
|
-
}
|
60
|
-
}
|
36
|
+
}, 0)
|
37
|
+
}, { once: true })
|
61
38
|
})
|
62
39
|
|
63
|
-
|
64
|
-
this.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
this.attachSafeZoneListener()
|
70
|
-
})
|
71
|
-
}
|
40
|
+
this.tooltip.addEventListener('mouseenter', () => {
|
41
|
+
clearTimeout(this.mouseenterTimeout)
|
42
|
+
})
|
43
|
+
this.tooltip.addEventListener('mouseleave', () => {
|
44
|
+
this.hideTooltip()
|
45
|
+
})
|
72
46
|
}
|
73
47
|
})
|
74
48
|
}
|
75
49
|
|
76
|
-
attachSafeZoneListener() {
|
77
|
-
clearSafeZoneListener(this)
|
78
|
-
this.safeZoneHandler = (e) => {
|
79
|
-
if (!this.currentTrigger) return
|
80
|
-
const triggerRect = this.currentTrigger.getBoundingClientRect()
|
81
|
-
const tooltipRect = this.tooltip.getBoundingClientRect()
|
82
|
-
const safeRect = getSafeZone(triggerRect, tooltipRect, this.position, SAFE_ZONE_MARGIN)
|
83
|
-
if (!isPointInsideRect(e.clientX, e.clientY, safeRect)) {
|
84
|
-
this.hideTooltip()
|
85
|
-
clearSafeZoneListener(this)
|
86
|
-
}
|
87
|
-
}
|
88
|
-
document.addEventListener('mousemove', this.safeZoneHandler)
|
89
|
-
}
|
90
|
-
|
91
50
|
checkCloseTooltip(trigger) {
|
92
51
|
document.querySelector('body').addEventListener('click', ({ target }) => {
|
93
52
|
const isTooltip = target.closest(`#${this.tooltipId}`) === this.tooltip
|
@@ -103,46 +62,27 @@ export default class PbTooltip extends PbEnhancedElement {
|
|
103
62
|
showTooltip(trigger) {
|
104
63
|
if (this.shouldShowTooltip === 'false') return
|
105
64
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
arrow({ element: arrowElement })
|
127
|
-
],
|
128
|
-
}).then(({ x, y, placement, middlewareData }) => {
|
129
|
-
Object.assign(this.tooltip.style, {
|
130
|
-
left: `${x}px`,
|
131
|
-
top: `${y}px`,
|
132
|
-
position: 'fixed'
|
133
|
-
})
|
134
|
-
this.tooltip.setAttribute('data-popper-placement', placement)
|
135
|
-
if (arrowElement && middlewareData.arrow) {
|
136
|
-
const { x: arrowX, y: arrowY } = middlewareData.arrow
|
137
|
-
Object.assign(arrowElement.style, {
|
138
|
-
left: arrowX != null ? `${arrowX}px` : '',
|
139
|
-
top: arrowY != null ? `${arrowY}px` : '',
|
140
|
-
position: 'absolute'
|
141
|
-
})
|
142
|
-
}
|
143
|
-
})
|
65
|
+
this.popper = createPopper(trigger, this.tooltip, {
|
66
|
+
placement: this.position,
|
67
|
+
strategy: 'fixed',
|
68
|
+
modifiers: [
|
69
|
+
{
|
70
|
+
name: 'offset',
|
71
|
+
options: {
|
72
|
+
offset: TOOLTIP_OFFSET,
|
73
|
+
},
|
74
|
+
},
|
75
|
+
{
|
76
|
+
name: 'arrow',
|
77
|
+
options: {
|
78
|
+
element: document.querySelector(`#${this.tooltipId}-arrow`),
|
79
|
+
},
|
80
|
+
},
|
81
|
+
offset,
|
82
|
+
preventOverflow,
|
83
|
+
flip,
|
84
|
+
],
|
144
85
|
})
|
145
|
-
|
146
86
|
this.tooltip.classList.add('show')
|
147
87
|
|
148
88
|
if (this.triggerMethod === 'click') {
|
@@ -154,50 +94,39 @@ export default class PbTooltip extends PbEnhancedElement {
|
|
154
94
|
}
|
155
95
|
|
156
96
|
hideTooltip() {
|
157
|
-
if (!this.tooltip) return
|
158
|
-
|
159
97
|
this.tooltip.classList.add('fade_out')
|
160
98
|
setTimeout(() => {
|
161
|
-
if (this.
|
162
|
-
|
163
|
-
this.cleanup = null
|
164
|
-
}
|
99
|
+
if (!this.popper) return
|
100
|
+
this.popper.destroy()
|
165
101
|
this.tooltip.classList.remove('show')
|
166
102
|
this.tooltip.classList.remove('fade_out')
|
167
|
-
this.tooltip.style.opacity = '0'
|
168
|
-
this.tooltip.style.visibility = 'hidden'
|
169
|
-
this.tooltip.style.pointerEvents = 'none'
|
170
|
-
this.tooltip.style.position = ''
|
171
|
-
this.tooltip.style.top = ''
|
172
|
-
this.tooltip.style.left = ''
|
173
|
-
this.tooltip.style.transform = ''
|
174
103
|
}, TOOLTIP_TIMEOUT)
|
175
104
|
}
|
176
105
|
|
177
106
|
get triggerElements() {
|
178
107
|
let triggerEl
|
108
|
+
|
179
109
|
if (this.triggerElementId) {
|
180
110
|
triggerEl = document.querySelector(`#${this.triggerElementId}`)
|
181
|
-
} else
|
111
|
+
} else {
|
182
112
|
const selectorIsId = this.triggerElementSelector.indexOf('#') > -1
|
183
113
|
triggerEl = selectorIsId
|
184
|
-
? document.querySelector(this.triggerElementSelector)
|
185
|
-
: document.querySelectorAll(this.triggerElementSelector)
|
186
|
-
} else {
|
187
|
-
triggerEl = this.element
|
114
|
+
? document.querySelector(`${this.triggerElementSelector}`)
|
115
|
+
: document.querySelectorAll(`${this.triggerElementSelector}`)
|
188
116
|
}
|
117
|
+
|
189
118
|
if (!triggerEl) {
|
190
|
-
console.error('Tooltip Kit:
|
119
|
+
console.error('Tooltip Kit: an invalid or unavailable DOM reference was provided!')
|
191
120
|
return []
|
192
121
|
}
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
return triggerEl
|
122
|
+
|
123
|
+
if (!triggerEl.length) triggerEl = [triggerEl]
|
124
|
+
return (this._triggerElements = this._triggerElements || triggerEl)
|
197
125
|
}
|
198
126
|
|
199
127
|
get tooltip() {
|
200
|
-
return (this._tooltip =
|
128
|
+
return (this._tooltip =
|
129
|
+
this._tooltip || this.element.querySelector(`#${this.tooltipId}`))
|
201
130
|
}
|
202
131
|
|
203
132
|
get position() {
|
@@ -223,60 +152,4 @@ export default class PbTooltip extends PbEnhancedElement {
|
|
223
152
|
get triggerMethod() {
|
224
153
|
return this.element.dataset.pbTooltipTriggerMethod || 'hover'
|
225
154
|
}
|
226
|
-
|
227
|
-
get tooltipInteraction() {
|
228
|
-
return this.element.dataset.pbTooltipInteraction === 'true'
|
229
|
-
}
|
230
|
-
|
231
|
-
get delayOpen() {
|
232
|
-
return this.element.dataset.pbTooltipDelayOpen
|
233
|
-
}
|
234
|
-
|
235
|
-
get delayClose() {
|
236
|
-
return this.element.dataset.pbTooltipDelayClose
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
function clearSafeZoneListener(context) {
|
241
|
-
if (context.safeZoneHandler) {
|
242
|
-
document.removeEventListener('mousemove', context.safeZoneHandler)
|
243
|
-
context.safeZoneHandler = null
|
244
|
-
}
|
245
|
-
}
|
246
|
-
|
247
|
-
function getSafeZone(triggerRect, tooltipRect, placement, margin) {
|
248
|
-
let safeRect = {}
|
249
|
-
if (placement.startsWith('top')) {
|
250
|
-
safeRect.left = triggerRect.left - margin
|
251
|
-
safeRect.right = triggerRect.right + margin
|
252
|
-
safeRect.top = tooltipRect.bottom - margin
|
253
|
-
safeRect.bottom = triggerRect.top + margin
|
254
|
-
} else if (placement.startsWith('bottom')) {
|
255
|
-
safeRect.left = triggerRect.left - margin
|
256
|
-
safeRect.right = triggerRect.right + margin
|
257
|
-
safeRect.top = triggerRect.bottom - margin
|
258
|
-
safeRect.bottom = tooltipRect.top + margin
|
259
|
-
} else if (placement.startsWith('left')) {
|
260
|
-
safeRect.top = triggerRect.top - margin
|
261
|
-
safeRect.bottom = triggerRect.bottom + margin
|
262
|
-
safeRect.left = tooltipRect.right - margin
|
263
|
-
safeRect.right = triggerRect.left + margin
|
264
|
-
} else if (placement.startsWith('right')) {
|
265
|
-
safeRect.top = triggerRect.top - margin
|
266
|
-
safeRect.bottom = triggerRect.bottom + margin
|
267
|
-
safeRect.left = triggerRect.right - margin
|
268
|
-
safeRect.right = tooltipRect.left + margin
|
269
|
-
} else {
|
270
|
-
safeRect = {
|
271
|
-
left: triggerRect.left - margin,
|
272
|
-
right: triggerRect.right + margin,
|
273
|
-
top: triggerRect.top - margin,
|
274
|
-
bottom: triggerRect.bottom + margin,
|
275
|
-
}
|
276
|
-
}
|
277
|
-
return safeRect
|
278
|
-
}
|
279
|
-
|
280
|
-
function isPointInsideRect(x, y, rect) {
|
281
|
-
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom
|
282
|
-
}
|
155
|
+
}
|
@@ -1,8 +1,11 @@
|
|
1
|
-
<%=
|
1
|
+
<%= content_tag(:div,
|
2
|
+
id: object.id,
|
3
|
+
data: object.data,
|
4
|
+
class: object.classname,
|
2
5
|
style: remove_height_properties(combined_html_options[:style]) || "",
|
3
6
|
**combined_html_options.except(:style)) do %>
|
4
7
|
<div class="tooltip_tooltip" id="<%= object.tooltip_id %>" role="tooltip" style="<%= object.height_and_width_helper %>">
|
5
8
|
<%= content.presence %>
|
6
9
|
<div class="arrow" id="<%= object.tooltip_id %>-arrow"></div>
|
7
10
|
</div>
|
8
|
-
<% end %>
|
11
|
+
<% end %>
|
@@ -18,18 +18,18 @@ const USERS = [
|
|
18
18
|
territory: "PHL",
|
19
19
|
},
|
20
20
|
{
|
21
|
-
name: "
|
22
|
-
title: "
|
21
|
+
name: "Jason Cypret",
|
22
|
+
title: "Vice President of User Experience",
|
23
23
|
territory: "PHL",
|
24
24
|
},
|
25
25
|
{
|
26
26
|
name: "Stephen Marshall",
|
27
|
-
title: "Senior
|
27
|
+
title: "Senior User Experience Engineer",
|
28
28
|
territory: "PHL",
|
29
29
|
},
|
30
30
|
{
|
31
31
|
name: "Jasper Furniss",
|
32
|
-
title: "
|
32
|
+
title: "Senior User Experience Engineer",
|
33
33
|
territory: "PHL",
|
34
34
|
},
|
35
35
|
];
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import PbEnhancedElement from '../pb_enhanced_element'
|
2
|
-
import { debounce } from '
|
2
|
+
import { debounce } from 'lodash'
|
3
3
|
|
4
4
|
export default class PbTypeahead extends PbEnhancedElement {
|
5
5
|
_searchInput: HTMLInputElement
|
@@ -284,4 +284,4 @@ export default class PbTypeahead extends PbEnhancedElement {
|
|
284
284
|
if (visible) visibilityProperty = '1'
|
285
285
|
this.resultsLoadingIndicator.style.opacity = visibilityProperty
|
286
286
|
}
|
287
|
-
}
|
287
|
+
}
|
@@ -1,8 +1,11 @@
|
|
1
1
|
<% if object.is_react? %>
|
2
2
|
<%= react_component('Typeahead', object.typeahead_react_options) %>
|
3
3
|
<% else %>
|
4
|
-
<%=
|
5
|
-
|
4
|
+
<%= content_tag(:div,
|
5
|
+
id: object.id,
|
6
|
+
data: object.data,
|
7
|
+
class: object.classname + object.inline_class,
|
8
|
+
**combined_html_options) do %>
|
6
9
|
<div class="pb_typeahead_wrapper">
|
7
10
|
<div class="pb_typeahead_loading_indicator" data-pb-typeahead-kit-loading-indicator>
|
8
11
|
<%= pb_rails("icon", props: {
|
@@ -1,4 +1,9 @@
|
|
1
|
-
<%=
|
1
|
+
<%= content_tag(:div,
|
2
|
+
aria: object.aria,
|
3
|
+
class: object.classname,
|
4
|
+
data: object.data,
|
5
|
+
id: object.id,
|
6
|
+
**combined_html_options) do %>
|
2
7
|
<% if object.avatar_url.present? || object.avatar %>
|
3
8
|
<%= pb_rails("avatar", props: {
|
4
9
|
name: object.name,
|