Skip to content

Commit

Permalink
Add support for custom figure attribution position
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva committed Aug 25, 2023
1 parent 71be322 commit 17952ab
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions app/scripts/components/common/figure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import T from 'prop-types';
import styled from 'styled-components';
import styled, { css } from 'styled-components';

import { glsp, themeVal, truncated } from '@devseed-ui/theme-provider';
import { Subtitle } from '@devseed-ui/typography';
Expand Down Expand Up @@ -45,10 +45,34 @@ export const FigcaptionInner = styled(Subtitle).attrs({
}
`;

function renderAttributionPosition(props) {
const { position } = props;

switch (position) {
case 'top-left':
return css`
top: ${variableGlsp()};
left: ${variableGlsp()};`;
case 'bottom-left':
return css`
bottom: ${variableGlsp()};
left: ${variableGlsp()};`;
case 'bottom-right':
return css`
bottom: ${variableGlsp()};
right: ${variableGlsp()};
`;
// top-right
default:
return css`
top: ${variableGlsp()};
right: ${variableGlsp()};
`;
}
}

export const FigureAttributionSelf = styled.p`
position: absolute;
top: ${variableGlsp()};
right: ${variableGlsp()};
z-index: 40;
max-width: calc(100% - ${glsp(2)}); /* stylelint-disable-line */
height: 1.5rem;
Expand All @@ -60,6 +84,8 @@ export const FigureAttributionSelf = styled.p`
background: ${themeVal('color.base-400a')};
overflow: hidden;
${renderAttributionPosition}
a,
a:visited {
color: inherit;
Expand Down Expand Up @@ -99,7 +125,7 @@ const FigureAttributionInner = styled.span`
`;

function FigureAttributionCmp(props) {
const { author, url, ...rest } = props;
const { author, url, position, ...rest } = props;

if (!author) return null;

Expand All @@ -113,7 +139,7 @@ function FigureAttributionCmp(props) {
: {};

return (
<FigureAttributionSelf {...rest}>
<FigureAttributionSelf position={position} {...rest}>
<FigureAttributionInner {...innerProps}>
<CollecticonCircleInformation />
<strong>Figure by {author}</strong>
Expand All @@ -128,5 +154,6 @@ export const FigureAttribution = styled(FigureAttributionCmp)`

FigureAttributionCmp.propTypes = {
author: T.string,
url: T.string
url: T.string,
position: T.oneOf(['top-left', 'top-right', 'bottom-left', 'bottom-right'])
};

0 comments on commit 17952ab

Please sign in to comment.