Skip to content

Commit b07a331

Browse files
wip - attempt at % width (#115)
1 parent 39fc4e9 commit b07a331

File tree

7 files changed

+50
-49
lines changed

7 files changed

+50
-49
lines changed

packages/dash-table/dash_table/bundle.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dash-table/dash_table/demo.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dash-table/src/core/Stylesheet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class StylesheetFacade {
5555
export default class Stylesheet {
5656
private stylesheet: StylesheetFacade;
5757

58-
static unit(dimension: any, defaultUnit: 'em' | 'rem' | 'px' = 'px') {
58+
static unit(dimension: any, defaultUnit: 'em' | 'rem' | 'px' | '%' = 'px') {
5959
if (Stylesheet.hasUnit(dimension)) {
6060
return dimension;
6161
} else {
@@ -65,7 +65,7 @@ export default class Stylesheet {
6565

6666
static hasUnit(dimension: any) {
6767
return typeof dimension === 'string' &&
68-
/^\d+(\.\d+)?(px|em|rem)$/.test(dimension);
68+
/^\d+(\.\d+)?(px|em|rem|%)$/.test(dimension);
6969
}
7070

7171
constructor(private readonly prefix: string) {

packages/dash-table/src/dash-table/components/ControlledTable/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,16 @@ export default class ControlledTable extends Component<ControlledTableProps> {
617617

618618
R.forEach(column => {
619619
const width = Stylesheet.unit(column.width || DEFAULT_CELL_WIDTH, 'px');
620+
const maxWidth = Stylesheet.unit(column.maxWidth || column.width || DEFAULT_CELL_WIDTH, 'px');
621+
const minWidth = Stylesheet.unit(column.minWidth || column.width || DEFAULT_CELL_WIDTH, 'px');
620622

621623
this.stylesheet.setRule(
622624
`.dash-spreadsheet-inner td.column-${typeIndex}`,
623-
`width: ${width}; max-width: ${width}; min-width: ${width};`
625+
`width: ${width}; max-width: ${maxWidth}; min-width: ${minWidth};`
624626
);
625627
this.stylesheet.setRule(
626628
`.dash-spreadsheet-inner th.column-${typeIndex}`,
627-
`width: ${width}; max-width: ${width}; min-width: ${width};`
629+
`width: ${width}; max-width: ${maxWidth}; min-width: ${minWidth};`
628630
);
629631

630632
++typeIndex;
@@ -725,7 +727,7 @@ export default class ControlledTable extends Component<ControlledTableProps> {
725727
'dash-spreadsheet-container',
726728
...(n_fixed_rows ? ['freeze-top'] : []),
727729
...(n_fixed_columns ? ['freeze-left'] : [])
728-
]
730+
];
729731

730732
const cells = this.getCells();
731733
const grid = this.getFragments(cells, n_fixed_columns, n_fixed_rows);

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,17 @@ export default class HeaderFactory {
180180

181181
// Calculate the width of all those columns combined
182182
const width = `calc(${spannedColumns.map(column => Stylesheet.unit(column.width || DEFAULT_CELL_WIDTH, 'px')).join(' + ')})`;
183+
const maxWidth = `calc(${spannedColumns.map(column => Stylesheet.unit(column.maxWidth || column.width || DEFAULT_CELL_WIDTH, 'px')).join(' + ')})`;
184+
const minWidth = `calc(${spannedColumns.map(column => Stylesheet.unit(column.minWidth || column.width || DEFAULT_CELL_WIDTH, 'px')).join(' + ')})`;
183185

184186
return (<th
185187
key={`header-cell-${columnId}`}
186188
colSpan={colSpan}
187189
className={
188190
`column-${columnId + offset} ` +
189191
(columnId === columns.length - 1 || columnId === R.last(columnIndices) ? 'cell--right-last ' : '')
190-
// (visibleIndex < n_fixed_columns ? `frozen-left frozen-left-${visibleIndex}` : '')
191-
192192
}
193-
style={visibleIndex < n_fixed_columns ? {
194-
maxWidth: width,
195-
minWidth: width,
196-
width: width
197-
} : undefined}
193+
style={visibleIndex < n_fixed_columns ? { maxWidth, minWidth, width } : undefined}
198194
>
199195
{rowSorting ? (
200196
<span

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@
8181
display: flex;
8282
flex-direction: column;
8383

84-
&.freeze-left,
85-
&.freeze-top {
86-
overflow: hidden !important;
87-
}
88-
8984
*,
9085
*:after,
9186
*:before {
@@ -121,24 +116,38 @@
121116
}
122117
}
123118

124-
.row-0 {
125-
display: flex;
126-
flex: 0 0 auto;
127-
flex-direction: row;
128-
}
119+
&.freeze-left,
120+
&.freeze-top {
121+
overflow: hidden !important;
129122

130-
.row-1 {
131-
display: flex;
132-
flex-direction: row;
133-
overflow: scroll;
134-
}
123+
.row-0 {
124+
display: flex;
125+
flex: 0 0 auto;
126+
flex-direction: row;
127+
}
128+
129+
.row-1 {
130+
display: flex;
131+
flex-direction: row;
132+
overflow: scroll;
133+
}
134+
135+
.cell-0-0,
136+
.cell-1-0 {
137+
flex: 0 0 auto;
138+
left: 0;
139+
position: sticky;
140+
z-index: 400;
141+
}
142+
143+
.cell-0-1 {
144+
z-index: 300;
145+
flex: 0 0 auto;
146+
}
135147

136-
.cell-0-0,
137-
.cell-1-0 {
138-
flex: 0 0 auto;
139-
left: 0;
140-
position: sticky;
141-
z-index: 400;
148+
.cell-1-1 {
149+
flex: 0 0 auto;
150+
}
142151
}
143152

144153
&:not(.freeze-top):not(.freeze-left) {
@@ -181,15 +190,6 @@
181190
}
182191
}
183192

184-
.cell-0-1 {
185-
z-index: 300;
186-
flex: 0 0 auto;
187-
}
188-
189-
.cell-1-1 {
190-
flex: 0 0 auto;
191-
}
192-
193193
.cell {
194194
td, th {
195195
.inset-shadow(var(--border), 0px, 0px, -1px, -1px);
@@ -453,4 +453,4 @@ th:hover .sort {
453453
.dash-spreadsheet-inner th:hover .column-header--delete {
454454
color: var(--accent);
455455
opacity: 1;
456-
}
456+
}

packages/dash-table/src/dash-table/components/Table/props.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export interface IColumn {
2727
editable?: boolean;
2828
name: string;
2929
options?: { label: string | number, value: any }[]; // legacy
30+
width?: string | number;
31+
maxWidth?: string | number;
32+
minWidth?: string | number;
3033
[key: string]: any;
3134
}
3235

0 commit comments

Comments
 (0)