@rubenpazch/textarea 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -2
- package/dist/Textarea.d.ts +20 -0
- package/dist/Textarea.d.ts.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +75 -3
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rubenpazch/textarea
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- catalogo:inicio (generado por pnpm catalogo, no editar) -->
|
|
4
|
+
|
|
5
|
+
Área de texto con etiqueta, ayuda, advertencia, error, contador de caracteres y crecimiento automático.
|
|
6
|
+
|
|
7
|
+
- **Usar cuando:** Textos de varias líneas: observaciones, motivos de anulación, descripciones.
|
|
8
|
+
- **Evitar cuando:** Una sola línea: usa TextInput. Texto con formato (negritas, enlaces, imágenes): usa RichTextEditor.
|
|
9
|
+
|
|
10
|
+
Se recomienda instalar el paquete completo `@rubenpazch/ui` (incluye este). Por separado:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @rubenpazch/textarea
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Textarea
|
|
17
|
+
|
|
18
|
+
Área de texto con etiqueta, ayuda, error, contador y crecimiento automático.
|
|
19
|
+
|
|
20
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
21
|
+
| ------------ | ------------------------- | ---- | ----------- | ---------------------------------------------------------------------------- |
|
|
22
|
+
| `onChange` | `(value: string) => void` | sí | | Recibe el texto nuevo. |
|
|
23
|
+
| `value` | `string` | sí | | Texto actual. |
|
|
24
|
+
| `autoResize` | `boolean` | | `false` | Crece con el contenido hasta maxRows. |
|
|
25
|
+
| `className` | `string` | | | Clase extra para el contenedor (márgenes, ancho). |
|
|
26
|
+
| `disabled` | `boolean` | | `false` | Campo deshabilitado. |
|
|
27
|
+
| `error` | `string` | | | Mensaje de error; marca el campo como inválido. |
|
|
28
|
+
| `hint` | `string` | | | Texto de ayuda bajo el campo. |
|
|
29
|
+
| `id` | `string` | | | id del control. Si no se pasa, se genera uno. |
|
|
30
|
+
| `label` | `string` | | | Etiqueta visible del campo (se asocia al control para lectores de pantalla). |
|
|
31
|
+
| `maxRows` | `number` | | `12` | Máximo de filas al crecer (por defecto 12). |
|
|
32
|
+
| `name` | `string` | | | name del control (formularios nativos y librerías de formularios). |
|
|
33
|
+
| `required` | `boolean` | | `false` | Campo obligatorio: muestra * y marca el control como requerido. |
|
|
34
|
+
| `rows` | `number` | | `4` | Filas visibles al inicio (por defecto 4). |
|
|
35
|
+
| `showCount` | `boolean` | | `true` | Muestra el contador "120/500" cuando hay maxLength. |
|
|
36
|
+
| `warning` | `string` | | | Advertencia (no bloquea). |
|
|
37
|
+
|
|
38
|
+
Tipos: `TextareaProps`.
|
|
39
|
+
|
|
40
|
+
<!-- catalogo:fin -->
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { FieldProps } from "@rubenpazch/shared";
|
|
3
|
+
export interface TextareaProps extends FieldProps, Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, "onChange" | "value" | "id" | "name" | "required" | "disabled" | "className"> {
|
|
4
|
+
/** Texto actual. */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Recibe el texto nuevo. */
|
|
7
|
+
onChange: (value: string) => void;
|
|
8
|
+
/** Filas visibles al inicio (por defecto 4). */
|
|
9
|
+
rows?: number;
|
|
10
|
+
/** Crece con el contenido hasta maxRows. */
|
|
11
|
+
autoResize?: boolean;
|
|
12
|
+
/** Máximo de filas al crecer (por defecto 12). */
|
|
13
|
+
maxRows?: number;
|
|
14
|
+
/** Muestra el contador "120/500" cuando hay maxLength. */
|
|
15
|
+
showCount?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Área de texto con etiqueta, ayuda, error, contador y crecimiento automático. */
|
|
18
|
+
declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
19
|
+
export default Textarea;
|
|
20
|
+
//# sourceMappingURL=Textarea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../src/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,WAAW,aACf,SACE,UAAU,EACV,IAAI,CACF,KAAK,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,EAC/C,UAAU,GACV,OAAO,GACP,IAAI,GACJ,MAAM,GACN,UAAU,GACV,UAAU,GACV,WAAW,CACd;IACH,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAKD,mFAAmF;AACnF,QAAA,MAAM,QAAQ,2FAuGb,CAAC;AAIF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),r=require("react"),a=require("@rubenpazch/shared");var n="Textarea-module_field__igFFJ",o="Textarea-module_label__LUl9G",l="Textarea-module_required__y8mTX",t="Textarea-module_textarea__iqULw",d="Textarea-module_autoResize__oYLcy",s="Textarea-module_invalid__0sZvS",i="Textarea-module_footer__V2PJa",u="Textarea-module_messages__WGAST",_="Textarea-module_hint__h-zPw",c="Textarea-module_error__pNzRk",m="Textarea-module_warning__esCQF",x="Textarea-module_count__DxkB6",b="Textarea-module_countNear__p-VVV";!function(e,r){void 0===r&&(r={});var a=r.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===a&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".Textarea-module_field__igFFJ {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-1);\n font-family: var(--lb-font-sans);\n}\n\n.Textarea-module_label__LUl9G {\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-foreground);\n}\n\n.Textarea-module_required__y8mTX {\n color: var(--lb-color-danger);\n}\n\n.Textarea-module_textarea__iqULw {\n width: 100%;\n box-sizing: border-box;\n padding: var(--lb-space-2) var(--lb-space-3);\n border: 1px solid var(--lb-color-border);\n border-radius: var(--lb-radius-md);\n background: var(--lb-color-background);\n color: var(--lb-color-foreground);\n font: inherit;\n font-size: var(--lb-font-size-sm);\n line-height: var(--lb-line-height-normal);\n resize: vertical;\n}\n\n.Textarea-module_textarea__iqULw::-moz-placeholder {\n color: var(--lb-color-muted-foreground);\n}\n\n.Textarea-module_textarea__iqULw::placeholder {\n color: var(--lb-color-muted-foreground);\n}\n\n.Textarea-module_textarea__iqULw:focus {\n outline: none;\n border-color: var(--lb-color-primary);\n box-shadow: 0 0 0 3px var(--lb-color-primary-subtle);\n}\n\n.Textarea-module_textarea__iqULw:disabled {\n background: var(--lb-color-muted);\n cursor: not-allowed;\n}\n\n.Textarea-module_autoResize__oYLcy {\n resize: none;\n overflow-y: auto;\n}\n\n.Textarea-module_invalid__0sZvS {\n border-color: var(--lb-color-danger);\n}\n\n.Textarea-module_invalid__0sZvS:focus {\n box-shadow: 0 0 0 3px var(--lb-color-red-subtle);\n}\n\n.Textarea-module_footer__V2PJa {\n display: flex;\n justify-content: space-between;\n gap: var(--lb-space-2);\n}\n\n.Textarea-module_messages__WGAST {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-1);\n}\n\n.Textarea-module_hint__h-zPw,\n.Textarea-module_error__pNzRk,\n.Textarea-module_warning__esCQF {\n margin: 0;\n font-size: var(--lb-font-size-xs);\n}\n\n.Textarea-module_hint__h-zPw { color: var(--lb-color-muted-foreground); }\n.Textarea-module_error__pNzRk { color: var(--lb-color-danger); }\n.Textarea-module_warning__esCQF { color: var(--lb-color-amber-strong); }\n\n.Textarea-module_count__DxkB6 {\n flex: none;\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-muted-foreground);\n font-variant-numeric: tabular-nums;\n}\n\n.Textarea-module_countNear__p-VVV {\n color: var(--lb-color-amber-strong);\n}\n");const h=(...e)=>e.filter(Boolean).join(" "),f=r.forwardRef(function({label:f,hint:v,error:g,warning:p,required:T=!1,disabled:w=!1,id:y,name:z,className:N,value:q,onChange:j,rows:L=4,autoResize:C=!1,maxRows:F=12,showCount:R=!0,maxLength:k,...S},U){const V=a.useFieldIds({id:y,name:z,required:T,error:g,warning:g?void 0:p,hint:v}),P=r.useRef(null);r.useLayoutEffect(()=>{const e=P.current;if(!C||!e)return;e.style.height="auto";const r=parseFloat(getComputedStyle(e).lineHeight)||20;e.style.height=`${Math.min(e.scrollHeight,r*F+16)}px`},[q,C,F]);const B=!!k&&q.length/k>.9;return e.jsxs("div",{className:h(n,N),children:[f&&e.jsxs("label",{htmlFor:V.inputId,className:o,children:[f,T&&e.jsxs("span",{className:l,"aria-hidden":"true",children:[" ","*"]})]}),e.jsx("textarea",{ref:a.mergeRefs(P,U),...S,...V.controlProps,name:z,required:T,disabled:w,rows:L,maxLength:k,value:q,onChange:e=>j(e.target.value),className:h(t,g&&s,C&&d)}),e.jsxs("div",{className:i,children:[e.jsxs("div",{className:u,children:[g&&e.jsx("p",{id:V.errorId,className:c,role:"alert",children:g}),!g&&p&&e.jsx("p",{id:V.warningId,className:m,children:p}),v&&e.jsx("p",{id:V.hintId,className:_,children:v})]}),R&&k&&e.jsxs("span",{className:h(x,B&&b),"aria-live":"polite",children:[q.length,"/",k]})]})]})});f.displayName="Textarea",module.exports=f;
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/Textarea.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React, { useLayoutEffect, useRef } from \"react\";\nimport { mergeRefs, useFieldIds } from \"@rubenpazch/shared\";\nimport type { FieldProps } from \"@rubenpazch/shared\";\nimport styles from \"./Textarea.module.css\";\n\nexport interface TextareaProps\n extends\n FieldProps,\n Omit<\n React.TextareaHTMLAttributes<HTMLTextAreaElement>,\n | \"onChange\"\n | \"value\"\n | \"id\"\n | \"name\"\n | \"required\"\n | \"disabled\"\n | \"className\"\n > {\n /** Texto actual. */\n value: string;\n /** Recibe el texto nuevo. */\n onChange: (value: string) => void;\n /** Filas visibles al inicio (por defecto 4). */\n rows?: number;\n /** Crece con el contenido hasta maxRows. */\n autoResize?: boolean;\n /** Máximo de filas al crecer (por defecto 12). */\n maxRows?: number;\n /** Muestra el contador \"120/500\" cuando hay maxLength. */\n showCount?: boolean;\n}\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/** Área de texto con etiqueta, ayuda, error, contador y crecimiento automático. */\nconst Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(\n function Textarea(\n {\n label,\n hint,\n error,\n warning,\n required = false,\n disabled = false,\n id,\n name,\n className,\n value,\n onChange,\n rows = 4,\n autoResize = false,\n maxRows = 12,\n showCount = true,\n maxLength,\n ...rest\n },\n ref,\n ) {\n const field = useFieldIds({\n id,\n name,\n required,\n error,\n warning: !error ? warning : undefined,\n hint,\n });\n const inner = useRef<HTMLTextAreaElement>(null);\n\n useLayoutEffect(() => {\n const el = inner.current;\n if (!autoResize || !el) return;\n el.style.height = \"auto\";\n const line = parseFloat(getComputedStyle(el).lineHeight) || 20;\n el.style.height = `${Math.min(el.scrollHeight, line * maxRows + 16)}px`;\n }, [value, autoResize, maxRows]);\n\n const near = maxLength ? value.length / maxLength > 0.9 : false;\n\n return (\n <div className={cx(styles.field, className)}>\n {label && (\n <label htmlFor={field.inputId} className={styles.label}>\n {label}\n {required && (\n <span className={styles.required} aria-hidden=\"true\">\n {\" \"}\n *\n </span>\n )}\n </label>\n )}\n <textarea\n ref={mergeRefs(inner, ref)}\n {...rest}\n {...field.controlProps}\n name={name}\n required={required}\n disabled={disabled}\n rows={rows}\n maxLength={maxLength}\n value={value}\n onChange={(e) => onChange(e.target.value)}\n className={cx(\n styles.textarea,\n error && styles.invalid,\n autoResize && styles.autoResize,\n )}\n />\n <div className={styles.footer}>\n <div className={styles.messages}>\n {error && (\n <p id={field.errorId} className={styles.error} role=\"alert\">\n {error}\n </p>\n )}\n {!error && warning && (\n <p id={field.warningId} className={styles.warning}>\n {warning}\n </p>\n )}\n {hint && (\n <p id={field.hintId} className={styles.hint}>\n {hint}\n </p>\n )}\n </div>\n {showCount && maxLength && (\n <span\n className={cx(styles.count, near && styles.countNear)}\n aria-live=\"polite\"\n >\n {value.length}/{maxLength}\n </span>\n )}\n </div>\n </div>\n );\n },\n);\n\nTextarea.displayName = \"Textarea\";\n\nexport default Textarea;\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","Textarea","React","forwardRef","label","hint","error","warning","required","disabled","id","name","className","value","onChange","rows","autoResize","maxRows","showCount","maxLength","rest","field","useFieldIds","undefined","inner","useRef","useLayoutEffect","el","current","height","line","parseFloat","getComputedStyle","lineHeight","Math","min","scrollHeight","near","length","_jsxs","styles","children","htmlFor","inputId","_jsx","mergeRefs","controlProps","e","target","errorId","role","warningId","hintId","displayName"],"mappings":"2iBAAA,SAAqBA,EAAKC,YACnBA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBW,CAqBzD,q2ECOA,MAAMe,EAAK,IAAIC,IACbA,EAAEC,OAAOC,SAASC,KAAK,KAGnBC,EAAWC,EAAMC,WACrB,UACEC,MACEA,EAAKC,KACLA,EAAIC,MACJA,EAAKC,QACLA,EAAOC,SACPA,GAAW,EAAKC,SAChBA,GAAW,EAAKC,GAChBA,EAAEC,KACFA,EAAIC,UACJA,EAASC,MACTA,EAAKC,SACLA,EAAQC,KACRA,EAAO,EAACC,WACRA,GAAa,EAAKC,QAClBA,EAAU,GAAEC,UACZA,GAAY,EAAIC,UAChBA,KACGC,GAELtC,GAEA,MAAMuC,EAAQC,EAAAA,YAAY,CACxBZ,KACAC,OACAH,WACAF,QACAC,QAAUD,OAAkBiB,EAAV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,EAAM+B,OAAQxC,UAAW4B,EAAWC,SACxCpC,OAINa,GAAaC,GACZoB,EAAAA,KAAA,OAAA,CACE3B,UAAWhB,EAAG4C,EAAcH,GAAQG,GAAiB,YAC3C,SAAQC,SAAA,CAEjB5B,EAAMyB,OAAM,IAAGnB,UAM5B,GAGFlB,EAASoD,YAAc","x_google_ignoreList":[0]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FieldProps } from '@rubenpazch/shared';
|
|
3
|
+
|
|
4
|
+
interface TextareaProps extends FieldProps, Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, "onChange" | "value" | "id" | "name" | "required" | "disabled" | "className"> {
|
|
5
|
+
/** Texto actual. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Recibe el texto nuevo. */
|
|
8
|
+
onChange: (value: string) => void;
|
|
9
|
+
/** Filas visibles al inicio (por defecto 4). */
|
|
10
|
+
rows?: number;
|
|
11
|
+
/** Crece con el contenido hasta maxRows. */
|
|
12
|
+
autoResize?: boolean;
|
|
13
|
+
/** Máximo de filas al crecer (por defecto 12). */
|
|
14
|
+
maxRows?: number;
|
|
15
|
+
/** Muestra el contador "120/500" cuando hay maxLength. */
|
|
16
|
+
showCount?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Área de texto con etiqueta, ayuda, error, contador y crecimiento automático. */
|
|
19
|
+
declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
20
|
+
|
|
21
|
+
export { Textarea as default };
|
|
22
|
+
export type { TextareaProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsxs as e,jsx as r}from"react/jsx-runtime";import a,{useRef as n,useLayoutEffect as o}from"react";import{useFieldIds as l,mergeRefs as t}from"@rubenpazch/shared";var d="Textarea-module_field__igFFJ",i="Textarea-module_label__LUl9G",s="Textarea-module_required__y8mTX",_="Textarea-module_textarea__iqULw",u="Textarea-module_autoResize__oYLcy",c="Textarea-module_invalid__0sZvS",m="Textarea-module_footer__V2PJa",x="Textarea-module_messages__WGAST",b="Textarea-module_hint__h-zPw",h="Textarea-module_error__pNzRk",f="Textarea-module_warning__esCQF",v="Textarea-module_count__DxkB6",p="Textarea-module_countNear__p-VVV";!function(e,r){void 0===r&&(r={});var a=r.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===a&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".Textarea-module_field__igFFJ {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-1);\n font-family: var(--lb-font-sans);\n}\n\n.Textarea-module_label__LUl9G {\n font-size: var(--lb-font-size-sm);\n font-weight: var(--lb-font-weight-medium);\n color: var(--lb-color-foreground);\n}\n\n.Textarea-module_required__y8mTX {\n color: var(--lb-color-danger);\n}\n\n.Textarea-module_textarea__iqULw {\n width: 100%;\n box-sizing: border-box;\n padding: var(--lb-space-2) var(--lb-space-3);\n border: 1px solid var(--lb-color-border);\n border-radius: var(--lb-radius-md);\n background: var(--lb-color-background);\n color: var(--lb-color-foreground);\n font: inherit;\n font-size: var(--lb-font-size-sm);\n line-height: var(--lb-line-height-normal);\n resize: vertical;\n}\n\n.Textarea-module_textarea__iqULw::-moz-placeholder {\n color: var(--lb-color-muted-foreground);\n}\n\n.Textarea-module_textarea__iqULw::placeholder {\n color: var(--lb-color-muted-foreground);\n}\n\n.Textarea-module_textarea__iqULw:focus {\n outline: none;\n border-color: var(--lb-color-primary);\n box-shadow: 0 0 0 3px var(--lb-color-primary-subtle);\n}\n\n.Textarea-module_textarea__iqULw:disabled {\n background: var(--lb-color-muted);\n cursor: not-allowed;\n}\n\n.Textarea-module_autoResize__oYLcy {\n resize: none;\n overflow-y: auto;\n}\n\n.Textarea-module_invalid__0sZvS {\n border-color: var(--lb-color-danger);\n}\n\n.Textarea-module_invalid__0sZvS:focus {\n box-shadow: 0 0 0 3px var(--lb-color-red-subtle);\n}\n\n.Textarea-module_footer__V2PJa {\n display: flex;\n justify-content: space-between;\n gap: var(--lb-space-2);\n}\n\n.Textarea-module_messages__WGAST {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-1);\n}\n\n.Textarea-module_hint__h-zPw,\n.Textarea-module_error__pNzRk,\n.Textarea-module_warning__esCQF {\n margin: 0;\n font-size: var(--lb-font-size-xs);\n}\n\n.Textarea-module_hint__h-zPw { color: var(--lb-color-muted-foreground); }\n.Textarea-module_error__pNzRk { color: var(--lb-color-danger); }\n.Textarea-module_warning__esCQF { color: var(--lb-color-amber-strong); }\n\n.Textarea-module_count__DxkB6 {\n flex: none;\n font-size: var(--lb-font-size-xs);\n color: var(--lb-color-muted-foreground);\n font-variant-numeric: tabular-nums;\n}\n\n.Textarea-module_countNear__p-VVV {\n color: var(--lb-color-amber-strong);\n}\n");const g=(...e)=>e.filter(Boolean).join(" "),T=a.forwardRef(function({label:a,hint:T,error:w,warning:y,required:z=!1,disabled:N=!1,id:L,name:q,className:C,value:F,onChange:k,rows:R=4,autoResize:S=!1,maxRows:U=12,showCount:V=!0,maxLength:P,...B},G){const I=l({id:L,name:q,required:z,error:w,warning:w?void 0:y,hint:T}),J=n(null);o(()=>{const e=J.current;if(!S||!e)return;e.style.height="auto";const r=parseFloat(getComputedStyle(e).lineHeight)||20;e.style.height=`${Math.min(e.scrollHeight,r*U+16)}px`},[F,S,U]);const j=!!P&&F.length/P>.9;return e("div",{className:g(d,C),children:[a&&e("label",{htmlFor:I.inputId,className:i,children:[a,z&&e("span",{className:s,"aria-hidden":"true",children:[" ","*"]})]}),r("textarea",{ref:t(J,G),...B,...I.controlProps,name:q,required:z,disabled:N,rows:R,maxLength:P,value:F,onChange:e=>k(e.target.value),className:g(_,w&&c,S&&u)}),e("div",{className:m,children:[e("div",{className:x,children:[w&&r("p",{id:I.errorId,className:h,role:"alert",children:w}),!w&&y&&r("p",{id:I.warningId,className:f,children:y}),T&&r("p",{id:I.hintId,className:b,children:T})]}),V&&P&&e("span",{className:g(v,j&&p),"aria-live":"polite",children:[F.length,"/",P]})]})]})});T.displayName="Textarea";export{T as default};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/Textarea.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React, { useLayoutEffect, useRef } from \"react\";\nimport { mergeRefs, useFieldIds } from \"@rubenpazch/shared\";\nimport type { FieldProps } from \"@rubenpazch/shared\";\nimport styles from \"./Textarea.module.css\";\n\nexport interface TextareaProps\n extends\n FieldProps,\n Omit<\n React.TextareaHTMLAttributes<HTMLTextAreaElement>,\n | \"onChange\"\n | \"value\"\n | \"id\"\n | \"name\"\n | \"required\"\n | \"disabled\"\n | \"className\"\n > {\n /** Texto actual. */\n value: string;\n /** Recibe el texto nuevo. */\n onChange: (value: string) => void;\n /** Filas visibles al inicio (por defecto 4). */\n rows?: number;\n /** Crece con el contenido hasta maxRows. */\n autoResize?: boolean;\n /** Máximo de filas al crecer (por defecto 12). */\n maxRows?: number;\n /** Muestra el contador \"120/500\" cuando hay maxLength. */\n showCount?: boolean;\n}\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/** Área de texto con etiqueta, ayuda, error, contador y crecimiento automático. */\nconst Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(\n function Textarea(\n {\n label,\n hint,\n error,\n warning,\n required = false,\n disabled = false,\n id,\n name,\n className,\n value,\n onChange,\n rows = 4,\n autoResize = false,\n maxRows = 12,\n showCount = true,\n maxLength,\n ...rest\n },\n ref,\n ) {\n const field = useFieldIds({\n id,\n name,\n required,\n error,\n warning: !error ? warning : undefined,\n hint,\n });\n const inner = useRef<HTMLTextAreaElement>(null);\n\n useLayoutEffect(() => {\n const el = inner.current;\n if (!autoResize || !el) return;\n el.style.height = \"auto\";\n const line = parseFloat(getComputedStyle(el).lineHeight) || 20;\n el.style.height = `${Math.min(el.scrollHeight, line * maxRows + 16)}px`;\n }, [value, autoResize, maxRows]);\n\n const near = maxLength ? value.length / maxLength > 0.9 : false;\n\n return (\n <div className={cx(styles.field, className)}>\n {label && (\n <label htmlFor={field.inputId} className={styles.label}>\n {label}\n {required && (\n <span className={styles.required} aria-hidden=\"true\">\n {\" \"}\n *\n </span>\n )}\n </label>\n )}\n <textarea\n ref={mergeRefs(inner, ref)}\n {...rest}\n {...field.controlProps}\n name={name}\n required={required}\n disabled={disabled}\n rows={rows}\n maxLength={maxLength}\n value={value}\n onChange={(e) => onChange(e.target.value)}\n className={cx(\n styles.textarea,\n error && styles.invalid,\n autoResize && styles.autoResize,\n )}\n />\n <div className={styles.footer}>\n <div className={styles.messages}>\n {error && (\n <p id={field.errorId} className={styles.error} role=\"alert\">\n {error}\n </p>\n )}\n {!error && warning && (\n <p id={field.warningId} className={styles.warning}>\n {warning}\n </p>\n )}\n {hint && (\n <p id={field.hintId} className={styles.hint}>\n {hint}\n </p>\n )}\n </div>\n {showCount && maxLength && (\n <span\n className={cx(styles.count, near && styles.countNear)}\n aria-live=\"polite\"\n >\n {value.length}/{maxLength}\n </span>\n )}\n </div>\n </div>\n );\n },\n);\n\nTextarea.displayName = \"Textarea\";\n\nexport default Textarea;\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","Textarea","React","forwardRef","label","hint","error","warning","required","disabled","id","name","className","value","onChange","rows","autoResize","maxRows","showCount","maxLength","rest","field","useFieldIds","undefined","inner","useRef","useLayoutEffect","el","current","height","line","parseFloat","getComputedStyle","lineHeight","Math","min","scrollHeight","near","length","_jsxs","styles","children","htmlFor","inputId","_jsx","mergeRefs","controlProps","e","target","errorId","role","warningId","hintId","displayName"],"mappings":"inBAAA,SAAqBA,EAAKC,YACnBA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBW,CAqBzD,q2ECOA,MAAMe,EAAK,IAAIC,IACbA,EAAEC,OAAOC,SAASC,KAAK,KAGnBC,EAAWC,EAAMC,WACrB,UACEC,MACEA,EAAKC,KACLA,EAAIC,MACJA,EAAKC,QACLA,EAAOC,SACPA,GAAW,EAAKC,SAChBA,GAAW,EAAKC,GAChBA,EAAEC,KACFA,EAAIC,UACJA,EAASC,MACTA,EAAKC,SACLA,EAAQC,KACRA,EAAO,EAACC,WACRA,GAAa,EAAK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WvC,UAAW4B,EAAcC,SAC9ClC,IAGJF,GACCuC,EAAA,IAAA,CAAGlC,GAAIW,EAAM+B,OAAQxC,UAAW4B,EAAWC,SACxCpC,OAINa,GAAaC,GACZoB,EAAA,OAAA,CACE3B,UAAWhB,EAAG4C,EAAcH,GAAQG,GAAiB,YAC3C,SAAQC,SAAA,CAEjB5B,EAAMyB,OAAM,IAAGnB,UAM5B,GAGFlB,EAASoD,YAAc","x_google_ignoreList":[0]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/textarea",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Área de texto con contador y crecimiento automático",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rubenpazch/lbyte-ui-library.git",
|
|
8
|
+
"directory": "packages/textarea"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"main": "dist/index.cjs.js",
|
|
12
|
+
"module": "dist/index.esm.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.esm.js",
|
|
18
|
+
"require": "./dist/index.cjs.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"**/*.css"
|
|
26
|
+
],
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": "^19.2.3",
|
|
29
|
+
"react-dom": "^19.2.3",
|
|
30
|
+
"@rubenpazch/tokens": "0.5.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@rubenpazch/shared": "5.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
37
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
38
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
39
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
40
|
+
"@testing-library/react": "^16.3.3",
|
|
41
|
+
"@types/jest": "^30.0.0",
|
|
42
|
+
"@types/react": "^19.2.18",
|
|
43
|
+
"@types/react-dom": "^19.2.5",
|
|
44
|
+
"autoprefixer": "^10.5.4",
|
|
45
|
+
"eslint": "^9.39.5",
|
|
46
|
+
"identity-obj-proxy": "^3.0.0",
|
|
47
|
+
"jest": "^30.5.0",
|
|
48
|
+
"jest-environment-jsdom": "^30.5.0",
|
|
49
|
+
"postcss": "^8.5.26",
|
|
50
|
+
"prettier": "^3.9.6",
|
|
51
|
+
"react": "^19.2.8",
|
|
52
|
+
"react-dom": "^19.2.8",
|
|
53
|
+
"rollup": "^4.63.1",
|
|
54
|
+
"rollup-plugin-dts": "^6.5.1",
|
|
55
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
56
|
+
"rollup-plugin-typescript2": "^0.37.0",
|
|
57
|
+
"tslib": "^2.8.1",
|
|
58
|
+
"typescript": "^6.0.3",
|
|
59
|
+
"@rubenpazch/eslint-config": "4.0.0",
|
|
60
|
+
"@rubenpazch/typescript-config": "3.0.0"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"lbyte": {
|
|
66
|
+
"categoria": "formularios",
|
|
67
|
+
"resumen": "Área de texto con etiqueta, ayuda, advertencia, error, contador de caracteres y crecimiento automático.",
|
|
68
|
+
"usarCuando": "Textos de varias líneas: observaciones, motivos de anulación, descripciones.",
|
|
69
|
+
"evitarCuando": "Una sola línea: usa TextInput. Texto con formato (negritas, enlaces, imágenes): usa RichTextEditor."
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "rollup -c",
|
|
73
|
+
"test": "jest --passWithNoTests",
|
|
74
|
+
"test:watch": "jest --watch",
|
|
75
|
+
"lint": "eslint src",
|
|
76
|
+
"clean": "rm -rf dist"
|
|
77
|
+
}
|
|
6
78
|
}
|