UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

247 lines (243 loc) 7.42 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/components/TextArea/TextArea.tsx var TextArea_exports = {}; __export(TextArea_exports, { default: () => TextArea_default }); module.exports = __toCommonJS(TextArea_exports); var import_react = require("react"); var import_phosphor_react = require("phosphor-react"); // src/utils/utils.ts var import_clsx = require("clsx"); var import_tailwind_merge = require("tailwind-merge"); function cn(...inputs) { return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs)); } // src/components/Text/Text.tsx var import_jsx_runtime = require("react/jsx-runtime"); var Text = ({ children, size = "md", weight = "normal", color = "text-text-950", as, className = "", ...props }) => { let sizeClasses = ""; let weightClasses = ""; const sizeClassMap = { "2xs": "text-2xs", xs: "text-xs", sm: "text-sm", md: "text-md", lg: "text-lg", xl: "text-xl", "2xl": "text-2xl", "3xl": "text-3xl", "4xl": "text-4xl", "5xl": "text-5xl", "6xl": "text-6xl" }; sizeClasses = sizeClassMap[size] ?? sizeClassMap.md; const weightClassMap = { hairline: "font-hairline", light: "font-light", normal: "font-normal", medium: "font-medium", semibold: "font-semibold", bold: "font-bold", extrabold: "font-extrabold", black: "font-black" }; weightClasses = weightClassMap[weight] ?? weightClassMap.normal; const baseClasses = "font-primary"; const Component = as ?? "p"; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( Component, { className: cn(baseClasses, sizeClasses, weightClasses, color, className), ...props, children } ); }; var Text_default = Text; // src/components/TextArea/TextArea.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var SIZE_CLASSES = { small: { textarea: "h-24 text-sm", // 96px height, 14px font textSize: "sm" }, medium: { textarea: "h-24 text-base", // 96px height, 16px font textSize: "md" }, large: { textarea: "h-24 text-lg", // 96px height, 18px font textSize: "lg" }, extraLarge: { textarea: "h-24 text-xl", // 96px height, 20px font textSize: "xl" } }; var BASE_TEXTAREA_CLASSES = "w-full box-border p-3 bg-background border border-solid rounded-[4px] resize-none focus:outline-none font-roboto font-normal leading-[150%] placeholder:text-text-600 transition-all duration-200"; var STATE_CLASSES = { default: { base: "border-border-300 bg-background text-text-600", hover: "hover:border-border-400", focus: "focus:border-border-500" }, hovered: { base: "border-border-400 bg-background text-text-600", hover: "", focus: "focus:border-border-500" }, focused: { base: "border-2 border-primary-950 bg-background text-text-900", hover: "", focus: "" }, invalid: { base: "border-2 border-red-700 bg-white text-gray-800", hover: "hover:border-red-700", focus: "focus:border-red-700" }, disabled: { base: "border-border-300 bg-background text-text-600 cursor-not-allowed opacity-40", hover: "", focus: "" } }; var TextArea = (0, import_react.forwardRef)( ({ label, size = "medium", state = "default", errorMessage, helperMessage, className = "", labelClassName = "", disabled, id, onChange, placeholder, required, showCharacterCount = false, maxLength, value, ...props }, ref) => { const generatedId = (0, import_react.useId)(); const inputId = id ?? `textarea-${generatedId}`; const [isFocused, setIsFocused] = (0, import_react.useState)(false); const currentLength = typeof value === "string" ? value.length : 0; const isNearLimit = maxLength && currentLength >= maxLength * 0.8; const handleChange = (event) => { onChange?.(event); }; const handleFocus = (event) => { setIsFocused(true); props.onFocus?.(event); }; const handleBlur = (event) => { setIsFocused(false); props.onBlur?.(event); }; let currentState = disabled ? "disabled" : state; if (isFocused && currentState !== "invalid" && currentState !== "disabled") { currentState = "focused"; } const sizeClasses = SIZE_CLASSES[size]; const stateClasses = STATE_CLASSES[currentState]; const textareaClasses = cn( BASE_TEXTAREA_CLASSES, sizeClasses.textarea, stateClasses.base, stateClasses.hover, stateClasses.focus, className ); return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `flex flex-col`, children: [ label && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)( Text_default, { as: "label", htmlFor: inputId, size: sizeClasses.textSize, weight: "medium", color: "text-text-950", className: cn("mb-1.5", labelClassName), children: [ label, " ", required && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "text-indicator-error", children: "*" }) ] } ), /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "textarea", { ref, id: inputId, disabled, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, className: textareaClasses, placeholder, required, maxLength, value, ...props } ), errorMessage && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "flex gap-1 items-center text-sm text-indicator-error mt-1.5", children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_phosphor_react.WarningCircle, { size: 16 }), " ", errorMessage ] }), !errorMessage && showCharacterCount && maxLength && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)( Text_default, { size: "sm", weight: "normal", className: `mt-1.5 ${isNearLimit ? "text-indicator-warning" : "text-text-500"}`, children: [ currentLength, "/", maxLength, " caracteres" ] } ), !errorMessage && helperMessage && !(showCharacterCount && maxLength) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text_default, { size: "sm", weight: "normal", className: "mt-1.5 text-text-500", children: helperMessage }) ] }); } ); TextArea.displayName = "TextArea"; var TextArea_default = TextArea; //# sourceMappingURL=index.js.map