UNPKG

515 BJavaScriptView Raw
1import React from 'react';
2const eventToPropRecord = {
3 'click': 'onClick',
4 'touchstart': 'onTouchStart'
5};
6export function withStopPropagation(events, element) {
7 const props = Object.assign({}, element.props);
8 for (const key of events) {
9 const prop = eventToPropRecord[key];
10 props[prop] = function (e) {
11 var _a, _b;
12 e.stopPropagation();
13 (_b = (_a = element.props)[prop]) === null || _b === void 0 ? void 0 : _b.call(_a, e);
14 };
15 }
16 return React.cloneElement(element, props);
17}
\No newline at end of file