Skip to content

Commit

Permalink
Refactor getZIndex
Browse files Browse the repository at this point in the history
Changed the function to return just the `z-index` value rather than the CSS declaration. This should prove more flexible. One example of this is that it can be used with `!important` without requiring an addition to the API.

It also makes it easier to test. As a consequence this change also updates the tests to more accurately reflect that we care what the z-indices are relative to one another, not their absolute values.
  • Loading branch information
JamieB-gu committed Nov 22, 2024
1 parent c9808f8 commit bafc352
Show file tree
Hide file tree
Showing 35 changed files with 62 additions and 86 deletions.
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/AdSlot.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const mobileStickyAdStyles = css`
margin: 0 auto;
right: 0;
left: 0;
${getZIndex('mobileSticky')}
z-index: ${getZIndex('mobileSticky')};
${from.phablet} {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/ArticleHeadline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const immersiveWrapper = css`
This z-index is what ensures the headline text shows above the pseudo black
box that extends the black background to the right
*/
${getZIndex('articleHeadline')}
z-index: ${getZIndex('articleHeadline')};
${until.mobileLandscape} {
margin-right: 40px;
}
Expand Down
12 changes: 8 additions & 4 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ export const Card = ({
href={`${linkTo}#comments`}
cssOverrides={css`
/* See: https://css-tricks.com/nested-links/ */
${getZIndex('card-nested-link')}
z-index: ${getZIndex('card-nested-link')};
/* The following styles turn off those provided by Link */
color: inherit;
color: inherit;
/* stylelint-disable-next-line property-disallowed-list */
font-family: inherit;
font-size: inherit;
Expand Down Expand Up @@ -614,7 +614,9 @@ export const Card = ({
<div
css={css`
position: relative;
${getZIndex('card-nested-link')}
z-index: ${getZIndex(
'card-nested-link',
)};
`}
>
<Island
Expand Down Expand Up @@ -654,7 +656,9 @@ export const Card = ({
css={css`
display: block;
position: relative;
${getZIndex('card-nested-link')}
z-index: ${getZIndex(
'card-nested-link',
)};
`}
>
<Island
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const brandingWrapperStyle = css`
text-align: right;
flex: auto;
/* See: https://css-tricks.com/nested-links/ */
${getZIndex('card-nested-link')}
z-index: ${getZIndex('card-nested-link')};
position: relative;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getZIndex } from '../../../lib/getZIndex';

const fauxLinkStyles = css`
position: absolute;
${getZIndex('card-link')};
z-index: ${getZIndex('card-link')};
top: 0;
right: 0;
bottom: 0;
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/CardHeadline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const getFontSize = (
const sublinkStyles = css`
display: block;
/* See: https://css-tricks.com/nested-links/ */
${getZIndex('card-nested-link')}
z-index: ${getZIndex('card-nested-link')};
/* The following styles turn off those provided by Link */
color: inherit;
text-decoration: none;
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/Carousel.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const buttonContainerStyle = css`
flex-direction: column;
justify-content: center;
position: absolute;
${getZIndex('onwardsCarousel')}
z-index: ${getZIndex('onwardsCarousel')};
height: 100%;
padding-bottom: 36px; /* Align buttons centrally with cards */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const buttonContainerStyle = css`
flex-direction: column;
justify-content: center;
position: absolute;
${getZIndex('onwardsCarousel')}
z-index: ${getZIndex('onwardsCarousel')};
height: 100%;
padding-bottom: 36px; /* Align buttons centrally with cards */
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Position = ({
css={css`
/* Decide where the content revealed by details appears */
position: absolute;
${getZIndex('summaryDetails')}
z-index: ${getZIndex('summaryDetails')};
${positionStyles}
`}
>
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/Dropdown.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface Props {
}

const ulStyles = css`
${getZIndex('dropdown')}
z-index: ${getZIndex('dropdown')};
list-style: none;
/* https://developer.mozilla.org/en-US/docs/Web/CSS/list-style#accessibility_concerns */
/* Needs double escape char: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#es2018_revision_of_illegal_escape_sequences */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const container = css`
position: relative;
top: 0;
background-color: ${palette.brand[800]};
${getZIndex('editionSwitcherBanner')};
z-index: ${getZIndex('editionSwitcherBanner')};
`;

const content = css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const hideBannerStyles = css`
const stickyContainerStyles = css`
position: sticky;
top: 0;
${getZIndex('expandableMarketingCardOverlay')};
z-index: ${getZIndex('expandableMarketingCardOverlay')};
/* The component slides in from the left-hand side */
animation: slidein 2.4s linear;
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/FeatureCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const CommentCount = ({
href={`${linkTo}#comments`}
cssOverrides={css`
/* See: https://css-tricks.com/nested-links/ */
${getZIndex('card-nested-link')}
z-index: ${getZIndex('card-nested-link')};
/* The following styles turn off those provided by Link */
color: inherit;
/* stylelint-disable-next-line property-disallowed-list */
Expand Down
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/GridItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const rightColumnStyles = css`
top: 0;
right: 0;
/* Pop me below the body */
${getZIndex('rightColumnArea')}
z-index: ${getZIndex('rightColumnArea')};
@supports (display: grid) {
position: relative;
Expand All @@ -25,7 +25,7 @@ const rightColumnStyles = css`

const bodyStyles = css`
/* Pop me above the right column */
${getZIndex('bodyArea')}
z-index: ${getZIndex('bodyArea')};
`;

const gridArea = css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const stickyNavBaseStyles = css`
background-color: ${sourcePalette.neutral[100]};
border: 1px solid ${sourcePalette.neutral[86]};
top: 0;
${getZIndex('banner')}
z-index: ${getZIndex('banner')};
`;

const olStyles = css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const LightboxLayout = ({ format, images }: Props) => {
html.lightbox-open {
#gu-lightbox {
position: fixed;
${getZIndex('lightbox')};
z-index: ${getZIndex('lightbox')};
}
body {
Expand Down
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/MainMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const immersiveWrapper = css`
we use this grow here to ensure the content fills the available height
*/
flex-grow: 1;
${getZIndex('mainMedia')}
z-index: ${getZIndex('mainMedia')};
/* Prevent the immersive image 100vh from spilling into main content */
overflow: hidden;
overflow: hidden;
`;

const chooseWrapper = (format: ArticleFormat) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface EditionDropdownProps {
}

const editionDropdownStyles = css`
${getZIndex('mastheadEditionDropdown')};
z-index: ${getZIndex('mastheadEditionDropdown')};
display: flex;
/** Required to absolutely position the dropdown menu */
position: relative;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const expandedMenuStyles = css`
`;

const wrapperMainMenuStyles = css`
${getZIndex('expanded-veggie-menu-wrapper')}
z-index: ${getZIndex('expanded-veggie-menu-wrapper')};
left: 0;
top: 0;
Expand All @@ -62,7 +62,7 @@ const wrapperMainMenuStyles = css`
const mainMenuStyles = css`
background-color: ${themePalette('--masthead-nav-background')};
${textSans20};
${getZIndex('expanded-veggie-menu')}
z-index: ${getZIndex('expanded-veggie-menu')};
left: 0;
top: 0;
box-sizing: border-box;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const labelStyles = css`
${`#${navInputCheckboxId}`}:checked ~ div & {
${until.desktop} {
/* Bump the z-index of the burger menu when expanded */
${getZIndex('mastheadVeggieBurgerExpandedMobile')}
z-index: ${getZIndex('mastheadVeggieBurgerExpandedMobile')};
}
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const containerStyles = css`
position: fixed;
bottom: -1px;
width: 100%;
${getZIndex('banner')}
z-index: ${getZIndex('banner')};
`;

// We can show a Braze banner if:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ const RemoteBanner = ({ module, fetchEmail }: RemoteBannerProps) => {
<div
css={css`
width: 100%;
${getZIndex('banner')}
z-index: ${getZIndex('banner')};
`}
>
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const stickyStyles = css`
position: sticky;
top: 0;
background: ${palette('--article-background')};
${getZIndex('tableOfContents')}
z-index: ${getZIndex('tableOfContents')};
max-height: 100vh;
overflow: scroll;
summary {
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/TopBarMyAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const myAccountLinkStyles = css`
margin: 0 ${space[1]}px 0 0;
}
${getZIndex('mastheadMyAccountDropdown')}
z-index: ${getZIndex('mastheadMyAccountDropdown')};
`;

export const buildIdentityLinks = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const fullscreenStyles = (id: string) => css`
width: 100svw;
/* stylelint-disable-next-line declaration-block-no-duplicate-properties */
height: 100svh;
${getZIndex('youTubeFullscreen')};
z-index: ${getZIndex('youTubeFullscreen')};
}
`;

Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/layouts/AudioLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const usCardStyles = css`
align-self: start;
position: sticky;
top: 0;
${getZIndex('expandableMarketingCardOverlay')}
z-index: ${getZIndex('expandableMarketingCardOverlay')};
${from.leftCol} {
margin-top: ${space[6]}px;
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/layouts/CommentLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const usCardStyles = css`
align-self: start;
position: sticky;
top: 0;
${getZIndex('expandableMarketingCardOverlay')}
z-index: ${getZIndex('expandableMarketingCardOverlay')};
${from.leftCol} {
margin-top: ${space[6]}px;
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/layouts/FullPageInteractiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const NavHeader = ({ article, NAV, format }: Props) => {
<section
/* Note, some interactives require this - e.g. https://www.theguardian.com/environment/ng-interactive/2015/jun/05/carbon-bomb-the-coal-boom-choking-china. */
css={css`
${getZIndex('fullPageInteractiveHeaderWrapper')};
z-index: ${getZIndex('fullPageInteractiveHeaderWrapper')};
position: relative;
`}
>
Expand Down
6 changes: 3 additions & 3 deletions dotcom-rendering/src/layouts/ImmersiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const usCardStyles = css`
align-self: start;
position: sticky;
top: 0;
${getZIndex('expandableMarketingCardOverlay')}
z-index: ${getZIndex('expandableMarketingCardOverlay')};
${from.leftCol} {
margin-top: ${space[6]}px;
Expand Down Expand Up @@ -238,7 +238,7 @@ const Box = ({ children }: { children: React.ReactNode }) => (
width: 50%;
right: 0;
background-color: ${themePalette('--headline-background')};
${getZIndex('immersiveBlackBox')}
z-index: ${getZIndex('immersiveBlackBox')};
top: 0;
bottom: 0;
}
Expand Down Expand Up @@ -410,7 +410,7 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
the text appears above the pseudo Box element
*/
position: relative;
${getZIndex('articleHeadline')};
z-index: ${getZIndex('articleHeadline')};
`}
>
<Section
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/layouts/LiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ export const LiveLayout = (props: WebProps | AppsProps) => {
css={css`
position: sticky;
top: 0;
${getZIndex('toast')};
z-index: ${getZIndex('toast')};
display: flex;
justify-content: center;
`}
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/layouts/ShowcaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const usCardStyles = css`
align-self: start;
position: sticky;
top: 0;
${getZIndex('expandableMarketingCardOverlay')}
z-index: ${getZIndex('expandableMarketingCardOverlay')};
${from.leftCol} {
margin-top: ${space[6]}px;
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/layouts/StandardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const usCardStyles = css`
align-self: start;
position: sticky;
top: 0;
${getZIndex('expandableMarketingCardOverlay')}
z-index: ${getZIndex('expandableMarketingCardOverlay')};
${from.leftCol} {
margin-top: ${space[6]}px;
Expand Down
7 changes: 3 additions & 4 deletions dotcom-rendering/src/layouts/lib/stickiness.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { css } from '@emotion/react';
import type { ZIndex } from '../../lib/getZIndex';
import { getZIndex, getZIndexImportant } from '../../lib/getZIndex';
import { getZIndex, type ZIndex } from '../../lib/getZIndex';
import { palette } from '../../palette';

type Props = {
Expand All @@ -18,7 +17,7 @@ const stickyStyles = css`
`;

const addZindex = (zIndex: ZIndex = 'stickyAdWrapper') => css`
${getZIndex(zIndex)}
z-index: ${getZIndex(zIndex)};
`;

const background = css`
Expand All @@ -30,7 +29,7 @@ const bannerWrapper = css`
/* stylelint-disable-next-line declaration-no-important */
position: fixed !important;
bottom: 0;
${getZIndexImportant('banner')}
z-index: ${getZIndex('banner')} !important;
max-height: 90vh;
overflow: auto;
/* stylelint-disable-next-line declaration-no-important */
Expand Down
Loading

0 comments on commit bafc352

Please sign in to comment.