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

Display image credit in LargeImageBlock #439

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 29 additions & 17 deletions common/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion common/__generated__/possible_types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 26 additions & 7 deletions components/common/StreamField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import IndicatorShowcaseBlock from 'components/contentblocks/IndicatorShowcaseBl
import QuestionAnswerBlock from 'components/contentblocks/QuestionAnswerBlock';
import RelatedIndicatorsBlock from 'components/contentblocks/RelatedIndicatorsBlock';
import RelatedPlanListBlock from 'components/contentblocks/RelatedPlanListBlock';
import { ImageCredit } from 'components/contentblocks/ContentPageHeaderBlock';
import { useTranslations } from 'next-intl';
import { usePlan } from 'context/plan';
import { Col, ColProps, Container, Row } from 'reactstrap';
import { ColumnProps } from 'reactstrap/types/lib/Col';
Expand Down Expand Up @@ -123,6 +125,7 @@ function StreamFieldBlock(props: StreamFieldBlockProps) {
const { __typename } = block;
const plan = usePlan();
const theme = useTheme();
const t = useTranslations();

switch (__typename) {
case 'RichTextBlock': {
Expand Down Expand Up @@ -254,6 +257,7 @@ function StreamFieldBlock(props: StreamFieldBlockProps) {
* fit_to_column: image is limited to text block width
* Image keeps it original ratio and doesn't crop
*/

const getColSize = (breakpoint) => {
if (block.width === 'maximum') return {};
switch (breakpoint) {
Expand All @@ -274,16 +278,31 @@ function StreamFieldBlock(props: StreamFieldBlockProps) {
xl={getColSize('xl')}
lg={getColSize('lg')}
md={getColSize('md')}
style={{
position: 'relative',
}}
>
<img
src={block.image?.renditionUncropped?.src}
alt={block.image?.altText}
<div
style={{
display: 'block',
width: '100%',
marginBottom: theme.spaces.s600,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we keep this marginBottom on the new div element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should! thanks @woodwoerk !

position: 'relative',
display: 'inline-block',
}}
/>
>
<img
src={block.image?.renditionUncropped?.src}
alt={block.image?.altText}
style={{
display: 'block',
width: '100%',
marginBottom: theme.spaces.s600,
}}
/>
{block.image?.imageCredit && (
<ImageCredit>
{`${t('image-credit')}: ${block.image.imageCredit}`}
</ImageCredit>
)}
</div>
</Col>
</Row>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion components/contentblocks/ContentPageHeaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ContentHeader = styled.header`
}
`;

const ImageCredit = styled.span`
export const ImageCredit = styled.span`
position: absolute;
top: 0;
right: 0;
Expand Down
1 change: 1 addition & 0 deletions fragments/stream-field.fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const STREAM_FIELD_FRAGMENT = gql`
renditionUncropped: rendition(size: "1320x1320", crop: false) {
src
}
imageCredit
}
width
}
Expand Down
Loading