wilday_ui 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/builds/wilday_ui/index.js +214 -8
- data/app/assets/builds/wilday_ui/index.js.map +3 -3
- data/app/assets/stylesheets/wilday_ui/button.css +245 -0
- data/app/helpers/wilday_ui/components/button_helper.rb +219 -19
- data/app/javascript/wilday_ui/controllers/dropdown_controller.js +270 -0
- data/app/javascript/wilday_ui/controllers/index.js +7 -6
- data/app/javascript/wilday_ui/index.js +1 -1
- data/app/views/wilday_ui/_button.html.erb +16 -14
- data/app/views/wilday_ui/button/_content.html.erb +22 -0
- data/app/views/wilday_ui/button/_dropdown_menu.html.erb +26 -0
- data/lib/wilday_ui/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c0fb2e9d7f76dd88e920fa1f552022a53e09cf41f5934a184c750752bcc1f1
|
4
|
+
data.tar.gz: be810e3532a63743bbc6c44def8d285d7359f2b43d3e818a08b26f29f4c12c8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc1bb71dfbb0626d11f5fb25de9d8fecd3f213953c3016a960d7bd7da8fd0705b9906e181b0d282efdfc7679bc04d1eabe7bd08f9fb9c79756df0f0919d0723
|
7
|
+
data.tar.gz: 2664658acf19f2ca4e1ec55f982b3f49b27117c780b663de19d7de94a073e4c6e847f09e0fc0b741d7ab3fc6ec1912d34560a0d7f70ce20e9b83c921a7630f5f
|
@@ -2491,15 +2491,224 @@ var ButtonController = class extends Controller {
|
|
2491
2491
|
}
|
2492
2492
|
};
|
2493
2493
|
|
2494
|
+
// app/javascript/wilday_ui/controllers/dropdown_controller.js
|
2495
|
+
var dropdown_controller_default = class extends Controller {
|
2496
|
+
static targets = ["button", "menu", "submenu"];
|
2497
|
+
static values = {
|
2498
|
+
trigger: { type: String, default: "click" },
|
2499
|
+
position: { type: String, default: "bottom" },
|
2500
|
+
align: { type: String, default: "start" }
|
2501
|
+
};
|
2502
|
+
connect() {
|
2503
|
+
const position = this.element.dataset.dropdownPositionValue;
|
2504
|
+
const align = this.element.dataset.dropdownAlignValue;
|
2505
|
+
if (position) this.positionValue = position;
|
2506
|
+
if (align) this.alignValue = align;
|
2507
|
+
if (this.triggerValue === "hover") {
|
2508
|
+
this.element.addEventListener("mouseenter", () => {
|
2509
|
+
console.log("Mouse enter - showing menu");
|
2510
|
+
this.handleHover(true);
|
2511
|
+
});
|
2512
|
+
this.element.addEventListener("mouseleave", () => {
|
2513
|
+
console.log("Mouse leave - hiding menu");
|
2514
|
+
this.handleHover(false);
|
2515
|
+
});
|
2516
|
+
}
|
2517
|
+
this.element.addEventListener("keydown", this.handleKeydown.bind(this));
|
2518
|
+
document.addEventListener("click", this.handleClickOutside.bind(this));
|
2519
|
+
this.setupSubmenus();
|
2520
|
+
}
|
2521
|
+
disconnect() {
|
2522
|
+
document.removeEventListener("click", this.handleClickOutside.bind(this));
|
2523
|
+
}
|
2524
|
+
handleHover(show) {
|
2525
|
+
if (show) {
|
2526
|
+
this.menuTarget.classList.add("show");
|
2527
|
+
this.buttonTarget.classList.add("active");
|
2528
|
+
this.buttonTarget.setAttribute("aria-expanded", "true");
|
2529
|
+
} else {
|
2530
|
+
this.menuTarget.classList.remove("show");
|
2531
|
+
this.buttonTarget.classList.remove("active");
|
2532
|
+
this.buttonTarget.setAttribute("aria-expanded", "false");
|
2533
|
+
}
|
2534
|
+
}
|
2535
|
+
toggle(event) {
|
2536
|
+
event.preventDefault();
|
2537
|
+
event.stopPropagation();
|
2538
|
+
if (this.isOpen) {
|
2539
|
+
this.menuTarget.classList.remove("show");
|
2540
|
+
} else {
|
2541
|
+
this.menuTarget.classList.add("show");
|
2542
|
+
}
|
2543
|
+
}
|
2544
|
+
show() {
|
2545
|
+
const menuElement = this.element.querySelector(".w-button-dropdown-menu");
|
2546
|
+
const buttonElement = this.element.querySelector(
|
2547
|
+
"[data-dropdown-target='button']"
|
2548
|
+
);
|
2549
|
+
this.updatePosition();
|
2550
|
+
menuElement.classList.add("show");
|
2551
|
+
buttonElement.classList.add("active");
|
2552
|
+
buttonElement.setAttribute("aria-expanded", "true");
|
2553
|
+
menuElement.dataset.position = this.positionValue || "bottom";
|
2554
|
+
menuElement.dataset.align = this.alignValue || "start";
|
2555
|
+
const firstItem = menuElement.querySelector(".w-button-dropdown-item");
|
2556
|
+
if (firstItem) firstItem.focus();
|
2557
|
+
}
|
2558
|
+
hide() {
|
2559
|
+
const menuElement = this.element.querySelector(".w-button-dropdown-menu");
|
2560
|
+
const buttonElement = this.element.querySelector(
|
2561
|
+
"[data-dropdown-target='button']"
|
2562
|
+
);
|
2563
|
+
menuElement.classList.remove("show");
|
2564
|
+
buttonElement.classList.remove("active");
|
2565
|
+
buttonElement.setAttribute("aria-expanded", "false");
|
2566
|
+
}
|
2567
|
+
handleClickOutside(event) {
|
2568
|
+
if (!this.element.contains(event.target)) {
|
2569
|
+
console.log("Click outside detected. Closing all dropdowns.");
|
2570
|
+
this.closeAllSubmenus();
|
2571
|
+
this.hide();
|
2572
|
+
}
|
2573
|
+
}
|
2574
|
+
handleKeydown(event) {
|
2575
|
+
if (!this.isOpen && event.key === "Enter") {
|
2576
|
+
this.show();
|
2577
|
+
return;
|
2578
|
+
}
|
2579
|
+
if (this.isOpen) {
|
2580
|
+
switch (event.key) {
|
2581
|
+
case "Escape":
|
2582
|
+
this.hide();
|
2583
|
+
this.buttonTarget.focus();
|
2584
|
+
break;
|
2585
|
+
case "ArrowDown":
|
2586
|
+
event.preventDefault();
|
2587
|
+
this.focusNextItem();
|
2588
|
+
break;
|
2589
|
+
case "ArrowUp":
|
2590
|
+
event.preventDefault();
|
2591
|
+
this.focusPreviousItem();
|
2592
|
+
break;
|
2593
|
+
case "ArrowRight":
|
2594
|
+
this.openSubmenu(event.target);
|
2595
|
+
break;
|
2596
|
+
case "ArrowLeft":
|
2597
|
+
this.closeSubmenu(event.target);
|
2598
|
+
break;
|
2599
|
+
case "Tab":
|
2600
|
+
this.hide();
|
2601
|
+
break;
|
2602
|
+
}
|
2603
|
+
}
|
2604
|
+
}
|
2605
|
+
setupSubmenus() {
|
2606
|
+
this.element.querySelectorAll(".w-button-dropdown-parent").forEach((parent) => {
|
2607
|
+
const submenu = parent.querySelector(".w-button-dropdown-menu");
|
2608
|
+
const arrow = parent.querySelector(".w-button-dropdown-arrow");
|
2609
|
+
if (!submenu) {
|
2610
|
+
return;
|
2611
|
+
}
|
2612
|
+
const trigger = parent.closest(".w-button-wrapper")?.dataset.dropdownTriggerValue || "click";
|
2613
|
+
if (trigger === "hover") {
|
2614
|
+
parent.addEventListener("mouseenter", () => {
|
2615
|
+
this.showSubmenu(submenu, arrow);
|
2616
|
+
});
|
2617
|
+
parent.addEventListener("mouseleave", () => {
|
2618
|
+
this.hideSubmenu(submenu, arrow);
|
2619
|
+
});
|
2620
|
+
} else if (trigger === "click") {
|
2621
|
+
parent.addEventListener("click", (event) => {
|
2622
|
+
event.stopPropagation();
|
2623
|
+
this.toggleSubmenu(submenu, arrow);
|
2624
|
+
});
|
2625
|
+
document.addEventListener("click", (event) => {
|
2626
|
+
if (!parent.contains(event.target)) {
|
2627
|
+
this.hideSubmenu(submenu, arrow);
|
2628
|
+
}
|
2629
|
+
});
|
2630
|
+
}
|
2631
|
+
});
|
2632
|
+
}
|
2633
|
+
toggleSubmenu(submenu, arrow) {
|
2634
|
+
if (submenu.classList.contains("show")) {
|
2635
|
+
this.hideSubmenu(submenu, arrow);
|
2636
|
+
} else {
|
2637
|
+
this.showSubmenu(submenu, arrow);
|
2638
|
+
}
|
2639
|
+
}
|
2640
|
+
showSubmenu(submenu, arrow) {
|
2641
|
+
submenu.classList.add("show");
|
2642
|
+
submenu.setAttribute("aria-expanded", "true");
|
2643
|
+
if (arrow) {
|
2644
|
+
arrow.classList.add("active");
|
2645
|
+
}
|
2646
|
+
}
|
2647
|
+
hideSubmenu(submenu, arrow) {
|
2648
|
+
submenu.classList.remove("show");
|
2649
|
+
submenu.setAttribute("aria-expanded", "false");
|
2650
|
+
if (arrow) {
|
2651
|
+
arrow.classList.remove("active");
|
2652
|
+
}
|
2653
|
+
}
|
2654
|
+
isParentOpen(parent) {
|
2655
|
+
const parentMenu = parent.closest(".w-button-dropdown-menu");
|
2656
|
+
return parentMenu && parentMenu.classList.contains("show");
|
2657
|
+
}
|
2658
|
+
closeAllSubmenus() {
|
2659
|
+
this.element.querySelectorAll(".w-button-dropdown-menu.show").forEach((menu) => {
|
2660
|
+
menu.classList.remove("show");
|
2661
|
+
menu.setAttribute("aria-expanded", "false");
|
2662
|
+
});
|
2663
|
+
}
|
2664
|
+
openSubmenu(parentItem) {
|
2665
|
+
const submenu = parentItem.querySelector(".w-button-dropdown-menu");
|
2666
|
+
if (submenu) {
|
2667
|
+
this.showSubmenu(submenu);
|
2668
|
+
submenu.querySelector(".w-button-dropdown-item").focus();
|
2669
|
+
}
|
2670
|
+
}
|
2671
|
+
closeSubmenu(parentItem) {
|
2672
|
+
const submenu = parentItem.closest(".w-button-dropdown-menu");
|
2673
|
+
if (submenu) {
|
2674
|
+
this.hideSubmenu(submenu);
|
2675
|
+
parentItem.closest(".w-button-dropdown-parent").focus();
|
2676
|
+
}
|
2677
|
+
}
|
2678
|
+
focusNextItem() {
|
2679
|
+
const items = this.getMenuItems();
|
2680
|
+
const currentIndex = items.indexOf(document.activeElement);
|
2681
|
+
const nextIndex = currentIndex + 1 < items.length ? currentIndex + 1 : 0;
|
2682
|
+
items[nextIndex].focus();
|
2683
|
+
}
|
2684
|
+
focusPreviousItem() {
|
2685
|
+
const items = this.getMenuItems();
|
2686
|
+
const currentIndex = items.indexOf(document.activeElement);
|
2687
|
+
const previousIndex = currentIndex > 0 ? currentIndex - 1 : items.length - 1;
|
2688
|
+
items[previousIndex].focus();
|
2689
|
+
}
|
2690
|
+
getMenuItems() {
|
2691
|
+
return Array.from(
|
2692
|
+
this.menuTarget.querySelectorAll(".w-button-dropdown-item")
|
2693
|
+
);
|
2694
|
+
}
|
2695
|
+
updatePosition() {
|
2696
|
+
const menuElement = this.element.querySelector(".w-button-dropdown-menu");
|
2697
|
+
const position = this.hasPositionValue ? this.positionValue : "bottom";
|
2698
|
+
const align = this.hasAlignValue ? this.alignValue : "start";
|
2699
|
+
menuElement.setAttribute("data-position", position);
|
2700
|
+
menuElement.setAttribute("data-align", align);
|
2701
|
+
}
|
2702
|
+
get isOpen() {
|
2703
|
+
return this.menuTarget.classList.contains("show");
|
2704
|
+
}
|
2705
|
+
};
|
2706
|
+
|
2494
2707
|
// app/javascript/wilday_ui/controllers/index.js
|
2495
2708
|
var application = Application.start();
|
2496
2709
|
window.Stimulus = application;
|
2497
2710
|
application.register("button", ButtonController);
|
2498
|
-
|
2499
|
-
console.log("\u2705 Stimulus is loaded and initialized.");
|
2500
|
-
} else {
|
2501
|
-
console.error("\u274C Stimulus failed to load.");
|
2502
|
-
}
|
2711
|
+
application.register("dropdown", dropdown_controller_default);
|
2503
2712
|
|
2504
2713
|
// app/javascript/wilday_ui/components/button.js
|
2505
2714
|
document.addEventListener("DOMContentLoaded", () => {
|
@@ -2513,7 +2722,4 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
2513
2722
|
});
|
2514
2723
|
});
|
2515
2724
|
});
|
2516
|
-
|
2517
|
-
// app/javascript/wilday_ui/index.js
|
2518
|
-
console.log("JavaScript loaded");
|
2519
2725
|
//# sourceMappingURL=index.js.map
|