@bentoproject/embedly-card

1.2305051745.1 • Public • Published

Bento Embedly Card

Provides responsive and shareable embeds using Embedly cards

Cards are the easiest way to leverage Embedly. For any media, cards provide a responsive embed with built-in embed analytics.

If you have a paid plan, use the <bento-embedly-key> or <BentoEmbedlyContext.Provider> component to set your API key. You just need one Bento Embedly key per page to remove Embedly's branding from the cards. Within your page, you can include one or multiple Bento Embedly Card instances.

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.

Import via npm

npm install @bentoproject/embedly-card
import {defineElement as defineBentoEmbedlyCard} from '@bentoproject/embedly-card';
defineBentoEmbedlyCard();

Include via <script>

<script type="module" src="https://cdn.ampproject.org/bento.mjs" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.ampproject.org/bento.js" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.mjs" crossorigin="anonymous"></script>
<script nomodule src="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.css" crossorigin="anonymous">

Example

<!DOCTYPE html>
<html>
  <head>
    <script
      type="module"
      async
      src="https://cdn.ampproject.org/bento.mjs"
    ></script>
    <script nomodule src="https://cdn.ampproject.org/bento.js"></script>
    <link
      rel="stylesheet"
      type="text/css"
      href="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.css"
    />
    <script
      type="module"
      async
      src="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.mjs"
    ></script>
    <script
      nomodule
      async
      src="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.js"
    ></script>
    <style>
      bento-embedly-card {
        width: 375px;
        height: 472px;
      }
    </style>
  </head>
  <body>
    <bento-embedly-key value="12af2e3543ee432ca35ac30a4b4f656a">
    </bento-embedly-key>

    <bento-embedly-card
      data-url="https://twitter.com/AMPhtml/status/986750295077040128"
      data-card-theme="dark"
      data-card-controls="0"
    >
    </bento-embedly-card>

    <bento-embedly-card
      id="my-url"
      data-url="https://www.youtube.com/watch?v=LZcKdHinUhE"
    >
    </bento-embedly-card>
  </body>
</html>

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/bento-embedly-card-1.0.css"
/>

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

<style>
  bento-embedly-card {
    display: block;
    overflow: hidden;
    position: relative;
  }
</style>

Container type

The bento-embedly-card 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-embedly-card {
  height: 100px;
  width: 100%;
}

Attributes

data-url

The URL to retrieve embedding information.

data-card-embed

The URL to a video or rich media. Use with static embeds like articles, instead of using the static page content in the card, the card will embed the video or rich media.

data-card-image

The URL to an image. Specifies which image to use in article cards when data-url points to an article. Not all image URLs are supported, if the image is not loaded, try a different image or domain.

data-card-controls

Enables share icons.

  • 0: Disable share icons.
  • 1: Enable share icons

The default is 1.

data-card-align

Aligns the card. The possible values are left, center and right. The default value is center.

data-card-recommend

When recommendations are supported, it disables embedly recommendations on video and rich cards. These are recommendations created by embedly.

  • 0: Disables embedly recommendations.
  • 1: Enables embedly recommendations.

The default value is 1.

data-card-via (optional)

Specifies the via content in the card. This is a great way to do attribution.

data-card-theme (optional)

Allows settings the dark theme which changes the background color of the main card container. Use dark to set this theme. For dark backgrounds it's better to specify this. The default is light, which sets no background color of the main card container.

title (optional)

Define a title attribute for the component to propagate to the underlying <iframe> element. The default value is "Embedly card".

API Example

Programmatically changing any of the attribute values, will automatically update the element. For example, by changing the data-url value, you can switch to a different embed:

<!DOCTYPE html>
<html>
  <head>
    <script
      type="module"
      async
      src="https://cdn.ampproject.org/bento.mjs"
    ></script>
    <script nomodule src="https://cdn.ampproject.org/bento.js"></script>
    <link
      rel="stylesheet"
      type="text/css"
      href="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.css"
    />
    <script
      type="module"
      async
      src="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.mjs"
    ></script>
    <script
      nomodule
      async
      src="https://cdn.ampproject.org/v0/bento-embedly-card-1.0.js"
    ></script>
    <style>
      bento-embedly-card {
        width: 375px;
        height: 472px;
      }
    </style>
  </head>
  <body>
    <bento-embedly-key value="12af2e3543ee432ca35ac30a4b4f656a">
    </bento-embedly-key>

    <bento-embedly-card
      data-url="https://twitter.com/AMPhtml/status/986750295077040128"
      data-card-theme="dark"
      data-card-controls="0"
    >
    </bento-embedly-card>

    <bento-embedly-card
      id="my-url"
      data-url="https://www.youtube.com/watch?v=LZcKdHinUhE"
    >
    </bento-embedly-card>

    <div class="buttons" style="margin-top: 8px">
      <button id="change-url">Change embed</button>
    </div>

    <script>
      (async () => {
        const embedlyCard = document.querySelector('#my-url');
        await customElements.whenDefined('bento-embedly-card');

        // set up button actions
        document.querySelector('#change-url').onclick = () => {
          embedlyCard.setAttribute(
            'data-url',
            'https://www.youtube.com/watch?v=wcJSHR0US80'
          );
        };
      })();
    </script>
  </body>
</html>

Preact/React Component

Import via npm

npm install @bentoproject/embedly-card
import {BentoEmbedlyCard} from '@bentoproject/embedly-card/react';
import '@bentoproject/embedly-card/styles.css';

function App() {
  return (
    <BentoEmbedlyContext.Provider
      value={{apiKey: '12af2e3543ee432ca35ac30a4b4f656a'}}
    >
      <BentoEmbedlyCard url="https://www.youtube.com/watch?v=LZcKdHinUhE"></BentoEmbedlyCard>
    </BentoEmbedlyContext.Provider>
  );
}

Layout and style

Container type

The BentoEmbedlyCard 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:

<BentoEmbedlyCard
  style={{width: 300, height: 100}}
  url="https://www.youtube.com/watch?v=LZcKdHinUhE"
></BentoEmbedlyCard>

Or via className:

<BentoEmbedlyCard
  className="custom-styles"
  url="https://www.youtube.com/watch?v=LZcKdHinUhE"
></BentoEmbedlyCard>
.custom-styles {
  height: 100px;
  width: 100%;
}

Props

url

The URL to retrieve embedding information.

cardEmbed

The URL to a video or rich media. Use with static embeds like articles, instead of using the static page content in the card, the card will embed the video or rich media.

cardImage

The URL to an image. Specifies which image to use in article cards when data-url points to an article. Not all image URLs are supported, if the image is not loaded, try a different image or domain.

cardControls

Enables share icons.

  • 0: Disable share icons.
  • 1: Enable share icons

The default is 1.

cardAlign

Aligns the card. The possible values are left, center and right. The default value is center.

cardRecommend

When recommendations are supported, it disables embedly recommendations on video and rich cards. These are recommendations created by embedly.

  • 0: Disables embedly recommendations.
  • 1: Enables embedly recommendations.

The default value is 1.

cardVia (optional)

Specifies the via content in the card. This is a great way to do attribution.

cardTheme (optional)

Allows settings the dark theme which changes the background color of the main card container. Use dark to set this theme. For dark backgrounds it's better to specify this. The default is light, which sets no background color of the main card container.

title (optional)

Define a title attribute for the component to propagate to the underlying <iframe> element. The default value is "Embedly card".

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2305241828.01nightly
1.2305051745.11latest

Version History

VersionDownloads (Last 7 Days)Published
1.2305241828.01
1.2305232041.01
1.2305051745.11
1.2305221508.01
1.2305182038.01
1.2305152039.01
1.2305051745.01
1.2305022024.01
1.2304262219.01
1.2304241924.01
1.2304212144.01
1.2304132133.01
1.2304122229.01
1.2304062309.01
1.2304040531.01
1.2303231800.00
1.2303151621.00
1.2303151529.00
1.2302271541.00
1.2302171719.00
1.2302031721.00
1.2302021743.00
1.2302012254.00
1.2301301810.00
1.2301261900.00
1.2301181928.00
1.2301112346.00
1.2301100345.00
1.2301041800.00
1.2301032153.00
1.2301031703.00
1.2212151632.20
1.2211302304.20
1.2212151632.10
1.2212151632.00
1.2211302304.10
1.2212092023.00
1.2212071834.00
1.2211302304.00
1.2211250451.00
1.2211182146.00
1.2211151402.00
1.2211111611.00
1.2211060024.00
1.2211042305.00
1.2210272257.00
1.2210251605.00
1.2210211855.00
1.2210191347.00
1.2210172057.00
1.2210142102.01
1.2210112333.00
1.2210071758.00
1.2210052034.00
1.2210041838.00
1.2210010655.01
1.2209142312.00
1.2208242209.11
1.2209131909.00
1.2209072154.00
1.2208242209.00
1.2208172101.00
1.2208051912.10
1.2208121708.00
1.2208112015.00
1.2207281718.20
1.2207281718.10
1.2208092047.00
1.2208081650.00
1.2208051912.00
1.2208042017.00
1.2208021808.00
1.2207281718.00
1.2207261725.00
1.2207221643.00
1.2207201724.02
1.2207181727.00
1.2207071723.00
1.2206291614.00
1.2206221455.00
1.2206162023.02
1.2206071918.10
1.2206131450.00
1.2206101637.00
1.2205270638.40
1.2206082301.00
1.2206072228.00
1.2206071918.00
1.2205270638.00
1.2205251942.02
1.2205120110.10
1.2205232225.01
1.2205191749.00
1.2205181800.02
1.2205161914.00
1.2205120110.01
1.2205101904.00
1.2205090810.00
1.2205051832.00
1.2205041533.00
1.2205031420.00
1.2204292129.00
1.2204281949.00
1.2204272205.02
1.2204252045.01
1.2204221712.00
1.2204211736.00
1.2204191429.01
1.2204182206.00
1.2204160405.00
1.2204142048.00
1.2204132005.00
1.2204122000.00
1.2204121632.00
1.2203281422.01
1.2203101844.01
1.2203231914.00
1.2203221937.00
1.2203172113.00
1.2203151539.00
1.2203041950.00
1.2202230359.10
1.2202252101.00
1.2202241911.00
1.2202232232.00
1.2202230359.00
1.2202180255.00
1.2202162256.00
1.2202152253.00
1.2202042210.10
1.2202142035.00
1.2202112230.01
1.2202092050.00
1.2202082004.00
1.2201262038.10
1.2202072236.00
1.2202042210.00
1.2202031816.00
1.2202022130.00
1.2202012258.00
1.2201212122.30
1.2201141909.40
1.2201141909.30
1.2201141909.10
1.2201141909.00
1.2201131702.00
1.2201122239.00
1.2112231523.20
1.2201120015.00
1.2112231523.10
1.2201101902.00
1.2201071715.00
1.2201061922.00
1.2201052144.00
1.2201042109.00
1.2112231523.00
1.2112221739.00
1.2112212349.00
1.2112201724.00
1.2112170012.00
1.2112162055.00
1.2112160003.00
1.2112132331.00
1.2112102136.00
1.2112091956.00
1.2111242025.10
1.2112082232.00
1.2112080230.10
1.2112080230.00
1.2112062322.20
1.2112062322.00
1.2112032204.00
1.2112021656.00
1.2112012300.00
1.2112010058.00
1.2111152338.20
1.2111292120.00
1.2111242025.00
1.2111230636.00
1.2111230244.00
1.2111191951.00
1.2111060251.90
1.2111182332.00
1.2111060251.30
1.2111180040.00
1.2111022043.00
1.2110212130.20
1.2110152252.30
1.2111011823.00
1.2110290545.00
1.2110281959.00
1.2110252343.00
1.2110261518.00

Package Sidebar

Install

npm i @bentoproject/embedly-card

Weekly Downloads

35

Version

1.2305051745.1

License

Apache-2.0

Unpacked Size

1.2 MB

Total Files

29

Last publish

Collaborators

  • bentoprojectbot
  • kristoferbaxter
  • esth