Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ampproject/amp-embedly-card

Package Overview
Dependencies
Maintainers
16
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ampproject/amp-embedly-card

AMP HTML amp-embedly-card Component

  • 1.2110011758.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-77.78%
Maintainers
16
Weekly downloads
 
Created
Source

Bento Embedly Card

Behavior

The Bento Embedly Card component provides you with responsive and shareable embeds to drive the reach of your websites, blog posts, and articles from any URL using Embedly cards. Use it as a web component <bento-embedly-card>, or a Preact/React functional component <BentoEmbedlyCard>.

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.

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

Example: Import via npm

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

Install via npm:

npm install @ampproject/bento-embedly-card
import '@ampproject/bento-embedly-card';

[/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-embedly-card {
      display: block;
      overflow: hidden;
      position: relative;
    }
  </style>
  <script 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>

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

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

<style data-bento-boilerplate>
  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".

Preact/React Component

The examples below demonstrate use of the <BentoEmbedlyCard> 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-embedly-card
import React from 'react';
import { BentoEmbedlyCard } from '@ampproject/bento-embedly-card/react';
import '@ampproject/bento-embedly-card/styles.css';

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

[/example]

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: '300px', height: '100px'}} 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".

FAQs

Package last updated on 14 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc