2a3b9e1e315217069bc54636795701319f22dca40fa17eb4210e77640423cf543f32f64e022de4ad9677ea32d438e4a12d029ab7c86981e234ea184db07090 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var util = require('../util.js');
  5. var tokens = require('../tokens.js');
  6. var index = require('../../../../hooks/use-namespace/index.js');
  7. var shared = require('@vue/shared');
  8. function useStyles(props) {
  9. const parent = vue.inject(tokens.TABLE_INJECTION_KEY);
  10. const ns = index.useNamespace("table");
  11. const getRowStyle = (row, rowIndex) => {
  12. const rowStyle = parent == null ? void 0 : parent.props.rowStyle;
  13. if (shared.isFunction(rowStyle)) {
  14. return rowStyle.call(null, {
  15. row,
  16. rowIndex
  17. });
  18. }
  19. return rowStyle || null;
  20. };
  21. const getRowClass = (row, rowIndex, displayIndex) => {
  22. var _a;
  23. const classes = [ns.e("row")];
  24. if ((parent == null ? void 0 : parent.props.highlightCurrentRow) && row === ((_a = props.store) == null ? void 0 : _a.states.currentRow.value)) {
  25. classes.push("current-row");
  26. }
  27. if (props.stripe && displayIndex % 2 === 1) {
  28. classes.push(ns.em("row", "striped"));
  29. }
  30. const rowClassName = parent == null ? void 0 : parent.props.rowClassName;
  31. if (shared.isString(rowClassName)) {
  32. classes.push(rowClassName);
  33. } else if (shared.isFunction(rowClassName)) {
  34. classes.push(rowClassName.call(null, {
  35. row,
  36. rowIndex
  37. }));
  38. }
  39. return classes;
  40. };
  41. const getCellStyle = (rowIndex, columnIndex, row, column) => {
  42. const cellStyle = parent == null ? void 0 : parent.props.cellStyle;
  43. let cellStyles = cellStyle != null ? cellStyle : {};
  44. if (shared.isFunction(cellStyle)) {
  45. cellStyles = cellStyle.call(null, {
  46. rowIndex,
  47. columnIndex,
  48. row,
  49. column
  50. });
  51. }
  52. const fixedStyle = util.getFixedColumnOffset(columnIndex, props == null ? void 0 : props.fixed, props.store);
  53. util.ensurePosition(fixedStyle, "left");
  54. util.ensurePosition(fixedStyle, "right");
  55. return Object.assign({}, cellStyles, fixedStyle);
  56. };
  57. const getCellClass = (rowIndex, columnIndex, row, column, offset) => {
  58. const fixedClasses = util.getFixedColumnsClass(ns.b(), columnIndex, props == null ? void 0 : props.fixed, props.store, void 0, offset);
  59. const classes = [column.id, column.align, column.className, ...fixedClasses];
  60. const cellClassName = parent == null ? void 0 : parent.props.cellClassName;
  61. if (shared.isString(cellClassName)) {
  62. classes.push(cellClassName);
  63. } else if (shared.isFunction(cellClassName)) {
  64. classes.push(cellClassName.call(null, {
  65. rowIndex,
  66. columnIndex,
  67. row,
  68. column
  69. }));
  70. }
  71. classes.push(ns.e("cell"));
  72. return classes.filter((className) => Boolean(className)).join(" ");
  73. };
  74. const getSpan = (row, column, rowIndex, columnIndex) => {
  75. let rowspan = 1;
  76. let colspan = 1;
  77. const fn = parent == null ? void 0 : parent.props.spanMethod;
  78. if (shared.isFunction(fn)) {
  79. const result = fn({
  80. row,
  81. column,
  82. rowIndex,
  83. columnIndex
  84. });
  85. if (shared.isArray(result)) {
  86. rowspan = result[0];
  87. colspan = result[1];
  88. } else if (shared.isObject(result)) {
  89. rowspan = result.rowspan;
  90. colspan = result.colspan;
  91. }
  92. }
  93. return { rowspan, colspan };
  94. };
  95. const getColspanRealWidth = (columns, colspan, index) => {
  96. if (colspan < 1) {
  97. return columns[index].realWidth;
  98. }
  99. const widthArr = columns.map(({ realWidth, width }) => realWidth || width).slice(index, index + colspan);
  100. return Number(widthArr.reduce((acc, width) => Number(acc) + Number(width), -1));
  101. };
  102. return {
  103. getRowStyle,
  104. getRowClass,
  105. getCellStyle,
  106. getCellClass,
  107. getSpan,
  108. getColspanRealWidth
  109. };
  110. }
  111. exports["default"] = useStyles;
  112. //# sourceMappingURL=styles-helper.js.map