Skip to content

Commit 60fd2d9

Browse files
committed
add support for more colors
1 parent ceb3284 commit 60fd2d9

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

demo/spreadsheet.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ select 'spreadsheet' as component,
99
select
1010
row_number() over (order by created_at) as x,
1111
0 as y,
12-
id as value
12+
id as value,
13+
'#80cbc4' as color -- light teal
1314
from todos
1415
order by created_at;
1516

@@ -26,6 +27,14 @@ with recursive n(n) as (
2627
union all
2728
select n + 1 from n
2829
)
29-
select n+5 as y , 4 as x, n as value, true as bold, true as italic, true as center, 'cyan' as color, '### ##0.00 €' as number_format
30+
select
31+
n+5 as y ,
32+
4 as x,
33+
n as value,
34+
true as bold,
35+
true as italic,
36+
true as center,
37+
'pink-lt' as color,
38+
'### ##0.00 €' as number_format
3039
from n
3140
limit 100;

src/spreadsheet.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,18 @@ async function handleUpdate(
180180
}
181181
}
182182

183+
const CSS_VARS = getComputedStyle(document.documentElement);
184+
183185
function cellFromProps(props: CellProps[]) {
184186
const s: IStyleData & { id?: string } = {};
185187
for (let i = 0; i < props.length; i++) {
186188
const n = props[i];
187189
if (n === 1) s.bl = 1;
188190
else if (n === 2) s.it = 1;
189191
else if (n === 3) {
190-
const color = props[++i];
191-
s.bg = {
192-
rgb: getComputedStyle(document.documentElement).getPropertyValue(
193-
`--tblr-${color}`,
194-
),
195-
};
192+
const color = props[++i].toString();
193+
const rgb = CSS_VARS.getPropertyValue(`--tblr-${color}`) || color;
194+
s.bg = { rgb };
196195
} else if (n === 4) s.ht = 2;
197196
else if (n === 5) s.ht = 3;
198197
else if (n === 6) {
@@ -253,7 +252,7 @@ async function renderSpreadsheet(
253252
setFrozenCells(univerAPI, activeSheet, freeze_x, freeze_y);
254253

255254
univerAPI.onCommandExecuted(({ id, params }) => {
256-
console.log(id, params);
255+
// To debug: console.log(id, params);
257256
const set_range: typeof SetRangeValuesMutation.id =
258257
"sheet.mutation.set-range-values";
259258
if (id === set_range) {

0 commit comments

Comments
 (0)