UNPKG

react-amphtml

Version:

Use amphtml components inside your React apps easily!

49 lines (41 loc) 1.48 kB
'use strict'; function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var __chunk_1 = require('../_virtual/_rollupPluginBabelHelpers.js'); var PropTypes = _interopDefault(require('prop-types')); var __chunk_2 = require('../constants.js'); var __chunk_3 = require('../lib/contextHelper.js'); var amphtml = require('../amphtml/amphtml.js'); var __chunk_8 = require('./Action.js'); const BLACKLIST = [__chunk_8.ON_ATTRIBUTE]; const boundAttributeRegExp = /^data-amp-.*?$/; const Bind = (_ref, context) => { let { children, version } = _ref, props = __chunk_1.objectWithoutProperties(_ref, ["children", "version"]); __chunk_3.default({ context, extension: 'amp-bind', version }); const boundAttributeProps = Object.entries(props).reduce((allProps, [propsName, propValue]) => __chunk_1.objectSpread({}, allProps, { [BLACKLIST.includes(propsName) || boundAttributeRegExp.test(propsName) ? propsName : `data-amp-bind-${propsName}`]: propValue }), {}); return children(boundAttributeProps); }; Bind.defaultProps = { version: 'latest' }; Bind.propTypes = { children: PropTypes.func.isRequired, version: amphtml.Script.propTypes && amphtml.Script.propTypes.version }; Bind.contextTypes = { [__chunk_2.CONTEXT_KEY]: PropTypes.shape({ addExtension: PropTypes.func.isRequired }) }; exports.BLACKLIST = BLACKLIST; exports.default = Bind; //# sourceMappingURL=Bind.js.map