Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added responsive styles to embeds #172

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion components/common/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ type RichTextImageProps = {
};
};

const RichTextStyles = styled.div`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because these styled components are still components, I wouldn't name it as just --Styles, even thought styling is here the only reason for the component's existence. I would maybe call these StyledRichText or RichTextContainer or something like that. (I think we have used at least Styled* elsewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. Thank you for a suggestion.

.responsive-object {
position: relative;
}

.responsive-object iframe,
.responsive-object object,
.responsive-object embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
`;

function ICompress() {
// eslint-disable-next-line max-len
return React.createElement(
Expand Down Expand Up @@ -239,7 +255,7 @@ export default function RichText(props: RichTextProps) {

return (
<div {...rest} className={`text-content ${className || ''}`}>
{parsedContent}
<RichTextStyles>{parsedContent}</RichTextStyles>
</div>
);
}
34 changes: 33 additions & 1 deletion components/common/StreamField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import AccessibilityStatementContactInformationBlock from 'components/contentblo
import type { StreamFieldFragmentFragment } from 'common/__generated__/graphql';
import CartographyVisualisationBlock from 'components/contentblocks/CartographyVisualisationBlock';
import { useTheme } from 'common/theme';
import styled from 'styled-components';

const STREAM_FIELD_FRAGMENT = gql`
fragment StreamFieldFragment on StreamFieldInterface {
Expand Down Expand Up @@ -275,6 +276,35 @@ const STREAM_FIELD_FRAGMENT = gql`
${CategoryListBlock.fragments.category}
`;

const ResponsiveStyles = styled.div`
.responsive-object {
width: 100%;
text-align: center;
}

.responsive-object iframe,
.responsive-object object,
.responsive-object embed {
width: 100%;
height: 100%;
}

.responsive-object-small iframe {
aspect-ratio: 16 / 9;
max-width: 300px;
}

.responsive-object-medium iframe {
aspect-ratio: 16 / 9;
max-width: 480px;
}

.responsive-object-large iframe {
aspect-ratio: 16 / 9;
max-width: 960px;
}
`;

type StreamFieldBlockProps = {
id: string;
page: any;
Expand Down Expand Up @@ -457,7 +487,9 @@ function StreamFieldBlock(props: StreamFieldBlockProps) {
md={{ size: 10, offset: 1 }}
className="my-4"
>
<div dangerouslySetInnerHTML={{ __html: block.embed.html }}></div>
<ResponsiveStyles
dangerouslySetInnerHTML={{ __html: block.embed.html }}
></ResponsiveStyles>
</Col>
</Row>
</Container>
Expand Down