@glideapps/glide-data-grid
Version:
React data grid for beautifully displaying and editing large amounts of data with amazing performance.
56 lines • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.newRowCellRenderer = void 0;
const data_grid_lib_js_1 = require("../internal/data-grid/render/data-grid-lib.js");
const data_grid_types_js_1 = require("../internal/data-grid/data-grid-types.js");
exports.newRowCellRenderer = {
getAccessibilityString: () => "",
kind: data_grid_types_js_1.InnerGridCellKind.NewRow,
needsHover: true,
needsHoverPosition: false,
measure: () => 200,
draw: a => drawNewRowCell(a, a.cell.hint, a.cell.icon),
onPaste: () => undefined,
};
function drawNewRowCell(args, data, icon) {
const { ctx, rect, hoverAmount, theme, spriteManager } = args;
const { x, y, width: w, height: h } = rect;
ctx.beginPath();
ctx.globalAlpha = hoverAmount;
ctx.rect(x + 1, y + 1, w, h - 2);
ctx.fillStyle = theme.bgHeaderHovered;
ctx.fill();
ctx.globalAlpha = 1;
ctx.beginPath();
const alwaysShowIcon = data !== "";
let textX = 0;
if (icon !== undefined) {
const padding = 8;
const size = h - padding;
const px = x + padding / 2;
const py = y + padding / 2;
spriteManager.drawSprite(icon, "normal", ctx, px, py, size, theme, alwaysShowIcon ? 1 : hoverAmount);
textX = size;
}
else {
textX = 24;
const finalLineSize = 12;
const lineSize = alwaysShowIcon ? finalLineSize : hoverAmount * finalLineSize;
const xTranslate = alwaysShowIcon ? 0 : (1 - hoverAmount) * finalLineSize * 0.5;
const padPlus = theme.cellHorizontalPadding + 4;
if (lineSize > 0) {
ctx.moveTo(x + padPlus + xTranslate, y + h / 2);
ctx.lineTo(x + padPlus + xTranslate + lineSize, y + h / 2);
ctx.moveTo(x + padPlus + xTranslate + lineSize * 0.5, y + h / 2 - lineSize * 0.5);
ctx.lineTo(x + padPlus + xTranslate + lineSize * 0.5, y + h / 2 + lineSize * 0.5);
ctx.lineWidth = 2;
ctx.strokeStyle = theme.bgIconHeader;
ctx.lineCap = "round";
ctx.stroke();
}
}
ctx.fillStyle = theme.textMedium;
ctx.fillText(data, textX + x + theme.cellHorizontalPadding + 0.5, y + h / 2 + (0, data_grid_lib_js_1.getMiddleCenterBias)(ctx, theme));
ctx.beginPath();
}
//# sourceMappingURL=new-row-cell.js.map