@tooark/web-components 1.3.0 → 1.4.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/dist/index.cjs CHANGED
@@ -324,7 +324,8 @@ const PERSON_SVG = `
324
324
  * carregar, as iniciais de `name` (primeira letra, ou primeira mais última
325
325
  * quando há sobrenome); sem nome e sem imagem, um glifo de pessoa decorativo
326
326
  * (`aria-hidden`, a menos que o host tenha aria-label próprio). `color` troca
327
- * o tint primary por uma cor própria (texto na cor, fundo suave).
327
+ * o tint primary por uma cor própria (texto na cor, fundo suave) e
328
+ * `variant="solid"` preenche o fundo com a cor e escreve as iniciais em branco.
328
329
  */
329
330
  class ArkAvatar extends HTMLElementBase {
330
331
  constructor() {
@@ -339,7 +340,7 @@ class ArkAvatar extends HTMLElementBase {
339
340
  this.ownLabel = null;
340
341
  }
341
342
  static get observedAttributes() {
342
- return ["name", "src", "size", "shape", "color", "aria-label", "theme", "class", "testid"];
343
+ return ["name", "src", "size", "shape", "color", "variant", "aria-label", "theme", "class", "testid"];
343
344
  }
344
345
  connectedCallback() {
345
346
  upgradeProperties(this);
@@ -380,6 +381,9 @@ class ArkAvatar extends HTMLElementBase {
380
381
  getShape() {
381
382
  return (this.getAttribute("shape") || "").toLowerCase() === "square" ? "square" : "circle";
382
383
  }
384
+ getVariant() {
385
+ return (this.getAttribute("variant") || "").toLowerCase() === "solid" ? "solid" : "soft";
386
+ }
383
387
  render() {
384
388
  const initials = document.createElement("span");
385
389
  initials.setAttribute("aria-hidden", "true");
@@ -418,7 +422,7 @@ class ArkAvatar extends HTMLElementBase {
418
422
  this.imageEl.hidden = failed;
419
423
  this.imageEl.className = failed ? "" : "ark:h-full ark:w-full ark:object-cover";
420
424
  }
421
- // Cor própria: texto na cor e fundo suave por color-mix, como o badge.
425
+ // Cor própria, como o badge: suave é texto na cor e fundo por color-mix; sólido é fundo na cor e texto branco.
422
426
  applyCustomColor() {
423
427
  const color = this.getAttribute("color")?.trim();
424
428
  if (!color) {
@@ -426,8 +430,9 @@ class ArkAvatar extends HTMLElementBase {
426
430
  this.style.removeProperty("--ark-avatar-fg");
427
431
  return;
428
432
  }
429
- this.style.setProperty("--ark-avatar-bg", `color-mix(in oklab, ${color} 18%, transparent)`);
430
- this.style.setProperty("--ark-avatar-fg", color);
433
+ const solid = this.getVariant() === "solid";
434
+ this.style.setProperty("--ark-avatar-bg", solid ? color : `color-mix(in oklab, ${color} 18%, transparent)`);
435
+ this.style.setProperty("--ark-avatar-fg", solid ? "#fff" : color);
431
436
  }
432
437
  applyOwnClasses(next) {
433
438
  this.syncingClass = true;
@@ -469,7 +474,9 @@ class ArkAvatar extends HTMLElementBase {
469
474
  ].join(" ");
470
475
  const colors = this.getAttribute("color")?.trim()
471
476
  ? "ark:bg-(--ark-avatar-bg) ark:text-(--ark-avatar-fg)"
472
- : "ark:bg-primary-soft ark:text-primary-soft-fg";
477
+ : this.getVariant() === "solid"
478
+ ? "ark:bg-primary ark:text-primary-fg"
479
+ : "ark:bg-primary-soft ark:text-primary-soft-fg";
473
480
  this.applyOwnClasses([
474
481
  "ark:inline-flex ark:shrink-0 ark:items-center ark:justify-center ark:overflow-hidden ark:align-middle ark:font-semibold ark:uppercase ark:leading-none ark:select-none",
475
482
  sizing.box,
@@ -2536,8 +2543,10 @@ let nextId$1 = 0;
2536
2543
  * formulário; os dois são controles nativos, então <fieldset disabled> os
2537
2544
  * desabilita sem JS. `label` vira um <label for> próprio; sem ele o host
2538
2545
  * precisa de aria-label, ou de filhos (texto livre, links), que dão nome à
2539
- * caixa por aria-labelledby e a alternam ao clique. Os nós próprios ficam no
2540
- * início do host, marcados data-ark-chrome, antes dos filhos do usuário.
2546
+ * caixa por aria-labelledby e a alternam ao clique. `helper` acrescenta uma
2547
+ * dica abaixo do rótulo, que descreve a caixa por aria-describedby. Os nós
2548
+ * próprios ficam no início do host, marcados data-ark-chrome, antes dos filhos
2549
+ * do usuário.
2541
2550
  */
2542
2551
  class ArkCheckbox extends HTMLElementBase {
2543
2552
  static get observedAttributes() {
@@ -2548,6 +2557,7 @@ class ArkCheckbox extends HTMLElementBase {
2548
2557
  "name",
2549
2558
  "value",
2550
2559
  "label",
2560
+ "helper",
2551
2561
  "aria-label",
2552
2562
  "size",
2553
2563
  "intent",
@@ -2563,6 +2573,7 @@ class ArkCheckbox extends HTMLElementBase {
2563
2573
  this.boxEl = null;
2564
2574
  this.iconEl = null;
2565
2575
  this.labelEl = null;
2576
+ this.helperEl = null;
2566
2577
  this.inputEl = null;
2567
2578
  this.observer = null;
2568
2579
  /** Glifo em exibição; a troca depois do primeiro render entra com scale-in. */
@@ -2717,11 +2728,11 @@ class ArkCheckbox extends HTMLElementBase {
2717
2728
  getSizing() {
2718
2729
  const size = (this.getAttribute("size") || "md").toLowerCase();
2719
2730
  const sizes = {
2720
- xs: { box: "ark:h-3.5 ark:w-3.5 ark:p-px", label: "ark:text-xs" },
2721
- sm: { box: "ark:h-4 ark:w-4 ark:p-px", label: "ark:text-sm" },
2722
- md: { box: "ark:h-5 ark:w-5 ark:p-0.5", label: "ark:text-sm" },
2723
- lg: { box: "ark:h-6 ark:w-6 ark:p-0.5", label: "ark:text-base" },
2724
- xl: { box: "ark:h-7 ark:w-7 ark:p-1", label: "ark:text-lg" }
2731
+ xs: { box: "ark:h-3.5 ark:w-3.5 ark:p-px", label: "ark:text-xs", helper: "ark:text-2xs" },
2732
+ sm: { box: "ark:h-4 ark:w-4 ark:p-px", label: "ark:text-sm", helper: "ark:text-xs" },
2733
+ md: { box: "ark:h-5 ark:w-5 ark:p-0.5", label: "ark:text-sm", helper: "ark:text-xs" },
2734
+ lg: { box: "ark:h-6 ark:w-6 ark:p-0.5", label: "ark:text-base", helper: "ark:text-sm" },
2735
+ xl: { box: "ark:h-7 ark:w-7 ark:p-1", label: "ark:text-lg", helper: "ark:text-base" }
2725
2736
  };
2726
2737
  return sizes[size] ?? sizes.md;
2727
2738
  }
@@ -2765,7 +2776,32 @@ class ArkCheckbox extends HTMLElementBase {
2765
2776
  }
2766
2777
  this.labelEl.htmlFor = this.boxEl?.id ?? "";
2767
2778
  this.labelEl.textContent = text;
2768
- this.labelEl.className = ["ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
2779
+ this.labelEl.className = ["ark:col-start-2 ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
2780
+ }
2781
+ // Dica própria: um <span> depois do rótulo, só enquanto `helper` existir, que descreve a caixa por aria-describedby.
2782
+ // Com ela o host vira grid (updateAppearance): a caixa na primeira coluna, rótulo e dica empilhados na segunda.
2783
+ syncHelper(sizing) {
2784
+ if (!this.boxEl)
2785
+ return;
2786
+ const text = this.getAttribute("helper");
2787
+ if (!text) {
2788
+ this.helperEl?.remove();
2789
+ this.helperEl = null;
2790
+ this.boxEl.removeAttribute("aria-describedby");
2791
+ return;
2792
+ }
2793
+ if (!this.helperEl) {
2794
+ const helper = document.createElement("span");
2795
+ helper.setAttribute("data-ark-chrome", "helper");
2796
+ helper.id = `${this.boxEl.id}-helper`;
2797
+ (this.labelEl ?? this.inputEl)?.after(helper);
2798
+ this.helperEl = helper;
2799
+ }
2800
+ if (this.helperEl.textContent !== text)
2801
+ this.helperEl.textContent = text;
2802
+ // order: 1 põe a dica depois do rótulo livre do usuário, que vem depois dos nós próprios.
2803
+ this.helperEl.className = ["ark:col-start-2 ark:order-1 ark:text-fg-muted", sizing.helper].join(" ");
2804
+ this.boxEl.setAttribute("aria-describedby", this.helperEl.id);
2769
2805
  }
2770
2806
  // Nome acessível da caixa: o <label for> próprio; senão aria-label; senão os filhos do usuário, via
2771
2807
  // aria-labelledby no host (que ganha um id quando falta).
@@ -2793,6 +2829,16 @@ class ArkCheckbox extends HTMLElementBase {
2793
2829
  this.boxEl.removeAttribute("aria-label");
2794
2830
  this.boxEl.removeAttribute("aria-labelledby");
2795
2831
  }
2832
+ // Nomeada pelo host, a dica entraria no nome: sai da árvore e segue como descrição (aria-describedby alcança
2833
+ // nós ocultos).
2834
+ if (this.helperEl) {
2835
+ if (this.boxEl.getAttribute("aria-labelledby") === this.id) {
2836
+ this.helperEl.setAttribute("aria-hidden", "true");
2837
+ }
2838
+ else {
2839
+ this.helperEl.removeAttribute("aria-hidden");
2840
+ }
2841
+ }
2796
2842
  }
2797
2843
  syncIcon(kind) {
2798
2844
  if (!this.iconEl || kind === this.iconKind)
@@ -2828,11 +2874,20 @@ class ArkCheckbox extends HTMLElementBase {
2828
2874
  const checked = this.checked;
2829
2875
  const indeterminate = this.indeterminate;
2830
2876
  const disabled = this.disabled;
2877
+ // Com `helper` o host é grid: caixa na primeira coluna, rótulo e dica empilhados na segunda.
2878
+ const layout = this.hasAttribute("helper")
2879
+ ? "ark:inline-grid ark:grid-cols-[auto_minmax(0,1fr)] ark:gap-x-2 ark:gap-y-0.5"
2880
+ : "ark:inline-flex ark:gap-2";
2831
2881
  // O host dimeriza tudo (caixa e rótulo) quando qualquer controle interno está desabilitado, inclusive
2832
2882
  // por <fieldset disabled>.
2833
- this.applyOwnClasses("ark:inline-flex ark:cursor-pointer ark:items-center ark:gap-2 ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50".split(" "));
2883
+ this.applyOwnClasses([
2884
+ layout,
2885
+ "ark:cursor-pointer ark:items-center ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50"
2886
+ ]
2887
+ .join(" ")
2888
+ .split(" "));
2834
2889
  this.boxEl.className = [
2835
- "ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-sm ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
2890
+ "ark:col-start-1 ark:row-start-1 ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-sm ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
2836
2891
  palette.ring,
2837
2892
  sizing.box,
2838
2893
  checked || indeterminate
@@ -2843,6 +2898,7 @@ class ArkCheckbox extends HTMLElementBase {
2843
2898
  this.boxEl.disabled = disabled;
2844
2899
  this.syncIcon(indeterminate ? "mixed" : checked ? "check" : "none");
2845
2900
  this.syncLabel(sizing);
2901
+ this.syncHelper(sizing);
2846
2902
  this.syncName();
2847
2903
  this.inputEl.checked = checked;
2848
2904
  this.inputEl.indeterminate = indeterminate;
@@ -2853,6 +2909,8 @@ class ArkCheckbox extends HTMLElementBase {
2853
2909
  applyTestHooks(this, "checkbox", this.inputEl, "input");
2854
2910
  if (this.labelEl)
2855
2911
  applyTestHooks(this, "checkbox", this.labelEl, "label");
2912
+ if (this.helperEl)
2913
+ applyTestHooks(this, "checkbox", this.helperEl, "helper");
2856
2914
  }
2857
2915
  }
2858
2916
  ArkCheckbox.tagName = "ark-checkbox";
@@ -3445,7 +3503,9 @@ function normalize(text) {
3445
3503
  * e um listbox oculto que é dono das opções visíveis por `aria-owns`. Itens
3446
3504
  * e cabeçalhos se ordenam por `order` no CSS, então nada é inserido entre os
3447
3505
  * filhos. Com `filter` o texto filtra localmente pelo `label` dos itens; em
3448
- * qualquer caso `ark-query` sai com debounce para busca assíncrona. O foco
3506
+ * qualquer caso `ark-query` sai com debounce para busca assíncrona. Sem opções
3507
+ * visíveis a mensagem é `noResults`; `hint` a troca enquanto o campo está
3508
+ * vazio e `busy` (busca em andamento) a troca por `searching`. O foco
3449
3509
  * fica sempre no campo; setas movem a opção ativa (`aria-activedescendant`),
3450
3510
  * Enter seleciona, Esc fecha; `hotkey` abre de qualquer lugar da página. A
3451
3511
  * página para de rolar enquanto aberta, salvo com `no-scroll-lock`.
@@ -3459,6 +3519,8 @@ class ArkCommandPalette extends HTMLElementBase {
3459
3519
  "filter",
3460
3520
  "query-delay",
3461
3521
  "label",
3522
+ "hint",
3523
+ "busy",
3462
3524
  "theme",
3463
3525
  "lang",
3464
3526
  "locale-json",
@@ -3660,6 +3722,13 @@ class ArkCommandPalette extends HTMLElementBase {
3660
3722
  set noScrollLock(value) {
3661
3723
  this.toggleAttribute("no-scroll-lock", core.coerceBooleanAttr(value));
3662
3724
  }
3725
+ /** Busca assíncrona em andamento (atributo `busy`): o listbox fica `aria-busy` e, sem opções, aparece `searching`. */
3726
+ get busy() {
3727
+ return this.hasAttribute("busy");
3728
+ }
3729
+ set busy(value) {
3730
+ this.toggleAttribute("busy", core.coerceBooleanAttr(value));
3731
+ }
3663
3732
  /** Texto atual do campo de busca. */
3664
3733
  get query() {
3665
3734
  return this.inputEl?.value ?? "";
@@ -3743,15 +3812,31 @@ class ArkCommandPalette extends HTMLElementBase {
3743
3812
  applyTestHooks(this, "command-palette", header, "group");
3744
3813
  });
3745
3814
  this.listEl.setAttribute("aria-owns", visible.map((item) => item.id).join(" "));
3746
- this.emptyEl.hidden = visible.length > 0;
3747
- const noResults = this.getLocale().noResults;
3748
- if (this.emptyEl.textContent !== noResults)
3749
- this.emptyEl.textContent = noResults;
3815
+ this.syncEmpty(visible.length);
3750
3816
  const enabled = visible.filter((item) => !item.disabled);
3751
3817
  if (!enabled.some((item) => item.id === this.activeId))
3752
3818
  this.activeId = enabled[0]?.id ?? null;
3753
3819
  this.applyActive(items);
3754
3820
  }
3821
+ // Mensagem sem opções visíveis: `searching` com `busy`, o `hint` do app com o campo vazio, senão `noResults`.
3822
+ syncEmpty(visible) {
3823
+ if (!this.listEl || !this.emptyEl)
3824
+ return;
3825
+ const locale = this.getLocale();
3826
+ const busy = this.busy;
3827
+ const hint = this.getAttribute("hint");
3828
+ const text = busy ? locale.searching : hint && this.query.trim() === "" ? hint : locale.noResults;
3829
+ this.emptyEl.hidden = visible > 0;
3830
+ // Só escreve o que mudou: o observer (subtree) veria a troca do nó de texto e sincronizaria em laço.
3831
+ if (this.emptyEl.textContent !== text)
3832
+ this.emptyEl.textContent = text;
3833
+ if (busy) {
3834
+ this.listEl.setAttribute("aria-busy", "true");
3835
+ }
3836
+ else {
3837
+ this.listEl.removeAttribute("aria-busy");
3838
+ }
3839
+ }
3755
3840
  applyActive(items) {
3756
3841
  for (const item of items) {
3757
3842
  const active = item.id === this.activeId;
@@ -3912,8 +3997,7 @@ class ArkCommandPalette extends HTMLElementBase {
3912
3997
  this.inputEl.removeAttribute(attr);
3913
3998
  }
3914
3999
  }
3915
- if (this.emptyEl.textContent !== locale.noResults)
3916
- this.emptyEl.textContent = locale.noResults;
4000
+ this.syncEmpty(this.visibleItems().length);
3917
4001
  applyTestHooks(this, "command-palette", this);
3918
4002
  applyTestHooks(this, "command-palette", this.inputEl, "input");
3919
4003
  applyTestHooks(this, "command-palette", this.listEl, "list");
@@ -5147,11 +5231,12 @@ function cssLength$1(value) {
5147
5231
  * página e só anima (o console inferior, um painel lateral fixo). Os filhos
5148
5232
  * do usuário são o corpo e ficam onde estão; um filho `slot="footer"` vai ao
5149
5233
  * fim por CSS. O cabeçalho (título `h2` de `label` e botão de fechar) é o
5150
- * primeiro filho, marcado `data-ark-chrome`. `side` escolhe a borda, a
5151
- * direção do slide (com o easing `sheet`) e a borda desenhada; `size` é um
5152
- * preset ou um comprimento CSS no eixo da gaveta. `open` é a fonte da
5153
- * verdade, como no ark-dialog, e em overlay a página para de rolar enquanto
5154
- * aberta, salvo com `no-scroll-lock`.
5234
+ * primeiro filho, marcado `data-ark-chrome`; um container `slot="actions"`
5235
+ * entra na linha dele por CSS, entre o título e o fechar. `side` escolhe a
5236
+ * borda, a direção do slide (com o easing `sheet`) e a borda desenhada;
5237
+ * `size` é um preset ou um comprimento CSS no eixo da gaveta. `open` é a fonte
5238
+ * da verdade, como no ark-dialog, e em overlay a página para de rolar
5239
+ * enquanto aberta, salvo com `no-scroll-lock`.
5155
5240
  */
5156
5241
  class ArkDrawer extends HTMLElementBase {
5157
5242
  static get observedAttributes() {
@@ -5176,6 +5261,10 @@ class ArkDrawer extends HTMLElementBase {
5176
5261
  this.titleEl = null;
5177
5262
  this.closeEl = null;
5178
5263
  this.observer = null;
5264
+ /** Mede o filho `slot="actions"`: a largura dele é o espaço que o título deixa livre na linha do cabeçalho. */
5265
+ this.actionsObserver = null;
5266
+ /** O filho `slot="actions"` que o actionsObserver mede. */
5267
+ this.observedActions = null;
5179
5268
  this.ownClasses = [];
5180
5269
  this.syncingClass = false;
5181
5270
  this.state = "closed";
@@ -5200,7 +5289,8 @@ class ArkDrawer extends HTMLElementBase {
5200
5289
  connectedCallback() {
5201
5290
  upgradeProperties(this);
5202
5291
  if (!this.observer) {
5203
- this.observer = new MutationObserver(() => this.syncFooter());
5292
+ // Rodapé e ações que chegam depois (frameworks) ganham o hook; as ações também mudam o cabeçalho.
5293
+ this.observer = new MutationObserver(() => this.updateAppearance());
5204
5294
  this.observer.observe(this, { childList: true });
5205
5295
  }
5206
5296
  this.updateAppearance();
@@ -5213,6 +5303,9 @@ class ArkDrawer extends HTMLElementBase {
5213
5303
  disconnectedCallback() {
5214
5304
  this.observer?.disconnect();
5215
5305
  this.observer = null;
5306
+ this.actionsObserver?.disconnect();
5307
+ this.actionsObserver = null;
5308
+ this.observedActions = null;
5216
5309
  this.releaseTrap?.();
5217
5310
  this.releaseTrap = null;
5218
5311
  core.unlockScroll(this);
@@ -5424,8 +5517,8 @@ class ArkDrawer extends HTMLElementBase {
5424
5517
  .split(/\s+/)
5425
5518
  .filter(Boolean);
5426
5519
  }
5427
- syncHeader(label, showClose) {
5428
- if (!label && !showClose) {
5520
+ syncHeader(label, showClose, withActions) {
5521
+ if (!label && !showClose && !withActions) {
5429
5522
  this.headerEl?.remove();
5430
5523
  this.headerEl = null;
5431
5524
  this.titleEl = null;
@@ -5438,8 +5531,14 @@ class ArkDrawer extends HTMLElementBase {
5438
5531
  this.prepend(header);
5439
5532
  this.headerEl = header;
5440
5533
  }
5441
- this.headerEl.className =
5442
- "ark:sticky ark:top-0 ark:z-10 ark:-mx-6 ark:flex ark:items-start ark:gap-4 ark:bg-surface ark:px-6 ark:pt-6 ark:pb-4";
5534
+ // As ações vêm antes do cabeçalho (order) e ocupam 3rem até o fim da linha do título: ele sobe por cima desse
5535
+ // espaço e guarda ao menos a altura dessa linha.
5536
+ this.headerEl.className = [
5537
+ "ark:sticky ark:top-0 ark:z-10 ark:-mx-6 ark:flex ark:items-start ark:gap-4 ark:bg-surface ark:px-6 ark:pt-6 ark:pb-4",
5538
+ withActions ? "ark:-mt-12 ark:min-h-16" : ""
5539
+ ]
5540
+ .join(" ")
5541
+ .trim();
5443
5542
  if (label) {
5444
5543
  if (!this.titleEl) {
5445
5544
  const title = document.createElement("h2");
@@ -5448,7 +5547,13 @@ class ArkDrawer extends HTMLElementBase {
5448
5547
  this.titleEl = title;
5449
5548
  }
5450
5549
  this.titleEl.textContent = label;
5451
- this.titleEl.className = "ark:min-w-0 ark:flex-1 ark:text-base ark:leading-6 ark:font-semibold ark:text-fg";
5550
+ // Com ações, o título deixa livre a largura medida delas mais o espaço entre as duas.
5551
+ this.titleEl.className = [
5552
+ "ark:min-w-0 ark:flex-1 ark:text-base ark:leading-6 ark:font-semibold ark:text-fg",
5553
+ withActions ? "ark:me-[calc(var(--ark-drawer-actions-width,0px)+1rem)]" : ""
5554
+ ]
5555
+ .join(" ")
5556
+ .trim();
5452
5557
  }
5453
5558
  else {
5454
5559
  this.titleEl?.remove();
@@ -5479,6 +5584,28 @@ class ArkDrawer extends HTMLElementBase {
5479
5584
  if (footer)
5480
5585
  applyTestHooks(this, "drawer", footer, "footer");
5481
5586
  }
5587
+ // Passa a medir o filho `slot="actions"` atual (ou nenhum). Sem ResizeObserver (SSR, jsdom) o título não reserva
5588
+ // a largura delas, só o espaço entre os dois.
5589
+ syncActions(actions) {
5590
+ if (actions)
5591
+ applyTestHooks(this, "drawer", actions, "actions");
5592
+ if (actions === this.observedActions)
5593
+ return;
5594
+ this.actionsObserver?.disconnect();
5595
+ this.observedActions = actions;
5596
+ if (!actions) {
5597
+ this.style.removeProperty("--ark-drawer-actions-width");
5598
+ return;
5599
+ }
5600
+ if (typeof ResizeObserver === "undefined")
5601
+ return;
5602
+ if (!this.actionsObserver) {
5603
+ this.actionsObserver = new ResizeObserver(() => {
5604
+ this.style.setProperty("--ark-drawer-actions-width", `${this.observedActions?.offsetWidth ?? 0}px`);
5605
+ });
5606
+ }
5607
+ this.actionsObserver.observe(actions);
5608
+ }
5482
5609
  applyOwnClasses(next) {
5483
5610
  this.syncingClass = true;
5484
5611
  for (const cls of this.ownClasses) {
@@ -5515,7 +5642,9 @@ class ArkDrawer extends HTMLElementBase {
5515
5642
  this.setAttribute("tabindex", "-1");
5516
5643
  this.setAttribute("data-ark-side", this.side);
5517
5644
  this.setAttribute("data-ark-mode", this.mode);
5518
- this.syncHeader(label, !this.hasAttribute("no-close-button"));
5645
+ const actions = this.querySelector(':scope > [slot="actions"]');
5646
+ this.syncHeader(label, !this.hasAttribute("no-close-button"), actions !== null);
5647
+ this.syncActions(actions);
5519
5648
  // Nome acessível: o título; sem ele um aria-label do usuário fica.
5520
5649
  if (label && this.titleEl) {
5521
5650
  this.setAttribute("aria-labelledby", this.titleId);
@@ -8208,7 +8337,7 @@ let nextId = 0;
8208
8337
  * silêncio e `change` dispara só no que ganhou a marca; as setas movem o foco
8209
8338
  * e marcam, Espaço marca o focado, e um único deles fica na ordem de Tab (o
8210
8339
  * marcado, ou o primeiro habilitado). `label`, aria-label e filhos nomeiam a
8211
- * opção como no ark-checkbox.
8340
+ * opção e `helper` a descreve, como no ark-checkbox.
8212
8341
  */
8213
8342
  class ArkRadio extends HTMLElementBase {
8214
8343
  static get observedAttributes() {
@@ -8218,6 +8347,7 @@ class ArkRadio extends HTMLElementBase {
8218
8347
  "name",
8219
8348
  "value",
8220
8349
  "label",
8350
+ "helper",
8221
8351
  "aria-label",
8222
8352
  "size",
8223
8353
  "intent",
@@ -8233,6 +8363,7 @@ class ArkRadio extends HTMLElementBase {
8233
8363
  this.boxEl = null;
8234
8364
  this.dotEl = null;
8235
8365
  this.labelEl = null;
8366
+ this.helperEl = null;
8236
8367
  this.inputEl = null;
8237
8368
  this.observer = null;
8238
8369
  /** Raiz do grupo no último connect, para ressincronizar os que ficam quando este sai. */
@@ -8453,11 +8584,11 @@ class ArkRadio extends HTMLElementBase {
8453
8584
  getSizing() {
8454
8585
  const size = (this.getAttribute("size") || "md").toLowerCase();
8455
8586
  const sizes = {
8456
- xs: { box: "ark:h-3.5 ark:w-3.5", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-xs" },
8457
- sm: { box: "ark:h-4 ark:w-4", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-sm" },
8458
- md: { box: "ark:h-5 ark:w-5", dot: "ark:h-2 ark:w-2", label: "ark:text-sm" },
8459
- lg: { box: "ark:h-6 ark:w-6", dot: "ark:h-2.5 ark:w-2.5", label: "ark:text-base" },
8460
- xl: { box: "ark:h-7 ark:w-7", dot: "ark:h-3 ark:w-3", label: "ark:text-lg" }
8587
+ xs: { box: "ark:h-3.5 ark:w-3.5", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-xs", helper: "ark:text-2xs" },
8588
+ sm: { box: "ark:h-4 ark:w-4", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-sm", helper: "ark:text-xs" },
8589
+ md: { box: "ark:h-5 ark:w-5", dot: "ark:h-2 ark:w-2", label: "ark:text-sm", helper: "ark:text-xs" },
8590
+ lg: { box: "ark:h-6 ark:w-6", dot: "ark:h-2.5 ark:w-2.5", label: "ark:text-base", helper: "ark:text-sm" },
8591
+ xl: { box: "ark:h-7 ark:w-7", dot: "ark:h-3 ark:w-3", label: "ark:text-lg", helper: "ark:text-base" }
8461
8592
  };
8462
8593
  return sizes[size] ?? sizes.md;
8463
8594
  }
@@ -8499,7 +8630,32 @@ class ArkRadio extends HTMLElementBase {
8499
8630
  }
8500
8631
  this.labelEl.htmlFor = this.boxEl?.id ?? "";
8501
8632
  this.labelEl.textContent = text;
8502
- this.labelEl.className = ["ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
8633
+ this.labelEl.className = ["ark:col-start-2 ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
8634
+ }
8635
+ // Dica própria: um <span> depois do rótulo, só enquanto `helper` existir, que descreve a opção por aria-describedby.
8636
+ // Com ela o host vira grid (updateAppearance): a opção na primeira coluna, rótulo e dica empilhados na segunda.
8637
+ syncHelper(sizing) {
8638
+ if (!this.boxEl)
8639
+ return;
8640
+ const text = this.getAttribute("helper");
8641
+ if (!text) {
8642
+ this.helperEl?.remove();
8643
+ this.helperEl = null;
8644
+ this.boxEl.removeAttribute("aria-describedby");
8645
+ return;
8646
+ }
8647
+ if (!this.helperEl) {
8648
+ const helper = document.createElement("span");
8649
+ helper.setAttribute("data-ark-chrome", "helper");
8650
+ helper.id = `${this.boxEl.id}-helper`;
8651
+ (this.labelEl ?? this.inputEl)?.after(helper);
8652
+ this.helperEl = helper;
8653
+ }
8654
+ if (this.helperEl.textContent !== text)
8655
+ this.helperEl.textContent = text;
8656
+ // order: 1 põe a dica depois do rótulo livre do usuário, que vem depois dos nós próprios.
8657
+ this.helperEl.className = ["ark:col-start-2 ark:order-1 ark:text-fg-muted", sizing.helper].join(" ");
8658
+ this.boxEl.setAttribute("aria-describedby", this.helperEl.id);
8503
8659
  }
8504
8660
  syncName() {
8505
8661
  if (!this.boxEl)
@@ -8525,6 +8681,16 @@ class ArkRadio extends HTMLElementBase {
8525
8681
  this.boxEl.removeAttribute("aria-label");
8526
8682
  this.boxEl.removeAttribute("aria-labelledby");
8527
8683
  }
8684
+ // Nomeada pelo host, a dica entraria no nome: sai da árvore e segue como descrição (aria-describedby alcança
8685
+ // nós ocultos).
8686
+ if (this.helperEl) {
8687
+ if (this.boxEl.getAttribute("aria-labelledby") === this.id) {
8688
+ this.helperEl.setAttribute("aria-hidden", "true");
8689
+ }
8690
+ else {
8691
+ this.helperEl.removeAttribute("aria-hidden");
8692
+ }
8693
+ }
8528
8694
  }
8529
8695
  syncDot(checked, sizing) {
8530
8696
  if (!this.dotEl)
@@ -8560,9 +8726,18 @@ class ArkRadio extends HTMLElementBase {
8560
8726
  const sizing = this.getSizing();
8561
8727
  const checked = this.checked;
8562
8728
  const disabled = this.disabled;
8563
- this.applyOwnClasses("ark:inline-flex ark:cursor-pointer ark:items-center ark:gap-2 ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50".split(" "));
8729
+ // Com `helper` o host é grid: caixa na primeira coluna, rótulo e dica empilhados na segunda.
8730
+ const layout = this.hasAttribute("helper")
8731
+ ? "ark:inline-grid ark:grid-cols-[auto_minmax(0,1fr)] ark:gap-x-2 ark:gap-y-0.5"
8732
+ : "ark:inline-flex ark:gap-2";
8733
+ this.applyOwnClasses([
8734
+ layout,
8735
+ "ark:cursor-pointer ark:items-center ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50"
8736
+ ]
8737
+ .join(" ")
8738
+ .split(" "));
8564
8739
  this.boxEl.className = [
8565
- "ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-full ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
8740
+ "ark:col-start-1 ark:row-start-1 ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-full ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
8566
8741
  palette.ring,
8567
8742
  sizing.box,
8568
8743
  checked ? palette.on : "ark:border-border-strong ark:bg-surface ark:text-transparent ark:hover:bg-surface-muted"
@@ -8571,6 +8746,7 @@ class ArkRadio extends HTMLElementBase {
8571
8746
  this.boxEl.disabled = disabled;
8572
8747
  this.syncDot(checked, sizing);
8573
8748
  this.syncLabel(sizing);
8749
+ this.syncHelper(sizing);
8574
8750
  this.syncName();
8575
8751
  this.inputEl.checked = checked;
8576
8752
  this.inputEl.disabled = disabled;
@@ -8581,6 +8757,8 @@ class ArkRadio extends HTMLElementBase {
8581
8757
  applyTestHooks(this, "radio", this.inputEl, "input");
8582
8758
  if (this.labelEl)
8583
8759
  applyTestHooks(this, "radio", this.labelEl, "label");
8760
+ if (this.helperEl)
8761
+ applyTestHooks(this, "radio", this.helperEl, "helper");
8584
8762
  }
8585
8763
  }
8586
8764
  ArkRadio.tagName = "ark-radio";