@vector-business-services/cristal-ds-web 0.13.0 → 0.13.1

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
@@ -88,6 +88,23 @@ var Accordion = react.forwardRef(function Accordion2({ multiple = false, activeI
88
88
  }
89
89
  );
90
90
  });
91
+
92
+ // src/components/popup.ts
93
+ function seguirLado(painel, alvo) {
94
+ if (!(painel instanceof HTMLElement) || !alvo) return;
95
+ const marcar = () => {
96
+ const acima = painel.getBoundingClientRect().top < alvo.getBoundingClientRect().top;
97
+ if (acima) painel.setAttribute("data-cr-lado", "acima");
98
+ else painel.removeAttribute("data-cr-lado");
99
+ };
100
+ marcar();
101
+ new MutationObserver(marcar).observe(painel, { attributes: true, attributeFilter: ["style"] });
102
+ }
103
+ var painelDoCampo = (campo, seletorDoPainel) => {
104
+ const lista = campo?.getAttribute("aria-controls");
105
+ return lista ? document.getElementById(lista)?.closest(seletorDoPainel) : null;
106
+ };
107
+ var aoPosicionar = (onEnter) => ({ onEnter });
91
108
  var AutoComplete = react.forwardRef(function AutoComplete2({
92
109
  variant = "outline",
93
110
  size = "large",
@@ -140,6 +157,11 @@ var AutoComplete = react.forwardRef(function AutoComplete2({
140
157
  // O Prime mostra um spinner próprio enquanto busca; o Figma não define esse estado.
141
158
  loadingIcon: { className: "cr-autocomplete__loader" },
142
159
  panel: { className: "cr-autocomplete__panel" },
160
+ // Lado da lista (acima ou abaixo do campo), medido logo depois de o Prime posicionar.
161
+ transition: aoPosicionar(() => {
162
+ const campo = document.getElementById(id);
163
+ seguirLado(painelDoCampo(campo, ".cr-autocomplete__panel"), campo);
164
+ }),
143
165
  list: { className: "cr-autocomplete__list" },
144
166
  item: { className: "cr-autocomplete__item" }
145
167
  },
@@ -239,8 +261,17 @@ function Tooltip({
239
261
  react.useEffect(() => {
240
262
  if (!describe) return;
241
263
  const elements = resolveTargets(target);
242
- elements.forEach((element) => element.setAttribute("aria-describedby", tooltipId));
243
- return () => elements.forEach((element) => element.removeAttribute("aria-describedby"));
264
+ const ids = (element) => (element.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean);
265
+ const gravar = (element, lista) => lista.length ? element.setAttribute("aria-describedby", lista.join(" ")) : element.removeAttribute("aria-describedby");
266
+ elements.forEach((element) => {
267
+ if (!ids(element).includes(tooltipId)) gravar(element, [...ids(element), tooltipId]);
268
+ });
269
+ return () => elements.forEach(
270
+ (element) => gravar(
271
+ element,
272
+ ids(element).filter((idAtual) => idAtual !== tooltipId)
273
+ )
274
+ );
244
275
  }, [target, tooltipId, describe]);
245
276
  const classes = ["cr-tooltip", `cr-tooltip--${type}`, className].filter(Boolean).join(" ");
246
277
  const pt = {
@@ -262,6 +293,7 @@ function Tooltip({
262
293
  showDelay,
263
294
  hideDelay,
264
295
  disabled,
296
+ closeOnEscape: true,
265
297
  onBeforeShow: (e) => e.originalEvent?.type !== "focus" || usandoTeclado,
266
298
  pt,
267
299
  children: content
@@ -577,7 +609,10 @@ var Checkbox = react.forwardRef(function Checkbox2({
577
609
  value,
578
610
  icon: /* @__PURE__ */ jsxRuntime.jsx(react$1.Check, { size: 16 }),
579
611
  pt: {
580
- root: { className: "cr-checkbox__control" },
612
+ // Marcado pela prop do Cristal, não pelo atributo interno do Prime (data-p-highlight).
613
+ root: {
614
+ className: `cr-checkbox__control${checked ? " cr-checkbox__control--checked" : ""}`
615
+ },
581
616
  input: { className: "cr-checkbox__input" },
582
617
  box: { className: "cr-checkbox__box" },
583
618
  icon: { className: "cr-checkbox__icon", "aria-hidden": true }
@@ -936,10 +971,17 @@ var Menu = react.forwardRef(function Menu2({
936
971
  className
937
972
  }, ref) {
938
973
  const primeRef = react.useRef(null);
974
+ const alvo = react.useRef(null);
939
975
  const context = react.useContext(api.PrimeReactContext);
940
976
  react.useImperativeHandle(ref, () => ({
941
- toggle: (event) => primeRef.current?.toggle(event),
942
- show: (event) => primeRef.current?.show(event),
977
+ toggle: (event) => {
978
+ alvo.current = event.currentTarget;
979
+ primeRef.current?.toggle(event);
980
+ },
981
+ show: (event) => {
982
+ alvo.current = event.currentTarget;
983
+ primeRef.current?.show(event);
984
+ },
943
985
  hide: (event) => primeRef.current?.hide(event),
944
986
  getElement: () => primeRef.current?.getElement() ?? null
945
987
  }));
@@ -977,6 +1019,12 @@ var Menu = react.forwardRef(function Menu2({
977
1019
  };
978
1020
  },
979
1021
  content: { className: "cr-menu__content" },
1022
+ // Lado do popup (acima ou abaixo de quem o abriu), medido logo depois de o Prime posicionar.
1023
+ // Numa microtarefa: no onEnter o Prime ainda está religando a ref (getElement vem vazio); ela
1024
+ // roda logo depois, antes de a tela ser pintada.
1025
+ transition: aoPosicionar(
1026
+ () => queueMicrotask(() => seguirLado(primeRef.current?.getElement(), alvo.current))
1027
+ ),
980
1028
  action: { className: "cr-menu__action" },
981
1029
  label: { className: "cr-menu__label" }
982
1030
  };
@@ -1234,9 +1282,12 @@ var MenuPrincipal = react.forwardRef(
1234
1282
  const primeRef = react.useRef(null);
1235
1283
  const context = react.useContext(api.PrimeReactContext);
1236
1284
  const [baseDoAlvo, setBaseDoAlvo] = react.useState();
1285
+ const alvo = react.useRef(null);
1237
1286
  const medirAlvo = (event) => {
1238
- const alvo = event.currentTarget;
1239
- if (alvo instanceof Element) setBaseDoAlvo(alvo.getBoundingClientRect().bottom);
1287
+ const elemento = event.currentTarget;
1288
+ if (!(elemento instanceof Element)) return;
1289
+ alvo.current = elemento;
1290
+ setBaseDoAlvo(elemento.getBoundingClientRect().bottom);
1240
1291
  };
1241
1292
  react.useImperativeHandle(ref, () => ({
1242
1293
  toggle: (event) => {
@@ -1295,7 +1346,12 @@ var MenuPrincipal = react.forwardRef(
1295
1346
  menu: { className: "cr-menu-principal__list", "aria-label": ariaLabel },
1296
1347
  submenuHeader: { className: "cr-menu-principal__group" },
1297
1348
  separator: { className: "cr-menu-principal__separator" },
1298
- menuitem: { className: "cr-menu-principal__item" }
1349
+ menuitem: { className: "cr-menu-principal__item" },
1350
+ // Lado do popup, medido logo depois de o Prime posicionar.
1351
+ // Numa microtarefa: no onEnter o Prime ainda está religando a ref (como no Menu).
1352
+ transition: aoPosicionar(
1353
+ () => queueMicrotask(() => seguirLado(primeRef.current?.getElement(), alvo.current))
1354
+ )
1299
1355
  };
1300
1356
  const menu$1 = /* @__PURE__ */ jsxRuntime.jsx(
1301
1357
  menu.Menu,
@@ -1782,9 +1838,23 @@ var Select = react.forwardRef(function Select2({
1782
1838
  input: { className: "cr-select__value" },
1783
1839
  trigger: { className: "cr-field__icon cr-select__trigger", "aria-hidden": true },
1784
1840
  panel: { className: "cr-select__panel" },
1841
+ // Lado da lista (acima ou abaixo do campo), medido logo depois de o Prime posicionar.
1842
+ transition: aoPosicionar(
1843
+ () => seguirLado(
1844
+ document.getElementById(listId)?.closest(".cr-select__panel"),
1845
+ document.getElementById(inputId)?.closest(".cr-select__control")
1846
+ )
1847
+ ),
1785
1848
  wrapper: { className: "cr-select__wrapper" },
1786
1849
  list: { className: "cr-select__list", id: listId },
1787
- item: { className: "cr-select__item" },
1850
+ // Selecionado e em foco (teclado) pelo contexto do pt, a API pública do Prime (não data-p-*).
1851
+ item: ({ context }) => ({
1852
+ className: [
1853
+ "cr-select__item",
1854
+ context.selected && "cr-select__item--selected",
1855
+ context.focused && "cr-select__item--focused"
1856
+ ].filter(Boolean).join(" ")
1857
+ }),
1788
1858
  emptyMessage: { className: "cr-select__item cr-select__empty" }
1789
1859
  };
1790
1860
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes, children: [
@@ -1972,7 +2042,8 @@ var Radio = react.forwardRef(function Radio2({
1972
2042
  disabled,
1973
2043
  required,
1974
2044
  pt: {
1975
- root: { className: "cr-radio__control" },
2045
+ // Marcado pela prop do Cristal, não pelo atributo interno do Prime (data-p-checked).
2046
+ root: { className: `cr-radio__control${checked ? " cr-radio__control--checked" : ""}` },
1976
2047
  input: { className: "cr-radio__input" },
1977
2048
  box: { className: "cr-radio__box" },
1978
2049
  icon: { className: "cr-radio__icon" }
@@ -2112,7 +2183,12 @@ var Switch = react.forwardRef(function Switch2({
2112
2183
  disabled,
2113
2184
  name,
2114
2185
  pt: {
2115
- root: { className: "cr-switch__control", role: void 0, "aria-checked": void 0 },
2186
+ // Ligado pela prop do Cristal, não pelo atributo interno do Prime (data-p-highlight).
2187
+ root: {
2188
+ className: `cr-switch__control${checked ? " cr-switch__control--checked" : ""}`,
2189
+ role: void 0,
2190
+ "aria-checked": void 0
2191
+ },
2116
2192
  input: { className: "cr-switch__input" },
2117
2193
  slider: { className: "cr-switch__track" }
2118
2194
  }