f987d5b6905ddd235a4f154424dbed5c2b01ee941554fbdb8c9d6ba6babfa086ca95a5f4879563f703bff8fe549c3f44a006103a5f7e0ce15930696301d35a 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { inject } from 'vue';
  2. import { getFixedColumnOffset, ensurePosition, getFixedColumnsClass } from '../util.mjs';
  3. import { TABLE_INJECTION_KEY } from '../tokens.mjs';
  4. import { useNamespace } from '../../../../hooks/use-namespace/index.mjs';
  5. import { isFunction, isString } from '@vue/shared';
  6. function useStyle(props) {
  7. const parent = inject(TABLE_INJECTION_KEY);
  8. const ns = useNamespace("table");
  9. const getHeaderRowStyle = (rowIndex) => {
  10. const headerRowStyle = parent == null ? void 0 : parent.props.headerRowStyle;
  11. if (isFunction(headerRowStyle)) {
  12. return headerRowStyle.call(null, { rowIndex });
  13. }
  14. return headerRowStyle;
  15. };
  16. const getHeaderRowClass = (rowIndex) => {
  17. const classes = [];
  18. const headerRowClassName = parent == null ? void 0 : parent.props.headerRowClassName;
  19. if (isString(headerRowClassName)) {
  20. classes.push(headerRowClassName);
  21. } else if (isFunction(headerRowClassName)) {
  22. classes.push(headerRowClassName.call(null, { rowIndex }));
  23. }
  24. return classes.join(" ");
  25. };
  26. const getHeaderCellStyle = (rowIndex, columnIndex, row, column) => {
  27. var _a;
  28. let headerCellStyles = (_a = parent == null ? void 0 : parent.props.headerCellStyle) != null ? _a : {};
  29. if (isFunction(headerCellStyles)) {
  30. headerCellStyles = headerCellStyles.call(null, {
  31. rowIndex,
  32. columnIndex,
  33. row,
  34. column
  35. });
  36. }
  37. const fixedStyle = getFixedColumnOffset(columnIndex, column.fixed, props.store, row);
  38. ensurePosition(fixedStyle, "left");
  39. ensurePosition(fixedStyle, "right");
  40. return Object.assign({}, headerCellStyles, fixedStyle);
  41. };
  42. const getHeaderCellClass = (rowIndex, columnIndex, row, column) => {
  43. const fixedClasses = getFixedColumnsClass(ns.b(), columnIndex, column.fixed, props.store, row);
  44. const classes = [
  45. column.id,
  46. column.order,
  47. column.headerAlign,
  48. column.className,
  49. column.labelClassName,
  50. ...fixedClasses
  51. ];
  52. if (!column.children) {
  53. classes.push("is-leaf");
  54. }
  55. if (column.sortable) {
  56. classes.push("is-sortable");
  57. }
  58. const headerCellClassName = parent == null ? void 0 : parent.props.headerCellClassName;
  59. if (isString(headerCellClassName)) {
  60. classes.push(headerCellClassName);
  61. } else if (isFunction(headerCellClassName)) {
  62. classes.push(headerCellClassName.call(null, {
  63. rowIndex,
  64. columnIndex,
  65. row,
  66. column
  67. }));
  68. }
  69. classes.push(ns.e("cell"));
  70. return classes.filter((className) => Boolean(className)).join(" ");
  71. };
  72. return {
  73. getHeaderRowStyle,
  74. getHeaderRowClass,
  75. getHeaderCellStyle,
  76. getHeaderCellClass
  77. };
  78. }
  79. export { useStyle as default };
  80. //# sourceMappingURL=style.helper.mjs.map