-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
INTENT TO IMPLEMENTProposes implementation of a significant new feature. https://bit.ly/amp-contribute-codeProposes implementation of a significant new feature. https://bit.ly/amp-contribute-codeWG: stories
Description
Summary
JSX expressions will be used to render content in the amp-story-shopping-attachment.

JSX support in amp-story will be added with #36640
Example Pseudocode
// Product list template with click handler, translated string and product list item children.
const ProductList = ({doc, onProductListClick, products}) => {
return (
<div onClick={onProductListClick}>
<span>{localize(doc, LocalizedStringId.AMP_STORY_SHOPPING_BUY_NOW)}</span>
<ul>
// Iterate over products and render `ProductListItem` elements with individual product data.
{products.map((product) => (
<ProductListItem product={product} />
))}
</ul>
</div>
);
};
// Product list item elements are generated from the ProductList parent.
const ProductListItem = ({product}) => {
const {name, brand} = product;
return (
<li role="button">
<div>name: {name}</div>
<div>brand: {brand}</div>
</li>
);
};
...
buildCallback() {
...
this.storeService_.subscribe(
StateProperty.SHOPPING_DATA,
(shoppingData) => {
this.element.appendChild(
<ProductList
doc={this.win.document}
onProductListClick={this.onProductListClick_}
products={shoppingData.products}
/>
);
}
);
...
}
Customization
The first version will support light(default) and dark theme.
Future versions may include additional color support and custom fonts.
Motivation
Using this will reduce code/surface for bugs/tech-debt.
Alternative Solutions
Template strings could be used however we will need to iterate over content. JSX provides this functionality.
Notifications
/cc @ampproject/wg-approvers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
INTENT TO IMPLEMENTProposes implementation of a significant new feature. https://bit.ly/amp-contribute-codeProposes implementation of a significant new feature. https://bit.ly/amp-contribute-codeWG: stories