react-amphtml
Version:
Use amphtml components inside your React apps easily!
30 lines (23 loc) • 969 B
JavaScript
;
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var PropTypes = _interopDefault(require('prop-types'));
const ON_ATTRIBUTE = 'on';
const Action = ({
children,
events
}) => {
const eventString = Object.entries(events).reduce((entireEventString, [eventName, eventActions], eventIndex) => {
const actionString = eventActions.reduce((entireActionString, nextAction, actionIndex) => `${entireActionString}${actionIndex > 0 ? ',' : ''}${nextAction}`, '');
return `${entireEventString}${eventIndex > 0 ? ';' : ''}${eventName}:${actionString}`;
}, '');
return children({
[ON_ATTRIBUTE]: eventString
});
};
Action.propTypes = {
children: PropTypes.func.isRequired,
events: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string.isRequired).isRequired).isRequired
};
exports.ON_ATTRIBUTE = ON_ATTRIBUTE;
exports.default = Action;
//# sourceMappingURL=Action.js.map