funda-ui
Version:
React components using pure Bootstrap 5+ which does not contain any external style and script libraries.
231 lines (206 loc) • 8.87 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["RPB"] = factory(require("react"));
else
root["RPB"] = factory(root["React"]);
})(this, (__WEBPACK_EXTERNAL_MODULE__787__) => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 787:
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_MODULE__787__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(787);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
* Creating a Textarea with dynamic height
*
* @usage:
const App = () => {
const [value, setValue] = useState("");
const el = useRef<HTMLTextAreaElement>(null);
const { reset } = useAutosizeTextArea({
el: el.current,
value: value,
cb: (res) => {
console.log('dimensions: ', res);
}
});
useImperativeHandle(
contentRef,
() => ({
resetHeight: () => {
reset();
},
}),
[contentRef, reset]
);
const handleChange = (evt: React.ChangeEvent<HTMLTextAreaElement>) => {
const val = evt.target?.value;
setValue(val);
};
const handleReset = () => {
reset();
};
return (
<div className="App">
<textarea
onChange={handleChange}
ref={el}
rows={3}
value={value}
/>
</div>
);
};
*/
var useAutosizeTextArea = function useAutosizeTextArea(_ref) {
var el = _ref.el,
value = _ref.value,
_ref$maxHeight = _ref.maxHeight,
maxHeight = _ref$maxHeight === void 0 ? 0 : _ref$maxHeight,
cb = _ref.cb;
var _useState = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false),
_useState2 = _slicedToArray(_useState, 2),
defaultRowHeightInit = _useState2[0],
setDefaultRowHeightInit = _useState2[1];
// Reset function to restore default height
var reset = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
if (!el) return;
var scrollHeight = el.scrollHeight;
el.style.height = scrollHeight + "px";
// Get current dimensions after reset
var style = window.getComputedStyle(el);
var _controlWidth = el.scrollWidth + parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth);
cb === null || cb === void 0 ? void 0 : cb([_controlWidth, scrollHeight]);
}, [el, cb]);
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
if (!el) return;
// Initialize default height
if (!defaultRowHeightInit) {
el.style.height = 'auto';
var initialHeight = el.scrollHeight;
setDefaultRowHeightInit(true);
// If the height is 0, set it to "auto"
if (initialHeight === 0) {
el.style.height = "auto";
} else {
el.style.height = initialHeight + "px";
}
}
// Get dimensions
var style = window.getComputedStyle(el);
var _controlWidth = el.scrollWidth + parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth);
// Calculate height
el.style.height = 'auto';
var finalHeight = el.scrollHeight;
// Apply max height limit if needed
if (maxHeight > 0 && finalHeight > maxHeight) {
finalHeight = maxHeight;
}
// Set final height
// If the height is 0, set it to "auto"
if (finalHeight === 0) {
el.style.height = "auto";
} else {
el.style.height = finalHeight + "px";
}
// Callback
cb === null || cb === void 0 ? void 0 : cb([_controlWidth, finalHeight]);
}, [el, value, maxHeight, defaultRowHeightInit]);
return {
reset: reset
};
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (useAutosizeTextArea);
})();
/******/ return __webpack_exports__;
/******/ })()
;
});