Skip to content

Commit

Permalink
refactor UL component to name prop as it is intended to be used rathe…
Browse files Browse the repository at this point in the history
…r than using contextual info
  • Loading branch information
cemms1 committed Nov 29, 2024
1 parent 1970f2c commit 96dbc0c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
24 changes: 14 additions & 10 deletions dotcom-rendering/src/components/Card/components/UL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { palette } from '../../../palette';

type Direction = 'row' | 'column' | 'row-reverse';

const ulStyles = (direction: Direction, isFlexibleContainer: boolean) => css`
const getSpacingPx = (hasLargeSpacing: boolean) =>
hasLargeSpacing ? space[6] : space[3];

const ulStyles = (direction: Direction, spacingPx: number) => css`
width: 100%;
position: relative;
display: flex;
Expand All @@ -16,15 +19,15 @@ const ulStyles = (direction: Direction, isFlexibleContainer: boolean) => css`
}
& > li {
margin-bottom: ${isFlexibleContainer ? space[6] : space[3]}px;
margin-bottom: ${spacingPx}px;
}
@supports (row-gap: 1em) {
& > li {
margin-bottom: 0;
}
/* Supported in flex layout is lacking: https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap#browser_compatibility */
row-gap: ${isFlexibleContainer ? space[6] : space[3]}px;
row-gap: ${spacingPx}px;
}
`;

Expand All @@ -34,8 +37,8 @@ const wrapStyles = css`
}
`;

const marginBottomStyles = (isFlexibleContainer: boolean) => css`
margin-bottom: ${isFlexibleContainer ? space[6] : space[3]}px;
const marginBottom = (spacingPx: number) => css`
margin-bottom: ${spacingPx}px;
`;

const topBarStyles = (splitTopBar: boolean) => css`
Expand Down Expand Up @@ -78,8 +81,8 @@ type Props = {
showTopBar?: boolean;
/** Used to add a gap in the center of the top bar */
splitTopBar?: boolean;
/** Used to give flexible container stories additional space */
isFlexibleContainer?: boolean;
/** Used to give beta containers additional space */
hasLargeSpacing?: boolean;
/** Overrides the vertical divider colour */
verticalDividerColour?: string;
};
Expand All @@ -91,16 +94,17 @@ export const UL = ({
padBottom = false,
wrapCards = false,
showTopBar = false,
isFlexibleContainer = false,
hasLargeSpacing = false,
splitTopBar = false,
verticalDividerColour = palette('--section-border'),
}: Props) => {
const spacingPx = getSpacingPx(hasLargeSpacing);
return (
<ul
css={[
ulStyles(direction, isFlexibleContainer),
ulStyles(direction, spacingPx),
showDivider && verticalDivider(verticalDividerColour),
padBottom && marginBottomStyles(isFlexibleContainer),
padBottom && marginBottom(spacingPx),
wrapCards && wrapStyles,
showTopBar && topBarStyles(splitTopBar),
]}
Expand Down
6 changes: 3 additions & 3 deletions dotcom-rendering/src/components/FlexibleGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const SplashCardLayout = ({
);

return (
<UL padBottom={true} isFlexibleContainer={true} showTopBar={false}>
<UL padBottom={true} hasLargeSpacing={true} showTopBar={false}>
<LI
padSides={true}
verticalDividerColour={palette('--card-border-supporting')}
Expand Down Expand Up @@ -279,7 +279,7 @@ export const BoostedCardLayout = ({
liveUpdatesPosition,
} = decideCardProperties(card.boostLevel);
return (
<UL padBottom={true} isFlexibleContainer={true} showTopBar={true}>
<UL padBottom={true} hasLargeSpacing={true} showTopBar={true}>
<LI
padSides={true}
verticalDividerColour={palette('--card-border-supporting')}
Expand Down Expand Up @@ -338,7 +338,7 @@ export const StandardCardLayout = ({
<UL
direction="row"
padBottom={true}
isFlexibleContainer={true}
hasLargeSpacing={true}
showTopBar={true}
splitTopBar={!isFirstRow}
>
Expand Down
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/FlexibleSpecial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const OneCardLayout = ({
card.supportingContent?.length ?? 0,
);
return (
<UL padBottom={true} isFlexibleContainer={true}>
<UL padBottom={true} hasLargeSpacing={true}>
<LI padSides={true}>
<FrontCard
trail={card}
Expand Down Expand Up @@ -185,7 +185,7 @@ const TwoCardOrFourCardLayout = ({
direction="row"
padBottom={true}
showTopBar={true}
isFlexibleContainer={true}
hasLargeSpacing={true}
>
{cards.map((card, cardIndex) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/StaticFeatureTwo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const StaticFeatureTwo = ({
direction="row"
padBottom={true}
showTopBar={true}
isFlexibleContainer={true}
hasLargeSpacing={true}
>
{cards.map((card) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/StaticMediumFour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const StaticMediumFour = ({
direction="row"
padBottom={true}
showTopBar={true}
isFlexibleContainer={true}
hasLargeSpacing={true}
>
{cards.map((card, cardIndex) => {
return (
Expand Down

0 comments on commit 96dbc0c

Please sign in to comment.