1.2110011758.0 • Published 3 years ago

@ampproject/amp-twitter v1.2110011758.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

$category@: social formats:

  • websites teaser: text: Displays a Twitter Tweet or Moment. experimental: true bento: true

Bento Twitter

Behavior

The Bento Twitter component allows you to embed a Tweet or Moment. Use it as a web component <bento-twitter>, or a Preact/React functional component <BentoTwitter>.

Web Component

You must include each Bento component's required CSS library to guarantee proper loading and before adding custom styles. Or use the light-weight pre-upgrade styles available inline. See Layout and style.

The examples below demonstrate use of the <bento-twitter> web component.

Example: Import via npm

example preview="top-frame" playground="false"

Install via npm:

npm install @ampproject/bento-twitter
import '@ampproject/bento-twitter';

/example

Example: Include via <script>

example preview="top-frame" playground="false"

<head>
  <script src="https://cdn.ampproject.org/custom-elements-polyfill.js"></script>
  <!-- These styles prevent Cumulative Layout Shift on the unupgraded custom element -->
  <style data-bento-boilerplate>
    bento-twitter {
      display: block;
      overflow: hidden;
      position: relative;
    }
  </style>
  <!-- TODO(wg-bento): Once available, change src to bento-twitter.js -->
  <script async src="https://cdn.ampproject.org/v0/amp-twitter-1.0.js"></script>
  <style>
    bento-twitter {
      width: 375px;
      height: 472px;
    }
  </style>
</head>
<bento-twitter id="my-tweet" data-tweetid="885634330868850689">
</bento-twitter>
<div class="buttons" style="margin-top: 8px;">
  <button id="change-tweet">
    Change tweet
  </button>
</div>

<script>
  (async () => {
    const twitter = document.querySelector('#my-tweet');
    await customElements.whenDefined('bento-twitter');

    // set up button actions
    document.querySelector('#change-tweet').onclick = () => {
      twitter.setAttribute('data-tweetid', '495719809695621121')
    }
  })();
</script>

/example

Layout and style

Each Bento component has a small CSS library you must include to guarantee proper loading without content shifts. Because of order-based specificity, you must manually ensure that stylesheets are included before any custom styles.

<link rel="stylesheet" type="text/css" href="https://cdn.ampproject.org/v0/amp-twitter-1.0.css">

Alternatively, you may also make the light-weight pre-upgrade styles available inline:

<style data-bento-boilerplate>
  bento-twitter {
    display: block;
    overflow: hidden;
    position: relative;
  }
</style>

Container type

The bento-twitter component has a defined layout size type. To ensure the component renders correctly, be sure to apply a size to the component and its immediate children (slides) via a desired CSS layout (such as one defined with height, width, aspect-ratio, or other such properties):

bento-twitter {
  height: 100px;
  width: 100%;
}

Attributes

Preact/React Component

The examples below demonstrate use of the <BentoTwitter> as a functional component usable with the Preact or React libraries.

Example: Import via npm

example preview="top-frame" playground="false"

Install via npm:

npm install @ampproject/bento-twitter
import React from 'react';
import { BentoTwitter } from '@ampproject/bento-twitter/react';
import '@ampproject/bento-twitter/styles.css';

function App() {
  return (
    <BentoTwitter tweetid="1356304203044499462">
    </BentoTwitter>
  );
}

/example

Layout and style

Container type

The BentoTwitter component has a defined layout size type. To ensure the component renders correctly, be sure to apply a size to the component and its immediate children (slides) via a desired CSS layout (such as one defined with height, width, aspect-ratio, or other such properties). These can be applied inline:

<BentoTwitter style={{width: '300px', height: '100px'}}  tweetid="1356304203044499462">
</BentoTwitter>

Or via className:

<BentoTwitter className='custom-styles'  tweetid="1356304203044499462">
</BentoTwitter>
.custom-styles {
  height: 100px;
  width: 100%;
}

Props

function MyComponent() { // etc return ( ); }

1.2110252343.0

3 years ago

1.2110152252.0

3 years ago

1.2110202310.0

3 years ago

1.2110142235.0

3 years ago

1.2110212130.0

3 years ago

1.2110121825.0

3 years ago

1.2110011758.0

3 years ago

1.2110082201.1

3 years ago

1.2110112305.0

3 years ago

1.2110181554.0

3 years ago

1.2110082201.2

3 years ago

1.2110192227.0

3 years ago

1.2109222204.0

3 years ago

1.2109212005.0

3 years ago

1.2109201529.0

3 years ago

1.2109180035.0

3 years ago

1.2109161911.0

3 years ago

1.2109151922.0

3 years ago

1.2109142054.0

3 years ago

1.2109102127.0

3 years ago

1.2109100544.0

3 years ago

1.2109082106.0

3 years ago

1.2109072113.0

3 years ago

1.2108280007.1

3 years ago

1.2109022317.0

3 years ago

1.2109032350.0

3 years ago

1.2108302037.0

3 years ago

1.2109010455.0

3 years ago

1.2109012253.0

3 years ago

1.2108242314.0

3 years ago

1.2108280007.0

3 years ago

1.2108270538.0

3 years ago

1.2108232044.0

3 years ago

1.2108221555.0

3 years ago

1.2108190446.0

3 years ago

1.2108192119.0

3 years ago

1.2108170213.0

3 years ago

1.2108052321.1

3 years ago

1.2108132216.0

3 years ago

1.2108130315.0

3 years ago

1.2108112212.0

3 years ago

1.2107302322.1

3 years ago

1.2108101942.0

3 years ago

1.2108100143.0

3 years ago

1.2108052321.0

3 years ago

1.2108040347.0

3 years ago

1.2108030112.0

3 years ago

1.2107300532.0

3 years ago

1.2107302322.0

3 years ago

1.2107282214.0

3 years ago

1.2107280004.0

3 years ago

1.2107240354.0

3 years ago

1.2107230121.0

3 years ago

1.2107212010.0

3 years ago

1.2107200040.0

3 years ago

1.2107202252.0

3 years ago

1.2107170150.0

3 years ago

1.2107152117.0

3 years ago

1.2107150011.0

3 years ago

1.2107140004.0

3 years ago

1.2107030008.1

3 years ago

1.2107130206.0

3 years ago

1.2107082341.0

3 years ago

1.2107092322.0

3 years ago

1.2107072148.0

3 years ago

1.2107030008.0

3 years ago

1.2106302324.0

3 years ago

1.2106292357.0

3 years ago

1.2107012021.0

3 years ago

1.2106290147.0

3 years ago

1.2106260436.0

3 years ago

1.2106240350.0

3 years ago

1.2106212012.0

3 years ago

1.2106222237.0

3 years ago

1.2106182132.0

3 years ago

1.2106172254.0

3 years ago

1.2106160500.0

3 years ago

1.2106141722.0

3 years ago

1.2106162301.0

3 years ago

1.2106120107.0

3 years ago

1.2106102303.0

3 years ago

1.2106092357.0

3 years ago

1.2106090052.0

3 years ago

1.2106072053.0

3 years ago

1.2106060839.0

3 years ago

1.2106040012.0

3 years ago

1.2105210438.3

3 years ago

1.2106030132.0

3 years ago

1.2106012301.0

3 years ago

1.2105281634.0

3 years ago

1.2105280035.0

3 years ago

1.2105271708.0

3 years ago

1.2105270452.0

3 years ago

1.2105242203.0

3 years ago

1.2105191214.2

3 years ago