Skip to content

Commit

Permalink
fix spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
silvalaura committed Oct 4, 2023
1 parent 3dfb148 commit 0c53a36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
15 changes: 10 additions & 5 deletions packages/react-magma-dom/src/components/InputBase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,15 @@ const IconButtonContainer = styled.span<{
const PasswordButtonContainer = styled.span<{
size?: InputSize;
theme: ThemeInterface;
buttonWidth: string;
buttonWidth: number;
}>`
background-color: transparent;
width: 0;
transform: translate(
-${props => props.buttonWidth},
${props =>
props.size === InputSize.large
? `${-props.buttonWidth - 8}px`
: `${-props.buttonWidth - 6}px`},
${props =>
props.size === InputSize.large ? props.theme.spaceScale.spacing03 : '6px'}
);
Expand Down Expand Up @@ -617,6 +620,10 @@ export const InputBase = React.forwardRef<HTMLInputElement, InputBaseProps>(
setValue(event.target.value);
}

const passwordBtnWidth = Number(
children?.props?.children[0].ref?.current?.offsetWidth
);

return (
<InputContainer>
<InputWrapper
Expand Down Expand Up @@ -735,9 +742,7 @@ export const InputBase = React.forwardRef<HTMLInputElement, InputBaseProps>(
inputSize === InputSize.large ? InputSize.large : InputSize.medium
}
theme={theme}
buttonWidth={
children?.props?.children[0].ref?.current?.offsetWidth + 6 + 'px'
}
buttonWidth={passwordBtnWidth}
>
{children}
</PasswordButtonContainer>
Expand Down
19 changes: 15 additions & 4 deletions packages/react-magma-dom/src/components/PasswordInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,25 @@ export const PasswordInput = React.forwardRef<
HIDE_PASSWORD_BUTTON_TEXT === i18n.password.hidden.buttonText;

const buttonRef = React.useRef<HTMLButtonElement>();

const getButtonWidth = () => {
if (usesDefaultText) {
if (inputSize === InputSize.large) {
return '64px';
}
return '54px';
} else {
return `${buttonRef?.current?.offsetWidth}px`;
}
}

const getInputStyle = () => {
if (isPasswordMaskButtonHidden) {
return {};
} else if (inputSize === InputSize.medium && usesDefaultText) {
return { width: 'calc(100% - 52px)' };
} else if (inputSize === InputSize.large && usesDefaultText) {
return { width: 'calc(100% - 56px)' };
return { width: 'calc(100% - 64px)' };
} else {
return { width: `calc(100% - ${buttonRef?.current?.offsetWidth}px)` };
}
Expand Down Expand Up @@ -190,11 +201,11 @@ export const PasswordInput = React.forwardRef<
: ButtonSize.medium
}
style={{
borderRadius: theme.borderRadius,
borderRadius: theme.borderRadiusSmall,
margin: '0 3px 0 0',
width: usesDefaultText ? '54px' : null,
width: getButtonWidth(),
minWidth: 0,
maxWidth: `${buttonRef?.current?.offsetWidth}px`,
maxWidth: getButtonWidth(),
}}
type={ButtonType.button}
variant={ButtonVariant.link}
Expand Down

0 comments on commit 0c53a36

Please sign in to comment.