Skip to content

Commit

Permalink
feat: polished wrapper prop for <FrameMetadata /> component (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia authored Feb 7, 2024
1 parent e5b305a commit f9f7652
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/honest-tigers-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@coinbase/onchainkit': patch
---

- **feat**: added `wrapper` prop to `<FrameMetadata />` component, that defaults to `React.Fragment` when not passed (original behavior). By @syntag #90 #91
- **feat**: exported `FrameMetadataResponse` type which can be useful when using `getFrameMetadata` in a TS project. By @syntag #90
4 changes: 2 additions & 2 deletions src/components/FrameMetadata.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ describe('FrameMetadata', () => {
expect(meta.container.querySelectorAll('meta').length).toBe(3);
});

it('renders with wrapperComponent', () => {
it('renders with wrapper', () => {
const meta = render(
<FrameMetadata
image="https://example.com/image.png"
wrapperComponent={({ children }) => <div id="wrapper">{children}</div>}
wrapper={({ children }) => <div id="wrapper">{children}</div>}
/>,
);

Expand Down
16 changes: 10 additions & 6 deletions src/components/FrameMetadata.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Fragment } from 'react';
import type { FrameMetadataType } from '../core/types';

type FrameMetadataReact = FrameMetadataType & {
wrapper?: React.ComponentType<any>;
};

/**
* FrameMetadata component
*
Expand All @@ -27,13 +31,13 @@ import type { FrameMetadataType } from '../core/types';
* />
* ```
*
* @param {FrameMetadataType} props - The metadata for the frame.
* @param {FrameMetadataReact} props - The metadata for the frame.
* @param {string} props.image - The image URL.
* @param {string} props.input - The input text.
* @param {string} props.post_url - The post URL.
* @param {number} props.refresh_period - The refresh period.
* @param {Array<{ label: string, action?: string }>} props.buttons - The buttons.
* @param {React.ComponentType<any> | undefined} props.wrapperComponent - The wrapper component meta tags are rendered in.
* @param {React.ComponentType<any> | undefined} props.wrapper - The wrapper component meta tags are rendered in.
* @returns {React.ReactElement} The FrameMetadata component.
*/
export function FrameMetadata({
Expand All @@ -42,10 +46,10 @@ export function FrameMetadata({
input,
post_url,
refresh_period,
wrapperComponent: WrapperComponent = Fragment,
}: FrameMetadataType) {
wrapper: Wrapper = Fragment,
}: FrameMetadataReact) {
return (
<WrapperComponent>
<Wrapper>
<meta name="fc:frame" content="vNext" />
{!!image && <meta name="fc:frame:image" content={image} />}
{!!input && <meta name="fc:frame:input:text" content={input.text} />}
Expand All @@ -66,6 +70,6 @@ export function FrameMetadata({
{!!refresh_period && (
<meta name="fc:frame:refresh_period" content={refresh_period.toString()} />
)}
</WrapperComponent>
</Wrapper>
);
}
1 change: 0 additions & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export type FrameMetadataType = {
input?: FrameInputMetadata;
post_url?: string;
refresh_period?: number;
wrapperComponent?: React.ComponentType<any>;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.5.0';
export const version = '0.5.1';

0 comments on commit f9f7652

Please sign in to comment.