@blueprintjs/select
Advanced tools
Comparing version 2.0.0-rc.3 to 2.0.0-rc.4
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("React"),require("classNames")):"function"==typeof define&&define.amd?define(["React","classNames"],t):"object"==typeof exports?exports.Select=t(require("React"),require("classNames")):(e.Blueprint=e.Blueprint||{},e.Blueprint.Select=t(e.React,e.classNames))}("undefined"!=typeof self?self:this,function(e,t){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(t,n){t.exports=e},function(e,t){e.exports=Blueprint.Core},function(e,n){e.exports=t},function(e,t,n){e.exports=n(4)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="pt-multi-select",o=r+"-popover",i="pt-omnibar",s=i+"-overlay",p="pt-select",a=p+"-popover",u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};function l(e,t){function n(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e};function v(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&(n[r[o]]=e[r[o]])}return n}var d=n(2),f=n.n(d),m=n(0),y=n(1),h=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.refHandlers={itemsParent:function(e){return t.itemsParentRef=e}},t.shouldCheckActiveItemInViewport=!1,t.handleItemSelect=function(e,n){y.Utils.safeInvoke(t.props.onActiveItemChange,e),y.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handleKeyDown=function(e){switch(e.keyCode){case y.Keys.ARROW_UP:e.preventDefault(),t.moveActiveIndex(-1);break;case y.Keys.ARROW_DOWN:e.preventDefault(),t.moveActiveIndex(1)}y.Utils.safeInvoke(t.props.onKeyDown,e)},t.handleKeyUp=function(e){var n=t.props,r=n.activeItem,o=n.onItemSelect,i=n.onKeyUp;e.keyCode===y.Keys.ENTER&&null!=r&&(e.preventDefault(),y.Utils.safeInvoke(o,r,e)),y.Utils.safeInvoke(i,e)},t.renderItem=function(e,n){var r=t.props,o=r.activeItem,i=r.itemListPredicate,s=r.itemPredicate,p=void 0===s?function(){return!0}:s,a=r.query,u=y.Utils.isFunction(i)?t.state.filteredItems.indexOf(e)>=0:p(a,e,n),l={active:o===e,disabled:!1,matchesPredicate:u};return t.props.itemRenderer(e,{handleClick:function(n){return t.handleItemSelect(e,n)},index:n,modifiers:l})},t}return l(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=e.className,n=e.items,r=e.renderer,o=e.query;return r({className:t,handleItemSelect:this.handleItemSelect,handleKeyDown:this.handleKeyDown,handleKeyUp:this.handleKeyUp,items:n,itemsParentRef:this.refHandlers.itemsParent,query:o,renderItem:this.renderItem})},t.prototype.componentWillMount=function(){this.setState({filteredItems:P(this.props)})},t.prototype.componentWillReceiveProps=function(e){e.items===this.props.items&&e.itemListPredicate===this.props.itemListPredicate&&e.itemPredicate===this.props.itemPredicate&&e.query===this.props.query||(this.shouldCheckActiveItemInViewport=!0,this.setState({filteredItems:P(e)}))},t.prototype.componentDidUpdate=function(){var e=this;this.shouldCheckActiveItemInViewport&&(requestAnimationFrame(function(){return e.scrollActiveItemIntoView()}),this.shouldCheckActiveItemInViewport=!1),this.getActiveIndex()<0&&(0!==this.state.filteredItems.length||void 0!==this.props.activeItem)&&y.Utils.safeInvoke(this.props.onActiveItemChange,this.state.filteredItems[0])},t.prototype.scrollActiveItemIntoView=function(){var e=this.getActiveElement();if(null!=this.itemsParentRef&&null!=e){var t=e.offsetTop,n=e.offsetHeight,r=this.itemsParentRef,o=r.offsetTop,i=r.scrollTop,s=r.clientHeight,p=this.getItemsParentPadding(),a=p.paddingTop,u=t+n+p.paddingBottom-o,l=t-a-o;u>=i+s?this.itemsParentRef.scrollTop=u+n-s:l<=i&&(this.itemsParentRef.scrollTop=l-n)}},t.prototype.getActiveElement=function(){if(null!=this.itemsParentRef)return this.itemsParentRef.children.item(this.getActiveIndex())},t.prototype.getActiveIndex=function(){var e=this.props.activeItem;return null==e?-1:this.state.filteredItems.indexOf(e)},t.prototype.getItemsParentPadding=function(){var e=getComputedStyle(this.itemsParentRef),t=e.paddingTop;return{paddingBottom:I(e.paddingBottom),paddingTop:I(t)}},t.prototype.moveActiveIndex=function(e){this.shouldCheckActiveItemInViewport=!0;var t=this.state.filteredItems,n=Math.max(t.length-1,0),r=y.Utils.clamp(this.getActiveIndex()+e,0,n);y.Utils.safeInvoke(this.props.onActiveItemChange,t[r])},t.displayName="Blueprint2.QueryList",t}(m.Component);function I(e){return null==e?0:parseInt(e.slice(0,-2),10)}function P(e){var t=e.items,n=e.itemPredicate,r=e.itemListPredicate,o=e.query;return y.Utils.isFunction(r)?r(o,t):y.Utils.isFunction(n)?t.filter(function(e,t){return n(o,e,t)}):t}var O=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={query:""},t.TypedQueryList=h.ofType(),t.refHandlers={queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,r=n.inputProps,o=void 0===r?{}:r,p=n.isOpen,a=n.overlayProps,u=void 0===a?{}:a,l=e.handleKeyDown,v=e.handleKeyUp,d=p&&!t.isQueryEmpty()?{onKeyDown:l,onKeyUp:v}:{};return m.createElement(y.Overlay,c({hasBackdrop:!0},u,{isOpen:p,className:f()(u.className,s),onClose:t.handleOverlayClose}),m.createElement("div",c({className:f()(e.className,i)},d),m.createElement(y.InputGroup,c({autoFocus:!0,className:y.Classes.LARGE,leftIcon:"search",placeholder:"Search...",value:e.query},o,{onChange:t.handleQueryChange})),t.maybeRenderMenu(e)))},t.isQueryEmpty=function(){return 0===t.state.query.length},t.handleActiveItemChange=function(e){return t.setState({activeItem:e})},t.handleItemSelect=function(e,n){t.isQueryEmpty()||y.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handleQueryChange=function(e){var n=t.props.inputProps,r=void 0===n?{}:n;t.setState({query:e.currentTarget.value}),y.Utils.safeInvoke(r.onChange,e)},t.handleOverlayClose=function(e){y.Utils.safeInvoke(t.props.onClose,e)},t}return l(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.initialContent,e.isOpen,e.inputProps,e.noResults,e.overlayProps,v(e,["initialContent","isOpen","inputProps","noResults","overlayProps"]));return m.createElement(this.TypedQueryList,c({},t,{activeItem:this.state.activeItem,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentWillReceiveProps=function(e){var t=e.isOpen,n=!this.props.isOpen&&t&&this.props.resetOnSelect;this.setState({activeItem:n?this.props.items[0]:this.state.activeItem,query:n?"":this.state.query})},t.prototype.renderItems=function(e){var t=e.items,n=e.renderItem,r=t.map(n).filter(function(e){return null!=e});return r.length>0?r:this.props.noResults},t.prototype.maybeRenderMenu=function(e){var t,n=this.props.initialContent;if(this.isQueryEmpty()?null!=n&&(t=n):t=this.renderItems(e),null!=t)return m.createElement(y.Menu,{ulRef:e.itemsParentRef},t)},t.displayName="Blueprint2.Omnibar",t}(m.PureComponent),g=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={isOpen:!1,query:""},t.TypedQueryList=h.ofType(),t.refHandlers={input:function(e){t.input=e;var n=t.props.tagInputProps,r=void 0===n?{}:n;y.Utils.safeInvoke(r.inputRef,e)},queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,i=n.tagInputProps,s=void 0===i?{}:i,p=n.popoverProps,a=void 0===p?{}:p,u=n.selectedItems,l=void 0===u?[]:u,v=e.handleKeyDown,d=e.handleKeyUp,h=e.query,I=c({placeholder:"Search..."},s.inputProps,{onChange:t.handleQueryChange,value:h});return m.createElement(y.Popover,c({autoFocus:!1,canEscapeKeyClose:!0,enforceFocus:!1,isOpen:t.state.isOpen,position:y.Position.BOTTOM_LEFT},a,{className:f()(e.className,a.className),onInteraction:t.handlePopoverInteraction,popoverClassName:f()(o,a.popoverClassName),popoverDidOpen:t.handlePopoverDidOpen,popoverWillOpen:t.handlePopoverWillOpen}),m.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(v),onKeyUp:t.state.isOpen?d:void 0},m.createElement(y.TagInput,c({},s,{inputProps:I,inputRef:t.refHandlers.input,className:f()(r,s.className),values:l.map(t.props.tagRenderer)}))),m.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(v),onKeyUp:d},m.createElement(y.Menu,{ulRef:e.itemsParentRef},t.renderItems(e))))},t.isQueryEmpty=function(){return 0===t.state.query.length},t.handleQueryChange=function(e){var n=t.props,r=n.tagInputProps,o=void 0===r?{}:r,i=n.openOnKeyDown,s=e.currentTarget.value;t.setState({query:s,isOpen:!t.isQueryEmpty()||!i}),null!=o.inputProps&&y.Utils.safeInvoke(o.inputProps.onChange,e)},t.handleItemSelect=function(e,n){null!=t.input&&t.input.focus(),null!=t.state.activeItem&&(t.props.resetOnSelect&&!t.isQueryEmpty()&&t.setState({activeItem:t.props.items[0],query:""}),y.Utils.safeInvoke(t.props.onItemSelect,e,n))},t.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var n=t.props,r=n.popoverProps,o=void 0===r?{}:r,i=n.resetOnSelect;null!=t.input&&t.input!==document.activeElement?t.setState({activeItem:i?t.props.items[0]:t.state.activeItem,isOpen:!1,query:i?"":t.state.query}):t.props.openOnKeyDown||t.setState({isOpen:!0}),y.Utils.safeInvoke(o.onInteraction,e)})},t.handlePopoverWillOpen=function(){var e=t.props,n=e.popoverProps,r=void 0===n?{}:n;e.resetOnSelect&&t.setState({activeItem:t.props.items[0]}),y.Utils.safeInvoke(r.popoverWillOpen)},t.handlePopoverDidOpen=function(){var e=t.props.popoverProps,n=void 0===e?{}:e;null!=t.queryList&&t.queryList.scrollActiveItemIntoView(),y.Utils.safeInvoke(n.popoverDidOpen)},t.handleActiveItemChange=function(e){return t.setState({activeItem:e})},t.getTargetKeyDownHandler=function(e){return function(n){var r=n.which,o=t.props.resetOnSelect;r===y.Keys.ESCAPE||r===y.Keys.TAB?(null!=t.input&&t.input.blur(),t.setState({activeItem:o?t.props.items[0]:t.state.activeItem,isOpen:!1,query:o?"":t.state.query})):r!==y.Keys.BACKSPACE&&r!==y.Keys.ARROW_LEFT&&r!==y.Keys.ARROW_RIGHT&&t.setState({isOpen:!0}),t.state.isOpen&&y.Utils.safeInvoke(e,n)}},t}return l(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.initialContent,e.noResults,e.openOnKeyDown,e.popoverProps,e.resetOnSelect,e.tagInputProps,v(e,["initialContent","noResults","openOnKeyDown","popoverProps","resetOnSelect","tagInputProps"]));return m.createElement(this.TypedQueryList,c({},t,{activeItem:this.state.activeItem,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.renderItems=function(e){var t=e.items,n=e.renderItem,r=this.props,o=r.initialContent,i=r.noResults;if(null!=o&&this.isQueryEmpty())return o;var s=t.map(n).filter(function(e){return null!=e});return s.length>0?s:i},t.displayName="Blueprint2.MultiSelect",t}(m.PureComponent),C=function(e){function t(t,n){var r=e.call(this,t,n)||this;r.TypedQueryList=h.ofType(),r.refHandlers={input:function(e){r.input=e;var t=r.props.inputProps,n=void 0===t?{}:t;y.Utils.safeInvoke(n.inputRef,e)},queryList:function(e){return r.list=e}},r.renderQueryList=function(e){var t=r.props,n=t.filterable,o=void 0===n||n,i=t.disabled,s=void 0!==i&&i,p=t.inputProps,u=void 0===p?{}:p,l=t.popoverProps,v=void 0===l?{}:l,d=m.createElement(y.InputGroup,c({autoFocus:!0,leftIcon:"search",placeholder:"Filter...",rightElement:r.maybeRenderInputClearButton(),value:e.query},u,{inputRef:r.refHandlers.input,onChange:r.handleQueryChange})),h=e.handleKeyDown,I=e.handleKeyUp;return m.createElement(y.Popover,c({autoFocus:!1,enforceFocus:!1,isOpen:r.state.isOpen,disabled:s,position:y.Position.BOTTOM_LEFT},v,{className:f()(e.className,v.className),onInteraction:r.handlePopoverInteraction,popoverClassName:f()(a,v.popoverClassName),popoverWillOpen:r.handlePopoverWillOpen,popoverDidOpen:r.handlePopoverDidOpen,popoverWillClose:r.handlePopoverWillClose}),m.createElement("div",{onKeyDown:r.state.isOpen?h:r.handleTargetKeyDown,onKeyUp:r.state.isOpen?I:void 0},r.props.children),m.createElement("div",{onKeyDown:h,onKeyUp:I},o?d:void 0,m.createElement(y.Menu,{ulRef:e.itemsParentRef},r.renderItems(e))))},r.isQueryEmpty=function(){return 0===r.state.query.length},r.handleActiveItemChange=function(e){return r.setState({activeItem:e})},r.handleTargetKeyDown=function(e){e.which!==y.Keys.ARROW_UP&&e.which!==y.Keys.ARROW_DOWN||r.setState({isOpen:!0})},r.handleItemSelect=function(e,t){r.setState({isOpen:!1}),r.props.resetOnSelect&&r.resetQuery(),y.Utils.safeInvoke(r.props.onItemSelect,e,t)},r.handlePopoverInteraction=function(e){r.setState({isOpen:e});var t=r.props.popoverProps,n=void 0===t?{}:t;y.Utils.safeInvoke(n.onInteraction,e)},r.handlePopoverWillOpen=function(){var e=r.props,t=e.popoverProps,n=void 0===t?{}:t,o=e.resetOnClose;r.previousFocusedElement=document.activeElement,o&&r.resetQuery(),y.Utils.safeInvoke(n.popoverWillOpen)},r.handlePopoverDidOpen=function(){null!=r.list&&r.list.scrollActiveItemIntoView(),requestAnimationFrame(function(){var e=r.props.inputProps;!1!==(void 0===e?{}:e).autoFocus&&null!=r.input&&r.input.focus()});var e=r.props.popoverProps,t=void 0===e?{}:e;y.Utils.safeInvoke(t.popoverDidOpen)},r.handlePopoverWillClose=function(){requestAnimationFrame(function(){void 0!==r.previousFocusedElement&&(r.previousFocusedElement.focus(),r.previousFocusedElement=void 0)});var e=r.props.popoverProps,t=void 0===e?{}:e;y.Utils.safeInvoke(t.popoverWillClose)},r.handleQueryChange=function(e){var t=r.props,n=t.inputProps,o=void 0===n?{}:n,i=t.onQueryChange,s=e.currentTarget.value;r.setState({query:s}),y.Utils.safeInvoke(o.onChange,e),y.Utils.safeInvoke(i,s)},r.resetQuery=function(){var e=r.props,t=e.items,n=e.onQueryChange;r.setState({activeItem:t[0],query:""}),y.Utils.safeInvoke(n,"")};var o=t.inputProps,i=void 0===o?{}:o,s=null==i.value?"":i.value.toString();return r.state={isOpen:!1,query:s},r}return l(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.filterable,e.initialContent,e.inputProps,e.noResults,e.popoverProps,v(e,["filterable","initialContent","inputProps","noResults","popoverProps"]));return m.createElement(this.TypedQueryList,c({},t,{activeItem:this.state.activeItem,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentWillReceiveProps=function(e){var t=e.inputProps,n=void 0===t?{}:t;void 0!==n.value&&this.state.query!==n.value&&this.setState({query:n.value.toString()})},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.list&&this.list.scrollActiveItemIntoView()},t.prototype.renderItems=function(e){var t=e.items,n=e.renderItem,r=this.props,o=r.initialContent,i=r.noResults;if(null!=o&&this.isQueryEmpty())return o;var s=t.map(n).filter(function(e){return null!=e});return s.length>0?s:i},t.prototype.maybeRenderInputClearButton=function(){return this.isQueryEmpty()?void 0:m.createElement(y.Button,{className:y.Classes.MINIMAL,icon:"cross",onClick:this.resetQuery})},t.displayName="Blueprint2.Select",t}(m.PureComponent),S=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={isOpen:!1,isTyping:!1,query:""},t.TypedQueryList=h.ofType(),t.refHandlers={input:function(e){t.input=e;var n=t.props.inputProps,r=void 0===n?{}:n;y.Utils.safeInvoke(r.inputRef,e)},queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,r=n.inputValueRenderer,o=n.inputProps,i=void 0===o?{}:o,s=n.popoverProps,p=void 0===s?{}:s,u=t.state,l=u.isTyping,v=u.selectedItem,d=u.query,h=e.handleKeyDown,I=e.handleKeyUp,P=l?d:v?r(v):"";return m.createElement(y.Popover,c({autoFocus:!1,enforceFocus:!1,isOpen:t.state.isOpen,position:y.Position.BOTTOM_LEFT},p,{className:f()(e.className,p.className),onInteraction:t.handlePopoverInteraction,popoverClassName:f()(a,p.popoverClassName),popoverDidOpen:t.handlePopoverDidOpen,popoverWillClose:t.handlePopoverWillClose}),m.createElement(y.InputGroup,c({placeholder:"Search...",value:P},i,{inputRef:t.refHandlers.input,onChange:t.handleQueryChange,onFocus:t.handleInputFocus,onKeyDown:t.getTargetKeyDownHandler(h),onKeyUp:t.getTargetKeyUpHandler(I)})),m.createElement("div",{onKeyDown:h,onKeyUp:I},m.createElement(y.Menu,{ulRef:e.itemsParentRef},t.renderItems(e))))},t.selectText=function(){requestAnimationFrame(function(){null!=t.input&&t.input.setSelectionRange(0,t.input.value.length)})},t.handleInputFocus=function(e){var n=t.props,r=n.openOnKeyDown,o=n.inputProps,i=void 0===o?{}:o;t.selectText(),r||t.setState({isOpen:!0}),y.Utils.safeInvoke(i.onFocus,e)},t.handleActiveItemChange=function(e){return t.setState({activeItem:e})},t.handleItemSelect=function(e,n){var r;t.props.closeOnSelect?(null!=t.input&&t.input.blur(),r=!1):(null!=t.input&&t.input.focus(),t.selectText(),r=!0),t.setState({isOpen:r,isTyping:!1,query:"",selectedItem:e}),y.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var n=t.props.popoverProps,r=void 0===n?{}:n;null!=t.input&&t.input!==document.activeElement&&t.setState({isOpen:!1}),y.Utils.safeInvoke(r.onInteraction,e)})},t.handlePopoverDidOpen=function(){var e=t.props.popoverProps,n=void 0===e?{}:e;null!=t.queryList&&t.queryList.scrollActiveItemIntoView(),y.Utils.safeInvoke(n.popoverDidOpen)},t.handlePopoverWillClose=function(){var e=t.props.popoverProps,n=void 0===e?{}:e,r=t.state.selectedItem;t.setState({activeItem:r||t.props.items[0],query:""}),y.Utils.safeInvoke(n.popoverDidOpen)},t.handleQueryChange=function(e){var n=t.props.inputProps,r=void 0===n?{}:n;t.setState({isTyping:!0,query:e.currentTarget.value}),y.Utils.safeInvoke(r.onChange,e)},t.getTargetKeyDownHandler=function(e){return function(n){var r=n.which,o=t.state,i=o.isTyping,s=o.selectedItem,p=t.props,a=p.inputProps,u=void 0===a?{}:a,l=p.openOnKeyDown;r===y.Keys.ESCAPE||r===y.Keys.TAB?(null!=t.input&&t.input.blur(),t.setState({isOpen:!1,selectedItem:i?void 0:s})):l&&r!==y.Keys.BACKSPACE&&r!==y.Keys.ARROW_LEFT&&r!==y.Keys.ARROW_RIGHT&&t.setState({isOpen:!0}),t.state.isOpen&&y.Utils.safeInvoke(e,n),y.Utils.safeInvoke(u.onKeyDown,n)}},t.getTargetKeyUpHandler=function(e){return function(n){var r=t.props.inputProps,o=void 0===r?{}:r;t.state.isOpen&&y.Utils.safeInvoke(e,n),y.Utils.safeInvoke(o.onKeyUp,n)}},t}return l(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.inputProps,e.noResults,e.popoverProps,v(e,["inputProps","noResults","popoverProps"]));return m.createElement(this.TypedQueryList,c({},t,{activeItem:this.state.activeItem,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.queryList&&this.queryList.scrollActiveItemIntoView()},t.prototype.renderItems=function(e){var t=e.items,n=e.renderItem,r=t.map(n).filter(function(e){return null!=e});return r.length>0?r:this.props.noResults},t.displayName="Blueprint2.Suggest",t.defaultProps={closeOnSelect:!0,openOnKeyDown:!1},t}(m.PureComponent);n.d(t,"MULTISELECT",function(){return r}),n.d(t,"MULTISELECT_POPOVER",function(){return o}),n.d(t,"OMNIBAR",function(){return i}),n.d(t,"OMNIBAR_OVERLAY",function(){return s}),n.d(t,"SELECT",function(){return p}),n.d(t,"SELECT_POPOVER",function(){return a}),n.d(t,"Omnibar",function(){return O}),n.d(t,"QueryList",function(){return h}),n.d(t,"MultiSelect",function(){return g}),n.d(t,"Select",function(){return C}),n.d(t,"Suggest",function(){return S})}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("React"),require("classNames")):"function"==typeof define&&define.amd?define(["React","classNames"],t):"object"==typeof exports?exports.Select=t(require("React"),require("classNames")):(e.Blueprint=e.Blueprint||{},e.Blueprint.Select=t(e.React,e.classNames))}("undefined"!=typeof self?self:this,function(e,t){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(t,n){t.exports=e},function(e,t){e.exports=Blueprint.Core},function(e,n){e.exports=t},function(e,t,n){e.exports=n(4)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};n.d(r,"MULTISELECT",function(){return o}),n.d(r,"MULTISELECT_POPOVER",function(){return i}),n.d(r,"OMNIBAR",function(){return s}),n.d(r,"OMNIBAR_OVERLAY",function(){return p}),n.d(r,"SELECT",function(){return a}),n.d(r,"SELECT_POPOVER",function(){return u});var o="pt-multi-select",i=o+"-popover",s="pt-omnibar",p=s+"-overlay",a="pt-select",u=a+"-popover";function l(e,t,n){if(0===e.query.length&&void 0!==n)return n;var r=e.filteredItems.map(e.renderItem).filter(function(e){return null!=e});return r.length>0?r:t}var c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};function v(e,t){function n(){this.constructor=e}c(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var d=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e};function f(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&(n[r[o]]=e[r[o]])}return n}var m=n(2),y=n.n(m),h=n(0),I=n(1),O=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.refHandlers={itemsParent:function(e){return t.itemsParentRef=e}},t.shouldCheckActiveItemInViewport=!1,t.renderItemList=function(e){var n=t.props,r=n.initialContent,o=l(e,n.noResults,r);return h.createElement(I.Menu,{ulRef:e.itemsParentRef},o)},t.renderItem=function(e,n){var r=t.props,o=r.activeItem,i=r.query,s=t.state.filteredItems.indexOf(e)>=0,p={active:o===e,disabled:!1,matchesPredicate:s};return t.props.itemRenderer(e,{handleClick:function(n){return t.handleItemSelect(e,n)},index:n,modifiers:p,query:i})},t.handleItemSelect=function(e,n){I.Utils.safeInvoke(t.props.onActiveItemChange,e),I.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handleKeyDown=function(e){switch(e.keyCode){case I.Keys.ARROW_UP:e.preventDefault(),t.moveActiveIndex(-1);break;case I.Keys.ARROW_DOWN:e.preventDefault(),t.moveActiveIndex(1)}I.Utils.safeInvoke(t.props.onKeyDown,e)},t.handleKeyUp=function(e){var n=t.props,r=n.activeItem,o=n.onItemSelect,i=n.onKeyUp;e.keyCode===I.Keys.ENTER&&null!=r&&(e.preventDefault(),I.Utils.safeInvoke(o,r,e)),I.Utils.safeInvoke(i,e)},t}return v(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=e.className,n=e.items,r=e.renderer,o=e.query,i=e.itemListRenderer,s=void 0===i?this.renderItemList:i,p=this.state.filteredItems;return r({className:t,filteredItems:p,handleItemSelect:this.handleItemSelect,handleKeyDown:this.handleKeyDown,handleKeyUp:this.handleKeyUp,itemList:s({filteredItems:p,items:n,itemsParentRef:this.refHandlers.itemsParent,query:o,renderItem:this.renderItem}),query:o})},t.prototype.componentWillMount=function(){this.setState({filteredItems:g(this.props)})},t.prototype.componentWillReceiveProps=function(e){e.items===this.props.items&&e.itemListPredicate===this.props.itemListPredicate&&e.itemPredicate===this.props.itemPredicate&&e.query===this.props.query||(this.shouldCheckActiveItemInViewport=!0,this.setState({filteredItems:g(e)}))},t.prototype.componentDidUpdate=function(){var e=this;this.shouldCheckActiveItemInViewport&&(requestAnimationFrame(function(){return e.scrollActiveItemIntoView()}),this.shouldCheckActiveItemInViewport=!1),this.getActiveIndex()<0&&(0!==this.state.filteredItems.length||void 0!==this.props.activeItem)&&I.Utils.safeInvoke(this.props.onActiveItemChange,this.state.filteredItems[0])},t.prototype.scrollActiveItemIntoView=function(){var e=this.getActiveElement();if(null!=this.itemsParentRef&&null!=e){var t=e.offsetTop,n=e.offsetHeight,r=this.itemsParentRef,o=r.offsetTop,i=r.scrollTop,s=r.clientHeight,p=this.getItemsParentPadding(),a=p.paddingTop,u=t+n+p.paddingBottom-o,l=t-a-o;u>=i+s?this.itemsParentRef.scrollTop=u+n-s:l<=i&&(this.itemsParentRef.scrollTop=l-n)}},t.prototype.getActiveElement=function(){if(null!=this.itemsParentRef)return this.itemsParentRef.children.item(this.getActiveIndex())},t.prototype.getActiveIndex=function(){var e=this.props.activeItem;return null==e?-1:this.state.filteredItems.indexOf(e)},t.prototype.getItemsParentPadding=function(){var e=getComputedStyle(this.itemsParentRef),t=e.paddingTop;return{paddingBottom:P(e.paddingBottom),paddingTop:P(t)}},t.prototype.moveActiveIndex=function(e){this.shouldCheckActiveItemInViewport=!0;var t=this.state.filteredItems,n=Math.max(t.length-1,0),r=I.Utils.clamp(this.getActiveIndex()+e,0,n);I.Utils.safeInvoke(this.props.onActiveItemChange,t[r])},t.displayName="Blueprint2.QueryList",t}(h.Component);function P(e){return null==e?0:parseInt(e.slice(0,-2),10)}function g(e){var t=e.items,n=e.itemPredicate,r=e.itemListPredicate,o=e.query;return I.Utils.isFunction(r)?r(o,t):I.Utils.isFunction(n)?t.filter(function(e,t){return n(o,e,t)}):t}var C=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={query:""},t.TypedQueryList=O.ofType(),t.refHandlers={queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,o=n.inputProps,i=void 0===o?{}:o,s=n.isOpen,p=n.overlayProps,a=void 0===p?{}:p,u=e.handleKeyDown,l=e.handleKeyUp,c=s&&!t.isQueryEmpty()?{onKeyDown:u,onKeyUp:l}:{};return h.createElement(I.Overlay,d({hasBackdrop:!0},a,{isOpen:s,className:y()(a.className,r.OMNIBAR_OVERLAY),onClose:t.handleOverlayClose}),h.createElement("div",d({className:y()(e.className,r.OMNIBAR)},c),h.createElement(I.InputGroup,d({autoFocus:!0,className:I.Classes.LARGE,leftIcon:"search",placeholder:"Search...",value:e.query},i,{onChange:t.handleQueryChange})),e.itemList))},t.isQueryEmpty=function(){return 0===t.state.query.length},t.handleActiveItemChange=function(e){return t.setState({activeItem:e})},t.handleItemSelect=function(e,n){t.isQueryEmpty()||I.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handleQueryChange=function(e){var n=t.props.inputProps,r=void 0===n?{}:n;t.setState({query:e.currentTarget.value}),I.Utils.safeInvoke(r.onChange,e)},t.handleOverlayClose=function(e){I.Utils.safeInvoke(t.props.onClose,e)},t}return v(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=e.initialContent,n=void 0===t?null:t,r=(e.isOpen,e.inputProps,e.overlayProps,f(e,["initialContent","isOpen","inputProps","overlayProps"]));return h.createElement(this.TypedQueryList,d({},r,{activeItem:this.state.activeItem,initialContent:n,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentWillReceiveProps=function(e){var t=e.isOpen,n=!this.props.isOpen&&t&&this.props.resetOnSelect;this.setState({activeItem:n?this.props.items[0]:this.state.activeItem,query:n?"":this.state.query})},t.displayName="Blueprint2.Omnibar",t}(h.PureComponent),S=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={isOpen:!1,query:""},t.TypedQueryList=O.ofType(),t.refHandlers={input:function(e){t.input=e;var n=t.props.tagInputProps,r=void 0===n?{}:n;I.Utils.safeInvoke(r.inputRef,e)},queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,o=n.tagInputProps,i=void 0===o?{}:o,s=n.popoverProps,p=void 0===s?{}:s,a=n.selectedItems,u=void 0===a?[]:a,l=e.handleKeyDown,c=e.handleKeyUp,v=e.query,f=d({placeholder:"Search..."},i.inputProps,{onChange:t.handleQueryChange,value:v});return h.createElement(I.Popover,d({autoFocus:!1,canEscapeKeyClose:!0,enforceFocus:!1,isOpen:t.state.isOpen,position:I.Position.BOTTOM_LEFT},p,{className:y()(e.className,p.className),onInteraction:t.handlePopoverInteraction,popoverClassName:y()(r.MULTISELECT_POPOVER,p.popoverClassName),popoverDidOpen:t.handlePopoverDidOpen,popoverWillOpen:t.handlePopoverWillOpen}),h.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(l),onKeyUp:t.state.isOpen?c:void 0},h.createElement(I.TagInput,d({},i,{inputProps:f,inputRef:t.refHandlers.input,className:y()(r.MULTISELECT,i.className),values:u.map(t.props.tagRenderer)}))),h.createElement("div",{onKeyDown:t.getTargetKeyDownHandler(l),onKeyUp:c},e.itemList))},t.isQueryEmpty=function(){return 0===t.state.query.length},t.handleQueryChange=function(e){var n=t.props,r=n.tagInputProps,o=void 0===r?{}:r,i=n.openOnKeyDown,s=e.currentTarget.value;t.setState({query:s,isOpen:!t.isQueryEmpty()||!i}),null!=o.inputProps&&I.Utils.safeInvoke(o.inputProps.onChange,e)},t.handleItemSelect=function(e,n){null!=t.input&&t.input.focus(),null!=t.state.activeItem&&(t.props.resetOnSelect&&!t.isQueryEmpty()&&t.setState({activeItem:t.props.items[0],query:""}),I.Utils.safeInvoke(t.props.onItemSelect,e,n))},t.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var n=t.props,r=n.popoverProps,o=void 0===r?{}:r,i=n.resetOnSelect;null!=t.input&&t.input!==document.activeElement?t.setState({activeItem:i?t.props.items[0]:t.state.activeItem,isOpen:!1,query:i?"":t.state.query}):t.props.openOnKeyDown||t.setState({isOpen:!0}),I.Utils.safeInvoke(o.onInteraction,e)})},t.handlePopoverWillOpen=function(){var e=t.props,n=e.popoverProps,r=void 0===n?{}:n;e.resetOnSelect&&t.setState({activeItem:t.props.items[0]}),I.Utils.safeInvoke(r.popoverWillOpen)},t.handlePopoverDidOpen=function(){var e=t.props.popoverProps,n=void 0===e?{}:e;null!=t.queryList&&t.queryList.scrollActiveItemIntoView(),I.Utils.safeInvoke(n.popoverDidOpen)},t.handleActiveItemChange=function(e){return t.setState({activeItem:e})},t.getTargetKeyDownHandler=function(e){return function(n){var r=n.which,o=t.props.resetOnSelect;r===I.Keys.ESCAPE||r===I.Keys.TAB?(null!=t.input&&t.input.blur(),t.setState({activeItem:o?t.props.items[0]:t.state.activeItem,isOpen:!1,query:o?"":t.state.query})):r!==I.Keys.BACKSPACE&&r!==I.Keys.ARROW_LEFT&&r!==I.Keys.ARROW_RIGHT&&t.setState({isOpen:!0}),t.state.isOpen&&I.Utils.safeInvoke(e,n)}},t}return v(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.openOnKeyDown,e.popoverProps,e.resetOnSelect,e.tagInputProps,f(e,["openOnKeyDown","popoverProps","resetOnSelect","tagInputProps"]));return h.createElement(this.TypedQueryList,d({},t,{activeItem:this.state.activeItem,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.displayName="Blueprint2.MultiSelect",t}(h.PureComponent),T=function(e){function t(t,n){var o=e.call(this,t,n)||this;o.TypedQueryList=O.ofType(),o.refHandlers={input:function(e){o.input=e;var t=o.props.inputProps,n=void 0===t?{}:t;I.Utils.safeInvoke(n.inputRef,e)},queryList:function(e){return o.list=e}},o.renderQueryList=function(e){var t=o.props,n=t.filterable,i=void 0===n||n,s=t.disabled,p=void 0!==s&&s,a=t.inputProps,u=void 0===a?{}:a,l=t.popoverProps,c=void 0===l?{}:l,v=h.createElement(I.InputGroup,d({autoFocus:!0,leftIcon:"search",placeholder:"Filter...",rightElement:o.maybeRenderInputClearButton(),value:e.query},u,{inputRef:o.refHandlers.input,onChange:o.handleQueryChange})),f=e.handleKeyDown,m=e.handleKeyUp;return h.createElement(I.Popover,d({autoFocus:!1,enforceFocus:!1,isOpen:o.state.isOpen,disabled:p,position:I.Position.BOTTOM_LEFT},c,{className:y()(e.className,c.className),onInteraction:o.handlePopoverInteraction,popoverClassName:y()(r.SELECT_POPOVER,c.popoverClassName),popoverWillOpen:o.handlePopoverWillOpen,popoverDidOpen:o.handlePopoverDidOpen,popoverWillClose:o.handlePopoverWillClose}),h.createElement("div",{onKeyDown:o.state.isOpen?f:o.handleTargetKeyDown,onKeyUp:o.state.isOpen?m:void 0},o.props.children),h.createElement("div",{onKeyDown:f,onKeyUp:m},i?v:void 0,e.itemList))},o.handleActiveItemChange=function(e){return o.setState({activeItem:e})},o.handleTargetKeyDown=function(e){e.which!==I.Keys.ARROW_UP&&e.which!==I.Keys.ARROW_DOWN||o.setState({isOpen:!0})},o.handleItemSelect=function(e,t){o.setState({isOpen:!1}),o.props.resetOnSelect&&o.resetQuery(),I.Utils.safeInvoke(o.props.onItemSelect,e,t)},o.handlePopoverInteraction=function(e){o.setState({isOpen:e});var t=o.props.popoverProps,n=void 0===t?{}:t;I.Utils.safeInvoke(n.onInteraction,e)},o.handlePopoverWillOpen=function(){var e=o.props,t=e.popoverProps,n=void 0===t?{}:t,r=e.resetOnClose;o.previousFocusedElement=document.activeElement,r&&o.resetQuery(),I.Utils.safeInvoke(n.popoverWillOpen)},o.handlePopoverDidOpen=function(){null!=o.list&&o.list.scrollActiveItemIntoView(),requestAnimationFrame(function(){var e=o.props.inputProps;!1!==(void 0===e?{}:e).autoFocus&&null!=o.input&&o.input.focus()});var e=o.props.popoverProps,t=void 0===e?{}:e;I.Utils.safeInvoke(t.popoverDidOpen)},o.handlePopoverWillClose=function(){requestAnimationFrame(function(){void 0!==o.previousFocusedElement&&(o.previousFocusedElement.focus(),o.previousFocusedElement=void 0)});var e=o.props.popoverProps,t=void 0===e?{}:e;I.Utils.safeInvoke(t.popoverWillClose)},o.handleQueryChange=function(e){var t=o.props,n=t.inputProps,r=void 0===n?{}:n,i=t.onQueryChange,s=e.currentTarget.value;o.setState({query:s}),I.Utils.safeInvoke(r.onChange,e),I.Utils.safeInvoke(i,s)},o.resetQuery=function(){var e=o.props,t=e.items,n=e.onQueryChange;o.setState({activeItem:t[0],query:""}),I.Utils.safeInvoke(n,"")};var i=t.inputProps,s=void 0===i?{}:i,p=null==s.value?"":s.value.toString();return o.state={isOpen:!1,query:p},o}return v(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.filterable,e.inputProps,e.popoverProps,f(e,["filterable","inputProps","popoverProps"]));return h.createElement(this.TypedQueryList,d({},t,{activeItem:this.state.activeItem,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentWillReceiveProps=function(e){var t=e.inputProps,n=void 0===t?{}:t;void 0!==n.value&&this.state.query!==n.value&&this.setState({query:n.value.toString()})},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.list&&this.list.scrollActiveItemIntoView()},t.prototype.maybeRenderInputClearButton=function(){return 0===this.state.query.length?void 0:h.createElement(I.Button,{className:I.Classes.MINIMAL,icon:"cross",onClick:this.resetQuery})},t.displayName="Blueprint2.Select",t}(h.PureComponent),E=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={isOpen:!1,isTyping:!1,query:""},t.TypedQueryList=O.ofType(),t.refHandlers={input:function(e){t.input=e;var n=t.props.inputProps,r=void 0===n?{}:n;I.Utils.safeInvoke(r.inputRef,e)},queryList:function(e){return t.queryList=e}},t.renderQueryList=function(e){var n=t.props,o=n.inputValueRenderer,i=n.inputProps,s=void 0===i?{}:i,p=n.popoverProps,a=void 0===p?{}:p,u=t.state,l=u.isTyping,c=u.selectedItem,v=u.query,f=e.handleKeyDown,m=e.handleKeyUp,O=l?v:c?o(c):"";return h.createElement(I.Popover,d({autoFocus:!1,enforceFocus:!1,isOpen:t.state.isOpen,position:I.Position.BOTTOM_LEFT},a,{className:y()(e.className,a.className),onInteraction:t.handlePopoverInteraction,popoverClassName:y()(r.SELECT_POPOVER,a.popoverClassName),popoverDidOpen:t.handlePopoverDidOpen,popoverWillClose:t.handlePopoverWillClose}),h.createElement(I.InputGroup,d({placeholder:"Search...",value:O},s,{inputRef:t.refHandlers.input,onChange:t.handleQueryChange,onFocus:t.handleInputFocus,onKeyDown:t.getTargetKeyDownHandler(f),onKeyUp:t.getTargetKeyUpHandler(m)})),h.createElement("div",{onKeyDown:f,onKeyUp:m},e.itemList))},t.selectText=function(){requestAnimationFrame(function(){null!=t.input&&t.input.setSelectionRange(0,t.input.value.length)})},t.handleInputFocus=function(e){var n=t.props,r=n.openOnKeyDown,o=n.inputProps,i=void 0===o?{}:o;t.selectText(),r||t.setState({isOpen:!0}),I.Utils.safeInvoke(i.onFocus,e)},t.handleActiveItemChange=function(e){return t.setState({activeItem:e})},t.handleItemSelect=function(e,n){var r;t.props.closeOnSelect?(null!=t.input&&t.input.blur(),r=!1):(null!=t.input&&t.input.focus(),t.selectText(),r=!0),t.setState({isOpen:r,isTyping:!1,query:"",selectedItem:e}),I.Utils.safeInvoke(t.props.onItemSelect,e,n)},t.handlePopoverInteraction=function(e){return requestAnimationFrame(function(){var n=t.props.popoverProps,r=void 0===n?{}:n;null!=t.input&&t.input!==document.activeElement&&t.setState({isOpen:!1}),I.Utils.safeInvoke(r.onInteraction,e)})},t.handlePopoverDidOpen=function(){var e=t.props.popoverProps,n=void 0===e?{}:e;null!=t.queryList&&t.queryList.scrollActiveItemIntoView(),I.Utils.safeInvoke(n.popoverDidOpen)},t.handlePopoverWillClose=function(){var e=t.props.popoverProps,n=void 0===e?{}:e,r=t.state.selectedItem;t.setState({activeItem:r||t.props.items[0],query:""}),I.Utils.safeInvoke(n.popoverDidOpen)},t.handleQueryChange=function(e){var n=t.props.inputProps,r=void 0===n?{}:n;t.setState({isTyping:!0,query:e.currentTarget.value}),I.Utils.safeInvoke(r.onChange,e)},t.getTargetKeyDownHandler=function(e){return function(n){var r=n.which,o=t.state,i=o.isTyping,s=o.selectedItem,p=t.props,a=p.inputProps,u=void 0===a?{}:a,l=p.openOnKeyDown;r===I.Keys.ESCAPE||r===I.Keys.TAB?(null!=t.input&&t.input.blur(),t.setState({isOpen:!1,selectedItem:i?void 0:s})):l&&r!==I.Keys.BACKSPACE&&r!==I.Keys.ARROW_LEFT&&r!==I.Keys.ARROW_RIGHT&&t.setState({isOpen:!0}),t.state.isOpen&&I.Utils.safeInvoke(e,n),I.Utils.safeInvoke(u.onKeyDown,n)}},t.getTargetKeyUpHandler=function(e){return function(n){var r=t.props.inputProps,o=void 0===r?{}:r;t.state.isOpen&&I.Utils.safeInvoke(e,n),I.Utils.safeInvoke(o.onKeyUp,n)}},t}return v(t,e),t.ofType=function(){return t},t.prototype.render=function(){var e=this.props,t=(e.inputProps,e.popoverProps,f(e,["inputProps","popoverProps"]));return h.createElement(this.TypedQueryList,d({},t,{activeItem:this.state.activeItem,onActiveItemChange:this.handleActiveItemChange,onItemSelect:this.handleItemSelect,query:this.state.query,ref:this.refHandlers.queryList,renderer:this.renderQueryList}))},t.prototype.componentDidUpdate=function(e,t){this.state.isOpen&&!t.isOpen&&null!=this.queryList&&this.queryList.scrollActiveItemIntoView()},t.displayName="Blueprint2.Suggest",t.defaultProps={closeOnSelect:!0,openOnKeyDown:!1},t}(h.PureComponent);n.d(t,"Classes",function(){return r}),n.d(t,"renderFilteredItems",function(){return l}),n.d(t,"Omnibar",function(){return C}),n.d(t,"QueryList",function(){return O}),n.d(t,"MultiSelect",function(){return S}),n.d(t,"Select",function(){return T}),n.d(t,"Suggest",function(){return E})}])}); |
@@ -21,4 +21,6 @@ /// <reference types="react" /> | ||
modifiers: IItemModifiers; | ||
/** The current query string used to filter the items. */ | ||
query: string; | ||
} | ||
/** Type alias for a function that receives an item and props and renders a JSX element (or `null`). */ | ||
export declare type ItemRenderer<T> = (item: T, itemProps: IItemRendererProps) => JSX.Element | null; |
"use strict"; | ||
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { HTMLInputProps, IBackdropProps, IInputGroupProps, IOverlayableProps, IOverlayProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface IOmnibarProps<T> extends IListItemsProps<T> { | ||
/** | ||
* React child to render when query is empty. | ||
*/ | ||
initialContent?: React.ReactChild; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: React.ReactChild; | ||
/** | ||
* Props to spread to `InputGroup`. All props are supported except `ref` (use `inputRef` instead). | ||
@@ -55,4 +49,2 @@ * If you want to control the filter input, you can pass `value` and `onChange` here | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private maybeRenderMenu(listProps); | ||
private isQueryEmpty; | ||
@@ -59,0 +51,0 @@ private handleActiveItemChange; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var core_1 = require("@blueprintjs/core"); | ||
var Classes = tslib_1.__importStar(require("../../common/classes")); | ||
var common_1 = require("../../common"); | ||
var queryList_1 = require("../query-list/queryList"); | ||
@@ -30,6 +30,6 @@ var Omnibar = /** @class */ (function (_super) { | ||
var handlers = isOpen && !_this.isQueryEmpty() ? { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp } : {}; | ||
return (React.createElement(core_1.Overlay, tslib_1.__assign({ hasBackdrop: true }, overlayProps, { isOpen: isOpen, className: classnames_1.default(overlayProps.className, Classes.OMNIBAR_OVERLAY), onClose: _this.handleOverlayClose }), | ||
React.createElement("div", tslib_1.__assign({ className: classnames_1.default(listProps.className, Classes.OMNIBAR) }, handlers), | ||
return (React.createElement(core_1.Overlay, tslib_1.__assign({ hasBackdrop: true }, overlayProps, { isOpen: isOpen, className: classnames_1.default(overlayProps.className, common_1.Classes.OMNIBAR_OVERLAY), onClose: _this.handleOverlayClose }), | ||
React.createElement("div", tslib_1.__assign({ className: classnames_1.default(listProps.className, common_1.Classes.OMNIBAR) }, handlers), | ||
React.createElement(core_1.InputGroup, tslib_1.__assign({ autoFocus: true, className: core_1.Classes.LARGE, leftIcon: "search", placeholder: "Search...", value: listProps.query }, inputProps, { onChange: _this.handleQueryChange })), | ||
_this.maybeRenderMenu(listProps)))); | ||
listProps.itemList))); | ||
}; | ||
@@ -58,4 +58,4 @@ _this.isQueryEmpty = function () { return _this.state.query.length === 0; }; | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, initialContent = _a.initialContent, isOpen = _a.isOpen, inputProps = _a.inputProps, noResults = _a.noResults, overlayProps = _a.overlayProps, restProps = tslib_1.__rest(_a, ["initialContent", "isOpen", "inputProps", "noResults", "overlayProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
var _a = this.props, _b = _a.initialContent, initialContent = _b === void 0 ? null : _b, isOpen = _a.isOpen, inputProps = _a.inputProps, overlayProps = _a.overlayProps, restProps = tslib_1.__rest(_a, ["initialContent", "isOpen", "inputProps", "overlayProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, initialContent: initialContent, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
}; | ||
@@ -70,21 +70,2 @@ Omnibar.prototype.componentWillReceiveProps = function (nextProps) { | ||
}; | ||
Omnibar.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : this.props.noResults; | ||
}; | ||
Omnibar.prototype.maybeRenderMenu = function (listProps) { | ||
var initialContent = this.props.initialContent; | ||
var menuChildren; | ||
if (!this.isQueryEmpty()) { | ||
menuChildren = this.renderItems(listProps); | ||
} | ||
else if (initialContent != null) { | ||
menuChildren = initialContent; | ||
} | ||
if (menuChildren != null) { | ||
return React.createElement(core_1.Menu, { ulRef: listProps.itemsParentRef }, menuChildren); | ||
} | ||
return undefined; | ||
}; | ||
Omnibar.displayName = "Blueprint2.Omnibar"; | ||
@@ -91,0 +72,0 @@ return Omnibar; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { IProps } from "@blueprintjs/core"; | ||
import { ItemRenderer } from "../../common/itemRenderer"; | ||
import { ItemListPredicate, ItemPredicate } from "../../common/predicate"; | ||
/** Reusable generic props for a component that operates on a filterable, selectable list of `items`. */ | ||
export interface IListItemsProps<T> extends IProps { | ||
/** Array of items in the list. */ | ||
items: T[]; | ||
/** | ||
* Customize querying of entire `items` array. Return new list of items. | ||
* This method can reorder, add, or remove items at will. | ||
* (Supports filter algorithms that operate on the entire set, rather than individual items.) | ||
* | ||
* If defined with `itemPredicate`, this prop takes priority and the other will be ignored. | ||
*/ | ||
itemListPredicate?: ItemListPredicate<T>; | ||
/** | ||
* Customize querying of individual items. Return `true` to keep the item, `false` to hide. | ||
* This method will be invoked once for each item, so it should be performant. For more complex | ||
* queries, use `itemListPredicate` to operate once on the entire array. | ||
* | ||
* If defined with `itemListPredicate`, this prop will be ignored. | ||
*/ | ||
itemPredicate?: ItemPredicate<T>; | ||
/** | ||
* Custom renderer for an item in the dropdown list. Receives a boolean indicating whether | ||
* this item is active (selected by keyboard arrows) and an `onClick` event handler that | ||
* should be attached to the returned element. | ||
*/ | ||
itemRenderer: ItemRenderer<T>; | ||
/** | ||
* Callback invoked when an item from the list is selected, | ||
* typically by clicking or pressing `enter` key. | ||
*/ | ||
onItemSelect: (item: T, event?: React.SyntheticEvent<HTMLElement>) => void; | ||
} | ||
import { IListItemsProps } from "../../common"; | ||
export interface IQueryListProps<T> extends IListItemsProps<T> { | ||
@@ -74,5 +41,12 @@ /** | ||
} | ||
/** Interface for object passed to `QueryList` `renderer` function. */ | ||
/** | ||
* An object describing how to render a `QueryList`. | ||
* A `QueryList` `renderer` receives this object as its sole argument. | ||
*/ | ||
export interface IQueryListRendererProps<T> extends IProps { | ||
/** | ||
* Array of items filtered by `itemListPredicate` or `itemPredicate`. | ||
*/ | ||
filteredItems: T[]; | ||
/** | ||
* Selection handler that should be invoked when a new item has been chosen, | ||
@@ -92,22 +66,5 @@ * perhaps because the user clicked it. | ||
handleKeyUp: React.KeyboardEventHandler<HTMLElement>; | ||
/** | ||
* Call this function to render an `item`. | ||
* `QueryList` will retrieve modifiers for the item and delegate to `itemRenderer` prop for the actual rendering. | ||
* The second parameter `index` is optional here; if provided, it will be passed through `itemRenderer` props. | ||
*/ | ||
renderItem: (item: T, index?: number) => JSX.Element | null; | ||
/** | ||
* Array of all (unfiltered) items in the list. | ||
* See `filteredItems` for a filtered array based on `query`. | ||
*/ | ||
items: T[]; | ||
/** | ||
* A ref handler that should be applied to the HTML element that contains the rendererd items. | ||
* This is required for the `QueryList` to scroll the active item into view automatically. | ||
*/ | ||
itemsParentRef: (ref: HTMLElement | null) => void; | ||
/** | ||
* Controlled query string. Attach an `onChange` handler to the relevant | ||
* element to control this prop from your application's state. | ||
*/ | ||
/** Rendered elements returned from `itemListRenderer` prop. */ | ||
itemList: React.ReactNode; | ||
/** The current query string. */ | ||
query: string; | ||
@@ -133,2 +90,6 @@ } | ||
scrollActiveItemIntoView(): void; | ||
/** default `itemListRenderer` implementation */ | ||
private renderItemList; | ||
/** wrapper around `itemRenderer` to inject props */ | ||
private renderItem; | ||
private getActiveElement(); | ||
@@ -141,3 +102,2 @@ private getActiveIndex(); | ||
private moveActiveIndex(direction); | ||
private renderItem; | ||
} |
@@ -11,2 +11,3 @@ "use strict"; | ||
var core_1 = require("@blueprintjs/core"); | ||
var common_1 = require("../../common"); | ||
var QueryList = /** @class */ (function (_super) { | ||
@@ -24,2 +25,24 @@ tslib_1.__extends(QueryList, _super); | ||
_this.shouldCheckActiveItemInViewport = false; | ||
/** default `itemListRenderer` implementation */ | ||
_this.renderItemList = function (listProps) { | ||
var _a = _this.props, initialContent = _a.initialContent, noResults = _a.noResults; | ||
var menuContent = common_1.renderFilteredItems(listProps, noResults, initialContent); | ||
return React.createElement(core_1.Menu, { ulRef: listProps.itemsParentRef }, menuContent); | ||
}; | ||
/** wrapper around `itemRenderer` to inject props */ | ||
_this.renderItem = function (item, index) { | ||
var _a = _this.props, activeItem = _a.activeItem, query = _a.query; | ||
var matchesPredicate = _this.state.filteredItems.indexOf(item) >= 0; | ||
var modifiers = { | ||
active: activeItem === item, | ||
disabled: false, | ||
matchesPredicate: matchesPredicate, | ||
}; | ||
return _this.props.itemRenderer(item, { | ||
handleClick: function (e) { return _this.handleItemSelect(item, e); }, | ||
index: index, | ||
modifiers: modifiers, | ||
query: query, | ||
}); | ||
}; | ||
_this.handleItemSelect = function (item, event) { | ||
@@ -55,18 +78,2 @@ core_1.Utils.safeInvoke(_this.props.onActiveItemChange, item); | ||
}; | ||
_this.renderItem = function (item, index) { | ||
var _a = _this.props, activeItem = _a.activeItem, itemListPredicate = _a.itemListPredicate, _b = _a.itemPredicate, itemPredicate = _b === void 0 ? function () { return true; } : _b, query = _a.query; | ||
var matchesPredicate = core_1.Utils.isFunction(itemListPredicate) | ||
? _this.state.filteredItems.indexOf(item) >= 0 | ||
: itemPredicate(query, item, index); | ||
var modifiers = { | ||
active: activeItem === item, | ||
disabled: false, | ||
matchesPredicate: matchesPredicate, | ||
}; | ||
return _this.props.itemRenderer(item, { | ||
handleClick: function (e) { return _this.handleItemSelect(item, e); }, | ||
index: index, | ||
modifiers: modifiers, | ||
}); | ||
}; | ||
return _this; | ||
@@ -78,12 +85,18 @@ } | ||
QueryList.prototype.render = function () { | ||
var _a = this.props, className = _a.className, items = _a.items, renderer = _a.renderer, query = _a.query; | ||
var _a = this.props, className = _a.className, items = _a.items, renderer = _a.renderer, query = _a.query, _b = _a.itemListRenderer, itemListRenderer = _b === void 0 ? this.renderItemList : _b; | ||
var filteredItems = this.state.filteredItems; | ||
return renderer({ | ||
className: className, | ||
filteredItems: filteredItems, | ||
handleItemSelect: this.handleItemSelect, | ||
handleKeyDown: this.handleKeyDown, | ||
handleKeyUp: this.handleKeyUp, | ||
items: items, | ||
itemsParentRef: this.refHandlers.itemsParent, | ||
itemList: itemListRenderer({ | ||
filteredItems: filteredItems, | ||
items: items, | ||
itemsParentRef: this.refHandlers.itemsParent, | ||
query: query, | ||
renderItem: this.renderItem, | ||
}), | ||
query: query, | ||
renderItem: this.renderItem, | ||
}); | ||
@@ -90,0 +103,0 @@ }; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { IPopoverProps, ITagInputProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface IMultiSelectProps<T> extends IListItemsProps<T> { | ||
@@ -9,8 +9,2 @@ /** Controlled selected values. */ | ||
/** | ||
* React child to render when query is empty. | ||
*/ | ||
initialContent?: React.ReactChild; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: React.ReactChild; | ||
/** | ||
* Whether the popover opens on key down or when `TagInput` is focused. | ||
@@ -49,3 +43,2 @@ * @default false | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private isQueryEmpty; | ||
@@ -52,0 +45,0 @@ private handleQueryChange; |
"use strict"; | ||
/** | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
@@ -11,3 +11,3 @@ * Licensed under the terms of the LICENSE file distributed with this project. | ||
var core_1 = require("@blueprintjs/core"); | ||
var Classes = tslib_1.__importStar(require("../../common/classes")); | ||
var common_1 = require("../../common"); | ||
var queryList_1 = require("../query-list/queryList"); | ||
@@ -37,7 +37,6 @@ var MultiSelect = /** @class */ (function (_super) { | ||
onChange: _this.handleQueryChange, value: query }); | ||
return (React.createElement(core_1.Popover, tslib_1.__assign({ autoFocus: false, canEscapeKeyClose: true, enforceFocus: false, isOpen: _this.state.isOpen, position: core_1.Position.BOTTOM_LEFT }, popoverProps, { className: classnames_1.default(listProps.className, popoverProps.className), onInteraction: _this.handlePopoverInteraction, popoverClassName: classnames_1.default(Classes.MULTISELECT_POPOVER, popoverProps.popoverClassName), popoverDidOpen: _this.handlePopoverDidOpen, popoverWillOpen: _this.handlePopoverWillOpen }), | ||
return (React.createElement(core_1.Popover, tslib_1.__assign({ autoFocus: false, canEscapeKeyClose: true, enforceFocus: false, isOpen: _this.state.isOpen, position: core_1.Position.BOTTOM_LEFT }, popoverProps, { className: classnames_1.default(listProps.className, popoverProps.className), onInteraction: _this.handlePopoverInteraction, popoverClassName: classnames_1.default(common_1.Classes.MULTISELECT_POPOVER, popoverProps.popoverClassName), popoverDidOpen: _this.handlePopoverDidOpen, popoverWillOpen: _this.handlePopoverWillOpen }), | ||
React.createElement("div", { onKeyDown: _this.getTargetKeyDownHandler(handleKeyDown), onKeyUp: _this.state.isOpen ? handleKeyUp : undefined }, | ||
React.createElement(core_1.TagInput, tslib_1.__assign({}, tagInputProps, { inputProps: defaultInputProps, inputRef: _this.refHandlers.input, className: classnames_1.default(Classes.MULTISELECT, tagInputProps.className), values: selectedItems.map(_this.props.tagRenderer) }))), | ||
React.createElement("div", { onKeyDown: _this.getTargetKeyDownHandler(handleKeyDown), onKeyUp: handleKeyUp }, | ||
React.createElement(core_1.Menu, { ulRef: listProps.itemsParentRef }, _this.renderItems(listProps))))); | ||
React.createElement(core_1.TagInput, tslib_1.__assign({}, tagInputProps, { inputProps: defaultInputProps, inputRef: _this.refHandlers.input, className: classnames_1.default(common_1.Classes.MULTISELECT, tagInputProps.className), values: selectedItems.map(_this.props.tagRenderer) }))), | ||
React.createElement("div", { onKeyDown: _this.getTargetKeyDownHandler(handleKeyDown), onKeyUp: handleKeyUp }, listProps.itemList))); | ||
}; | ||
@@ -134,14 +133,5 @@ _this.isQueryEmpty = function () { return _this.state.query.length === 0; }; | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, initialContent = _a.initialContent, noResults = _a.noResults, openOnKeyDown = _a.openOnKeyDown, popoverProps = _a.popoverProps, resetOnSelect = _a.resetOnSelect, tagInputProps = _a.tagInputProps, restProps = tslib_1.__rest(_a, ["initialContent", "noResults", "openOnKeyDown", "popoverProps", "resetOnSelect", "tagInputProps"]); | ||
var _a = this.props, openOnKeyDown = _a.openOnKeyDown, popoverProps = _a.popoverProps, resetOnSelect = _a.resetOnSelect, tagInputProps = _a.tagInputProps, restProps = tslib_1.__rest(_a, ["openOnKeyDown", "popoverProps", "resetOnSelect", "tagInputProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
}; | ||
MultiSelect.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var _b = this.props, initialContent = _b.initialContent, noResults = _b.noResults; | ||
if (initialContent != null && this.isQueryEmpty()) { | ||
return initialContent; | ||
} | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : noResults; | ||
}; | ||
MultiSelect.displayName = "Blueprint2.MultiSelect"; | ||
@@ -148,0 +138,0 @@ return MultiSelect; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { HTMLInputProps, IInputGroupProps, IPopoverProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface ISelectProps<T> extends IListItemsProps<T> { | ||
@@ -13,6 +13,2 @@ /** | ||
/** | ||
* React child to render when query is empty. | ||
*/ | ||
initialContent?: React.ReactChild; | ||
/** | ||
* Whether the component is non-interactive. | ||
@@ -23,4 +19,2 @@ * Note that you'll also need to disable the component's children, if appropriate. | ||
disabled?: boolean; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: React.ReactChild; | ||
/** | ||
@@ -71,5 +65,3 @@ * Props to spread to `InputGroup`. All props are supported except `ref` (use `inputRef` instead). | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private maybeRenderInputClearButton(); | ||
private isQueryEmpty; | ||
private handleActiveItemChange; | ||
@@ -76,0 +68,0 @@ private handleTargetKeyDown; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var core_1 = require("@blueprintjs/core"); | ||
var Classes = tslib_1.__importStar(require("../../common/classes")); | ||
var common_1 = require("../../common"); | ||
var queryList_1 = require("../query-list/queryList"); | ||
@@ -33,9 +33,8 @@ var Select = /** @class */ (function (_super) { | ||
var handleKeyDown = listProps.handleKeyDown, handleKeyUp = listProps.handleKeyUp; | ||
return (React.createElement(core_1.Popover, tslib_1.__assign({ autoFocus: false, enforceFocus: false, isOpen: _this.state.isOpen, disabled: disabled, position: core_1.Position.BOTTOM_LEFT }, popoverProps, { className: classnames_1.default(listProps.className, popoverProps.className), onInteraction: _this.handlePopoverInteraction, popoverClassName: classnames_1.default(Classes.SELECT_POPOVER, popoverProps.popoverClassName), popoverWillOpen: _this.handlePopoverWillOpen, popoverDidOpen: _this.handlePopoverDidOpen, popoverWillClose: _this.handlePopoverWillClose }), | ||
return (React.createElement(core_1.Popover, tslib_1.__assign({ autoFocus: false, enforceFocus: false, isOpen: _this.state.isOpen, disabled: disabled, position: core_1.Position.BOTTOM_LEFT }, popoverProps, { className: classnames_1.default(listProps.className, popoverProps.className), onInteraction: _this.handlePopoverInteraction, popoverClassName: classnames_1.default(common_1.Classes.SELECT_POPOVER, popoverProps.popoverClassName), popoverWillOpen: _this.handlePopoverWillOpen, popoverDidOpen: _this.handlePopoverDidOpen, popoverWillClose: _this.handlePopoverWillClose }), | ||
React.createElement("div", { onKeyDown: _this.state.isOpen ? handleKeyDown : _this.handleTargetKeyDown, onKeyUp: _this.state.isOpen ? handleKeyUp : undefined }, _this.props.children), | ||
React.createElement("div", { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }, | ||
filterable ? input : undefined, | ||
React.createElement(core_1.Menu, { ulRef: listProps.itemsParentRef }, _this.renderItems(listProps))))); | ||
listProps.itemList))); | ||
}; | ||
_this.isQueryEmpty = function () { return _this.state.query.length === 0; }; | ||
_this.handleActiveItemChange = function (activeItem) { return _this.setState({ activeItem: activeItem }); }; | ||
@@ -119,3 +118,3 @@ _this.handleTargetKeyDown = function (event) { | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, filterable = _a.filterable, initialContent = _a.initialContent, inputProps = _a.inputProps, noResults = _a.noResults, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["filterable", "initialContent", "inputProps", "noResults", "popoverProps"]); | ||
var _a = this.props, filterable = _a.filterable, inputProps = _a.inputProps, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["filterable", "inputProps", "popoverProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
@@ -134,13 +133,4 @@ }; | ||
}; | ||
Select.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var _b = this.props, initialContent = _b.initialContent, noResults = _b.noResults; | ||
if (initialContent != null && this.isQueryEmpty()) { | ||
return initialContent; | ||
} | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : noResults; | ||
}; | ||
Select.prototype.maybeRenderInputClearButton = function () { | ||
return !this.isQueryEmpty() ? (React.createElement(core_1.Button, { className: core_1.Classes.MINIMAL, icon: "cross", onClick: this.resetQuery })) : (undefined); | ||
return this.state.query.length === 0 ? (undefined) : (React.createElement(core_1.Button, { className: core_1.Classes.MINIMAL, icon: "cross", onClick: this.resetQuery })); | ||
}; | ||
@@ -147,0 +137,0 @@ Select.displayName = "Blueprint2.Select"; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { HTMLInputProps, IInputGroupProps, IPopoverProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface ISuggestProps<T> extends IListItemsProps<T> { | ||
@@ -19,4 +19,2 @@ /** | ||
inputValueRenderer: (item: T) => string; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: string | JSX.Element; | ||
/** | ||
@@ -52,3 +50,2 @@ * Whether the popover opens on key down or when the input is focused. | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private selectText; | ||
@@ -55,0 +52,0 @@ private handleInputFocus; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var core_1 = require("@blueprintjs/core"); | ||
var Classes = tslib_1.__importStar(require("../../common/classes")); | ||
var common_1 = require("../../common"); | ||
var queryList_1 = require("../query-list/queryList"); | ||
@@ -38,6 +38,5 @@ var Suggest = /** @class */ (function (_super) { | ||
var inputValue = isTyping ? query : selectedItem ? inputValueRenderer(selectedItem) : ""; | ||
return (React.createElement(core_1.Popover, tslib_1.__assign({ autoFocus: false, enforceFocus: false, isOpen: _this.state.isOpen, position: core_1.Position.BOTTOM_LEFT }, popoverProps, { className: classnames_1.default(listProps.className, popoverProps.className), onInteraction: _this.handlePopoverInteraction, popoverClassName: classnames_1.default(Classes.SELECT_POPOVER, popoverProps.popoverClassName), popoverDidOpen: _this.handlePopoverDidOpen, popoverWillClose: _this.handlePopoverWillClose }), | ||
return (React.createElement(core_1.Popover, tslib_1.__assign({ autoFocus: false, enforceFocus: false, isOpen: _this.state.isOpen, position: core_1.Position.BOTTOM_LEFT }, popoverProps, { className: classnames_1.default(listProps.className, popoverProps.className), onInteraction: _this.handlePopoverInteraction, popoverClassName: classnames_1.default(common_1.Classes.SELECT_POPOVER, popoverProps.popoverClassName), popoverDidOpen: _this.handlePopoverDidOpen, popoverWillClose: _this.handlePopoverWillClose }), | ||
React.createElement(core_1.InputGroup, tslib_1.__assign({ placeholder: "Search...", value: inputValue }, inputProps, { inputRef: _this.refHandlers.input, onChange: _this.handleQueryChange, onFocus: _this.handleInputFocus, onKeyDown: _this.getTargetKeyDownHandler(handleKeyDown), onKeyUp: _this.getTargetKeyUpHandler(handleKeyUp) })), | ||
React.createElement("div", { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }, | ||
React.createElement(core_1.Menu, { ulRef: listProps.itemsParentRef }, _this.renderItems(listProps))))); | ||
React.createElement("div", { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }, listProps.itemList))); | ||
}; | ||
@@ -163,3 +162,3 @@ _this.selectText = function () { | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, inputProps = _a.inputProps, noResults = _a.noResults, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["inputProps", "noResults", "popoverProps"]); | ||
var _a = this.props, inputProps = _a.inputProps, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["inputProps", "popoverProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
@@ -172,7 +171,2 @@ }; | ||
}; | ||
Suggest.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : this.props.noResults; | ||
}; | ||
Suggest.displayName = "Blueprint2.Suggest"; | ||
@@ -179,0 +173,0 @@ // Note: can't use <T> in static members, so this remains dynamically typed. |
@@ -1,4 +0,2 @@ | ||
export * from "./common/classes"; | ||
export * from "./common/itemRenderer"; | ||
export * from "./common/predicate"; | ||
export * from "./common"; | ||
export * from "./components"; |
@@ -9,3 +9,3 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./common/classes"), exports); | ||
tslib_1.__exportStar(require("./common"), exports); | ||
tslib_1.__exportStar(require("./components"), exports); |
@@ -21,4 +21,6 @@ /// <reference types="react" /> | ||
modifiers: IItemModifiers; | ||
/** The current query string used to filter the items. */ | ||
query: string; | ||
} | ||
/** Type alias for a function that receives an item and props and renders a JSX element (or `null`). */ | ||
export declare type ItemRenderer<T> = (item: T, itemProps: IItemRendererProps) => JSX.Element | null; |
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { HTMLInputProps, IBackdropProps, IInputGroupProps, IOverlayableProps, IOverlayProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface IOmnibarProps<T> extends IListItemsProps<T> { | ||
/** | ||
* React child to render when query is empty. | ||
*/ | ||
initialContent?: React.ReactChild; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: React.ReactChild; | ||
/** | ||
* Props to spread to `InputGroup`. All props are supported except `ref` (use `inputRef` instead). | ||
@@ -55,4 +49,2 @@ * If you want to control the filter input, you can pass `value` and `onChange` here | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private maybeRenderMenu(listProps); | ||
private isQueryEmpty; | ||
@@ -59,0 +51,0 @@ private handleActiveItemChange; |
@@ -9,4 +9,4 @@ /* | ||
import * as React from "react"; | ||
import { Classes as CoreClasses, InputGroup, Menu, Overlay, Utils, } from "@blueprintjs/core"; | ||
import * as Classes from "../../common/classes"; | ||
import { Classes as CoreClasses, InputGroup, Overlay, Utils, } from "@blueprintjs/core"; | ||
import { Classes } from "../../common"; | ||
import { QueryList } from "../query-list/queryList"; | ||
@@ -31,3 +31,3 @@ var Omnibar = /** @class */ (function (_super) { | ||
React.createElement(InputGroup, tslib_1.__assign({ autoFocus: true, className: CoreClasses.LARGE, leftIcon: "search", placeholder: "Search...", value: listProps.query }, inputProps, { onChange: _this.handleQueryChange })), | ||
_this.maybeRenderMenu(listProps)))); | ||
listProps.itemList))); | ||
}; | ||
@@ -56,4 +56,4 @@ _this.isQueryEmpty = function () { return _this.state.query.length === 0; }; | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, initialContent = _a.initialContent, isOpen = _a.isOpen, inputProps = _a.inputProps, noResults = _a.noResults, overlayProps = _a.overlayProps, restProps = tslib_1.__rest(_a, ["initialContent", "isOpen", "inputProps", "noResults", "overlayProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
var _a = this.props, _b = _a.initialContent, initialContent = _b === void 0 ? null : _b, isOpen = _a.isOpen, inputProps = _a.inputProps, overlayProps = _a.overlayProps, restProps = tslib_1.__rest(_a, ["initialContent", "isOpen", "inputProps", "overlayProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, initialContent: initialContent, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
}; | ||
@@ -68,21 +68,2 @@ Omnibar.prototype.componentWillReceiveProps = function (nextProps) { | ||
}; | ||
Omnibar.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : this.props.noResults; | ||
}; | ||
Omnibar.prototype.maybeRenderMenu = function (listProps) { | ||
var initialContent = this.props.initialContent; | ||
var menuChildren; | ||
if (!this.isQueryEmpty()) { | ||
menuChildren = this.renderItems(listProps); | ||
} | ||
else if (initialContent != null) { | ||
menuChildren = initialContent; | ||
} | ||
if (menuChildren != null) { | ||
return React.createElement(Menu, { ulRef: listProps.itemsParentRef }, menuChildren); | ||
} | ||
return undefined; | ||
}; | ||
Omnibar.displayName = "Blueprint2.Omnibar"; | ||
@@ -89,0 +70,0 @@ return Omnibar; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { IProps } from "@blueprintjs/core"; | ||
import { ItemRenderer } from "../../common/itemRenderer"; | ||
import { ItemListPredicate, ItemPredicate } from "../../common/predicate"; | ||
/** Reusable generic props for a component that operates on a filterable, selectable list of `items`. */ | ||
export interface IListItemsProps<T> extends IProps { | ||
/** Array of items in the list. */ | ||
items: T[]; | ||
/** | ||
* Customize querying of entire `items` array. Return new list of items. | ||
* This method can reorder, add, or remove items at will. | ||
* (Supports filter algorithms that operate on the entire set, rather than individual items.) | ||
* | ||
* If defined with `itemPredicate`, this prop takes priority and the other will be ignored. | ||
*/ | ||
itemListPredicate?: ItemListPredicate<T>; | ||
/** | ||
* Customize querying of individual items. Return `true` to keep the item, `false` to hide. | ||
* This method will be invoked once for each item, so it should be performant. For more complex | ||
* queries, use `itemListPredicate` to operate once on the entire array. | ||
* | ||
* If defined with `itemListPredicate`, this prop will be ignored. | ||
*/ | ||
itemPredicate?: ItemPredicate<T>; | ||
/** | ||
* Custom renderer for an item in the dropdown list. Receives a boolean indicating whether | ||
* this item is active (selected by keyboard arrows) and an `onClick` event handler that | ||
* should be attached to the returned element. | ||
*/ | ||
itemRenderer: ItemRenderer<T>; | ||
/** | ||
* Callback invoked when an item from the list is selected, | ||
* typically by clicking or pressing `enter` key. | ||
*/ | ||
onItemSelect: (item: T, event?: React.SyntheticEvent<HTMLElement>) => void; | ||
} | ||
import { IListItemsProps } from "../../common"; | ||
export interface IQueryListProps<T> extends IListItemsProps<T> { | ||
@@ -74,5 +41,12 @@ /** | ||
} | ||
/** Interface for object passed to `QueryList` `renderer` function. */ | ||
/** | ||
* An object describing how to render a `QueryList`. | ||
* A `QueryList` `renderer` receives this object as its sole argument. | ||
*/ | ||
export interface IQueryListRendererProps<T> extends IProps { | ||
/** | ||
* Array of items filtered by `itemListPredicate` or `itemPredicate`. | ||
*/ | ||
filteredItems: T[]; | ||
/** | ||
* Selection handler that should be invoked when a new item has been chosen, | ||
@@ -92,22 +66,5 @@ * perhaps because the user clicked it. | ||
handleKeyUp: React.KeyboardEventHandler<HTMLElement>; | ||
/** | ||
* Call this function to render an `item`. | ||
* `QueryList` will retrieve modifiers for the item and delegate to `itemRenderer` prop for the actual rendering. | ||
* The second parameter `index` is optional here; if provided, it will be passed through `itemRenderer` props. | ||
*/ | ||
renderItem: (item: T, index?: number) => JSX.Element | null; | ||
/** | ||
* Array of all (unfiltered) items in the list. | ||
* See `filteredItems` for a filtered array based on `query`. | ||
*/ | ||
items: T[]; | ||
/** | ||
* A ref handler that should be applied to the HTML element that contains the rendererd items. | ||
* This is required for the `QueryList` to scroll the active item into view automatically. | ||
*/ | ||
itemsParentRef: (ref: HTMLElement | null) => void; | ||
/** | ||
* Controlled query string. Attach an `onChange` handler to the relevant | ||
* element to control this prop from your application's state. | ||
*/ | ||
/** Rendered elements returned from `itemListRenderer` prop. */ | ||
itemList: React.ReactNode; | ||
/** The current query string. */ | ||
query: string; | ||
@@ -133,2 +90,6 @@ } | ||
scrollActiveItemIntoView(): void; | ||
/** default `itemListRenderer` implementation */ | ||
private renderItemList; | ||
/** wrapper around `itemRenderer` to inject props */ | ||
private renderItem; | ||
private getActiveElement(); | ||
@@ -141,3 +102,2 @@ private getActiveIndex(); | ||
private moveActiveIndex(direction); | ||
private renderItem; | ||
} |
@@ -8,3 +8,4 @@ /* | ||
import * as React from "react"; | ||
import { Keys, Utils } from "@blueprintjs/core"; | ||
import { Keys, Menu, Utils } from "@blueprintjs/core"; | ||
import { renderFilteredItems } from "../../common"; | ||
var QueryList = /** @class */ (function (_super) { | ||
@@ -22,2 +23,24 @@ tslib_1.__extends(QueryList, _super); | ||
_this.shouldCheckActiveItemInViewport = false; | ||
/** default `itemListRenderer` implementation */ | ||
_this.renderItemList = function (listProps) { | ||
var _a = _this.props, initialContent = _a.initialContent, noResults = _a.noResults; | ||
var menuContent = renderFilteredItems(listProps, noResults, initialContent); | ||
return React.createElement(Menu, { ulRef: listProps.itemsParentRef }, menuContent); | ||
}; | ||
/** wrapper around `itemRenderer` to inject props */ | ||
_this.renderItem = function (item, index) { | ||
var _a = _this.props, activeItem = _a.activeItem, query = _a.query; | ||
var matchesPredicate = _this.state.filteredItems.indexOf(item) >= 0; | ||
var modifiers = { | ||
active: activeItem === item, | ||
disabled: false, | ||
matchesPredicate: matchesPredicate, | ||
}; | ||
return _this.props.itemRenderer(item, { | ||
handleClick: function (e) { return _this.handleItemSelect(item, e); }, | ||
index: index, | ||
modifiers: modifiers, | ||
query: query, | ||
}); | ||
}; | ||
_this.handleItemSelect = function (item, event) { | ||
@@ -53,18 +76,2 @@ Utils.safeInvoke(_this.props.onActiveItemChange, item); | ||
}; | ||
_this.renderItem = function (item, index) { | ||
var _a = _this.props, activeItem = _a.activeItem, itemListPredicate = _a.itemListPredicate, _b = _a.itemPredicate, itemPredicate = _b === void 0 ? function () { return true; } : _b, query = _a.query; | ||
var matchesPredicate = Utils.isFunction(itemListPredicate) | ||
? _this.state.filteredItems.indexOf(item) >= 0 | ||
: itemPredicate(query, item, index); | ||
var modifiers = { | ||
active: activeItem === item, | ||
disabled: false, | ||
matchesPredicate: matchesPredicate, | ||
}; | ||
return _this.props.itemRenderer(item, { | ||
handleClick: function (e) { return _this.handleItemSelect(item, e); }, | ||
index: index, | ||
modifiers: modifiers, | ||
}); | ||
}; | ||
return _this; | ||
@@ -76,12 +83,18 @@ } | ||
QueryList.prototype.render = function () { | ||
var _a = this.props, className = _a.className, items = _a.items, renderer = _a.renderer, query = _a.query; | ||
var _a = this.props, className = _a.className, items = _a.items, renderer = _a.renderer, query = _a.query, _b = _a.itemListRenderer, itemListRenderer = _b === void 0 ? this.renderItemList : _b; | ||
var filteredItems = this.state.filteredItems; | ||
return renderer({ | ||
className: className, | ||
filteredItems: filteredItems, | ||
handleItemSelect: this.handleItemSelect, | ||
handleKeyDown: this.handleKeyDown, | ||
handleKeyUp: this.handleKeyUp, | ||
items: items, | ||
itemsParentRef: this.refHandlers.itemsParent, | ||
itemList: itemListRenderer({ | ||
filteredItems: filteredItems, | ||
items: items, | ||
itemsParentRef: this.refHandlers.itemsParent, | ||
query: query, | ||
renderItem: this.renderItem, | ||
}), | ||
query: query, | ||
renderItem: this.renderItem, | ||
}); | ||
@@ -88,0 +101,0 @@ }; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { IPopoverProps, ITagInputProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface IMultiSelectProps<T> extends IListItemsProps<T> { | ||
@@ -9,8 +9,2 @@ /** Controlled selected values. */ | ||
/** | ||
* React child to render when query is empty. | ||
*/ | ||
initialContent?: React.ReactChild; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: React.ReactChild; | ||
/** | ||
* Whether the popover opens on key down or when `TagInput` is focused. | ||
@@ -49,3 +43,2 @@ * @default false | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private isQueryEmpty; | ||
@@ -52,0 +45,0 @@ private handleQueryChange; |
@@ -1,2 +0,2 @@ | ||
/** | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
@@ -8,4 +8,4 @@ * Licensed under the terms of the LICENSE file distributed with this project. | ||
import * as React from "react"; | ||
import { Keys, Menu, Popover, Position, TagInput, Utils, } from "@blueprintjs/core"; | ||
import * as Classes from "../../common/classes"; | ||
import { Keys, Popover, Position, TagInput, Utils, } from "@blueprintjs/core"; | ||
import { Classes } from "../../common"; | ||
import { QueryList } from "../query-list/queryList"; | ||
@@ -38,4 +38,3 @@ var MultiSelect = /** @class */ (function (_super) { | ||
React.createElement(TagInput, tslib_1.__assign({}, tagInputProps, { inputProps: defaultInputProps, inputRef: _this.refHandlers.input, className: classNames(Classes.MULTISELECT, tagInputProps.className), values: selectedItems.map(_this.props.tagRenderer) }))), | ||
React.createElement("div", { onKeyDown: _this.getTargetKeyDownHandler(handleKeyDown), onKeyUp: handleKeyUp }, | ||
React.createElement(Menu, { ulRef: listProps.itemsParentRef }, _this.renderItems(listProps))))); | ||
React.createElement("div", { onKeyDown: _this.getTargetKeyDownHandler(handleKeyDown), onKeyUp: handleKeyUp }, listProps.itemList))); | ||
}; | ||
@@ -132,14 +131,5 @@ _this.isQueryEmpty = function () { return _this.state.query.length === 0; }; | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, initialContent = _a.initialContent, noResults = _a.noResults, openOnKeyDown = _a.openOnKeyDown, popoverProps = _a.popoverProps, resetOnSelect = _a.resetOnSelect, tagInputProps = _a.tagInputProps, restProps = tslib_1.__rest(_a, ["initialContent", "noResults", "openOnKeyDown", "popoverProps", "resetOnSelect", "tagInputProps"]); | ||
var _a = this.props, openOnKeyDown = _a.openOnKeyDown, popoverProps = _a.popoverProps, resetOnSelect = _a.resetOnSelect, tagInputProps = _a.tagInputProps, restProps = tslib_1.__rest(_a, ["openOnKeyDown", "popoverProps", "resetOnSelect", "tagInputProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
}; | ||
MultiSelect.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var _b = this.props, initialContent = _b.initialContent, noResults = _b.noResults; | ||
if (initialContent != null && this.isQueryEmpty()) { | ||
return initialContent; | ||
} | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : noResults; | ||
}; | ||
MultiSelect.displayName = "Blueprint2.MultiSelect"; | ||
@@ -146,0 +136,0 @@ return MultiSelect; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { HTMLInputProps, IInputGroupProps, IPopoverProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface ISelectProps<T> extends IListItemsProps<T> { | ||
@@ -13,6 +13,2 @@ /** | ||
/** | ||
* React child to render when query is empty. | ||
*/ | ||
initialContent?: React.ReactChild; | ||
/** | ||
* Whether the component is non-interactive. | ||
@@ -23,4 +19,2 @@ * Note that you'll also need to disable the component's children, if appropriate. | ||
disabled?: boolean; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: React.ReactChild; | ||
/** | ||
@@ -71,5 +65,3 @@ * Props to spread to `InputGroup`. All props are supported except `ref` (use `inputRef` instead). | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private maybeRenderInputClearButton(); | ||
private isQueryEmpty; | ||
private handleActiveItemChange; | ||
@@ -76,0 +68,0 @@ private handleTargetKeyDown; |
@@ -9,4 +9,4 @@ /* | ||
import * as React from "react"; | ||
import { Button, Classes as CoreClasses, InputGroup, Keys, Menu, Popover, Position, Utils, } from "@blueprintjs/core"; | ||
import * as Classes from "../../common/classes"; | ||
import { Button, Classes as CoreClasses, InputGroup, Keys, Popover, Position, Utils, } from "@blueprintjs/core"; | ||
import { Classes } from "../../common"; | ||
import { QueryList } from "../query-list/queryList"; | ||
@@ -35,5 +35,4 @@ var Select = /** @class */ (function (_super) { | ||
filterable ? input : undefined, | ||
React.createElement(Menu, { ulRef: listProps.itemsParentRef }, _this.renderItems(listProps))))); | ||
listProps.itemList))); | ||
}; | ||
_this.isQueryEmpty = function () { return _this.state.query.length === 0; }; | ||
_this.handleActiveItemChange = function (activeItem) { return _this.setState({ activeItem: activeItem }); }; | ||
@@ -117,3 +116,3 @@ _this.handleTargetKeyDown = function (event) { | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, filterable = _a.filterable, initialContent = _a.initialContent, inputProps = _a.inputProps, noResults = _a.noResults, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["filterable", "initialContent", "inputProps", "noResults", "popoverProps"]); | ||
var _a = this.props, filterable = _a.filterable, inputProps = _a.inputProps, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["filterable", "inputProps", "popoverProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
@@ -132,13 +131,4 @@ }; | ||
}; | ||
Select.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var _b = this.props, initialContent = _b.initialContent, noResults = _b.noResults; | ||
if (initialContent != null && this.isQueryEmpty()) { | ||
return initialContent; | ||
} | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : noResults; | ||
}; | ||
Select.prototype.maybeRenderInputClearButton = function () { | ||
return !this.isQueryEmpty() ? (React.createElement(Button, { className: CoreClasses.MINIMAL, icon: "cross", onClick: this.resetQuery })) : (undefined); | ||
return this.state.query.length === 0 ? (undefined) : (React.createElement(Button, { className: CoreClasses.MINIMAL, icon: "cross", onClick: this.resetQuery })); | ||
}; | ||
@@ -145,0 +135,0 @@ Select.displayName = "Blueprint2.Select"; |
/// <reference types="react" /> | ||
import * as React from "react"; | ||
import { HTMLInputProps, IInputGroupProps, IPopoverProps } from "@blueprintjs/core"; | ||
import { IListItemsProps } from "../query-list/queryList"; | ||
import { IListItemsProps } from "../../common"; | ||
export interface ISuggestProps<T> extends IListItemsProps<T> { | ||
@@ -19,4 +19,2 @@ /** | ||
inputValueRenderer: (item: T) => string; | ||
/** React child to render when filtering items returns zero results. */ | ||
noResults?: string | JSX.Element; | ||
/** | ||
@@ -52,3 +50,2 @@ * Whether the popover opens on key down or when the input is focused. | ||
private renderQueryList; | ||
private renderItems({items, renderItem}); | ||
private selectText; | ||
@@ -55,0 +52,0 @@ private handleInputFocus; |
@@ -9,4 +9,4 @@ /* | ||
import * as React from "react"; | ||
import { InputGroup, Keys, Menu, Popover, Position, Utils, } from "@blueprintjs/core"; | ||
import * as Classes from "../../common/classes"; | ||
import { InputGroup, Keys, Popover, Position, Utils, } from "@blueprintjs/core"; | ||
import { Classes } from "../../common"; | ||
import { QueryList } from "../query-list/queryList"; | ||
@@ -38,4 +38,3 @@ var Suggest = /** @class */ (function (_super) { | ||
React.createElement(InputGroup, tslib_1.__assign({ placeholder: "Search...", value: inputValue }, inputProps, { inputRef: _this.refHandlers.input, onChange: _this.handleQueryChange, onFocus: _this.handleInputFocus, onKeyDown: _this.getTargetKeyDownHandler(handleKeyDown), onKeyUp: _this.getTargetKeyUpHandler(handleKeyUp) })), | ||
React.createElement("div", { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }, | ||
React.createElement(Menu, { ulRef: listProps.itemsParentRef }, _this.renderItems(listProps))))); | ||
React.createElement("div", { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }, listProps.itemList))); | ||
}; | ||
@@ -161,3 +160,3 @@ _this.selectText = function () { | ||
// omit props specific to this component, spread the rest. | ||
var _a = this.props, inputProps = _a.inputProps, noResults = _a.noResults, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["inputProps", "noResults", "popoverProps"]); | ||
var _a = this.props, inputProps = _a.inputProps, popoverProps = _a.popoverProps, restProps = tslib_1.__rest(_a, ["inputProps", "popoverProps"]); | ||
return (React.createElement(this.TypedQueryList, tslib_1.__assign({}, restProps, { activeItem: this.state.activeItem, onActiveItemChange: this.handleActiveItemChange, onItemSelect: this.handleItemSelect, query: this.state.query, ref: this.refHandlers.queryList, renderer: this.renderQueryList }))); | ||
@@ -170,7 +169,2 @@ }; | ||
}; | ||
Suggest.prototype.renderItems = function (_a) { | ||
var items = _a.items, renderItem = _a.renderItem; | ||
var renderedItems = items.map(renderItem).filter(function (item) { return item != null; }); | ||
return renderedItems.length > 0 ? renderedItems : this.props.noResults; | ||
}; | ||
Suggest.displayName = "Blueprint2.Suggest"; | ||
@@ -177,0 +171,0 @@ // Note: can't use <T> in static members, so this remains dynamically typed. |
@@ -1,4 +0,2 @@ | ||
export * from "./common/classes"; | ||
export * from "./common/itemRenderer"; | ||
export * from "./common/predicate"; | ||
export * from "./common"; | ||
export * from "./components"; |
@@ -6,3 +6,3 @@ /* | ||
*/ | ||
export * from "./common/classes"; | ||
export * from "./common"; | ||
export * from "./components"; |
{ | ||
"name": "@blueprintjs/select", | ||
"version": "2.0.0-rc.3", | ||
"version": "2.0.0-rc.4", | ||
"description": "Components related to selecting items from a list", | ||
@@ -20,2 +20,3 @@ "main": "lib/cjs/index.js", | ||
"dist:bundle": "cross-env NODE_ENV=production webpack", | ||
"dist:css": "css-dist lib/css/*.css", | ||
"dist:verify": "assert-package-layout", | ||
@@ -34,3 +35,3 @@ "lint": "npm-run-all -p lint:stylelint lint:tslint", | ||
"dependencies": { | ||
"@blueprintjs/core": "^2.0.0-rc.3", | ||
"@blueprintjs/core": "^2.0.0-rc.4", | ||
"classnames": "^2.2", | ||
@@ -37,0 +38,0 @@ "tslib": "^1.9.0" |
@@ -32,2 +32,5 @@ /* | ||
modifiers: IItemModifiers; | ||
/** The current query string used to filter the items. */ | ||
query: string; | ||
} | ||
@@ -34,0 +37,0 @@ |
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
@@ -7,0 +7,0 @@ /** |
@@ -47,3 +47,3 @@ @# Select | ||
The **@blueprintjs/select** package exports `ItemPredicate<T>` and `ItemListPredicate<T>` type aliases to simplify the process of implementing these functions. | ||
See the code sample in [Item Renderer API](#select/select-component.item-renderer-api) below for usage. | ||
See the code sample in [Item Renderer API](#select/select-component.item-renderer) below for usage. | ||
@@ -54,2 +54,10 @@ @### Non-ideal states | ||
@## Custom menu | ||
By default, `Select` renders the displayed items in a [`Menu`](#core/components/menu). This behavior can be overridden by providing the `itemListRenderer` prop, giving you full control over the layout of the items. For example, you can group items under a common heading, or render large data sets using [react-virtualized](https://github.com/bvaughn/react-virtualized). | ||
Note that the non-ideal states of `noResults` and `initialContent` are specific to the default renderer. If you provide the `itemListRenderer` prop, these props will be ignored. | ||
See the code sample in [Item List Renderer API](#select/select-component.item-list-renderer) below for usage. | ||
@## Controlled usage | ||
@@ -75,3 +83,3 @@ | ||
@### Item Renderer API | ||
@### Item renderer | ||
@@ -112,1 +120,32 @@ `Select`'s `itemRenderer` will be called for each item and receives the item and a props object containing data specific | ||
@interface IItemRendererProps | ||
@### Item list renderer | ||
If provided, the `itemListRenderer` prop will be called to render the contents of the dropdown menu. It has access to the items, the current query, and a `renderItem` callback for rendering a single item. A ref handler (`itemsParentRef`) is given as well; it should be attached to the parent element of the rendered menu items so that the currently selected item can be scrolled into view automatically. | ||
```tsx | ||
import { ItemListRenderer } from "@blueprintjs/select"; | ||
const renderMenu: ItemListRenderer<Film> = ({ items, itemsParentRef, query, renderItem }) => { | ||
const renderedItems = items.map(renderItem).filter(item => item != null); | ||
return ( | ||
<Menu ulRef={itemsParentRef}> | ||
<MenuItem | ||
disabled={true} | ||
text={`Found ${renderedItems.length} items matching "${query}"`} | ||
/> | ||
{renderedItems} | ||
</Menu> | ||
); | ||
}; | ||
<FilmSelect | ||
itemListRenderer={renderMenu} | ||
itemPredicate={filterFilm} | ||
itemRenderer={renderFilm} | ||
items={...} | ||
onItemSelect={...} | ||
/> | ||
``` | ||
@interface IItemListRendererProps |
@@ -7,5 +7,3 @@ /* | ||
export * from "./common/classes"; | ||
export * from "./common/itemRenderer"; | ||
export * from "./common/predicate"; | ||
export * from "./common"; | ||
export * from "./components"; |
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
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
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
84
241788
3986