@vector-business-services/cristal-ds-web 0.18.0 → 0.19.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.d.cts CHANGED
@@ -908,6 +908,14 @@ interface TableProps<T extends DataTableValue> extends PrimeTableProps<T> {
908
908
  * Padrão: true.
909
909
  */
910
910
  columnMenu?: boolean;
911
+ /**
912
+ * Cabeçalho das colunas fixo na página: enquanto a página (ou o contêiner que rola em volta)
913
+ * passa pela Table, o cabeçalho fica no topo da tela, até a última linha. Soma com o
914
+ * `scrollHeight` do Prime, que fixa o cabeçalho dentro da Table. Padrão: false.
915
+ */
916
+ stickyHeader?: boolean;
917
+ /** Distância do topo da tela em que o cabeçalho para, em px (uma barra fixa da página). Padrão: 0. */
918
+ stickyHeaderOffset?: number;
911
919
  }
912
920
  /** A ref da Table é a do DataTable do Prime: `getElement()`, `exportCSV()`, `reset()`... */
913
921
  type TableHandle<T extends DataTableValue = DataTableValue> = DataTable<T[]>;
package/dist/index.d.ts CHANGED
@@ -908,6 +908,14 @@ interface TableProps<T extends DataTableValue> extends PrimeTableProps<T> {
908
908
  * Padrão: true.
909
909
  */
910
910
  columnMenu?: boolean;
911
+ /**
912
+ * Cabeçalho das colunas fixo na página: enquanto a página (ou o contêiner que rola em volta)
913
+ * passa pela Table, o cabeçalho fica no topo da tela, até a última linha. Soma com o
914
+ * `scrollHeight` do Prime, que fixa o cabeçalho dentro da Table. Padrão: false.
915
+ */
916
+ stickyHeader?: boolean;
917
+ /** Distância do topo da tela em que o cabeçalho para, em px (uma barra fixa da página). Padrão: 0. */
918
+ stickyHeaderOffset?: number;
911
919
  }
912
920
  /** A ref da Table é a do DataTable do Prime: `getElement()`, `exportCSV()`, `reset()`... */
913
921
  type TableHandle<T extends DataTableValue = DataTableValue> = DataTable<T[]>;
package/dist/index.js CHANGED
@@ -2531,6 +2531,31 @@ var Tabs = forwardRef(function Tabs2({ activeIndex, onTabChange, children, id, c
2531
2531
  function Column(_props) {
2532
2532
  return null;
2533
2533
  }
2534
+ function useCabecalhoNaPagina(raiz, ligado, offset) {
2535
+ useEffect(() => {
2536
+ const wrapper = raiz.current?.querySelector(".cr-table__wrapper");
2537
+ if (!ligado || !wrapper) return;
2538
+ const posicionar = () => {
2539
+ const thead = wrapper.querySelector(".cr-table__thead");
2540
+ if (!thead) return;
2541
+ const limite = Math.max(0, wrapper.clientHeight - thead.offsetHeight);
2542
+ const desce = Math.min(limite, Math.max(0, offset - wrapper.getBoundingClientRect().top));
2543
+ thead.style.transform = desce ? `translateY(${desce}px)` : "";
2544
+ };
2545
+ posicionar();
2546
+ const observador = new ResizeObserver(posicionar);
2547
+ observador.observe(wrapper);
2548
+ document.addEventListener("scroll", posicionar, { capture: true, passive: true });
2549
+ window.addEventListener("resize", posicionar, { passive: true });
2550
+ return () => {
2551
+ observador.disconnect();
2552
+ document.removeEventListener("scroll", posicionar, { capture: true });
2553
+ window.removeEventListener("resize", posicionar);
2554
+ const thead = wrapper.querySelector(".cr-table__thead");
2555
+ if (thead) thead.style.transform = "";
2556
+ };
2557
+ }, [raiz, ligado, offset]);
2558
+ }
2534
2559
  var caixa = (label) => ({
2535
2560
  root: (options) => ({
2536
2561
  className: `cr-checkbox cr-checkbox__control${options?.props.checked ? " cr-checkbox__control--checked" : ""}`,
@@ -2627,12 +2652,16 @@ function TableBase({
2627
2652
  emptyMessage = "N\xE3o h\xE1 registros para mostrar.",
2628
2653
  loading,
2629
2654
  columnMenu = true,
2655
+ stickyHeader = false,
2656
+ stickyHeaderOffset = 0,
2630
2657
  ...props
2631
2658
  }, ref) {
2632
2659
  const elementos = Children.toArray(children).filter(isValidElement);
2633
2660
  const colunaDeSelecao = elementos.some((element) => element.props.selectionMode === "multiple");
2634
2661
  const template = paginatorTemplate(rowsPerPageLabel);
2635
2662
  const carregando = Boolean(loading);
2663
+ const raiz = useRef(null);
2664
+ useCabecalhoNaPagina(raiz, stickyHeader, stickyHeaderOffset);
2636
2665
  const paginaPropria = !props.onPage;
2637
2666
  const ordemPropria = !props.onSort;
2638
2667
  const [pagina, setPagina] = useState({
@@ -2740,7 +2769,7 @@ function TableBase({
2740
2769
  };
2741
2770
  return (
2742
2771
  // Contêiner da consulta de largura: a variante de 360px também muda a caixa do DataTable.
2743
- /* @__PURE__ */ jsxs("div", { className: "cr-table", children: [
2772
+ /* @__PURE__ */ jsxs("div", { ref: raiz, className: "cr-table", children: [
2744
2773
  /* @__PURE__ */ jsx(
2745
2774
  DataTable,
2746
2775
  {