diff --git a/README.md b/README.md index a0848af..dcae97d 100644 --- a/README.md +++ b/README.md @@ -107,12 +107,10 @@ const finalHTML = ` #### [amp-accordion](https://www.ampproject.org/docs/reference/components/amp-accordion) -#### [amp-bind](https://www.ampproject.org/docs/reference/components/amp-bind) +#### [amp-ad](https://www.ampproject.org/docs/reference/components/amp-ad) #### [amp-install-serviceworker](https://www.ampproject.org/docs/reference/components/amp-install-serviceworker) -#### [amp-ad](https://www.ampproject.org/docs/reference/components/amp-ad) - Example usage: ```jsx @@ -129,6 +127,24 @@ Props: - dataNoServiceWorkerFallbackUrlMatch (optional) - dataNoServiceWorkerFallbackShellUrl (optional) +### [amp-bind](https://www.ampproject.org/docs/reference/components/amp-bind) +Example usage: +```jsx + + I will get the [text] and [class] attributes + +``` +### [amp-state](https://www.ampproject.org/docs/reference/components/amp-bind) +Example usage: +```jsx + + {{ + dog: 10, + cat: 90 + }} + +``` + ## Todo - [ ] Define all the AMP components with their properties and scripts in a JSON file and use that to generate them. diff --git a/src/__tests__/components/State-test.js b/src/__tests__/components/State-test.js new file mode 100644 index 0000000..e14b31b --- /dev/null +++ b/src/__tests__/components/State-test.js @@ -0,0 +1,29 @@ +import React from 'react' +import State from '../../components/State' +import Helmet from '../../utils/Helmet' +import { renderComponent } from '../test-utils' + +describe('State', () => { + it('works', () => { + const res = renderComponent( + + {{ + lion: 'mammal' + }} + + ) + expect(res.toJSON()).toMatchSnapshot() + }) + + it('injects the right script tag', () => { + renderComponent( + + {{}} + + ) + Helmet.canUseDOM = false + const staticHead = Helmet.renderStatic() + expect(staticHead.scriptTags).toMatchSnapshot() + }) +}) + diff --git a/src/__tests__/components/__snapshots__/State-test.js.snap b/src/__tests__/components/__snapshots__/State-test.js.snap new file mode 100644 index 0000000..5f84399 --- /dev/null +++ b/src/__tests__/components/__snapshots__/State-test.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`State injects the right script tag 1`] = ` +Array [ + Object { + "async": true, + "custom-element": "amp-bind", + "src": "https://cdn.ampproject.org/v0/amp-bind-0.1.js", + }, +] +`; + +exports[`State works 1`] = ` + + + +`; diff --git a/src/components/State.js b/src/components/State.js new file mode 100644 index 0000000..0387358 --- /dev/null +++ b/src/components/State.js @@ -0,0 +1,38 @@ +/* eslint-disable react/no-danger */ +import React, { Component, Fragment } from 'react' +import { shape, string } from 'prop-types' +import { Helmet } from 'react-helmet' + +class State extends Component { + static propTypes = { + children: shape({}), + id: string + } + + static defaultProps = { + children: {}, + id: null + } + + render() { + const { children, id } = this.props + + return ( + + + + + + + + + ) + } +} + +export default State diff --git a/src/index.js b/src/index.js index 83d3872..dada104 100644 --- a/src/index.js +++ b/src/index.js @@ -8,4 +8,6 @@ export { default as Ad } from './components/Ad' export { default as Form } from './components/Form' export { default as Bind } from './components/Bind' export { default as InstallServiceworker } from './components/InstallServiceworker' +export { default as State } from './components/State' + export { default as Helmet } from './utils/Helmet'
I will get the [text] and [class] attributes