@helpwave/hightide
Version:
helpwave's component and theming library
154 lines (149 loc) • 5.88 kB
JavaScript
;
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);
// src/components/user-input/Textarea.tsx
var Textarea_exports = {};
__export(Textarea_exports, {
Textarea: () => Textarea
});
module.exports = __toCommonJS(Textarea_exports);
var import_react2 = require("react");
var import_clsx = __toESM(require("clsx"));
// src/hooks/useSaveDelay.ts
var import_react = require("react");
function useSaveDelay(setNotificationStatus, delay) {
const [updateTimer, setUpdateTimer] = (0, import_react.useState)(void 0);
const [notificationTimer, setNotificationTimer] = (0, import_react.useState)(void 0);
const restartTimer = (onSave) => {
clearTimeout(updateTimer);
setUpdateTimer(setTimeout(() => {
onSave();
setNotificationStatus(true);
clearTimeout(notificationTimer);
setNotificationTimer(setTimeout(() => {
setNotificationStatus(false);
clearTimeout(notificationTimer);
}, delay));
clearTimeout(updateTimer);
}, delay));
};
const clearUpdateTimer = (hasSaved = true) => {
clearTimeout(updateTimer);
if (hasSaved) {
setNotificationStatus(true);
clearTimeout(notificationTimer);
setNotificationTimer(setTimeout(() => {
setNotificationStatus(false);
clearTimeout(notificationTimer);
}, delay));
} else {
setNotificationStatus(false);
}
};
(0, import_react.useEffect)(() => {
return () => {
clearTimeout(updateTimer);
clearTimeout(notificationTimer);
};
}, []);
return { restartTimer, clearUpdateTimer };
}
// src/util/noop.ts
var noop = () => void 0;
// src/components/user-input/Label.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var styleMapping = {
labelSmall: "textstyle-label-sm",
labelMedium: "textstyle-label-md",
labelBig: "textstyle-label-lg"
};
var Label = ({
children,
name,
labelType = "labelSmall",
...props
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { ...props, children: children ? children : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: styleMapping[labelType], children: name }) });
};
// src/components/user-input/Textarea.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var Textarea = ({
label,
headline,
id,
resizable = false,
onChange = noop,
disclaimer,
onBlur = noop,
onEditCompleted = noop,
defaultStyle = true,
className,
...props
}) => {
const [hasFocus, setHasFocus] = (0, import_react2.useState)(false);
const { restartTimer, clearUpdateTimer } = useSaveDelay(() => void 0, 3e3);
const onEditCompletedWrapper = (text) => {
onEditCompleted(text);
clearUpdateTimer();
};
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "w-full", children: [
label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { ...label, htmlFor: id, className: (0, import_clsx.default)("mb-1", label.className), labelType: label.labelType ?? "labelSmall" }),
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `${(0, import_clsx.default)(" bg-surface text-on-surface focus-within:border-primary relative", { "shadow border-2 border-gray-300 hover:border-primary rounded-lg": defaultStyle })}`, children: [
headline && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mx-3 mt-3 block text-gray-700 font-bold", children: headline }),
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"textarea",
{
id,
className: (0, import_clsx.default)("pt-0 px-3 border-transparent focus:border-transparent focus:ring-0 appearance-none border w-full leading-tight focus:outline-none", { "resize-none": !resizable, "h-32": defaultStyle, "mt-3": !headline }, className),
onChange: (event) => {
const value = event.target.value;
restartTimer(() => {
onEditCompletedWrapper(value);
});
onChange(value);
},
onFocus: () => {
setHasFocus(true);
},
onBlur: (event) => {
onBlur(event);
onEditCompletedWrapper(event.target.value);
setHasFocus(false);
},
...props
}
)
] }),
hasFocus && disclaimer && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "text-negative", children: disclaimer })
] });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Textarea
});
//# sourceMappingURL=Textarea.js.map