0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-24 22:05:56 -05:00

refactor(console): use switch-case to make the select aligment logic more readable (#812)

This commit is contained in:
Xiao Yijun 2022-05-13 12:13:44 +08:00 committed by GitHub
parent c6b44eea87
commit b14a705bd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,20 +42,35 @@ const selectVerticalAlignment = ({
const isTopAllowed = verticalTop >= minY; const isTopAllowed = verticalTop >= minY;
const isBottomAllowed = verticalBottom + overlayHeight <= maxY; const isBottomAllowed = verticalBottom + overlayHeight <= maxY;
if (verticalAlign === 'top') { switch (verticalAlign) {
if (isTopAllowed) { case 'top': {
return 'top'; if (isTopAllowed) {
return 'top';
}
if (isBottomAllowed) {
return 'bottom';
}
return verticalAlign;
} }
return isBottomAllowed ? 'bottom' : 'top'; case 'bottom': {
} if (isBottomAllowed) {
return 'bottom';
}
// Mark: VerticalAlign === 'bottom' if (isTopAllowed) {
if (isBottomAllowed) { return 'top';
return 'bottom'; }
}
return isTopAllowed ? 'top' : 'bottom'; return verticalAlign;
}
default: {
return verticalAlign;
}
}
}; };
const selectHorizontalAlignment = ({ const selectHorizontalAlignment = ({