Source

style/isSmallerThanBreakpoint.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isNum_1 = __importDefault(require("../number/isNum"));
/**
 * Check if the given windowWidth is smaller than the breakpoint
 * @param windowWidth usually use with hook `useWindowSize`
 * @param breakpoint (optional) can be number, "100%" or "". Default ""
 * If "100%", always return true, is smaller than breakpoint
 * If "", check with param `min`
 * @param min (optional) minimum breakpoint. Default 0
 * Use if want to ensure return true if smaller than `min` no matter what `breakpoint` is
 * If both `breakpoint` and `min` are not provided, will return false
 * @category style
 * @module isSmallerThanBreakpoint
 */
var isSmallerThanBreakpoint = function (windowWidth, breakpoint, min) {
    if (breakpoint === void 0) { breakpoint = ''; }
    if (min === void 0) { min = 0; }
    // Always return true if breakpoint is "100%"
    if (breakpoint === '100%')
        return true;
    // Convert breakpoint into px or use fallback
    var breakpointPx = (function () {
        var breakpointString = breakpoint.toString();
        // If can be parse to number
        if ((0, isNum_1.default)(breakpointString, true))
            return parseFloat(breakpointString);
        return min;
    })();
    // Limit breakpoint
    var limitedBreakpointPx = Math.max(min, breakpointPx);
    return windowWidth < limitedBreakpointPx;
};
exports.default = isSmallerThanBreakpoint;