Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS cleanups, fixes, and reimplementations #1780

Merged
merged 37 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
87c520c
Clean up a bit of the core css, and Header type
nstepien Oct 9, 2019
1dd80a0
Row css cleanup
nstepien Oct 9, 2019
0f4217b
Fix fragment id prop warning in dev mode
nstepien Oct 9, 2019
4a1539a
context menu styling
nstepien Oct 9, 2019
f1831ae
Fix missing background color on frozen cells
nstepien Oct 9, 2019
3274cdc
Use flex to align cells vertically, small optimizations
nstepien Oct 9, 2019
68319b5
header cells = cells
nstepien Oct 9, 2019
8f7b035
Use sticky position for frozen header cells as well
nstepien Oct 9, 2019
847aaa4
Fix tests
nstepien Oct 9, 2019
f1bfc57
Editor styling
nstepien Oct 10, 2019
0946abc
Fix tests
nstepien Oct 10, 2019
8df3097
bit more padding
nstepien Oct 10, 2019
39e3df2
small fixes
nstepien Oct 10, 2019
e551156
Merge remote-tracking branch 'origin/canary' into ns-css
nstepien Oct 10, 2019
0b62bf3
Redo checkbox styling
nstepien Oct 10, 2019
d1d0632
Merge remote-tracking branch 'origin/canary' into ns-css
nstepien Oct 11, 2019
a798e63
Merge branch 'canary' into ns-css
nstepien Oct 11, 2019
a71bb68
Merge branch 'canary' into ns-css
nstepien Oct 11, 2019
2655198
more draggable header cell fixes
nstepien Oct 11, 2019
69e0d31
fix NumericFilter style
nstepien Oct 11, 2019
9a2039b
Align cells vertically using line-height
nstepien Oct 11, 2019
1c726b2
pull header sort arrows to the right
nstepien Oct 11, 2019
6992bc7
Fix tests
nstepien Oct 11, 2019
1733bf2
set line-height on the root
nstepien Oct 11, 2019
fae14e1
Couple cleanups
nstepien Oct 11, 2019
b24647b
rdg-cell
nstepien Oct 11, 2019
c7be8ee
more renaming
nstepien Oct 11, 2019
fe6abab
center filters again
nstepien Oct 12, 2019
242f370
Add MUI icons package
nstepien Oct 14, 2019
ccb75df
Replace glyphicons
nstepien Oct 14, 2019
644eb2a
harmonize frozen cell styles
nstepien Oct 14, 2019
1616b74
Fix jest performance
nstepien Oct 14, 2019
54d387d
Merge branch 'canary' into ns-css
nstepien Oct 15, 2019
51bb092
Scroll the header as a whole, skip some refs
nstepien Oct 15, 2019
5f6e2f6
Fix tests
nstepien Oct 15, 2019
ed99436
Fix sortable header cell text overflow
nstepien Oct 15, 2019
10b0028
Fix tests
nstepien Oct 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions examples/demos/example08-sortable-cols.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,31 @@ export default class extends React.Component {
{
key: 'task',
name: 'Title',
width: 200,
sortable: true
},
{
key: 'priority',
name: 'Priority',
width: 200,
sortable: true
},
{
key: 'issueType',
name: 'Issue Type',
width: 200,
sortable: true
},
{
key: 'complete',
name: '% Complete',
width: 200,
sortable: true
},
{
key: 'startDate',
name: 'Start Date',
width: 200,
sortable: true
},
{
key: 'completeDate',
name: 'Expected Complete',
width: 200,
sortable: true
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,19 @@ export default function NumericFilter<R>({ column, onChange }: Props<R>) {
}

const inputKey = `header-filter-${column.key as keyof R}`;
const columnStyle: React.CSSProperties = {
float: 'left',
marginRight: 5,
maxWidth: '80%'
};
const badgeStyle: React.CSSProperties = {
cursor: 'help'
};

const tooltipText = 'Input Methods: Range (x-y), Greater Then (>x), Less Then (<y)';

return (
<div>
<div style={columnStyle}>
<input
key={inputKey}
placeholder="e.g. 3,10-15,>20"
className="form-control input-sm"
onChange={handleChange}
onKeyPress={handleKeyPress}
/>
</div>
<div className="input-sm">
<span className="badge" style={badgeStyle} title={tooltipText}>?</span>
</div>
<div className="rdg-numeric-filter">
<input
key={inputKey}
className="rdg-filter"
placeholder="e.g. 3,10-15,>20"
onChange={handleChange}
onKeyPress={handleKeyPress}
/>
<span className="rdg-filter-badge" title={tooltipText}>?</span>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { DragSource, DropTarget } from 'react-dnd';

class DraggableHeaderCell extends React.Component {
Expand All @@ -21,18 +22,13 @@ class DraggableHeaderCell extends React.Component {
canDrop
} = this.props;

let opacity = 1;
if (isDragging) {
opacity = 0.2;
}

// set drag source and drop target on header cell
// width: 0 - otherwise drag clone was wrongly positioned
return connectDragSource(
connectDropTarget(
<div
style={{ width: 0, cursor: 'move', opacity }}
className={isOver && canDrop ? 'rdg-can-drop' : ''}
className={classNames('rdg-draggable-header-cell', { 'rdg-can-drop': isOver && canDrop })}
style={{ opacity: isDragging ? 0.2 : 1 }}
>
{this.props.children}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DraggableHeaderCell extends Component {
if (isDragging) {
return null;
}
return connectDragSource(<div style={{ cursor: 'move' }}>{this.props.children}</div>);
return connectDragSource(<div className="rdg-draggable-header-cell">{this.props.children}</div>);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class DropDownEditor extends React.Component {
return (
<select
ref={this.setSelectRef}
style={{ width: '100%' }}
className="rdg-select-editor"
defaultValue={this.props.value}
onBlur={this.props.onBlur}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ describe('DropDownEditor', () => {
);
});

it('should pass width=100% to the select node as an inline style', () => {
const Select = TestUtils.findRenderedDOMComponentWithTag(component, 'select');
expect(Select.style.width).toBe('100%');
});

it('should pass the value to the select node as an inline value', () => {
const Select = TestUtils.findRenderedDOMComponentWithTag(component, 'select');
expect(Select.value).toBe('option2');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function GroupedColumnButton({ name, columnKey, onColumnGroupDele
return (
<div className="grouped-col-btn btn btn-sm">
<span className="grouped-col-btn__name">{name}</span>
<span className="grouped-col-btn__remove glyphicon glyphicon-trash" onClick={onClick} />
<span className="grouped-col-btn__remove glyphicon glyphicon-trash" onClick={onClick}>×</span>
</div>
);
}
39 changes: 39 additions & 0 deletions packages/react-data-grid-addons/style/rdg-contextmenu.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.react-contextmenu {
cursor: pointer;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 3px;
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.24);

font-size: 14px;
line-height: 2;
white-space: nowrap;

> .react-contextmenu-item:not(:last-child) {
border-bottom: 1px solid #ddd;
}

.react-contextmenu-submenu > & {
margin-top: -1px;
}
}

.react-contextmenu-item:not(.react-contextmenu-submenu) {
padding: 0 12px;
}

.react-contextmenu-item--selected {
background-color: darken(#fff, 4%);
}

.react-contextmenu-submenu > .react-contextmenu-item {
&::after {
content: "▶";
margin-left: 12px;
margin-right: -6px;
}

&:not(.react-contextmenu-item--active) + .react-contextmenu {
display: none;
}
}
3 changes: 2 additions & 1 deletion packages/react-data-grid-addons/style/rdg-image.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
display: inline-block;
height: 40px;
width: 40px;
}
vertical-align: middle;
}
16 changes: 16 additions & 0 deletions packages/react-data-grid-addons/style/react-data-grid-addons.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@import 'rdg-contextmenu.less';
@import 'rdg-drop-target.less';
@import 'rdg-image.less';
@import 'rdg-toolbar.less';

.rdg-dragging {
cursor: grabbing;
}

.rdg-draggable-header-cell {
cursor: move;
display: inline-block;
height: inherit;
background-color: inherit;
}

.rdg-can-drop {
background-color: #ececec;
}
30 changes: 20 additions & 10 deletions packages/react-data-grid/src/Canvas.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment, useState, useRef, useEffect, useMemo } from 'react';
import React, { useState, useRef, useEffect, useMemo } from 'react';
import { isElement } from 'react-is';

import Row from './Row';
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function Canvas<R>({
rowHeight,
rowKey,
rowRenderer,
RowsContainer = Fragment,
RowsContainer,
rowsCount,
scrollToRowIndex,
selectedRows
Expand Down Expand Up @@ -275,12 +275,26 @@ export default function Canvas<R>({
);
}

const paddingTop = rowOverscanStartIdx * rowHeight;
const paddingBottom = (rowsCount - 1 - rowOverscanEndIdx) * rowHeight;
let grid = (
<div
className="rdg-grid"
style={{
width: columnMetrics.totalColumnWidth,
paddingTop: rowOverscanStartIdx * rowHeight,
paddingBottom: (rowsCount - 1 - rowOverscanEndIdx) * rowHeight
}}
>
{getRows()}
</div>
);

if (RowsContainer !== undefined) {
grid = <RowsContainer id={contextMenu ? contextMenu.props.id : 'rowsContainer'}>{grid}</RowsContainer>;
}

return (
<div
className="react-grid-Canvas"
className="rdg-viewport"
style={{ height }}
ref={canvas}
onScroll={handleScroll}
Expand Down Expand Up @@ -311,11 +325,7 @@ export default function Canvas<R>({
editorPortalTarget={editorPortalTarget}
{...interactionMasksMetaData}
/>
<RowsContainer id={contextMenu ? contextMenu.props.id : 'rowsContainer'}>
<div className="rdg-rows-container" style={{ width: columnMetrics.totalColumnWidth, paddingTop, paddingBottom }}>
{getRows()}
</div>
</RowsContainer>
{grid}
</div>
);
}
14 changes: 9 additions & 5 deletions packages/react-data-grid/src/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ export default class Cell<R> extends React.Component<CellProps<R>> implements Ce
};

getStyle(): React.CSSProperties {
const { column, height, scrollLeft } = this.props;
const { column } = this.props;

return {
height,
const style: React.CSSProperties = {
width: column.width,
left: column.left,
transform: !isPositionStickySupported() && isFrozen(column) ? `translateX(${scrollLeft}px)` : 'none'
left: column.left
};

if (!isPositionStickySupported() && isFrozen(column)) {
style.transform = `translateX(${this.props.scrollLeft}px)`;
}

return style;
}

getCellClass() {
Expand Down
22 changes: 10 additions & 12 deletions packages/react-data-grid/src/Cell/CellContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function CellContent<R>({
}: CellContentProps<R>) {
const isExpandCell = expandableOptions ? expandableOptions.field === column.key : false;
const treeDepth = expandableOptions ? expandableOptions.treeDepth : 0;
const marginLeft = expandableOptions && isExpandCell ? expandableOptions.treeDepth * 30 : 0;
const style = expandableOptions && isExpandCell ? { marginLeft: expandableOptions.treeDepth * 30 } : undefined;

function handleDeleteSubRow() {
if (onDeleteSubRow) {
Expand Down Expand Up @@ -67,17 +67,15 @@ export default function CellContent<R>({
return (
<div className={classes}>
{cellDeleter}
<div className="react-grid-Cell__container" style={{ marginLeft }}>
<span>
<CellValue<R>
rowIdx={rowIdx}
rowData={rowData}
column={column}
value={value}
isRowSelected={isRowSelected}
onRowSelectionChange={onRowSelectionChange}
/>
</span>
<div style={style}>
<CellValue<R>
rowIdx={rowIdx}
rowData={rowData}
column={column}
value={value}
isRowSelected={isRowSelected}
onRowSelectionChange={onRowSelectionChange}
/>
{cellControls}
</div>
{tooltip && <span className="cell-tooltip-text">{tooltip}</span>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/adazzle/react-data-grid/pull/1773/files/cba04c56c295e32fa3f036cb6cd9dbd5f8d5ec60#r333000852

Thoughts about removing this here? Since the style is touched, if we want to remove, I bet it's better in this PR. Or we keep it for revisiting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in a separate PR.

Expand Down
9 changes: 1 addition & 8 deletions packages/react-data-grid/src/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { forwardRef, useRef, useState, useMemo, useImperativeHandle } from 'react';
import classNames from 'classnames';

import HeaderRow from './HeaderRow';
import { getColumnMetrics } from './utils/columnUtils';
Expand All @@ -26,7 +25,6 @@ export interface HeaderProps<R> extends SharedDataGridProps<R> {
columnMetrics: ColumnMetrics<R>;
headerRows: [HeaderRowData<R>, HeaderRowData<R> | undefined];
cellMetaData: CellMetaData<R>;
rowOffsetHeight: number;
onSort?(columnKey: keyof R, direction: DEFINE_SORT): void;
onColumnResize(idx: number, width: number): void;
}
Expand Down Expand Up @@ -124,17 +122,12 @@ export default forwardRef(function Header<R>(props: HeaderProps<R>, ref: React.R
props.cellMetaData.onCellClick({ rowIdx: -1, idx: -1 });
}

const className = classNames('react-grid-Header', {
'react-grid-Header--resizing': resizing !== null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like we need it no.

});

return (
<div
className="rdg-header"
style={{
height: props.rowOffsetHeight,
paddingRight: getScrollbarSize()
}}
className={className}
onClick={onHeaderClick}
>
{getHeaderRows()}
Expand Down
Loading