Skip to content

Commit

Permalink
Fix block embeds positioning with float elements
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinewi committed Jan 6, 2025
1 parent 0554aa0 commit 657fcb6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
9 changes: 7 additions & 2 deletions packages/ndla-ui/src/Embed/AudioEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
*/

import { Figure } from "@ndla/primitives";
import { styled } from "@ndla/styled-system/jsx";
import type { AudioMetaData } from "@ndla/types-embed";
import EmbedErrorPlaceholder from "./EmbedErrorPlaceholder";
import type { Author } from "./ImageEmbed";
import AudioPlayer from "../AudioPlayer";
import { EmbedByline } from "../LicenseByline";
import { licenseAttributes } from "../utils/licenseAttributes";

const StyledFigure = styled(Figure, {
base: { clear: "both" },
});

interface Props {
embed: AudioMetaData;
lang?: string;
Expand Down Expand Up @@ -46,7 +51,7 @@ const AudioEmbed = ({ embed, lang }: Props) => {
const licenseProps = licenseAttributes(data.copyright.license.license, lang, embedData.url);

return (
<Figure lang={lang} data-embed-type={type} {...licenseProps}>
<StyledFigure lang={lang} data-embed-type={type} {...licenseProps}>
<AudioPlayer
description={data.podcastMeta?.introduction ?? ""}
img={img}
Expand All @@ -64,7 +69,7 @@ const AudioEmbed = ({ embed, lang }: Props) => {
type={data.audioType === "standard" ? "audio" : "podcast"}
copyright={embed.data.copyright}
/>
</Figure>
</StyledFigure>
);
};

Expand Down
14 changes: 10 additions & 4 deletions packages/ndla-ui/src/Embed/IframeEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const StyledIframe = styled("iframe", {
},
});

const StyledFigure = styled(Figure, {
base: {
clear: "both",
},
});

const IframeEmbed = ({ embed }: Props) => {
const { t } = useTranslation();
const iframeRef = useRef<HTMLIFrameElement>(null);
Expand All @@ -50,15 +56,15 @@ const IframeEmbed = ({ embed }: Props) => {
const alt = embedData.alt !== undefined ? embedData.alt : iframeImage?.alttext.alttext;
const image = { src: iframeImage?.image.imageUrl, alt: alt ?? "" };
return (
<Figure data-embed-type="iframe">
<StyledFigure data-embed-type="iframe">
<ResourceBox
image={image}
title={embedData.title ?? ""}
url={embedData.url}
caption={embedData.caption ?? ""}
buttonText={t("license.other.itemImage.ariaLabel")}
/>
</Figure>
</StyledFigure>
);
}

Expand All @@ -69,7 +75,7 @@ const IframeEmbed = ({ embed }: Props) => {
const urlOrTitle = title || url;

return (
<Figure data-embed-type="iframe">
<StyledFigure data-embed-type="iframe">
<StyledIframe
ref={iframeRef}
title={urlOrTitle}
Expand All @@ -80,7 +86,7 @@ const IframeEmbed = ({ embed }: Props) => {
allow="fullscreen; encrypted-media"
loading="lazy"
/>
</Figure>
</StyledFigure>
);
};

Expand Down
10 changes: 8 additions & 2 deletions packages/ndla-ui/src/Embed/UuDisclaimerEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const StyledSafeLink = styled(SafeLink, {
},
});

const Wrapper = styled("div", {
base: {
clear: "both",
},
});

const UuDisclaimerEmbed = ({ embed, children }: Props) => {
if (embed.status === "error") {
return null;
Expand All @@ -59,7 +65,7 @@ const UuDisclaimerEmbed = ({ embed, children }: Props) => {
) : null;

return (
<div role="region" data-embed-type="uu-disclaimer">
<Wrapper role="region" data-embed-type="uu-disclaimer">
<StyledMessageBox variant="warning" contentEditable={false}>
<InformationLine />
<Disclaimer>
Expand All @@ -68,7 +74,7 @@ const UuDisclaimerEmbed = ({ embed, children }: Props) => {
</Disclaimer>
</StyledMessageBox>
<div data-uu-content="">{children}</div>
</div>
</Wrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const StyledSection = styled("section", {
flexDirection: "column",
alignItems: "center",
gap: "medium",
clear: "both",
},
});

Expand Down
1 change: 1 addition & 0 deletions packages/primitives/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const Table = styled(
maxWidth: "100%",
padding: "4xsmall",
tableLayout: "fixed",
clear: "both",
"& > caption": {
fontWeight: "bold",
textAlign: "left",
Expand Down

0 comments on commit 657fcb6

Please sign in to comment.