wilday_ui 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50912590c0a438d5c271b389672df9d96c03ddf8001899804d072ddb9e18e925
4
- data.tar.gz: 8924aaef953638212799214a462b906eb05c010a260670e78977e683200b9716
3
+ metadata.gz: 6aae81001c80b4c0fd86eaca5391e6de697a87b88e38215bd1889a70163dafe7
4
+ data.tar.gz: 87cff2dba0f7408ae84456cec4b6aac1927f1bcc27ad09309091c2b43c3df45a
5
5
  SHA512:
6
- metadata.gz: 6d58f3efc56e7e0e32330dd9f5fa5b7098271926a00eeca6c594afe1e496abba345438a82d654a5c0952847e5edc875ed754487135580bfc4e19879b6f801216
7
- data.tar.gz: a771bc6e4cbd382061fa53349d9232cec601776158ff18160bb41132dad50bafaa84286a3c90993a91bc888beab239890ce2088a0ece112cd7abcc2d4404809c
6
+ metadata.gz: '09d8ec007fb7c0757f65ded7d2e059281752c2fdc07cee90aea77dc82b008adb9e07c6161cd527635ceb289121a030b29234a6d5c306a24e68b3d9378e0bfc0e'
7
+ data.tar.gz: da49ca71e648b9e527d02668a83cc6130dcb53ada46f195e9bb19dc4e3a5cf716b9d0b7353f4e68cfdc01416c6bdc5b8a15afc8ea349ea9fe8053be3c74bf318
@@ -2929,6 +2929,242 @@ var confirmation_controller_default = class extends Controller {
2929
2929
  }
2930
2930
  };
2931
2931
 
2932
+ // app/javascript/wilday_ui/controllers/tooltip_controller.js
2933
+ var tooltip_controller_default = class extends Controller {
2934
+ static targets = ["trigger"];
2935
+ static values = {
2936
+ content: String,
2937
+ position: { type: String, default: "top" },
2938
+ align: { type: String, default: "center" },
2939
+ trigger: { type: String, default: "hover" },
2940
+ showDelay: { type: Number, default: 0 },
2941
+ hideDelay: { type: Number, default: 0 },
2942
+ offset: { type: Number, default: 8 },
2943
+ theme: { type: String, default: "light" },
2944
+ size: { type: String, default: "md" },
2945
+ arrow: { type: Boolean, default: false },
2946
+ customStyle: String
2947
+ };
2948
+ connect() {
2949
+ this.tooltipElement = null;
2950
+ this.showTimeoutId = null;
2951
+ this.hideTimeoutId = null;
2952
+ this.setupTooltip();
2953
+ this.scrollHandler = () => {
2954
+ if (this.tooltipElement.style.display !== "none") {
2955
+ const triggerRect = this.triggerTarget.getBoundingClientRect();
2956
+ const isInViewport = triggerRect.top >= 0 && triggerRect.left >= 0 && triggerRect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && triggerRect.right <= (window.innerWidth || document.documentElement.clientWidth);
2957
+ if (isInViewport) {
2958
+ this.position();
2959
+ } else {
2960
+ this.hide();
2961
+ }
2962
+ }
2963
+ };
2964
+ window.addEventListener("scroll", this.scrollHandler);
2965
+ }
2966
+ disconnect() {
2967
+ if (this.clickOutsideHandler) {
2968
+ document.removeEventListener("click", this.clickOutsideHandler);
2969
+ }
2970
+ window.removeEventListener("scroll", this.scrollHandler);
2971
+ this.removeTooltip();
2972
+ }
2973
+ setupTooltip() {
2974
+ this.tooltipElement = this.createTooltipElement();
2975
+ document.body.appendChild(this.tooltipElement);
2976
+ if (this.triggerValue === "hover") {
2977
+ this.triggerTarget.addEventListener("mouseenter", () => this.show());
2978
+ this.triggerTarget.addEventListener("mouseleave", () => this.hide());
2979
+ this.triggerTarget.addEventListener("focusin", () => this.show());
2980
+ this.triggerTarget.addEventListener("focusout", () => this.hide());
2981
+ } else if (this.triggerValue === "click") {
2982
+ const hasDropdown = this.element.hasAttribute("data-controller") && this.element.getAttribute("data-controller").includes("dropdown");
2983
+ const hasClipboard = this.element.hasAttribute("data-controller") && this.element.getAttribute("data-controller").includes("clipboard");
2984
+ if (hasDropdown || hasClipboard) {
2985
+ this.triggerTarget.addEventListener("mouseenter", () => this.show());
2986
+ this.triggerTarget.addEventListener("mouseleave", () => this.hide());
2987
+ } else {
2988
+ this.triggerTarget.addEventListener("click", (e) => {
2989
+ e.stopPropagation();
2990
+ this.toggle();
2991
+ });
2992
+ this.clickOutsideHandler = (e) => {
2993
+ if (!this.triggerTarget.contains(e.target) && !this.tooltipElement.contains(e.target)) {
2994
+ this.hide();
2995
+ }
2996
+ };
2997
+ document.addEventListener("click", this.clickOutsideHandler);
2998
+ }
2999
+ }
3000
+ }
3001
+ createTooltipElement() {
3002
+ const tooltip = document.createElement("div");
3003
+ tooltip.id = this.triggerTarget.getAttribute("aria-describedby");
3004
+ tooltip.className = `w-tooltip w-tooltip-${this.themeValue} w-tooltip-size-${this.sizeValue}`;
3005
+ if (this.arrowValue) tooltip.classList.add("w-tooltip-arrow");
3006
+ tooltip.setAttribute("role", "tooltip");
3007
+ tooltip.setAttribute("data-position", this.positionValue);
3008
+ tooltip.setAttribute("data-align", this.alignValue);
3009
+ tooltip.innerHTML = this.contentValue;
3010
+ if (this.hasCustomStyleValue && this.customStyleValue) {
3011
+ tooltip.style.cssText += this.customStyleValue;
3012
+ }
3013
+ tooltip.style.display = "none";
3014
+ return tooltip;
3015
+ }
3016
+ show() {
3017
+ clearTimeout(this.hideTimeoutId);
3018
+ this.showTimeoutId = setTimeout(() => {
3019
+ this.tooltipElement.style.transform = "none";
3020
+ this.tooltipElement.style.visibility = "hidden";
3021
+ this.tooltipElement.style.display = "block";
3022
+ this.tooltipElement.offsetHeight;
3023
+ this.position();
3024
+ this.tooltipElement.style.visibility = "visible";
3025
+ requestAnimationFrame(() => {
3026
+ this.tooltipElement.classList.add("w-tooltip-visible");
3027
+ });
3028
+ }, this.showDelayValue);
3029
+ }
3030
+ hide() {
3031
+ clearTimeout(this.showTimeoutId);
3032
+ this.hideTimeoutId = setTimeout(() => {
3033
+ this.tooltipElement.classList.remove("w-tooltip-visible");
3034
+ setTimeout(() => {
3035
+ this.tooltipElement.style.display = "none";
3036
+ }, 150);
3037
+ }, this.hideDelayValue);
3038
+ }
3039
+ toggle() {
3040
+ if (this.tooltipElement.style.display === "none") {
3041
+ this.show();
3042
+ } else {
3043
+ this.hide();
3044
+ }
3045
+ }
3046
+ position() {
3047
+ const triggerRect = this.triggerTarget.getBoundingClientRect();
3048
+ const tooltipRect = this.tooltipElement.getBoundingClientRect();
3049
+ const viewportHeight = window.innerHeight;
3050
+ const viewportWidth = window.innerWidth;
3051
+ const arrowOffset = this.arrowValue ? 2 : 0;
3052
+ const scrollX = window.pageXOffset || document.documentElement.scrollLeft;
3053
+ const scrollY = window.pageYOffset || document.documentElement.scrollTop;
3054
+ console.log("=== Initial Values ===");
3055
+ console.log("Viewport Height:", viewportHeight);
3056
+ console.log("Viewport Width:", viewportWidth);
3057
+ console.log("Trigger Top:", triggerRect.top);
3058
+ console.log("Trigger Bottom:", triggerRect.bottom);
3059
+ console.log("Trigger Left:", triggerRect.left);
3060
+ console.log("Trigger Right:", triggerRect.right);
3061
+ console.log("Tooltip Height:", tooltipRect.height);
3062
+ console.log("Tooltip Width:", tooltipRect.width);
3063
+ let position = this.positionValue;
3064
+ let top, left;
3065
+ const spaceBelow = viewportHeight - triggerRect.bottom;
3066
+ const spaceAbove = triggerRect.top;
3067
+ const spaceRight = viewportWidth - triggerRect.right;
3068
+ const spaceLeft = triggerRect.left;
3069
+ const requiredSpaceVertical = tooltipRect.height + this.offsetValue + arrowOffset;
3070
+ const requiredSpaceHorizontal = tooltipRect.width + this.offsetValue + arrowOffset;
3071
+ console.log("\n=== Space Calculation ===");
3072
+ console.log("Space Above:", spaceAbove);
3073
+ console.log("Space Below:", spaceBelow);
3074
+ console.log("Space Left:", spaceLeft);
3075
+ console.log("Space Right:", spaceRight);
3076
+ console.log("Required Space Vertical:", requiredSpaceVertical);
3077
+ console.log("Required Space Horizontal:", requiredSpaceHorizontal);
3078
+ if (position === "right" && spaceRight >= requiredSpaceHorizontal) {
3079
+ position = "right";
3080
+ console.log("Using right - sufficient space");
3081
+ } else if (position === "left" && spaceLeft >= requiredSpaceHorizontal) {
3082
+ position = "left";
3083
+ console.log("Using left - sufficient space");
3084
+ } else if (position === "top" && spaceAbove >= requiredSpaceVertical) {
3085
+ position = "top";
3086
+ console.log("Using top - sufficient space");
3087
+ } else if (position === "bottom" && spaceBelow >= requiredSpaceVertical) {
3088
+ position = "bottom";
3089
+ console.log("Using bottom - sufficient space");
3090
+ } else if (spaceBelow >= requiredSpaceVertical) {
3091
+ position = "bottom";
3092
+ console.log("Fallback to bottom - sufficient space");
3093
+ } else {
3094
+ position = "top";
3095
+ console.log("Fallback to top - insufficient space below");
3096
+ }
3097
+ switch (position) {
3098
+ case "top":
3099
+ top = triggerRect.top - tooltipRect.height - this.offsetValue - arrowOffset;
3100
+ if (this.alignValue === "end") {
3101
+ left = triggerRect.right - tooltipRect.width;
3102
+ } else if (this.alignValue === "center") {
3103
+ left = triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
3104
+ } else {
3105
+ left = triggerRect.left;
3106
+ }
3107
+ break;
3108
+ case "bottom":
3109
+ top = triggerRect.bottom + this.offsetValue + arrowOffset;
3110
+ if (this.alignValue === "end") {
3111
+ left = triggerRect.right - tooltipRect.width;
3112
+ } else if (this.alignValue === "center") {
3113
+ left = triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
3114
+ } else {
3115
+ left = triggerRect.left;
3116
+ }
3117
+ break;
3118
+ case "left":
3119
+ left = triggerRect.left - tooltipRect.width - this.offsetValue - arrowOffset;
3120
+ if (this.alignValue === "end") {
3121
+ top = triggerRect.bottom - tooltipRect.height;
3122
+ } else if (this.alignValue === "center") {
3123
+ top = triggerRect.top + triggerRect.height / 2 - tooltipRect.height / 2;
3124
+ } else {
3125
+ top = triggerRect.top;
3126
+ }
3127
+ break;
3128
+ case "right":
3129
+ left = triggerRect.right + this.offsetValue + arrowOffset;
3130
+ if (this.alignValue === "end") {
3131
+ top = triggerRect.bottom - tooltipRect.height;
3132
+ } else if (this.alignValue === "center") {
3133
+ top = triggerRect.top + triggerRect.height / 2 - tooltipRect.height / 2;
3134
+ } else {
3135
+ top = triggerRect.top;
3136
+ }
3137
+ break;
3138
+ }
3139
+ if (top < 0) {
3140
+ top = this.offsetValue;
3141
+ } else if (top + tooltipRect.height > viewportHeight) {
3142
+ top = viewportHeight - tooltipRect.height - this.offsetValue;
3143
+ }
3144
+ if (left < 0) {
3145
+ left = this.offsetValue;
3146
+ } else if (left + tooltipRect.width > viewportWidth) {
3147
+ left = viewportWidth - tooltipRect.width - this.offsetValue;
3148
+ }
3149
+ console.log("\n=== Final Position ===");
3150
+ console.log("Position:", position);
3151
+ console.log("Top:", top);
3152
+ console.log("Left:", left);
3153
+ console.log("Alignment:", this.alignValue);
3154
+ top += scrollY;
3155
+ left += scrollX;
3156
+ this.tooltipElement.setAttribute("data-position", position);
3157
+ this.tooltipElement.style.top = `${top}px`;
3158
+ this.tooltipElement.style.left = `${left}px`;
3159
+ }
3160
+ removeTooltip() {
3161
+ if (this.tooltipElement) {
3162
+ this.tooltipElement.remove();
3163
+ this.tooltipElement = null;
3164
+ }
3165
+ }
3166
+ };
3167
+
2932
3168
  // app/javascript/wilday_ui/controllers/index.js
2933
3169
  var application = Application.start();
2934
3170
  window.Stimulus = application;
@@ -2936,6 +3172,7 @@ application.register("button", ButtonController);
2936
3172
  application.register("dropdown", dropdown_controller_default);
2937
3173
  application.register("clipboard", clipboard_controller_default);
2938
3174
  application.register("confirmation", confirmation_controller_default);
3175
+ application.register("tooltip", tooltip_controller_default);
2939
3176
 
2940
3177
  // app/javascript/wilday_ui/components/button.js
2941
3178
  document.addEventListener("DOMContentLoaded", () => {