qlik-oss/sn-table

View on GitHub
src/table/pagination-table/components/body/withColumnStyling.tsx

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import React, { useMemo } from "react";
import { CellHOC, CellHOCProps } from "../../../types";
import { getColumnStyle } from "../../../utils/styling-utils";

export default function withColumnStyling(CellComponent: CellHOC) {
  const HOC = (props: CellHOCProps) => {
    const { cell, column, styling } = props;

    const columnStyling = useMemo(
      () => getColumnStyle(styling, cell.qAttrExps, column.stylingIDs),
      [styling, cell.qAttrExps, column.stylingIDs],
    );

    return <CellComponent {...props} styling={columnStyling} />;
  };

  return HOC;
}