Skip to content

Commit

Permalink
Merge pull request #28 from yongdamsh/fix/size-calculation
Browse files Browse the repository at this point in the history
Fix size calculation by checking sign
  • Loading branch information
Brew-Brew authored Jun 16, 2021
2 parents a59949f + f85e737 commit 146dda6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cssinjs-inlclude-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ function parseParam(param: string) {
return [sign, screenSize];
}

function calculateSize(sign: string, screenSize: string) {
if (sign.includes("=")) {
return breakpoints[screenSize];
}

if (sign.includes(">")) {
return breakpoints[screenSize] + 1;
}

return breakpoints[screenSize] - 1;
}

function convertToQuery(param: string) {
const [sign, screenSize] = parseParam(param);
const hasEqualSign = sign.includes("=");
const size = hasEqualSign
? breakpoints[screenSize]
: breakpoints[screenSize] - 1;
const size = calculateSize(sign, screenSize);
const unit = typeof size === "number" ? "px" : "";
const widthCondition = sign.includes(">") ? "min-width" : "max-width";
return `(${widthCondition}: ${size}${unit})`;
Expand Down

0 comments on commit 146dda6

Please sign in to comment.