@rubenpazch/textarea 0.1.0 → 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/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +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-
|
|
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
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +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,
|
|
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,EAAVhB,EAClBF,SAEImB,EAAQC,EAAAA,OAA4B,MAE1CC,EAAAA,gBAAgB,KACd,MAAMC,EAAKH,EAAMI,QACjB,IAAKZ,IAAeW,EAAI,OACxBA,EAAGxC,MAAM0C,OAAS,OAClB,MAAMC,EAAOC,WAAWC,iBAAiBL,GAAIM,aAAe,GAC5DN,EAAGxC,MAAM0C,OAAS,GAAGK,KAAKC,IAA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GED
|
@@ -1,2 +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",
|
|
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
2
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +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,
|
|
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,EAAKC,QAClBA,EAAU,GAAEC,UACZA,GAAY,EAAIC,UAChBA,KACGC,GAELtC,GAEA,MAAMuC,EAAQC,EAAY,CACxBZ,KACAC,OACAH,WACAF,QACAC,QAAUD,OAAkBiB,EAAVhB,EAClBF,SAEImB,EAAQC,EAA4B,MAE1CC,EAAgB,KACd,MAAMC,EAAKH,EAAMI,QACjB,IAAKZ,IAAeW,EAAI,OACxBA,EAAGxC,MAAM0C,OAAS,OAClB,M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":[0]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/textarea",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Área de texto con contador y crecimiento automático",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "^19.2.3",
|
|
29
29
|
"react-dom": "^19.2.3",
|
|
30
|
-
"@rubenpazch/tokens": "0.
|
|
30
|
+
"@rubenpazch/tokens": "0.5.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@rubenpazch/shared": "5.2.0"
|