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 isBottomAllowed = verticalBottom + overlayHeight <= maxY;
if (verticalAlign === 'top') {
if (isTopAllowed) {
return 'top';
switch (verticalAlign) {
case '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 (isBottomAllowed) {
return 'bottom';
}
if (isTopAllowed) {
return 'top';
}
return isTopAllowed ? 'top' : 'bottom';
return verticalAlign;
}
default: {
return verticalAlign;
}
}
};
const selectHorizontalAlignment = ({