Skip to content

Commit

Permalink
Replace duplicated icon size styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmockett committed Jun 13, 2024
1 parent ab51dc4 commit 3534fe6
Showing 1 changed file with 22 additions and 47 deletions.
69 changes: 22 additions & 47 deletions libs/@guardian/source/src/react-components/button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ const button = css`
&:focus {
${focusHaloSpaced};
}
svg {
flex: 0 0 auto;
display: block;
position: relative;
}
`;

const primary = (button: ThemeButton): SerializedStyles => css`
Expand Down Expand Up @@ -99,6 +105,10 @@ const defaultSize = css`
padding: 0 ${space[5]}px;
border-radius: ${height.ctaMedium}px;
padding-bottom: 2px;
.src-button-space {
width: ${space[3]}px;
}
`;

const smallSize = css`
Expand All @@ -108,6 +118,10 @@ const smallSize = css`
padding: 0 ${space[4]}px;
border-radius: ${height.ctaSmall}px;
padding-bottom: 2px;
.src-button-space {
width: ${space[2]}px;
}
`;

const xsmallSize = css`
Expand All @@ -117,44 +131,16 @@ const xsmallSize = css`
padding: 0 ${space[3]}px;
border-radius: ${height.ctaXsmall}px;
padding-bottom: 1px;
`;

const iconDefault = css`
svg {
flex: 0 0 auto;
display: block;
position: relative;
}
.src-button-space {
width: ${space[3]}px;
}
`;
const iconSmall = css`
svg {
flex: 0 0 auto;
display: block;
position: relative;
}
.src-button-space {
width: ${space[2]}px;
}
`;

const iconXsmall = css`
svg {
flex: 0 0 auto;
display: block;
position: relative;
}
.src-button-space {
width: ${space[1]}px;
}
`;

/* TODO: we add some negative margin to icons to account for
the extra space encoded into the SVG. We should consider removing
or significantly reducing this space
/**
* TODO: we add some negative margin to icons to account for the extra space
* encoded into the SVG. We should consider removing or significantly reducing
* this space.
*/
const pullIconTowardEdge = -space[1];

Expand All @@ -171,22 +157,18 @@ const iconRight = css`
}
`;

const iconOnly = css`
padding: 0;
`;

const iconOnlyDefault = css`
${iconOnly};
padding: 0;
width: ${width.ctaMedium}px;
`;

const iconOnlySmall = css`
${iconOnly};
padding: 0;
width: ${width.ctaSmall}px;
`;

const iconOnlyXsmall = css`
${iconOnly};
padding: 0;
width: ${width.ctaXsmall}px;
`;

Expand Down Expand Up @@ -226,13 +208,7 @@ const sizes: {
small: smallSize,
xsmall: xsmallSize,
};
const iconSizes: {
[key in Size]: SerializedStyles;
} = {
default: iconDefault,
small: iconSmall,
xsmall: iconXsmall,
};

const iconOnlySizes: {
[key in Size]: SerializedStyles;
} = {
Expand Down Expand Up @@ -264,7 +240,6 @@ export const buttonStyles =
button,
sizes[size],
priorities[priority](mergedTheme(providerTheme.button, theme)),
iconSvg ?? isLoading ? iconSizes[size] : '',
(iconSvg ?? isLoading) && !hideLabel ? iconSides[iconSide] : '',
nudgeIcon ? iconNudgeAnimation : '',
hideLabel ? iconOnlySizes[size] : '',
Expand Down

0 comments on commit 3534fe6

Please sign in to comment.