@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
39 lines (38 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseThreshold = exports.ThresholdUnits = void 0;
exports.ThresholdUnits = {
Pixel: 'Pixel',
Percent: 'Percent',
};
const defaultThreshold = {
unit: exports.ThresholdUnits.Percent,
value: 0.8,
};
function parseThreshold(scrollThreshold) {
if (typeof scrollThreshold === 'number') {
return {
unit: exports.ThresholdUnits.Percent,
value: scrollThreshold * 100,
};
}
if (typeof scrollThreshold === 'string') {
if (scrollThreshold.match(/^(\d*(\.\d+)?)px$/)) {
return {
unit: exports.ThresholdUnits.Pixel,
value: parseFloat(scrollThreshold),
};
}
if (scrollThreshold.match(/^(\d*(\.\d+)?)%$/)) {
return {
unit: exports.ThresholdUnits.Percent,
value: parseFloat(scrollThreshold),
};
}
console.warn('scrollThreshold format is invalid. Valid formats: "120px", "50%"...');
return defaultThreshold;
}
console.warn('scrollThreshold should be string or number');
return defaultThreshold;
}
exports.parseThreshold = parseThreshold;