Skip to content

@arqel-dev/fields — Referencia de API

21 inputs ricos de React registrados vía el FieldRegistry de @arqel-dev/ui. 12 entry points por subpath.

ts
import '@arqel-dev/fields/register';                           // side-effect: registers all 21
import { TextInput, SlugInput, slugify } from '@arqel-dev/fields';
// or subset
import { TextInput, EmailInput } from '@arqel-dev/fields/text';
import { CurrencyInput } from '@arqel-dev/fields/number';

Cada componente recibe FieldRendererProps (re-exportado desde @arqel-dev/ui/form):

ts
type FieldRendererProps = {
  field: FieldSchema;
  value: unknown;
  onChange: (value: unknown) => void;
  errors?: string[];
  disabled?: boolean;
  inputId: string;
  describedBy?: string;
};
SubpathComponentes
/textTextInput, TextareaInput, EmailInput, UrlInput, PasswordInput (toggle reveal aria-pressed)
/numberNumberInput (botones stepper), CurrencyInput (Intl-format en blur, raw en focus)
/booleanCheckbox, Toggle (role=switch + thumb iOS)
/selectSelectInput, MultiSelectInput (chips removibles), RadioGroup (role=radiogroup)
/relationshipBelongsToInput (fetch async + debounce 300ms + role=combobox/listbox), HasManyReadonly
/dateDateInput, DateTimeInput
/fileFileInput (drag-drop en un <section>), ImageInput (preview con URL.createObjectURL)
/slugSlugInput + helper slugify
/colorColorInput (picker nativo + presets + texto hex)
/hiddenHiddenInput

slugify(input: string): string

Normaliza a [a-z0-9-]+:

ts
slugify('Hello World!')        // 'hello-world'
slugify(' --foo--bar-- ')      // 'foo-bar'
slugify('São Paulo')           // 'sao-paulo' (NFD diacritics stripping)

Side-effect de register.ts

El único archivo con sideEffects: true en package.json. Importa una vez en boot:

tsx
// resources/js/app.tsx
import '@arqel-dev/ui/styles.css';
import '@arqel-dev/fields/register';
import { createArqelApp } from '@arqel-dev/react/inertia';

A partir de este import, <FieldRenderer> resuelve field.component === 'TextInput' al componente rico. Sin el import, hace fallback al nativo de @arqel-dev/ui/form.

Override personalizado

tsx
import { registerField } from '@arqel-dev/ui/form';
import { MyFancyText } from './MyFancyText';

registerField('TextInput', MyFancyText);                   // after register.ts

Tipo de Field personalizado

Tres piezas (PHP del servidor + React + register):

php
// app/Arqel/Fields/RatingField.php
final class RatingField extends Field
{
    protected string $type = 'rating';
    protected string $component = 'RatingInput';
}
tsx
// resources/js/fields/RatingInput.tsx
import type { FieldRendererProps } from '@arqel-dev/ui/form';

export function RatingInput({ field, value, onChange, errors, inputId }: FieldRendererProps) {
  // ...
}
tsx
// resources/js/app.tsx
import '@arqel-dev/fields/register';
import { registerField } from '@arqel-dev/ui/form';
import { RatingInput } from './fields/RatingInput';

registerField('RatingInput', RatingInput);

Relacionado

Licencia MIT — construido con Inertia + React + Laravel.