@leafygreen-ui/select
Advanced tools
Comparing version 2.0.3 to 2.0.4
# @leafygreen-ui/select | ||
## 2.0.4 | ||
### Patch Changes | ||
- 90321b36: Imports validateProps functions from `@leafygreen-ui/a11y` package. | ||
- ab581f34: Re-released components that were erroneously released without `.d.ts` files | ||
- Updated dependencies [ab581f34] | ||
- Updated dependencies [90321b36] | ||
- @leafygreen-ui/button@11.0.2 | ||
- @leafygreen-ui/palette@3.2.1 | ||
- @leafygreen-ui/lib@7.0.0 | ||
- @leafygreen-ui/icon@10.2.1 | ||
- @leafygreen-ui/leafygreen-provider@2.0.3 | ||
- @leafygreen-ui/popover@7.1.4 | ||
- @leafygreen-ui/tokens@0.5.1 | ||
## 2.0.3 | ||
@@ -4,0 +20,0 @@ |
@@ -1,2 +0,2 @@ | ||
import{transparentize as e}from"polished";import{uiColors as n}from"@leafygreen-ui/palette";import r,{createContext as t,useContext as o,useRef as i,useCallback as a,useEffect as l,useMemo as u,useState as c}from"react";import s from"prop-types";import{css as d,cx as f}from"@leafygreen-ui/emotion";import{usePrevious as p,useViewportSize as b}from"@leafygreen-ui/hooks";import{IdAllocator as h,isComponentType as v,keyMap as g}from"@leafygreen-ui/lib";import{fontFamilies as m,breakpoints as y}from"@leafygreen-ui/tokens";import x,{Align as w,Justify as O}from"@leafygreen-ui/popover";import k from"@leafygreen-ui/icon/dist/Checkmark";import{isFragment as E}from"react-is";import N,{Variant as D}from"@leafygreen-ui/button";import S from"@leafygreen-ui/icon/dist/CaretDown";function C(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function j(){return(j=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function F(e,n){if(null==e)return{};var r,t,o=function(e,n){if(null==e)return{};var r,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)r=i[t],n.indexOf(r)>=0||(o[r]=e[r]);return o}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(t=0;t<i.length;t++)r=i[t],n.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function P(e,n){return n||(n=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(n)}}))}function z(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],t=!0,o=!1,i=void 0;try{for(var a,l=e[Symbol.iterator]();!(t=(a=l.next()).done)&&(r.push(a.value),!n||r.length!==n);t=!0);}catch(e){o=!0,i=e}finally{try{t||null==l.return||l.return()}finally{if(o)throw i}}return r}(e,n)||H(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e){return function(e){if(Array.isArray(e))return I(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||H(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function H(e,n){if(e){if("string"==typeof e)return I(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?I(e,n):void 0}}function I(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}var T,G,K="dark",V="light",L=(C(T={},V,{label:{base:n.gray.dark3,disabled:n.gray.dark1},description:n.gray.dark1,border:{base:n.gray.light1,open:n.gray.dark1},text:{base:n.gray.dark3,deselected:n.gray.dark1,disabled:n.gray.base},menu:{shadow:e(.78,n.black)},option:{group:{label:n.gray.dark3,border:n.gray.light2},background:{base:n.white,hovered:n.gray.light2,focused:n.blue.light3},text:{base:n.gray.dark3,selected:n.blue.base,disabled:n.gray.base},icon:{base:n.gray.dark1,selected:n.blue.base,disabled:n.gray.base}}}),C(T,K,{label:{base:n.white,disabled:n.gray.light1},description:n.gray.light1,border:{base:n.gray.dark2,open:n.gray.dark2},text:{base:n.white,deselected:n.gray.light1,disabled:n.gray.dark1},menu:{shadow:e(.2,n.black)},option:{group:{label:n.white,border:n.gray.dark1},background:{base:n.gray.dark2,hovered:n.gray.dark1,focused:n.blue.base},text:{base:n.white,selected:"#9DD0E7",disabled:n.gray.base},icon:{base:n.gray.light1,selected:"#9DD0E7",disabled:n.gray.base}}}),T),M={XSmall:"xsmall",Small:"small",Default:"default",Large:"large"},R=(C(G={},M.XSmall,{height:22,text:12,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),C(G,M.Small,{height:28,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),C(G,M.Default,{height:36,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:20},option:{text:14}}),C(G,M.Large,{height:48,text:18,label:{text:18,lineHeight:21},description:{text:18,lineHeight:24},option:{text:16}}),G),B=36,q=16,U={text:16,lineHeight:19},X={text:16,lineHeight:22},W={text:16},Y=t({mode:V,size:M.Default,open:!1,disabled:!1});function $(){var e=P(["\n cursor: not-allowed;\n color: ",";\n "]);return $=function(){return e},e}function J(){var e=P(["\n cursor: pointer;\n color: ",";\n "]);return J=function(){return e},e}function Q(){var e=P(["\n display: flex;\n "]);return Q=function(){return e},e}function Z(){var e=P(["\n display: flex;\n justify-content: space-between;\n width: 100%;\n "]);return Z=function(){return e},e}function _(){var e=P(["\n color: ",";\n "]);return _=function(){return e},e}function ee(){var e=P(["\n color: ",";\n "]);return ee=function(){return e},e}function ne(){var e=P(["\n color: ",";\n "]);return ne=function(){return e},e}function re(){var e=P(["\n color: ",";\n "]);return re=function(){return e},e}function te(){var e=P(["\n height: 100%;\n "]);return te=function(){return e},e}function oe(){var e=P(["\n font-weight: bold;\n "]);return oe=function(){return e},e}function ie(){var e=P(["\n min-width: 16px;\n margin-right: 6px;\n"]);return ie=function(){return e},e}function ae(){var e=P(["\n display: flex;\n align-items: center;\n"]);return ae=function(){return e},e}function le(){var e=P(["\n display: flex;\n width: 100%;\n padding: 10px 12px;\n outline: none;\n overflow-wrap: anywhere;\n transition: background-color 150ms ease-in-out;\n"]);return le=function(){return e},e}var ue=d(le()),ce=d(ae()),se=d(ie());function de(e){var n,t=e.children,u=e.className,c=e.glyph,s=e.selected,b=e.focused,h=e.disabled,v=e.onClick,g=e.onFocus,m=e.isDeselection,y=e.triggerScrollIntoView,x=e.hasGlyphs,w=o(Y).mode,O=L[w].option,E=i(null),N=a((function(){var e=E.current,n=e.offsetParent;n.scrollTop=e.offsetTop+(e.clientHeight-n.clientHeight)/2}),[E]),D=p(y),S=y&&!D;l((function(){S&&N()}),[N,S]);var j=p(b),F=b&&!j;l((function(){F&&E.current.focus()}),[F]);var P=r.createElement("span",{className:f(ce,C({},d(oe()),s&&!m))},t),z=r.createElement("span",{className:f(se,d(te()))}),A=z;c&&(c.type.isGlyph?A=r.cloneElement(c,{key:"glyph",className:f(se,d(re(),O.icon.base),C({},d(ne(),O.icon.disabled),h),c.props.className)}):console.error("`Option` instance did not render icon because it is not a known glyph element."));var H,I=s&&!m?r.createElement(k,{key:"checkmark",className:f(se,d(ee(),O.icon.selected),C({},d(_(),O.icon.disabled),h))}):z;return H=x?r.createElement("span",{className:d(Z())},r.createElement("span",{className:d(Q())},A,P),I):r.createElement(r.Fragment,null,I,P),r.createElement("li",{role:"option","aria-selected":s,tabIndex:-1,ref:E,className:f(ue,d(J(),O.text.base),(n={},C(n,d("\n &:focus {\n background-color: ".concat(O.background.focused,";\n }\n\n &:hover {\n background-color: ").concat(O.background.hovered,";\n }\n ")),!h),C(n,d($(),O.text.disabled),h),n),u),onClick:v,onFocus:g,onKeyDown:void 0},H)}function fe(e){throw Error("`Option` must be a child of a `Select` instance")}de.displayName="Option",fe.displayName="Option";var pe=s.oneOfType([s.string,s.number]);function be(){var e=P(["\n color: ",";\n "]);return be=function(){return e},e}function he(){var e=P(["\n border-bottom: 1px solid ",";\n "]);return he=function(){return e},e}function ve(){var e=P(["\n cursor: default;\n width: 100%;\n padding: 0 12px 2px;\n outline: none;\n overflow-wrap: anywhere;\n font-size: 13px;\n line-height: 16px;\n font-weight: bold;\n"]);return ve=function(){return e},e}function ge(){var e=P(["\n padding-top: 8px;\n"]);return ge=function(){return e},e}fe.propTypes={children:s.oneOfType([pe,s.arrayOf(s.oneOfType([pe,s.oneOf([!1,null,void 0,""])]))]).isRequired,className:s.string,glyph:s.element,value:s.string,disabled:s.bool};var me=d(ge()),ye=d(ve()),xe=h.create("select-option-group");function we(e){var n=e.className,t=e.label,i=e.children,a=o(Y).mode,l=L[a].option,c=u((function(){return xe.generate()}),[]);return r.createElement("div",{className:f(me,d(he(),l.group.border),n)},r.createElement("div",{id:c,className:f(ye,d(be(),l.group.label))},t),r.createElement("div",{role:"group","aria-labelledby":c},i))}function Oe(e){throw Error("`OptionGroup` must be a child of a `Select` instance")}function ke(e){return null==e||!1===e||""===e}function Ee(e,n){r.Children.forEach(e,(function(e){v(e,"Option")?n(e):v(e,"OptionGroup")?Ee(e.props.children,(function(r){return n(r,e)})):E(e)&&Ee(e.props.children,n)}))}function Ne(e,n,t){return r.Children.map(e,(function(e){if(v(e,"Option"))return r.createElement(de,n(e));if(v(e,"OptionGroup")){var o=e.props,i=o.children,a=F(o,["children"]);return r.createElement(we,j({className:void 0},a),Ne(i,(function(r){return n(r,e)}),t))}return E(e)?Ne(e.props.children,n,t):(ke(e)||null==t||t(e),null)}))}function De(e){return null===e?"":void 0!==e.props.value?e.props.value:Array.isArray(e.props.children)?e.props.children.filter((function(e){return!ke(e)})).join(""):e.props.children.toString()}function Se(e,n){var r,t,o;return null!==(r=e.props.disabled)&&void 0!==r&&r||null!==(t=null==n||null===(o=n.props)||void 0===o?void 0:o.disabled)&&void 0!==t&&t}function Ce(e,n,r){return De(e)===r&&!Se(e,n)}function je(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.initialValue,t=n.deps,o=void 0===t?[]:t,a=i(r);return u((function(){return{get current(){return a.current},set current(n){a.current=n,e(n)}}}),[e,a].concat(A(o)))}function Fe(e,n){var r=a((function(e,n){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(n):e&&(e.current=n)}),[]);return je(a((function(n){return r(e,n)}),[e,r]),{initialValue:n})}we.displayName="OptionGroup",Oe.displayName="OptionGroup",Oe.propTypes={children:s.oneOfType([s.element,s.arrayOf(s.oneOfType([s.oneOf([!1,null,void 0,""]),s.element]))]).isRequired,className:s.string,label:s.string.isRequired,disabled:s.bool};var Pe=function(e){var n=z(c(e),2),r=n[0];return je(n[1],{initialValue:e,deps:[r]})};function ze(){var e=P(["\n font-family: ",";\n font-size: ","px;\n max-height: ","px;\n background-color: ",";\n box-shadow: 0 3px 7px 0 ",";\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n }\n "]);return ze=function(){return e},e}function Ae(){var e=P(["\n position: relative;\n text-align: left;\n width: 100%;\n border-radius: 3px;\n line-height: 16px;\n list-style: none;\n margin: 0;\n padding: 0;\n overflow: auto;\n"]);return Ae=function(){return e},e}var He=d(Ae()),Ie=r.forwardRef((function(e,n){var t=e.children,i=e.id,l=e.referenceElement,u=e.onClose,c=e.onFocusPreviousOption,s=e.onFocusNextOption,p=e.onSelectFocusedOption,h=e.className,v=e.usePortal,k=e.labelId,E=o(Y),N=E.mode,D=E.size,S=E.disabled,C=E.open,j=L[N],F=R[D],P=Fe(n,null),z=a((function(e){if(!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case g.Tab:case g.Enter:p(e);break;case g.Escape:u();break;case g.ArrowUp:c();break;case g.ArrowDown:s();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[u,s,c,p]),A=b(),H=null===A||null===P.current?0:A.height-P.current.getBoundingClientRect().top-10,I=a((function(e){P.current&&P.current.focus(),e.stopPropagation()}),[P]);return r.createElement(x,{active:C&&!S,spacing:4,align:w.Bottom,justify:O.Middle,adjustOnMutation:!0,className:h,refEl:l,usePortal:v},r.createElement("ul",{"aria-labelledby":k,role:"listbox",ref:P,tabIndex:-1,onKeyDown:z,onClick:I,className:f(He,d(ze(),m.default,F.option.text,H,j.option.background.base,j.menu.shadow,y.Desktop,W.text)),id:i},t))}));function Te(){var e=P(["\n height: ","px;\n font-size: ","px;\n width: 100%;\n color: ",";\n border-color: ",";\n\n @media only screen and (max-width: ","px) {\n height: ","px;\n font-size: ","px;\n }\n "]);return Te=function(){return e},e}function Ge(){var e=P(["\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n"]);return Ge=function(){return e},e}function Ke(){var e=P(["\n margin-top: 2px;\n\n // reset default Button padding\n > span {\n padding: 0;\n }\n"]);return Ke=function(){return e},e}Ie.displayName="ListMenu";var Ve=d(Ke()),Le=d(Ge()),Me=r.forwardRef((function(e,n){var t=e.children,i=e.value,l=e.text,u=e.name,c=e.deselected,s=(e.readOnly,e.onDeselect),p=e.onFocusFirstOption,b=e.onFocusLastOption,h=e.onClose,v=e.onOpen,m=F(e,["children","value","text","name","deselected","readOnly","onDeselect","onFocusFirstOption","onFocusLastOption","onClose","onOpen"]),x=o(Y),w=x.mode,O=x.open,k=x.size,E=x.disabled,C=Fe(n,null),P=L[w],z=R[k],A=a((function(e){if(!E&&!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case g.Tab:h(),n=!0;break;case g.Escape:O?h():s(e);break;case g.ArrowUp:v(),b();break;case g.ArrowDown:v(),p();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[E,h,s,p,b,v,O]),H=a((function(){O?h():v(),C.current.focus()}),[h,v,O,C]);return r.createElement(N,j({},m,{ref:C,name:u,value:i,disabled:E,onClick:H,onKeyDown:A,variant:D.Default,darkMode:w===K,rightGlyph:r.createElement(S,null),className:f(Ve,d(Te(),z.height,z.text,c?P.text.deselected:P.text.base,O&&!E?P.border.open:P.border.base,y.Desktop,B,q))}),r.createElement("span",{className:Le},l),t)}));function Re(){var e=P(["\n width: ","px;\n "]);return Re=function(){return e},e}function Be(){var e=P(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return Be=function(){return e},e}function qe(){var e=P(["\n cursor: not-allowed;\n "]);return qe=function(){return e},e}function Ue(){var e=P(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return Ue=function(){return e},e}function Xe(){var e=P(["\n cursor: not-allowed;\n "]);return Xe=function(){return e},e}function We(){var e=P(["\n margin-bottom: 2px;\n font-weight: bold;\n"]);return We=function(){return e},e}function Ye(){var e=P(["\n font-family: ",";\n display: block;\n"]);return Ye=function(){return e},e}Me.displayName="MenuButton";var $e=d(Ye(),m.default),Je=d(We()),Qe=h.create("select");function Ze(e){var n,t=e.children,o=e.darkMode,i=void 0!==o&&o,s=e.size,p=void 0===s?M.Default:s,h=e.disabled,v=void 0!==h&&h,g=e.usePortal,m=void 0===g||g,x=e.placeholder,w=void 0===x?"Select":x,O=e.className,k=e.id,E=e.label,N=e.description,D=e.name,S=e.defaultValue,j=e.value,F=e.onChange,P=e.readOnly,A=e["aria-labelledby"],H=u((function(){return null!=k?k:Qe.generate()}),[k]),I=u((function(){return null!=A?A:"".concat(H,"-label")}),[A,H]),T="".concat(H,"-description"),G="".concat(H,"-menu"),B=z(c(!1),2),q=B[0],W=B[1],$=Pe(null),J=Pe(null),Q=i?K:V,Z=L[Q],_=R[p],ee=u((function(){return{mode:Q,size:p,open:q,disabled:v}}),[Q,p,q,v]);l((function(){void 0!==j&&void 0===F&&!0!==P&&console.warn("You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.")}),[F,P,j]),E||A||console.error("For screen-reader accessibility, label or aria-labelledby must be provided to IconButton.");var ne=a((function(){W(!0)}),[]),re=a((function(){W(!1),$.current.focus()}),[$]);l((function(){if(q){var e=function(e){var n=$.current.contains(e.target)||J.current.contains(e.target);W(n)};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}}),[J,$,q]);var te=u((function(){var e=null;return void 0===j&&void 0!==S&&Ee(t,(function(n,r){Ce(n,r,S)&&(e=n)})),e}),[t,S,j]),oe=z(c(te),2),ie=oe[0],ae=oe[1];l((function(){var e;null!==ie&&ae(null!==(e=function(e,n){var r,t,o,i,a,l,u,c;return Ee(e,(function(e){if(e===n)a=n;else if(e.props.children===n.props.children&&e.props.value===n.props.value){var r;null!==(r=l)&&void 0!==r||(l=e)}else if(void 0!==e.props.value&&e.props.value===n.props.value){var t;null!==(t=u)&&void 0!==t||(u=e)}else if(De(e)===De(n)){var o;null!==(o=c)&&void 0!==o||(c=e)}})),null!==(r=null!==(t=null!==(o=null!==(i=a)&&void 0!==i?i:l)&&void 0!==o?o:u)&&void 0!==t?t:c)&&void 0!==r?r:null}(t,ie))&&void 0!==e?e:te)}),[t,te,ie]);var le=u((function(){if(void 0!==j){var e=null;return Ee(t,(function(n,r){Ce(n,r,j)&&(e=n)})),e}return ie}),[t,ie,j]),ue=a((function(e,n){void 0===j&&ae(e),null==F||F(De(e),n),be(void 0),re()}),[F,re,j]),ce=a((function(e,n){return function(r){r.preventDefault(),r.stopPropagation(),v||n||(ue(e,r),re())}}),[v,re,ue]),se=a((function(e){ue(null,e)}),[ue]),fe=z(c(),2),pe=fe[0],be=fe[1],he=u((function(){var e=[null];return Ee(t,(function(n,r){Se(n,r)||e.push(n)})),e}),[t]),ve=a((function(e){void 0!==pe&&ue(pe,e)}),[pe,ue]),ge=a((function(){be(null)}),[]),me=a((function(){be(he[he.length-1])}),[he]),ye=a((function(){if(void 0===pe||0===he.indexOf(pe))me();else{var e=he.indexOf(pe)-1;be(he[e])}}),[he,pe,me]),xe=a((function(){if(void 0===pe||he.indexOf(pe)===he.length-1)ge();else{var e=he.indexOf(pe)+1;be(he[e])}}),[he,pe,ge]),we=a((function(e,n){return function(r){r.preventDefault(),r.stopPropagation(),v||n||be(e)}}),[v]),Oe=b(),ke=u((function(){var e=!1;return Ee(t,(function(n){e||(e=void 0!==n.props.glyph)})),e}),[t]),je=u((function(){return null!==Oe&&null!==J.current&&void 0===pe&&q}),[pe,J,q,Oe]),Fe=u((function(){var e=null===le;return r.createElement(de,{className:void 0,glyph:void 0,selected:e,focused:null===pe,disabled:!1,onClick:ce(null,!1),onFocus:we(null,!1),isDeselection:!0,hasGlyphs:!0,triggerScrollIntoView:e&&je},w)}),[je,pe,ce,we,w,le]),ze=u((function(){return Ne(t,(function(e,n){var r=e===le,t=Se(e,n);return{className:e.props.className,glyph:e.props.glyph,selected:r,focused:e===pe,disabled:t,children:e.props.children,isDeselection:!1,hasGlyphs:ke,onClick:ce(e,t),onFocus:we(e,t),triggerScrollIntoView:r&&je}}),(function(){console.error("`Select` instance received child that is not `Option` or `OptionGroup`.")}))}),[je,t,pe,ce,we,ke,le]);return r.createElement("div",{className:f(C({},d(Xe()),v),O)},E&&r.createElement("label",{id:I,className:f($e,Je,d(Ue(),v?Z.label.disabled:Z.label.base,_.label.text,_.label.lineHeight,y.Desktop,U.text,U.lineHeight),C({},d(qe()),v))},E),N&&r.createElement("div",{id:T,className:f($e,d(Be(),Z.description,_.description.text,_.description.lineHeight,y.Desktop,X.text,X.lineHeight))},N),r.createElement(Y.Provider,{value:ee},r.createElement(Me,{ref:$,name:D,readOnly:P,value:De(le),text:null!==le?le.props.children:w,deselected:null===le,onDeselect:se,onOpen:ne,onClose:re,onFocusFirstOption:ge,onFocusLastOption:me,"aria-labelledby":I,"aria-controls":G,"aria-expanded":q,"aria-describedby":T},r.createElement(Ie,{labelId:I,id:G,referenceElement:$,ref:J,onClose:re,onSelectFocusedOption:ve,onFocusPreviousOption:ye,onFocusNextOption:xe,usePortal:m,className:d(Re(),null===(n=$.current)||void 0===n?void 0:n.clientWidth)},Fe,ze))))}Ze.displayName="Select",Ze.propTypes={label:s.string,"aria-labelledby":s.string,description:s.string,placeholder:s.string,className:s.string,darkMode:s.bool,size:s.oneOf(Object.values(M)),disabled:s.bool,id:s.string,value:s.string,defaultValue:s.string,onChange:s.func,readOnly:s.bool};export{fe as Option,Oe as OptionGroup,Ze as Select,M as Size}; | ||
import{transparentize as e}from"polished";import{uiColors as n}from"@leafygreen-ui/palette";import r,{createContext as t,useContext as o,useRef as i,useCallback as a,useEffect as l,useMemo as u,useState as c}from"react";import s from"prop-types";import{css as d,cx as f}from"@leafygreen-ui/emotion";import{usePrevious as p,useViewportSize as b}from"@leafygreen-ui/hooks";import{IdAllocator as h,isComponentType as v,keyMap as g}from"@leafygreen-ui/lib";import{fontFamilies as m,breakpoints as y}from"@leafygreen-ui/tokens";import x,{Align as w,Justify as O}from"@leafygreen-ui/popover";import k from"@leafygreen-ui/icon/dist/Checkmark";import{isFragment as E}from"react-is";import N,{Variant as D}from"@leafygreen-ui/button";import S from"@leafygreen-ui/icon/dist/CaretDown";function C(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function j(){return(j=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function F(e,n){if(null==e)return{};var r,t,o=function(e,n){if(null==e)return{};var r,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)r=i[t],n.indexOf(r)>=0||(o[r]=e[r]);return o}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(t=0;t<i.length;t++)r=i[t],n.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function P(e,n){return n||(n=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(n)}}))}function z(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],t=!0,o=!1,i=void 0;try{for(var a,l=e[Symbol.iterator]();!(t=(a=l.next()).done)&&(r.push(a.value),!n||r.length!==n);t=!0);}catch(e){o=!0,i=e}finally{try{t||null==l.return||l.return()}finally{if(o)throw i}}return r}(e,n)||H(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e){return function(e){if(Array.isArray(e))return T(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||H(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function H(e,n){if(e){if("string"==typeof e)return T(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?T(e,n):void 0}}function T(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}var I,G,K="dark",V="light",L=(C(I={},V,{label:{base:n.gray.dark3,disabled:n.gray.dark1},description:n.gray.dark1,border:{base:n.gray.light1,open:n.gray.dark1},text:{base:n.gray.dark3,deselected:n.gray.dark1,disabled:n.gray.base},menu:{shadow:e(.78,n.black)},option:{group:{label:n.gray.dark3,border:n.gray.light2},background:{base:n.white,hovered:n.gray.light2,focused:n.blue.light3},text:{base:n.gray.dark3,selected:n.blue.base,disabled:n.gray.base},icon:{base:n.gray.dark1,selected:n.blue.base,disabled:n.gray.base}}}),C(I,K,{label:{base:n.white,disabled:n.gray.light1},description:n.gray.light1,border:{base:n.gray.dark2,open:n.gray.dark2},text:{base:n.white,deselected:n.gray.light1,disabled:n.gray.dark1},menu:{shadow:e(.2,n.black)},option:{group:{label:n.white,border:n.gray.dark1},background:{base:n.gray.dark2,hovered:n.gray.dark1,focused:n.blue.base},text:{base:n.white,selected:"#9DD0E7",disabled:n.gray.base},icon:{base:n.gray.light1,selected:"#9DD0E7",disabled:n.gray.base}}}),I),M={XSmall:"xsmall",Small:"small",Default:"default",Large:"large"},R=(C(G={},M.XSmall,{height:22,text:12,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),C(G,M.Small,{height:28,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),C(G,M.Default,{height:36,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:20},option:{text:14}}),C(G,M.Large,{height:48,text:18,label:{text:18,lineHeight:21},description:{text:18,lineHeight:24},option:{text:16}}),G),B=36,q=16,U={text:16,lineHeight:19},X={text:16,lineHeight:22},W={text:16},Y=t({mode:V,size:M.Default,open:!1,disabled:!1});function $(){var e=P(["\n cursor: not-allowed;\n color: ",";\n "]);return $=function(){return e},e}function J(){var e=P(["\n cursor: pointer;\n color: ",";\n "]);return J=function(){return e},e}function Q(){var e=P(["\n display: flex;\n "]);return Q=function(){return e},e}function Z(){var e=P(["\n display: flex;\n justify-content: space-between;\n width: 100%;\n "]);return Z=function(){return e},e}function _(){var e=P(["\n color: ",";\n "]);return _=function(){return e},e}function ee(){var e=P(["\n color: ",";\n "]);return ee=function(){return e},e}function ne(){var e=P(["\n color: ",";\n "]);return ne=function(){return e},e}function re(){var e=P(["\n color: ",";\n "]);return re=function(){return e},e}function te(){var e=P(["\n height: 100%;\n "]);return te=function(){return e},e}function oe(){var e=P(["\n font-weight: bold;\n "]);return oe=function(){return e},e}function ie(){var e=P(["\n min-width: 16px;\n margin-right: 6px;\n"]);return ie=function(){return e},e}function ae(){var e=P(["\n display: flex;\n align-items: center;\n"]);return ae=function(){return e},e}function le(){var e=P(["\n display: flex;\n width: 100%;\n padding: 10px 12px;\n outline: none;\n overflow-wrap: anywhere;\n transition: background-color 150ms ease-in-out;\n"]);return le=function(){return e},e}var ue=d(le()),ce=d(ae()),se=d(ie());function de(e){var n,t=e.children,u=e.className,c=e.glyph,s=e.selected,b=e.focused,h=e.disabled,v=e.onClick,g=e.onFocus,m=e.isDeselection,y=e.triggerScrollIntoView,x=e.hasGlyphs,w=o(Y).mode,O=L[w].option,E=i(null),N=a((function(){var e=E.current,n=e.offsetParent;n.scrollTop=e.offsetTop+(e.clientHeight-n.clientHeight)/2}),[E]),D=p(y),S=y&&!D;l((function(){S&&N()}),[N,S]);var j=p(b),F=b&&!j;l((function(){F&&E.current.focus()}),[F]);var P=r.createElement("span",{className:f(ce,C({},d(oe()),s&&!m))},t),z=r.createElement("span",{className:f(se,d(te()))}),A=z;c&&(c.type.isGlyph?A=r.cloneElement(c,{key:"glyph",className:f(se,d(re(),O.icon.base),C({},d(ne(),O.icon.disabled),h),c.props.className)}):console.error("`Option` instance did not render icon because it is not a known glyph element."));var H,T=s&&!m?r.createElement(k,{key:"checkmark",className:f(se,d(ee(),O.icon.selected),C({},d(_(),O.icon.disabled),h))}):z;return H=x?r.createElement("span",{className:d(Z())},r.createElement("span",{className:d(Q())},A,P),T):r.createElement(r.Fragment,null,T,P),r.createElement("li",{role:"option","aria-selected":s,tabIndex:-1,ref:E,className:f(ue,d(J(),O.text.base),(n={},C(n,d("\n &:focus {\n background-color: ".concat(O.background.focused,";\n }\n\n &:hover {\n background-color: ").concat(O.background.hovered,";\n }\n ")),!h),C(n,d($(),O.text.disabled),h),n),u),onClick:v,onFocus:g,onKeyDown:void 0},H)}function fe(e){throw Error("`Option` must be a child of a `Select` instance")}de.displayName="Option",fe.displayName="Option";var pe=s.oneOfType([s.string,s.number]);function be(){var e=P(["\n color: ",";\n "]);return be=function(){return e},e}function he(){var e=P(["\n border-bottom: 1px solid ",";\n "]);return he=function(){return e},e}function ve(){var e=P(["\n cursor: default;\n width: 100%;\n padding: 0 12px 2px;\n outline: none;\n overflow-wrap: anywhere;\n font-size: 13px;\n line-height: 16px;\n font-weight: bold;\n"]);return ve=function(){return e},e}function ge(){var e=P(["\n padding-top: 8px;\n"]);return ge=function(){return e},e}fe.propTypes={children:s.oneOfType([pe,s.arrayOf(s.oneOfType([pe,s.oneOf([!1,null,void 0,""])]))]).isRequired,className:s.string,glyph:s.element,value:s.string,disabled:s.bool};var me=d(ge()),ye=d(ve()),xe=h.create("select-option-group");function we(e){var n=e.className,t=e.label,i=e.children,a=o(Y).mode,l=L[a].option,c=u((function(){return xe.generate()}),[]);return r.createElement("div",{className:f(me,d(he(),l.group.border),n)},r.createElement("div",{id:c,className:f(ye,d(be(),l.group.label))},t),r.createElement("div",{role:"group","aria-labelledby":c},i))}function Oe(e){throw Error("`OptionGroup` must be a child of a `Select` instance")}function ke(e){return null==e||!1===e||""===e}function Ee(e,n){r.Children.forEach(e,(function(e){v(e,"Option")?n(e):v(e,"OptionGroup")?Ee(e.props.children,(function(r){return n(r,e)})):E(e)&&Ee(e.props.children,n)}))}function Ne(e,n,t){return r.Children.map(e,(function(e){if(v(e,"Option"))return r.createElement(de,n(e));if(v(e,"OptionGroup")){var o=e.props,i=o.children,a=F(o,["children"]);return r.createElement(we,j({className:void 0},a),Ne(i,(function(r){return n(r,e)}),t))}return E(e)?Ne(e.props.children,n,t):(ke(e)||null==t||t(e),null)}))}function De(e){return null===e?"":void 0!==e.props.value?e.props.value:Array.isArray(e.props.children)?e.props.children.filter((function(e){return!ke(e)})).join(""):e.props.children.toString()}function Se(e,n){var r,t,o;return null!==(r=e.props.disabled)&&void 0!==r&&r||null!==(t=null==n||null===(o=n.props)||void 0===o?void 0:o.disabled)&&void 0!==t&&t}function Ce(e,n,r){return De(e)===r&&!Se(e,n)}function je(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.initialValue,t=n.deps,o=void 0===t?[]:t,a=i(r);return u((function(){return{get current(){return a.current},set current(n){a.current=n,e(n)}}}),[e,a].concat(A(o)))}function Fe(e,n){var r=a((function(e,n){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(n):e&&(e.current=n)}),[]);return je(a((function(n){return r(e,n)}),[e,r]),{initialValue:n})}we.displayName="OptionGroup",Oe.displayName="OptionGroup",Oe.propTypes={children:s.oneOfType([s.element,s.arrayOf(s.oneOfType([s.oneOf([!1,null,void 0,""]),s.element]))]).isRequired,className:s.string,label:s.string.isRequired,disabled:s.bool};var Pe=function(e){var n=z(c(e),2),r=n[0];return je(n[1],{initialValue:e,deps:[r]})};function ze(){var e=P(["\n font-family: ",";\n font-size: ","px;\n max-height: ","px;\n background-color: ",";\n box-shadow: 0 3px 7px 0 ",";\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n }\n "]);return ze=function(){return e},e}function Ae(){var e=P(["\n position: relative;\n text-align: left;\n width: 100%;\n border-radius: 3px;\n line-height: 16px;\n list-style: none;\n margin: 0;\n padding: 0;\n overflow: auto;\n"]);return Ae=function(){return e},e}var He=d(Ae()),Te=r.forwardRef((function(e,n){var t=e.children,i=e.id,l=e.referenceElement,u=e.onClose,c=e.onFocusPreviousOption,s=e.onFocusNextOption,p=e.onSelectFocusedOption,h=e.className,v=e.usePortal,k=e.labelId,E=o(Y),N=E.mode,D=E.size,S=E.disabled,C=E.open,j=L[N],F=R[D],P=Fe(n,null),z=a((function(e){if(!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case g.Tab:case g.Enter:p(e);break;case g.Escape:u();break;case g.ArrowUp:c();break;case g.ArrowDown:s();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[u,s,c,p]),A=b(),H=null===A||null===P.current?0:A.height-P.current.getBoundingClientRect().top-10,T=a((function(e){P.current&&P.current.focus(),e.stopPropagation()}),[P]);return r.createElement(x,{active:C&&!S,spacing:4,align:w.Bottom,justify:O.Middle,adjustOnMutation:!0,className:h,refEl:l,usePortal:v},r.createElement("ul",{"aria-labelledby":k,role:"listbox",ref:P,tabIndex:-1,onKeyDown:z,onClick:T,className:f(He,d(ze(),m.default,F.option.text,H,j.option.background.base,j.menu.shadow,y.Desktop,W.text)),id:i},t))}));function Ie(){var e=P(["\n height: ","px;\n font-size: ","px;\n width: 100%;\n color: ",";\n border-color: ",";\n\n @media only screen and (max-width: ","px) {\n height: ","px;\n font-size: ","px;\n }\n "]);return Ie=function(){return e},e}function Ge(){var e=P(["\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n"]);return Ge=function(){return e},e}function Ke(){var e=P(["\n margin-top: 2px;\n\n // reset default Button padding\n > span {\n padding: 0;\n }\n"]);return Ke=function(){return e},e}Te.displayName="ListMenu";var Ve=d(Ke()),Le=d(Ge()),Me=r.forwardRef((function(e,n){var t=e.children,i=e.value,l=e.text,u=e.name,c=e.deselected,s=(e.readOnly,e.onDeselect),p=e.onFocusFirstOption,b=e.onFocusLastOption,h=e.onClose,v=e.onOpen,m=F(e,["children","value","text","name","deselected","readOnly","onDeselect","onFocusFirstOption","onFocusLastOption","onClose","onOpen"]),x=o(Y),w=x.mode,O=x.open,k=x.size,E=x.disabled,C=Fe(n,null),P=L[w],z=R[k],A=a((function(e){if(!E&&!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case g.Tab:h(),n=!0;break;case g.Escape:O?h():s(e);break;case g.ArrowUp:v(),b();break;case g.ArrowDown:v(),p();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[E,h,s,p,b,v,O]),H=a((function(){O?h():v(),C.current.focus()}),[h,v,O,C]);return r.createElement(N,j({},m,{ref:C,name:u,value:i,disabled:E,onClick:H,onKeyDown:A,variant:D.Default,darkMode:w===K,rightGlyph:r.createElement(S,null),className:f(Ve,d(Ie(),z.height,z.text,c?P.text.deselected:P.text.base,O&&!E?P.border.open:P.border.base,y.Desktop,B,q))}),r.createElement("span",{className:Le},l),t)}));function Re(){var e=P(["\n width: ","px;\n "]);return Re=function(){return e},e}function Be(){var e=P(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return Be=function(){return e},e}function qe(){var e=P(["\n cursor: not-allowed;\n "]);return qe=function(){return e},e}function Ue(){var e=P(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return Ue=function(){return e},e}function Xe(){var e=P(["\n cursor: not-allowed;\n "]);return Xe=function(){return e},e}function We(){var e=P(["\n margin-bottom: 2px;\n font-weight: bold;\n"]);return We=function(){return e},e}function Ye(){var e=P(["\n font-family: ",";\n display: block;\n"]);return Ye=function(){return e},e}Me.displayName="MenuButton";var $e=d(Ye(),m.default),Je=d(We()),Qe=h.create("select");function Ze(e){var n,t=e.children,o=e.darkMode,i=void 0!==o&&o,s=e.size,p=void 0===s?M.Default:s,h=e.disabled,v=void 0!==h&&h,g=e.usePortal,m=void 0===g||g,x=e.placeholder,w=void 0===x?"Select":x,O=e.className,k=e.id,E=e.label,N=e.description,D=e.name,S=e.defaultValue,j=e.value,F=e.onChange,P=e.readOnly,A=e["aria-labelledby"];E||A||console.error("For screen-reader accessibility, label or aria-labelledby must be provided to Select.");var H=u((function(){return null!=k?k:Qe.generate()}),[k]),T=u((function(){return null!=A?A:"".concat(H,"-label")}),[A,H]),I="".concat(H,"-description"),G="".concat(H,"-menu"),B=z(c(!1),2),q=B[0],W=B[1],$=Pe(null),J=Pe(null),Q=i?K:V,Z=L[Q],_=R[p],ee=u((function(){return{mode:Q,size:p,open:q,disabled:v}}),[Q,p,q,v]);l((function(){void 0!==j&&void 0===F&&!0!==P&&console.warn("You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.")}),[F,P,j]);var ne=a((function(){W(!0)}),[]),re=a((function(){W(!1),$.current.focus()}),[$]);l((function(){if(q){var e=function(e){var n=$.current.contains(e.target)||J.current.contains(e.target);W(n)};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}}),[J,$,q]);var te=u((function(){var e=null;return void 0===j&&void 0!==S&&Ee(t,(function(n,r){Ce(n,r,S)&&(e=n)})),e}),[t,S,j]),oe=z(c(te),2),ie=oe[0],ae=oe[1];l((function(){var e;null!==ie&&ae(null!==(e=function(e,n){var r,t,o,i,a,l,u,c;return Ee(e,(function(e){if(e===n)a=n;else if(e.props.children===n.props.children&&e.props.value===n.props.value){var r;null!==(r=l)&&void 0!==r||(l=e)}else if(void 0!==e.props.value&&e.props.value===n.props.value){var t;null!==(t=u)&&void 0!==t||(u=e)}else if(De(e)===De(n)){var o;null!==(o=c)&&void 0!==o||(c=e)}})),null!==(r=null!==(t=null!==(o=null!==(i=a)&&void 0!==i?i:l)&&void 0!==o?o:u)&&void 0!==t?t:c)&&void 0!==r?r:null}(t,ie))&&void 0!==e?e:te)}),[t,te,ie]);var le=u((function(){if(void 0!==j){var e=null;return Ee(t,(function(n,r){Ce(n,r,j)&&(e=n)})),e}return ie}),[t,ie,j]),ue=a((function(e,n){void 0===j&&ae(e),null==F||F(De(e),n),be(void 0),re()}),[F,re,j]),ce=a((function(e,n){return function(r){r.preventDefault(),r.stopPropagation(),v||n||(ue(e,r),re())}}),[v,re,ue]),se=a((function(e){ue(null,e)}),[ue]),fe=z(c(),2),pe=fe[0],be=fe[1],he=u((function(){var e=[null];return Ee(t,(function(n,r){Se(n,r)||e.push(n)})),e}),[t]),ve=a((function(e){void 0!==pe&&ue(pe,e)}),[pe,ue]),ge=a((function(){be(null)}),[]),me=a((function(){be(he[he.length-1])}),[he]),ye=a((function(){if(void 0===pe||0===he.indexOf(pe))me();else{var e=he.indexOf(pe)-1;be(he[e])}}),[he,pe,me]),xe=a((function(){if(void 0===pe||he.indexOf(pe)===he.length-1)ge();else{var e=he.indexOf(pe)+1;be(he[e])}}),[he,pe,ge]),we=a((function(e,n){return function(r){r.preventDefault(),r.stopPropagation(),v||n||be(e)}}),[v]),Oe=b(),ke=u((function(){var e=!1;return Ee(t,(function(n){e||(e=void 0!==n.props.glyph)})),e}),[t]),je=u((function(){return null!==Oe&&null!==J.current&&void 0===pe&&q}),[pe,J,q,Oe]),Fe=u((function(){var e=null===le;return r.createElement(de,{className:void 0,glyph:void 0,selected:e,focused:null===pe,disabled:!1,onClick:ce(null,!1),onFocus:we(null,!1),isDeselection:!0,hasGlyphs:!0,triggerScrollIntoView:e&&je},w)}),[je,pe,ce,we,w,le]),ze=u((function(){return Ne(t,(function(e,n){var r=e===le,t=Se(e,n);return{className:e.props.className,glyph:e.props.glyph,selected:r,focused:e===pe,disabled:t,children:e.props.children,isDeselection:!1,hasGlyphs:ke,onClick:ce(e,t),onFocus:we(e,t),triggerScrollIntoView:r&&je}}),(function(){console.error("`Select` instance received child that is not `Option` or `OptionGroup`.")}))}),[je,t,pe,ce,we,ke,le]);return r.createElement("div",{className:f(C({},d(Xe()),v),O)},E&&r.createElement("label",{id:T,className:f($e,Je,d(Ue(),v?Z.label.disabled:Z.label.base,_.label.text,_.label.lineHeight,y.Desktop,U.text,U.lineHeight),C({},d(qe()),v))},E),N&&r.createElement("div",{id:I,className:f($e,d(Be(),Z.description,_.description.text,_.description.lineHeight,y.Desktop,X.text,X.lineHeight))},N),r.createElement(Y.Provider,{value:ee},r.createElement(Me,{ref:$,name:D,readOnly:P,value:De(le),text:null!==le?le.props.children:w,deselected:null===le,onDeselect:se,onOpen:ne,onClose:re,onFocusFirstOption:ge,onFocusLastOption:me,"aria-labelledby":T,"aria-controls":G,"aria-expanded":q,"aria-describedby":I},r.createElement(Te,{labelId:T,id:G,referenceElement:$,ref:J,onClose:re,onSelectFocusedOption:ve,onFocusPreviousOption:ye,onFocusNextOption:xe,usePortal:m,className:d(Re(),null===(n=$.current)||void 0===n?void 0:n.clientWidth)},Fe,ze))))}Ze.displayName="Select",Ze.propTypes={label:s.string,"aria-labelledby":s.string,description:s.string,placeholder:s.string,className:s.string,darkMode:s.bool,size:s.oneOf(Object.values(M)),disabled:s.bool,id:s.string,value:s.string,defaultValue:s.string,onChange:s.func,readOnly:s.bool};export{fe as Option,Oe as OptionGroup,Ze as Select,M as Size}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("polished"),require("@leafygreen-ui/palette"),require("react"),require("prop-types"),require("@leafygreen-ui/emotion"),require("@leafygreen-ui/hooks"),require("@leafygreen-ui/lib"),require("@leafygreen-ui/tokens"),require("@leafygreen-ui/popover"),require("@leafygreen-ui/icon/dist/Checkmark"),require("react-is"),require("@leafygreen-ui/button"),require("@leafygreen-ui/icon/dist/CaretDown")):"function"==typeof define&&define.amd?define(["exports","polished","@leafygreen-ui/palette","react","prop-types","@leafygreen-ui/emotion","@leafygreen-ui/hooks","@leafygreen-ui/lib","@leafygreen-ui/tokens","@leafygreen-ui/popover","@leafygreen-ui/icon/dist/Checkmark","react-is","@leafygreen-ui/button","@leafygreen-ui/icon/dist/CaretDown"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/select"]={},e.polished,e["@leafygreen-ui/palette"],e.React,e.PropTypes,e["@leafygreen-ui/emotion"],e["@leafygreen-ui/hooks"],e["@leafygreen-ui/lib"],e["@leafygreen-ui/tokens"],e["@leafygreen-ui/popover"],e.Checkmark,e.reactIs,e["@leafygreen-ui/button"],e.CaretDown)}(this,(function(e,n,t,r,o,a,l,i,u,s,c,d,f,p){"use strict";function b(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var g,y,h=b(r),v=b(o),m=b(s),x=b(c),k=b(f),C=b(p);function w(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function O(){return(O=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function E(e,n){if(null==e)return{};var t,r,o=function(e,n){if(null==e)return{};var t,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(o[t]=e[t]);return o}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function N(e,n){return n||(n=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(n)}}))}function S(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var t=[],r=!0,o=!1,a=void 0;try{for(var l,i=e[Symbol.iterator]();!(r=(l=i.next()).done)&&(t.push(l.value),!n||t.length!==n);r=!0);}catch(e){o=!0,a=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw a}}return t}(e,n)||M(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(e){return function(e){if(Array.isArray(e))return F(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||M(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function M(e,n){if(e){if("string"==typeof e)return F(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?F(e,n):void 0}}function F(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var j="dark",z="light",P=(w(g={},z,{label:{base:t.uiColors.gray.dark3,disabled:t.uiColors.gray.dark1},description:t.uiColors.gray.dark1,border:{base:t.uiColors.gray.light1,open:t.uiColors.gray.dark1},text:{base:t.uiColors.gray.dark3,deselected:t.uiColors.gray.dark1,disabled:t.uiColors.gray.base},menu:{shadow:n.transparentize(.78,t.uiColors.black)},option:{group:{label:t.uiColors.gray.dark3,border:t.uiColors.gray.light2},background:{base:t.uiColors.white,hovered:t.uiColors.gray.light2,focused:t.uiColors.blue.light3},text:{base:t.uiColors.gray.dark3,selected:t.uiColors.blue.base,disabled:t.uiColors.gray.base},icon:{base:t.uiColors.gray.dark1,selected:t.uiColors.blue.base,disabled:t.uiColors.gray.base}}}),w(g,j,{label:{base:t.uiColors.white,disabled:t.uiColors.gray.light1},description:t.uiColors.gray.light1,border:{base:t.uiColors.gray.dark2,open:t.uiColors.gray.dark2},text:{base:t.uiColors.white,deselected:t.uiColors.gray.light1,disabled:t.uiColors.gray.dark1},menu:{shadow:n.transparentize(.2,t.uiColors.black)},option:{group:{label:t.uiColors.white,border:t.uiColors.gray.dark1},background:{base:t.uiColors.gray.dark2,hovered:t.uiColors.gray.dark1,focused:t.uiColors.blue.base},text:{base:t.uiColors.white,selected:"#9DD0E7",disabled:t.uiColors.gray.base},icon:{base:t.uiColors.gray.light1,selected:"#9DD0E7",disabled:t.uiColors.gray.base}}}),g),T={XSmall:"xsmall",Small:"small",Default:"default",Large:"large"},A=(w(y={},T.XSmall,{height:22,text:12,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),w(y,T.Small,{height:28,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),w(y,T.Default,{height:36,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:20},option:{text:14}}),w(y,T.Large,{height:48,text:18,label:{text:18,lineHeight:21},description:{text:18,lineHeight:24},option:{text:16}}),y),I=36,q=16,H={text:16,lineHeight:19},G={text:16,lineHeight:22},V={text:16},K=r.createContext({mode:z,size:T.Default,open:!1,disabled:!1});function R(){var e=N(["\n cursor: not-allowed;\n color: ",";\n "]);return R=function(){return e},e}function L(){var e=N(["\n cursor: pointer;\n color: ",";\n "]);return L=function(){return e},e}function B(){var e=N(["\n display: flex;\n "]);return B=function(){return e},e}function U(){var e=N(["\n display: flex;\n justify-content: space-between;\n width: 100%;\n "]);return U=function(){return e},e}function X(){var e=N(["\n color: ",";\n "]);return X=function(){return e},e}function _(){var e=N(["\n color: ",";\n "]);return _=function(){return e},e}function J(){var e=N(["\n color: ",";\n "]);return J=function(){return e},e}function W(){var e=N(["\n color: ",";\n "]);return W=function(){return e},e}function Y(){var e=N(["\n height: 100%;\n "]);return Y=function(){return e},e}function $(){var e=N(["\n font-weight: bold;\n "]);return $=function(){return e},e}function Q(){var e=N(["\n min-width: 16px;\n margin-right: 6px;\n"]);return Q=function(){return e},e}function Z(){var e=N(["\n display: flex;\n align-items: center;\n"]);return Z=function(){return e},e}function ee(){var e=N(["\n display: flex;\n width: 100%;\n padding: 10px 12px;\n outline: none;\n overflow-wrap: anywhere;\n transition: background-color 150ms ease-in-out;\n"]);return ee=function(){return e},e}var ne=a.css(ee()),te=a.css(Z()),re=a.css(Q());function oe(e){var n,t=e.children,o=e.className,i=e.glyph,u=e.selected,s=e.focused,c=e.disabled,d=e.onClick,f=e.onFocus,p=e.isDeselection,b=e.triggerScrollIntoView,g=e.hasGlyphs,y=r.useContext(K).mode,v=P[y].option,m=r.useRef(null),k=r.useCallback((function(){var e=m.current,n=e.offsetParent;n.scrollTop=e.offsetTop+(e.clientHeight-n.clientHeight)/2}),[m]),C=l.usePrevious(b),O=b&&!C;r.useEffect((function(){O&&k()}),[k,O]);var E=l.usePrevious(s),N=s&&!E;r.useEffect((function(){N&&m.current.focus()}),[N]);var S=h.default.createElement("span",{className:a.cx(te,w({},a.css($()),u&&!p))},t),D=h.default.createElement("span",{className:a.cx(re,a.css(Y()))}),M=D;i&&(i.type.isGlyph?M=h.default.cloneElement(i,{key:"glyph",className:a.cx(re,a.css(W(),v.icon.base),w({},a.css(J(),v.icon.disabled),c),i.props.className)}):console.error("`Option` instance did not render icon because it is not a known glyph element."));var F,j=u&&!p?h.default.createElement(x.default,{key:"checkmark",className:a.cx(re,a.css(_(),v.icon.selected),w({},a.css(X(),v.icon.disabled),c))}):D;return F=g?h.default.createElement("span",{className:a.css(U())},h.default.createElement("span",{className:a.css(B())},M,S),j):h.default.createElement(h.default.Fragment,null,j,S),h.default.createElement("li",{role:"option","aria-selected":u,tabIndex:-1,ref:m,className:a.cx(ne,a.css(L(),v.text.base),(n={},w(n,a.css("\n &:focus {\n background-color: ".concat(v.background.focused,";\n }\n\n &:hover {\n background-color: ").concat(v.background.hovered,";\n }\n ")),!c),w(n,a.css(R(),v.text.disabled),c),n),o),onClick:d,onFocus:f,onKeyDown:void 0},F)}function ae(e){throw Error("`Option` must be a child of a `Select` instance")}oe.displayName="Option",ae.displayName="Option";var le=v.default.oneOfType([v.default.string,v.default.number]);function ie(){var e=N(["\n color: ",";\n "]);return ie=function(){return e},e}function ue(){var e=N(["\n border-bottom: 1px solid ",";\n "]);return ue=function(){return e},e}function se(){var e=N(["\n cursor: default;\n width: 100%;\n padding: 0 12px 2px;\n outline: none;\n overflow-wrap: anywhere;\n font-size: 13px;\n line-height: 16px;\n font-weight: bold;\n"]);return se=function(){return e},e}function ce(){var e=N(["\n padding-top: 8px;\n"]);return ce=function(){return e},e}ae.propTypes={children:v.default.oneOfType([le,v.default.arrayOf(v.default.oneOfType([le,v.default.oneOf([!1,null,void 0,""])]))]).isRequired,className:v.default.string,glyph:v.default.element,value:v.default.string,disabled:v.default.bool};var de=a.css(ce()),fe=a.css(se()),pe=i.IdAllocator.create("select-option-group");function be(e){var n=e.className,t=e.label,o=e.children,l=r.useContext(K).mode,i=P[l].option,u=r.useMemo((function(){return pe.generate()}),[]);return h.default.createElement("div",{className:a.cx(de,a.css(ue(),i.group.border),n)},h.default.createElement("div",{id:u,className:a.cx(fe,a.css(ie(),i.group.label))},t),h.default.createElement("div",{role:"group","aria-labelledby":u},o))}function ge(e){throw Error("`OptionGroup` must be a child of a `Select` instance")}function ye(e){return null==e||!1===e||""===e}function he(e,n){h.default.Children.forEach(e,(function(e){i.isComponentType(e,"Option")?n(e):i.isComponentType(e,"OptionGroup")?he(e.props.children,(function(t){return n(t,e)})):d.isFragment(e)&&he(e.props.children,n)}))}function ve(e,n,t){return h.default.Children.map(e,(function(e){if(i.isComponentType(e,"Option"))return h.default.createElement(oe,n(e));if(i.isComponentType(e,"OptionGroup")){var r=e.props,o=r.children,a=E(r,["children"]);return h.default.createElement(be,O({className:void 0},a),ve(o,(function(t){return n(t,e)}),t))}return d.isFragment(e)?ve(e.props.children,n,t):(ye(e)||null==t||t(e),null)}))}function me(e){return null===e?"":void 0!==e.props.value?e.props.value:Array.isArray(e.props.children)?e.props.children.filter((function(e){return!ye(e)})).join(""):e.props.children.toString()}function xe(e,n){var t,r,o;return null!==(t=e.props.disabled)&&void 0!==t&&t||null!==(r=null==n||null===(o=n.props)||void 0===o?void 0:o.disabled)&&void 0!==r&&r}function ke(e,n,t){return me(e)===t&&!xe(e,n)}function Ce(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=n.initialValue,o=n.deps,a=void 0===o?[]:o,l=r.useRef(t);return r.useMemo((function(){return{get current(){return l.current},set current(n){l.current=n,e(n)}}}),[e,l].concat(D(a)))}function we(e,n){var t=r.useCallback((function(e,n){Array.isArray(e)?e.forEach(t):"function"==typeof e?e(n):e&&(e.current=n)}),[]);return Ce(r.useCallback((function(n){return t(e,n)}),[e,t]),{initialValue:n})}be.displayName="OptionGroup",ge.displayName="OptionGroup",ge.propTypes={children:v.default.oneOfType([v.default.element,v.default.arrayOf(v.default.oneOfType([v.default.oneOf([!1,null,void 0,""]),v.default.element]))]).isRequired,className:v.default.string,label:v.default.string.isRequired,disabled:v.default.bool};var Oe=function(e){var n=S(r.useState(e),2),t=n[0];return Ce(n[1],{initialValue:e,deps:[t]})};function Ee(){var e=N(["\n font-family: ",";\n font-size: ","px;\n max-height: ","px;\n background-color: ",";\n box-shadow: 0 3px 7px 0 ",";\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n }\n "]);return Ee=function(){return e},e}function Ne(){var e=N(["\n position: relative;\n text-align: left;\n width: 100%;\n border-radius: 3px;\n line-height: 16px;\n list-style: none;\n margin: 0;\n padding: 0;\n overflow: auto;\n"]);return Ne=function(){return e},e}var Se=a.css(Ne()),De=h.default.forwardRef((function(e,n){var t=e.children,o=e.id,c=e.referenceElement,d=e.onClose,f=e.onFocusPreviousOption,p=e.onFocusNextOption,b=e.onSelectFocusedOption,g=e.className,y=e.usePortal,v=e.labelId,x=r.useContext(K),k=x.mode,C=x.size,w=x.disabled,O=x.open,E=P[k],N=A[C],S=we(n,null),D=r.useCallback((function(e){if(!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case i.keyMap.Tab:case i.keyMap.Enter:b(e);break;case i.keyMap.Escape:d();break;case i.keyMap.ArrowUp:f();break;case i.keyMap.ArrowDown:p();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[d,p,f,b]),M=l.useViewportSize(),F=null===M||null===S.current?0:M.height-S.current.getBoundingClientRect().top-10,j=r.useCallback((function(e){S.current&&S.current.focus(),e.stopPropagation()}),[S]);return h.default.createElement(m.default,{active:O&&!w,spacing:4,align:s.Align.Bottom,justify:s.Justify.Middle,adjustOnMutation:!0,className:g,refEl:c,usePortal:y},h.default.createElement("ul",{"aria-labelledby":v,role:"listbox",ref:S,tabIndex:-1,onKeyDown:D,onClick:j,className:a.cx(Se,a.css(Ee(),u.fontFamilies.default,N.option.text,F,E.option.background.base,E.menu.shadow,u.breakpoints.Desktop,V.text)),id:o},t))}));function Me(){var e=N(["\n height: ","px;\n font-size: ","px;\n width: 100%;\n color: ",";\n border-color: ",";\n\n @media only screen and (max-width: ","px) {\n height: ","px;\n font-size: ","px;\n }\n "]);return Me=function(){return e},e}function Fe(){var e=N(["\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n"]);return Fe=function(){return e},e}function je(){var e=N(["\n margin-top: 2px;\n\n // reset default Button padding\n > span {\n padding: 0;\n }\n"]);return je=function(){return e},e}De.displayName="ListMenu";var ze=a.css(je()),Pe=a.css(Fe()),Te=h.default.forwardRef((function(e,n){var t=e.children,o=e.value,l=e.text,s=e.name,c=e.deselected,d=(e.readOnly,e.onDeselect),p=e.onFocusFirstOption,b=e.onFocusLastOption,g=e.onClose,y=e.onOpen,v=E(e,["children","value","text","name","deselected","readOnly","onDeselect","onFocusFirstOption","onFocusLastOption","onClose","onOpen"]),m=r.useContext(K),x=m.mode,w=m.open,N=m.size,S=m.disabled,D=we(n,null),M=P[x],F=A[N],z=r.useCallback((function(e){if(!S&&!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case i.keyMap.Tab:g(),n=!0;break;case i.keyMap.Escape:w?g():d(e);break;case i.keyMap.ArrowUp:y(),b();break;case i.keyMap.ArrowDown:y(),p();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[S,g,d,p,b,y,w]),T=r.useCallback((function(){w?g():y(),D.current.focus()}),[g,y,w,D]);return h.default.createElement(k.default,O({},v,{ref:D,name:s,value:o,disabled:S,onClick:T,onKeyDown:z,variant:f.Variant.Default,darkMode:x===j,rightGlyph:h.default.createElement(C.default,null),className:a.cx(ze,a.css(Me(),F.height,F.text,c?M.text.deselected:M.text.base,w&&!S?M.border.open:M.border.base,u.breakpoints.Desktop,I,q))}),h.default.createElement("span",{className:Pe},l),t)}));function Ae(){var e=N(["\n width: ","px;\n "]);return Ae=function(){return e},e}function Ie(){var e=N(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return Ie=function(){return e},e}function qe(){var e=N(["\n cursor: not-allowed;\n "]);return qe=function(){return e},e}function He(){var e=N(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return He=function(){return e},e}function Ge(){var e=N(["\n cursor: not-allowed;\n "]);return Ge=function(){return e},e}function Ve(){var e=N(["\n margin-bottom: 2px;\n font-weight: bold;\n"]);return Ve=function(){return e},e}function Ke(){var e=N(["\n font-family: ",";\n display: block;\n"]);return Ke=function(){return e},e}Te.displayName="MenuButton";var Re=a.css(Ke(),u.fontFamilies.default),Le=a.css(Ve()),Be=i.IdAllocator.create("select");function Ue(e){var n,t=e.children,o=e.darkMode,i=void 0!==o&&o,s=e.size,c=void 0===s?T.Default:s,d=e.disabled,f=void 0!==d&&d,p=e.usePortal,b=void 0===p||p,g=e.placeholder,y=void 0===g?"Select":g,v=e.className,m=e.id,x=e.label,k=e.description,C=e.name,O=e.defaultValue,E=e.value,N=e.onChange,D=e.readOnly,M=e["aria-labelledby"],F=r.useMemo((function(){return null!=m?m:Be.generate()}),[m]),I=r.useMemo((function(){return null!=M?M:"".concat(F,"-label")}),[M,F]),q="".concat(F,"-description"),V="".concat(F,"-menu"),R=S(r.useState(!1),2),L=R[0],B=R[1],U=Oe(null),X=Oe(null),_=i?j:z,J=P[_],W=A[c],Y=r.useMemo((function(){return{mode:_,size:c,open:L,disabled:f}}),[_,c,L,f]);r.useEffect((function(){void 0!==E&&void 0===N&&!0!==D&&console.warn("You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.")}),[N,D,E]),x||M||console.error("For screen-reader accessibility, label or aria-labelledby must be provided to IconButton.");var $=r.useCallback((function(){B(!0)}),[]),Q=r.useCallback((function(){B(!1),U.current.focus()}),[U]);r.useEffect((function(){if(L){var e=function(e){var n=U.current.contains(e.target)||X.current.contains(e.target);B(n)};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}}),[X,U,L]);var Z=r.useMemo((function(){var e=null;return void 0===E&&void 0!==O&&he(t,(function(n,t){ke(n,t,O)&&(e=n)})),e}),[t,O,E]),ee=S(r.useState(Z),2),ne=ee[0],te=ee[1];r.useEffect((function(){var e;null!==ne&&te(null!==(e=function(e,n){var t,r,o,a,l,i,u,s;return he(e,(function(e){if(e===n)l=n;else if(e.props.children===n.props.children&&e.props.value===n.props.value){var t;null!==(t=i)&&void 0!==t||(i=e)}else if(void 0!==e.props.value&&e.props.value===n.props.value){var r;null!==(r=u)&&void 0!==r||(u=e)}else if(me(e)===me(n)){var o;null!==(o=s)&&void 0!==o||(s=e)}})),null!==(t=null!==(r=null!==(o=null!==(a=l)&&void 0!==a?a:i)&&void 0!==o?o:u)&&void 0!==r?r:s)&&void 0!==t?t:null}(t,ne))&&void 0!==e?e:Z)}),[t,Z,ne]);var re=r.useMemo((function(){if(void 0!==E){var e=null;return he(t,(function(n,t){ke(n,t,E)&&(e=n)})),e}return ne}),[t,ne,E]),ae=r.useCallback((function(e,n){void 0===E&&te(e),null==N||N(me(e),n),ce(void 0),Q()}),[N,Q,E]),le=r.useCallback((function(e,n){return function(t){t.preventDefault(),t.stopPropagation(),f||n||(ae(e,t),Q())}}),[f,Q,ae]),ie=r.useCallback((function(e){ae(null,e)}),[ae]),ue=S(r.useState(),2),se=ue[0],ce=ue[1],de=r.useMemo((function(){var e=[null];return he(t,(function(n,t){xe(n,t)||e.push(n)})),e}),[t]),fe=r.useCallback((function(e){void 0!==se&&ae(se,e)}),[se,ae]),pe=r.useCallback((function(){ce(null)}),[]),be=r.useCallback((function(){ce(de[de.length-1])}),[de]),ge=r.useCallback((function(){if(void 0===se||0===de.indexOf(se))be();else{var e=de.indexOf(se)-1;ce(de[e])}}),[de,se,be]),ye=r.useCallback((function(){if(void 0===se||de.indexOf(se)===de.length-1)pe();else{var e=de.indexOf(se)+1;ce(de[e])}}),[de,se,pe]),Ce=r.useCallback((function(e,n){return function(t){t.preventDefault(),t.stopPropagation(),f||n||ce(e)}}),[f]),we=l.useViewportSize(),Ee=r.useMemo((function(){var e=!1;return he(t,(function(n){e||(e=void 0!==n.props.glyph)})),e}),[t]),Ne=r.useMemo((function(){return null!==we&&null!==X.current&&void 0===se&&L}),[se,X,L,we]),Se=r.useMemo((function(){var e=null===re;return h.default.createElement(oe,{className:void 0,glyph:void 0,selected:e,focused:null===se,disabled:!1,onClick:le(null,!1),onFocus:Ce(null,!1),isDeselection:!0,hasGlyphs:!0,triggerScrollIntoView:e&&Ne},y)}),[Ne,se,le,Ce,y,re]),Me=r.useMemo((function(){return ve(t,(function(e,n){var t=e===re,r=xe(e,n);return{className:e.props.className,glyph:e.props.glyph,selected:t,focused:e===se,disabled:r,children:e.props.children,isDeselection:!1,hasGlyphs:Ee,onClick:le(e,r),onFocus:Ce(e,r),triggerScrollIntoView:t&&Ne}}),(function(){console.error("`Select` instance received child that is not `Option` or `OptionGroup`.")}))}),[Ne,t,se,le,Ce,Ee,re]);return h.default.createElement("div",{className:a.cx(w({},a.css(Ge()),f),v)},x&&h.default.createElement("label",{id:I,className:a.cx(Re,Le,a.css(He(),f?J.label.disabled:J.label.base,W.label.text,W.label.lineHeight,u.breakpoints.Desktop,H.text,H.lineHeight),w({},a.css(qe()),f))},x),k&&h.default.createElement("div",{id:q,className:a.cx(Re,a.css(Ie(),J.description,W.description.text,W.description.lineHeight,u.breakpoints.Desktop,G.text,G.lineHeight))},k),h.default.createElement(K.Provider,{value:Y},h.default.createElement(Te,{ref:U,name:C,readOnly:D,value:me(re),text:null!==re?re.props.children:y,deselected:null===re,onDeselect:ie,onOpen:$,onClose:Q,onFocusFirstOption:pe,onFocusLastOption:be,"aria-labelledby":I,"aria-controls":V,"aria-expanded":L,"aria-describedby":q},h.default.createElement(De,{labelId:I,id:V,referenceElement:U,ref:X,onClose:Q,onSelectFocusedOption:fe,onFocusPreviousOption:ge,onFocusNextOption:ye,usePortal:b,className:a.css(Ae(),null===(n=U.current)||void 0===n?void 0:n.clientWidth)},Se,Me))))}Ue.displayName="Select",Ue.propTypes={label:v.default.string,"aria-labelledby":v.default.string,description:v.default.string,placeholder:v.default.string,className:v.default.string,darkMode:v.default.bool,size:v.default.oneOf(Object.values(T)),disabled:v.default.bool,id:v.default.string,value:v.default.string,defaultValue:v.default.string,onChange:v.default.func,readOnly:v.default.bool},e.Option=ae,e.OptionGroup=ge,e.Select=Ue,e.Size=T,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("polished"),require("@leafygreen-ui/palette"),require("react"),require("prop-types"),require("@leafygreen-ui/emotion"),require("@leafygreen-ui/hooks"),require("@leafygreen-ui/lib"),require("@leafygreen-ui/tokens"),require("@leafygreen-ui/popover"),require("@leafygreen-ui/icon/dist/Checkmark"),require("react-is"),require("@leafygreen-ui/button"),require("@leafygreen-ui/icon/dist/CaretDown")):"function"==typeof define&&define.amd?define(["exports","polished","@leafygreen-ui/palette","react","prop-types","@leafygreen-ui/emotion","@leafygreen-ui/hooks","@leafygreen-ui/lib","@leafygreen-ui/tokens","@leafygreen-ui/popover","@leafygreen-ui/icon/dist/Checkmark","react-is","@leafygreen-ui/button","@leafygreen-ui/icon/dist/CaretDown"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/select"]={},e.polished,e["@leafygreen-ui/palette"],e.React,e.PropTypes,e["@leafygreen-ui/emotion"],e["@leafygreen-ui/hooks"],e["@leafygreen-ui/lib"],e["@leafygreen-ui/tokens"],e["@leafygreen-ui/popover"],e.Checkmark,e.reactIs,e["@leafygreen-ui/button"],e.CaretDown)}(this,(function(e,n,t,r,o,a,l,i,u,s,c,d,f,p){"use strict";function b(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var g,y,h=b(r),v=b(o),m=b(s),x=b(c),k=b(f),C=b(p);function w(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function O(){return(O=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function E(e,n){if(null==e)return{};var t,r,o=function(e,n){if(null==e)return{};var t,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(o[t]=e[t]);return o}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function N(e,n){return n||(n=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(n)}}))}function S(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var t=[],r=!0,o=!1,a=void 0;try{for(var l,i=e[Symbol.iterator]();!(r=(l=i.next()).done)&&(t.push(l.value),!n||t.length!==n);r=!0);}catch(e){o=!0,a=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw a}}return t}(e,n)||M(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(e){return function(e){if(Array.isArray(e))return F(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||M(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function M(e,n){if(e){if("string"==typeof e)return F(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?F(e,n):void 0}}function F(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var j="dark",z="light",P=(w(g={},z,{label:{base:t.uiColors.gray.dark3,disabled:t.uiColors.gray.dark1},description:t.uiColors.gray.dark1,border:{base:t.uiColors.gray.light1,open:t.uiColors.gray.dark1},text:{base:t.uiColors.gray.dark3,deselected:t.uiColors.gray.dark1,disabled:t.uiColors.gray.base},menu:{shadow:n.transparentize(.78,t.uiColors.black)},option:{group:{label:t.uiColors.gray.dark3,border:t.uiColors.gray.light2},background:{base:t.uiColors.white,hovered:t.uiColors.gray.light2,focused:t.uiColors.blue.light3},text:{base:t.uiColors.gray.dark3,selected:t.uiColors.blue.base,disabled:t.uiColors.gray.base},icon:{base:t.uiColors.gray.dark1,selected:t.uiColors.blue.base,disabled:t.uiColors.gray.base}}}),w(g,j,{label:{base:t.uiColors.white,disabled:t.uiColors.gray.light1},description:t.uiColors.gray.light1,border:{base:t.uiColors.gray.dark2,open:t.uiColors.gray.dark2},text:{base:t.uiColors.white,deselected:t.uiColors.gray.light1,disabled:t.uiColors.gray.dark1},menu:{shadow:n.transparentize(.2,t.uiColors.black)},option:{group:{label:t.uiColors.white,border:t.uiColors.gray.dark1},background:{base:t.uiColors.gray.dark2,hovered:t.uiColors.gray.dark1,focused:t.uiColors.blue.base},text:{base:t.uiColors.white,selected:"#9DD0E7",disabled:t.uiColors.gray.base},icon:{base:t.uiColors.gray.light1,selected:"#9DD0E7",disabled:t.uiColors.gray.base}}}),g),T={XSmall:"xsmall",Small:"small",Default:"default",Large:"large"},A=(w(y={},T.XSmall,{height:22,text:12,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),w(y,T.Small,{height:28,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:16},option:{text:14}}),w(y,T.Default,{height:36,text:14,label:{text:14,lineHeight:16},description:{text:14,lineHeight:20},option:{text:14}}),w(y,T.Large,{height:48,text:18,label:{text:18,lineHeight:21},description:{text:18,lineHeight:24},option:{text:16}}),y),I=36,q=16,H={text:16,lineHeight:19},G={text:16,lineHeight:22},V={text:16},K=r.createContext({mode:z,size:T.Default,open:!1,disabled:!1});function R(){var e=N(["\n cursor: not-allowed;\n color: ",";\n "]);return R=function(){return e},e}function L(){var e=N(["\n cursor: pointer;\n color: ",";\n "]);return L=function(){return e},e}function B(){var e=N(["\n display: flex;\n "]);return B=function(){return e},e}function U(){var e=N(["\n display: flex;\n justify-content: space-between;\n width: 100%;\n "]);return U=function(){return e},e}function X(){var e=N(["\n color: ",";\n "]);return X=function(){return e},e}function _(){var e=N(["\n color: ",";\n "]);return _=function(){return e},e}function J(){var e=N(["\n color: ",";\n "]);return J=function(){return e},e}function W(){var e=N(["\n color: ",";\n "]);return W=function(){return e},e}function Y(){var e=N(["\n height: 100%;\n "]);return Y=function(){return e},e}function $(){var e=N(["\n font-weight: bold;\n "]);return $=function(){return e},e}function Q(){var e=N(["\n min-width: 16px;\n margin-right: 6px;\n"]);return Q=function(){return e},e}function Z(){var e=N(["\n display: flex;\n align-items: center;\n"]);return Z=function(){return e},e}function ee(){var e=N(["\n display: flex;\n width: 100%;\n padding: 10px 12px;\n outline: none;\n overflow-wrap: anywhere;\n transition: background-color 150ms ease-in-out;\n"]);return ee=function(){return e},e}var ne=a.css(ee()),te=a.css(Z()),re=a.css(Q());function oe(e){var n,t=e.children,o=e.className,i=e.glyph,u=e.selected,s=e.focused,c=e.disabled,d=e.onClick,f=e.onFocus,p=e.isDeselection,b=e.triggerScrollIntoView,g=e.hasGlyphs,y=r.useContext(K).mode,v=P[y].option,m=r.useRef(null),k=r.useCallback((function(){var e=m.current,n=e.offsetParent;n.scrollTop=e.offsetTop+(e.clientHeight-n.clientHeight)/2}),[m]),C=l.usePrevious(b),O=b&&!C;r.useEffect((function(){O&&k()}),[k,O]);var E=l.usePrevious(s),N=s&&!E;r.useEffect((function(){N&&m.current.focus()}),[N]);var S=h.default.createElement("span",{className:a.cx(te,w({},a.css($()),u&&!p))},t),D=h.default.createElement("span",{className:a.cx(re,a.css(Y()))}),M=D;i&&(i.type.isGlyph?M=h.default.cloneElement(i,{key:"glyph",className:a.cx(re,a.css(W(),v.icon.base),w({},a.css(J(),v.icon.disabled),c),i.props.className)}):console.error("`Option` instance did not render icon because it is not a known glyph element."));var F,j=u&&!p?h.default.createElement(x.default,{key:"checkmark",className:a.cx(re,a.css(_(),v.icon.selected),w({},a.css(X(),v.icon.disabled),c))}):D;return F=g?h.default.createElement("span",{className:a.css(U())},h.default.createElement("span",{className:a.css(B())},M,S),j):h.default.createElement(h.default.Fragment,null,j,S),h.default.createElement("li",{role:"option","aria-selected":u,tabIndex:-1,ref:m,className:a.cx(ne,a.css(L(),v.text.base),(n={},w(n,a.css("\n &:focus {\n background-color: ".concat(v.background.focused,";\n }\n\n &:hover {\n background-color: ").concat(v.background.hovered,";\n }\n ")),!c),w(n,a.css(R(),v.text.disabled),c),n),o),onClick:d,onFocus:f,onKeyDown:void 0},F)}function ae(e){throw Error("`Option` must be a child of a `Select` instance")}oe.displayName="Option",ae.displayName="Option";var le=v.default.oneOfType([v.default.string,v.default.number]);function ie(){var e=N(["\n color: ",";\n "]);return ie=function(){return e},e}function ue(){var e=N(["\n border-bottom: 1px solid ",";\n "]);return ue=function(){return e},e}function se(){var e=N(["\n cursor: default;\n width: 100%;\n padding: 0 12px 2px;\n outline: none;\n overflow-wrap: anywhere;\n font-size: 13px;\n line-height: 16px;\n font-weight: bold;\n"]);return se=function(){return e},e}function ce(){var e=N(["\n padding-top: 8px;\n"]);return ce=function(){return e},e}ae.propTypes={children:v.default.oneOfType([le,v.default.arrayOf(v.default.oneOfType([le,v.default.oneOf([!1,null,void 0,""])]))]).isRequired,className:v.default.string,glyph:v.default.element,value:v.default.string,disabled:v.default.bool};var de=a.css(ce()),fe=a.css(se()),pe=i.IdAllocator.create("select-option-group");function be(e){var n=e.className,t=e.label,o=e.children,l=r.useContext(K).mode,i=P[l].option,u=r.useMemo((function(){return pe.generate()}),[]);return h.default.createElement("div",{className:a.cx(de,a.css(ue(),i.group.border),n)},h.default.createElement("div",{id:u,className:a.cx(fe,a.css(ie(),i.group.label))},t),h.default.createElement("div",{role:"group","aria-labelledby":u},o))}function ge(e){throw Error("`OptionGroup` must be a child of a `Select` instance")}function ye(e){return null==e||!1===e||""===e}function he(e,n){h.default.Children.forEach(e,(function(e){i.isComponentType(e,"Option")?n(e):i.isComponentType(e,"OptionGroup")?he(e.props.children,(function(t){return n(t,e)})):d.isFragment(e)&&he(e.props.children,n)}))}function ve(e,n,t){return h.default.Children.map(e,(function(e){if(i.isComponentType(e,"Option"))return h.default.createElement(oe,n(e));if(i.isComponentType(e,"OptionGroup")){var r=e.props,o=r.children,a=E(r,["children"]);return h.default.createElement(be,O({className:void 0},a),ve(o,(function(t){return n(t,e)}),t))}return d.isFragment(e)?ve(e.props.children,n,t):(ye(e)||null==t||t(e),null)}))}function me(e){return null===e?"":void 0!==e.props.value?e.props.value:Array.isArray(e.props.children)?e.props.children.filter((function(e){return!ye(e)})).join(""):e.props.children.toString()}function xe(e,n){var t,r,o;return null!==(t=e.props.disabled)&&void 0!==t&&t||null!==(r=null==n||null===(o=n.props)||void 0===o?void 0:o.disabled)&&void 0!==r&&r}function ke(e,n,t){return me(e)===t&&!xe(e,n)}function Ce(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=n.initialValue,o=n.deps,a=void 0===o?[]:o,l=r.useRef(t);return r.useMemo((function(){return{get current(){return l.current},set current(n){l.current=n,e(n)}}}),[e,l].concat(D(a)))}function we(e,n){var t=r.useCallback((function(e,n){Array.isArray(e)?e.forEach(t):"function"==typeof e?e(n):e&&(e.current=n)}),[]);return Ce(r.useCallback((function(n){return t(e,n)}),[e,t]),{initialValue:n})}be.displayName="OptionGroup",ge.displayName="OptionGroup",ge.propTypes={children:v.default.oneOfType([v.default.element,v.default.arrayOf(v.default.oneOfType([v.default.oneOf([!1,null,void 0,""]),v.default.element]))]).isRequired,className:v.default.string,label:v.default.string.isRequired,disabled:v.default.bool};var Oe=function(e){var n=S(r.useState(e),2),t=n[0];return Ce(n[1],{initialValue:e,deps:[t]})};function Ee(){var e=N(["\n font-family: ",";\n font-size: ","px;\n max-height: ","px;\n background-color: ",";\n box-shadow: 0 3px 7px 0 ",";\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n }\n "]);return Ee=function(){return e},e}function Ne(){var e=N(["\n position: relative;\n text-align: left;\n width: 100%;\n border-radius: 3px;\n line-height: 16px;\n list-style: none;\n margin: 0;\n padding: 0;\n overflow: auto;\n"]);return Ne=function(){return e},e}var Se=a.css(Ne()),De=h.default.forwardRef((function(e,n){var t=e.children,o=e.id,c=e.referenceElement,d=e.onClose,f=e.onFocusPreviousOption,p=e.onFocusNextOption,b=e.onSelectFocusedOption,g=e.className,y=e.usePortal,v=e.labelId,x=r.useContext(K),k=x.mode,C=x.size,w=x.disabled,O=x.open,E=P[k],N=A[C],S=we(n,null),D=r.useCallback((function(e){if(!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case i.keyMap.Tab:case i.keyMap.Enter:b(e);break;case i.keyMap.Escape:d();break;case i.keyMap.ArrowUp:f();break;case i.keyMap.ArrowDown:p();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[d,p,f,b]),M=l.useViewportSize(),F=null===M||null===S.current?0:M.height-S.current.getBoundingClientRect().top-10,j=r.useCallback((function(e){S.current&&S.current.focus(),e.stopPropagation()}),[S]);return h.default.createElement(m.default,{active:O&&!w,spacing:4,align:s.Align.Bottom,justify:s.Justify.Middle,adjustOnMutation:!0,className:g,refEl:c,usePortal:y},h.default.createElement("ul",{"aria-labelledby":v,role:"listbox",ref:S,tabIndex:-1,onKeyDown:D,onClick:j,className:a.cx(Se,a.css(Ee(),u.fontFamilies.default,N.option.text,F,E.option.background.base,E.menu.shadow,u.breakpoints.Desktop,V.text)),id:o},t))}));function Me(){var e=N(["\n height: ","px;\n font-size: ","px;\n width: 100%;\n color: ",";\n border-color: ",";\n\n @media only screen and (max-width: ","px) {\n height: ","px;\n font-size: ","px;\n }\n "]);return Me=function(){return e},e}function Fe(){var e=N(["\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n"]);return Fe=function(){return e},e}function je(){var e=N(["\n margin-top: 2px;\n\n // reset default Button padding\n > span {\n padding: 0;\n }\n"]);return je=function(){return e},e}De.displayName="ListMenu";var ze=a.css(je()),Pe=a.css(Fe()),Te=h.default.forwardRef((function(e,n){var t=e.children,o=e.value,l=e.text,s=e.name,c=e.deselected,d=(e.readOnly,e.onDeselect),p=e.onFocusFirstOption,b=e.onFocusLastOption,g=e.onClose,y=e.onOpen,v=E(e,["children","value","text","name","deselected","readOnly","onDeselect","onFocusFirstOption","onFocusLastOption","onClose","onOpen"]),m=r.useContext(K),x=m.mode,w=m.open,N=m.size,S=m.disabled,D=we(n,null),M=P[x],F=A[N],z=r.useCallback((function(e){if(!S&&!(e.ctrlKey||e.shiftKey||e.altKey)){var n=!1;switch(e.keyCode){case i.keyMap.Tab:g(),n=!0;break;case i.keyMap.Escape:w?g():d(e);break;case i.keyMap.ArrowUp:y(),b();break;case i.keyMap.ArrowDown:y(),p();break;default:n=!0}n||(e.preventDefault(),e.stopPropagation())}}),[S,g,d,p,b,y,w]),T=r.useCallback((function(){w?g():y(),D.current.focus()}),[g,y,w,D]);return h.default.createElement(k.default,O({},v,{ref:D,name:s,value:o,disabled:S,onClick:T,onKeyDown:z,variant:f.Variant.Default,darkMode:x===j,rightGlyph:h.default.createElement(C.default,null),className:a.cx(ze,a.css(Me(),F.height,F.text,c?M.text.deselected:M.text.base,w&&!S?M.border.open:M.border.base,u.breakpoints.Desktop,I,q))}),h.default.createElement("span",{className:Pe},l),t)}));function Ae(){var e=N(["\n width: ","px;\n "]);return Ae=function(){return e},e}function Ie(){var e=N(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return Ie=function(){return e},e}function qe(){var e=N(["\n cursor: not-allowed;\n "]);return qe=function(){return e},e}function He(){var e=N(["\n color: ",";\n font-size: ","px;\n line-height: ","px;\n\n @media only screen and (max-width: ","px) {\n font-size: ","px;\n line-height: ","px;\n }\n "]);return He=function(){return e},e}function Ge(){var e=N(["\n cursor: not-allowed;\n "]);return Ge=function(){return e},e}function Ve(){var e=N(["\n margin-bottom: 2px;\n font-weight: bold;\n"]);return Ve=function(){return e},e}function Ke(){var e=N(["\n font-family: ",";\n display: block;\n"]);return Ke=function(){return e},e}Te.displayName="MenuButton";var Re=a.css(Ke(),u.fontFamilies.default),Le=a.css(Ve()),Be=i.IdAllocator.create("select");function Ue(e){var n,t=e.children,o=e.darkMode,i=void 0!==o&&o,s=e.size,c=void 0===s?T.Default:s,d=e.disabled,f=void 0!==d&&d,p=e.usePortal,b=void 0===p||p,g=e.placeholder,y=void 0===g?"Select":g,v=e.className,m=e.id,x=e.label,k=e.description,C=e.name,O=e.defaultValue,E=e.value,N=e.onChange,D=e.readOnly,M=e["aria-labelledby"];x||M||console.error("For screen-reader accessibility, label or aria-labelledby must be provided to Select.");var F=r.useMemo((function(){return null!=m?m:Be.generate()}),[m]),I=r.useMemo((function(){return null!=M?M:"".concat(F,"-label")}),[M,F]),q="".concat(F,"-description"),V="".concat(F,"-menu"),R=S(r.useState(!1),2),L=R[0],B=R[1],U=Oe(null),X=Oe(null),_=i?j:z,J=P[_],W=A[c],Y=r.useMemo((function(){return{mode:_,size:c,open:L,disabled:f}}),[_,c,L,f]);r.useEffect((function(){void 0!==E&&void 0===N&&!0!==D&&console.warn("You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.")}),[N,D,E]);var $=r.useCallback((function(){B(!0)}),[]),Q=r.useCallback((function(){B(!1),U.current.focus()}),[U]);r.useEffect((function(){if(L){var e=function(e){var n=U.current.contains(e.target)||X.current.contains(e.target);B(n)};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}}),[X,U,L]);var Z=r.useMemo((function(){var e=null;return void 0===E&&void 0!==O&&he(t,(function(n,t){ke(n,t,O)&&(e=n)})),e}),[t,O,E]),ee=S(r.useState(Z),2),ne=ee[0],te=ee[1];r.useEffect((function(){var e;null!==ne&&te(null!==(e=function(e,n){var t,r,o,a,l,i,u,s;return he(e,(function(e){if(e===n)l=n;else if(e.props.children===n.props.children&&e.props.value===n.props.value){var t;null!==(t=i)&&void 0!==t||(i=e)}else if(void 0!==e.props.value&&e.props.value===n.props.value){var r;null!==(r=u)&&void 0!==r||(u=e)}else if(me(e)===me(n)){var o;null!==(o=s)&&void 0!==o||(s=e)}})),null!==(t=null!==(r=null!==(o=null!==(a=l)&&void 0!==a?a:i)&&void 0!==o?o:u)&&void 0!==r?r:s)&&void 0!==t?t:null}(t,ne))&&void 0!==e?e:Z)}),[t,Z,ne]);var re=r.useMemo((function(){if(void 0!==E){var e=null;return he(t,(function(n,t){ke(n,t,E)&&(e=n)})),e}return ne}),[t,ne,E]),ae=r.useCallback((function(e,n){void 0===E&&te(e),null==N||N(me(e),n),ce(void 0),Q()}),[N,Q,E]),le=r.useCallback((function(e,n){return function(t){t.preventDefault(),t.stopPropagation(),f||n||(ae(e,t),Q())}}),[f,Q,ae]),ie=r.useCallback((function(e){ae(null,e)}),[ae]),ue=S(r.useState(),2),se=ue[0],ce=ue[1],de=r.useMemo((function(){var e=[null];return he(t,(function(n,t){xe(n,t)||e.push(n)})),e}),[t]),fe=r.useCallback((function(e){void 0!==se&&ae(se,e)}),[se,ae]),pe=r.useCallback((function(){ce(null)}),[]),be=r.useCallback((function(){ce(de[de.length-1])}),[de]),ge=r.useCallback((function(){if(void 0===se||0===de.indexOf(se))be();else{var e=de.indexOf(se)-1;ce(de[e])}}),[de,se,be]),ye=r.useCallback((function(){if(void 0===se||de.indexOf(se)===de.length-1)pe();else{var e=de.indexOf(se)+1;ce(de[e])}}),[de,se,pe]),Ce=r.useCallback((function(e,n){return function(t){t.preventDefault(),t.stopPropagation(),f||n||ce(e)}}),[f]),we=l.useViewportSize(),Ee=r.useMemo((function(){var e=!1;return he(t,(function(n){e||(e=void 0!==n.props.glyph)})),e}),[t]),Ne=r.useMemo((function(){return null!==we&&null!==X.current&&void 0===se&&L}),[se,X,L,we]),Se=r.useMemo((function(){var e=null===re;return h.default.createElement(oe,{className:void 0,glyph:void 0,selected:e,focused:null===se,disabled:!1,onClick:le(null,!1),onFocus:Ce(null,!1),isDeselection:!0,hasGlyphs:!0,triggerScrollIntoView:e&&Ne},y)}),[Ne,se,le,Ce,y,re]),Me=r.useMemo((function(){return ve(t,(function(e,n){var t=e===re,r=xe(e,n);return{className:e.props.className,glyph:e.props.glyph,selected:t,focused:e===se,disabled:r,children:e.props.children,isDeselection:!1,hasGlyphs:Ee,onClick:le(e,r),onFocus:Ce(e,r),triggerScrollIntoView:t&&Ne}}),(function(){console.error("`Select` instance received child that is not `Option` or `OptionGroup`.")}))}),[Ne,t,se,le,Ce,Ee,re]);return h.default.createElement("div",{className:a.cx(w({},a.css(Ge()),f),v)},x&&h.default.createElement("label",{id:I,className:a.cx(Re,Le,a.css(He(),f?J.label.disabled:J.label.base,W.label.text,W.label.lineHeight,u.breakpoints.Desktop,H.text,H.lineHeight),w({},a.css(qe()),f))},x),k&&h.default.createElement("div",{id:q,className:a.cx(Re,a.css(Ie(),J.description,W.description.text,W.description.lineHeight,u.breakpoints.Desktop,G.text,G.lineHeight))},k),h.default.createElement(K.Provider,{value:Y},h.default.createElement(Te,{ref:U,name:C,readOnly:D,value:me(re),text:null!==re?re.props.children:y,deselected:null===re,onDeselect:ie,onOpen:$,onClose:Q,onFocusFirstOption:pe,onFocusLastOption:be,"aria-labelledby":I,"aria-controls":V,"aria-expanded":L,"aria-describedby":q},h.default.createElement(De,{labelId:I,id:V,referenceElement:U,ref:X,onClose:Q,onSelectFocusedOption:fe,onFocusPreviousOption:ge,onFocusNextOption:ye,usePortal:b,className:a.css(Ae(),null===(n=U.current)||void 0===n?void 0:n.clientWidth)},Se,Me))))}Ue.displayName="Select",Ue.propTypes={label:v.default.string,"aria-labelledby":v.default.string,description:v.default.string,placeholder:v.default.string,className:v.default.string,darkMode:v.default.bool,size:v.default.oneOf(Object.values(T)),disabled:v.default.bool,id:v.default.string,value:v.default.string,defaultValue:v.default.string,onChange:v.default.func,readOnly:v.default.bool},e.Option=ae,e.OptionGroup=ge,e.Select=Ue,e.Size=T,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@leafygreen-ui/select", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "leafyGreen UI Kit Select", | ||
@@ -23,10 +23,10 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@leafygreen-ui/button": "^11.0.0", | ||
"@leafygreen-ui/button": "^11.0.2", | ||
"@leafygreen-ui/emotion": "^3.0.1", | ||
"@leafygreen-ui/hooks": "^6.0.0", | ||
"@leafygreen-ui/icon": "^10.0.0", | ||
"@leafygreen-ui/lib": "^6.1.2", | ||
"@leafygreen-ui/palette": "^3.2.0", | ||
"@leafygreen-ui/popover": "^7.1.2", | ||
"@leafygreen-ui/tokens": "0.5.0", | ||
"@leafygreen-ui/icon": "^10.2.1", | ||
"@leafygreen-ui/lib": "^7.0.0", | ||
"@leafygreen-ui/palette": "^3.2.1", | ||
"@leafygreen-ui/popover": "^7.1.4", | ||
"@leafygreen-ui/tokens": "0.5.1", | ||
"@types/react-is": "^17.0.0", | ||
@@ -37,4 +37,4 @@ "polished": "^4.0.3", | ||
"peerDependencies": { | ||
"@leafygreen-ui/leafygreen-provider": "^2.0.1" | ||
"@leafygreen-ui/leafygreen-provider": "^2.0.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
508995
38
2847
+ Added@leafygreen-ui/lib@13.7.0(transitive)
+ Added@leafygreen-ui/tokens@0.5.1(transitive)
- Removed@leafygreen-ui/lib@13.8.06.3.0(transitive)
- Removed@leafygreen-ui/tokens@0.5.00.5.3(transitive)
- Removedreact@18.3.1(transitive)
Updated@leafygreen-ui/icon@^10.2.1
Updated@leafygreen-ui/lib@^7.0.0
Updated@leafygreen-ui/tokens@0.5.1