diff --git a/packages/anvil-embed-frame/package.json b/packages/anvil-embed-frame/package.json index a45e167..e9bcbf4 100644 --- a/packages/anvil-embed-frame/package.json +++ b/packages/anvil-embed-frame/package.json @@ -11,7 +11,8 @@ "build:changelog": "yarn auto-changelog", "pack": "yarn pack", "version": "yarn build:changelog && git add CHANGELOG.md", - "test": "yarn mocha --config ./test/mocha.js" + "test": "yarn mocha --config ./test/mocha.js", + "watch": "nodemon --watch src --exec 'yarn build'" }, "repository": { "type": "git", diff --git a/packages/anvil-embed-frame/src/index.js b/packages/anvil-embed-frame/src/index.js index c18823f..278d811 100644 --- a/packages/anvil-embed-frame/src/index.js +++ b/packages/anvil-embed-frame/src/index.js @@ -7,6 +7,7 @@ import PropTypes from 'prop-types' * @prop {Function} onEvent * @prop {String} anvilURL * @prop {String} scroll + * @prop {object} style */ /** @@ -28,6 +29,10 @@ class AnvilEmbedFrame extends React.Component { window.removeEventListener('message', this.handleEvent) } + postMessage = (message) => { + this.iframeRef.current.contentWindow.postMessage(message, '*') + } + /** * @param {Object} options * @param {String} options.origin @@ -42,7 +47,7 @@ class AnvilEmbedFrame extends React.Component { } render () { - const { iframeURL, onEvent, anvilURL, scroll, ...others } = this.props + const { iframeURL, onEvent, anvilURL, scroll, style, ...others } = this.props return ( @@ -68,6 +74,7 @@ AnvilEmbedFrame.propTypes = { onEvent: PropTypes.func, anvilURL: PropTypes.string, scroll: PropTypes.oneOf(['auto', 'smooth']), + style: PropTypes.object, } export default AnvilEmbedFrame diff --git a/packages/anvil-embed-frame/test/src/index.test.js b/packages/anvil-embed-frame/test/src/index.test.js index e3a5a7e..e4cb090 100644 --- a/packages/anvil-embed-frame/test/src/index.test.js +++ b/packages/anvil-embed-frame/test/src/index.test.js @@ -44,4 +44,20 @@ describe('AnvilEmbedFrame', function () { expect($.handleEvent).to.have.been.calledWith(data) }) }) + + it('calls postMessage successfully', () => { + const wrapper = $.render + const iframe = wrapper.find('iframe') + const postMessage = sinon.spy() + const iframeMock = { + contentWindow: { + postMessage, + }, + } + + iframe.getElement().ref.current = iframeMock + + wrapper.instance().postMessage({ action: 'test' }) + expect(postMessage.called).to.be.equal(true) + }) }) diff --git a/packages/anvil-embed-frame/types/index.d.ts b/packages/anvil-embed-frame/types/index.d.ts index 6da62f4..58b6f21 100644 --- a/packages/anvil-embed-frame/types/index.d.ts +++ b/packages/anvil-embed-frame/types/index.d.ts @@ -13,6 +13,7 @@ export type Props = { * @prop {String} anvilURL * @prop {boolean} enableDefaultStyles * @prop {String} scroll + * @prop {object} style */ /** * @extends React.Component @@ -48,8 +49,9 @@ declare namespace AnvilEmbedFrame { const enableDefaultStyles_1: PropTypes.Requireable; export { enableDefaultStyles_1 as enableDefaultStyles }; export const scroll: PropTypes.Requireable; + export const style: PropTypes.Requireable; } } import Reacat from "react"; import PropTypes from "prop-types"; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file +//# sourceMappingURL=index.d.ts.map