UNPKG

@kloudlite/design-system

Version:

A design system for building ambitious products.

124 lines (120 loc) 4.16 kB
"use strict"; "use client"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // components/atoms/pulsable.tsx var pulsable_exports = {}; __export(pulsable_exports, { default: () => pulsable_default }); module.exports = __toCommonJS(pulsable_exports); var import_react2 = require("react"); // components/utils.tsx var import_classnames = __toESM(require("classnames"), 1); var import_react = require("react"); var import_uuid = require("uuid"); var cn = (...props) => { return (0, import_classnames.default)(...props); }; // components/atoms/pulsable.tsx var import_jsx_runtime = require("react/jsx-runtime"); var Pulsable = ({ children, isLoading }) => { const ref = (0, import_react2.useRef)(null); const [isCalculating, setCalculating] = (0, import_react2.useState)(true); (0, import_react2.useEffect)(() => { setCalculating(true); if (isLoading) { if (!ref.current) { return; } const docs = ref.current.querySelectorAll(".pulsable"); docs.forEach((element) => { element.classList.add("pulse-element"); element.childNodes.forEach((ch) => { if (ch.classList && !ch.classList.contains("pulse-child")) { ch.classList?.add("pulse-child-element"); logger.log(ch?.getAttribute("disabled")); } }); const pc = element.querySelector(".pulse-child"); if (!pc) { const pulseEl = document.createElement("div"); pulseEl.classList.add( "absolute", "z-20", "!bg-[#bebebe82]", "animate-pulse", "w-full", "h-full", "inset-0", "rounded", "pulse-child" ); element.appendChild(pulseEl); } }); setCalculating(false); } else { if (!ref.current) { return; } const pc = ref.current.querySelectorAll(".pulse-child"); pc.forEach((v) => { v.parentNode?.removeChild(v); }); const pc2 = ref.current.querySelectorAll(".pulse-element"); pc2.forEach((v) => { v.classList.remove("pulse-element"); }); const docs = ref.current.querySelectorAll(".pulsable"); docs.forEach((element) => { element.childNodes.forEach((ch) => { ch.classList?.remove("pulse-child-element"); if (!ch?.classList.contains("pulse-has-disabled-attr")) { ch?.removeAttribute("disabled"); } }); }); setCalculating(false); } }, [isLoading, ref.current]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "div", { ref, className: cn("pulse-container", { "kl-opacity-0 kl-transition-all": isLoading && isCalculating }), children } ); }; var pulsable_default = Pulsable;