Skip to content
Open
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
24 changes: 0 additions & 24 deletions dotcom-rendering/src/components/GalleryCaption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,10 @@ const styles = css`

${between.desktop.and.leftCol} {
${grid.column.right}

position: relative; /* allows the ::before to be positioned relative to this */

&::before {
content: '';
position: absolute;
left: -10px; /* 10px to the left of this element */
top: 0;
bottom: 0;
width: 1px;
background-color: ${palette('--article-border')};
}
}

${from.leftCol} {
${grid.column.left}

position: relative; /* allows the ::before to be positioned relative to this */

&::after {
content: '';
position: absolute;
right: -11px;
top: -12px;
bottom: 0;
width: 1px;
background-color: ${palette('--article-border')};
}
}
`;

Expand Down
7 changes: 5 additions & 2 deletions dotcom-rendering/src/components/GalleryImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ type Props = {
};

const styles = css`
overflow: hidden;
${grid.paddedContainer}
${grid.verticalRules()}
${grid.verticalRules({ plusChild: 1 })}
grid-auto-flow: row dense;
background-color: ${palette('--article-inner-background')};

Expand All @@ -34,7 +35,9 @@ const styles = css`

${from.desktop} {
&:first-of-type {
padding-top: ${space[3]}px;
& > * {
padding-top: ${space[3]}px;
}
}
}
`;
Expand Down
50 changes: 35 additions & 15 deletions dotcom-rendering/src/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,54 @@ const paddedContainer = `
// ----- Vertical Rules ----- //

type VerticalRuleOptions = {
centre?: boolean;
plusChild?: number;
};

/**
* Render Guardian grid vertical rules.
*
* Left and right rules are always present.
* A centre rule can optionally be enabled.
* A centre rule can optionally be enabled, anchored to the nth
* child of the grid container as specified by the `plusChild` option
*
* Usage:
* css([grid.container, grid.verticalRules()])
* css([grid.container, grid.verticalRules({ centre: true })])
* css([grid.container, grid.verticalRules({ plusChild: 3 })])
*/
const optionalCentreRule = `/* CENTRE RULE */
& > *:first-child::before {
grid-column: centre-column-start;
transform: translateX(-${columnGap});
${fromBreakpoint.leftCol} {
transform: translateX(calc(-${columnGap} / 2));
}

// The centre rule is self-contained on the nth child element rather than on
// the grid container, so that `top: 0` aligns to that element's top edge.
// `bottom` uses a large negative value to extend the rule down to the
// container's bottom; ensure `overflow: hidden` is set on the container
const optionalCentreRule = (nth: number): string => `/* CENTRE RULE */
& > *:nth-child(${nth}) {
position: relative;

&::before {
position: absolute;
top: 0;
bottom: -9999px;
width: 1px;
background-color: ${palette('--article-border')};
content: '';
grid-column: centre-column-start;
transform: translateX(-${columnGap});

${fromBreakpoint.leftCol} {
transform: translateX(calc(-${columnGap} / 2));
}
}
}`;

const verticalRules = (options: VerticalRuleOptions = {}): string => `
const verticalRules = (options: VerticalRuleOptions = {}): string => {
const { plusChild } = options;

return `
${fromBreakpoint.tablet} {
position: relative;

&::before,
&::after
${options.centre ? ', & > *:first-child::before' : ''} {
&::after {
position: absolute;
top: 0;
bottom: 0;
Expand Down Expand Up @@ -145,8 +164,9 @@ const verticalRules = (options: VerticalRuleOptions = {}): string => `
}
}

${options.centre ? optionalCentreRule : ''}
`;
${plusChild !== undefined ? optionalCentreRule(plusChild) : ''}
}`;
};

// ----- API ----- //

Expand Down
Loading