@rubenpazch/form-field 0.0.0-stage → 0.1.0
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 +52 -2
- package/dist/FormField.d.ts +39 -0
- package/dist/FormField.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 +42 -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,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rubenpazch/form-field
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- catalogo:inicio (generado por pnpm catalogo, no editar) -->
|
|
4
|
+
|
|
5
|
+
FormField (etiqueta, ayuda y error asociados a cualquier control), FormRow (columnas que se apilan en móvil) y FormActions (pie con botones).
|
|
6
|
+
|
|
7
|
+
- **Usar cuando:** Armar formularios: FormRow para poner campos lado a lado, FormActions para Cancelar/Guardar, FormField para controles propios o de terceros.
|
|
8
|
+
- **Evitar cuando:** Con componentes de la librería (TextInput, Select…) no hace falta FormField: ya traen etiqueta y mensajes.
|
|
9
|
+
|
|
10
|
+
Se recomienda instalar el paquete completo `@rubenpazch/ui` (incluye este). Por separado:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @rubenpazch/form-field
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## FormField
|
|
17
|
+
|
|
18
|
+
Envoltorio de campo: etiqueta, ayuda, advertencia y error asociados a cualquier control
|
|
19
|
+
(nativo o de terceros). Los componentes de la librería ya lo traen; úsalo para controles propios.
|
|
20
|
+
|
|
21
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
22
|
+
| ----------- | ----------- | ---- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `children` | `ReactNode` | sí | | El control. Puede ser un elemento (`<input />`, `<select>`) al que se le agregan id y ARIA, o una función que recibe esos atributos: `{(props) => <MiControl {...props} />}`. |
|
|
24
|
+
| `className` | `string` | | | Clase extra para el contenedor (márgenes, ancho). |
|
|
25
|
+
| `disabled` | `boolean` | | `false` | Campo deshabilitado. |
|
|
26
|
+
| `error` | `string` | | | Mensaje de error; marca el campo como inválido. |
|
|
27
|
+
| `hint` | `string` | | | Texto de ayuda bajo el campo. |
|
|
28
|
+
| `id` | `string` | | | id del control. Si no se pasa, se genera uno. |
|
|
29
|
+
| `label` | `string` | | | Etiqueta visible del campo (se asocia al control para lectores de pantalla). |
|
|
30
|
+
| `name` | `string` | | | name del control (formularios nativos y librerías de formularios). |
|
|
31
|
+
| `required` | `boolean` | | `false` | Campo obligatorio: muestra * y marca el control como requerido. |
|
|
32
|
+
| `warning` | `string` | | | Advertencia (no bloquea). |
|
|
33
|
+
|
|
34
|
+
## FormRow
|
|
35
|
+
|
|
36
|
+
Fila de campos en columnas que se apilan en móvil.
|
|
37
|
+
|
|
38
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
39
|
+
| --------- | ------------------ | ---- | ----------- | ----------------------------------------------------------------- |
|
|
40
|
+
| `columns` | `1 \| 2 \| 3 \| 4` | | `2` | Columnas en pantallas anchas (en móvil siempre 1). Por defecto 2. |
|
|
41
|
+
|
|
42
|
+
## FormActions
|
|
43
|
+
|
|
44
|
+
Pie de formulario con los botones (Cancelar / Guardar).
|
|
45
|
+
|
|
46
|
+
| Prop | Tipo | Req. | Por defecto | Descripción |
|
|
47
|
+
| -------- | ------------------------------------------- | ---- | ----------- | ---------------------------------------------------------------------- |
|
|
48
|
+
| `align` | `"start" \| "end" \| "between" \| "center"` | | `end` | Alineación de los botones: end (por defecto), start, between o center. |
|
|
49
|
+
| `sticky` | `boolean` | | `false` | Fija el pie al fondo de la pantalla en formularios largos. |
|
|
50
|
+
|
|
51
|
+
Tipos: `FormFieldProps`, `FormFieldControlProps`, `FormRowProps`, `FormActionsProps`.
|
|
52
|
+
|
|
53
|
+
<!-- catalogo:fin -->
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { FieldProps } from "@rubenpazch/shared";
|
|
3
|
+
/** Atributos que FormField pasa al control (id y ARIA). */
|
|
4
|
+
export interface FormFieldControlProps {
|
|
5
|
+
id: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
"aria-invalid"?: true;
|
|
10
|
+
"aria-describedby"?: string;
|
|
11
|
+
"aria-required"?: true;
|
|
12
|
+
}
|
|
13
|
+
export interface FormFieldProps extends FieldProps {
|
|
14
|
+
/**
|
|
15
|
+
* El control. Puede ser un elemento (`<input />`, `<select>`) al que se le agregan id y ARIA,
|
|
16
|
+
* o una función que recibe esos atributos: `{(props) => <MiControl {...props} />}`.
|
|
17
|
+
*/
|
|
18
|
+
children: React.ReactElement | ((control: FormFieldControlProps) => React.ReactNode);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Envoltorio de campo: etiqueta, ayuda, advertencia y error asociados a cualquier control
|
|
22
|
+
* (nativo o de terceros). Los componentes de la librería ya lo traen; úsalo para controles propios.
|
|
23
|
+
*/
|
|
24
|
+
export default function FormField({ label, hint, error, warning, required, disabled, id, name, className, children, }: FormFieldProps): React.JSX.Element;
|
|
25
|
+
export interface FormRowProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
26
|
+
/** Columnas en pantallas anchas (en móvil siempre 1). Por defecto 2. */
|
|
27
|
+
columns?: 1 | 2 | 3 | 4;
|
|
28
|
+
}
|
|
29
|
+
/** Fila de campos en columnas que se apilan en móvil. */
|
|
30
|
+
export declare function FormRow({ columns, className, style, ...rest }: FormRowProps): React.JSX.Element;
|
|
31
|
+
export interface FormActionsProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
32
|
+
/** Alineación de los botones: end (por defecto), start, between o center. */
|
|
33
|
+
align?: "start" | "end" | "between" | "center";
|
|
34
|
+
/** Fija el pie al fondo de la pantalla en formularios largos. */
|
|
35
|
+
sticky?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Pie de formulario con los botones (Cancelar / Guardar). */
|
|
38
|
+
export declare function FormActions({ align, sticky, className, ...rest }: FormActionsProps): React.JSX.Element;
|
|
39
|
+
//# sourceMappingURL=FormField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../src/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMrD,2DAA2D;AAC3D,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD;;;OAGG;IACH,QAAQ,EACN,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,OAAO,EAAE,qBAAqB,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;CAC9E;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,KAAK,EACL,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAgB,EAChB,QAAgB,EAChB,EAAE,EACF,IAAI,EACJ,SAAS,EACT,QAAQ,GACT,EAAE,cAAc,qBAsDhB;AAED,MAAM,WAAW,YAAa,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IACxE,wEAAwE;IACxE,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACzB;AAED,yDAAyD;AACzD,wBAAgB,OAAO,CAAC,EACtB,OAAW,EACX,SAAS,EACT,KAAK,EACL,GAAG,IAAI,EACR,EAAE,YAAY,qBAQd;AAED,MAAM,WAAW,gBAAiB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5E,6EAA6E;IAC7E,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC/C,iEAAiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,8DAA8D;AAC9D,wBAAgB,WAAW,CAAC,EAC1B,KAAa,EACb,MAAc,EACd,SAAS,EACT,GAAG,IAAI,EACR,EAAE,gBAAgB,qBAYlB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),n=require("react"),r=require("@rubenpazch/shared");var l={field:"FormField-module_field__NtNhy",disabled:"FormField-module_disabled__6QQvg",label:"FormField-module_label__h0tkS",required:"FormField-module_required__KXTA-",hint:"FormField-module_hint__c8XID",error:"FormField-module_error__N-aJu",warning:"FormField-module_warning__w1KNU",row:"FormField-module_row__bkL0U",actions:"FormField-module_actions__uSz3M","align-start":"FormField-module_align-start__68tEg","align-end":"FormField-module_align-end__qI-0v","align-between":"FormField-module_align-between__sWMaX","align-center":"FormField-module_align-center__JYQ9f",sticky:"FormField-module_sticky__y-vnK"};!function(e,n){void 0===n&&(n={});var r=n.insertAt;if("undefined"!=typeof document){var l=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&l.firstChild?l.insertBefore(o,l.firstChild):l.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".FormField-module_field__NtNhy {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-1);\n font-family: var(--lb-font-sans);\n}\n\n.FormField-module_disabled__6QQvg {\n opacity: 0.7;\n}\n\n.FormField-module_label__h0tkS {\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.FormField-module_required__KXTA- {\n color: var(--lb-color-danger);\n}\n\n.FormField-module_hint__c8XID,\n.FormField-module_error__N-aJu,\n.FormField-module_warning__w1KNU {\n margin: 0;\n font-size: var(--lb-font-size-xs);\n}\n\n.FormField-module_hint__c8XID { color: var(--lb-color-muted-foreground); }\n.FormField-module_error__N-aJu { color: var(--lb-color-danger); }\n.FormField-module_warning__w1KNU { color: var(--lb-color-amber-strong); }\n\n.FormField-module_row__bkL0U {\n display: grid;\n grid-template-columns: 1fr;\n gap: var(--lb-space-4);\n}\n\n@media (min-width: 640px) {\n .FormField-module_row__bkL0U {\n grid-template-columns: repeat(var(--lb-form-cols, 2), minmax(0, 1fr));\n }\n}\n\n.FormField-module_actions__uSz3M {\n display: flex;\n flex-wrap: wrap;\n gap: var(--lb-space-2);\n padding-top: var(--lb-space-4);\n border-top: 1px solid var(--lb-color-border);\n}\n\n.FormField-module_align-start__68tEg { justify-content: flex-start; }\n.FormField-module_align-end__qI-0v { justify-content: flex-end; }\n.FormField-module_align-between__sWMaX { justify-content: space-between; }\n.FormField-module_align-center__JYQ9f { justify-content: center; }\n\n.FormField-module_sticky__y-vnK {\n position: sticky;\n bottom: 0;\n z-index: 1;\n padding-bottom: var(--lb-space-4);\n background: var(--lb-color-background);\n}\n");const o=(...e)=>e.filter(Boolean).join(" ");exports.FormActions=function({align:n="end",sticky:r=!1,className:i,...d}){return e.jsx("div",{className:o(l.actions,l[`align-${n}`],r&&l.sticky,i),...d})},exports.FormRow=function({columns:n=2,className:r,style:i,...d}){return e.jsx("div",{className:o(l.row,r),style:{...i,"--lb-form-cols":n},...d})},exports.default=function({label:i,hint:d,error:a,warning:t,required:s=!1,disabled:m=!1,id:_,name:c,className:u,children:F}){const b=r.useFieldIds({id:_,name:c,required:s,error:a,warning:a?void 0:t,hint:d}),f={...b.controlProps,name:c,required:s,disabled:m},g="function"==typeof F?F(f):n.cloneElement(F,f);return e.jsxs("div",{className:o(l.field,m&&l.disabled,u),children:[i&&e.jsxs("label",{htmlFor:b.inputId,className:l.label,children:[i,s&&e.jsxs("span",{className:l.required,"aria-hidden":"true",children:[" ","*"]})]}),g,a&&e.jsx("p",{id:b.errorId,className:l.error,role:"alert",children:a}),!a&&t&&e.jsx("p",{id:b.warningId,className:l.warning,children:t}),d&&e.jsx("p",{id:b.hintId,className:l.hint,children:d})]})};
|
|
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/FormField.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 from \"react\";\nimport { useFieldIds } from \"@rubenpazch/shared\";\nimport type { FieldProps } from \"@rubenpazch/shared\";\nimport styles from \"./FormField.module.css\";\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/** Atributos que FormField pasa al control (id y ARIA). */\nexport interface FormFieldControlProps {\n id: string;\n name?: string;\n required?: boolean;\n disabled?: boolean;\n \"aria-invalid\"?: true;\n \"aria-describedby\"?: string;\n \"aria-required\"?: true;\n}\n\nexport interface FormFieldProps extends FieldProps {\n /**\n * El control. Puede ser un elemento (`<input />`, `<select>`) al que se le agregan id y ARIA,\n * o una función que recibe esos atributos: `{(props) => <MiControl {...props} />}`.\n */\n children:\n React.ReactElement | ((control: FormFieldControlProps) => React.ReactNode);\n}\n\n/**\n * Envoltorio de campo: etiqueta, ayuda, advertencia y error asociados a cualquier control\n * (nativo o de terceros). Los componentes de la librería ya lo traen; úsalo para controles propios.\n */\nexport default function FormField({\n label,\n hint,\n error,\n warning,\n required = false,\n disabled = false,\n id,\n name,\n className,\n children,\n}: FormFieldProps) {\n const field = useFieldIds({\n id,\n name,\n required,\n error,\n warning: !error ? warning : undefined,\n hint,\n });\n const control: FormFieldControlProps = {\n ...field.controlProps,\n name,\n required,\n disabled,\n };\n const content =\n typeof children === \"function\"\n ? children(control)\n : React.cloneElement(\n children as React.ReactElement<Record<string, unknown>>,\n control as unknown as Record<string, unknown>,\n );\n\n return (\n <div className={cx(styles.field, disabled && styles.disabled, 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 {content}\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 );\n}\n\nexport interface FormRowProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Columnas en pantallas anchas (en móvil siempre 1). Por defecto 2. */\n columns?: 1 | 2 | 3 | 4;\n}\n\n/** Fila de campos en columnas que se apilan en móvil. */\nexport function FormRow({\n columns = 2,\n className,\n style,\n ...rest\n}: FormRowProps) {\n return (\n <div\n className={cx(styles.row, className)}\n style={{ ...style, [\"--lb-form-cols\" as string]: columns }}\n {...rest}\n />\n );\n}\n\nexport interface FormActionsProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Alineación de los botones: end (por defecto), start, between o center. */\n align?: \"start\" | \"end\" | \"between\" | \"center\";\n /** Fija el pie al fondo de la pantalla en formularios largos. */\n sticky?: boolean;\n}\n\n/** Pie de formulario con los botones (Cancelar / Guardar). */\nexport function FormActions({\n align = \"end\",\n sticky = false,\n className,\n ...rest\n}: FormActionsProps) {\n return (\n <div\n className={cx(\n styles.actions,\n styles[`align-${align}`],\n sticky && styles.sticky,\n className,\n )}\n {...rest}\n />\n );\n}\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","align","sticky","className","rest","_jsx","styles","actions","columns","row","label","hint","error","warning","required","disabled","id","name","children","field","useFieldIds","undefined","control","controlProps","content","React","cloneElement","_jsxs","htmlFor","inputId","errorId","role","warningId","hintId"],"mappings":"iwBAAA,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,qsDCpBA,MAAMe,EAAK,IAAIC,IACbA,EAAEC,OAAOC,SAASC,KAAK,mCA0HGC,MAC1BA,EAAQ,MAAKC,OACbA,GAAS,EAAKC,UACdA,KACGC,IAEH,OACEC,EAAAA,IAAA,MAAA,CACEF,UAAWP,EACTU,EAAOC,QACPD,EAAO,SAASL,KAChBC,GAAUI,EAAOJ,OACjBC,MAEEC,GAGV,kBAxCM,UAAkBI,QACtBA,EAAU,EAACL,UACXA,EAAShB,MACTA,KACGiB,IAEH,OACEC,EAAAA,IAAA,MAAA,CACEF,UAAWP,EAAGU,EAAOG,IAAKN,GAC1BhB,MAAO,IAAKA,EAAO,iBAA8BqB,MAC7CJ,GAGV,kBAtFc,UAAoBM,MAChCA,EAAKC,KACLA,EAAIC,MACJA,EAAKC,QACLA,EAAOC,SACPA,GAAW,EAAKC,SAChBA,GAAW,EAAKC,GAChBA,EAAEC,KACFA,EAAId,UACJA,EAASe,SACTA,IAEA,MAAMC,EAAQC,EAAAA,YAAY,CACxBJ,KACAC,OACAH,WACAF,QACAC,QAAUD,OAAkBS,EAAVR,EAClBF,SAEIW,EAAiC,IAClCH,EAAMI,aACTN,OACAH,WACAC,YAEIS,EACgB,mBAAbN,EACHA,EAASI,GACTG,EAAMC,aACJR,EACAI,GAGR,OACEK,EAAAA,KAAA,MAAA,CAAKxB,UAAWP,EAAGU,EAAOa,MAAOJ,GAAYT,EAAOS,SAAUZ,GAAUe,SAAA,CACrER,GACCiB,EAAAA,KAAA,QAAA,CAAOC,QAAST,EAAMU,QAAS1B,UAAWG,EAAOI,MAAKQ,SAAA,CACnDR,EACAI,GACCa,EAAAA,KAAA,OAAA,CAAMxB,UAAWG,EAAOQ,SAAQ,cAAc,OAAMI,SAAA,CACjD,IAAG,UAMXM,EACAZ,GACCP,EAAAA,IAAA,IAAA,CAAGW,GAAIG,EAAMW,QAAS3B,UAAWG,EAAOM,MAAOmB,KAAK,QAAOb,SACxDN,KAGHA,GAASC,GACTR,MAAA,IAAA,CAAGW,GAAIG,EAAMa,UAAW7B,UAAWG,EAAOO,QAAOK,SAC9CL,IAGJF,GACCN,EAAAA,IAAA,IAAA,CAAGW,GAAIG,EAAMc,OAAQ9B,UAAWG,EAAOK,KAAIO,SACxCP,MAKX","x_google_ignoreList":[0]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FieldProps } from '@rubenpazch/shared';
|
|
3
|
+
|
|
4
|
+
/** Atributos que FormField pasa al control (id y ARIA). */
|
|
5
|
+
interface FormFieldControlProps {
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
"aria-invalid"?: true;
|
|
11
|
+
"aria-describedby"?: string;
|
|
12
|
+
"aria-required"?: true;
|
|
13
|
+
}
|
|
14
|
+
interface FormFieldProps extends FieldProps {
|
|
15
|
+
/**
|
|
16
|
+
* El control. Puede ser un elemento (`<input />`, `<select>`) al que se le agregan id y ARIA,
|
|
17
|
+
* o una función que recibe esos atributos: `{(props) => <MiControl {...props} />}`.
|
|
18
|
+
*/
|
|
19
|
+
children: React.ReactElement | ((control: FormFieldControlProps) => React.ReactNode);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Envoltorio de campo: etiqueta, ayuda, advertencia y error asociados a cualquier control
|
|
23
|
+
* (nativo o de terceros). Los componentes de la librería ya lo traen; úsalo para controles propios.
|
|
24
|
+
*/
|
|
25
|
+
declare function FormField({ label, hint, error, warning, required, disabled, id, name, className, children, }: FormFieldProps): React.JSX.Element;
|
|
26
|
+
interface FormRowProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
27
|
+
/** Columnas en pantallas anchas (en móvil siempre 1). Por defecto 2. */
|
|
28
|
+
columns?: 1 | 2 | 3 | 4;
|
|
29
|
+
}
|
|
30
|
+
/** Fila de campos en columnas que se apilan en móvil. */
|
|
31
|
+
declare function FormRow({ columns, className, style, ...rest }: FormRowProps): React.JSX.Element;
|
|
32
|
+
interface FormActionsProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
33
|
+
/** Alineación de los botones: end (por defecto), start, between o center. */
|
|
34
|
+
align?: "start" | "end" | "between" | "center";
|
|
35
|
+
/** Fija el pie al fondo de la pantalla en formularios largos. */
|
|
36
|
+
sticky?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Pie de formulario con los botones (Cancelar / Guardar). */
|
|
39
|
+
declare function FormActions({ align, sticky, className, ...rest }: FormActionsProps): React.JSX.Element;
|
|
40
|
+
|
|
41
|
+
export { FormActions, FormRow, FormField as default };
|
|
42
|
+
export type { FormActionsProps, FormFieldControlProps, FormFieldProps, FormRowProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,GACjB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsxs as e,jsx as n}from"react/jsx-runtime";import r from"react";import{useFieldIds as l}from"@rubenpazch/shared";var o={field:"FormField-module_field__NtNhy",disabled:"FormField-module_disabled__6QQvg",label:"FormField-module_label__h0tkS",required:"FormField-module_required__KXTA-",hint:"FormField-module_hint__c8XID",error:"FormField-module_error__N-aJu",warning:"FormField-module_warning__w1KNU",row:"FormField-module_row__bkL0U",actions:"FormField-module_actions__uSz3M","align-start":"FormField-module_align-start__68tEg","align-end":"FormField-module_align-end__qI-0v","align-between":"FormField-module_align-between__sWMaX","align-center":"FormField-module_align-center__JYQ9f",sticky:"FormField-module_sticky__y-vnK"};!function(e,n){void 0===n&&(n={});var r=n.insertAt;if("undefined"!=typeof document){var l=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&l.firstChild?l.insertBefore(o,l.firstChild):l.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".FormField-module_field__NtNhy {\n display: flex;\n flex-direction: column;\n gap: var(--lb-space-1);\n font-family: var(--lb-font-sans);\n}\n\n.FormField-module_disabled__6QQvg {\n opacity: 0.7;\n}\n\n.FormField-module_label__h0tkS {\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.FormField-module_required__KXTA- {\n color: var(--lb-color-danger);\n}\n\n.FormField-module_hint__c8XID,\n.FormField-module_error__N-aJu,\n.FormField-module_warning__w1KNU {\n margin: 0;\n font-size: var(--lb-font-size-xs);\n}\n\n.FormField-module_hint__c8XID { color: var(--lb-color-muted-foreground); }\n.FormField-module_error__N-aJu { color: var(--lb-color-danger); }\n.FormField-module_warning__w1KNU { color: var(--lb-color-amber-strong); }\n\n.FormField-module_row__bkL0U {\n display: grid;\n grid-template-columns: 1fr;\n gap: var(--lb-space-4);\n}\n\n@media (min-width: 640px) {\n .FormField-module_row__bkL0U {\n grid-template-columns: repeat(var(--lb-form-cols, 2), minmax(0, 1fr));\n }\n}\n\n.FormField-module_actions__uSz3M {\n display: flex;\n flex-wrap: wrap;\n gap: var(--lb-space-2);\n padding-top: var(--lb-space-4);\n border-top: 1px solid var(--lb-color-border);\n}\n\n.FormField-module_align-start__68tEg { justify-content: flex-start; }\n.FormField-module_align-end__qI-0v { justify-content: flex-end; }\n.FormField-module_align-between__sWMaX { justify-content: space-between; }\n.FormField-module_align-center__JYQ9f { justify-content: center; }\n\n.FormField-module_sticky__y-vnK {\n position: sticky;\n bottom: 0;\n z-index: 1;\n padding-bottom: var(--lb-space-4);\n background: var(--lb-color-background);\n}\n");const i=(...e)=>e.filter(Boolean).join(" ");function d({label:d,hint:a,error:t,warning:m,required:_=!1,disabled:s=!1,id:c,name:u,className:F,children:f}){const g=l({id:c,name:u,required:_,error:t,warning:t?void 0:m,hint:a}),b={...g.controlProps,name:u,required:_,disabled:s},p="function"==typeof f?f(b):r.cloneElement(f,b);return e("div",{className:i(o.field,s&&o.disabled,F),children:[d&&e("label",{htmlFor:g.inputId,className:o.label,children:[d,_&&e("span",{className:o.required,"aria-hidden":"true",children:[" ","*"]})]}),p,t&&n("p",{id:g.errorId,className:o.error,role:"alert",children:t}),!t&&m&&n("p",{id:g.warningId,className:o.warning,children:m}),a&&n("p",{id:g.hintId,className:o.hint,children:a})]})}function a({columns:e=2,className:r,style:l,...d}){return n("div",{className:i(o.row,r),style:{...l,"--lb-form-cols":e},...d})}function t({align:e="end",sticky:r=!1,className:l,...d}){return n("div",{className:i(o.actions,o[`align-${e}`],r&&o.sticky,l),...d})}export{t as FormActions,a as FormRow,d 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/FormField.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 from \"react\";\nimport { useFieldIds } from \"@rubenpazch/shared\";\nimport type { FieldProps } from \"@rubenpazch/shared\";\nimport styles from \"./FormField.module.css\";\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/** Atributos que FormField pasa al control (id y ARIA). */\nexport interface FormFieldControlProps {\n id: string;\n name?: string;\n required?: boolean;\n disabled?: boolean;\n \"aria-invalid\"?: true;\n \"aria-describedby\"?: string;\n \"aria-required\"?: true;\n}\n\nexport interface FormFieldProps extends FieldProps {\n /**\n * El control. Puede ser un elemento (`<input />`, `<select>`) al que se le agregan id y ARIA,\n * o una función que recibe esos atributos: `{(props) => <MiControl {...props} />}`.\n */\n children:\n React.ReactElement | ((control: FormFieldControlProps) => React.ReactNode);\n}\n\n/**\n * Envoltorio de campo: etiqueta, ayuda, advertencia y error asociados a cualquier control\n * (nativo o de terceros). Los componentes de la librería ya lo traen; úsalo para controles propios.\n */\nexport default function FormField({\n label,\n hint,\n error,\n warning,\n required = false,\n disabled = false,\n id,\n name,\n className,\n children,\n}: FormFieldProps) {\n const field = useFieldIds({\n id,\n name,\n required,\n error,\n warning: !error ? warning : undefined,\n hint,\n });\n const control: FormFieldControlProps = {\n ...field.controlProps,\n name,\n required,\n disabled,\n };\n const content =\n typeof children === \"function\"\n ? children(control)\n : React.cloneElement(\n children as React.ReactElement<Record<string, unknown>>,\n control as unknown as Record<string, unknown>,\n );\n\n return (\n <div className={cx(styles.field, disabled && styles.disabled, 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 {content}\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 );\n}\n\nexport interface FormRowProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Columnas en pantallas anchas (en móvil siempre 1). Por defecto 2. */\n columns?: 1 | 2 | 3 | 4;\n}\n\n/** Fila de campos en columnas que se apilan en móvil. */\nexport function FormRow({\n columns = 2,\n className,\n style,\n ...rest\n}: FormRowProps) {\n return (\n <div\n className={cx(styles.row, className)}\n style={{ ...style, [\"--lb-form-cols\" as string]: columns }}\n {...rest}\n />\n );\n}\n\nexport interface FormActionsProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Alineación de los botones: end (por defecto), start, between o center. */\n align?: \"start\" | \"end\" | \"between\" | \"center\";\n /** Fija el pie al fondo de la pantalla en formularios largos. */\n sticky?: boolean;\n}\n\n/** Pie de formulario con los botones (Cancelar / Guardar). */\nexport function FormActions({\n align = \"end\",\n sticky = false,\n className,\n ...rest\n}: FormActionsProps) {\n return (\n <div\n className={cx(\n styles.actions,\n styles[`align-${align}`],\n sticky && styles.sticky,\n className,\n )}\n {...rest}\n />\n );\n}\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","FormField","label","hint","error","warning","required","disabled","id","name","className","children","field","useFieldIds","undefined","control","controlProps","content","React","cloneElement","_jsxs","styles","htmlFor","inputId","_jsx","errorId","role","warningId","hintId","FormRow","columns","rest","row","FormActions","align","sticky","actions"],"mappings":"+tBAAA,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,qsDCpBA,MAAMe,EAAK,IAAIC,IACbA,EAAEC,OAAOC,SAASC,KAAK,KA0BX,SAAUC,GAAUC,MAChCA,EAAKC,KACLA,EAAIC,MACJA,EAAKC,QACLA,EAAOC,SACPA,GAAW,EAAKC,SAChBA,GAAW,EAAKC,GAChBA,EAAEC,KACFA,EAAIC,UACJA,EAASC,SACTA,IAEA,MAAMC,EAAQC,EAAY,CACxBL,KACAC,OACAH,WACAF,QACAC,QAAUD,OAAkBU,EAAVT,EAClBF,SAEIY,EAAiC,IAClCH,EAAMI,aACTP,OACAH,WACAC,YAEIU,EACgB,mBAAbN,EACHA,EAASI,GACTG,EAAMC,aACJR,EACAI,GAGR,OACEK,EAAA,MAAA,CAAKV,UAAWd,EAAGyB,EAAOT,MAAOL,GAAYc,EAAOd,SAAUG,GAAUC,SAAA,CACrET,GACCkB,EAAA,QAAA,CAAOE,QAASV,EAAMW,QAASb,UAAWW,EAAOnB,MAAKS,SAAA,CACnDT,EACAI,GACCc,EAAA,OAAA,CAAMV,UAAWW,EAAOf,SAAQ,cAAc,OAAMK,SAAA,CACjD,IAAG,UAMXM,EACAb,GACCoB,EAAA,IAAA,CAAGhB,GAAII,EAAMa,QAASf,UAAWW,EAAOjB,MAAOsB,KAAK,QAAOf,SACxDP,KAGHA,GAASC,GACTmB,EAAA,IAAA,CAAGhB,GAAII,EAAMe,UAAWjB,UAAWW,EAAOhB,QAAOM,SAC9CN,IAGJF,GACCqB,EAAA,IAAA,CAAGhB,GAAII,EAAMgB,OAAQlB,UAAWW,EAAOlB,KAAIQ,SACxCR,MAKX,CAQM,SAAU0B,GAAQC,QACtBA,EAAU,EAACpB,UACXA,EAASvB,MACTA,KACG4C,IAEH,OACEP,EAAA,MAAA,CACEd,UAAWd,EAAGyB,EAAOW,IAAKtB,GAC1BvB,MAAO,IAAKA,EAAO,iBAA8B2C,MAC7CC,GAGV,UAUgBE,GAAYC,MAC1BA,EAAQ,MAAKC,OACbA,GAAS,EAAKzB,UACdA,KACGqB,IAEH,OACEP,EAAA,MAAA,CACEd,UAAWd,EACTyB,EAAOe,QACPf,EAAO,SAASa,KAChBC,GAAUd,EAAOc,OACjBzB,MAEEqB,GAGV","x_google_ignoreList":[0]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rubenpazch/form-field",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Envoltorio de campo, filas y pie de formulario",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rubenpazch/lbyte-ui-library.git",
|
|
8
|
+
"directory": "packages/form-field"
|
|
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.4.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": "FormField (etiqueta, ayuda y error asociados a cualquier control), FormRow (columnas que se apilan en móvil) y FormActions (pie con botones).",
|
|
68
|
+
"usarCuando": "Armar formularios: FormRow para poner campos lado a lado, FormActions para Cancelar/Guardar, FormField para controles propios o de terceros.",
|
|
69
|
+
"evitarCuando": "Con componentes de la librería (TextInput, Select…) no hace falta FormField: ya traen etiqueta y mensajes."
|
|
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
|
}
|