@raulaguila/maat-ui 0.8.0 → 0.9.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,6 @@ 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`.
@@ -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";
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: " " } : {}),
16
+ ...(floating ? { id } : {}),
17
+ ...(floating === true ? { 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, control] }) : _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": floating === "select" ? "select" : "", 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raulaguila/maat-ui",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public"
package/styles.css CHANGED
@@ -431,30 +431,85 @@ html[data-density="compact"] {
431
431
  [data-ui-app-header] { height: 56px; padding-inline: 0; margin-bottom: 8px; }
432
432
  }
433
433
 
434
- /* The native input state also covers values restored before hydration. */
435
- [data-ui-floating-control] { position: relative; min-width: 0 }
436
- [data-ui-floating-control] > label {
437
- position: absolute;
434
+ /* The label sizes the middle grid track. Its top edge opens without painting
435
+ over the surface, including on translucent inputs and native autofill. */
436
+ [data-ui-floating-control] {
437
+ --field-line: var(--input);
438
+ --field-stroke: 1px;
439
+ display: grid;
440
+ grid-template-columns: .5rem fit-content(calc(100% - 3.5rem)) minmax(0, 1fr);
441
+ position: relative;
442
+ min-width: 0;
443
+ }
444
+ [data-ui-floating-control] > * { grid-row: 1 }
445
+ [data-ui-floating-input] { grid-column: 1 / -1; min-width: 0 }
446
+ [data-ui-floating-control] [data-ui-floating-input] input {
447
+ border-color: transparent;
448
+ box-shadow: none;
449
+ }
450
+ [data-ui-floating-control]::before, [data-ui-floating-control]::after, [data-ui-floating-edge] {
451
+ grid-row: 1;
438
452
  z-index: 1;
439
- inset-inline-start: .5rem;
453
+ pointer-events: none;
454
+ border: var(--field-stroke) solid var(--field-line);
455
+ }
456
+ [data-ui-floating-control]::before, [data-ui-floating-control]::after { content: "" }
457
+ [data-ui-floating-control]::before {
458
+ grid-column: 1;
459
+ border-inline-end: 0;
460
+ border-start-start-radius: .5rem;
461
+ border-end-start-radius: .5rem;
462
+ }
463
+ [data-ui-floating-control]::after {
464
+ grid-column: 3;
465
+ border-inline-start: 0;
466
+ border-start-end-radius: .5rem;
467
+ border-end-end-radius: .5rem;
468
+ }
469
+ [data-ui-floating-edge] { grid-column: 2; border-inline: 0; border-top-color: transparent }
470
+ [data-ui-floating-control] > label {
471
+ position: relative;
472
+ grid-column: 2;
473
+ align-self: start;
474
+ z-index: 2;
440
475
  top: 0;
441
476
  transform: translateY(-50%);
442
477
  padding-inline: .25rem;
443
- max-width: calc(100% - 3.5rem);
444
- background: var(--floating-label-surface, var(--card));
445
478
  color: var(--muted-foreground);
446
479
  font-size: .75rem;
447
480
  line-height: 1rem;
448
481
  }
449
- [data-ui-floating-control]:not(:focus-within):has(input:placeholder-shown):not(:has(input:is(:autofill, :-webkit-autofill))) > label {
450
- top: 50%;
451
- background: transparent;
452
- font-size: 1rem;
453
- cursor: text;
482
+ [data-ui-floating-control]:not(:focus-within):has(input:placeholder-shown):not(:has(input:is(:autofill, :-webkit-autofill))) {
483
+ & > label { top: 50%; font-size: 1rem; cursor: text }
484
+ & > [data-ui-floating-edge] { border-top-color: var(--field-line) }
485
+ & input::placeholder { color: transparent }
486
+ }
487
+ [data-ui-floating-control="select"] {
488
+ & [data-ui-floating-input] :is(select, button[aria-haspopup]) {
489
+ width: 100%;
490
+ min-width: 0;
491
+ border-color: transparent;
492
+ box-shadow: none;
493
+ }
494
+ & > label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block }
495
+ &:not(:focus-within):not(:has([aria-expanded="true"])):has([data-placeholder], select option:checked[value=""]:not([data-value-label])) {
496
+ & > label { top: 50%; font-size: .875rem; pointer-events: none }
497
+ & > [data-ui-floating-edge] { border-top-color: var(--field-line) }
498
+ & [data-slot="select-value"] { visibility: hidden }
499
+ & select { color: transparent }
500
+ & select option { color: var(--foreground) }
501
+ }
502
+ &:has(select:disabled, button:disabled, [aria-disabled="true"]) > label { opacity: .65 }
503
+ }
504
+ [data-ui-floating-control]:is(:focus-within, :has([aria-expanded="true"])) { --field-line: var(--ring); --field-stroke: 2px }
505
+ [data-ui-floating-control]:is(:focus-within, :has([aria-expanded="true"])) > label { color: var(--primary) }
506
+ [data-ui-floating-control]:has([aria-invalid=true]) { --field-line: var(--destructive) }
507
+ [data-ui-floating-control]:has([aria-invalid=true]) > label { color: var(--destructive) }
508
+ @media (forced-colors: active) {
509
+ [data-ui-floating-control] { --field-line: ButtonText }
510
+ [data-ui-floating-control]:is(:focus-within, :has([aria-expanded="true"])) { --field-line: Highlight }
511
+ [data-ui-floating-edge] { forced-color-adjust: none }
454
512
  }
455
- [data-ui-floating-control]:focus-within > label { color: var(--primary) }
456
- [data-ui-floating-control]:has(input[aria-invalid=true]) > label { color: var(--destructive) }
457
- .dark [data-ui-auth-card] { --floating-label-surface: var(--background) }
458
513
  @media (prefers-reduced-motion: no-preference) {
459
514
  [data-ui-floating-control] > label { transition: top 140ms ease-out, font-size 140ms ease-out }
460
515
  }