Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Update padding logic for sm/xs button
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanbrud committed May 22, 2023
1 parent 76f2ab0 commit 2a26b44
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/components/Button/Button.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const ButtonStyled = styled.button<any>`

const sizePads = {
xxs: 0.125,
xs: 0.25,
sm: 0.5,
xs: 0.3125,
sm: 0.625,
md: 0.75,
lg: 1,
xl: 1.25,
Expand Down Expand Up @@ -134,24 +134,46 @@ function buttonMotion({ theme }) {

function buttonPadding({ icon, iconOnly, iconPosition, size }) {
return (
!iconOnly && iconButtonPadding(icon, iconPosition, sizePads[size])
!iconOnly &&
iconButtonPadding(icon, iconPosition, sizePads[size], size)
);
}

function iconButtonPadding(icon, iconPosition, pad) {
function iconButtonPadding(icon, iconPosition, pad, size) {
const minHeight = rem(3);
const minWidth = `${pad * 4 + 2}rem`;

// Some button sizes are "off" the padding formula based on design decions
const sizeAdjustments = {
xxs: { left: 0, right: 0 },
xs: { left: 0.065, right: 0.19125 },
sm: { left: -0.125, right: -0.125 },
md: { left: 0, right: 0 },
lg: { left: 0, right: 0 },
xl: { left: 0, right: 0 },
xxl: { left: 0, right: 0 },
};

switch (icon && iconPosition) {
case 'left':
return {
padding: '0 ' + pad + 'rem',
padding:
'0 ' +
(pad + sizeAdjustments[size].right) +
'rem 0 ' +
(pad + sizeAdjustments[size].left) +
'rem',
minHeight,
minWidth,
};
case 'right':
return {
padding: '0 ' + pad + 'rem',
padding:
'0 ' +
(pad + sizeAdjustments[size].right) +
'rem 0 ' +
(pad + sizeAdjustments[size].left) +
'rem',
minHeight,
minWidth,
};
Expand Down

0 comments on commit 2a26b44

Please sign in to comment.