Skip to content

Commit 697c381

Browse files
committed
Merge pull request plotly#444 from plotly/Issue435
Issue 435 - Table selected cell
1 parent 22bb3cc commit 697c381

File tree

10 files changed

+55
-27
lines changed

10 files changed

+55
-27
lines changed

packages/dash-table/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
[#434](https://github.com/plotly/dash-table/issues/434)
88
- Fix CSS borders propeties overwrite style_* borders properties.
99

10+
[#435](https://github.com/plotly/dash-table/issues/434)
11+
- selected_cells background color is set through styling pipeline / derivations.
12+
1013
## [3.7.0] - 2019-05-15
1114
### Added
1215
[#397](https://github.com/plotly/dash-table/pull/397), [#410](https://github.com/plotly/dash-table/pull/410)

packages/dash-table/generator/cssPropertiesGenerator.js

-3
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,6 @@ snakes.forEach(([snake, camel]) => map.set(snake, camel));
300300
kebabs.forEach(([kebab, camel]) => map.set(kebab, camel));
301301
camels.forEach(([camel]) => map.set(camel, camel));
302302

303-
map.forEach((value, key) => console.log(value, key));
304-
console.log(map.size);
305-
306303
const fs = require('fs');
307304

308305
var stream1 = fs.createWriteStream("src/dash-table/derived/style/py2jsCssProperties.ts");

packages/dash-table/src/dash-table/components/CellFactory.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export default class CellFactory {
6363
columns,
6464
relevantStyles,
6565
virtualized.data,
66-
virtualized.offset
66+
virtualized.offset,
67+
selected_cells
6768
);
6869

6970
const dataOpStyles = this.dataOpStyles(

packages/dash-table/src/dash-table/components/Table/Dropdown.css

-5
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,3 @@
113113
.dash-spreadsheet .Select-control {
114114
padding-left: 2px;
115115
}
116-
117-
.dash-spreadsheet .cell--selected .Select-control {
118-
background-color: var(--selected-background);
119-
border-radius: 0;
120-
}

packages/dash-table/src/dash-table/components/Table/Table.less

-11
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,13 @@
244244
}
245245
}
246246

247-
.selected-row {
248-
td, th {
249-
background-color: var(--selected-row);
250-
}
251-
}
252-
253247
tr {
254248
background-color: white;
255249
}
256250

257251
td {
258252
background-color: inherit;
259253

260-
&.cell--selected {
261-
background-color: var(--selected-background);
262-
}
263-
264254
&.focused {
265255
margin: -1px;
266256
z-index: 200;
@@ -367,7 +357,6 @@
367357
--faded-text-header: rgb(180, 180, 180);
368358
--selected-background: rgba(255, 65, 54, 0.2);
369359
--faded-dropdown: rgb(240, 240, 240);
370-
--selected-row: #fff0ff;
371360
--muted: rgb(200, 200, 200);
372361
}
373362

packages/dash-table/src/dash-table/derived/cell/wrapperStyles.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as R from 'ramda';
22
import { CSSProperties } from 'react';
33

44
import { memoizeOneFactory } from 'core/memoizer';
5-
import { Data, VisibleColumns, IViewportOffset } from 'dash-table/components/Table/props';
5+
import { Data, VisibleColumns, IViewportOffset, SelectedCells, ICellCoordinates } from 'dash-table/components/Table/props';
66
import { IConvertedStyle } from '../style';
77
import { BORDER_PROPERTIES_AND_FRAGMENTS } from '../edges/type';
88

@@ -12,9 +12,10 @@ function getter(
1212
columns: VisibleColumns,
1313
columnStyles: IConvertedStyle[],
1414
data: Data,
15-
offset: IViewportOffset
15+
offset: IViewportOffset,
16+
selectedCells: SelectedCells
1617
): Style[][] {
17-
return R.addIndex<any, Style[]>(R.map)((datum, index) => R.map(column => {
18+
return R.addIndex<any, Style[]>(R.map)((datum, index) => R.addIndex<any, Style>(R.map)((column, columnIndex) => {
1819
const relevantStyles = R.map(
1920
s => s.style,
2021
R.filter<IConvertedStyle>(
@@ -25,7 +26,11 @@ function getter(
2526
columnStyles
2627
)
2728
);
28-
29+
const matchCell = (cell: ICellCoordinates) => cell.row === index && cell.column === columnIndex;
30+
const isSelectedCell: boolean = R.any(matchCell)(selectedCells);
31+
if (isSelectedCell) {
32+
relevantStyles.push({backgroundColor: 'var(--selected-background)'});
33+
}
2934
return relevantStyles.length ?
3035
R.omit(
3136
BORDER_PROPERTIES_AND_FRAGMENTS,

packages/dash-table/src/dash-table/derived/cell/wrappers.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class Wrappers {
3333
(column, columnIndex) => {
3434
const active = isActiveCell(activeCell, rowIndex + offset.rows, columnIndex + offset.columns);
3535
const selected = isSelectedCell(selectedCells, rowIndex + offset.rows, columnIndex + offset.columns);
36-
3736
const isDropdown = column.presentation === Presentation.Dropdown;
38-
3937
const classes =
4038
'dash-cell' +
4139
` column-${columnIndex}` +

packages/dash-table/tests/visual/percy-storybook/DashTable.percy.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ storiesOf('DashTable/Hidden Columns', module)
229229
id='table'
230230
data={dataA2J}
231231
columns={hiddenColumns}
232+
active_cell={makeCell(1, 1, dataA2J, hiddenColumns)}
232233
selected_cells={makeSelection([[1, 1], [1, 2], [2, 1], [2, 2]], dataA2J, hiddenColumns)}
233234
style_data_conditional={style_data_conditional}
234235
/>));

packages/dash-table/tests/visual/percy-storybook/Style.percy.tsx

+38-1
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,42 @@ storiesOf('DashTable/Style type condition', module)
134134
if: { column_id: 'Humidity', filter: '{Humidity} eq 20' },
135135
background_color: 'yellow'
136136
}]}
137-
137+
/>))
138+
.add('single selected cells on dark themes', () => (<DataTable
139+
id='styling-11'
140+
data={data}
141+
selected_cells={[{row: 1, column: 1, column_id: 'Region'}]}
142+
active_cell={{row: 1, column: 1}}
143+
columns={R.map(
144+
i => ({ name: i, id: i }),
145+
R.keysIn(data[0]))
146+
}
147+
content_style='grow'
148+
style_table={{
149+
width: '100%'
150+
}}
151+
style_data_conditional={[{
152+
background_color: 'rgb(50, 50, 50)',
153+
color: 'white',
154+
font_family: 'arial'
155+
}]}
156+
/>))
157+
.add('multiple selected cells on dark themes', () => (<DataTable
158+
id='styling-12'
159+
data={data}
160+
selected_cells={[{row: 1, column: 1, column_id: 'Region'}, {row: 1, column: 2, column_id: 'Temperature'}, {row: 2, column: 1, column_id: 'Region'}, {row: 2, column: 2, column_id: 'Temperature'}]}
161+
active_cell={{row: 1, column: 1}}
162+
columns={R.map(
163+
i => ({ name: i, id: i }),
164+
R.keysIn(data[0]))
165+
}
166+
content_style='grow'
167+
style_table={{
168+
width: '100%'
169+
}}
170+
style_data_conditional={[{
171+
background_color: 'rgb(50, 50, 50)',
172+
color: 'white',
173+
font_family: 'arial'
174+
}]}
138175
/>));

packages/dash-table/tests/visual/percy-storybook/fixtures.ts

+2
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ export default [
410410
id: 'table',
411411
editable: true,
412412
selected_cells: [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],
413+
active_cell: [1, 1],
413414
columns: [
414415
{
415416
name: 'Column 1',
@@ -444,6 +445,7 @@ export default [
444445
id: 'table',
445446
editable: true,
446447
selected_cells: [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]],
448+
active_cell: [1, 1],
447449
merge_duplicate_headers: true,
448450
columns: [
449451
{

0 commit comments

Comments
 (0)