Repository URL to install this package:
Version:
0.9.6 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @todo isArray needs to be used here to make sure the list is array type
*/
const isNonEmptyArray = (list) => list && list.length > 0;
exports.isNonEmptyArray = isNonEmptyArray;
/**
* get device type based on the window width
*/
function getDeviceType() {
const screenWidth = window.outerWidth;
const isMobileDevice = (screenWidth <= 767);
const isTabletDevice = (screenWidth >= 768 && screenWidth <= 1024);
const isDesktopDevice = (screenWidth > 1024);
if (isMobileDevice) {
return 'mobile';
}
else if (isTabletDevice) {
return 'tablet';
}
else {
return 'desktop';
}
}
exports.getDeviceType = getDeviceType;
/**
* get item display count based on the device type
*/
function getItemDisplayCount(props) {
const { displayCountOnMobile, displayCountOnTablet, displayCountOnDesktop, list } = props;
const deviceType = getDeviceType();
const count = ((deviceType === 'mobile') ? displayCountOnMobile : (deviceType === 'tablet') ? displayCountOnTablet : displayCountOnDesktop);
// making sure that the display count should not be greater than list length
if (isNonEmptyArray(list)) {
if (list.length >= count) {
return count;
}
else {
return list.length;
}
}
else {
return 0;
}
}
exports.getItemDisplayCount = getItemDisplayCount;
/**
* @description used to get item width based displayCount on the device width
*/
function getItemWidth(displayCount) {
/**
* @todo dynamic width needs to be added here
*/
const screenWidth = window.outerWidth;
return Math.round(screenWidth / displayCount);
}
exports.getItemWidth = getItemWidth;
//# sourceMappingURL=deps.js.map