@raulaguila/maat-ui 0.8.1 → 0.10.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 CHANGED
@@ -194,3 +194,8 @@ Valem para endpoints, tabelas e jobs novos. Os contratos v1 existentes continuam
194
194
  | Idiomas | Catálogo em `src/lib/i18n/messages.ts` (`pt-BR` é a fonte, `en-US` tem as mesmas chaves). `make check-i18n` roda o teste vitest de paridade de chaves. |
195
195
  | Rotas | Recursos de um usuário ficam em `[username]/[slug]`. Abas de página usam `PageTabs`. |
196
196
  | Código | Alias `@/` para `src/`; ESLint com `core-web-vitals` e `typescript` do `eslint-config-next`; `app/error.tsx` em cada aplicação. |
197
+
198
+
199
+ Nos formulários, use `<FormField floating="select" label="Idioma">` diretamente ao redor do `SelectTrigger`, do `DropdownSelectTrigger`, do `SearchableChoice` ou do `select` nativo de escolha única. O campo associa o rótulo ao controle e mantém a ajuda e o erro acessíveis. No seletor nativo, `<option value="">Selecione</option>` representa o estado vazio. Para exibir uma escolha explícita como “Nenhum” mesmo quando seu valor é a string vazia, marque essa opção com `data-value-label`.
200
+
201
+ Para textos de várias linhas com rótulo curto, use `<FormField floating="textarea" label="Observações"><Textarea rows={3} /></FormField>`. O rótulo vazio começa na primeira linha. Mantenha perguntas longas acima do controle. A altura máxima padrão é o menor valor entre 16 rem e 35% da altura visível da tela, com rolagem interna.
@@ -18,11 +18,11 @@ export function DropdownSelect({ children, ...selection }) {
18
18
  }
19
19
  export function DropdownSelectTrigger({ children, className, size = "default", disabled, ...props }) {
20
20
  const selection = useSelection();
21
- return _jsxs(DropdownMenuTrigger, { ...props, "data-slot": "dropdown-select-trigger", disabled: selection.disabled || disabled, render: _jsx(Button, { variant: "outline", size: size }), className: cn("min-w-0 max-w-full justify-between border-input dark:bg-[color-mix(in_oklab,var(--input-fill)_30%,transparent)]", className), children: [children, _jsx(ChevronDown, { className: "size-3.5 shrink-0 text-muted-foreground", "aria-hidden": true })] });
21
+ return _jsxs(DropdownMenuTrigger, { ...props, "data-slot": "dropdown-select-trigger", "data-placeholder": selection.value == null || selection.value === "" ? "" : undefined, disabled: selection.disabled || disabled, render: _jsx(Button, { variant: "outline", size: size }), className: cn("min-w-0 max-w-full justify-between border-input dark:bg-[color-mix(in_oklab,var(--input-fill)_30%,transparent)]", className), children: [children, _jsx(ChevronDown, { className: "size-3.5 shrink-0 text-muted-foreground", "aria-hidden": true })] });
22
22
  }
23
23
  export function DropdownSelectValue({ children, placeholder, className, ...props }) {
24
24
  const { value, items } = useSelection();
25
- return _jsx("span", { ...props, className: cn("block min-w-0 flex-1 truncate text-left", className), children: children ?? (value == null ? placeholder : items?.[value] ?? (value || placeholder)) });
25
+ return _jsx("span", { "data-slot": "select-value", ...props, className: cn("block min-w-0 flex-1 truncate text-left", className), children: children ?? (value == null ? placeholder : items?.[value] ?? (value || placeholder)) });
26
26
  }
27
27
  export function DropdownSelectContent({ children, className, ...props }) {
28
28
  const { value, onValueChange, disabled } = useSelection();
@@ -3,8 +3,7 @@ import { type ComponentProps, type ReactNode } from "react";
3
3
  export declare function FormFieldGrid({ className, columns, ...props }: ComponentProps<"div"> & {
4
4
  columns?: 2 | 3;
5
5
  }): import("react").JSX.Element;
6
- export declare function FormField({ id, label, description, error, children, className, labelClassName, floating }: {
7
- id: string;
6
+ export declare function FormField({ id: providedId, label, description, error, children, className, labelClassName, floating }: {
8
7
  label: ReactNode;
9
8
  description?: ReactNode;
10
9
  /** Shown in place of the description, in red and announced; marks the control aria-invalid. */
@@ -12,6 +11,10 @@ export declare function FormField({ id, label, description, error, children, cla
12
11
  children: ReactNode;
13
12
  className?: string;
14
13
  labelClassName?: string;
15
- /** Float the label on the border of a single text or password input. */
14
+ } & ({
15
+ id: string;
16
16
  floating?: boolean;
17
- }): import("react").JSX.Element;
17
+ } | {
18
+ id?: string;
19
+ floating: "select" | "textarea";
20
+ })): import("react").JSX.Element;
@@ -1,20 +1,23 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { cloneElement, isValidElement } from "react";
2
+ import { cloneElement, isValidElement, useId } from "react";
3
3
  import { Label } from "./label.js";
4
4
  import { cn } from "./cn.js";
5
5
  /** Share label, control and help rows so wrapped labels never offset controls. */
6
6
  export function FormFieldGrid({ className, columns = 2, ...props }) {
7
7
  return _jsx("div", { "data-slot": "form-field-grid", className: cn("grid min-w-0 grid-cols-1 gap-x-4 gap-y-4 sm:gap-y-0 sm:*:data-[slot=form-field]:row-span-3 sm:*:data-[slot=form-field]:grid-rows-subgrid", columns === 3 ? "sm:grid-cols-3" : "sm:grid-cols-2", className), ...props });
8
8
  }
9
- export function FormField({ id, label, description, error, children, className, labelClassName, floating = false }) {
9
+ export function FormField({ id: providedId, label, description, error, children, className, labelClassName, floating = false }) {
10
+ const generatedId = useId();
11
+ const id = providedId ?? (isValidElement(children) ? children.props.id : undefined) ?? generatedId;
10
12
  const note = error || description;
11
13
  const noteId = `${id}-note`;
12
14
  // The single control gets the state and the note's id; a group of controls sets its own.
13
15
  const control = isValidElement(children) ? cloneElement(children, {
14
- ...(floating ? { id, placeholder: children.props.placeholder || " " } : {}),
16
+ ...(floating ? { id } : {}),
17
+ ...(floating && floating !== "select" ? { placeholder: children.props.placeholder || " " } : {}),
15
18
  "aria-invalid": error ? true : children.props["aria-invalid"],
16
19
  "aria-describedby": note ? [children.props["aria-describedby"], noteId].filter(Boolean).join(" ") : children.props["aria-describedby"],
17
20
  }) : children;
18
21
  const fieldLabel = _jsx(Label, { htmlFor: id, className: cn(!floating && "self-end pb-2", labelClassName), children: label });
19
- return _jsxs("div", { "data-slot": "form-field", className: cn("grid min-w-0 grid-rows-[auto_auto_1fr] content-start gap-0", className), children: [floating ? _jsxs("div", { "data-ui-floating-control": true, children: [fieldLabel, _jsx("div", { "data-ui-floating-input": true, children: control }), _jsx("span", { "data-ui-floating-edge": true, "aria-hidden": "true" })] }) : _jsxs(_Fragment, { children: [fieldLabel, _jsx("div", { "data-slot": "form-control", className: "min-w-0 self-start *:data-[slot=select-trigger]:w-full *:data-[slot=dropdown-select-trigger]:w-full", children: control })] }), _jsx("div", { id: noteId, "data-slot": "form-description", role: error ? "alert" : undefined, className: cn("min-w-0 space-y-2 text-xs", error ? "text-destructive" : "text-muted-foreground", note && "pt-2"), "aria-hidden": note ? undefined : true, children: note })] });
22
+ return _jsxs("div", { "data-slot": "form-field", className: cn("grid min-w-0 grid-rows-[auto_auto_1fr] content-start gap-0", className), children: [floating ? _jsxs("div", { "data-ui-floating-control": typeof floating === "string" ? floating : "", children: [fieldLabel, _jsx("div", { "data-ui-floating-input": true, children: control }), _jsx("span", { "data-ui-floating-edge": true, "aria-hidden": "true" })] }) : _jsxs(_Fragment, { children: [fieldLabel, _jsx("div", { "data-slot": "form-control", className: "min-w-0 self-start *:data-[slot=select-trigger]:w-full *:data-[slot=dropdown-select-trigger]:w-full", children: control })] }), _jsx("div", { id: noteId, "data-slot": "form-description", role: error ? "alert" : undefined, className: cn("min-w-0 space-y-2 text-xs", error ? "text-destructive" : "text-muted-foreground", note && "pt-2"), "aria-hidden": note ? undefined : true, children: note })] });
20
23
  }
@@ -17,7 +17,7 @@ export function SearchableChoice({ options, value, onValueChange, placeholder, s
17
17
  return _jsxs(DropdownSelect, { value: value, onValueChange: onValueChange, items: Object.fromEntries(options.map(o => [o.value, o.label])), children: [_jsx(DropdownSelectTrigger, { ...trigger, children: _jsx(DropdownSelectValue, { placeholder: placeholder }) }), _jsx(DropdownSelectContent, { children: options.map(o => _jsxs(DropdownSelectItem, { value: o.value, label: o.label, description: o.description, children: [o.icon, o.label] }, o.value)) })] });
18
18
  const label = (id) => options.find(o => o.value === id)?.label ?? id;
19
19
  return _jsxs(Combobox.Root, { items: options.map(o => o.value), value: value, onValueChange: next => { if (next !== null)
20
- onValueChange(next); }, itemToStringLabel: label, children: [_jsxs(Combobox.Trigger, { ...trigger, render: _jsx(Button, { variant: "outline" }), className: cn("min-w-0 max-w-full justify-between", trigger.className), children: [_jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: value ? label(value) : placeholder }), _jsx(ChevronDown, { className: "size-3.5 shrink-0 text-muted-foreground", "aria-hidden": true })] }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { sideOffset: 4, align: "start", className: "z-50", children: _jsxs(Combobox.Popup, { className: "flex max-h-[min(420px,var(--available-height))] w-[max(260px,var(--anchor-width))] max-w-[calc(100vw-32px)] flex-col rounded-lg bg-popover p-2 text-popover-foreground shadow-md ring-1 ring-foreground/10", children: [_jsx(Combobox.Input, { render: _jsx(Input, {}), "aria-label": searchLabel, placeholder: searchLabel, className: "mb-2 min-h-11 shrink-0" }), _jsx(Combobox.Empty, { className: "p-3 text-sm text-muted-foreground empty:hidden", children: noChoices }), _jsx(Combobox.List, { className: "min-h-0 overflow-y-auto overscroll-contain", children: (id) => {
20
+ onValueChange(next); }, itemToStringLabel: label, children: [_jsxs(Combobox.Trigger, { "data-slot": "searchable-choice-trigger", "data-placeholder": value ? undefined : "", ...trigger, render: _jsx(Button, { variant: "outline" }), className: cn("min-w-0 max-w-full justify-between", trigger.className), children: [_jsx("span", { "data-slot": "select-value", className: "min-w-0 flex-1 truncate text-left", children: value ? label(value) : placeholder }), _jsx(ChevronDown, { className: "size-3.5 shrink-0 text-muted-foreground", "aria-hidden": true })] }), _jsx(Combobox.Portal, { children: _jsx(Combobox.Positioner, { sideOffset: 4, align: "start", className: "z-50", children: _jsxs(Combobox.Popup, { className: "flex max-h-[min(420px,var(--available-height))] w-[max(260px,var(--anchor-width))] max-w-[calc(100vw-32px)] flex-col rounded-lg bg-popover p-2 text-popover-foreground shadow-md ring-1 ring-foreground/10", children: [_jsx(Combobox.Input, { render: _jsx(Input, {}), "aria-label": searchLabel, placeholder: searchLabel, className: "mb-2 min-h-11 shrink-0" }), _jsx(Combobox.Empty, { className: "p-3 text-sm text-muted-foreground empty:hidden", children: noChoices }), _jsx(Combobox.List, { className: "min-h-0 overflow-y-auto overscroll-contain", children: (id) => {
21
21
  const option = options.find(o => o.value === id);
22
22
  const index = options.indexOf(option);
23
23
  return _jsxs(Combobox.Item, { value: id, "aria-label": option.label, "aria-describedby": option.description ? `${uid}-${index}` : undefined, className: "flex min-h-11 cursor-default items-start gap-2 rounded-md px-2 py-2 text-sm outline-none data-highlighted:bg-accent data-highlighted:text-accent-foreground", children: [_jsx("span", { className: "w-4 shrink-0", children: _jsx(Combobox.ItemIndicator, { children: _jsx(Check, { className: "size-4" }) }) }), _jsxs("span", { className: "min-w-0 flex-1 wrap-anywhere", children: [_jsxs("span", { className: "flex items-center gap-2", children: [option.icon, option.label] }), option.description && _jsx("span", { id: `${uid}-${index}`, className: "mt-1 block text-xs text-muted-foreground", children: option.description })] })] }, id);
package/dist/textarea.js CHANGED
@@ -2,6 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cn } from "./cn.js";
3
3
  /** Multi-line twin of Input: same border, fill, focus and invalid states. */
4
4
  function Textarea({ className, ...props }) {
5
- return (_jsx("textarea", { "data-slot": "textarea", className: cn("w-full min-w-0 rounded-lg border border-input bg-card px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground/70 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-[color-mix(in_oklab,var(--input-fill)_30%,transparent)] dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className), ...props }));
5
+ return (_jsx("textarea", { "data-slot": "textarea", className: cn("block w-full min-w-0 max-h-(--textarea-max-height) resize-y overflow-y-auto rounded-lg border border-input bg-card px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground/70 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-[color-mix(in_oklab,var(--input-fill)_30%,transparent)] dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className), ...props }));
6
6
  }
7
7
  export { Textarea };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raulaguila/maat-ui",
3
- "version": "0.8.1",
3
+ "version": "0.10.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public"
package/styles.css CHANGED
@@ -114,6 +114,7 @@
114
114
  --space-list: 0.75rem;
115
115
  --space-card: 1.25rem;
116
116
  --space-row: 0.5rem;
117
+ --textarea-max-height: min(16rem, 35dvh);
117
118
  --control-h: 2rem;
118
119
  --control-h-sm: 1.75rem;
119
120
  --control-h-lg: 2.25rem;
@@ -484,13 +485,52 @@ html[data-density="compact"] {
484
485
  & > [data-ui-floating-edge] { border-top-color: var(--field-line) }
485
486
  & input::placeholder { color: transparent }
486
487
  }
487
- [data-ui-floating-control]:focus-within { --field-line: var(--ring); --field-stroke: 2px }
488
- [data-ui-floating-control]:focus-within > label { color: var(--primary) }
489
- [data-ui-floating-control]:has(input[aria-invalid=true]) { --field-line: var(--destructive) }
490
- [data-ui-floating-control]:has(input[aria-invalid=true]) > label { color: var(--destructive) }
488
+ [data-ui-floating-control="textarea"] {
489
+ & [data-ui-floating-input] textarea {
490
+ display: block;
491
+ width: 100%;
492
+ max-height: var(--textarea-max-height);
493
+ overflow-y: auto;
494
+ border-color: transparent;
495
+ box-shadow: none;
496
+ }
497
+ &:not(:focus-within):has(textarea:placeholder-shown) {
498
+ & > label {
499
+ top: .5625rem;
500
+ transform: none;
501
+ line-height: 1.25rem;
502
+ font-size: .875rem;
503
+ cursor: text;
504
+ }
505
+ & > [data-ui-floating-edge] { border-top-color: var(--field-line) }
506
+ & textarea::placeholder { color: transparent }
507
+ }
508
+ &:has(textarea:disabled) > label { opacity: .65 }
509
+ }
510
+ [data-ui-floating-control="select"] {
511
+ & [data-ui-floating-input] :is(select, button[aria-haspopup]) {
512
+ width: 100%;
513
+ min-width: 0;
514
+ border-color: transparent;
515
+ box-shadow: none;
516
+ }
517
+ & > label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block }
518
+ &:not(:focus-within):not(:has([aria-expanded="true"])):has([data-placeholder], select option:checked[value=""]:not([data-value-label])) {
519
+ & > label { top: 50%; font-size: .875rem; pointer-events: none }
520
+ & > [data-ui-floating-edge] { border-top-color: var(--field-line) }
521
+ & [data-slot="select-value"] { visibility: hidden }
522
+ & select { color: transparent }
523
+ & select option { color: var(--foreground) }
524
+ }
525
+ &:has(select:disabled, button:disabled, [aria-disabled="true"]) > label { opacity: .65 }
526
+ }
527
+ [data-ui-floating-control]:is(:focus-within, :has([aria-expanded="true"])) { --field-line: var(--ring); --field-stroke: 2px }
528
+ [data-ui-floating-control]:is(:focus-within, :has([aria-expanded="true"])) > label { color: var(--primary) }
529
+ [data-ui-floating-control]:has([aria-invalid=true]) { --field-line: var(--destructive) }
530
+ [data-ui-floating-control]:has([aria-invalid=true]) > label { color: var(--destructive) }
491
531
  @media (forced-colors: active) {
492
532
  [data-ui-floating-control] { --field-line: ButtonText }
493
- [data-ui-floating-control]:focus-within { --field-line: Highlight }
533
+ [data-ui-floating-control]:is(:focus-within, :has([aria-expanded="true"])) { --field-line: Highlight }
494
534
  [data-ui-floating-edge] { forced-color-adjust: none }
495
535
  }
496
536
  @media (prefers-reduced-motion: no-preference) {