Skip to content

Commit

Permalink
Rename EmbedlyCard -> BentoEmbedlyCard (ampproject#35977)
Browse files Browse the repository at this point in the history
  • Loading branch information
caroqliu authored and rbeckthomas committed Sep 14, 2021
1 parent f37036a commit 0c43dfe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
16 changes: 8 additions & 8 deletions extensions/amp-embedly-card/1.0/base-element.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import * as Preact from '#preact';
import {PreactBaseElement} from '#preact/base-element';

import {EmbedlyCard} from './component';
import {EmbedlyContext} from './embedly-context';
import {BentoEmbedlyCard} from './component';
import {BentoEmbedlyContext} from './embedly-context';

export class BaseElement extends PreactBaseElement {}

/** @override */
BaseElement['Component'] = EmbedlyCardWithContext;
BaseElement['Component'] = BentoEmbedlyCardWithContext;

/**
* @param {!EmbedlyCardDef.Props} props
* @param {!BentoEmbedlyCardDef.Props} props
* @return {PreactDef.Renderable}
*/
function EmbedlyCardWithContext(props) {
function BentoEmbedlyCardWithContext(props) {
// Extract Embedly Key
const ampEmbedlyKeyElement = document.querySelector('amp-embedly-key');
const apiKey = ampEmbedlyKeyElement?.getAttribute('value') || '';

return (
<EmbedlyContext.Provider value={apiKey}>
<EmbedlyCard {...props}></EmbedlyCard>
</EmbedlyContext.Provider>
<BentoEmbedlyContext.Provider value={apiKey}>
<BentoEmbedlyCard {...props}></BentoEmbedlyCard>
</BentoEmbedlyContext.Provider>
);
}

Expand Down
18 changes: 9 additions & 9 deletions extensions/amp-embedly-card/1.0/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {forwardRef} from '#preact/compat';
import {useValueRef} from '#preact/component';
import {ProxyIframeEmbed} from '#preact/component/3p-frame';

import {EmbedlyContext} from './embedly-context';
import {BentoEmbedlyContext} from './embedly-context';

/**
* Attribute name used to set api key with name
Expand All @@ -18,11 +18,11 @@ const API_KEY_ATTR_NAME = 'data-card-key';
const FULL_HEIGHT = '100%';

/**
* @param {!EmbedlyCardDef.Props} props
* @param {{current: ?EmbedlyCardDef.Api}} ref
* @param {!BentoEmbedlyCardDef.Props} props
* @param {{current: ?BentoEmbedlyCardDef.Api}} ref
* @return {PreactDef.Renderable}
*/
export function EmbedlyCardWithRef(
export function BentoEmbedlyCardWithRef(
{onLoad, requestResize, style, title, url, ...rest},
ref
) {
Expand All @@ -46,11 +46,11 @@ export function EmbedlyCardWithRef(
[requestResize, onLoadRef]
);

const {apiKey} = useContext(EmbedlyContext);
const {apiKey} = useContext(BentoEmbedlyContext);

// Check for valid props
if (!checkProps(url)) {
displayWarning('url prop is required for EmbedlyCard');
displayWarning('url prop is required for BentoEmbedlyCard');
}

// Prepare options for ProxyIframeEmbed
Expand Down Expand Up @@ -96,6 +96,6 @@ function displayWarning(message) {
.warn(message);
}

const EmbedlyCard = forwardRef(EmbedlyCardWithRef);
EmbedlyCard.displayName = 'EmbedlyCard'; // Make findable for tests.
export {EmbedlyCard};
const BentoEmbedlyCard = forwardRef(BentoEmbedlyCardWithRef);
BentoEmbedlyCard.displayName = 'BentoEmbedlyCard'; // Make findable for tests.
export {BentoEmbedlyCard};
6 changes: 3 additions & 3 deletions extensions/amp-embedly-card/1.0/component.type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @externs */

/** @const */
var EmbedlyCardDef = {};
var BentoEmbedlyCardDef = {};

/**
* @typedef {{
Expand All @@ -11,11 +11,11 @@ var EmbedlyCardDef = {};
* url: (string),
* }}
*/
EmbedlyCardDef.Props;
BentoEmbedlyCardDef.Props;

/**
* @typedef {{
* apiKey: (string|undefined),
* }}
*/
EmbedlyCardDef.EmbedlyContext;
BentoEmbedlyCardDef.EmbedlyContext;
6 changes: 3 additions & 3 deletions extensions/amp-embedly-card/1.0/embedly-context.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createContext} from '#preact';

const EmbedlyContext = createContext(
/** @type {EmbedlyCardDef.EmbedlyContext} */ ({apiKey: ''})
const BentoEmbedlyContext = createContext(
/** @type {BentoEmbedlyCardDef.EmbedlyContext} */ ({apiKey: ''})
);
export {EmbedlyContext};
export {BentoEmbedlyContext};
20 changes: 10 additions & 10 deletions extensions/amp-embedly-card/1.0/storybook/Basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ import {text, withKnobs} from '@storybook/addon-knobs';

import * as Preact from '#preact';

import {EmbedlyCard} from '../component';
import {EmbedlyContext} from '../embedly-context';
import {BentoEmbedlyCard} from '../component';
import {BentoEmbedlyContext} from '../embedly-context';

export default {
title: 'EmbedlyCard',
component: EmbedlyCard,
component: BentoEmbedlyCard,
decorators: [withKnobs],
};

export const _default = () => {
return (
<EmbedlyCard
<BentoEmbedlyCard
url="https://www.youtube.com/watch?v=lBTCB7yLs8Y"
title="Embedly Card"
title="BentoEmbedly Card"
style={{width: '400px', height: '400px'}}
/>
);
};

export const WithAPIKey = () => {
const apiKey = text('Embedly API Key', 'valid-api-key');
const apiKey = text('BentoEmbedly API Key', 'valid-api-key');

return (
<EmbedlyContext.Provider value={apiKey}>
<EmbedlyCard
<BentoEmbedlyContext.Provider value={apiKey}>
<BentoEmbedlyCard
url="https://www.youtube.com/watch?v=lBTCB7yLs8Y"
title="Embedly Card"
title="BentoEmbedly Card"
style={{width: '400px', height: '400px'}}
/>
</EmbedlyContext.Provider>
</BentoEmbedlyContext.Provider>
);
};

0 comments on commit 0c43dfe

Please sign in to comment.