Skip to content

Commit 1ae06f4

Browse files
authored
Merge pull request #4 from trydionel/DEVELOP-1138-bugfixes
[DEVELOP-1138] Small revisions to component UX
2 parents 7d5e319 + f1b7105 commit 1ae06f4

File tree

4 files changed

+438
-37
lines changed

4 files changed

+438
-37
lines changed

src/components/AspectRatio.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
3+
export interface AspectRatioProps {
4+
aspectRatio: number;
5+
children: any;
6+
}
7+
8+
export const AspectRatio = ({ aspectRatio, children }: AspectRatioProps) => (
9+
<div style={{ position: 'relative', paddingTop: `${100 / aspectRatio}%` }}>
10+
<div
11+
style={{
12+
position: 'absolute',
13+
top: 0,
14+
left: 0,
15+
width: '100%',
16+
height: '100%',
17+
}}
18+
>
19+
{children}
20+
</div>
21+
</div>
22+
);

src/components/EmbeddedContent.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import { AspectRatio } from "./AspectRatio";
23

34
export interface EmbeddedContentProps {
45
src: string;
@@ -12,18 +13,18 @@ export interface EmbeddedContentProps {
1213
*/
1314
export const EmbeddedContent = ({
1415
src,
15-
aspectRatio = 16 / 9,
16-
}: EmbeddedContentProps) => (
17-
<div style={{ position: "relative", paddingTop: `${100 / aspectRatio}%` }}>
18-
<div
19-
style={{
20-
position: "absolute",
21-
top: 0,
22-
left: 0,
23-
width: "100%",
24-
height: "100%",
25-
}}
26-
>
16+
aspectRatio = 4 / 3,
17+
}: EmbeddedContentProps) => {
18+
if (!src) {
19+
return (
20+
<aha-box>
21+
<p>No URL provided</p>
22+
</aha-box>
23+
)
24+
}
25+
26+
return (
27+
<AspectRatio aspectRatio={aspectRatio}>
2728
<iframe
2829
src={aha.sanitizeUrl(src)}
2930
width="100%"
@@ -37,6 +38,6 @@ export const EmbeddedContent = ({
3738
>
3839
Unable to load content
3940
</iframe>
40-
</div>
41-
</div>
42-
);
41+
</AspectRatio>
42+
)
43+
}

src/patterns/EmbeddedContentAttribute.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface EmbeddedContentAttributeProps {
1111
placeholder: string | undefined;
1212
/** Optional function that allows component to modify supplied user input before saving */
1313
onLinkUpdated?: LinkUpdatedCallback;
14+
aspectRatio?: number;
1415
}
1516

1617
/**
@@ -26,14 +27,15 @@ export const EmbeddedContentAttribute = ({
2627
product,
2728
placeholder,
2829
onLinkUpdated = (v) => v,
30+
aspectRatio = 4 / 3,
2931
}: EmbeddedContentAttributeProps) => {
30-
const fieldName = `${product.replace(/\s+/g, "")}:link`;
32+
const fieldName = `${product.replace(/\s+/g, '')}:link`
3133
const src = fields[fieldName] as string;
3234

3335
const openLink = () => {
3436
const sanitized = aha.sanitizeUrl(src);
35-
window.open(sanitized, "_blank", "noopener,noreferrer");
36-
};
37+
window.open(sanitized, '_blank', 'noopener,noreferrer');
38+
}
3739

3840
const setLink = (e: React.ChangeEvent<HTMLInputElement>) => {
3941
let value = e.target.value;
@@ -63,16 +65,19 @@ export const EmbeddedContentAttribute = ({
6365

6466
return (
6567
<div
66-
style={{ display: "grid", gridTemplateColumns: "1fr auto", gridGap: 10 }}
68+
style={{ display: 'grid', alignItems: 'start', gridTemplateColumns: '1fr auto', gridGap: 10 }}
6769
>
68-
<EmbeddedContent src={src} />
70+
<EmbeddedContent src={src} aspectRatio={aspectRatio} />
6971
<aha-menu>
7072
<aha-button slot="button" type="attribute" size="small">
7173
<aha-icon icon="fa-solid fa-ellipsis"></aha-icon>
7274
</aha-button>
7375
<aha-menu-item onClick={openLink}>View in {product}</aha-menu-item>
74-
<aha-menu-item onClick={removeLink}>Remove</aha-menu-item>
76+
<hr />
77+
<aha-menu-item onClick={removeLink}>
78+
<span className="text-error">Remove</span>
79+
</aha-menu-item>
7580
</aha-menu>
7681
</div>
77-
);
82+
)
7883
};

0 commit comments

Comments
 (0)