jobiqo-cl
Version:
[](https://circleci.com/gh/jobiqo/jobiqo-cl)
28 lines (25 loc) • 2.17 kB
JavaScript
import { useState, useEffect, createElement } from 'react';
import { noScrollbarsClassName, zeroRightClassName, fullWidthClassName } from './constants.js';
import '../../../react-style-singleton/dist/es2015/singleton.js';
import '../../../react-style-singleton/dist/es2015/hook.js';
import { styleSingleton } from '../../../react-style-singleton/dist/es2015/component.js';
import { getGapWidth } from './utils.js';
var Style = styleSingleton();
var getStyles = function (_a, allowRelative, gapMode, important) {
var left = _a.left, top = _a.top, right = _a.right, gap = _a.gap;
if (gapMode === void 0) { gapMode = 'margin'; }
return "\n ." + noScrollbarsClassName + " {\n overflow: hidden " + important + ";\n padding-right: " + gap + "px " + important + ";\n }\n body {\n overflow: hidden " + important + ";\n " + [
allowRelative && "position: relative " + important + ";",
gapMode === 'margin' && "\n padding-left: " + left + "px;\n padding-top: " + top + "px;\n padding-right: " + right + "px;\n margin-left:0;\n margin-top:0;\n margin-right: " + gap + "px " + important + ";\n ",
gapMode === 'padding' && "padding-right: " + gap + "px " + important + ";",
].filter(Boolean).join('') + "\n }\n \n ." + zeroRightClassName + " {\n right: " + gap + "px " + important + ";\n }\n \n ." + fullWidthClassName + " {\n margin-right: " + gap + "px " + important + ";\n }\n \n ." + zeroRightClassName + " ." + zeroRightClassName + " {\n right: 0 " + important + ";\n }\n \n ." + fullWidthClassName + " ." + fullWidthClassName + " {\n margin-right: 0 " + important + ";\n }\n";
};
var RemoveScrollBar = function (props) {
var _a = useState(getGapWidth(props.gapMode)), gap = _a[0], setGap = _a[1];
useEffect(function () {
setGap(getGapWidth(props.gapMode));
}, [props.gapMode]);
var noRelative = props.noRelative, noImportant = props.noImportant, _b = props.gapMode, gapMode = _b === void 0 ? 'margin' : _b;
return createElement(Style, { styles: getStyles(gap, !noRelative, gapMode, !noImportant ? "!important" : '') });
};
export { RemoveScrollBar };