Skip to content

Commit

Permalink
chore(clerk-js): remove unused fitTextInOneLine and textWidthForCurre…
Browse files Browse the repository at this point in the history
…ntSize
  • Loading branch information
zythosec committed Oct 25, 2024
1 parent abeb659 commit a101b70
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions packages/clerk-js/src/ui/components/SignIn/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,6 @@ import type { PreferredSignInStrategy, SignInFactor, SignInResource, SignInStrat
import { PREFERRED_SIGN_IN_STRATEGIES } from '../../common/constants';
import { otpPrefFactorComparator, passwordPrefFactorComparator } from '../../utils/factorSorting';

const FONT_SIZE_STEP = 2;

// creates a hidden element and returns what the text's width
// would be if it were rendered inside the parent
function textWidthForCurrentSize(text: string, parent: HTMLElement) {
const hiddenTextContainer = document.createElement('div');
hiddenTextContainer.style.position = 'absolute';
hiddenTextContainer.style.left = '-99in';
hiddenTextContainer.style.whiteSpace = 'nowrap';
hiddenTextContainer.innerHTML = text;

parent.appendChild(hiddenTextContainer);
const result = hiddenTextContainer.clientWidth;
parent.removeChild(hiddenTextContainer);
return result;
}

export function fitTextInOneLine(text: string, containerEl: HTMLElement, defaultSize: string): void {
const getContainerFontSize = () => window.getComputedStyle(containerEl).getPropertyValue('font-size');
const decreaseSize = () => {
const fontSizeWithUnit = getContainerFontSize();
const newSize = (Number.parseInt(fontSizeWithUnit) - FONT_SIZE_STEP) * 0.85;
containerEl.style.fontSize = `${newSize}px`;
};
const increaseSize = () => {
const fontSizeWithUnit = getContainerFontSize();
const newSize = Number.parseInt(fontSizeWithUnit) + FONT_SIZE_STEP / 2;
containerEl.style.fontSize = `${newSize}px`;
};

containerEl.style.fontSize = defaultSize;
while (textWidthForCurrentSize(text, containerEl) > containerEl.clientWidth) {
decreaseSize();
}

if (
getContainerFontSize() >= defaultSize ||
textWidthForCurrentSize(text, containerEl) > containerEl.clientWidth * 0.75
) {
return;
}

while (textWidthForCurrentSize(text, containerEl) < containerEl.clientWidth) {
increaseSize();
}
}

const factorForIdentifier = (i: string | null) => (f: SignInFactor) => {
return 'safeIdentifier' in f && f.safeIdentifier === i;
};
Expand Down

0 comments on commit a101b70

Please sign in to comment.