@instincthub/react-ui 0.1.57 → 0.1.59
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/dist/node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addYears.js +2 -0
- package/dist/node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addYears.js.map +1 -0
- package/dist/node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subYears.js +2 -0
- package/dist/node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subYears.js.map +1 -0
- package/dist/src/assets/css/ui/action.css +6 -2
- package/dist/src/assets/css/ui/dropdown-styles.css +23 -0
- package/dist/src/components/forms/DateRangePicker.js +1 -1
- package/dist/src/components/ui/Action.js +1 -1
- package/dist/src/components/ui/Action.js.map +1 -1
- package/dist/src/components/ui/Dropdown.js +1 -1
- package/dist/src/types/components/ui/Dropdown.d.ts +0 -57
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addYears.js","sources":["../../../../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addYears.js"],"sourcesContent":["import { addMonths } from \"./addMonths.js\";\n\n/**\n * The {@link addYears} function options.\n */\n\n/**\n * @name addYears\n * @category Year Helpers\n * @summary Add the specified number of years to the given date.\n *\n * @description\n * Add the specified number of years to the given date.\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n * @typeParam ResultDate - The result `Date` type.\n *\n * @param date - The date to be changed\n * @param amount - The amount of years to be added.\n * @param options - The options\n *\n * @returns The new date with the years added\n *\n * @example\n * // Add 5 years to 1 September 2014:\n * const result = addYears(new Date(2014, 8, 1), 5)\n * //=> Sun Sep 01 2019 00:00:00\n */\nexport function addYears(date, amount, options) {\n return addMonths(date, amount * 12, options);\n}\n\n// Fallback for modularized imports:\nexport default addYears;\n"],"names":["addYears","date","amount","options","addMonths"],"mappings":"2CA4BO,SAASA,EAASC,EAAMC,EAAQC,GACrC,OAAOC,EAAUH,EAAe,GAATC,EAAaC,EACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subYears.js","sources":["../../../../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subYears.js"],"sourcesContent":["import { addYears } from \"./addYears.js\";\n\n/**\n * The {@link subYears} function options.\n */\n\n/**\n * @name subYears\n * @category Year Helpers\n * @summary Subtract the specified number of years from the given date.\n *\n * @description\n * Subtract the specified number of years from the given date.\n *\n * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).\n * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.\n *\n * @param date - The date to be changed\n * @param amount - The amount of years to be subtracted.\n * @param options - An object with options\n *\n * @returns The new date with the years subtracted\n *\n * @example\n * // Subtract 5 years from 1 September 2014:\n * const result = subYears(new Date(2014, 8, 1), 5)\n * //=> Tue Sep 01 2009 00:00:00\n */\nexport function subYears(date, amount, options) {\n return addYears(date, -amount, options);\n}\n\n// Fallback for modularized imports:\nexport default subYears;\n"],"names":["subYears","date","amount","options","addYears"],"mappings":"yCA4BO,SAASA,EAASC,EAAMC,EAAQC,GACrC,OAAOC,EAASH,GAAOC,EAAQC,EACjC"}
|
|
@@ -184,9 +184,13 @@
|
|
|
184
184
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
185
185
|
border: var(--borderDefault);
|
|
186
186
|
z-index: 20;
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
/* max-height is set inline from the space the chosen side actually has, so
|
|
188
|
+
a long list scrolls in here instead of running off the viewport. The
|
|
189
|
+
scroll is contained: chaining it to the page would move the trigger out
|
|
190
|
+
from under the menu. */
|
|
191
|
+
overflow-x: hidden;
|
|
189
192
|
overflow-y: auto;
|
|
193
|
+
overscroll-behavior: contain;
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
/* Alignment is resolved in JS when the menu is positioned; these remain only
|
|
@@ -88,6 +88,26 @@
|
|
|
88
88
|
left: 0;
|
|
89
89
|
right: auto;
|
|
90
90
|
z-index: 1200;
|
|
91
|
+
/*
|
|
92
|
+
* The menu's max-height is set inline from the space the trigger actually
|
|
93
|
+
* has. Laying it out as a column lets the search box keep its natural height
|
|
94
|
+
* and hands the remainder to the options list, which then scrolls. Without
|
|
95
|
+
* this the list kept its own flat 250px and the menu's `overflow: hidden`
|
|
96
|
+
* clipped whatever the search box pushed past the bottom, with no way to
|
|
97
|
+
* reach it.
|
|
98
|
+
*/
|
|
99
|
+
display: flex;
|
|
100
|
+
flex-direction: column;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.ihub-dropdown-menu-portal .ihub-dropdown-search {
|
|
104
|
+
flex: 0 0 auto;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.ihub-dropdown-menu-portal .ihub-dropdown-options {
|
|
108
|
+
flex: 1 1 auto;
|
|
109
|
+
max-height: none;
|
|
110
|
+
min-height: 0;
|
|
91
111
|
}
|
|
92
112
|
|
|
93
113
|
@keyframes ihub-dropdown-appear {
|
|
@@ -126,6 +146,9 @@
|
|
|
126
146
|
.ihub-dropdown-options {
|
|
127
147
|
max-height: 250px;
|
|
128
148
|
overflow-y: auto;
|
|
149
|
+
/* Do not chain to the page at the ends of the list: that would scroll the
|
|
150
|
+
trigger out from under the menu the user is still reading. */
|
|
151
|
+
overscroll-behavior: contain;
|
|
129
152
|
}
|
|
130
153
|
|
|
131
154
|
.ihub-dropdown-option {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as e}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as n,jsx as t}from"react/jsx-runtime";import a from"@mui/icons-material/CalendarMonthOutlined";import r,{useState as d,useRef as i,useMemo as o,useEffect as l,useCallback as u}from"react";import{endOfWeek as s}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfWeek.js";import{startOfWeek as c}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfWeek.js";import{endOfMonth as m}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfMonth.js";import{subDays as f}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subDays.js";import{formatDate as p}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/format.js";import{startOfDay as h}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfDay.js";import{isBefore as b}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isBefore.js";import{isAfter as v}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isAfter.js";import{startOfMonth as y}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfMonth.js";import{getDay as D}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDay.js";import{getDaysInMonth as N}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDaysInMonth.js";import{isSameDay as M}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isSameDay.js";import{isValid as _}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isValid.js";import{subMonths as g}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subMonths.js";import{addMonths as k}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMonths.js";var w=function(e){if(!e)return null;var n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e.trim());if(n){var t=Number(n[1]),a=Number(n[2])-1,r=Number(n[3]),d=new Date(t,a,r);return d.getFullYear()!==t||d.getMonth()!==a||d.getDate()!==r?null:_(d)?d:null}var i=new Date(e);return _(i)?h(i):null},j=function(_){var j=_.label,C=_.startLabel,O=void 0===C?"From":C,T=_.endLabel,x=void 0===T?"To":T,L=_.value,F=_.onChange,P=_.required,E=void 0!==P&&P,S=_.minDate,A=_.maxDate,W=_.disabledDates,B=void 0===W?[]:W,I=_.dateFormat,K=void 0===I?"yyyy-MM-dd":I,q=_.placeholder,Y=_.errorMessage,H=_.className,Q=void 0===H?"":H,V=_.name,z=_.id,G=_.disabled,J=void 0!==G&&G,R=_.showCalendarIcon,U=void 0===R||R,X=_.showQuickActions,Z=void 0===X||X,$=_.ariaLabel,ee=d(w(null==L?void 0:L.startDate)),ne=e(ee,2),te=ne[0],ae=ne[1],re=d(w(null==L?void 0:L.endDate)),de=e(re,2),ie=de[0],oe=de[1],le=d(null),ue=e(le,2),se=ue[0],ce=ue[1],me=d(!1),fe=e(me,2),pe=fe[0],he=fe[1],be=d(w(null==L?void 0:L.startDate)||new Date),ve=e(be,2),ye=ve[0],De=ve[1],Ne=d("start"),Me=e(Ne,2),_e=Me[0],ge=Me[1],ke=d(null),we=e(ke,2),je=we[0],Ce=we[1],Oe=d(null),Te=e(Oe,2),xe=Te[0],Le=Te[1],Fe=d(null),Pe=e(Fe,2),Ee=Pe[0],Se=Pe[1],Ae=Y||Ee,We=i(null),Be=i(null),Ie=i(null),Ke=i(null),qe=r.useId(),Ye=z||"ihub-daterange-".concat(qe),He="".concat(Ye,"-error"),Qe=Ye,Ve="".concat(Ye,"-end"),ze=o(function(){return w(S)},[S]),Ge=o(function(){return w(A)},[A]);l(function(){if(L){var e=w(L.startDate);ae(e),oe(w(L.endDate)),ce(null),e&&!pe&&De(e)}},[null==L?void 0:L.startDate,null==L?void 0:L.endDate]),l(function(){Y&&Se(null)},[Y]);var Je=u(function(){ce(null),Ce(null),ge("start"),he(!1),Le(null)},[]);l(function(){var e=function(e){Be.current&&!Be.current.contains(e.target)&&Je()};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}},[Je]);var Re=u(function(e){var n=p(e,"yyyy-MM-dd");return B.includes(n)},[B]),Ue=u(function(e){var n=h(e);return(!ze||!b(n,ze))&&(!Ge||!v(n,Ge))},[ze,Ge]),Xe=u(function(e){var n=h(e);return ze&&b(n,ze)&&(n=ze),Ge&&v(n,Ge)&&(n=Ge),ze&&b(n,ze)?null:n},[ze,Ge]),Ze=u(function(e){if(!e)return"";try{return p(e,K)}catch(e){return""}},[K]),$e=u(function(e,n){null==F||F({startDate:e?p(e,"yyyy-MM-dd"):"",endDate:n?p(n,"yyyy-MM-dd"):""})},[F]),en=o(function(){for(var e=ye.getFullYear(),n=ye.getMonth(),t=y(ye),a=D(t),r=N(ye),d=[],i=0;i<a;i++)d.push(null);for(var o=1;o<=r;o++)d.push(new Date(e,n,o));return d},[ye]),nn=function(e,n){var t=Xe(e),a=Xe(n);t&&a&&!v(t,a)?Re(t)||Re(a)?Se("That preset starts or ends on an unavailable date."):(ae(t),oe(a),ce(null),Ce(null),ge("start"),Se(null),De(t),$e(t,a),he(!1),Le(null)):Se("That preset falls outside the allowed date range.")},tn=function(e){if(!J){if(he(!0),Le(e),"start"===e)return ce(null),ge("start"),void(te&&De(te));te&&!ie?(ce(te),ge("end")):(ce(null),ge("start")),ie?De(ie):te&&De(te)}},an=function(e,n){"Enter"!==e.key&&" "!==e.key&&"ArrowDown"!==e.key||(e.preventDefault(),tn(n))},rn=Ze(null!=se?se:te),dn=se?"":Ze(ie);return n("div",{ref:Be,className:"ihub-daterange-picker-wrapper ".concat(Q),onKeyDown:function(e){var n,t;if("Escape"===e.key&&pe){e.stopPropagation();var a=xe;Je(),"end"===a?null===(n=Ke.current)||void 0===n||n.focus():null===(t=Ie.current)||void 0===t||t.focus()}},children:[j&&n("label",{className:"ihub-datetime-label",htmlFor:Qe,children:[j,E&&t("span",{className:"ihub-required",children:"*"})]}),n("div",{className:"ihub-daterange-inputs",children:[n("div",{className:"ihub-daterange-input-container ".concat("start"===xe?"active":""),onClick:function(){return tn("start")},children:[t("input",{ref:Ie,id:Qe,type:"text",className:"ihub-datetime-input",value:rn,readOnly:!0,placeholder:(null==q?void 0:q.start)||O,disabled:J,onKeyDown:function(e){return an(e,"start")},"aria-label":$?"".concat($," start date"):"".concat(O),"aria-invalid":!!Ae||void 0,"aria-describedby":Ae?He:void 0}),U&&t("div",{className:"ihub-datetime-icons",children:t("button",{type:"button",className:"ihub-datetime-icon-btn",disabled:J,"aria-label":"Open calendar for start date","aria-expanded":pe&&"start"===xe,onClick:function(e){e.stopPropagation(),tn("start")},children:t(a,{})})})]}),t("span",{className:"ihub-daterange-separator-arrow","aria-hidden":"true",children:"→"}),n("div",{className:"ihub-daterange-input-container ".concat("end"===xe?"active":""),onClick:function(){return tn("end")},children:[t("input",{ref:Ke,id:Ve,type:"text",className:"ihub-datetime-input",value:dn,readOnly:!0,placeholder:(null==q?void 0:q.end)||x,disabled:J,onKeyDown:function(e){return an(e,"end")},"aria-label":$?"".concat($," end date"):"".concat(x),"aria-invalid":!!Ae||void 0,"aria-describedby":Ae?He:void 0}),U&&t("div",{className:"ihub-datetime-icons",children:t("button",{type:"button",className:"ihub-datetime-icon-btn",disabled:J,"aria-label":"Open calendar for end date","aria-expanded":pe&&"end"===xe,onClick:function(e){e.stopPropagation(),tn("end")},children:t(a,{})})})]})]}),Ae&&t("div",{className:"ihub-datetime-error",id:He,role:"alert",children:Ae}),pe&&!J&&n("div",{ref:We,className:"ihub-datetime-picker-dropdown",role:"dialog","aria-label":"Date range picker",children:[t("div",{className:"ihub-daterange-phase-indicator",children:"start"===_e?"Select start date":"Select end date"}),n("div",{className:"ihub-datetime-calendar",children:[n("div",{className:"ihub-datetime-month-nav",children:[t("button",{type:"button",onClick:function(){return De(g(ye,1))},className:"ihub-datetime-nav-btn","aria-label":"Previous month",children:"‹"}),t("span",{className:"ihub-datetime-month-year","aria-live":"polite",children:p(ye,"MMMM yyyy")}),t("button",{type:"button",onClick:function(){return De(k(ye,1))},className:"ihub-datetime-nav-btn","aria-label":"Next month",children:"›"})]}),t("div",{className:"ihub-datetime-weekdays",children:["Su","Mo","Tu","We","Th","Fr","Sa"].map(function(e){return t("div",{className:"ihub-datetime-weekday",children:e},e)})}),t("div",{className:"ihub-datetime-days",children:en.map(function(e,n){if(!e)return t("div",{className:"ihub-datetime-day-empty"},"empty-".concat(n));var a=Boolean(se&&M(e,se)||!se&&(te&&M(e,te)||ie&&M(e,ie))),r=M(e,new Date),d=Re(e)||!Ue(e),i=function(e){var n=null!=se?se:te;if(!n)return"";var t=se?je:ie,a=n,r=null!=t?t:n;if(b(r,a)){var d=[r,a];a=d[0],r=d[1]}var i=[];return M(e,a)&&i.push("range-start"),t&&M(e,r)&&i.push("range-end"),t&&v(e,a)&&b(e,r)&&!M(e,a)&&!M(e,r)&&i.push("in-range"),i.join(" ")}(e);return t("button",{type:"button",className:"ihub-datetime-day ".concat(a?"selected":""," ").concat(r?"today":""," ").concat(d?"disabled":""," ").concat(i),onClick:function(){return function(e){if(!Re(e)&&Ue(e)){if("start"===_e||!se)return ce(e),ge("end"),Le("end"),void Se(null);var n=se,t=e;if(b(t,n)){var a=[t,n];n=a[0],t=a[1]}ae(n),oe(t),ce(null),Ce(null),ge("start"),Se(null),$e(n,t),he(!1),Le(null)}}(e)},onMouseEnter:function(){se&&Ce(e)},onMouseLeave:function(){return Ce(null)},onFocus:function(){se&&Ce(e)},disabled:d,"aria-label":p(e,"MMMM d, yyyy"),"aria-pressed":a,"aria-current":r?"date":void 0,children:e.getDate()},e.getTime())})})]}),Z&&n("div",{className:"ihub-daterange-presets",children:[t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=h(new Date);nn(e,e)},children:"Today"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=new Date;nn(c(e),h(s(e)))},children:"This Week"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=new Date;nn(y(e),h(m(e)))},children:"This Month"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=h(new Date);nn(f(e,6),e)},children:"Last 7 Days"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=h(new Date);nn(f(e,29),e)},children:"Last 30 Days"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){ae(null),oe(null),ce(null),Ce(null),ge("start"),Le("start"),Se(E?"Please select a date range.":null),$e(null,null)},children:"Clear"})]})]}),(null==V?void 0:V.start)&&t("input",{type:"hidden",name:V.start,value:te?p(te,"yyyy-MM-dd"):""}),(null==V?void 0:V.end)&&t("input",{type:"hidden",name:V.end,value:ie?p(ie,"yyyy-MM-dd"):""})]})};export{j as default};
|
|
1
|
+
import{slicedToArray as e}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as n,jsx as t}from"react/jsx-runtime";import a from"@mui/icons-material/CalendarMonthOutlined";import r,{useState as o,useRef as d,useMemo as i,useEffect as l,useCallback as u,useLayoutEffect as s}from"react";import{addDays as c}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addDays.js";import{addYears as m}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addYears.js";import{subYears as f}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subYears.js";import{endOfWeek as p}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfWeek.js";import{startOfWeek as b}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfWeek.js";import{subDays as h}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subDays.js";import{endOfMonth as v}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfMonth.js";import{formatDate as y}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/format.js";import{startOfDay as g}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfDay.js";import{isBefore as D}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isBefore.js";import{isAfter as M}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isAfter.js";import{startOfMonth as N}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/startOfMonth.js";import{getDay as _}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDay.js";import{getDaysInMonth as k}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDaysInMonth.js";import{isSameDay as w}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isSameDay.js";import{isValid as j}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isValid.js";import{addMonths as C}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/addMonths.js";import{subMonths as F}from"../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/subMonths.js";var x=function(e){if(!e)return null;var n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e.trim());if(n){var t=Number(n[1]),a=Number(n[2])-1,r=Number(n[3]),o=new Date(t,a,r);return o.getFullYear()!==t||o.getMonth()!==a||o.getDate()!==r?null:j(o)?o:null}var d=new Date(e);return j(d)?g(d):null},O=function(j){var O=j.label,T=j.startLabel,L=void 0===T?"From":T,P=j.endLabel,A=void 0===P?"To":P,Y=j.value,E=j.onChange,K=j.required,S=void 0!==K&&K,I=j.minDate,W=j.maxDate,B=j.disabledDates,q=void 0===B?[]:B,H=j.dateFormat,U=void 0===H?"yyyy-MM-dd":H,Q=j.placeholder,R=j.errorMessage,V=j.className,z=void 0===V?"":V,G=j.name,J=j.id,X=j.disabled,Z=void 0!==X&&X,$=j.showCalendarIcon,ee=void 0===$||$,ne=j.showQuickActions,te=void 0===ne||ne,ae=j.ariaLabel,re=o(x(null==Y?void 0:Y.startDate)),oe=e(re,2),de=oe[0],ie=oe[1],le=o(x(null==Y?void 0:Y.endDate)),ue=e(le,2),se=ue[0],ce=ue[1],me=o(null),fe=e(me,2),pe=fe[0],be=fe[1],he=o(!1),ve=e(he,2),ye=ve[0],ge=ve[1],De=o(x(null==Y?void 0:Y.startDate)||new Date),Me=e(De,2),Ne=Me[0],_e=Me[1],ke=o("start"),we=e(ke,2),je=we[0],Ce=we[1],Fe=o(null),xe=e(Fe,2),Oe=xe[0],Te=xe[1],Le=o(null),Pe=e(Le,2),Ae=Pe[0],Ye=Pe[1],Ee=o(null),Ke=e(Ee,2),Se=Ke[0],Ie=Ke[1],We=R||Se,Be=o(null),qe=e(Be,2),He=qe[0],Ue=qe[1],Qe=d(null),Re=d(null),Ve=d(null),ze=d(null),Ge=d(new Map),Je=d(!1),Xe=r.useId(),Ze=J||"ihub-daterange-".concat(Xe),$e="".concat(Ze,"-error"),en=Ze,nn="".concat(Ze,"-end"),tn=i(function(){return x(I)},[I]),an=i(function(){return x(W)},[W]);l(function(){if(Y){var e=x(Y.startDate);ie(e),ce(x(Y.endDate)),be(null),e&&!ye&&_e(e)}},[null==Y?void 0:Y.startDate,null==Y?void 0:Y.endDate]),l(function(){R&&Ie(null)},[R]);var rn=u(function(){be(null),Te(null),Ce("start"),ge(!1),Ye(null),Ue(null)},[]);l(function(){var e=function(e){Re.current&&!Re.current.contains(e.target)&&rn()};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}},[rn]);var on=u(function(e){var n=y(e,"yyyy-MM-dd");return q.includes(n)},[q]),dn=u(function(e){var n=g(e);return(!tn||!D(n,tn))&&(!an||!M(n,an))},[tn,an]),ln=u(function(e){var n=g(e);return tn&&D(n,tn)&&(n=tn),an&&M(n,an)&&(n=an),tn&&D(n,tn)?null:n},[tn,an]),un=u(function(e){if(!e)return"";try{return y(e,U)}catch(e){return""}},[U]),sn=u(function(e,n){null==E||E({startDate:e?y(e,"yyyy-MM-dd"):"",endDate:n?y(n,"yyyy-MM-dd"):""})},[E]),cn=i(function(){for(var e=Ne.getFullYear(),n=Ne.getMonth(),t=N(Ne),a=_(t),r=k(Ne),o=[],d=0;d<a;d++)o.push(null);for(var i=1;i<=r;i++)o.push(new Date(e,n,i));return o},[Ne]),mn=function(e){return y(e,"yyyy-MM-dd")},fn=u(function(e){return!on(e)&&dn(e)},[on,dn]),pn=i(function(){for(var e,n,t=function(e){return e.getMonth()===Ne.getMonth()&&e.getFullYear()===Ne.getFullYear()},a=cn.filter(function(e){return null!==e}),r=0,o=[He,pe,de,se];r<o.length;r++){var d=o[r];if(d&&t(d)&&fn(d))return d}var i=new Date;return t(i)&&fn(i)?i:null!==(e=null!==(n=a.find(fn))&&void 0!==n?n:a[0])&&void 0!==e?e:null},[He,pe,de,se,Ne,cn,fn]),bn=u(function(e,n){for(var t=g(e),a=0;a<=400;a++){if(!dn(t))return;if(!on(t))return Ue(t),t.getMonth()===Ne.getMonth()&&t.getFullYear()===Ne.getFullYear()||_e(N(t)),void(Je.current=!0);t=c(t,n)}},[dn,on,Ne]);s(function(){var e;Je.current&&(Je.current=!1,ye&&He&&(null===(e=Ge.current.get(mn(He)))||void 0===e||e.focus()))});var hn=function(e,n){var t=ln(e),a=ln(n);t&&a&&!M(t,a)?on(t)||on(a)?Ie("That preset starts or ends on an unavailable date."):(ie(t),ce(a),be(null),Te(null),Ce("start"),Ie(null),_e(t),sn(t,a),ge(!1),Ye(null)):Ie("That preset falls outside the allowed date range.")},vn=function(e){if(!Z){if(ge(!0),Ye(e),"start"===e)return be(null),Ce("start"),void(de&&_e(de));de&&!se?(be(de),Ce("end")):(be(null),Ce("start")),se?_e(se):de&&_e(de)}},yn=function(e,n){"Enter"!==e.key&&" "!==e.key&&"ArrowDown"!==e.key||(e.preventDefault(),vn(n))},gn=un(null!=pe?pe:de),Dn=pe?"":un(se);return n("div",{ref:Re,className:"ihub-daterange-picker-wrapper ".concat(z),onKeyDown:function(e){var n,t;if("Escape"===e.key&&ye){e.stopPropagation();var a=Ae;rn(),"end"===a?null===(n=ze.current)||void 0===n||n.focus():null===(t=Ve.current)||void 0===t||t.focus()}},children:[O&&n("label",{className:"ihub-datetime-label",htmlFor:en,children:[O,S&&t("span",{className:"ihub-required",children:"*"})]}),n("div",{className:"ihub-daterange-inputs",children:[n("div",{className:"ihub-daterange-input-container ".concat("start"===Ae?"active":""),onClick:function(){return vn("start")},children:[t("input",{ref:Ve,id:en,type:"text",className:"ihub-datetime-input",value:gn,readOnly:!0,placeholder:(null==Q?void 0:Q.start)||L,disabled:Z,onKeyDown:function(e){return yn(e,"start")},"aria-label":ae?"".concat(ae," start date"):"".concat(L),"aria-invalid":!!We||void 0,"aria-describedby":We?$e:void 0}),ee&&t("div",{className:"ihub-datetime-icons",children:t("button",{type:"button",className:"ihub-datetime-icon-btn",disabled:Z,"aria-label":"Open calendar for start date","aria-expanded":ye&&"start"===Ae,onClick:function(e){e.stopPropagation(),vn("start")},children:t(a,{})})})]}),t("span",{className:"ihub-daterange-separator-arrow","aria-hidden":"true",children:"→"}),n("div",{className:"ihub-daterange-input-container ".concat("end"===Ae?"active":""),onClick:function(){return vn("end")},children:[t("input",{ref:ze,id:nn,type:"text",className:"ihub-datetime-input",value:Dn,readOnly:!0,placeholder:(null==Q?void 0:Q.end)||A,disabled:Z,onKeyDown:function(e){return yn(e,"end")},"aria-label":ae?"".concat(ae," end date"):"".concat(A),"aria-invalid":!!We||void 0,"aria-describedby":We?$e:void 0}),ee&&t("div",{className:"ihub-datetime-icons",children:t("button",{type:"button",className:"ihub-datetime-icon-btn",disabled:Z,"aria-label":"Open calendar for end date","aria-expanded":ye&&"end"===Ae,onClick:function(e){e.stopPropagation(),vn("end")},children:t(a,{})})})]})]}),We&&t("div",{className:"ihub-datetime-error",id:$e,role:"alert",children:We}),ye&&!Z&&n("div",{ref:Qe,className:"ihub-datetime-picker-dropdown",role:"dialog","aria-label":"Date range picker",children:[t("div",{className:"ihub-daterange-phase-indicator",children:"start"===je?"Select start date":"Select end date"}),n("div",{className:"ihub-datetime-calendar",children:[n("div",{className:"ihub-datetime-month-nav",children:[t("button",{type:"button",onClick:function(){return _e(F(Ne,1))},className:"ihub-datetime-nav-btn","aria-label":"Previous month",children:"‹"}),t("span",{className:"ihub-datetime-month-year","aria-live":"polite",children:y(Ne,"MMMM yyyy")}),t("button",{type:"button",onClick:function(){return _e(C(Ne,1))},className:"ihub-datetime-nav-btn","aria-label":"Next month",children:"›"})]}),t("div",{className:"ihub-datetime-weekdays",children:["Su","Mo","Tu","We","Th","Fr","Sa"].map(function(e){return t("div",{className:"ihub-datetime-weekday",children:e},e)})}),t("div",{className:"ihub-datetime-days",children:cn.map(function(e,n){if(!e)return t("div",{className:"ihub-datetime-day-empty"},"empty-".concat(n));var a=Boolean(pe&&w(e,pe)||!pe&&(de&&w(e,de)||se&&w(e,se))),r=w(e,new Date),o=on(e)||!dn(e),d=function(e){var n=null!=pe?pe:de;if(!n)return"";var t=pe?Oe:se,a=n,r=null!=t?t:n;if(D(r,a)){var o=[r,a];a=o[0],r=o[1]}var d=[];return w(e,a)&&d.push("range-start"),t&&w(e,r)&&d.push("range-end"),t&&M(e,a)&&D(e,r)&&!w(e,a)&&!w(e,r)&&d.push("in-range"),d.join(" ")}(e);return t("button",{ref:function(n){var t=mn(e);n?Ge.current.set(t,n):Ge.current.delete(t)},type:"button",className:"ihub-datetime-day ".concat(a?"selected":""," ").concat(r?"today":""," ").concat(o?"disabled":""," ").concat(d),onClick:function(){return function(e){if(!on(e)&&dn(e)){if("start"===je||!pe)return be(e),Ce("end"),Ye("end"),void Ie(null);var n=pe,t=e;if(D(t,n)){var a=[t,n];n=a[0],t=a[1]}ie(n),ce(t),be(null),Te(null),Ce("start"),Ie(null),sn(n,t),ge(!1),Ye(null)}}(e)},onKeyDown:function(n){return function(e,n){var t=e.shiftKey,a=!0;switch(e.key){case"ArrowLeft":bn(h(n,1),-1);break;case"ArrowRight":bn(c(n,1),1);break;case"ArrowUp":bn(h(n,7),-1);break;case"ArrowDown":bn(c(n,7),1);break;case"Home":bn(b(n),1);break;case"End":bn(p(n),-1);break;case"PageUp":bn(t?f(n,1):F(n,1),-1);break;case"PageDown":bn(t?m(n,1):C(n,1),1);break;default:a=!1}a&&(e.preventDefault(),e.stopPropagation())}(n,e)},onMouseEnter:function(){pe&&Te(e)},onMouseLeave:function(){return Te(null)},onFocus:function(){pe&&Te(e)},disabled:o,tabIndex:pn&&w(e,pn)?0:-1,"aria-label":y(e,"MMMM d, yyyy"),"aria-pressed":a,"aria-current":r?"date":void 0,children:e.getDate()},e.getTime())})})]}),te&&n("div",{className:"ihub-daterange-presets",children:[t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=g(new Date);hn(e,e)},children:"Today"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=new Date;hn(b(e),g(p(e)))},children:"This Week"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=new Date;hn(N(e),g(v(e)))},children:"This Month"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=g(new Date);hn(h(e,6),e)},children:"Last 7 Days"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){var e=g(new Date);hn(h(e,29),e)},children:"Last 30 Days"}),t("button",{type:"button",className:"ihub-datetime-action-btn",onClick:function(){ie(null),ce(null),be(null),Te(null),Ce("start"),Ye("start"),Ie(S?"Please select a date range.":null),sn(null,null)},children:"Clear"})]})]}),(null==G?void 0:G.start)&&t("input",{type:"hidden",name:G.start,value:de?y(de,"yyyy-MM-dd"):""}),(null==G?void 0:G.end)&&t("input",{type:"hidden",name:G.end,value:se?y(se,"yyyy-MM-dd"):""})]})};export{O as default};
|
|
2
2
|
//# sourceMappingURL=DateRangePicker.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as n,objectSpread2 as
|
|
1
|
+
import{slicedToArray as n,objectSpread2 as i}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as e,Fragment as t,jsx as o}from"react/jsx-runtime";import r from"react";import{createPortal as a}from"react-dom";import d from"next/link";var c=function(c){var l=c.label,s=c.onClick,u=c.href,h=c.variant,m=void 0===h?"primary":h,f=c.size,p=void 0===f?"medium":f,b=c.fullWidth,v=void 0!==b&&b,w=c.disabled,g=void 0!==w&&w,k=c.iconBefore,N=c.iconAfter,x=c.className,C=void 0===x?"":x,y=c.target,L=c.type,B=void 0===L?"button":L,M=c.animated,E=void 0!==M&&M,H=c.dropdown,j=void 0!==H&&H,P=c.dropdownItems,W=void 0===P?[]:P,z=c.dropdownPosition,R=void 0===z?"right":z,S=r.useState(!1),A=n(S,2),_=A[0],D=A[1],I=r.useRef(null),T=r.useRef(null),q=r.useState({top:0,left:0,maxHeight:0}),F=n(q,2),G=F[0],J=F[1],K=r.useCallback(function(){var n=I.current;if(!n)return!1;var i=n.getBoundingClientRect();if(i.bottom<0||i.top>window.innerHeight||i.right<0||i.left>window.innerWidth)return!1;var e=Math.min(40*W.length+8,300),t=Math.max(i.width,160),o=window.innerHeight-i.bottom-8-8,r=i.top-8-8,a=o<Math.min(e,120)&&r>o,d=Math.max(120,a?r:o),c=Math.min(e,d),l=i.left;return"right"===R?l=i.right-t:"center"===R&&(l=i.left+i.width/2-t/2),J({top:a?i.top-c-8:i.bottom+8,left:Math.max(8,Math.min(l,window.innerWidth-t-8)),maxHeight:c}),!0},[W.length,R]);r.useEffect(function(){if(_){var n=function(n){var i,e,t=n.target;null!==(i=I.current)&&void 0!==i&&i.contains(t)||null!==(e=T.current)&&void 0!==e&&e.contains(t)||D(!1)},i=function(n){var i,e=n.target;e&&null!==(i=T.current)&&void 0!==i&&i.contains(e)||K()||D(!1)},e=function(){K()||D(!1)};return document.addEventListener("mousedown",n),window.addEventListener("scroll",i,!0),window.addEventListener("resize",e),function(){document.removeEventListener("mousedown",n),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",e)}}},[_,K]);var O=["ihub-action","ihub-action-".concat(m),"ihub-action-".concat(p),v?"ihub-action-full-width":"",g?"ihub-action-disabled":"",E?"ihub-action-animated":"",j?"ihub-action-with-dropdown":"",C].filter(Boolean).join(" "),Q=e(t,{children:[k&&o("span",{className:"ihub-action-icon-before",children:k}),o("span",{className:"ihub-action-label",children:l}),j&&o("span",{className:"ihub-action-dropdown-icon",children:o("svg",{width:"12",height:"7",viewBox:"0 0 12 7",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:"primary"===m?{color:"#fff"}:{},children:o("path",{d:"M1 1L6 6L11 1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),!j&&N&&o("span",{className:"ihub-action-icon-after",children:N})]}),U=_&&j&&W.length>0&&o("div",{ref:T,className:"ihub-action-dropdown-menu ihub-action-dropdown-".concat(R),style:{top:G.top,left:G.left,maxHeight:G.maxHeight||void 0},onClick:function(n){return n.stopPropagation()},children:W.map(function(n,i){var r=["ihub-action-dropdown-item",n.disabled?"ihub-action-dropdown-item-disabled":"",n.className||""].filter(Boolean).join(" "),a=e(t,{children:[n.iconBefore&&o("span",{className:"ihub-action-dropdown-item-icon",children:n.iconBefore}),o("span",{className:"ihub-action-dropdown-item-label",children:n.label})]});return n.href&&!n.disabled?o(d,{href:n.href,className:r,onClick:function(){n.onClick&&n.onClick(),D(!1)},children:a},i):o("button",{className:r,onClick:function(){!n.disabled&&n.onClick&&(n.onClick(),D(!1))},disabled:n.disabled,type:"button",children:a},i)})});return function(n){return j?e("div",{className:"ihub-action-dropdown-container",ref:I,children:[n,U&&"undefined"!=typeof document&&a(U,document.body)]}):n}(!u||g||j?o("button",i(i({type:B,className:O,onClick:j?function(n){if(j){if(n.preventDefault(),n.stopPropagation(),_)return void D(!1);K()&&D(!0)}}:s,disabled:g},j?{"aria-haspopup":"menu","aria-expanded":_}:{}),{},{children:Q})):o(d,{href:u,className:O,target:y,onClick:s,children:Q}))};export{c as default};
|
|
2
2
|
//# sourceMappingURL=Action.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.js","sources":["../../../../src/components/ui/Action.tsx"],"sourcesContent":["import React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport Link from \"next/link\";\n\n/**\n * Defines the structure of a dropdown item\n */\nexport interface ActionDropdownItem {\n /** Text label to display for the dropdown item */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the dropdown item is a link */\n href?: string;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Whether the item is disabled */\n disabled?: boolean;\n /** Optional additional class names */\n className?: string;\n}\n\n/**\n * ActionProps interface defines all possible props for the Action component\n */\ninterface ActionProps {\n /** Text label to display in the action element */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the action is a link */\n href?: string;\n /** Visual style variant */\n variant?: \"primary\" | \"secondary\" | \"outline\" | \"danger\" | \"text\";\n /** Size variation */\n size?: \"small\" | \"medium\" | \"large\";\n /** Whether the action should take up full width of container */\n fullWidth?: boolean;\n /** Whether the action is disabled */\n disabled?: boolean;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Icon to display after the label */\n iconAfter?: React.ReactNode;\n /** Optional additional class names */\n className?: string;\n /** Target attribute for links */\n target?: \"_blank\" | \"_self\" | \"_parent\" | \"_top\";\n /** Type attribute for buttons */\n type?: \"button\" | \"submit\" | \"reset\";\n /** Whether to add animation effect */\n animated?: boolean;\n /** Whether to show a dropdown menu */\n dropdown?: boolean;\n /** Items to display in the dropdown menu */\n dropdownItems?: ActionDropdownItem[];\n /** Position of the dropdown menu */\n dropdownPosition?: \"left\" | \"right\" | \"center\";\n}\n\n/**\n * Action component\n * A versatile Action component that can be rendered as a button or link\n * with various styles, sizes, icon options, and dropdown functionality\n * @example\n * <Action\n * label=\"Click Me\"\n * onClick={() => alert('Action clicked!')}\n * variant=\"primary\"\n * size=\"medium\"\n * fullWidth={false}\n * disabled={false}\n * iconBefore={<Icon />}\n * />\n */\nconst Action: React.FC<ActionProps> = ({\n label,\n onClick,\n href,\n variant = \"primary\",\n size = \"medium\",\n fullWidth = false,\n disabled = false,\n iconBefore,\n iconAfter,\n className = \"\",\n target,\n type = \"button\",\n animated = false,\n dropdown = false,\n dropdownItems = [],\n dropdownPosition = \"right\",\n}) => {\n // State to manage dropdown visibility\n const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);\n const dropdownRef = React.useRef<HTMLDivElement>(null);\n const menuRef = React.useRef<HTMLDivElement>(null);\n const [menuPosition, setMenuPosition] = React.useState<{\n top: number;\n left: number;\n }>({ top: 0, left: 0 });\n\n /**\n * Positions the menu from the trigger's bounding box.\n *\n * The menu is rendered into `document.body` rather than beside the trigger,\n * because an absolutely-positioned menu is clipped by any scrolling ancestor\n * — and the most common host for this component is a table row inside\n * `IHubTableServer`'s `.ihub-scroll-container` (`overflow: auto`), which is\n * only as tall as its rows. On a long table the menu had room and looked\n * fine; on a one-row table it was cut to a sliver. Filtering a table down to\n * a single result is exactly when someone reaches for that row's actions, so\n * the broken case was the common one.\n *\n * Flips above the trigger when there is not enough room below, and clamps to\n * the viewport horizontally.\n */\n const positionMenu = React.useCallback(() => {\n const trigger = dropdownRef.current;\n if (!trigger) return;\n\n const rect = trigger.getBoundingClientRect();\n const estimatedHeight = Math.min(dropdownItems.length * 40 + 8, 300);\n const menuWidth = Math.max(rect.width, 160);\n const openUpward =\n window.innerHeight - rect.bottom < estimatedHeight &&\n rect.top > estimatedHeight;\n\n let left = rect.left;\n if (dropdownPosition === \"right\") left = rect.right - menuWidth;\n else if (dropdownPosition === \"center\")\n left = rect.left + rect.width / 2 - menuWidth / 2;\n\n setMenuPosition({\n top: openUpward\n ? rect.top - estimatedHeight - 8\n : rect.bottom + 8,\n left: Math.max(8, Math.min(left, window.innerWidth - menuWidth - 8)),\n });\n }, [dropdownItems.length, dropdownPosition]);\n\n // Handle opening/closing the dropdown\n const toggleDropdown = (e: React.MouseEvent) => {\n if (dropdown) {\n e.preventDefault();\n e.stopPropagation();\n if (!isDropdownOpen) positionMenu();\n setIsDropdownOpen((prev) => !prev);\n }\n };\n\n // Close dropdown when clicking outside\n React.useEffect(() => {\n if (!isDropdownOpen) return;\n\n // Both refs are checked: the menu now lives outside the trigger's subtree,\n // so testing only the container would close it on its own menu items.\n const handleClickOutside = (event: MouseEvent) => {\n const target = event.target as Node;\n if (\n dropdownRef.current?.contains(target) ||\n menuRef.current?.contains(target)\n ) {\n return;\n }\n setIsDropdownOpen(false);\n };\n\n // Fixed coordinates go stale as soon as anything scrolls. Capture phase,\n // because the table's own scroll container never bubbles to window.\n const handleReflow = () => setIsDropdownOpen(false);\n\n document.addEventListener(\"mousedown\", handleClickOutside);\n window.addEventListener(\"scroll\", handleReflow, true);\n window.addEventListener(\"resize\", handleReflow);\n\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n window.removeEventListener(\"scroll\", handleReflow, true);\n window.removeEventListener(\"resize\", handleReflow);\n };\n }, [isDropdownOpen]);\n\n // Construct class names based on props\n const baseClasses = [\n \"ihub-action\",\n `ihub-action-${variant}`,\n `ihub-action-${size}`,\n fullWidth ? \"ihub-action-full-width\" : \"\",\n disabled ? \"ihub-action-disabled\" : \"\",\n animated ? \"ihub-action-animated\" : \"\",\n dropdown ? \"ihub-action-with-dropdown\" : \"\",\n className,\n ]\n .filter(Boolean)\n .join(\" \");\n\n // Common content for both button and link\n const content = (\n <>\n {iconBefore && (\n <span className=\"ihub-action-icon-before\">{iconBefore}</span>\n )}\n <span className=\"ihub-action-label\">{label}</span>\n {dropdown && (\n <span className=\"ihub-action-dropdown-icon\">\n <svg\n width=\"12\"\n height=\"7\"\n viewBox=\"0 0 12 7\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n style={variant === \"primary\" ? { color: \"#fff\" } : {}}\n >\n <path\n d=\"M1 1L6 6L11 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n </span>\n )}\n {!dropdown && iconAfter && (\n <span className=\"ihub-action-icon-after\">{iconAfter}</span>\n )}\n </>\n );\n\n // Dropdown menu\n const dropdownMenu = isDropdownOpen &&\n dropdown &&\n dropdownItems.length > 0 && (\n <div\n ref={menuRef}\n className={`ihub-action-dropdown-menu ihub-action-dropdown-${dropdownPosition}`}\n style={{ top: menuPosition.top, left: menuPosition.left }}\n onClick={(e) => e.stopPropagation()}\n >\n {dropdownItems.map((item, index) => {\n const itemClasses = [\n \"ihub-action-dropdown-item\",\n item.disabled ? \"ihub-action-dropdown-item-disabled\" : \"\",\n item.className || \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n const itemContent = (\n <>\n {item.iconBefore && (\n <span className=\"ihub-action-dropdown-item-icon\">\n {item.iconBefore}\n </span>\n )}\n <span className=\"ihub-action-dropdown-item-label\">\n {item.label}\n </span>\n </>\n );\n\n if (item.href && !item.disabled) {\n return (\n <Link\n key={index}\n href={item.href}\n className={itemClasses}\n onClick={() => {\n if (item.onClick) item.onClick();\n setIsDropdownOpen(false);\n }}\n >\n {itemContent}\n </Link>\n );\n }\n\n return (\n <button\n key={index}\n className={itemClasses}\n onClick={() => {\n if (!item.disabled && item.onClick) {\n item.onClick();\n setIsDropdownOpen(false);\n }\n }}\n disabled={item.disabled}\n type=\"button\"\n >\n {itemContent}\n </button>\n );\n })}\n </div>\n );\n\n // Wrapper to contain both the action and dropdown\n const renderWithDropdown = (actionElement: React.ReactElement) => {\n if (!dropdown) return actionElement;\n\n return (\n <div className=\"ihub-action-dropdown-container\" ref={dropdownRef}>\n {actionElement}\n {dropdownMenu &&\n typeof document !== \"undefined\" &&\n createPortal(dropdownMenu, document.body)}\n </div>\n );\n };\n\n // Render the appropriate element\n const actionElement =\n href && !disabled && !dropdown ? (\n <Link\n href={href}\n className={baseClasses}\n target={target}\n onClick={onClick}\n >\n {content}\n </Link>\n ) : (\n <button\n type={type}\n className={baseClasses}\n onClick={dropdown ? toggleDropdown : onClick}\n disabled={disabled}\n {...(dropdown\n ? { \"aria-haspopup\": \"menu\" as const, \"aria-expanded\": isDropdownOpen }\n : {})}\n >\n {content}\n </button>\n );\n\n return renderWithDropdown(actionElement);\n};\n\nexport default Action;\n"],"names":["Action","_ref","label","onClick","href","_ref$variant","variant","_ref$size","size","_ref$fullWidth","fullWidth","_ref$disabled","disabled","iconBefore","iconAfter","_ref$className","className","target","_ref$type","type","_ref$animated","animated","_ref$dropdown","dropdown","_ref$dropdownItems","dropdownItems","_ref$dropdownPosition","dropdownPosition","_React$useState","React","useState","_React$useState2","_slicedToArray","isDropdownOpen","setIsDropdownOpen","dropdownRef","useRef","menuRef","_React$useState3","top","left","_React$useState4","menuPosition","setMenuPosition","positionMenu","useCallback","trigger","current","rect","getBoundingClientRect","estimatedHeight","Math","min","length","menuWidth","max","width","openUpward","window","innerHeight","bottom","right","innerWidth","useEffect","handleClickOutside","event","_dropdownRef$current","_menuRef$current","contains","handleReflow","document","addEventListener","removeEventListener","baseClasses","concat","filter","Boolean","join","content","_jsxs","_Fragment","children","_jsx","height","viewBox","fill","xmlns","style","color","d","stroke","strokeWidth","strokeLinecap","strokeLinejoin","dropdownMenu","ref","e","stopPropagation","map","item","index","itemClasses","itemContent","Link","actionElement","createPortal","body","renderWithDropdown","_objectSpread","preventDefault","prev"],"mappings":"yPA2EA,IAAMA,EAAgC,SAA1BC,GAiBP,IAhBHC,EAAKD,EAALC,MACAC,EAAOF,EAAPE,QACAC,EAAIH,EAAJG,KAAIC,EAAAJ,EACJK,QAAAA,OAAU,IAAHD,EAAG,UAASA,EAAAE,EAAAN,EACnBO,KAAAA,OAAO,IAAHD,EAAG,SAAQA,EAAAE,EAAAR,EACfS,UAAAA,OAAY,IAAHD,GAAQA,EAAAE,EAAAV,EACjBW,SAAAA,OAAW,IAAHD,GAAQA,EAChBE,EAAUZ,EAAVY,WACAC,EAASb,EAATa,UAASC,EAAAd,EACTe,UAAAA,OAAY,IAAHD,EAAG,GAAEA,EACdE,EAAMhB,EAANgB,OAAMC,EAAAjB,EACNkB,KAAAA,OAAO,IAAHD,EAAG,SAAQA,EAAAE,EAAAnB,EACfoB,SAAAA,OAAW,IAAHD,GAAQA,EAAAE,EAAArB,EAChBsB,SAAAA,OAAW,IAAHD,GAAQA,EAAAE,EAAAvB,EAChBwB,cAAAA,OAAgB,IAAHD,EAAG,GAAEA,EAAAE,EAAAzB,EAClB0B,iBAA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/ui/Action.tsx"],"sourcesContent":["import React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport Link from \"next/link\";\n\n/** Menu geometry. Item height is approximate — it only sizes the menu before\n * it renders; the inline max-height is what actually bounds it. */\nconst ITEM_HEIGHT = 40;\nconst MENU_PADDING = 8;\nconst MENU_GAP = 8;\nconst VIEWPORT_MARGIN = 8;\nconst MIN_MENU_WIDTH = 160;\nconst MAX_MENU_HEIGHT = 300;\nconst MIN_USABLE_HEIGHT = 120;\n\n/**\n * Defines the structure of a dropdown item\n */\nexport interface ActionDropdownItem {\n /** Text label to display for the dropdown item */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the dropdown item is a link */\n href?: string;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Whether the item is disabled */\n disabled?: boolean;\n /** Optional additional class names */\n className?: string;\n}\n\n/**\n * ActionProps interface defines all possible props for the Action component\n */\ninterface ActionProps {\n /** Text label to display in the action element */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the action is a link */\n href?: string;\n /** Visual style variant */\n variant?: \"primary\" | \"secondary\" | \"outline\" | \"danger\" | \"text\";\n /** Size variation */\n size?: \"small\" | \"medium\" | \"large\";\n /** Whether the action should take up full width of container */\n fullWidth?: boolean;\n /** Whether the action is disabled */\n disabled?: boolean;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Icon to display after the label */\n iconAfter?: React.ReactNode;\n /** Optional additional class names */\n className?: string;\n /** Target attribute for links */\n target?: \"_blank\" | \"_self\" | \"_parent\" | \"_top\";\n /** Type attribute for buttons */\n type?: \"button\" | \"submit\" | \"reset\";\n /** Whether to add animation effect */\n animated?: boolean;\n /** Whether to show a dropdown menu */\n dropdown?: boolean;\n /** Items to display in the dropdown menu */\n dropdownItems?: ActionDropdownItem[];\n /** Position of the dropdown menu */\n dropdownPosition?: \"left\" | \"right\" | \"center\";\n}\n\n/**\n * Action component\n * A versatile Action component that can be rendered as a button or link\n * with various styles, sizes, icon options, and dropdown functionality\n * @example\n * <Action\n * label=\"Click Me\"\n * onClick={() => alert('Action clicked!')}\n * variant=\"primary\"\n * size=\"medium\"\n * fullWidth={false}\n * disabled={false}\n * iconBefore={<Icon />}\n * />\n */\nconst Action: React.FC<ActionProps> = ({\n label,\n onClick,\n href,\n variant = \"primary\",\n size = \"medium\",\n fullWidth = false,\n disabled = false,\n iconBefore,\n iconAfter,\n className = \"\",\n target,\n type = \"button\",\n animated = false,\n dropdown = false,\n dropdownItems = [],\n dropdownPosition = \"right\",\n}) => {\n // State to manage dropdown visibility\n const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);\n const dropdownRef = React.useRef<HTMLDivElement>(null);\n const menuRef = React.useRef<HTMLDivElement>(null);\n const [menuPosition, setMenuPosition] = React.useState<{\n top: number;\n left: number;\n maxHeight: number;\n }>({ top: 0, left: 0, maxHeight: 0 });\n\n /**\n * Positions the menu from the trigger's bounding box.\n *\n * The menu is rendered into `document.body` rather than beside the trigger,\n * because an absolutely-positioned menu is clipped by any scrolling ancestor\n * — and the most common host for this component is a table row inside\n * `IHubTableServer`'s `.ihub-scroll-container` (`overflow: auto`), which is\n * only as tall as its rows. On a long table the menu had room and looked\n * fine; on a one-row table it was cut to a sliver. Filtering a table down to\n * a single result is exactly when someone reaches for that row's actions, so\n * the broken case was the common one.\n *\n * Flips above the trigger when there is not enough room below, and clamps to\n * the viewport horizontally.\n */\n const positionMenu = React.useCallback(() => {\n const trigger = dropdownRef.current;\n if (!trigger) return false;\n\n const rect = trigger.getBoundingClientRect();\n\n // Scrolled out of view — including horizontally, since a table scrolls\n // sideways. Nothing to pin the menu to.\n if (\n rect.bottom < 0 ||\n rect.top > window.innerHeight ||\n rect.right < 0 ||\n rect.left > window.innerWidth\n ) {\n return false;\n }\n\n const desiredHeight = Math.min(\n dropdownItems.length * ITEM_HEIGHT + MENU_PADDING,\n MAX_MENU_HEIGHT\n );\n const menuWidth = Math.max(rect.width, MIN_MENU_WIDTH);\n const spaceBelow =\n window.innerHeight - rect.bottom - MENU_GAP - VIEWPORT_MARGIN;\n const spaceAbove = rect.top - MENU_GAP - VIEWPORT_MARGIN;\n\n // Prefer below; flip only when below cannot show a usable amount and above\n // is genuinely roomier.\n const openUpward =\n spaceBelow < Math.min(desiredHeight, MIN_USABLE_HEIGHT) &&\n spaceAbove > spaceBelow;\n\n const available = Math.max(\n MIN_USABLE_HEIGHT,\n openUpward ? spaceAbove : spaceBelow\n );\n const maxHeight = Math.min(desiredHeight, available);\n\n let left = rect.left;\n if (dropdownPosition === \"right\") left = rect.right - menuWidth;\n else if (dropdownPosition === \"center\")\n left = rect.left + rect.width / 2 - menuWidth / 2;\n\n setMenuPosition({\n top: openUpward ? rect.top - maxHeight - MENU_GAP : rect.bottom + MENU_GAP,\n left: Math.max(\n VIEWPORT_MARGIN,\n Math.min(left, window.innerWidth - menuWidth - VIEWPORT_MARGIN)\n ),\n maxHeight,\n });\n return true;\n }, [dropdownItems.length, dropdownPosition]);\n\n // Handle opening/closing the dropdown\n const toggleDropdown = (e: React.MouseEvent) => {\n if (dropdown) {\n e.preventDefault();\n e.stopPropagation();\n if (isDropdownOpen) {\n setIsDropdownOpen(false);\n return;\n }\n // Only open once we know where to put it; otherwise an off-screen\n // trigger would drop the menu in the top-left corner.\n if (positionMenu()) setIsDropdownOpen(true);\n }\n };\n\n // Close dropdown when clicking outside\n React.useEffect(() => {\n if (!isDropdownOpen) return;\n\n // Both refs are checked: the menu now lives outside the trigger's subtree,\n // so testing only the container would close it on its own menu items.\n const handleClickOutside = (event: MouseEvent) => {\n const target = event.target as Node;\n if (\n dropdownRef.current?.contains(target) ||\n menuRef.current?.contains(target)\n ) {\n return;\n }\n setIsDropdownOpen(false);\n };\n\n // Fixed coordinates go stale as soon as anything scrolls, so the menu is\n // repositioned to stay pinned to its trigger. It is NOT closed: the menu\n // caps its own height and scrolls internally, and closing here also fired\n // for scrolls originating INSIDE the menu — which made a list long enough\n // to need scrolling impossible to scroll. Capture phase, because a table's\n // own scroll container never bubbles to window.\n const handleScroll = (event: Event) => {\n const target = event.target as Node | null;\n if (target && menuRef.current?.contains(target)) return;\n if (!positionMenu()) setIsDropdownOpen(false);\n };\n\n const handleResize = () => {\n if (!positionMenu()) setIsDropdownOpen(false);\n };\n\n document.addEventListener(\"mousedown\", handleClickOutside);\n window.addEventListener(\"scroll\", handleScroll, true);\n window.addEventListener(\"resize\", handleResize);\n\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n window.removeEventListener(\"scroll\", handleScroll, true);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [isDropdownOpen, positionMenu]);\n\n // Construct class names based on props\n const baseClasses = [\n \"ihub-action\",\n `ihub-action-${variant}`,\n `ihub-action-${size}`,\n fullWidth ? \"ihub-action-full-width\" : \"\",\n disabled ? \"ihub-action-disabled\" : \"\",\n animated ? \"ihub-action-animated\" : \"\",\n dropdown ? \"ihub-action-with-dropdown\" : \"\",\n className,\n ]\n .filter(Boolean)\n .join(\" \");\n\n // Common content for both button and link\n const content = (\n <>\n {iconBefore && (\n <span className=\"ihub-action-icon-before\">{iconBefore}</span>\n )}\n <span className=\"ihub-action-label\">{label}</span>\n {dropdown && (\n <span className=\"ihub-action-dropdown-icon\">\n <svg\n width=\"12\"\n height=\"7\"\n viewBox=\"0 0 12 7\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n style={variant === \"primary\" ? { color: \"#fff\" } : {}}\n >\n <path\n d=\"M1 1L6 6L11 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n </span>\n )}\n {!dropdown && iconAfter && (\n <span className=\"ihub-action-icon-after\">{iconAfter}</span>\n )}\n </>\n );\n\n // Dropdown menu\n const dropdownMenu = isDropdownOpen &&\n dropdown &&\n dropdownItems.length > 0 && (\n <div\n ref={menuRef}\n className={`ihub-action-dropdown-menu ihub-action-dropdown-${dropdownPosition}`}\n style={{\n top: menuPosition.top,\n left: menuPosition.left,\n maxHeight: menuPosition.maxHeight || undefined,\n }}\n onClick={(e) => e.stopPropagation()}\n >\n {dropdownItems.map((item, index) => {\n const itemClasses = [\n \"ihub-action-dropdown-item\",\n item.disabled ? \"ihub-action-dropdown-item-disabled\" : \"\",\n item.className || \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n const itemContent = (\n <>\n {item.iconBefore && (\n <span className=\"ihub-action-dropdown-item-icon\">\n {item.iconBefore}\n </span>\n )}\n <span className=\"ihub-action-dropdown-item-label\">\n {item.label}\n </span>\n </>\n );\n\n if (item.href && !item.disabled) {\n return (\n <Link\n key={index}\n href={item.href}\n className={itemClasses}\n onClick={() => {\n if (item.onClick) item.onClick();\n setIsDropdownOpen(false);\n }}\n >\n {itemContent}\n </Link>\n );\n }\n\n return (\n <button\n key={index}\n className={itemClasses}\n onClick={() => {\n if (!item.disabled && item.onClick) {\n item.onClick();\n setIsDropdownOpen(false);\n }\n }}\n disabled={item.disabled}\n type=\"button\"\n >\n {itemContent}\n </button>\n );\n })}\n </div>\n );\n\n // Wrapper to contain both the action and dropdown\n const renderWithDropdown = (actionElement: React.ReactElement) => {\n if (!dropdown) return actionElement;\n\n return (\n <div className=\"ihub-action-dropdown-container\" ref={dropdownRef}>\n {actionElement}\n {dropdownMenu &&\n typeof document !== \"undefined\" &&\n createPortal(dropdownMenu, document.body)}\n </div>\n );\n };\n\n // Render the appropriate element\n const actionElement =\n href && !disabled && !dropdown ? (\n <Link\n href={href}\n className={baseClasses}\n target={target}\n onClick={onClick}\n >\n {content}\n </Link>\n ) : (\n <button\n type={type}\n className={baseClasses}\n onClick={dropdown ? toggleDropdown : onClick}\n disabled={disabled}\n {...(dropdown\n ? { \"aria-haspopup\": \"menu\" as const, \"aria-expanded\": isDropdownOpen }\n : {})}\n >\n {content}\n </button>\n );\n\n return renderWithDropdown(actionElement);\n};\n\nexport default Action;\n"],"names":["Action","_ref","label","onClick","href","_ref$variant","variant","_ref$size","size","_ref$fullWidth","fullWidth","_ref$disabled","disabled","iconBefore","iconAfter","_ref$className","className","target","_ref$type","type","_ref$animated","animated","_ref$dropdown","dropdown","_ref$dropdownItems","dropdownItems","_ref$dropdownPosition","dropdownPosition","_React$useState","React","useState","_React$useState2","_slicedToArray","isDropdownOpen","setIsDropdownOpen","dropdownRef","useRef","menuRef","_React$useState3","top","left","maxHeight","_React$useState4","menuPosition","setMenuPosition","positionMenu","useCallback","trigger","current","rect","getBoundingClientRect","bottom","window","innerHeight","right","innerWidth","desiredHeight","Math","min","length","menuWidth","max","width","spaceBelow","spaceAbove","openUpward","available","useEffect","handleClickOutside","event","_dropdownRef$current","_menuRef$current","contains","handleScroll","_menuRef$current2","handleResize","document","addEventListener","removeEventListener","baseClasses","concat","filter","Boolean","join","content","_jsxs","_Fragment","children","_jsx","height","viewBox","fill","xmlns","style","color","d","stroke","strokeWidth","strokeLinecap","strokeLinejoin","dropdownMenu","ref","undefined","e","stopPropagation","map","item","index","itemClasses","itemContent","Link","actionElement","createPortal","body","renderWithDropdown","_objectSpread","preventDefault"],"mappings":"yPAMA,IA+EMA,EAAgC,SAA1BC,GAiBP,IAhBHC,EAAKD,EAALC,MACAC,EAAOF,EAAPE,QACAC,EAAIH,EAAJG,KAAIC,EAAAJ,EACJK,QAAAA,OAAU,IAAHD,EAAG,UAASA,EAAAE,EAAAN,EACnBO,KAAAA,OAAO,IAAHD,EAAG,SAAQA,EAAAE,EAAAR,EACfS,UAAAA,OAAY,IAAHD,GAAQA,EAAAE,EAAAV,EACjBW,SAAAA,OAAW,IAAHD,GAAQA,EAChBE,EAAUZ,EAAVY,WACAC,EAASb,EAATa,UAASC,EAAAd,EACTe,UAAAA,OAAY,IAAHD,EAAG,GAAEA,EACdE,EAAMhB,EAANgB,OAAMC,EAAAjB,EACNkB,KAAAA,OAAO,IAAHD,EAAG,SAAQA,EAAAE,EAAAnB,EACfoB,SAAAA,OAAW,IAAHD,GAAQA,EAAAE,EAA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fO,KAAK,kBAEJ0F,GAXIF,OAyDjB,OAtC2B,SAACI,GAC1B,OAAKxF,EAGH8D,EAAA,MAAA,CAAKrE,UAAU,iCAAiCqF,IAAKlE,EAAWoD,SAAA,CAC7DwB,EACAX,GACqB,oBAAbxB,UACPoC,EAAaZ,EAAcxB,SAASqC,SAPpBF,EAqCjBG,EAvBL9G,GAASQ,GAAaW,EAUpBiE,EAAA,SAAA2B,EAAAA,EAAA,CACEhG,KAAMA,EACNH,UAAW+D,EACX5E,QAASoB,EA9MQ,SAACgF,GACtB,GAAIhF,EAAU,CAGZ,GAFAgF,EAAEa,iBACFb,EAAEC,kBACEvE,EAEF,YADAC,GAAkB,GAKhBW,KAAgBX,GAAkB,EACvC,GAmMwC/B,EACrCS,SAAUA,GACLW,EACD,CAAE,gBAAiB,OAAiB,gBAAiBU,GACrD,CAAA,GAAE,GAAA,UAELmD,KAlBHI,EAACsB,EACC,CAAA1G,KAAMA,EACNY,UAAW+D,EACX9D,OAAQA,EACRd,QAASA,EAAOoF,SAEfH,IAiBT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as e,toConsumableArray as n}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as o,jsx as i}from"react/jsx-runtime";import{useState as
|
|
1
|
+
import{slicedToArray as e,toConsumableArray as n}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as o,jsx as i}from"react/jsx-runtime";import{useState as t,useRef as r,useEffect as a,useCallback as l,useLayoutEffect as d,useMemo as c}from"react";import{createPortal as u}from"react-dom";import s from"@mui/icons-material/CloseOutlined";import p from"@mui/icons-material/KeyboardArrowDownOutlined";import m from"@mui/icons-material/SearchOutlined";var h=function(h){var v=h.label,f=h.name,b=h.key_name,w=h.required,g=h.options,y=h.selectedValue,N=h.onChange,x=h.placeholder,A=void 0===x?"Select...":x,E=h.className,C=void 0===E?"":E,L=h.isMulti,k=void 0!==L&&L,H=h.isSearchable,M=void 0!==H&&H,D=h.noOptionsMessage,O=void 0===D?"No options available":D,S=h.isDisabled,K=void 0!==S&&S,P=h.maxHeight,_=void 0===P?250:P,j=h.renderOption,q=t(!1),z=e(q,2),B=z[0],R=z[1],F=t(""),I=e(F,2),T=I[0],U=I[1],V=t(y),W=e(V,2),G=W[0],J=W[1],Q=r(null),X=r(null),Y=r(null),Z=t({top:0,left:0,width:0,maxHeight:_}),$=e(Z,2),ee=$[0],ne=$[1];a(function(){J(y)},[y]);var oe=l(function(){var e,n=null===(e=Q.current)||void 0===e?void 0:e.getBoundingClientRect();if(!n)return!1;if(n.bottom<0||n.top>window.innerHeight||n.right<0||n.left>window.innerWidth)return!1;var o=window.innerHeight-n.bottom-5-8,i=n.top-5-8,t=o<Math.min(_,120)&&i>o,r=Math.max(120,t?i:o),a=Math.min(_,r);return ne({top:t?Math.max(8,n.top-a-5):n.bottom+5,left:n.left,width:n.width,maxHeight:a}),!0},[_]);d(function(){B&&oe()},[B,oe]),d(function(){B&&oe()},[G,B,oe]),a(function(){if(B){var e=function(e){var n,o,i=e.target;i instanceof Node&&(null!==(n=Q.current)&&void 0!==n&&n.contains(i)||null!==(o=X.current)&&void 0!==o&&o.contains(i)||R(!1))},n=function(e){var n,o=e.target;o instanceof Node&&null!==(n=X.current)&&void 0!==n&&n.contains(o)||oe()||R(!1)},o=function(){oe()||R(!1)},i=function(e){"Escape"===e.key&&R(!1)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),document.addEventListener("keydown",i),window.addEventListener("scroll",n,!0),window.addEventListener("resize",o),function(){document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",i),window.removeEventListener("scroll",n,!0),window.removeEventListener("resize",o)}}},[B,oe]),a(function(){B&&M&&Y.current&&Y.current.focus()},[B,M]);var ie=c(function(){if(!T)return g;var e=T.toLowerCase();return g.filter(function(n){var o=b?n[b]:null==n?void 0:n.label;return"number"==typeof o?String(o).includes(e):"string"==typeof o&&o.toLowerCase().includes(e)})},[g,T,b]),te=function(e){if(!K)switch(e.key){case"Enter":case"ArrowDown":case"ArrowUp":B||R(!0);break;case"Escape":R(!1)}},re=G?Array.isArray(G)?g.filter(function(e){return G.includes(e.value)}):g.filter(function(e){return e.value===G}):[];return o("div",{className:"ihub-wrapper ihub-dropdown-field ".concat(C," ").concat(K?"ihub-dropdown-disabled":""," ").concat(B?"active":""),ref:Q,tabIndex:K?-1:0,onKeyDown:te,"aria-expanded":B,"aria-disabled":K,"aria-haspopup":"listbox",role:"combobox",children:[o("div",{className:"ihub-dropdown-trigger ".concat(B?"ihub-dropdown-open":""),onClick:function(){K||(U(""),B?R(!1):oe()&&R(!0))},children:[i("div",{className:"ihub-dropdown-value",children:re.length>0?k?i("div",{className:"ihub-dropdown-tags",children:re.map(function(e){return o("div",{className:"ihub-dropdown-tag",children:[b?e[b]:null==e?void 0:e.label,i("button",{type:"button",className:"ihub-dropdown-tag-remove",onClick:function(n){return function(e,n){if(n.stopPropagation(),Array.isArray(G)){var o=G.filter(function(n){return n!==e});J(o),null==N||N(o)}}(e.value,n)},"aria-label":"Remove ".concat(b?e[b]:null==e?void 0:e.label),children:i(s,{})})]},e.value)})}):b?re[0][b]:re[0].label:i("span",{className:"ihub-dropdown-placeholder",children:A})}),i("div",{className:"ihub-dropdown-indicator",children:i(p,{className:B?"ihub-dropdown-chevron-up":""})}),v&&o("label",{htmlFor:f,className:"ihub-chips-label ihub-text-label",children:[v,w&&i("span",{className:"ihub-required",children:"*"})]}),f?i("input",{name:f,type:"hidden",value:"".concat(G),onChange:function(){}}):""]}),B&&"undefined"!=typeof document&&u(o("div",{ref:X,className:"ihub-dropdown-menu ihub-dropdown-menu-portal",style:{maxHeight:"".concat(ee.maxHeight,"px"),top:"".concat(ee.top,"px"),left:"".concat(ee.left,"px"),width:"".concat(ee.width,"px")},role:"listbox","aria-multiselectable":k,onKeyDown:te,children:[M&&o("div",{className:"ihub-dropdown-search",children:[i(m,{className:"ihub-dropdown-search-icon"}),i("input",{type:"text",value:T,onChange:function(e){return U(e.target.value)},placeholder:"Search...",ref:Y,className:"ihub-dropdown-search-input",onClick:function(e){return e.stopPropagation()}})]}),i("div",{className:"ihub-dropdown-options",children:ie.length>0?ie.map(function(e){var o=Array.isArray(G)?G.includes(e.value):G===e.value;return i("div",{className:"ihub-dropdown-option ".concat(o?"ihub-dropdown-selected":""," ").concat(e.disabled?"ihub-dropdown-disabled-option":""),onClick:function(){return function(e){if(!e.disabled)if(k){var o=Array.isArray(G)?G:[];if(o.includes(e.value)){var i=o.filter(function(n){return n!==e.value});J(i),null==N||N(i)}else{var t=[].concat(n(o),[e.value]);J(t),null==N||N(t)}}else J(e.value),null==N||N(e.value),R(!1)}(e)},role:"option","aria-selected":o,"aria-disabled":e.disabled,children:j?j(e):b?e[b]:null==e?void 0:e.label},e.value)}):i("div",{className:"ihub-dropdown-no-options",children:O})})]}),document.body)]})};export{h as default};
|
|
2
2
|
//# sourceMappingURL=Dropdown.js.map
|
|
@@ -1,61 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { DropdownPropsType } from "@/types";
|
|
3
|
-
/**
|
|
4
|
-
* A dropdown component that allows users to select one or multiple options
|
|
5
|
-
* @example
|
|
6
|
-
* ```tsx
|
|
7
|
-
* const options = [
|
|
8
|
-
* {
|
|
9
|
-
* value: "js",
|
|
10
|
-
* label: "JavaScript",
|
|
11
|
-
* icon: <CodeOutlinedIcon />,
|
|
12
|
-
* description: "Popular",
|
|
13
|
-
* },
|
|
14
|
-
* {
|
|
15
|
-
* value: "py",
|
|
16
|
-
* label: "Python",
|
|
17
|
-
* icon: <CodeOutlinedIcon />,
|
|
18
|
-
* description: "Popular",
|
|
19
|
-
* }
|
|
20
|
-
* ]
|
|
21
|
-
* <Dropdown
|
|
22
|
-
* label="Dropdown"
|
|
23
|
-
* name="dropdown"
|
|
24
|
-
* key_name="id"
|
|
25
|
-
* options={options}
|
|
26
|
-
* selectedValue={selectedValue}
|
|
27
|
-
* onChange={handleChange}
|
|
28
|
-
* placeholder="Select an option"
|
|
29
|
-
* className="ihub-dropdown"
|
|
30
|
-
* isMulti={true}
|
|
31
|
-
* isSearchable={true}
|
|
32
|
-
* noOptionsMessage="No options available"
|
|
33
|
-
* isDisabled={false}
|
|
34
|
-
* maxHeight={250}
|
|
35
|
-
* renderOption={renderOption}
|
|
36
|
-
* />
|
|
37
|
-
*
|
|
38
|
-
* @prop {string} label - The label text for the dropdown
|
|
39
|
-
* @prop {string} name - The name attribute for the dropdown
|
|
40
|
-
* @prop {string} key_name - The key name of the dropdown (description, name key, etc)
|
|
41
|
-
* @prop {boolean} required - Whether the dropdown is required
|
|
42
|
-
* @prop {DropdownOptionType[]} options - The options to display in the dropdown
|
|
43
|
-
* @prop {string | string[]} selectedValue - The value(s) currently selected in the dropdown
|
|
44
|
-
* @prop {function} onChange - The function to call when the selected value changes
|
|
45
|
-
* @prop {string} placeholder - The placeholder text for the dropdown
|
|
46
|
-
* @prop {string} className - The class name for the dropdown
|
|
47
|
-
* @prop {boolean} isMulti - Whether the dropdown allows multiple selections
|
|
48
|
-
* @prop {boolean} isSearchable - Whether the dropdown allows searching
|
|
49
|
-
* @prop {string} noOptionsMessage - The message to display when there are no options
|
|
50
|
-
* @prop {boolean} isDisabled - Whether the dropdown is disabled
|
|
51
|
-
* @prop {number} maxHeight - The maximum height of the dropdown menu
|
|
52
|
-
* @prop {function} renderOption - The function to render the option label
|
|
53
|
-
*
|
|
54
|
-
* The menu is rendered through a portal on `document.body` at fixed
|
|
55
|
-
* coordinates taken from the trigger. An absolutely positioned menu is clipped
|
|
56
|
-
* by any ancestor with `overflow: auto|hidden` — a table's scroll container, a
|
|
57
|
-
* modal body, a card — which made the component unusable in exactly the places
|
|
58
|
-
* a compact picker is most wanted.
|
|
59
|
-
*/
|
|
60
3
|
declare const Dropdown: React.FC<DropdownPropsType>;
|
|
61
4
|
export default Dropdown;
|