ae9e4d7b5decb4e716c82db75621a5861556c50c1d3bf56223befb423ce59001a5a04f4eec19924b8b8916aa327ca406d402c1f58e202dd306a2c01127433c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { computed, unref } from 'vue';
  2. import { sum, enforceUnit } from '../utils.mjs';
  3. import { isNumber } from '../../../../utils/types.mjs';
  4. import { addUnit } from '../../../../utils/dom/style.mjs';
  5. const useStyles = (props, {
  6. columnsTotalWidth,
  7. rowsHeight,
  8. fixedColumnsOnLeft,
  9. fixedColumnsOnRight
  10. }) => {
  11. const bodyWidth = computed(() => {
  12. const { fixed, width, vScrollbarSize } = props;
  13. const ret = width - vScrollbarSize;
  14. return fixed ? Math.max(Math.round(unref(columnsTotalWidth)), ret) : ret;
  15. });
  16. const mainTableHeight = computed(() => {
  17. const { height = 0, maxHeight = 0, footerHeight: footerHeight2, hScrollbarSize } = props;
  18. if (maxHeight > 0) {
  19. const _fixedRowsHeight = unref(fixedRowsHeight);
  20. const _rowsHeight = unref(rowsHeight);
  21. const _headerHeight = unref(headerHeight);
  22. const total = _headerHeight + _fixedRowsHeight + _rowsHeight + hScrollbarSize;
  23. return Math.min(total, maxHeight - footerHeight2);
  24. }
  25. return height - footerHeight2;
  26. });
  27. const fixedTableHeight = computed(() => {
  28. const { maxHeight } = props;
  29. const tableHeight = unref(mainTableHeight);
  30. if (isNumber(maxHeight) && maxHeight > 0)
  31. return tableHeight;
  32. const totalHeight = unref(rowsHeight) + unref(headerHeight) + unref(fixedRowsHeight);
  33. return Math.min(tableHeight, totalHeight);
  34. });
  35. const mapColumn = (column) => column.width;
  36. const leftTableWidth = computed(() => sum(unref(fixedColumnsOnLeft).map(mapColumn)));
  37. const rightTableWidth = computed(() => sum(unref(fixedColumnsOnRight).map(mapColumn)));
  38. const headerHeight = computed(() => sum(props.headerHeight));
  39. const fixedRowsHeight = computed(() => {
  40. var _a;
  41. return (((_a = props.fixedData) == null ? void 0 : _a.length) || 0) * props.rowHeight;
  42. });
  43. const windowHeight = computed(() => {
  44. return unref(mainTableHeight) - unref(headerHeight) - unref(fixedRowsHeight);
  45. });
  46. const rootStyle = computed(() => {
  47. const { style = {}, height, width } = props;
  48. return enforceUnit({
  49. ...style,
  50. height,
  51. width
  52. });
  53. });
  54. const footerHeight = computed(() => enforceUnit({ height: props.footerHeight }));
  55. const emptyStyle = computed(() => ({
  56. top: addUnit(unref(headerHeight)),
  57. bottom: addUnit(props.footerHeight),
  58. width: addUnit(props.width)
  59. }));
  60. return {
  61. bodyWidth,
  62. fixedTableHeight,
  63. mainTableHeight,
  64. leftTableWidth,
  65. rightTableWidth,
  66. windowHeight,
  67. footerHeight,
  68. emptyStyle,
  69. rootStyle,
  70. headerHeight
  71. };
  72. };
  73. export { useStyles };
  74. //# sourceMappingURL=use-styles.mjs.map