@dubix/ui 0.0.0-stage → 0.2.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.
@@ -0,0 +1,25 @@
1
+ import { type AriaAttributes, type ReactElement, type ReactNode } from 'react';
2
+ /** Lo que Field le agrega al control. Input, Textarea o cualquier componente que pase estas props a su elemento nativo. */
3
+ export interface FieldControlProps {
4
+ id?: string | undefined;
5
+ required?: boolean | undefined;
6
+ 'aria-describedby'?: string | undefined;
7
+ 'aria-invalid'?: AriaAttributes['aria-invalid'];
8
+ }
9
+ export interface FieldProps {
10
+ /** Texto de la etiqueta. Obligatorio: es el nombre accesible del control. */
11
+ label: ReactNode;
12
+ /** Texto de ayuda debajo del control. Mientras haya `error`, no se muestra. */
13
+ help?: ReactNode;
14
+ /** Mensaje de error. Lo decide la pantalla: Field no valida. Marca el control con `aria-invalid="true"`. */
15
+ error?: ReactNode;
16
+ /** Campo obligatorio: asterisco en la etiqueta (`aria-hidden`) y `required` en el control. */
17
+ required?: boolean | undefined;
18
+ /** id del control (sin espacios). Si no viene o es vacío, se usa el del control y, si tampoco tiene, uno generado con `useId`. */
19
+ id?: string | undefined;
20
+ /** Se suma a `dx-field`, en el contenedor. */
21
+ className?: string | undefined;
22
+ /** Un solo control: `<Input />` o `<Textarea />`. */
23
+ children: ReactElement<FieldControlProps>;
24
+ }
25
+ export declare function Field({ label, help, error, required, id, className, children }: FieldProps): import("react").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment, cloneElement, isValidElement, useId } from 'react';
3
+ const hasContent = (node) => node != null && typeof node !== 'boolean' && node !== '';
4
+ const AlertIcon = () => (_jsxs("svg", { className: "dx-field__error-icon", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", "aria-hidden": "true", focusable: "false", children: [_jsx("circle", { cx: "8", cy: "8", r: "6.25" }), _jsx("path", { d: "M8 4.75v3.5M8 11.1v.15" })] }));
5
+ export function Field({ label, help, error, required = false, id, className, children }) {
6
+ const generatedId = useId();
7
+ // Un Fragment también es un elemento válido, pero clonarlo no cablea nada: el label quedaría apuntando a un id inexistente.
8
+ if (!isValidElement(children) || children.type === Fragment) {
9
+ throw new Error('Field: el hijo tiene que ser un único control (<Input /> o <Textarea />), no texto, varios hijos ni un Fragment.');
10
+ }
11
+ const control = children.props;
12
+ // || y no ??: un id vacío ("") dejaría el label sin asociar.
13
+ const controlId = id || control.id || generatedId;
14
+ const helpId = controlId + '-ayuda';
15
+ const errorId = controlId + '-error';
16
+ const showError = hasContent(error);
17
+ const showHelp = !showError && hasContent(help);
18
+ const describedBy = [control['aria-describedby'], showHelp && helpId, showError && errorId].filter(Boolean).join(' ');
19
+ return (_jsxs("div", { className: className ? `dx-field ${className}` : 'dx-field', children: [_jsxs("label", { className: "dx-field__label", htmlFor: controlId, children: [label, required && _jsx("span", { className: "dx-field__required", "aria-hidden": "true", children: "*" })] }), cloneElement(children, {
20
+ id: controlId,
21
+ 'aria-describedby': describedBy || undefined,
22
+ 'aria-invalid': showError ? true : control['aria-invalid'],
23
+ required: required || control.required,
24
+ }), showHelp && _jsx("p", { className: "dx-field__help", id: helpId, children: help }), showError && (_jsxs("p", { className: "dx-field__error", id: errorId, children: [_jsx(AlertIcon, {}), _jsx("span", { children: error })] }))] }));
25
+ }
@@ -0,0 +1,2 @@
1
+ export { Field } from './Field.js';
2
+ export type { FieldControlProps, FieldProps } from './Field.js';
@@ -0,0 +1 @@
1
+ export { Field } from './Field.js';
@@ -0,0 +1,12 @@
1
+ import type { ComponentPropsWithRef, ReactNode } from 'react';
2
+ export interface InputProps extends Omit<ComponentPropsWithRef<'input'>, 'size'> {
3
+ /** Ícono antes del texto; se renderiza con `aria-hidden`. */
4
+ iconStart?: ReactNode;
5
+ /** Ícono después del texto; se renderiza con `aria-hidden`. */
6
+ iconEnd?: ReactNode;
7
+ }
8
+ /**
9
+ * Campo de texto de una línea. Las props van al `<input>` nativo (también `ref`); `className`, al contenedor `.dx-input`.
10
+ * `size` (el ancho en caracteres de HTML) no se acepta: queda reservado para los tamaños del componente.
11
+ */
12
+ export declare function Input({ iconStart, iconEnd, className, ...rest }: InputProps): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const hasNode = (node) => node != null && typeof node !== 'boolean';
3
+ /**
4
+ * Campo de texto de una línea. Las props van al `<input>` nativo (también `ref`); `className`, al contenedor `.dx-input`.
5
+ * `size` (el ancho en caracteres de HTML) no se acepta: queda reservado para los tamaños del componente.
6
+ */
7
+ export function Input({ iconStart, iconEnd, className, ...rest }) {
8
+ return (_jsxs("div", { className: className ? `dx-input ${className}` : 'dx-input', children: [hasNode(iconStart) && _jsx("span", { className: "dx-input__icon", "aria-hidden": "true", children: iconStart }), _jsx("input", { ...rest, className: "dx-input__control" }), hasNode(iconEnd) && _jsx("span", { className: "dx-input__icon", "aria-hidden": "true", children: iconEnd })] }));
9
+ }
@@ -0,0 +1,2 @@
1
+ export { Input } from './Input.js';
2
+ export type { InputProps } from './Input.js';
@@ -0,0 +1 @@
1
+ export { Input } from './Input.js';
@@ -0,0 +1,18 @@
1
+ import type { ComponentPropsWithRef } from 'react';
2
+ /** Forma del marcador: una línea de texto, un rectángulo (campo, botón, imagen) o un círculo (avatar). */
3
+ export type SkeletonShape = 'row' | 'block' | 'circle';
4
+ /** `aria-hidden` queda fuera: el marcador siempre está oculto a los lectores de pantalla. */
5
+ export interface SkeletonProps extends Omit<ComponentPropsWithRef<'div'>, 'aria-hidden'> {
6
+ /** Forma. Por defecto `row`. */
7
+ shape?: SkeletonShape | undefined;
8
+ /** Ancho: número en px o longitud CSS. Por defecto 100 % (`row`, `block`); en `circle` es el diámetro. */
9
+ width?: number | string | undefined;
10
+ /** Alto: número en px o longitud CSS. Por defecto una línea de texto (`row`), un control (`block`) o el diámetro (`circle`). */
11
+ height?: number | string | undefined;
12
+ }
13
+ /**
14
+ * Marcador de carga con la forma del contenido que reemplaza. Siempre `aria-hidden`: quien anuncia «cargando» es la
15
+ * pantalla, con un contenedor `role="status"` y `aria-busy="true"`. `className` se suma a `dx-skeleton`; `ref`, `style`
16
+ * y el resto de las props van al `<div>`.
17
+ */
18
+ export declare function Skeleton({ shape, width, height, className, style, ...rest }: SkeletonProps): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Marcador de carga con la forma del contenido que reemplaza. Siempre `aria-hidden`: quien anuncia «cargando» es la
4
+ * pantalla, con un contenedor `role="status"` y `aria-busy="true"`. `className` se suma a `dx-skeleton`; `ref`, `style`
5
+ * y el resto de las props van al `<div>`.
6
+ */
7
+ export function Skeleton({ shape = 'row', width, height, className, style, ...rest }) {
8
+ // Un círculo tiene un solo tamaño: el que venga (width o height) vale para los dos lados.
9
+ const size = shape === 'circle' ? (width ?? height) : undefined;
10
+ return (_jsx("div", { ...rest, className: className ? `dx-skeleton ${className}` : 'dx-skeleton', "data-shape": shape, "aria-hidden": "true", style: { width: size ?? width, height: size ?? height, ...style } }));
11
+ }
@@ -0,0 +1,2 @@
1
+ export { Skeleton } from './Skeleton.js';
2
+ export type { SkeletonProps, SkeletonShape } from './Skeleton.js';
@@ -0,0 +1 @@
1
+ export { Skeleton } from './Skeleton.js';