@transferwise/components 40.8.3 → 40.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/build/es/no-polyfill/common/hooks/useConditionalListener/useConditionalListener.js +3 -12
- package/build/es/no-polyfill/select/Select.js +3 -3
- package/build/es/polyfill/common/hooks/useConditionalListener/useConditionalListener.js +3 -12
- package/build/es/polyfill/select/Select.js +3 -3
- package/build/types/common/commonProps.d.ts +1 -0
- package/build/types/common/hooks/useConditionalListener/useConditionalListener.d.ts +9 -1
- package/build/types/select/Select.d.ts +1 -0
- package/build/umd/no-polyfill/main.js +1 -1
- package/build/umd/polyfill/main.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [40.9.0](https://github.com/transferwise/neptune-web/compare/@transferwise/components@40.8.4...@transferwise/components@40.9.0) (2022-05-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **select:** expose buttonProps for select button ([#1443](https://github.com/transferwise/neptune-web/issues/1443)) ([9530c30](https://github.com/transferwise/neptune-web/commit/9530c306826527ec51ab15c3c8e1ab727b826eb4))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [40.8.4](https://github.com/transferwise/neptune-web/compare/@transferwise/components@40.8.3...@transferwise/components@40.8.4) (2022-05-05)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* types for `useConditionalListener` hooks ([#1437](https://github.com/transferwise/neptune-web/issues/1437)) ([f2ccb49](https://github.com/transferwise/neptune-web/commit/f2ccb492ea8624f01e077c3b2d001667c9deeb46))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [40.8.3](https://github.com/transferwise/neptune-web/compare/@transferwise/components@40.8.2...@transferwise/components@40.8.3) (2022-05-04)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @param {bool} attachListener - condition to be met for the listener to be attached
|
|
5
|
-
* @param {Function} callback - function registered with the event listener
|
|
6
|
-
* @param {string} eventType - type of event to attach to document
|
|
7
|
-
* @usage `useConditionalListener({
|
|
8
|
-
* eventType: 'click',
|
|
9
|
-
* callback,
|
|
10
|
-
* attachListener: condition,
|
|
11
|
-
* });`
|
|
12
|
-
*/export var useConditionalListener=function(a){var b=a.attachListener,c=a.callback,d=a.eventType,e=a.parent;useEffect(function(){return b&&!isUndefined(e)&&e.addEventListener(d,c,!0),function(){isUndefined(e)||e.removeEventListener(d,c,!0)}},[b])};
|
|
1
|
+
// @ts-expect-error remove this when `@transferwise/neptune-validation` provides types
|
|
2
|
+
import{isUndefined}from"@transferwise/neptune-validation";import{useEffect}from"react";export var useConditionalListener=function(a){var b=a.attachListener,c=a.callback,d=a.eventType,e=a.parent;useEffect(function(){return b&&// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
3
|
+
!isUndefined(e)&&e.addEventListener(d,c,!0),function(){isUndefined(e)||e.removeEventListener(d,c,!0)}},[b,c,d,e])};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _assertThisInitialized from"@babel/runtime/helpers/assertThisInitialized";import _inherits from"@babel/runtime/helpers/inherits";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _defineProperty from"@babel/runtime/helpers/defineProperty";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}import classNames from"classnames";import PropTypes from"prop-types";import{Component,createRef}from"react";import Transition from"react-transition-group/Transition";import Chevron from"../chevron";import{Breakpoint}from"../common";import{addClickClassToDocumentOnIos,removeClickClassFromDocumentOnIos}from"../common/domHelpers";import KeyCodes from"../common/keyCodes";import Dimmer from"../dimmer";import SlidingPanel from"../slidingPanel";import{addClassAndTriggerReflow,removeClass}from"./domHelpers";import Option from"./option";import SearchBox from"./searchBox";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";import{Fragment as _Fragment}from"react/jsx-runtime";function clamp(a,b,c){return Math.max(Math.min(b,c),a)}function actionableOption(a){return!a.header&&!a.separator&&!a.disabled}var isFunction=function(a){return a&&"[object Function]"==={}.toString.call(a)};function stopPropagation(a){a.stopPropagation(),a.preventDefault(),a.nativeEvent&&a.nativeEvent.stopImmediatePropagation&&a.nativeEvent.stopImmediatePropagation()}function getShouldRenderWithPortal(){return"undefined"!=typeof document&&"undefined"!=typeof window&&window.matchMedia&&window.matchMedia("(max-width: ".concat(Breakpoint.SMALL,"px)")).matches}var OPTIONS_PAGE_SIZE=100,BOOTSTRAP_DROPDOWN_ANIMATION_TIME=200,defer=function(a){return setTimeout(a,0)},includesString=function(a,b){return a.toLowerCase().includes(b.toLowerCase())},arrayIncludesString=function(a,b){return a.some(function(a){return includesString(a,b)})},defaultFilterFunction=function(a,b){return a.label&&includesString(a.label,b)||a.note&&includesString(a.note,b)||a.secondary&&includesString(a.secondary,b)||a.currency&&includesString(a.currency,b)||a.searchStrings&&arrayIncludesString(a.searchStrings,b)},Select=/*#__PURE__*/function(a){function b(a){var d;return _classCallCheck(this,b),d=c.call(this,a),_defineProperty(_assertThisInitialized(d),"handleResize",function(){d.setState({shouldRenderWithPortal:getShouldRenderWithPortal()})}),_defineProperty(_assertThisInitialized(d),"handleOnFocus",function(a){return d.props.onFocus&&d.props.onFocus(a)}),_defineProperty(_assertThisInitialized(d),"handleOnBlur",function(a){var b=d.props.onBlur,c=a.nativeEvent;if(c){var e=c.relatedTarget,f=a.currentTarget;if(f&&e&&f.contains(e))return}b&&b(a)}),_defineProperty(_assertThisInitialized(d),"getOptions",function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:d.props.options,b=d.props.search;if(!b||!d.state.searchValue)return a;var c=isFunction(b)?b:defaultFilterFunction;return a.filter(function(a){return c(a,d.state.searchValue)})}),_defineProperty(_assertThisInitialized(d),"handleSearchChange",function(a){d.setState({numberOfOptionsShown:OPTIONS_PAGE_SIZE}),d.props.onSearchChange?d.props.onSearchChange(a.target.value):d.setState({searchValue:a.target.value})}),_defineProperty(_assertThisInitialized(d),"handleKeyDown",function(a){var b=d.state.open;switch(a.keyCode){case KeyCodes.UP:b?d.moveFocusWithDifference(-1):d.open(),a.preventDefault();break;case KeyCodes.DOWN:b?d.moveFocusWithDifference(1):d.open(),a.preventDefault();break;case KeyCodes.SPACE:a.target!==d.searchBoxRef.current&&(b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault());break;case KeyCodes.ENTER:b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault();break;case KeyCodes.ESCAPE:d.close(),a.preventDefault();break;case KeyCodes.TAB:b&&d.selectKeyboardFocusedOption();break;default:}}),_defineProperty(_assertThisInitialized(d),"handleButtonClick",function(){d.props.disabled||d.open()}),_defineProperty(_assertThisInitialized(d),"handleDocumentClick",function(){d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"handleTouchStart",function(a){a.currentTarget===a.target&&d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"style",function(a){return d.props.classNames[a]||a}),_defineProperty(_assertThisInitialized(d),"renderOption",function(a,b){var c;if(a.separator)return/*#__PURE__*/_jsx("li",{className:d.style("divider")},b);if(a.header)return/*#__PURE__*/_jsx("li",{className:d.style("dropdown-header"),onClick:stopPropagation,onKeyPress:stopPropagation,children:a.header},b);var e=d.props.selected&&d.props.selected.value===a.value,f=d.state.keyboardFocusedOptionIndex===d.getIndexWithoutHeadersForIndexWithHeaders(b),g=classNames(d.style("tw-dropdown-item"),d.style("tw-dropdown-item--clickable"),(c={},_defineProperty(c,d.style("active"),e),_defineProperty(c,d.style("tw-dropdown-item--focused"),f&&!a.disabled),_defineProperty(c,d.style("disabled"),a.disabled),c));return/*#__PURE__*/_jsx("li",{className:g,onClick:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),onKeyPress:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),children:/*#__PURE__*/_jsx("a",{disabled:a.disabled,children:/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},a),{},{classNames:d.props.classNames}))})},b)}),d.state={open:!1,searchValue:"",keyboardFocusedOptionIndex:null,numberOfOptionsShown:OPTIONS_PAGE_SIZE},d.searchBoxRef=/*#__PURE__*/createRef(),d.dropdownMenuRef=/*#__PURE__*/createRef(),d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"componentDidMount",value:function componentDidMount(){this.setState({shouldRenderWithPortal:getShouldRenderWithPortal()}),window.addEventListener("resize",this.handleResize)}},{key:"componentWillUnmount",value:function componentWillUnmount(){this.close(),window.removeEventListener("resize",this.handleResize)}},{key:"getIndexWithoutHeadersForIndexWithHeaders",value:function getIndexWithoutHeadersForIndexWithHeaders(a){return this.getOptions().reduce(function(b,c,d){return d<a&&actionableOption(c)?b+1:b},0)}},{key:"selectKeyboardFocusedOption",value:function selectKeyboardFocusedOption(){if(null!==this.state.keyboardFocusedOptionIndex){var a=this.state.keyboardFocusedOptionIndex;this.selectOption(this.getOptions().filter(actionableOption)[a])}}},{key:"moveFocusWithDifference",value:function moveFocusWithDifference(a){var b=this;this.setState(function(c,d){var e=b.getOptions(d.options).filter(actionableOption),f=e.reduce(function(a,b,c){return null===a?d.selected&&d.selected.value===b.value?c:null:a},null),g=c.keyboardFocusedOptionIndex,h=g;if(null===g&&null===f)return{keyboardFocusedOptionIndex:0};null===g&&null!==f&&(h=f);var i=h+a,j=clamp(0,e.length-1,i);return{keyboardFocusedOptionIndex:j}})}},{key:"open",value:function open(){var a=this;this.setState({open:!0},function(){var b="undefined"!=typeof window&&window.matchMedia&&!!window.matchMedia("(pointer: coarse)").matches,c=!!a.props.onSearchChange||!!a.props.search;defer(function(){!b&&c&&a.searchBoxRef.current&&a.searchBoxRef.current.focus(),addClickClassToDocumentOnIos(),document.addEventListener("click",a.handleDocumentClick,!1)})})}},{key:"close",value:function close(){var a=this;this.setState({open:!1,keyboardFocusedOptionIndex:null},function(){defer(function(){removeClickClassFromDocumentOnIos(),document.removeEventListener("click",a.handleDocumentClick,!1)})})}},{key:"createSelectHandlerForOption",value:function createSelectHandlerForOption(a){var b=this;return function(c){stopPropagation(c),b.selectOption(a)}}},{key:"selectOption",value:function selectOption(a){a&&!a.placeholder?this.props.onChange(a):this.props.onChange(null),this.close()}},{key:"renderOptionsList",value:function renderOptionsList(){var a,b=this.props,c=b.dropdownRight,d=b.dropdownWidth,e=b.onSearchChange,f=b.placeholder,g=b.required,h=b.search,i=b.searchValue,j=b.searchPlaceholder,k=this.state.open,l=this.style,m=!!e||!!h,n=classNames(l("tw-select"),l("dropdown-menu"),(a={},_defineProperty(a,l("dropdown-menu-".concat(c,"-right")),c),_defineProperty(a,l("dropdown-menu-".concat(d)),d),_defineProperty(a,l("dropdown-menu--open"),k),a));return/*#__PURE__*/_jsxs("ul",{className:n,children:[g||m||!f?"":this.renderPlaceHolderOption(),m&&/*#__PURE__*/_jsx(SearchBox,{ref:this.searchBoxRef,classNames:this.props.classNames,value:i||this.state.searchValue,placeholder:j,onChange:this.handleSearchChange,onClick:stopPropagation}),this.renderOptions(),this.state.numberOfOptionsShown<this.getOptions().length?this.renderShowMore():""]})}},{key:"renderOptions",value:function renderOptions(){return this.getOptions().slice(0,this.state.numberOfOptionsShown).map(this.renderOption)}},{key:"renderShowMore",value:function renderShowMore(){return/*#__PURE__*/ (/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider"),this.style("show-more")),onClick:this.showMore.bind(this),onKeyPress:this.showMore.bind(this),children:/*#__PURE__*/_jsx("a",{children:"..."})}))}},{key:"showMore",value:function showMore(a){stopPropagation(a),this.setState(function(a){return{numberOfOptionsShown:a.numberOfOptionsShown+OPTIONS_PAGE_SIZE}})}},{key:"renderPlaceHolderOption",value:function renderPlaceHolderOption(){var a=this.props.placeholder;return/*#__PURE__*/_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider")),onClick:this.createSelectHandlerForOption({placeholder:a}),onKeyPress:this.createSelectHandlerForOption({placeholder:a}),children:/*#__PURE__*/_jsx("a",{children:a})})}},{key:"renderButtonInternals",value:function renderButtonInternals(){var a=this.props,b=a.selected,c=a.placeholder;return b?/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},b),{},{classNames:this.props.classNames,selected:!0})):/*#__PURE__*/_jsx("span",{className:this.style("form-control-placeholder"),children:c})}},{key:"render",value:function render(){var a,b,c=this,d=this.props,e=d.disabled,f=d.size,g=d.block,h=d.id,i=d.dropdownUp,j=d.inverse,k=this.state,l=k.open,m=k.shouldRenderWithPortal,n=this.style,o=classNames(n("tw-select"),n("btn-group"),(a={},_defineProperty(a,n("btn-block"),g),_defineProperty(a,n("dropup"),i),_defineProperty(a,n("dropdown"),!i),a)),p=classNames(n("btn"),n("btn-input"),(b={},_defineProperty(b,"".concat(n("btn-input-inverse")," ").concat(n("btn-addon")),j),_defineProperty(b,n("btn-xs"),"xs"===f),_defineProperty(b,n("btn-sm"),"sm"===f),_defineProperty(b,n("btn-md"),"md"===f),_defineProperty(b,n("btn-lg"),"lg"===f),b),n("dropdown-toggle")),q=n("open");return/*#__PURE__*/ (// A transition is used here in order to mount and unmount the dropdown menu while retaining animations
|
|
1
|
+
import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _assertThisInitialized from"@babel/runtime/helpers/assertThisInitialized";import _inherits from"@babel/runtime/helpers/inherits";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _defineProperty from"@babel/runtime/helpers/defineProperty";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}import classNames from"classnames";import PropTypes from"prop-types";import{Component,createRef}from"react";import Transition from"react-transition-group/Transition";import Chevron from"../chevron";import{Breakpoint}from"../common";import{addClickClassToDocumentOnIos,removeClickClassFromDocumentOnIos}from"../common/domHelpers";import KeyCodes from"../common/keyCodes";import Dimmer from"../dimmer";import SlidingPanel from"../slidingPanel";import{addClassAndTriggerReflow,removeClass}from"./domHelpers";import Option from"./option";import SearchBox from"./searchBox";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";import{Fragment as _Fragment}from"react/jsx-runtime";function clamp(a,b,c){return Math.max(Math.min(b,c),a)}function actionableOption(a){return!a.header&&!a.separator&&!a.disabled}var isFunction=function(a){return a&&"[object Function]"==={}.toString.call(a)};function stopPropagation(a){a.stopPropagation(),a.preventDefault(),a.nativeEvent&&a.nativeEvent.stopImmediatePropagation&&a.nativeEvent.stopImmediatePropagation()}function getShouldRenderWithPortal(){return"undefined"!=typeof document&&"undefined"!=typeof window&&window.matchMedia&&window.matchMedia("(max-width: ".concat(Breakpoint.SMALL,"px)")).matches}var OPTIONS_PAGE_SIZE=100,BOOTSTRAP_DROPDOWN_ANIMATION_TIME=200,defer=function(a){return setTimeout(a,0)},includesString=function(a,b){return a.toLowerCase().includes(b.toLowerCase())},arrayIncludesString=function(a,b){return a.some(function(a){return includesString(a,b)})},defaultFilterFunction=function(a,b){return a.label&&includesString(a.label,b)||a.note&&includesString(a.note,b)||a.secondary&&includesString(a.secondary,b)||a.currency&&includesString(a.currency,b)||a.searchStrings&&arrayIncludesString(a.searchStrings,b)},Select=/*#__PURE__*/function(a){function b(a){var d;return _classCallCheck(this,b),d=c.call(this,a),_defineProperty(_assertThisInitialized(d),"handleResize",function(){d.setState({shouldRenderWithPortal:getShouldRenderWithPortal()})}),_defineProperty(_assertThisInitialized(d),"handleOnFocus",function(a){return d.props.onFocus&&d.props.onFocus(a)}),_defineProperty(_assertThisInitialized(d),"handleOnBlur",function(a){var b=d.props.onBlur,c=a.nativeEvent;if(c){var e=c.relatedTarget,f=a.currentTarget;if(f&&e&&f.contains(e))return}b&&b(a)}),_defineProperty(_assertThisInitialized(d),"getOptions",function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:d.props.options,b=d.props.search;if(!b||!d.state.searchValue)return a;var c=isFunction(b)?b:defaultFilterFunction;return a.filter(function(a){return c(a,d.state.searchValue)})}),_defineProperty(_assertThisInitialized(d),"handleSearchChange",function(a){d.setState({numberOfOptionsShown:OPTIONS_PAGE_SIZE}),d.props.onSearchChange?d.props.onSearchChange(a.target.value):d.setState({searchValue:a.target.value})}),_defineProperty(_assertThisInitialized(d),"handleKeyDown",function(a){var b=d.state.open;switch(a.keyCode){case KeyCodes.UP:b?d.moveFocusWithDifference(-1):d.open(),a.preventDefault();break;case KeyCodes.DOWN:b?d.moveFocusWithDifference(1):d.open(),a.preventDefault();break;case KeyCodes.SPACE:a.target!==d.searchBoxRef.current&&(b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault());break;case KeyCodes.ENTER:b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault();break;case KeyCodes.ESCAPE:d.close(),a.preventDefault();break;case KeyCodes.TAB:b&&d.selectKeyboardFocusedOption();break;default:}}),_defineProperty(_assertThisInitialized(d),"handleButtonClick",function(){d.props.disabled||d.open()}),_defineProperty(_assertThisInitialized(d),"handleDocumentClick",function(){d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"handleTouchStart",function(a){a.currentTarget===a.target&&d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"style",function(a){return d.props.classNames[a]||a}),_defineProperty(_assertThisInitialized(d),"renderOption",function(a,b){var c;if(a.separator)return/*#__PURE__*/_jsx("li",{className:d.style("divider")},b);if(a.header)return/*#__PURE__*/_jsx("li",{className:d.style("dropdown-header"),onClick:stopPropagation,onKeyPress:stopPropagation,children:a.header},b);var e=d.props.selected&&d.props.selected.value===a.value,f=d.state.keyboardFocusedOptionIndex===d.getIndexWithoutHeadersForIndexWithHeaders(b),g=classNames(d.style("tw-dropdown-item"),d.style("tw-dropdown-item--clickable"),(c={},_defineProperty(c,d.style("active"),e),_defineProperty(c,d.style("tw-dropdown-item--focused"),f&&!a.disabled),_defineProperty(c,d.style("disabled"),a.disabled),c));return/*#__PURE__*/_jsx("li",{className:g,onClick:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),onKeyPress:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),children:/*#__PURE__*/_jsx("a",{disabled:a.disabled,children:/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},a),{},{classNames:d.props.classNames}))})},b)}),d.state={open:!1,searchValue:"",keyboardFocusedOptionIndex:null,numberOfOptionsShown:OPTIONS_PAGE_SIZE},d.searchBoxRef=/*#__PURE__*/createRef(),d.dropdownMenuRef=/*#__PURE__*/createRef(),d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"componentDidMount",value:function componentDidMount(){this.setState({shouldRenderWithPortal:getShouldRenderWithPortal()}),window.addEventListener("resize",this.handleResize)}},{key:"componentWillUnmount",value:function componentWillUnmount(){this.close(),window.removeEventListener("resize",this.handleResize)}},{key:"getIndexWithoutHeadersForIndexWithHeaders",value:function getIndexWithoutHeadersForIndexWithHeaders(a){return this.getOptions().reduce(function(b,c,d){return d<a&&actionableOption(c)?b+1:b},0)}},{key:"selectKeyboardFocusedOption",value:function selectKeyboardFocusedOption(){if(null!==this.state.keyboardFocusedOptionIndex){var a=this.state.keyboardFocusedOptionIndex;this.selectOption(this.getOptions().filter(actionableOption)[a])}}},{key:"moveFocusWithDifference",value:function moveFocusWithDifference(a){var b=this;this.setState(function(c,d){var e=b.getOptions(d.options).filter(actionableOption),f=e.reduce(function(a,b,c){return null===a?d.selected&&d.selected.value===b.value?c:null:a},null),g=c.keyboardFocusedOptionIndex,h=g;if(null===g&&null===f)return{keyboardFocusedOptionIndex:0};null===g&&null!==f&&(h=f);var i=h+a,j=clamp(0,e.length-1,i);return{keyboardFocusedOptionIndex:j}})}},{key:"open",value:function open(){var a=this;this.setState({open:!0},function(){var b="undefined"!=typeof window&&window.matchMedia&&!!window.matchMedia("(pointer: coarse)").matches,c=!!a.props.onSearchChange||!!a.props.search;defer(function(){!b&&c&&a.searchBoxRef.current&&a.searchBoxRef.current.focus(),addClickClassToDocumentOnIos(),document.addEventListener("click",a.handleDocumentClick,!1)})})}},{key:"close",value:function close(){var a=this;this.setState({open:!1,keyboardFocusedOptionIndex:null},function(){defer(function(){removeClickClassFromDocumentOnIos(),document.removeEventListener("click",a.handleDocumentClick,!1)})})}},{key:"createSelectHandlerForOption",value:function createSelectHandlerForOption(a){var b=this;return function(c){stopPropagation(c),b.selectOption(a)}}},{key:"selectOption",value:function selectOption(a){a&&!a.placeholder?this.props.onChange(a):this.props.onChange(null),this.close()}},{key:"renderOptionsList",value:function renderOptionsList(){var a,b=this.props,c=b.dropdownRight,d=b.dropdownWidth,e=b.id,f=b.onSearchChange,g=b.placeholder,h=b.required,i=b.search,j=b.searchValue,k=b.searchPlaceholder,l=this.state.open,m=this.style,n=!!f||!!i,o=classNames(m("tw-select"),m("dropdown-menu"),(a={},_defineProperty(a,m("dropdown-menu-".concat(c,"-right")),c),_defineProperty(a,m("dropdown-menu-".concat(d)),d),_defineProperty(a,m("dropdown-menu--open"),l),a));return/*#__PURE__*/_jsxs("ul",{className:o,"aria-labelledby":e,children:[h||n||!g?"":this.renderPlaceHolderOption(),n&&/*#__PURE__*/_jsx(SearchBox,{ref:this.searchBoxRef,classNames:this.props.classNames,value:j||this.state.searchValue,placeholder:k,onChange:this.handleSearchChange,onClick:stopPropagation}),this.renderOptions(),this.state.numberOfOptionsShown<this.getOptions().length?this.renderShowMore():""]})}},{key:"renderOptions",value:function renderOptions(){return this.getOptions().slice(0,this.state.numberOfOptionsShown).map(this.renderOption)}},{key:"renderShowMore",value:function renderShowMore(){return/*#__PURE__*/ (/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider"),this.style("show-more")),onClick:this.showMore.bind(this),onKeyPress:this.showMore.bind(this),children:/*#__PURE__*/_jsx("a",{children:"..."})}))}},{key:"showMore",value:function showMore(a){stopPropagation(a),this.setState(function(a){return{numberOfOptionsShown:a.numberOfOptionsShown+OPTIONS_PAGE_SIZE}})}},{key:"renderPlaceHolderOption",value:function renderPlaceHolderOption(){var a=this.props.placeholder;return/*#__PURE__*/_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider")),onClick:this.createSelectHandlerForOption({placeholder:a}),onKeyPress:this.createSelectHandlerForOption({placeholder:a}),children:/*#__PURE__*/_jsx("a",{children:a})})}},{key:"renderButtonInternals",value:function renderButtonInternals(){var a=this.props,b=a.selected,c=a.placeholder;return b?/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},b),{},{classNames:this.props.classNames,selected:!0})):/*#__PURE__*/_jsx("span",{className:this.style("form-control-placeholder"),children:c})}},{key:"render",value:function render(){var a,b,c=this,d=this.props,e=d.disabled,f=d.size,g=d.block,h=d.id,i=d.dropdownUp,j=d.inverse,k=d.buttonProps,l=this.state,m=l.open,n=l.shouldRenderWithPortal,o=this.style,p=classNames(o("tw-select"),o("btn-group"),(a={},_defineProperty(a,o("btn-block"),g),_defineProperty(a,o("dropup"),i),_defineProperty(a,o("dropdown"),!i),a)),q=classNames(o("btn"),o("btn-input"),(b={},_defineProperty(b,"".concat(o("btn-input-inverse")," ").concat(o("btn-addon")),j),_defineProperty(b,o("btn-xs"),"xs"===f),_defineProperty(b,o("btn-sm"),"sm"===f),_defineProperty(b,o("btn-md"),"md"===f),_defineProperty(b,o("btn-lg"),"lg"===f),b),o("dropdown-toggle")),r=o("open");return/*#__PURE__*/ (// A transition is used here in order to mount and unmount the dropdown menu while retaining animations
|
|
2
2
|
_jsx(_Fragment,{children:/*#__PURE__*/_jsxs("div",{// eslint-disable-line jsx-a11y/no-static-element-interactions
|
|
3
|
-
ref:this.dropdownMenuRef,className:
|
|
3
|
+
ref:this.dropdownMenuRef,className:p,onKeyDown:this.handleKeyDown,onTouchMove:this.handleTouchStart,onFocus:this.handleOnFocus,onBlur:this.handleOnBlur,children:[/*#__PURE__*/_jsxs("button",_objectSpread(_objectSpread({disabled:e,className:q,type:"button",id:h,"aria-expanded":m,onClick:this.handleButtonClick},k),{},{children:[this.renderButtonInternals(),/*#__PURE__*/_jsx(Chevron,{disabled:e,className:"".concat(o("tw-icon")," ").concat(o("tw-chevron-up-icon")," ").concat(o("tw-chevron")," ").concat(o("bottom")," ").concat(o("tw-select-chevron"))})]})),n?/*#__PURE__*/_jsx(Dimmer,{open:m,children:/*#__PURE__*/_jsx(SlidingPanel,{open:m,position:"bottom",children:this.renderOptionsList()})}):/*#__PURE__*/_jsx(Transition,{in:m,timeout:BOOTSTRAP_DROPDOWN_ANIMATION_TIME,onEntering:function onEntering(){c.dropdownMenuRef.current&&addClassAndTriggerReflow(c.dropdownMenuRef.current,r)},onExit:function onExit(){c.dropdownMenuRef.current&&removeClass(c.dropdownMenuRef.current,r)},children:function children(a){return"exited"!==a&&c.renderOptionsList()}})]})}))}}],[{key:"getDerivedStateFromProps",value:function getDerivedStateFromProps(a,b){var c=!!a.options.length;if(b.open&&(""!==a.searchValue||""!==b.searchValue)){if(c&&null===b.keyboardFocusedOptionIndex)return{keyboardFocusedOptionIndex:0};if(!c&&null!==b.keyboardFocusedOptionIndex)return{keyboardFocusedOptionIndex:null}}return null}}]),b}(Component);export{Select as default};Select.propTypes={placeholder:PropTypes.string,id:PropTypes.string,required:PropTypes.bool,disabled:PropTypes.bool,inverse:PropTypes.bool,dropdownRight:PropTypes.oneOf(["xs","sm","md","lg","xl"]),dropdownWidth:PropTypes.oneOf(["sm","md","lg"]),size:PropTypes.oneOf(["sm","md","lg"]),block:PropTypes.bool,selected:PropTypes.shape({value:PropTypes.any.isRequired,label:PropTypes.node,icon:PropTypes.node,currency:PropTypes.string,note:PropTypes.node,secondary:PropTypes.node}),/**
|
|
4
4
|
* Search toggle
|
|
5
5
|
* if `true` default search functionality being enabled (not case sensitive search in option labels & currency props)
|
|
6
6
|
* if `function` you can define your own search function to implement custom search experience. This search function used while filtering the options array. The custom search function takes two parameters. First is the option the second is the keyword.
|
|
7
7
|
*/search:PropTypes.oneOfType([PropTypes.bool,PropTypes.func]),onChange:PropTypes.func.isRequired,onFocus:PropTypes.func,onBlur:PropTypes.func,options:PropTypes.arrayOf(PropTypes.shape({value:PropTypes.any,label:PropTypes.node,header:PropTypes.node,icon:PropTypes.node,currency:PropTypes.string,note:PropTypes.node,secondary:PropTypes.node,separator:PropTypes.bool,disabled:PropTypes.bool,searchStrings:PropTypes.arrayOf(PropTypes.string)})).isRequired,/**
|
|
8
8
|
* To have full control of your search value and response use `onSearchChange` function combined with `searchValue` and custom filtering on the options array.
|
|
9
9
|
* DO NOT USE TOGETHER WITH `search` PROPERTY
|
|
10
|
-
*/onSearchChange:PropTypes.func,searchValue:PropTypes.string,searchPlaceholder:PropTypes.string,classNames:PropTypes.objectOf(PropTypes.string),dropdownUp:PropTypes.bool},Select.defaultProps={id:void 0,placeholder:void 0,size:"md",dropdownRight:null,dropdownWidth:null,inverse:!1,required:!1,disabled:!1,block:!0,selected:null,onFocus:null,onBlur:null,onSearchChange:void 0,search:!1,searchValue:"",searchPlaceholder:"Search...",classNames:{},dropdownUp:!1};
|
|
10
|
+
*/onSearchChange:PropTypes.func,searchValue:PropTypes.string,searchPlaceholder:PropTypes.string,classNames:PropTypes.objectOf(PropTypes.string),dropdownUp:PropTypes.bool,buttonProps:PropTypes.object},Select.defaultProps={id:void 0,placeholder:void 0,size:"md",dropdownRight:null,dropdownWidth:null,inverse:!1,required:!1,disabled:!1,block:!0,selected:null,onFocus:null,onBlur:null,onSearchChange:void 0,search:!1,searchValue:"",searchPlaceholder:"Search...",classNames:{},dropdownUp:!1,buttonProps:{}};
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @param {bool} attachListener - condition to be met for the listener to be attached
|
|
5
|
-
* @param {Function} callback - function registered with the event listener
|
|
6
|
-
* @param {string} eventType - type of event to attach to document
|
|
7
|
-
* @usage `useConditionalListener({
|
|
8
|
-
* eventType: 'click',
|
|
9
|
-
* callback,
|
|
10
|
-
* attachListener: condition,
|
|
11
|
-
* });`
|
|
12
|
-
*/export var useConditionalListener=function(a){var b=a.attachListener,c=a.callback,d=a.eventType,e=a.parent;useEffect(function(){return b&&!isUndefined(e)&&e.addEventListener(d,c,!0),function(){isUndefined(e)||e.removeEventListener(d,c,!0)}},[b])};
|
|
1
|
+
// @ts-expect-error remove this when `@transferwise/neptune-validation` provides types
|
|
2
|
+
import{isUndefined}from"@transferwise/neptune-validation";import{useEffect}from"react";export var useConditionalListener=function(a){var b=a.attachListener,c=a.callback,d=a.eventType,e=a.parent;useEffect(function(){return b&&// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
3
|
+
!isUndefined(e)&&e.addEventListener(d,c,!0),function(){isUndefined(e)||e.removeEventListener(d,c,!0)}},[b,c,d,e])};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _assertThisInitialized from"@babel/runtime/helpers/assertThisInitialized";import _inherits from"@babel/runtime/helpers/inherits";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _defineProperty from"@babel/runtime/helpers/defineProperty";import"core-js/modules/es.reflect.construct.js";import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.array.includes.js";import"core-js/modules/es.string.includes.js";import"core-js/modules/es.regexp.exec.js";import"core-js/modules/es.string.search.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/es.array.reduce.js";import"core-js/modules/es.array.map.js";import"core-js/modules/es.array.slice.js";import"core-js/modules/es.array.concat.js";import classNames from"classnames";import PropTypes from"prop-types";import{Component,createRef}from"react";import Transition from"react-transition-group/Transition";import Chevron from"../chevron";import{Breakpoint}from"../common";import{addClickClassToDocumentOnIos,removeClickClassFromDocumentOnIos}from"../common/domHelpers";import KeyCodes from"../common/keyCodes";import Dimmer from"../dimmer";import SlidingPanel from"../slidingPanel";import{addClassAndTriggerReflow,removeClass}from"./domHelpers";import Option from"./option";import SearchBox from"./searchBox";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";import{Fragment as _Fragment}from"react/jsx-runtime";function clamp(a,b,c){return Math.max(Math.min(b,c),a)}function actionableOption(a){return!a.header&&!a.separator&&!a.disabled}var isFunction=function(a){return a&&"[object Function]"==={}.toString.call(a)};function stopPropagation(a){a.stopPropagation(),a.preventDefault(),a.nativeEvent&&a.nativeEvent.stopImmediatePropagation&&a.nativeEvent.stopImmediatePropagation()}function getShouldRenderWithPortal(){return"undefined"!=typeof document&&"undefined"!=typeof window&&window.matchMedia&&window.matchMedia("(max-width: ".concat(Breakpoint.SMALL,"px)")).matches}var OPTIONS_PAGE_SIZE=100,BOOTSTRAP_DROPDOWN_ANIMATION_TIME=200,defer=function(a){return setTimeout(a,0)},includesString=function(a,b){return a.toLowerCase().includes(b.toLowerCase())},arrayIncludesString=function(a,b){return a.some(function(a){return includesString(a,b)})},defaultFilterFunction=function(a,b){return a.label&&includesString(a.label,b)||a.note&&includesString(a.note,b)||a.secondary&&includesString(a.secondary,b)||a.currency&&includesString(a.currency,b)||a.searchStrings&&arrayIncludesString(a.searchStrings,b)},Select=/*#__PURE__*/function(a){function b(a){var d;return _classCallCheck(this,b),d=c.call(this,a),_defineProperty(_assertThisInitialized(d),"handleResize",function(){d.setState({shouldRenderWithPortal:getShouldRenderWithPortal()})}),_defineProperty(_assertThisInitialized(d),"handleOnFocus",function(a){return d.props.onFocus&&d.props.onFocus(a)}),_defineProperty(_assertThisInitialized(d),"handleOnBlur",function(a){var b=d.props.onBlur,c=a.nativeEvent;if(c){var e=c.relatedTarget,f=a.currentTarget;if(f&&e&&f.contains(e))return}b&&b(a)}),_defineProperty(_assertThisInitialized(d),"getOptions",function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:d.props.options,b=d.props.search;if(!b||!d.state.searchValue)return a;var c=isFunction(b)?b:defaultFilterFunction;return a.filter(function(a){return c(a,d.state.searchValue)})}),_defineProperty(_assertThisInitialized(d),"handleSearchChange",function(a){d.setState({numberOfOptionsShown:OPTIONS_PAGE_SIZE}),d.props.onSearchChange?d.props.onSearchChange(a.target.value):d.setState({searchValue:a.target.value})}),_defineProperty(_assertThisInitialized(d),"handleKeyDown",function(a){var b=d.state.open;switch(a.keyCode){case KeyCodes.UP:b?d.moveFocusWithDifference(-1):d.open(),a.preventDefault();break;case KeyCodes.DOWN:b?d.moveFocusWithDifference(1):d.open(),a.preventDefault();break;case KeyCodes.SPACE:a.target!==d.searchBoxRef.current&&(b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault());break;case KeyCodes.ENTER:b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault();break;case KeyCodes.ESCAPE:d.close(),a.preventDefault();break;case KeyCodes.TAB:b&&d.selectKeyboardFocusedOption();break;default:}}),_defineProperty(_assertThisInitialized(d),"handleButtonClick",function(){d.props.disabled||d.open()}),_defineProperty(_assertThisInitialized(d),"handleDocumentClick",function(){d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"handleTouchStart",function(a){a.currentTarget===a.target&&d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"style",function(a){return d.props.classNames[a]||a}),_defineProperty(_assertThisInitialized(d),"renderOption",function(a,b){var c;if(a.separator)return/*#__PURE__*/_jsx("li",{className:d.style("divider")},b);if(a.header)return/*#__PURE__*/_jsx("li",{className:d.style("dropdown-header"),onClick:stopPropagation,onKeyPress:stopPropagation,children:a.header},b);var e=d.props.selected&&d.props.selected.value===a.value,f=d.state.keyboardFocusedOptionIndex===d.getIndexWithoutHeadersForIndexWithHeaders(b),g=classNames(d.style("tw-dropdown-item"),d.style("tw-dropdown-item--clickable"),(c={},_defineProperty(c,d.style("active"),e),_defineProperty(c,d.style("tw-dropdown-item--focused"),f&&!a.disabled),_defineProperty(c,d.style("disabled"),a.disabled),c));return/*#__PURE__*/_jsx("li",{className:g,onClick:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),onKeyPress:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),children:/*#__PURE__*/_jsx("a",{disabled:a.disabled,children:/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},a),{},{classNames:d.props.classNames}))})},b)}),d.state={open:!1,searchValue:"",keyboardFocusedOptionIndex:null,numberOfOptionsShown:OPTIONS_PAGE_SIZE},d.searchBoxRef=/*#__PURE__*/createRef(),d.dropdownMenuRef=/*#__PURE__*/createRef(),d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"componentDidMount",value:function componentDidMount(){this.setState({shouldRenderWithPortal:getShouldRenderWithPortal()}),window.addEventListener("resize",this.handleResize)}},{key:"componentWillUnmount",value:function componentWillUnmount(){this.close(),window.removeEventListener("resize",this.handleResize)}},{key:"getIndexWithoutHeadersForIndexWithHeaders",value:function getIndexWithoutHeadersForIndexWithHeaders(a){return this.getOptions().reduce(function(b,c,d){return d<a&&actionableOption(c)?b+1:b},0)}},{key:"selectKeyboardFocusedOption",value:function selectKeyboardFocusedOption(){if(null!==this.state.keyboardFocusedOptionIndex){var a=this.state.keyboardFocusedOptionIndex;this.selectOption(this.getOptions().filter(actionableOption)[a])}}},{key:"moveFocusWithDifference",value:function moveFocusWithDifference(a){var b=this;this.setState(function(c,d){var e=b.getOptions(d.options).filter(actionableOption),f=e.reduce(function(a,b,c){return null===a?d.selected&&d.selected.value===b.value?c:null:a},null),g=c.keyboardFocusedOptionIndex,h=g;if(null===g&&null===f)return{keyboardFocusedOptionIndex:0};null===g&&null!==f&&(h=f);var i=h+a,j=clamp(0,e.length-1,i);return{keyboardFocusedOptionIndex:j}})}},{key:"open",value:function open(){var a=this;this.setState({open:!0},function(){var b="undefined"!=typeof window&&window.matchMedia&&!!window.matchMedia("(pointer: coarse)").matches,c=!!a.props.onSearchChange||!!a.props.search;defer(function(){!b&&c&&a.searchBoxRef.current&&a.searchBoxRef.current.focus(),addClickClassToDocumentOnIos(),document.addEventListener("click",a.handleDocumentClick,!1)})})}},{key:"close",value:function close(){var a=this;this.setState({open:!1,keyboardFocusedOptionIndex:null},function(){defer(function(){removeClickClassFromDocumentOnIos(),document.removeEventListener("click",a.handleDocumentClick,!1)})})}},{key:"createSelectHandlerForOption",value:function createSelectHandlerForOption(a){var b=this;return function(c){stopPropagation(c),b.selectOption(a)}}},{key:"selectOption",value:function selectOption(a){a&&!a.placeholder?this.props.onChange(a):this.props.onChange(null),this.close()}},{key:"renderOptionsList",value:function renderOptionsList(){var a,b=this.props,c=b.dropdownRight,d=b.dropdownWidth,e=b.onSearchChange,f=b.placeholder,g=b.required,h=b.search,i=b.searchValue,j=b.searchPlaceholder,k=this.state.open,l=this.style,m=!!e||!!h,n=classNames(l("tw-select"),l("dropdown-menu"),(a={},_defineProperty(a,l("dropdown-menu-".concat(c,"-right")),c),_defineProperty(a,l("dropdown-menu-".concat(d)),d),_defineProperty(a,l("dropdown-menu--open"),k),a));return/*#__PURE__*/_jsxs("ul",{className:n,children:[g||m||!f?"":this.renderPlaceHolderOption(),m&&/*#__PURE__*/_jsx(SearchBox,{ref:this.searchBoxRef,classNames:this.props.classNames,value:i||this.state.searchValue,placeholder:j,onChange:this.handleSearchChange,onClick:stopPropagation}),this.renderOptions(),this.state.numberOfOptionsShown<this.getOptions().length?this.renderShowMore():""]})}},{key:"renderOptions",value:function renderOptions(){return this.getOptions().slice(0,this.state.numberOfOptionsShown).map(this.renderOption)}},{key:"renderShowMore",value:function renderShowMore(){return/*#__PURE__*/ (/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider"),this.style("show-more")),onClick:this.showMore.bind(this),onKeyPress:this.showMore.bind(this),children:/*#__PURE__*/_jsx("a",{children:"..."})}))}},{key:"showMore",value:function showMore(a){stopPropagation(a),this.setState(function(a){return{numberOfOptionsShown:a.numberOfOptionsShown+OPTIONS_PAGE_SIZE}})}},{key:"renderPlaceHolderOption",value:function renderPlaceHolderOption(){var a=this.props.placeholder;return/*#__PURE__*/_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider")),onClick:this.createSelectHandlerForOption({placeholder:a}),onKeyPress:this.createSelectHandlerForOption({placeholder:a}),children:/*#__PURE__*/_jsx("a",{children:a})})}},{key:"renderButtonInternals",value:function renderButtonInternals(){var a=this.props,b=a.selected,c=a.placeholder;return b?/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},b),{},{classNames:this.props.classNames,selected:!0})):/*#__PURE__*/_jsx("span",{className:this.style("form-control-placeholder"),children:c})}},{key:"render",value:function render(){var a,b,c=this,d=this.props,e=d.disabled,f=d.size,g=d.block,h=d.id,i=d.dropdownUp,j=d.inverse,k=this.state,l=k.open,m=k.shouldRenderWithPortal,n=this.style,o=classNames(n("tw-select"),n("btn-group"),(a={},_defineProperty(a,n("btn-block"),g),_defineProperty(a,n("dropup"),i),_defineProperty(a,n("dropdown"),!i),a)),p=classNames(n("btn"),n("btn-input"),(b={},_defineProperty(b,"".concat(n("btn-input-inverse")," ").concat(n("btn-addon")),j),_defineProperty(b,n("btn-xs"),"xs"===f),_defineProperty(b,n("btn-sm"),"sm"===f),_defineProperty(b,n("btn-md"),"md"===f),_defineProperty(b,n("btn-lg"),"lg"===f),b),n("dropdown-toggle")),q=n("open");return/*#__PURE__*/ (// A transition is used here in order to mount and unmount the dropdown menu while retaining animations
|
|
1
|
+
import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _assertThisInitialized from"@babel/runtime/helpers/assertThisInitialized";import _inherits from"@babel/runtime/helpers/inherits";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _defineProperty from"@babel/runtime/helpers/defineProperty";import"core-js/modules/es.reflect.construct.js";import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.array.includes.js";import"core-js/modules/es.string.includes.js";import"core-js/modules/es.regexp.exec.js";import"core-js/modules/es.string.search.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/es.array.reduce.js";import"core-js/modules/es.array.map.js";import"core-js/modules/es.array.slice.js";import"core-js/modules/es.array.concat.js";import classNames from"classnames";import PropTypes from"prop-types";import{Component,createRef}from"react";import Transition from"react-transition-group/Transition";import Chevron from"../chevron";import{Breakpoint}from"../common";import{addClickClassToDocumentOnIos,removeClickClassFromDocumentOnIos}from"../common/domHelpers";import KeyCodes from"../common/keyCodes";import Dimmer from"../dimmer";import SlidingPanel from"../slidingPanel";import{addClassAndTriggerReflow,removeClass}from"./domHelpers";import Option from"./option";import SearchBox from"./searchBox";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";import{Fragment as _Fragment}from"react/jsx-runtime";function clamp(a,b,c){return Math.max(Math.min(b,c),a)}function actionableOption(a){return!a.header&&!a.separator&&!a.disabled}var isFunction=function(a){return a&&"[object Function]"==={}.toString.call(a)};function stopPropagation(a){a.stopPropagation(),a.preventDefault(),a.nativeEvent&&a.nativeEvent.stopImmediatePropagation&&a.nativeEvent.stopImmediatePropagation()}function getShouldRenderWithPortal(){return"undefined"!=typeof document&&"undefined"!=typeof window&&window.matchMedia&&window.matchMedia("(max-width: ".concat(Breakpoint.SMALL,"px)")).matches}var OPTIONS_PAGE_SIZE=100,BOOTSTRAP_DROPDOWN_ANIMATION_TIME=200,defer=function(a){return setTimeout(a,0)},includesString=function(a,b){return a.toLowerCase().includes(b.toLowerCase())},arrayIncludesString=function(a,b){return a.some(function(a){return includesString(a,b)})},defaultFilterFunction=function(a,b){return a.label&&includesString(a.label,b)||a.note&&includesString(a.note,b)||a.secondary&&includesString(a.secondary,b)||a.currency&&includesString(a.currency,b)||a.searchStrings&&arrayIncludesString(a.searchStrings,b)},Select=/*#__PURE__*/function(a){function b(a){var d;return _classCallCheck(this,b),d=c.call(this,a),_defineProperty(_assertThisInitialized(d),"handleResize",function(){d.setState({shouldRenderWithPortal:getShouldRenderWithPortal()})}),_defineProperty(_assertThisInitialized(d),"handleOnFocus",function(a){return d.props.onFocus&&d.props.onFocus(a)}),_defineProperty(_assertThisInitialized(d),"handleOnBlur",function(a){var b=d.props.onBlur,c=a.nativeEvent;if(c){var e=c.relatedTarget,f=a.currentTarget;if(f&&e&&f.contains(e))return}b&&b(a)}),_defineProperty(_assertThisInitialized(d),"getOptions",function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:d.props.options,b=d.props.search;if(!b||!d.state.searchValue)return a;var c=isFunction(b)?b:defaultFilterFunction;return a.filter(function(a){return c(a,d.state.searchValue)})}),_defineProperty(_assertThisInitialized(d),"handleSearchChange",function(a){d.setState({numberOfOptionsShown:OPTIONS_PAGE_SIZE}),d.props.onSearchChange?d.props.onSearchChange(a.target.value):d.setState({searchValue:a.target.value})}),_defineProperty(_assertThisInitialized(d),"handleKeyDown",function(a){var b=d.state.open;switch(a.keyCode){case KeyCodes.UP:b?d.moveFocusWithDifference(-1):d.open(),a.preventDefault();break;case KeyCodes.DOWN:b?d.moveFocusWithDifference(1):d.open(),a.preventDefault();break;case KeyCodes.SPACE:a.target!==d.searchBoxRef.current&&(b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault());break;case KeyCodes.ENTER:b?d.selectKeyboardFocusedOption():d.open(),a.preventDefault();break;case KeyCodes.ESCAPE:d.close(),a.preventDefault();break;case KeyCodes.TAB:b&&d.selectKeyboardFocusedOption();break;default:}}),_defineProperty(_assertThisInitialized(d),"handleButtonClick",function(){d.props.disabled||d.open()}),_defineProperty(_assertThisInitialized(d),"handleDocumentClick",function(){d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"handleTouchStart",function(a){a.currentTarget===a.target&&d.state.open&&d.close()}),_defineProperty(_assertThisInitialized(d),"style",function(a){return d.props.classNames[a]||a}),_defineProperty(_assertThisInitialized(d),"renderOption",function(a,b){var c;if(a.separator)return/*#__PURE__*/_jsx("li",{className:d.style("divider")},b);if(a.header)return/*#__PURE__*/_jsx("li",{className:d.style("dropdown-header"),onClick:stopPropagation,onKeyPress:stopPropagation,children:a.header},b);var e=d.props.selected&&d.props.selected.value===a.value,f=d.state.keyboardFocusedOptionIndex===d.getIndexWithoutHeadersForIndexWithHeaders(b),g=classNames(d.style("tw-dropdown-item"),d.style("tw-dropdown-item--clickable"),(c={},_defineProperty(c,d.style("active"),e),_defineProperty(c,d.style("tw-dropdown-item--focused"),f&&!a.disabled),_defineProperty(c,d.style("disabled"),a.disabled),c));return/*#__PURE__*/_jsx("li",{className:g,onClick:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),onKeyPress:a.disabled?stopPropagation:d.createSelectHandlerForOption(a),children:/*#__PURE__*/_jsx("a",{disabled:a.disabled,children:/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},a),{},{classNames:d.props.classNames}))})},b)}),d.state={open:!1,searchValue:"",keyboardFocusedOptionIndex:null,numberOfOptionsShown:OPTIONS_PAGE_SIZE},d.searchBoxRef=/*#__PURE__*/createRef(),d.dropdownMenuRef=/*#__PURE__*/createRef(),d}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"componentDidMount",value:function componentDidMount(){this.setState({shouldRenderWithPortal:getShouldRenderWithPortal()}),window.addEventListener("resize",this.handleResize)}},{key:"componentWillUnmount",value:function componentWillUnmount(){this.close(),window.removeEventListener("resize",this.handleResize)}},{key:"getIndexWithoutHeadersForIndexWithHeaders",value:function getIndexWithoutHeadersForIndexWithHeaders(a){return this.getOptions().reduce(function(b,c,d){return d<a&&actionableOption(c)?b+1:b},0)}},{key:"selectKeyboardFocusedOption",value:function selectKeyboardFocusedOption(){if(null!==this.state.keyboardFocusedOptionIndex){var a=this.state.keyboardFocusedOptionIndex;this.selectOption(this.getOptions().filter(actionableOption)[a])}}},{key:"moveFocusWithDifference",value:function moveFocusWithDifference(a){var b=this;this.setState(function(c,d){var e=b.getOptions(d.options).filter(actionableOption),f=e.reduce(function(a,b,c){return null===a?d.selected&&d.selected.value===b.value?c:null:a},null),g=c.keyboardFocusedOptionIndex,h=g;if(null===g&&null===f)return{keyboardFocusedOptionIndex:0};null===g&&null!==f&&(h=f);var i=h+a,j=clamp(0,e.length-1,i);return{keyboardFocusedOptionIndex:j}})}},{key:"open",value:function open(){var a=this;this.setState({open:!0},function(){var b="undefined"!=typeof window&&window.matchMedia&&!!window.matchMedia("(pointer: coarse)").matches,c=!!a.props.onSearchChange||!!a.props.search;defer(function(){!b&&c&&a.searchBoxRef.current&&a.searchBoxRef.current.focus(),addClickClassToDocumentOnIos(),document.addEventListener("click",a.handleDocumentClick,!1)})})}},{key:"close",value:function close(){var a=this;this.setState({open:!1,keyboardFocusedOptionIndex:null},function(){defer(function(){removeClickClassFromDocumentOnIos(),document.removeEventListener("click",a.handleDocumentClick,!1)})})}},{key:"createSelectHandlerForOption",value:function createSelectHandlerForOption(a){var b=this;return function(c){stopPropagation(c),b.selectOption(a)}}},{key:"selectOption",value:function selectOption(a){a&&!a.placeholder?this.props.onChange(a):this.props.onChange(null),this.close()}},{key:"renderOptionsList",value:function renderOptionsList(){var a,b=this.props,c=b.dropdownRight,d=b.dropdownWidth,e=b.id,f=b.onSearchChange,g=b.placeholder,h=b.required,i=b.search,j=b.searchValue,k=b.searchPlaceholder,l=this.state.open,m=this.style,n=!!f||!!i,o=classNames(m("tw-select"),m("dropdown-menu"),(a={},_defineProperty(a,m("dropdown-menu-".concat(c,"-right")),c),_defineProperty(a,m("dropdown-menu-".concat(d)),d),_defineProperty(a,m("dropdown-menu--open"),l),a));return/*#__PURE__*/_jsxs("ul",{className:o,"aria-labelledby":e,children:[h||n||!g?"":this.renderPlaceHolderOption(),n&&/*#__PURE__*/_jsx(SearchBox,{ref:this.searchBoxRef,classNames:this.props.classNames,value:j||this.state.searchValue,placeholder:k,onChange:this.handleSearchChange,onClick:stopPropagation}),this.renderOptions(),this.state.numberOfOptionsShown<this.getOptions().length?this.renderShowMore():""]})}},{key:"renderOptions",value:function renderOptions(){return this.getOptions().slice(0,this.state.numberOfOptionsShown).map(this.renderOption)}},{key:"renderShowMore",value:function renderShowMore(){return/*#__PURE__*/ (/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider"),this.style("show-more")),onClick:this.showMore.bind(this),onKeyPress:this.showMore.bind(this),children:/*#__PURE__*/_jsx("a",{children:"..."})}))}},{key:"showMore",value:function showMore(a){stopPropagation(a),this.setState(function(a){return{numberOfOptionsShown:a.numberOfOptionsShown+OPTIONS_PAGE_SIZE}})}},{key:"renderPlaceHolderOption",value:function renderPlaceHolderOption(){var a=this.props.placeholder;return/*#__PURE__*/_jsx("li",{className:classNames(this.style("tw-dropdown-item--clickable"),this.style("tw-dropdown-item--divider")),onClick:this.createSelectHandlerForOption({placeholder:a}),onKeyPress:this.createSelectHandlerForOption({placeholder:a}),children:/*#__PURE__*/_jsx("a",{children:a})})}},{key:"renderButtonInternals",value:function renderButtonInternals(){var a=this.props,b=a.selected,c=a.placeholder;return b?/*#__PURE__*/_jsx(Option,_objectSpread(_objectSpread({},b),{},{classNames:this.props.classNames,selected:!0})):/*#__PURE__*/_jsx("span",{className:this.style("form-control-placeholder"),children:c})}},{key:"render",value:function render(){var a,b,c=this,d=this.props,e=d.disabled,f=d.size,g=d.block,h=d.id,i=d.dropdownUp,j=d.inverse,k=d.buttonProps,l=this.state,m=l.open,n=l.shouldRenderWithPortal,o=this.style,p=classNames(o("tw-select"),o("btn-group"),(a={},_defineProperty(a,o("btn-block"),g),_defineProperty(a,o("dropup"),i),_defineProperty(a,o("dropdown"),!i),a)),q=classNames(o("btn"),o("btn-input"),(b={},_defineProperty(b,"".concat(o("btn-input-inverse")," ").concat(o("btn-addon")),j),_defineProperty(b,o("btn-xs"),"xs"===f),_defineProperty(b,o("btn-sm"),"sm"===f),_defineProperty(b,o("btn-md"),"md"===f),_defineProperty(b,o("btn-lg"),"lg"===f),b),o("dropdown-toggle")),r=o("open");return/*#__PURE__*/ (// A transition is used here in order to mount and unmount the dropdown menu while retaining animations
|
|
2
2
|
_jsx(_Fragment,{children:/*#__PURE__*/_jsxs("div",{// eslint-disable-line jsx-a11y/no-static-element-interactions
|
|
3
|
-
ref:this.dropdownMenuRef,className:
|
|
3
|
+
ref:this.dropdownMenuRef,className:p,onKeyDown:this.handleKeyDown,onTouchMove:this.handleTouchStart,onFocus:this.handleOnFocus,onBlur:this.handleOnBlur,children:[/*#__PURE__*/_jsxs("button",_objectSpread(_objectSpread({disabled:e,className:q,type:"button",id:h,"aria-expanded":m,onClick:this.handleButtonClick},k),{},{children:[this.renderButtonInternals(),/*#__PURE__*/_jsx(Chevron,{disabled:e,className:"".concat(o("tw-icon")," ").concat(o("tw-chevron-up-icon")," ").concat(o("tw-chevron")," ").concat(o("bottom")," ").concat(o("tw-select-chevron"))})]})),n?/*#__PURE__*/_jsx(Dimmer,{open:m,children:/*#__PURE__*/_jsx(SlidingPanel,{open:m,position:"bottom",children:this.renderOptionsList()})}):/*#__PURE__*/_jsx(Transition,{in:m,timeout:BOOTSTRAP_DROPDOWN_ANIMATION_TIME,onEntering:function onEntering(){c.dropdownMenuRef.current&&addClassAndTriggerReflow(c.dropdownMenuRef.current,r)},onExit:function onExit(){c.dropdownMenuRef.current&&removeClass(c.dropdownMenuRef.current,r)},children:function children(a){return"exited"!==a&&c.renderOptionsList()}})]})}))}}],[{key:"getDerivedStateFromProps",value:function getDerivedStateFromProps(a,b){var c=!!a.options.length;if(b.open&&(""!==a.searchValue||""!==b.searchValue)){if(c&&null===b.keyboardFocusedOptionIndex)return{keyboardFocusedOptionIndex:0};if(!c&&null!==b.keyboardFocusedOptionIndex)return{keyboardFocusedOptionIndex:null}}return null}}]),b}(Component);export{Select as default};Select.propTypes={placeholder:PropTypes.string,id:PropTypes.string,required:PropTypes.bool,disabled:PropTypes.bool,inverse:PropTypes.bool,dropdownRight:PropTypes.oneOf(["xs","sm","md","lg","xl"]),dropdownWidth:PropTypes.oneOf(["sm","md","lg"]),size:PropTypes.oneOf(["sm","md","lg"]),block:PropTypes.bool,selected:PropTypes.shape({value:PropTypes.any.isRequired,label:PropTypes.node,icon:PropTypes.node,currency:PropTypes.string,note:PropTypes.node,secondary:PropTypes.node}),/**
|
|
4
4
|
* Search toggle
|
|
5
5
|
* if `true` default search functionality being enabled (not case sensitive search in option labels & currency props)
|
|
6
6
|
* if `function` you can define your own search function to implement custom search experience. This search function used while filtering the options array. The custom search function takes two parameters. First is the option the second is the keyword.
|
|
7
7
|
*/search:PropTypes.oneOfType([PropTypes.bool,PropTypes.func]),onChange:PropTypes.func.isRequired,onFocus:PropTypes.func,onBlur:PropTypes.func,options:PropTypes.arrayOf(PropTypes.shape({value:PropTypes.any,label:PropTypes.node,header:PropTypes.node,icon:PropTypes.node,currency:PropTypes.string,note:PropTypes.node,secondary:PropTypes.node,separator:PropTypes.bool,disabled:PropTypes.bool,searchStrings:PropTypes.arrayOf(PropTypes.string)})).isRequired,/**
|
|
8
8
|
* To have full control of your search value and response use `onSearchChange` function combined with `searchValue` and custom filtering on the options array.
|
|
9
9
|
* DO NOT USE TOGETHER WITH `search` PROPERTY
|
|
10
|
-
*/onSearchChange:PropTypes.func,searchValue:PropTypes.string,searchPlaceholder:PropTypes.string,classNames:PropTypes.objectOf(PropTypes.string),dropdownUp:PropTypes.bool},Select.defaultProps={id:void 0,placeholder:void 0,size:"md",dropdownRight:null,dropdownWidth:null,inverse:!1,required:!1,disabled:!1,block:!0,selected:null,onFocus:null,onBlur:null,onSearchChange:void 0,search:!1,searchValue:"",searchPlaceholder:"Search...",classNames:{},dropdownUp:!1};
|
|
10
|
+
*/onSearchChange:PropTypes.func,searchValue:PropTypes.string,searchPlaceholder:PropTypes.string,classNames:PropTypes.objectOf(PropTypes.string),dropdownUp:PropTypes.bool,buttonProps:PropTypes.object},Select.defaultProps={id:void 0,placeholder:void 0,size:"md",dropdownRight:null,dropdownWidth:null,inverse:!1,required:!1,disabled:!1,block:!0,selected:null,onFocus:null,onBlur:null,onSearchChange:void 0,search:!1,searchValue:"",searchPlaceholder:"Search...",classNames:{},dropdownUp:!1,buttonProps:{}};
|
|
@@ -15,6 +15,7 @@ export declare type LinkProps = {
|
|
|
15
15
|
target?: '_blank' | '_self' | '_parent' | '_top';
|
|
16
16
|
};
|
|
17
17
|
export declare type Heading = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
18
|
+
export declare type ParentElement = HTMLElement | Window | Document;
|
|
18
19
|
export declare type OnClickHandler = {
|
|
19
20
|
onClick: (event: Event) => void;
|
|
20
21
|
};
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { ParentElement } from '../..';
|
|
2
|
+
declare type Data = {
|
|
3
|
+
attachListener: boolean;
|
|
4
|
+
callback: EventListenerOrEventListenerObject;
|
|
5
|
+
eventType: string;
|
|
6
|
+
parent: ParentElement | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const useConditionalListener: ({ attachListener, callback, eventType, parent }: Data) => void;
|
|
9
|
+
export {};
|