Add QExcell cell text colors

This commit is contained in:
Курнат Андрей
2026-06-01 06:19:24 +03:00
parent 08fe16bdf6
commit 9c48e1d8b1
6 changed files with 51 additions and 13 deletions
+27
View File
@@ -17,6 +17,7 @@ import {
Save,
Sigma,
Trash2,
Type,
Underline
} from "lucide-react";
import type { CellFormat, SheetChart, SheetChartType, Workbook } from "../../types";
@@ -48,6 +49,15 @@ const fillSwatches = [
{ color: "EADCF8", label: "Светло-фиолетовая заливка" }
];
const textColorSwatches = [
{ color: "", label: "Авто цвет текста" },
{ color: "202124", label: "Черный текст" },
{ color: "0F5FAE", label: "Синий текст" },
{ color: "0F766E", label: "Зеленый текст" },
{ color: "C2410C", label: "Красный текст" },
{ color: "7C3AED", label: "Фиолетовый текст" }
];
const numberFormatOptions = [
{ value: "", label: "Обычный" },
{ value: "0.00", label: "Число" },
@@ -85,12 +95,14 @@ function normalizedFillColor(value?: string) {
}
function normalizedCellFormat(format: CellFormat): CellFormat | undefined {
const textColor = normalizedFillColor(format.textColor);
const fillColor = normalizedFillColor(format.fillColor);
const numberFormat = format.numberFormat?.trim();
const normalized: CellFormat = {
...(format.bold ? { bold: true } : {}),
...(format.italics ? { italics: true } : {}),
...(format.underline ? { underline: true } : {}),
...(textColor ? { textColor } : {}),
...(fillColor ? { fillColor } : {}),
...(numberFormat ? { numberFormat } : {})
};
@@ -103,6 +115,7 @@ function cellInputStyle(format?: CellFormat): CSSProperties {
...(format?.bold ? { fontWeight: 700 } : {}),
...(format?.italics ? { fontStyle: "italic" } : {}),
...(format?.underline ? { textDecoration: "underline" } : {}),
...(format?.textColor ? { color: `#${format.textColor}` } : {}),
...(format?.fillColor ? { backgroundColor: `#${format.fillColor}` } : {})
};
}
@@ -462,6 +475,20 @@ export function QExcell({ workbook, onChange }: QExcellProps) {
/>
))}
</div>
<div className="fill-swatches" aria-label="Цвет текста">
<Type size={16} aria-hidden="true" />
{textColorSwatches.map((swatch) => (
<button
key={swatch.label}
className={`fill-swatch ${swatch.color ? "" : "is-empty"} ${selectedCellFormat.textColor === swatch.color || (!selectedCellFormat.textColor && !swatch.color) ? "is-active" : ""}`.trim()}
type="button"
onClick={() => updateCellFormat(selectedCell, { textColor: swatch.color })}
title={swatch.label}
aria-label={swatch.label}
style={swatch.color ? { backgroundColor: `#${swatch.color}` } : undefined}
/>
))}
</div>
</div>
<button className="compact-command" type="button" onClick={() => void chooseXlsx()}>
<FileUp size={16} />