Skip to content

Commit 932fec2

Browse files
Add optional aspect ratio to url parameters
1 parent a1b07be commit 932fec2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

integrations/toucantoco/src/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type ToucanRuntimeContext = RuntimeContext<ToucanRuntimeEnvironment>;
1818
const embedBlock = createComponent<{
1919
toucanId?: string;
2020
url?: string;
21+
height?: number;
22+
width?: number;
2123
}>({
2224
componentId: 'embed',
2325

@@ -41,7 +43,16 @@ const embedBlock = createComponent<{
4143

4244
async render(element, context) {
4345
const { environment } = context;
44-
const { toucanId, url } = element.props;
46+
const { toucanId, url, height, width } = element.props;
47+
48+
function getAspectRatio(height?: number, width?: number): number {
49+
if (height && width && height > 0 && width > 0) {
50+
return width / height;
51+
}
52+
return 1;
53+
}
54+
55+
const aspectRatio = getAspectRatio(height, width);
4556

4657
if (!toucanId || !url) {
4758
return (
@@ -62,7 +73,7 @@ const embedBlock = createComponent<{
6273
source={{
6374
url: environment.integration.urls.icon,
6475
}}
65-
aspectRatio={1}
76+
aspectRatio={aspectRatio}
6677
/>
6778
) : undefined
6879
}

integrations/toucantoco/src/toucan.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ export function extractToucanInfoFromURL(input: string):
55
| undefined
66
| {
77
toucanId?: string;
8+
height?: number;
9+
width?: number;
810
} {
911
const url = new URL(input);
1012

1113
// Ignore non-TT URLs
1214
const toucanId = url.searchParams.get('id');
15+
let height = Number(url.searchParams.get('height')) || 100;
16+
let width = Number(url.searchParams.get('width')) || 100;
17+
1318
if (!toucanId || !url.hostname.endsWith('.toucantoco.com')) {
1419
return;
1520
}
1621

17-
return { toucanId };
22+
return { toucanId, height, width };
1823
}

0 commit comments

Comments
 (0)