bright-components 10.2.5 → 10.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Modal/index.js +23 -1
- package/dist/components/Snackbar/index.js +17 -1
- package/dist/components/Typeahead/index.js +1 -1
- package/package.json +1 -1
- package/src/components/Modal/index.js +22 -1
- package/src/components/Snackbar/index.js +16 -1
- package/src/components/Typeahead/index.js +1 -1
- package/src/components/Typeahead/test.js +18 -0
| @@ -19,6 +19,8 @@ var _vars = _interopRequireDefault(require("../../constants/vars")); | |
| 19 19 |  | 
| 20 20 | 
             
            var _colors = _interopRequireDefault(require("../../constants/colors"));
         | 
| 21 21 |  | 
| 22 | 
            +
            var _reactAutobind = _interopRequireDefault(require("react-autobind"));
         | 
| 23 | 
            +
             | 
| 22 24 | 
             
            function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
         | 
| 23 25 |  | 
| 24 26 | 
             
            function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
         | 
| @@ -77,6 +79,14 @@ ModalContainer.displayName = 'ModalContainer'; | |
| 77 79 | 
             
            Background.displayName = 'Background';
         | 
| 78 80 |  | 
| 79 81 | 
             
            class Modal extends _react.default.Component {
         | 
| 82 | 
            +
              constructor(props) {
         | 
| 83 | 
            +
                super(props);
         | 
| 84 | 
            +
                this.state = {
         | 
| 85 | 
            +
                  createdElement: null
         | 
| 86 | 
            +
                };
         | 
| 87 | 
            +
                (0, _reactAutobind.default)(this);
         | 
| 88 | 
            +
              }
         | 
| 89 | 
            +
             | 
| 80 90 | 
             
              componentDidMount() {
         | 
| 81 91 | 
             
                /* istanbul ignore next */
         | 
| 82 92 | 
             
                if (this.props.version === '1') {
         | 
| @@ -85,10 +95,18 @@ class Modal extends _react.default.Component { | |
| 85 95 | 
             
                }
         | 
| 86 96 |  | 
| 87 97 | 
             
                document.body.style.overflow = 'hidden';
         | 
| 98 | 
            +
                const randomId = Math.random().toString();
         | 
| 99 | 
            +
                const wrapperElement = document.createElement('div');
         | 
| 100 | 
            +
                wrapperElement.setAttribute('id', `modal${randomId}`);
         | 
| 101 | 
            +
                document.body.appendChild(wrapperElement);
         | 
| 102 | 
            +
                this.setState({
         | 
| 103 | 
            +
                  createdElement: wrapperElement
         | 
| 104 | 
            +
                });
         | 
| 88 105 | 
             
              }
         | 
| 89 106 |  | 
| 90 107 | 
             
              componentWillUnmount() {
         | 
| 91 108 | 
             
                document.body.style.overflow = 'auto';
         | 
| 109 | 
            +
                this.state.createdElement.parentNode.removeChild(this.state.createdElement);
         | 
| 92 110 | 
             
              }
         | 
| 93 111 |  | 
| 94 112 | 
             
              render() {
         | 
| @@ -111,6 +129,10 @@ class Modal extends _react.default.Component { | |
| 111 129 | 
             
                  }
         | 
| 112 130 | 
             
                };
         | 
| 113 131 |  | 
| 132 | 
            +
                if (!this.state.createdElement) {
         | 
| 133 | 
            +
                  return null;
         | 
| 134 | 
            +
                }
         | 
| 135 | 
            +
             | 
| 114 136 | 
             
                return (0, _reactDom.createPortal)(_react.default.createElement(Background, _extends({
         | 
| 115 137 | 
             
                  onClick: dismiss,
         | 
| 116 138 | 
             
                  version: version
         | 
| @@ -132,7 +154,7 @@ class Modal extends _react.default.Component { | |
| 132 154 | 
             
                  return _react.default.cloneElement(child, {
         | 
| 133 155 | 
             
                    close
         | 
| 134 156 | 
             
                  });
         | 
| 135 | 
            -
                }))),  | 
| 157 | 
            +
                }))), this.state.createdElement);
         | 
| 136 158 | 
             
              }
         | 
| 137 159 |  | 
| 138 160 | 
             
            }
         | 
| @@ -124,6 +124,9 @@ const delays = { | |
| 124 124 | 
             
            class Snackbar extends _react.default.Component {
         | 
| 125 125 | 
             
              constructor(props) {
         | 
| 126 126 | 
             
                super(props);
         | 
| 127 | 
            +
                this.state = {
         | 
| 128 | 
            +
                  createdElement: null
         | 
| 129 | 
            +
                };
         | 
| 127 130 | 
             
                (0, _reactAutobind.default)(this);
         | 
| 128 131 | 
             
                this.timer = null;
         | 
| 129 132 | 
             
              }
         | 
| @@ -132,6 +135,14 @@ class Snackbar extends _react.default.Component { | |
| 132 135 | 
             
                if (this.props.visible) {
         | 
| 133 136 | 
             
                  this.hideAfterDelay();
         | 
| 134 137 | 
             
                }
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                const randomId = Math.random().toString();
         | 
| 140 | 
            +
                const wrapperElement = document.createElement('div');
         | 
| 141 | 
            +
                wrapperElement.setAttribute('id', `modal${randomId}`);
         | 
| 142 | 
            +
                document.body.appendChild(wrapperElement);
         | 
| 143 | 
            +
                this.setState({
         | 
| 144 | 
            +
                  createdElement: wrapperElement
         | 
| 145 | 
            +
                });
         | 
| 135 146 | 
             
              }
         | 
| 136 147 |  | 
| 137 148 | 
             
              componentDidUpdate(prevProps) {
         | 
| @@ -141,6 +152,7 @@ class Snackbar extends _react.default.Component { | |
| 141 152 | 
             
              }
         | 
| 142 153 |  | 
| 143 154 | 
             
              componentWillUnmount() {
         | 
| 155 | 
            +
                this.state.createdElement.parentNode.removeChild(this.state.createdElement);
         | 
| 144 156 | 
             
                window.clearTimeout(this.timer);
         | 
| 145 157 | 
             
              }
         | 
| 146 158 |  | 
| @@ -172,6 +184,10 @@ class Snackbar extends _react.default.Component { | |
| 172 184 | 
             
                } = _this$props,
         | 
| 173 185 | 
             
                      rest = _objectWithoutProperties(_this$props, ["visible", "children", "onClose", "hideClose", "action", "onAction", "displayTime", "type"]);
         | 
| 174 186 |  | 
| 187 | 
            +
                if (!this.state.createdElement) {
         | 
| 188 | 
            +
                  return null;
         | 
| 189 | 
            +
                }
         | 
| 190 | 
            +
             | 
| 175 191 | 
             
                return (0, _reactDom.createPortal)(_react.default.createElement(SlideUpLeft, _extends({
         | 
| 176 192 | 
             
                  visible: visible
         | 
| 177 193 | 
             
                }, rest), _react.default.createElement(SnackWrapper, {
         | 
| @@ -188,7 +204,7 @@ class Snackbar extends _react.default.Component { | |
| 188 204 | 
             
                }, action), displayTime === 'persistent' && _react.default.createElement(ToastOutlineButton, {
         | 
| 189 205 | 
             
                  type: type,
         | 
| 190 206 | 
             
                  onClick: onClose
         | 
| 191 | 
            -
                }, "Dismiss")))))),  | 
| 207 | 
            +
                }, "Dismiss")))))), this.state.createdElement);
         | 
| 192 208 | 
             
              }
         | 
| 193 209 |  | 
| 194 210 | 
             
            }
         | 
| @@ -171,7 +171,7 @@ class Typeahead extends _react.default.Component { | |
| 171 171 | 
             
                let nextIndex = highlightIndex;
         | 
| 172 172 | 
             
                const isActionKey = ['ArrowDown', 'ArrowUp', 'Enter', 'Escape', 'Tab'].includes(e.key);
         | 
| 173 173 |  | 
| 174 | 
            -
                if (!isActionKey) {
         | 
| 174 | 
            +
                if (!isActionKey || !this.options[highlightIndex]) {
         | 
| 175 175 | 
             
                  return;
         | 
| 176 176 | 
             
                }
         | 
| 177 177 |  | 
    
        package/package.json
    CHANGED
    
    
| @@ -6,6 +6,7 @@ import get from 'lodash.get'; | |
| 6 6 | 
             
            import spacing from 'constants/spacing';
         | 
| 7 7 | 
             
            import vars from 'constants/vars';
         | 
| 8 8 | 
             
            import colors from 'constants/colors';
         | 
| 9 | 
            +
            import autobind from 'react-autobind';
         | 
| 9 10 |  | 
| 10 11 | 
             
            const MODAL_WIDTHS = vars.modalWidths;
         | 
| 11 12 |  | 
| @@ -59,6 +60,12 @@ ModalContainer.displayName = 'ModalContainer'; | |
| 59 60 | 
             
            Background.displayName = 'Background';
         | 
| 60 61 |  | 
| 61 62 | 
             
            class Modal extends React.Component {
         | 
| 63 | 
            +
            	constructor(props) {
         | 
| 64 | 
            +
            		super(props);
         | 
| 65 | 
            +
            		this.state = { createdElement: null };
         | 
| 66 | 
            +
            		autobind(this);
         | 
| 67 | 
            +
            	}
         | 
| 68 | 
            +
             | 
| 62 69 | 
             
            	componentDidMount() {
         | 
| 63 70 | 
             
            		/* istanbul ignore next */
         | 
| 64 71 | 
             
            		if (this.props.version === '1') {
         | 
| @@ -67,10 +74,20 @@ class Modal extends React.Component { | |
| 67 74 | 
             
            		}
         | 
| 68 75 |  | 
| 69 76 | 
             
            		document.body.style.overflow = 'hidden';
         | 
| 77 | 
            +
             | 
| 78 | 
            +
            		const randomId = Math.random().toString();
         | 
| 79 | 
            +
            		const wrapperElement = document.createElement('div');
         | 
| 80 | 
            +
            		wrapperElement.setAttribute('id', `modal${randomId}`);
         | 
| 81 | 
            +
            		document.body.appendChild(wrapperElement);
         | 
| 82 | 
            +
            		this.setState({ createdElement: wrapperElement });
         | 
| 70 83 | 
             
            	}
         | 
| 71 84 |  | 
| 72 85 | 
             
            	componentWillUnmount() {
         | 
| 73 86 | 
             
            		document.body.style.overflow = 'auto';
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            		this.state.createdElement.parentNode.removeChild(
         | 
| 89 | 
            +
            			this.state.createdElement
         | 
| 90 | 
            +
            		);
         | 
| 74 91 | 
             
            	}
         | 
| 75 92 |  | 
| 76 93 | 
             
            	render() {
         | 
| @@ -91,6 +108,10 @@ class Modal extends React.Component { | |
| 91 108 | 
             
            			}
         | 
| 92 109 | 
             
            		};
         | 
| 93 110 |  | 
| 111 | 
            +
            		if (!this.state.createdElement) {
         | 
| 112 | 
            +
            			return null;
         | 
| 113 | 
            +
            		}
         | 
| 114 | 
            +
             | 
| 94 115 | 
             
            		return createPortal(
         | 
| 95 116 | 
             
            			<Background
         | 
| 96 117 | 
             
            				onClick={dismiss}
         | 
| @@ -117,7 +138,7 @@ class Modal extends React.Component { | |
| 117 138 | 
             
            					})}
         | 
| 118 139 | 
             
            				</ModalContainer>
         | 
| 119 140 | 
             
            			</Background>,
         | 
| 120 | 
            -
            			 | 
| 141 | 
            +
            			this.state.createdElement
         | 
| 121 142 | 
             
            		);
         | 
| 122 143 | 
             
            	}
         | 
| 123 144 | 
             
            }
         | 
| @@ -114,6 +114,7 @@ const delays = { | |
| 114 114 | 
             
            class Snackbar extends React.Component {
         | 
| 115 115 | 
             
            	constructor(props) {
         | 
| 116 116 | 
             
            		super(props);
         | 
| 117 | 
            +
            		this.state = { createdElement: null };
         | 
| 117 118 | 
             
            		autobind(this);
         | 
| 118 119 |  | 
| 119 120 | 
             
            		this.timer = null;
         | 
| @@ -123,6 +124,12 @@ class Snackbar extends React.Component { | |
| 123 124 | 
             
            		if (this.props.visible) {
         | 
| 124 125 | 
             
            			this.hideAfterDelay();
         | 
| 125 126 | 
             
            		}
         | 
| 127 | 
            +
             | 
| 128 | 
            +
            		const randomId = Math.random().toString();
         | 
| 129 | 
            +
            		const wrapperElement = document.createElement('div');
         | 
| 130 | 
            +
            		wrapperElement.setAttribute('id', `modal${randomId}`);
         | 
| 131 | 
            +
            		document.body.appendChild(wrapperElement);
         | 
| 132 | 
            +
            		this.setState({ createdElement: wrapperElement });
         | 
| 126 133 | 
             
            	}
         | 
| 127 134 |  | 
| 128 135 | 
             
            	componentDidUpdate(prevProps) {
         | 
| @@ -132,6 +139,10 @@ class Snackbar extends React.Component { | |
| 132 139 | 
             
            	}
         | 
| 133 140 |  | 
| 134 141 | 
             
            	componentWillUnmount() {
         | 
| 142 | 
            +
            		this.state.createdElement.parentNode.removeChild(
         | 
| 143 | 
            +
            			this.state.createdElement
         | 
| 144 | 
            +
            		);
         | 
| 145 | 
            +
             | 
| 135 146 | 
             
            		window.clearTimeout(this.timer);
         | 
| 136 147 | 
             
            	}
         | 
| 137 148 |  | 
| @@ -159,6 +170,10 @@ class Snackbar extends React.Component { | |
| 159 170 | 
             
            			...rest
         | 
| 160 171 | 
             
            		} = this.props;
         | 
| 161 172 |  | 
| 173 | 
            +
            		if (!this.state.createdElement) {
         | 
| 174 | 
            +
            			return null;
         | 
| 175 | 
            +
            		}
         | 
| 176 | 
            +
             | 
| 162 177 | 
             
            		return createPortal(
         | 
| 163 178 | 
             
            			<SlideUpLeft visible={visible} {...rest}>
         | 
| 164 179 | 
             
            				<SnackWrapper type={type} data-testid="snackwrapper">
         | 
| @@ -190,7 +205,7 @@ class Snackbar extends React.Component { | |
| 190 205 | 
             
            					</ContentWrapper>
         | 
| 191 206 | 
             
            				</SnackWrapper>
         | 
| 192 207 | 
             
            			</SlideUpLeft>,
         | 
| 193 | 
            -
            			 | 
| 208 | 
            +
            			this.state.createdElement
         | 
| 194 209 | 
             
            		);
         | 
| 195 210 | 
             
            	}
         | 
| 196 211 | 
             
            }
         | 
| @@ -228,6 +228,13 @@ describe('<Typeahead />', () => { | |
| 228 228 | 
             
            			[firstOption, secondOption] = wrapper.getAllByRole('listitem');
         | 
| 229 229 | 
             
            			expect(firstOption).not.toHaveStyleRule('background', '#D0EBFD');
         | 
| 230 230 | 
             
            			expect(secondOption).toHaveStyleRule('background', '#D0EBFD');
         | 
| 231 | 
            +
             | 
| 232 | 
            +
            			fireEvent.keyDown(input, { key: 'ArrowUp' });
         | 
| 233 | 
            +
            			fireEvent.keyDown(input, { key: 'ArrowUp' });
         | 
| 234 | 
            +
            			fireEvent.keyDown(input, { key: 'ArrowUp' });
         | 
| 235 | 
            +
             | 
| 236 | 
            +
            			expect(firstOption).toHaveStyleRule('background', '#D0EBFD');
         | 
| 237 | 
            +
            			expect(secondOption).not.toHaveStyleRule('background', '#D0EBFD');
         | 
| 231 238 | 
             
            		});
         | 
| 232 239 |  | 
| 233 240 | 
             
            		it('should highlight a new option on the up arrow key', () => {
         | 
| @@ -284,5 +291,16 @@ describe('<Typeahead />', () => { | |
| 284 291 |  | 
| 285 292 | 
             
            			expect(scrollIntoView).not.toHaveBeenCalled();
         | 
| 286 293 | 
             
            		});
         | 
| 294 | 
            +
             | 
| 295 | 
            +
            		it('should handle live updates to the list changing the length of the list', () => {
         | 
| 296 | 
            +
            			const input = wrapper.getByPlaceholderText('Search or select');
         | 
| 297 | 
            +
             | 
| 298 | 
            +
            			fireEvent.focus(input);
         | 
| 299 | 
            +
             | 
| 300 | 
            +
            			wrapper.rerender(<Typeahead {...props} options={[]} />);
         | 
| 301 | 
            +
            			fireEvent.keyDown(input, { key: 'Enter' });
         | 
| 302 | 
            +
             | 
| 303 | 
            +
            			expect(setSelected).toHaveBeenCalledTimes(0);
         | 
| 304 | 
            +
            		});
         | 
| 287 305 | 
             
            	});
         | 
| 288 306 | 
             
            });
         |