@unabridged/midwest 0.12.1 → 0.13.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.
- package/app/assets/javascript/midwest/index.ts +3 -1
- package/app/assets/javascript/midwest.js +86 -1
- package/app/assets/javascript/midwest.js.map +1 -1
- package/app/assets/stylesheets/midwest.css +1 -1
- package/app/assets/stylesheets/midwest.tailwind.css +2 -1
- package/dist/css/midwest.css +1 -1
- package/dist/javascript/collection/app/assets/javascript/midwest/index.js +3 -0
- package/dist/javascript/collection/app/assets/javascript/midwest/index.js.map +1 -1
- package/dist/javascript/collection/app/components/midwest/chart_component/chart_component_controller.js +88 -0
- package/dist/javascript/collection/app/components/midwest/chart_component/chart_component_controller.js.map +1 -0
- package/dist/javascript/midwest.d.ts +25 -1
- package/dist/javascript/midwest.js +86 -1
- package/dist/javascript/midwest.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,9 +14,10 @@ import CountdownTimer from '../../../components/midwest/countdown_timer_componen
|
|
|
14
14
|
import Badge from '../../../components/midwest/badge_component/badge_component_controller'
|
|
15
15
|
import Confirmation from '../../../components/midwest/confirmation_component/confirmation_component_controller'
|
|
16
16
|
import AvatarGroup from '../../../components/midwest/avatar_group_component/avatar_group_component_controller'
|
|
17
|
+
import Chart from '../../../components/midwest/chart_component/chart_component_controller'
|
|
17
18
|
/* IMPORTS */
|
|
18
19
|
|
|
19
|
-
export { Card, Banner, CountdownTimer }
|
|
20
|
+
export { Card, Banner, CountdownTimer, Chart }
|
|
20
21
|
|
|
21
22
|
export function registerMidwestControllers (application: any) {
|
|
22
23
|
application.register('midwest-card', Card)
|
|
@@ -35,5 +36,6 @@ export function registerMidwestControllers (application: any) {
|
|
|
35
36
|
application.register('midwest-badge', Badge)
|
|
36
37
|
application.register('midwest-confirmation', Confirmation)
|
|
37
38
|
application.register('midwest-avatar-group', AvatarGroup)
|
|
39
|
+
application.register('midwest-chart', Chart)
|
|
38
40
|
/* EXPORTS */
|
|
39
41
|
}
|
|
@@ -3656,6 +3656,90 @@ class AvatarGroup extends Controller {
|
|
|
3656
3656
|
}
|
|
3657
3657
|
}
|
|
3658
3658
|
|
|
3659
|
+
class Chart extends Controller {
|
|
3660
|
+
static targets = ["tooltip", "svg"];
|
|
3661
|
+
static values = { tooltipEnabled: { type: Boolean, default: true } };
|
|
3662
|
+
connect() {
|
|
3663
|
+
if (this.tooltipEnabledValue && this.hasTooltipTarget) {
|
|
3664
|
+
this.attachListeners();
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
disconnect() {
|
|
3668
|
+
if (!this.hasSvgTarget)
|
|
3669
|
+
return;
|
|
3670
|
+
this.svgTarget.removeEventListener("pointerover", this.showTooltipOnPointer);
|
|
3671
|
+
this.svgTarget.removeEventListener("pointermove", this.moveTooltip);
|
|
3672
|
+
this.svgTarget.removeEventListener("pointerout", this.hideTooltip);
|
|
3673
|
+
this.svgTarget.removeEventListener("focusin", this.showTooltipOnFocus);
|
|
3674
|
+
this.svgTarget.removeEventListener("focusout", this.hideTooltip);
|
|
3675
|
+
}
|
|
3676
|
+
attachListeners() {
|
|
3677
|
+
this.svgTarget.addEventListener("pointerover", this.showTooltipOnPointer);
|
|
3678
|
+
this.svgTarget.addEventListener("pointermove", this.moveTooltip);
|
|
3679
|
+
this.svgTarget.addEventListener("pointerout", this.hideTooltip);
|
|
3680
|
+
this.svgTarget.addEventListener("focusin", this.showTooltipOnFocus);
|
|
3681
|
+
this.svgTarget.addEventListener("focusout", this.hideTooltip);
|
|
3682
|
+
}
|
|
3683
|
+
// Arrow functions so `this` is stable for add/removeEventListener pairing.
|
|
3684
|
+
showTooltipOnPointer = (event) => {
|
|
3685
|
+
if (!this.hasTooltipTarget)
|
|
3686
|
+
return;
|
|
3687
|
+
const target = event.target.closest("[data-tooltip-content]");
|
|
3688
|
+
if (!target)
|
|
3689
|
+
return;
|
|
3690
|
+
this.tooltipTarget.textContent = target.dataset.tooltipContent ?? "";
|
|
3691
|
+
this.tooltipTarget.classList.add("is-visible");
|
|
3692
|
+
this.positionAtPointer(event);
|
|
3693
|
+
};
|
|
3694
|
+
// Reposition tooltip as the pointer moves within the SVG so it tracks the cursor.
|
|
3695
|
+
moveTooltip = (event) => {
|
|
3696
|
+
if (!this.tooltipTarget.classList.contains("is-visible"))
|
|
3697
|
+
return;
|
|
3698
|
+
this.positionAtPointer(event);
|
|
3699
|
+
};
|
|
3700
|
+
// Show and position the tooltip above the focused element for keyboard users.
|
|
3701
|
+
showTooltipOnFocus = (event) => {
|
|
3702
|
+
if (!this.hasTooltipTarget)
|
|
3703
|
+
return;
|
|
3704
|
+
const target = event.target.closest("[data-tooltip-content]");
|
|
3705
|
+
if (!target)
|
|
3706
|
+
return;
|
|
3707
|
+
this.tooltipTarget.textContent = target.dataset.tooltipContent ?? "";
|
|
3708
|
+
this.tooltipTarget.classList.add("is-visible");
|
|
3709
|
+
this.positionAtElement(target);
|
|
3710
|
+
};
|
|
3711
|
+
hideTooltip = () => {
|
|
3712
|
+
if (!this.hasTooltipTarget)
|
|
3713
|
+
return;
|
|
3714
|
+
this.tooltipTarget.classList.remove("is-visible");
|
|
3715
|
+
};
|
|
3716
|
+
// Position the tooltip relative to the pointer cursor.
|
|
3717
|
+
positionAtPointer(event) {
|
|
3718
|
+
const rect = this.element.getBoundingClientRect();
|
|
3719
|
+
const tipW = this.tooltipTarget.offsetWidth;
|
|
3720
|
+
const tipH = this.tooltipTarget.offsetHeight;
|
|
3721
|
+
const rawLeft = event.clientX - rect.left + 8;
|
|
3722
|
+
const rawTop = event.clientY - rect.top - 28;
|
|
3723
|
+
const left = Math.min(rawLeft, rect.width - tipW - 4);
|
|
3724
|
+
const top = Math.max(rawTop, tipH + 4);
|
|
3725
|
+
this.tooltipTarget.style.left = `${left}px`;
|
|
3726
|
+
this.tooltipTarget.style.top = `${top}px`;
|
|
3727
|
+
}
|
|
3728
|
+
// Position the tooltip centred above a focused SVG element (keyboard navigation).
|
|
3729
|
+
positionAtElement(el) {
|
|
3730
|
+
const containerRect = this.element.getBoundingClientRect();
|
|
3731
|
+
const elRect = el.getBoundingClientRect();
|
|
3732
|
+
const tipW = this.tooltipTarget.offsetWidth;
|
|
3733
|
+
const tipH = this.tooltipTarget.offsetHeight;
|
|
3734
|
+
const rawLeft = elRect.left - containerRect.left + elRect.width / 2 - tipW / 2;
|
|
3735
|
+
const rawTop = elRect.top - containerRect.top - tipH - 8;
|
|
3736
|
+
const left = Math.max(4, Math.min(rawLeft, containerRect.width - tipW - 4));
|
|
3737
|
+
const top = Math.max(4, rawTop);
|
|
3738
|
+
this.tooltipTarget.style.left = `${left}px`;
|
|
3739
|
+
this.tooltipTarget.style.top = `${top}px`;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
|
|
3659
3743
|
function registerMidwestControllers(application) {
|
|
3660
3744
|
application.register("midwest-card", Card);
|
|
3661
3745
|
application.register("midwest-banner", Banner);
|
|
@@ -3673,7 +3757,8 @@ function registerMidwestControllers(application) {
|
|
|
3673
3757
|
application.register("midwest-badge", Badge);
|
|
3674
3758
|
application.register("midwest-confirmation", ConfirmationController);
|
|
3675
3759
|
application.register("midwest-avatar-group", AvatarGroup);
|
|
3760
|
+
application.register("midwest-chart", Chart);
|
|
3676
3761
|
}
|
|
3677
3762
|
|
|
3678
|
-
export { Banner, Card, CountdownTimer, registerMidwestControllers };
|
|
3763
|
+
export { Banner, Card, Chart, CountdownTimer, registerMidwestControllers };
|
|
3679
3764
|
//# sourceMappingURL=midwest.js.map
|