tav-ui
Version:
81 lines (76 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('../const2.js');
const containDotTextWidth = 12 * 2 + 7.5;
const textWidth = (n) => 12 * n;
const dividerWidth = 17;
const padding = 10 * 2;
const moreBtnWidth = 13.5 + 10;
const maxWidth = containDotTextWidth * 3 + dividerWidth * 2;
const minWidth = 60;
function limitActionLabel(actions, labelMaxLength = 3) {
return actions.map((action) => {
const { label } = action;
if (label && label.length > labelMaxLength) {
action.tooltip = label;
action.label = `${label.substring(0, 2)}..`;
}
return action;
});
}
function isOverMaxWidth(actions) {
if (!actions)
return false;
const getTotal = (_actions) => {
return _actions.reduce((total, action, idx) => {
if (action.label) {
total += textWidth(action.label.length);
} else {
total += 0;
}
if (idx !== _actions.length - 1) {
total += dividerWidth;
}
return total;
}, 0);
};
const result = getTotal(actions) > maxWidth;
return result;
}
function useColumnActionAutoWidth(actions, handleLimit = true) {
if (!actions)
return void 0;
const getTotal = (_actions) => {
return _actions.reduce((total, action, idx) => {
if (action.label) {
if (action.label.includes("..")) {
total += containDotTextWidth;
} else {
total += textWidth(action.label.length);
}
} else {
total += 0;
}
if (idx !== _actions.length - 1) {
total += dividerWidth;
} else {
total += padding;
}
return total;
}, 0);
};
const handledActions = handleLimit ? limitActionLabel(JSON.parse(JSON.stringify(actions))) : JSON.parse(JSON.stringify(actions));
if (handledActions.length <= _const.MAX_ACTION_NUMBER) {
const total = getTotal(handledActions);
return total < minWidth ? minWidth : total;
} else {
const contentActions = handledActions.slice(0, 2);
let total = getTotal(contentActions);
total += moreBtnWidth;
return total < minWidth ? minWidth : total;
}
}
exports.isOverMaxWidth = isOverMaxWidth;
exports.limitActionLabel = limitActionLabel;
exports.useColumnActionAutoWidth = useColumnActionAutoWidth;
//# sourceMappingURL=useColumnAutoWidth2.js.map