@nuralyui/dropdown 0.0.19 → 0.0.20
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/bundle.js +515 -2
- package/package.json +1 -1
package/bundle.js
CHANGED
|
@@ -1,6 +1,519 @@
|
|
|
1
|
-
import{css as o,LitElement as t,nothing as n,html as i}from"lit";import{property as r,customElement as e}from"lit/decorators.js";import{classMap as d}from"lit/directives/class-map.js";import{styleMap as s}from"lit/directives/style-map.js";import{NuralyUIBaseMixin as a}from"@nuralyui/common/mixins";const l=o`:host{display:inline-block;position:relative;color:var(--nuraly-color-text);font-family:var(--nuraly-dropdown-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif)}.dropdown{position:relative;display:inline-block}.dropdown__trigger{display:inline-block;cursor:pointer}.dropdown__trigger:focus-within{outline:var(--nuraly-focus-outline,2px solid #0f62fe);outline-offset:var(--nuraly-focus-outline-offset,1px)}.dropdown__panel{position:absolute;top:100%;left:0;z-index:var(--nuraly-dropdown-z-index,9999);background:var(--nuraly-color-dropdown-background,#fff);border:var(--nuraly-dropdown-border-width,1px) solid var(--nuraly-color-dropdown-border,#e0e0e0);border-radius:var(--nuraly-dropdown-border-radius,6px);box-shadow:var(--nuraly-dropdown-shadow,0 2px 6px rgba(0,0,0,.15));min-width:var(--nuraly-dropdown-min-width,10rem);max-width:var(--nuraly-dropdown-max-width,20rem);max-height:var(--nuraly-dropdown-max-height,200px);overflow:auto;opacity:0;visibility:hidden;transform:translateY(-8px);transition:all var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease);box-sizing:border-box;isolation:isolate;transform-origin:top center}.dropdown__panel--open{opacity:1;visibility:visible;transform:translateY(0)}:host([open]) .dropdown__panel{opacity:1;visibility:visible;transform:translateY(0)}.dropdown__panel--top,.dropdown__panel--top-end,.dropdown__panel--top-start{top:auto;bottom:100%;margin-bottom:1px;margin-top:0;transform:translateY(8px)}.dropdown__panel--top-end.dropdown__panel--open,.dropdown__panel--top-start.dropdown__panel--open,.dropdown__panel--top.dropdown__panel--open{transform:translateY(0)}.dropdown__panel--bottom-end,.dropdown__panel--top-end{left:auto;right:0}.dropdown__panel--bottom-start,.dropdown__panel--top-start{left:0;right:auto}.dropdown__panel--small{font-size:var(--nuraly-dropdown-small-font-size,.75rem)}.dropdown__panel--medium{font-size:var(--nuraly-dropdown-font-size,.875rem)}.dropdown__panel--large{font-size:var(--nuraly-dropdown-large-font-size,1rem)}.dropdown__panel--none{transition:none}.dropdown__panel--none:not(.dropdown__panel--open){opacity:0;visibility:hidden;transform:none}.dropdown__panel--none.dropdown__panel--open{opacity:1;visibility:visible;transform:none}.dropdown__panel--fade{transition:opacity var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease),visibility var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease)}.dropdown__panel--fade:not(.dropdown__panel--open){opacity:0;visibility:hidden;transform:none}.dropdown__panel--fade.dropdown__panel--open{opacity:1;visibility:visible;transform:none}.dropdown__panel--slide{transition:opacity var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease),visibility var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease),transform var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease)}.dropdown__panel--slide:not(.dropdown__panel--open){opacity:0;visibility:hidden;transform:translateY(-12px)}.dropdown__panel--slide.dropdown__panel--open{opacity:1;visibility:visible;transform:translateY(0)}.dropdown__panel--slide.dropdown__panel--top-end:not(.dropdown__panel--open),.dropdown__panel--slide.dropdown__panel--top-start:not(.dropdown__panel--open),.dropdown__panel--slide.dropdown__panel--top:not(.dropdown__panel--open){transform:translateY(12px)}.dropdown__panel--scale{transition:opacity var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease),visibility var(--nuraly-dropdown-animation-duration,.15s) var(--nuraly-dropdown-animation-timing,ease),transform var(--nuraly-dropdown-animation-duration,.15s) cubic-bezier(.25,.46,.45,.94)}.dropdown__panel--scale:not(.dropdown__panel--open){opacity:0;visibility:hidden;transform:scale(.9) translateY(-8px)}.dropdown__panel--scale.dropdown__panel--open{opacity:1;visibility:visible;transform:scale(1) translateY(0)}.dropdown__panel--scale.dropdown__panel--top-end:not(.dropdown__panel--open),.dropdown__panel--scale.dropdown__panel--top-start:not(.dropdown__panel--open),.dropdown__panel--scale.dropdown__panel--top:not(.dropdown__panel--open){transform:scale(.9) translateY(8px)}.dropdown__panel--scale.dropdown__panel--top-end.dropdown__panel--open,.dropdown__panel--scale.dropdown__panel--top-start.dropdown__panel--open,.dropdown__panel--scale.dropdown__panel--top.dropdown__panel--open{transform:scale(1) translateY(0)}.dropdown__arrow{position:absolute;width:0;height:0;border:var(--nuraly-dropdown-arrow-size) solid transparent;border-bottom-color:var(--nuraly-dropdown-background);top:calc(-1 * var(--nuraly-dropdown-arrow-size) * 2);left:50%;transform:translateX(-50%)}.dropdown__arrow::before{content:'';position:absolute;width:0;height:0;border:calc(var(--nuraly-dropdown-arrow-size) + 1px) solid transparent;border-bottom-color:var(--nuraly-dropdown-border-color);top:calc(-1 * var(--nuraly-dropdown-arrow-size) - 1px);left:calc(-1 * var(--nuraly-dropdown-arrow-size) - 1px)}.dropdown__content{overflow:auto}.dropdown__items{display:flex;flex-direction:column;margin:0;padding:0;list-style:none;overflow:visible}.dropdown__item{display:flex;align-items:center;gap:var(--nuraly-dropdown-item-gap);padding:var(--nuraly-dropdown-item-padding);background:var(--nuraly-color-dropdown-item-background);border:none;color:var(--nuraly-color-dropdown-item-text);cursor:pointer;text-align:left;width:100%;min-height:var(--nuraly-dropdown-item-min-height);transition:var(--nuraly-dropdown-item-transition);font-size:inherit;font-family:inherit;line-height:var(--nuraly-dropdown-item-line-height);position:relative}.dropdown__item:hover:not(.dropdown__item--disabled){background:var(--nuraly-color-dropdown-item-background-hover);color:var(--nuraly-color-dropdown-item-text-hover)}.dropdown__item:focus{outline:0;background:var(--nuraly-color-dropdown-item-background-focus);color:var(--nuraly-color-dropdown-item-text-focus)}.dropdown__item:focus-visible{outline:2px solid var(--nuraly-focus-color,#0f62fe);outline-offset:-2px;background:var(--nuraly-color-dropdown-item-background-focus);color:var(--nuraly-color-dropdown-item-text-focus)}.dropdown__item:active:not(.dropdown__item--disabled){background:var(--nuraly-color-dropdown-item-background-active);color:var(--nuraly-color-dropdown-item-text-active)}.dropdown__item--disabled{opacity:var(--nuraly-dropdown-item-disabled-opacity,.5);cursor:not-allowed;pointer-events:none}.dropdown__item-icon{flex-shrink:0;width:var(--nuraly-dropdown-item-icon-size);height:var(--nuraly-dropdown-item-icon-size)}.dropdown__item-label{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dropdown__divider{height:1px;background:var(--nuraly-dropdown-divider-color);margin:var(--nuraly-dropdown-divider-margin)}.dropdown__item-container{position:relative}:host([has-cascading]) .dropdown__panel{overflow:visible!important;max-height:none!important}:host([has-cascading]) .dropdown__items{overflow:visible!important}:host([has-cascading]) .dropdown__content{overflow:visible!important}.dropdown__item--has-submenu{display:flex;justify-content:space-between;align-items:center}.dropdown__submenu-arrow{margin-left:auto;font-size:.75em;opacity:.6;transition:transform .15s ease}.dropdown__item--has-submenu:hover .dropdown__submenu-arrow{opacity:1}.dropdown__submenu{position:absolute;top:0;z-index:calc(var(--nuraly-dropdown-z-index,9999) + 1);background:var(--nuraly-color-dropdown-background,#fff);border:var(--nuraly-dropdown-border-width,1px) solid var(--nuraly-color-dropdown-border,#e0e0e0);border-radius:var(--nuraly-dropdown-border-radius,6px);box-shadow:var(--nuraly-dropdown-shadow,0 2px 6px rgba(0,0,0,.15));min-width:var(--nuraly-dropdown-min-width,10rem);max-width:var(--nuraly-dropdown-max-width,20rem);max-height:var(--nuraly-dropdown-max-height,200px);overflow:auto;box-sizing:border-box;animation:fadeInSubmenu .15s ease;opacity:1;visibility:visible;pointer-events:auto}.dropdown__custom-content{padding:var(--nuraly-dropdown-item-padding,8px 12px);max-width:100%;box-sizing:border-box}.dropdown__custom-content h3,.dropdown__custom-content h4{margin:0 0 8px 0;font-size:.875rem;font-weight:600;color:var(--nuraly-color-text-primary)}.dropdown__custom-content p{margin:0 0 8px 0;font-size:.75rem;color:var(--nuraly-color-text-secondary);line-height:1.4}.dropdown__custom-content button,.dropdown__custom-content input,.dropdown__custom-content select{width:100%;margin-bottom:8px}.dropdown__custom-content button:last-child,.dropdown__custom-content input:last-child,.dropdown__custom-content p:last-child{margin-bottom:0}.dropdown__submenu--right{left:100%;margin-left:4px}.dropdown__submenu--left{right:100%;margin-right:4px}@keyframes fadeInSubmenu{from{opacity:0;transform:translateX(-8px)}to{opacity:1;transform:translateX(0)}}.dropdown__submenu--left{animation-name:fadeInSubmenuLeft}@keyframes fadeInSubmenuLeft{from{opacity:0;transform:translateX(8px)}to{opacity:1;transform:translateX(0)}}:host(:focus-within) .dropdown__trigger{outline:var(--nuraly-dropdown-focus-outline);outline-offset:var(--nuraly-dropdown-focus-offset)}:host([disabled]){opacity:var(--nuraly-dropdown-disabled-opacity,.5);pointer-events:none}[hidden]{display:none!important}`;class p{constructor(o){this._host=o,this._host.addController(this)}get host(){return this._host}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}requestUpdate(){this._host.requestUpdate()}dispatchEvent(o){return this._host.dispatchEvent(o)}handleError(o,t){console.error(`Dropdown Controller Error in ${t}:`,o)}findElement(o){var t;return null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(o)}findElements(o){var t;return null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelectorAll(o)}}class h extends p{constructor(o){super(o),this._isOpen=!1,this._position={top:0,left:0,width:0,placement:"bottom"},this._triggerElement=null,this._dropdownElement=null,this._outsideClickHandler=null,this._keydownHandler=null,this._hoverTimer=null,this._triggerClickHandler=null,this._triggerHoverHandler=null,this._triggerLeaveHandler=null,this._triggerFocusHandler=null,this._triggerBlurHandler=null,this._scrollHandler=null,this._resizeHandler=null,this._isOpen=o.open}get isOpen(){return this._isOpen}get position(){return Object.assign({},this._position)}hostConnected(){}hostUpdated(){this._isOpen!==this.host.open&&(this._isOpen=this.host.open),this._triggerElement||this.setupTriggerListeners()}hostDisconnected(){this.cleanup()}open(){try{this._isOpen||this.host.disabled||(this._isOpen=!0,this.host.open=!0,this.requestUpdate(),setTimeout((()=>{this.calculatePosition(),this.setupEventListeners()}),10),this.dispatchEvent(new CustomEvent("nr-dropdown-open",{bubbles:!0,composed:!0,detail:{dropdown:this.host}})))}catch(o){this.handleError(o,"open")}}close(){try{this._isOpen&&(this.removeEventListeners(),this._isOpen=!1,this.host.open=!1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-dropdown-close",{bubbles:!0,composed:!0,detail:{dropdown:this.host}})))}catch(o){this.handleError(o,"close")}}toggle(){try{this._isOpen?this.close():this.open()}catch(o){this.handleError(o,"toggle")}}removeTriggerListeners(){this._triggerElement&&(this._triggerClickHandler&&(this._triggerElement.removeEventListener("click",this._triggerClickHandler),this._triggerClickHandler=null),this._triggerHoverHandler&&(this._triggerElement.removeEventListener("mouseenter",this._triggerHoverHandler),this._triggerHoverHandler=null),this._triggerLeaveHandler&&(this._triggerElement.removeEventListener("mouseleave",this._triggerLeaveHandler),this._triggerLeaveHandler=null),this._triggerFocusHandler&&(this._triggerElement.removeEventListener("focusin",this._triggerFocusHandler),this._triggerFocusHandler=null),this._triggerBlurHandler&&(this._triggerElement.removeEventListener("focusout",this._triggerBlurHandler),this._triggerBlurHandler=null))}findDropdownElements(){this._dropdownElement=this.findElement(".dropdown__panel"),this._triggerElement=this.findElement(".dropdown__trigger")}setupTriggerListeners(){if(this.findDropdownElements(),this._triggerElement)switch(this.removeTriggerListeners(),this.host.trigger){case"click":this._triggerClickHandler=this.handleTriggerClick.bind(this),this._triggerElement.addEventListener("click",this._triggerClickHandler);break;case"hover":this._triggerHoverHandler=this.handleTriggerHover.bind(this),this._triggerLeaveHandler=this.handleTriggerLeave.bind(this),this._triggerElement.addEventListener("mouseenter",this._triggerHoverHandler),this._triggerElement.addEventListener("mouseleave",this._triggerLeaveHandler);break;case"focus":this._triggerFocusHandler=this.handleTriggerFocus.bind(this),this._triggerBlurHandler=this.handleTriggerBlur.bind(this),this._triggerElement.addEventListener("focusin",this._triggerFocusHandler),this._triggerElement.addEventListener("focusout",this._triggerBlurHandler)}}setupEventListeners(){this.host.closeOnOutsideClick&&(this._outsideClickHandler=this.handleOutsideClick.bind(this),document.addEventListener("click",this._outsideClickHandler,!0)),this.host.closeOnEscape&&(this._keydownHandler=this.handleKeydown.bind(this),document.addEventListener("keydown",this._keydownHandler)),this._scrollHandler=this.handleScroll.bind(this),this._resizeHandler=this.handleResize.bind(this),window.addEventListener("scroll",this._scrollHandler,!0),window.addEventListener("resize",this._resizeHandler)}removeEventListeners(){this._outsideClickHandler&&(document.removeEventListener("click",this._outsideClickHandler,!0),this._outsideClickHandler=null),this._keydownHandler&&(document.removeEventListener("keydown",this._keydownHandler),this._keydownHandler=null),this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null)}handleTriggerClick(){this.host.disabled||this.toggle()}handleTriggerHover(){this.host.disabled||(this._hoverTimer&&clearTimeout(this._hoverTimer),this._hoverTimer=window.setTimeout((()=>{this.open()}),this.host.delay))}handleTriggerLeave(){this._hoverTimer&&(clearTimeout(this._hoverTimer),this._hoverTimer=null),setTimeout((()=>{this.isHoveringDropdown()||this.close()}),100)}handleTriggerFocus(){this.host.disabled||this.open()}handleTriggerBlur(){setTimeout((()=>{this.isDropdownFocused()||this.close()}),100)}handleOutsideClick(o){var t,n;const i=o.target;if(null===(t=this._triggerElement)||void 0===t?void 0:t.contains(i))return;if(i.closest(".dropdown__panel"))return;if(null===(n=this._dropdownElement)||void 0===n?void 0:n.contains(i))return;if(i.closest("nr-dropdown"))return;if(i.closest(".dropdown__custom-content"))return;if(["INPUT","BUTTON","TEXTAREA","SELECT","A"].includes(i.tagName)){if(i.closest(".dropdown__panel"))return}i.closest(".dropdown")||i.closest('[class*="dropdown"]')||this.host.closeOnOutsideClick&&this.close()}handleKeydown(o){"Escape"===o.key&&this.close()}handleScroll(){}handleResize(){this._isOpen&&this.calculatePosition()}calculatePosition(){var o;try{if(this._dropdownElement&&this._triggerElement||this.findDropdownElements(),!this._dropdownElement||!this._triggerElement)return;const t=this._triggerElement.getBoundingClientRect(),n=((null===(o=window.visualViewport)||void 0===o?void 0:o.height)||window.innerHeight)-t.bottom,i=t.top,r=200,e=this.determineOptimalPlacement(r,i,n);this.applyPlacement(e)}catch(o){this.handleError(o,"calculatePosition")}}determineOptimalPlacement(o,t,n){return n>=o?"bottom":t>=o||t>n?"top":"bottom"}applyPlacement(o){this._dropdownElement&&(this._dropdownElement.classList.remove("dropdown__panel--top","dropdown__panel--bottom"),this._dropdownElement.classList.add(`dropdown__panel--${o}`),this._position.placement=o)}isHoveringDropdown(){var o;return(null===(o=this._dropdownElement)||void 0===o?void 0:o.matches(":hover"))||!1}isDropdownFocused(){var o;const t=document.activeElement;if(!t)return!1;if(null===(o=this._dropdownElement)||void 0===o?void 0:o.contains(t))return!0;if(t.closest(".dropdown__custom-content"))return!0;if(["INPUT","BUTTON","TEXTAREA","SELECT","A"].includes(t.tagName)){if(t.closest(".dropdown__panel"))return!0}return!1}handleItemClick(o){this.dispatchEvent(new CustomEvent("nr-dropdown-item-click",{bubbles:!0,composed:!0,detail:{item:o,dropdown:this.host}})),this.host.autoClose&&this.close()}cleanup(){this.removeEventListeners(),this.removeTriggerListeners(),this._hoverTimer&&(clearTimeout(this._hoverTimer),this._hoverTimer=null)}}
|
|
1
|
+
import{css as o,LitElement as t,nothing as n,html as i}from"lit";import{property as e,customElement as r}from"lit/decorators.js";import{classMap as d}from"lit/directives/class-map.js";import{styleMap as s}from"lit/directives/style-map.js";import{NuralyUIBaseMixin as a}from"@nuralyui/common/mixins";const l=o`
|
|
2
|
+
:host {
|
|
3
|
+
display: inline-block;
|
|
4
|
+
position: relative;
|
|
5
|
+
color: var(--nuraly-color-text);
|
|
6
|
+
font-family: var(--nuraly-dropdown-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.dropdown {
|
|
10
|
+
position: relative;
|
|
11
|
+
display: inline-block;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.dropdown__trigger {
|
|
15
|
+
display: inline-block;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.dropdown__trigger:focus-within {
|
|
20
|
+
outline: var(--nuraly-focus-outline, 2px solid #0f62fe);
|
|
21
|
+
outline-offset: var(--nuraly-focus-outline-offset, 1px);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.dropdown__panel {
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: 100%;
|
|
27
|
+
left: 0;
|
|
28
|
+
z-index: var(--nuraly-dropdown-z-index, 9999);
|
|
29
|
+
background: var(--nuraly-color-dropdown-background, #ffffff);
|
|
30
|
+
border: var(--nuraly-dropdown-border-width, 1px) solid var(--nuraly-color-dropdown-border, #e0e0e0);
|
|
31
|
+
border-radius: var(--nuraly-dropdown-border-radius, 6px);
|
|
32
|
+
box-shadow: var(--nuraly-dropdown-shadow, 0 2px 6px rgba(0, 0, 0, 0.15));
|
|
33
|
+
min-width: var(--nuraly-dropdown-min-width, 10rem);
|
|
34
|
+
max-width: var(--nuraly-dropdown-max-width, 20rem);
|
|
35
|
+
max-height: var(--nuraly-dropdown-max-height, 200px);
|
|
36
|
+
overflow: auto;
|
|
37
|
+
/* Use opacity and visibility for smooth animations */
|
|
38
|
+
opacity: 0;
|
|
39
|
+
visibility: hidden;
|
|
40
|
+
transform: translateY(-8px);
|
|
41
|
+
transition: all var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease);
|
|
42
|
+
/* Ensure proper containment */
|
|
43
|
+
box-sizing: border-box;
|
|
44
|
+
/* Create new stacking context to prevent layering issues */
|
|
45
|
+
isolation: isolate;
|
|
46
|
+
/* Force above other elements */
|
|
47
|
+
transform-origin: top center;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.dropdown__panel--open {
|
|
51
|
+
opacity: 1;
|
|
52
|
+
visibility: visible;
|
|
53
|
+
transform: translateY(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* Alternative attribute-based selector (like select component) */
|
|
57
|
+
:host([open]) .dropdown__panel {
|
|
58
|
+
opacity: 1;
|
|
59
|
+
visibility: visible;
|
|
60
|
+
transform: translateY(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Placement variants */
|
|
64
|
+
.dropdown__panel--top,
|
|
65
|
+
.dropdown__panel--top-start,
|
|
66
|
+
.dropdown__panel--top-end {
|
|
67
|
+
top: auto;
|
|
68
|
+
bottom: 100%;
|
|
69
|
+
margin-bottom: 1px;
|
|
70
|
+
margin-top: 0;
|
|
71
|
+
transform: translateY(8px);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.dropdown__panel--top.dropdown__panel--open,
|
|
75
|
+
.dropdown__panel--top-start.dropdown__panel--open,
|
|
76
|
+
.dropdown__panel--top-end.dropdown__panel--open {
|
|
77
|
+
transform: translateY(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.dropdown__panel--bottom-end,
|
|
81
|
+
.dropdown__panel--top-end {
|
|
82
|
+
left: auto;
|
|
83
|
+
right: 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.dropdown__panel--bottom-start,
|
|
87
|
+
.dropdown__panel--top-start {
|
|
88
|
+
left: 0;
|
|
89
|
+
right: auto;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* Size variants */
|
|
93
|
+
.dropdown__panel--small {
|
|
94
|
+
font-size: var(--nuraly-dropdown-small-font-size, 0.75rem);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.dropdown__panel--medium {
|
|
98
|
+
font-size: var(--nuraly-dropdown-font-size, 0.875rem);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.dropdown__panel--large {
|
|
102
|
+
font-size: var(--nuraly-dropdown-large-font-size, 1rem);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Animation variants */
|
|
106
|
+
|
|
107
|
+
/* No animation - instant show/hide */
|
|
108
|
+
.dropdown__panel--none {
|
|
109
|
+
transition: none;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.dropdown__panel--none:not(.dropdown__panel--open) {
|
|
113
|
+
opacity: 0;
|
|
114
|
+
visibility: hidden;
|
|
115
|
+
transform: none;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.dropdown__panel--none.dropdown__panel--open {
|
|
119
|
+
opacity: 1;
|
|
120
|
+
visibility: visible;
|
|
121
|
+
transform: none;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Fade animation - opacity only */
|
|
125
|
+
.dropdown__panel--fade {
|
|
126
|
+
transition: opacity var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease),
|
|
127
|
+
visibility var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.dropdown__panel--fade:not(.dropdown__panel--open) {
|
|
131
|
+
opacity: 0;
|
|
132
|
+
visibility: hidden;
|
|
133
|
+
transform: none;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.dropdown__panel--fade.dropdown__panel--open {
|
|
137
|
+
opacity: 1;
|
|
138
|
+
visibility: visible;
|
|
139
|
+
transform: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* Slide animation - slide down/up with opacity */
|
|
143
|
+
.dropdown__panel--slide {
|
|
144
|
+
transition: opacity var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease),
|
|
145
|
+
visibility var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease),
|
|
146
|
+
transform var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.dropdown__panel--slide:not(.dropdown__panel--open) {
|
|
150
|
+
opacity: 0;
|
|
151
|
+
visibility: hidden;
|
|
152
|
+
transform: translateY(-12px);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.dropdown__panel--slide.dropdown__panel--open {
|
|
156
|
+
opacity: 1;
|
|
157
|
+
visibility: visible;
|
|
158
|
+
transform: translateY(0);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* For top-positioned dropdowns, slide direction is reversed */
|
|
162
|
+
.dropdown__panel--slide.dropdown__panel--top:not(.dropdown__panel--open),
|
|
163
|
+
.dropdown__panel--slide.dropdown__panel--top-start:not(.dropdown__panel--open),
|
|
164
|
+
.dropdown__panel--slide.dropdown__panel--top-end:not(.dropdown__panel--open) {
|
|
165
|
+
transform: translateY(12px);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Scale animation - scale and opacity */
|
|
169
|
+
.dropdown__panel--scale {
|
|
170
|
+
transition: opacity var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease),
|
|
171
|
+
visibility var(--nuraly-dropdown-animation-duration, 0.15s) var(--nuraly-dropdown-animation-timing, ease),
|
|
172
|
+
transform var(--nuraly-dropdown-animation-duration, 0.15s) cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.dropdown__panel--scale:not(.dropdown__panel--open) {
|
|
176
|
+
opacity: 0;
|
|
177
|
+
visibility: hidden;
|
|
178
|
+
transform: scale(0.9) translateY(-8px);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.dropdown__panel--scale.dropdown__panel--open {
|
|
182
|
+
opacity: 1;
|
|
183
|
+
visibility: visible;
|
|
184
|
+
transform: scale(1) translateY(0);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* For top-positioned scale dropdowns */
|
|
188
|
+
.dropdown__panel--scale.dropdown__panel--top:not(.dropdown__panel--open),
|
|
189
|
+
.dropdown__panel--scale.dropdown__panel--top-start:not(.dropdown__panel--open),
|
|
190
|
+
.dropdown__panel--scale.dropdown__panel--top-end:not(.dropdown__panel--open) {
|
|
191
|
+
transform: scale(0.9) translateY(8px);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.dropdown__panel--scale.dropdown__panel--top.dropdown__panel--open,
|
|
195
|
+
.dropdown__panel--scale.dropdown__panel--top-start.dropdown__panel--open,
|
|
196
|
+
.dropdown__panel--scale.dropdown__panel--top-end.dropdown__panel--open {
|
|
197
|
+
transform: scale(1) translateY(0);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* Arrow */
|
|
201
|
+
.dropdown__arrow {
|
|
202
|
+
position: absolute;
|
|
203
|
+
width: 0;
|
|
204
|
+
height: 0;
|
|
205
|
+
border: var(--nuraly-dropdown-arrow-size) solid transparent;
|
|
206
|
+
border-bottom-color: var(--nuraly-dropdown-background);
|
|
207
|
+
top: calc(-1 * var(--nuraly-dropdown-arrow-size) * 2);
|
|
208
|
+
left: 50%;
|
|
209
|
+
transform: translateX(-50%);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.dropdown__arrow::before {
|
|
213
|
+
content: '';
|
|
214
|
+
position: absolute;
|
|
215
|
+
width: 0;
|
|
216
|
+
height: 0;
|
|
217
|
+
border: calc(var(--nuraly-dropdown-arrow-size) + 1px) solid transparent;
|
|
218
|
+
border-bottom-color: var(--nuraly-dropdown-border-color);
|
|
219
|
+
top: calc(-1 * var(--nuraly-dropdown-arrow-size) - 1px);
|
|
220
|
+
left: calc(-1 * var(--nuraly-dropdown-arrow-size) - 1px);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* Content areas */
|
|
224
|
+
.dropdown__content {
|
|
225
|
+
overflow: auto;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.dropdown__items {
|
|
229
|
+
display: flex;
|
|
230
|
+
flex-direction: column;
|
|
231
|
+
margin: 0;
|
|
232
|
+
padding: 0;
|
|
233
|
+
list-style: none;
|
|
234
|
+
overflow: visible; /* Allow submenus to extend outside */
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.dropdown__item {
|
|
238
|
+
display: flex;
|
|
239
|
+
align-items: center;
|
|
240
|
+
gap: var(--nuraly-dropdown-item-gap);
|
|
241
|
+
padding: var(--nuraly-dropdown-item-padding);
|
|
242
|
+
background: var(--nuraly-color-dropdown-item-background);
|
|
243
|
+
border: none;
|
|
244
|
+
color: var(--nuraly-color-dropdown-item-text);
|
|
245
|
+
cursor: pointer;
|
|
246
|
+
text-align: left;
|
|
247
|
+
width: 100%;
|
|
248
|
+
min-height: var(--nuraly-dropdown-item-min-height);
|
|
249
|
+
transition: var(--nuraly-dropdown-item-transition);
|
|
250
|
+
font-size: inherit;
|
|
251
|
+
font-family: inherit;
|
|
252
|
+
line-height: var(--nuraly-dropdown-item-line-height);
|
|
253
|
+
position: relative;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.dropdown__item:hover:not(.dropdown__item--disabled) {
|
|
257
|
+
background: var(--nuraly-color-dropdown-item-background-hover);
|
|
258
|
+
color: var(--nuraly-color-dropdown-item-text-hover);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.dropdown__item:focus {
|
|
262
|
+
outline: none;
|
|
263
|
+
background: var(--nuraly-color-dropdown-item-background-focus);
|
|
264
|
+
color: var(--nuraly-color-dropdown-item-text-focus);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.dropdown__item:focus-visible {
|
|
268
|
+
outline: 2px solid var(--nuraly-focus-color, #0f62fe);
|
|
269
|
+
outline-offset: -2px;
|
|
270
|
+
background: var(--nuraly-color-dropdown-item-background-focus);
|
|
271
|
+
color: var(--nuraly-color-dropdown-item-text-focus);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.dropdown__item:active:not(.dropdown__item--disabled) {
|
|
275
|
+
background: var(--nuraly-color-dropdown-item-background-active);
|
|
276
|
+
color: var(--nuraly-color-dropdown-item-text-active);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.dropdown__item--disabled {
|
|
280
|
+
opacity: var(--nuraly-dropdown-item-disabled-opacity, 0.5);
|
|
281
|
+
cursor: not-allowed;
|
|
282
|
+
pointer-events: none;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.dropdown__item-icon {
|
|
286
|
+
flex-shrink: 0;
|
|
287
|
+
width: var(--nuraly-dropdown-item-icon-size);
|
|
288
|
+
height: var(--nuraly-dropdown-item-icon-size);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.dropdown__item-label {
|
|
292
|
+
flex: 1;
|
|
293
|
+
overflow: hidden;
|
|
294
|
+
text-overflow: ellipsis;
|
|
295
|
+
white-space: nowrap;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.dropdown__divider {
|
|
299
|
+
height: 1px;
|
|
300
|
+
background: var(--nuraly-dropdown-divider-color);
|
|
301
|
+
margin: var(--nuraly-dropdown-divider-margin);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/* Cascading dropdown styles */
|
|
305
|
+
.dropdown__item-container {
|
|
306
|
+
position: relative;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/* Allow submenus to overflow when dropdown has cascading items */
|
|
310
|
+
:host([has-cascading]) .dropdown__panel {
|
|
311
|
+
overflow: visible !important;
|
|
312
|
+
max-height: none !important; /* Remove height restriction for cascading */
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
:host([has-cascading]) .dropdown__items {
|
|
316
|
+
overflow: visible !important;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/* For cascading dropdowns, we need to handle scrolling differently */
|
|
320
|
+
:host([has-cascading]) .dropdown__content {
|
|
321
|
+
overflow: visible !important;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.dropdown__item--has-submenu {
|
|
325
|
+
display: flex;
|
|
326
|
+
justify-content: space-between;
|
|
327
|
+
align-items: center;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.dropdown__submenu-arrow {
|
|
331
|
+
margin-left: auto;
|
|
332
|
+
font-size: 0.75em;
|
|
333
|
+
opacity: 0.6;
|
|
334
|
+
transition: transform 0.15s ease;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.dropdown__item--has-submenu:hover .dropdown__submenu-arrow {
|
|
338
|
+
opacity: 1;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.dropdown__submenu {
|
|
342
|
+
position: absolute;
|
|
343
|
+
top: 0;
|
|
344
|
+
z-index: calc(var(--nuraly-dropdown-z-index, 9999) + 1);
|
|
345
|
+
background: var(--nuraly-color-dropdown-background, #ffffff);
|
|
346
|
+
border: var(--nuraly-dropdown-border-width, 1px) solid var(--nuraly-color-dropdown-border, #e0e0e0);
|
|
347
|
+
border-radius: var(--nuraly-dropdown-border-radius, 6px);
|
|
348
|
+
box-shadow: var(--nuraly-dropdown-shadow, 0 2px 6px rgba(0, 0, 0, 0.15));
|
|
349
|
+
min-width: var(--nuraly-dropdown-min-width, 10rem);
|
|
350
|
+
max-width: var(--nuraly-dropdown-max-width, 20rem);
|
|
351
|
+
max-height: var(--nuraly-dropdown-max-height, 200px);
|
|
352
|
+
overflow: auto;
|
|
353
|
+
box-sizing: border-box;
|
|
354
|
+
animation: fadeInSubmenu 0.15s ease;
|
|
355
|
+
/* Ensure submenu is visible */
|
|
356
|
+
opacity: 1;
|
|
357
|
+
visibility: visible;
|
|
358
|
+
pointer-events: auto;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.dropdown__custom-content {
|
|
362
|
+
padding: var(--nuraly-dropdown-item-padding, 8px 12px);
|
|
363
|
+
max-width: 100%;
|
|
364
|
+
box-sizing: border-box;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/* Custom content styling */
|
|
368
|
+
.dropdown__custom-content h3,
|
|
369
|
+
.dropdown__custom-content h4 {
|
|
370
|
+
margin: 0 0 8px 0;
|
|
371
|
+
font-size: 0.875rem;
|
|
372
|
+
font-weight: 600;
|
|
373
|
+
color: var(--nuraly-color-text-primary);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.dropdown__custom-content p {
|
|
377
|
+
margin: 0 0 8px 0;
|
|
378
|
+
font-size: 0.75rem;
|
|
379
|
+
color: var(--nuraly-color-text-secondary);
|
|
380
|
+
line-height: 1.4;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.dropdown__custom-content button,
|
|
384
|
+
.dropdown__custom-content input,
|
|
385
|
+
.dropdown__custom-content select {
|
|
386
|
+
width: 100%;
|
|
387
|
+
margin-bottom: 8px;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.dropdown__custom-content button:last-child,
|
|
391
|
+
.dropdown__custom-content input:last-child,
|
|
392
|
+
.dropdown__custom-content p:last-child {
|
|
393
|
+
margin-bottom: 0;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.dropdown__submenu--right {
|
|
397
|
+
left: 100%;
|
|
398
|
+
margin-left: 4px;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.dropdown__submenu--left {
|
|
402
|
+
right: 100%;
|
|
403
|
+
margin-right: 4px;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
@keyframes fadeInSubmenu {
|
|
407
|
+
from {
|
|
408
|
+
opacity: 0;
|
|
409
|
+
transform: translateX(-8px);
|
|
410
|
+
}
|
|
411
|
+
to {
|
|
412
|
+
opacity: 1;
|
|
413
|
+
transform: translateX(0);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.dropdown__submenu--left {
|
|
418
|
+
animation-name: fadeInSubmenuLeft;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
@keyframes fadeInSubmenuLeft {
|
|
422
|
+
from {
|
|
423
|
+
opacity: 0;
|
|
424
|
+
transform: translateX(8px);
|
|
425
|
+
}
|
|
426
|
+
to {
|
|
427
|
+
opacity: 1;
|
|
428
|
+
transform: translateX(0);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/* Focus styles for accessibility */
|
|
433
|
+
:host(:focus-within) .dropdown__trigger {
|
|
434
|
+
outline: var(--nuraly-dropdown-focus-outline);
|
|
435
|
+
outline-offset: var(--nuraly-dropdown-focus-offset);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/* Disabled state */
|
|
439
|
+
:host([disabled]) {
|
|
440
|
+
opacity: var(--nuraly-dropdown-disabled-opacity, 0.5);
|
|
441
|
+
pointer-events: none;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/* Hidden state */
|
|
445
|
+
[hidden] {
|
|
446
|
+
display: none !important;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
`;class p{constructor(o){this._host=o,this._host.addController(this)}get host(){return this._host}hostConnected(){}hostDisconnected(){}hostUpdate(){}hostUpdated(){}requestUpdate(){this._host.requestUpdate()}dispatchEvent(o){return this._host.dispatchEvent(o)}handleError(o,t){console.error(`Dropdown Controller Error in ${t}:`,o)}findElement(o){var t;return null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelector(o)}findElements(o){var t;return null===(t=this._host.shadowRoot)||void 0===t?void 0:t.querySelectorAll(o)}}class h extends p{constructor(o){super(o),this._isOpen=!1,this._position={top:0,left:0,width:0,placement:"bottom"},this._triggerElement=null,this._dropdownElement=null,this._outsideClickHandler=null,this._keydownHandler=null,this._hoverTimer=null,this._triggerClickHandler=null,this._triggerHoverHandler=null,this._triggerLeaveHandler=null,this._triggerFocusHandler=null,this._triggerBlurHandler=null,this._scrollHandler=null,this._resizeHandler=null,this._isOpen=o.open}get isOpen(){return this._isOpen}get position(){return Object.assign({},this._position)}hostConnected(){}hostUpdated(){this._isOpen!==this.host.open&&(this._isOpen=this.host.open),this._triggerElement||this.setupTriggerListeners()}hostDisconnected(){this.cleanup()}open(){try{this._isOpen||this.host.disabled||(this._isOpen=!0,this.host.open=!0,this.requestUpdate(),setTimeout((()=>{this.calculatePosition(),this.setupEventListeners()}),10),this.dispatchEvent(new CustomEvent("nr-dropdown-open",{bubbles:!0,composed:!0,detail:{dropdown:this.host}})))}catch(o){this.handleError(o,"open")}}close(){try{this._isOpen&&(this.removeEventListeners(),this._isOpen=!1,this.host.open=!1,this.requestUpdate(),this.dispatchEvent(new CustomEvent("nr-dropdown-close",{bubbles:!0,composed:!0,detail:{dropdown:this.host}})))}catch(o){this.handleError(o,"close")}}toggle(){try{this._isOpen?this.close():this.open()}catch(o){this.handleError(o,"toggle")}}removeTriggerListeners(){this._triggerElement&&(this._triggerClickHandler&&(this._triggerElement.removeEventListener("click",this._triggerClickHandler),this._triggerClickHandler=null),this._triggerHoverHandler&&(this._triggerElement.removeEventListener("mouseenter",this._triggerHoverHandler),this._triggerHoverHandler=null),this._triggerLeaveHandler&&(this._triggerElement.removeEventListener("mouseleave",this._triggerLeaveHandler),this._triggerLeaveHandler=null),this._triggerFocusHandler&&(this._triggerElement.removeEventListener("focusin",this._triggerFocusHandler),this._triggerFocusHandler=null),this._triggerBlurHandler&&(this._triggerElement.removeEventListener("focusout",this._triggerBlurHandler),this._triggerBlurHandler=null))}findDropdownElements(){this._dropdownElement=this.findElement(".dropdown__panel"),this._triggerElement=this.findElement(".dropdown__trigger")}setupTriggerListeners(){if(this.findDropdownElements(),this._triggerElement)switch(this.removeTriggerListeners(),this.host.trigger){case"click":this._triggerClickHandler=this.handleTriggerClick.bind(this),this._triggerElement.addEventListener("click",this._triggerClickHandler);break;case"hover":this._triggerHoverHandler=this.handleTriggerHover.bind(this),this._triggerLeaveHandler=this.handleTriggerLeave.bind(this),this._triggerElement.addEventListener("mouseenter",this._triggerHoverHandler),this._triggerElement.addEventListener("mouseleave",this._triggerLeaveHandler);break;case"focus":this._triggerFocusHandler=this.handleTriggerFocus.bind(this),this._triggerBlurHandler=this.handleTriggerBlur.bind(this),this._triggerElement.addEventListener("focusin",this._triggerFocusHandler),this._triggerElement.addEventListener("focusout",this._triggerBlurHandler)}}setupEventListeners(){this.host.closeOnOutsideClick&&(this._outsideClickHandler=this.handleOutsideClick.bind(this),document.addEventListener("click",this._outsideClickHandler,!0)),this.host.closeOnEscape&&(this._keydownHandler=this.handleKeydown.bind(this),document.addEventListener("keydown",this._keydownHandler)),this._scrollHandler=this.handleScroll.bind(this),this._resizeHandler=this.handleResize.bind(this),window.addEventListener("scroll",this._scrollHandler,!0),window.addEventListener("resize",this._resizeHandler)}removeEventListeners(){this._outsideClickHandler&&(document.removeEventListener("click",this._outsideClickHandler,!0),this._outsideClickHandler=null),this._keydownHandler&&(document.removeEventListener("keydown",this._keydownHandler),this._keydownHandler=null),this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null)}handleTriggerClick(){this.host.disabled||this.toggle()}handleTriggerHover(){this.host.disabled||(this._hoverTimer&&clearTimeout(this._hoverTimer),this._hoverTimer=window.setTimeout((()=>{this.open()}),this.host.delay))}handleTriggerLeave(){this._hoverTimer&&(clearTimeout(this._hoverTimer),this._hoverTimer=null),setTimeout((()=>{this.isHoveringDropdown()||this.close()}),100)}handleTriggerFocus(){this.host.disabled||this.open()}handleTriggerBlur(){setTimeout((()=>{this.isDropdownFocused()||this.close()}),100)}handleOutsideClick(o){var t,n;const i=o.target;if(null===(t=this._triggerElement)||void 0===t?void 0:t.contains(i))return;if(i.closest(".dropdown__panel"))return;if(null===(n=this._dropdownElement)||void 0===n?void 0:n.contains(i))return;if(i.closest("nr-dropdown"))return;if(i.closest(".dropdown__custom-content"))return;if(["INPUT","BUTTON","TEXTAREA","SELECT","A"].includes(i.tagName)){if(i.closest(".dropdown__panel"))return}i.closest(".dropdown")||i.closest('[class*="dropdown"]')||this.host.closeOnOutsideClick&&this.close()}handleKeydown(o){"Escape"===o.key&&this.close()}handleScroll(){}handleResize(){this._isOpen&&this.calculatePosition()}calculatePosition(){var o;try{if(this._dropdownElement&&this._triggerElement||this.findDropdownElements(),!this._dropdownElement||!this._triggerElement)return;const t=this._triggerElement.getBoundingClientRect(),n=((null===(o=window.visualViewport)||void 0===o?void 0:o.height)||window.innerHeight)-t.bottom,i=t.top,e=200,r=this.determineOptimalPlacement(e,i,n);this.applyPlacement(r)}catch(o){this.handleError(o,"calculatePosition")}}determineOptimalPlacement(o,t,n){return n>=o?"bottom":t>=o||t>n?"top":"bottom"}applyPlacement(o){this._dropdownElement&&(this._dropdownElement.classList.remove("dropdown__panel--top","dropdown__panel--bottom"),this._dropdownElement.classList.add(`dropdown__panel--${o}`),this._position.placement=o)}isHoveringDropdown(){var o;return(null===(o=this._dropdownElement)||void 0===o?void 0:o.matches(":hover"))||!1}isDropdownFocused(){var o;const t=document.activeElement;if(!t)return!1;if(null===(o=this._dropdownElement)||void 0===o?void 0:o.contains(t))return!0;if(t.closest(".dropdown__custom-content"))return!0;if(["INPUT","BUTTON","TEXTAREA","SELECT","A"].includes(t.tagName)){if(t.closest(".dropdown__panel"))return!0}return!1}handleItemClick(o){this.dispatchEvent(new CustomEvent("nr-dropdown-item-click",{bubbles:!0,composed:!0,detail:{item:o,dropdown:this.host}})),this.host.autoClose&&this.close()}cleanup(){this.removeEventListeners(),this.removeTriggerListeners(),this._hoverTimer&&(clearTimeout(this._hoverTimer),this._hoverTimer=null)}}
|
|
2
450
|
/**
|
|
3
451
|
* @license
|
|
4
452
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
5
453
|
* SPDX-License-Identifier: MIT
|
|
6
|
-
*/var
|
|
454
|
+
*/var c=function(o,t,n,i){for(var e,r=arguments.length,d=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i,s=o.length-1;s>=0;s--)(e=o[s])&&(d=(r<3?e(d):r>3?e(t,n,d):e(t,n))||d);return r>3&&d&&Object.defineProperty(t,n,d),d};let u=class extends(a(t)){constructor(){super(...arguments),this.requiredComponents=["nr-icon"],this.items=[],this.open=!1,this.placement="bottom",this.trigger="hover",this.size="medium",this.animation="fade",this.disabled=!1,this.arrow=!1,this.autoClose=!1,this.closeOnOutsideClick=!0,this.closeOnEscape=!0,this.offset=4,this.delay=50,this.maxHeight="300px",this.minWidth="auto",this.cascadeDirection="auto",this.cascadeDelay=50,this.cascadeOnHover=!0,this.dropdownController=new h(this),this.openSubmenus=new Set,this.submenuTimers=new Map,this.handleDropdownPanelClick=o=>{o.stopPropagation()},this.handleItemClick=o=>{o.disabled||(o.options&&o.options.length>0||o.customContent?this.toggleSubmenu(o.id):this.dropdownController.handleItemClick(o))},this.handleItemHover=o=>{var t;if(((null===(t=o.options)||void 0===t?void 0:t.length)||o.customContent)&&(this.clearSubmenuTimer(o.id),this.cascadeOnHover)){const t=window.setTimeout((()=>{this.showSubmenu(o.id)}),this.cascadeDelay);this.submenuTimers.set(o.id,t)}},this.handleItemLeave=o=>{var t;if(!(null===(t=o.options)||void 0===t?void 0:t.length)&&!o.customContent)return;this.clearSubmenuTimer(o.id);const n=window.setTimeout((()=>{this.hideSubmenu(o.id)}),100);this.submenuTimers.set(`hide-${o.id}`,n)},this.handleSubmenuEnter=o=>{this.clearSubmenuTimer(`hide-${o}`)},this.handleSubmenuLeave=o=>{const t=window.setTimeout((()=>{this.hideSubmenu(o)}),100);this.submenuTimers.set(`hide-${o}`,t)}}connectedCallback(){super.connectedCallback(),this.updateCascadingAttribute()}updated(o){super.updated(o),o.has("items")&&this.updateCascadingAttribute()}disconnectedCallback(){super.disconnectedCallback()}firstUpdated(){}updateCascadingAttribute(){this.items.some((o=>o.options&&o.options.length>0||!!o.customContent))?this.setAttribute("has-cascading",""):this.removeAttribute("has-cascading")}clearSubmenuTimer(o){const t=this.submenuTimers.get(o);t&&(clearTimeout(t),this.submenuTimers.delete(o))}toggleSubmenu(o){this.openSubmenus.has(o)?this.hideSubmenu(o):this.showSubmenu(o)}showSubmenu(o){this.openSubmenus.add(o),this.requestUpdate()}hideSubmenu(o){this.openSubmenus.delete(o),this.requestUpdate()}show(){this.dropdownController.open()}hide(){this.dropdownController.close()}toggle(){this.dropdownController.toggle()}renderItems(){return this.items.length?i`
|
|
455
|
+
<div class="dropdown__items">
|
|
456
|
+
${this.items.map((o=>{if(o.divider)return i`<div class="dropdown__divider"></div>`;const t=!!(o.options&&o.options.length>0)||!!o.customContent,e=t&&this.openSubmenus.has(o.id);return i`
|
|
457
|
+
<div class="dropdown__item-container ${d({"dropdown__item-container--has-submenu":t})}">
|
|
458
|
+
<button
|
|
459
|
+
class="dropdown__item ${d({"dropdown__item--disabled":!!o.disabled,"dropdown__item--has-submenu":t})}"
|
|
460
|
+
?disabled="${o.disabled}"
|
|
461
|
+
@click="${()=>this.handleItemClick(o)}"
|
|
462
|
+
@mouseenter="${()=>t&&this.handleItemHover(o)}"
|
|
463
|
+
@mouseleave="${()=>t&&this.handleItemLeave(o)}"
|
|
464
|
+
>
|
|
465
|
+
${o.icon?i`<nr-icon name="${o.icon}" class="dropdown__item-icon"></nr-icon>`:n}
|
|
466
|
+
<span class="dropdown__item-label">${o.label}</span>
|
|
467
|
+
${t?i`<nr-icon name="chevron-right" class="dropdown__submenu-arrow"></nr-icon>`:n}
|
|
468
|
+
</button>
|
|
469
|
+
|
|
470
|
+
${t&&e?i`
|
|
471
|
+
<div class="dropdown__submenu ${d({"dropdown__submenu--right":"right"===this.cascadeDirection||"auto"===this.cascadeDirection,"dropdown__submenu--left":"left"===this.cascadeDirection})}"
|
|
472
|
+
@mouseenter="${()=>this.handleSubmenuEnter(o.id)}"
|
|
473
|
+
@mouseleave="${()=>this.handleSubmenuLeave(o.id)}">
|
|
474
|
+
${o.customContent?i`
|
|
475
|
+
<div class="dropdown__custom-content">
|
|
476
|
+
${"string"==typeof o.customContent?i`<div .innerHTML="${o.customContent}"></div>`:o.customContent}
|
|
477
|
+
</div>
|
|
478
|
+
`:i`
|
|
479
|
+
<div class="dropdown__items">
|
|
480
|
+
${o.options.map((o=>o.divider?i`<div class="dropdown__divider"></div>`:i`
|
|
481
|
+
<button
|
|
482
|
+
class="dropdown__item ${d({"dropdown__item--disabled":!!o.disabled})}"
|
|
483
|
+
?disabled="${o.disabled}"
|
|
484
|
+
@click="${()=>this.handleItemClick(o)}"
|
|
485
|
+
>
|
|
486
|
+
${o.icon?i`<nr-icon name="${o.icon}" class="dropdown__item-icon"></nr-icon>`:n}
|
|
487
|
+
<span class="dropdown__item-label">${o.label}</span>
|
|
488
|
+
</button>
|
|
489
|
+
`))}
|
|
490
|
+
</div>
|
|
491
|
+
`}
|
|
492
|
+
</div>
|
|
493
|
+
`:n}
|
|
494
|
+
</div>
|
|
495
|
+
`}))}
|
|
496
|
+
</div>
|
|
497
|
+
`:n}render(){const o={dropdown__panel:!0,"dropdown__panel--open":this.open,[`dropdown__panel--${this.size}`]:!0,[`dropdown__panel--${this.animation}`]:!0,[`dropdown__panel--${this.placement}`]:!0,"dropdown__panel--with-arrow":this.arrow},t={maxHeight:this.maxHeight,minWidth:this.minWidth};return i`
|
|
498
|
+
<div class="dropdown">
|
|
499
|
+
<div class="dropdown__trigger">
|
|
500
|
+
<slot name="trigger"></slot>
|
|
501
|
+
</div>
|
|
502
|
+
|
|
503
|
+
<div
|
|
504
|
+
class="${d(o)}"
|
|
505
|
+
style="${s(t)}"
|
|
506
|
+
@click="${this.handleDropdownPanelClick}"
|
|
507
|
+
>
|
|
508
|
+
${this.arrow?i`<div class="dropdown__arrow"></div>`:n}
|
|
509
|
+
|
|
510
|
+
<slot name="header"></slot>
|
|
511
|
+
|
|
512
|
+
<div class="dropdown__content">
|
|
513
|
+
<slot name="content">${this.renderItems()}</slot>
|
|
514
|
+
</div>
|
|
515
|
+
|
|
516
|
+
<slot name="footer"></slot>
|
|
517
|
+
</div>
|
|
518
|
+
</div>
|
|
519
|
+
`}};u.styles=l,c([e({type:Array})],u.prototype,"items",void 0),c([e({type:Boolean,reflect:!0})],u.prototype,"open",void 0),c([e({type:String})],u.prototype,"placement",void 0),c([e({type:String})],u.prototype,"trigger",void 0),c([e({type:String})],u.prototype,"size",void 0),c([e({type:String})],u.prototype,"animation",void 0),c([e({type:Boolean})],u.prototype,"disabled",void 0),c([e({type:Boolean})],u.prototype,"arrow",void 0),c([e({type:Boolean,attribute:"auto-close"})],u.prototype,"autoClose",void 0),c([e({type:Boolean,attribute:"close-on-outside-click"})],u.prototype,"closeOnOutsideClick",void 0),c([e({type:Boolean,attribute:"close-on-escape"})],u.prototype,"closeOnEscape",void 0),c([e({type:Number})],u.prototype,"offset",void 0),c([e({type:Number})],u.prototype,"delay",void 0),c([e({type:String,attribute:"max-height"})],u.prototype,"maxHeight",void 0),c([e({type:String,attribute:"min-width"})],u.prototype,"minWidth",void 0),c([e({type:String,attribute:"cascade-direction"})],u.prototype,"cascadeDirection",void 0),c([e({type:Number,attribute:"cascade-delay"})],u.prototype,"cascadeDelay",void 0),c([e({type:Boolean,attribute:"cascade-on-hover"})],u.prototype,"cascadeOnHover",void 0),u=c([r("nr-dropdown")],u);export{u as NrDropdownElement};
|