Skip to content

amp-story-shopping Template rendering I2I #36459

@processprocess

Description

@processprocess

Summary

JSX expressions will be used to render content in the amp-story-shopping-attachment.
Screen Shot 2021-10-21 at 4 27 34 PM

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

Metadata

Metadata

Labels

INTENT TO IMPLEMENTProposes implementation of a significant new feature. https://bit.ly/amp-contribute-codeWG: stories

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions