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

Use the new jsx runtime, bump peerDeps #2184

Merged
merged 17 commits into from
Nov 9, 2020
Merged
14 changes: 12 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,17 @@ const rules = {
'no-duplicate-imports': 0, // replace by @typescript-eslint/no-duplicate-imports
'no-new-symbol': 0,
'no-restricted-exports': 0,
'no-restricted-imports': 0,
'no-restricted-imports': [1, {
"paths": [{
"name": "react",
"importNames": ["default"],
"message": "Use named imports instead."
}, {
"name": "react-dom",
"importNames": ["default"],
"message": "Use named imports instead."
}]
}],
'no-this-before-super': 0,
'no-useless-computed-key': [1, { enforceForClassMembers: true }],
'no-useless-constructor': 0, // replaced by @typescript-eslint/no-useless-constructor
Expand Down Expand Up @@ -371,7 +381,7 @@ const rules = {
afterOpening: 'never',
beforeClosing: 'never'
}],
'react/jsx-uses-react': 1,
'react/jsx-uses-react': 0,
'react/jsx-uses-vars': 1,
'react/jsx-wrap-multilines': [1, {
declaration: 'parens-new-line',
Expand Down
2 changes: 1 addition & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'core-js/stable';
import '../style/index.less';
import '../stories/index.less';
import React, { StrictMode } from 'react';
import { StrictMode } from 'react';
import { ResizeObserver as Polyfill } from '@juggle/resize-observer';
import { addDecorator } from '@storybook/react';

Expand Down
2 changes: 1 addition & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@babel/proposal-optional-chaining"
]
}],
["@babel/react", { "useSpread": true }],
["@babel/react", { "runtime": "automatic" }],
"@babel/typescript"
],
"plugins": [
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"typescript": "~4.0.5"
},
"peerDependencies": {
"react": "^16.8 || ^17.0",
"react-dom": "^16.8 || ^17.0"
"react": "^16.14 || ^17.0",
"react-dom": "^16.14 || ^17.0"
}
}
2 changes: 1 addition & 1 deletion src/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, memo, useRef } from 'react';
import { forwardRef, memo, useRef } from 'react';
import clsx from 'clsx';

import type { CellRendererProps } from './types';
Expand Down
1 change: 0 additions & 1 deletion src/Columns.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { SelectCellFormatter } from './formatters';
import type { Column } from './types';
import { stopPropagation } from './utils/domUtils';
Expand Down
9 changes: 4 additions & 5 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, {
import {
forwardRef,
useState,
useRef,
useLayoutEffect,
useImperativeHandle,
useCallback,
createElement
useCallback
} from 'react';
import clsx from 'clsx';

Expand Down Expand Up @@ -189,7 +188,7 @@ function DataGrid<R, SR>({
onExpandedGroupIdsChange,
// Custom renderers
rowRenderer: RowRenderer = Row,
emptyRowsRenderer,
emptyRowsRenderer: EmptyRowsRenderer,
// Event props
onRowClick,
onScroll,
Expand Down Expand Up @@ -911,7 +910,7 @@ function DataGrid<R, SR>({
onFiltersChange={onFiltersChange}
/>
)}
{rows.length === 0 && emptyRowsRenderer ? createElement(emptyRowsRenderer) : (
{rows.length === 0 && EmptyRowsRenderer ? <EmptyRowsRenderer /> : (
<>
<div
ref={focusSinkRef}
Expand Down
2 changes: 1 addition & 1 deletion src/EditCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback } from 'react';
import { useState, useCallback } from 'react';
import clsx from 'clsx';

import EditorContainer from './editors/EditorContainer';
Expand Down
14 changes: 8 additions & 6 deletions src/FilterRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createElement, memo } from 'react';
import { memo } from 'react';
import clsx from 'clsx';

import type { CalculatedColumn, Filters } from './types';
Expand Down Expand Up @@ -48,11 +48,13 @@ function FilterRow<R, SR>({
style={style}
className={className}
>
{column.filterRenderer && createElement(column.filterRenderer, {
column,
value: filters?.[column.key],
onChange: value => onChange(key, value)
})}
{column.filterRenderer && (
<column.filterRenderer
column={column}
value={filters?.[column.key]}
onChange={value => onChange(key, value)}
/>
)}
</div>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion src/GroupCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo } from 'react';
import { memo } from 'react';
import clsx from 'clsx';

import type { CalculatedColumn } from './types';
Expand Down
2 changes: 1 addition & 1 deletion src/GroupRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo } from 'react';
import { memo } from 'react';
import clsx from 'clsx';

import type { CalculatedColumn, Position, SelectRowEvent, Omit } from './types';
Expand Down
19 changes: 10 additions & 9 deletions src/HeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React, { createElement } from 'react';
import clsx from 'clsx';

import type { CalculatedColumn } from './types';
Expand Down Expand Up @@ -42,14 +41,16 @@ export default function HeaderCell<R, SR>({
}: HeaderCellProps<R, SR>) {
function getCell() {
if (column.headerRenderer) {
return createElement(column.headerRenderer, {
column,
sortColumn,
sortDirection,
onSort,
allRowsSelected,
onAllRowsSelectionChange
});
return (
<column.headerRenderer
column={column}
sortColumn={sortColumn}
sortDirection={sortDirection}
onSort={onSort}
allRowsSelected={allRowsSelected}
onAllRowsSelectionChange={onAllRowsSelectionChange}
/>
);
}

if (column.sortable) {
Expand Down
2 changes: 1 addition & 1 deletion src/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, memo } from 'react';
import { useCallback, memo } from 'react';

import HeaderCell from './HeaderCell';
import type { CalculatedColumn } from './types';
Expand Down
2 changes: 1 addition & 1 deletion src/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, forwardRef } from 'react';
import { memo, forwardRef } from 'react';
import clsx from 'clsx';

import Cell from './Cell';
Expand Down
2 changes: 1 addition & 1 deletion src/SummaryCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo } from 'react';
import { memo } from 'react';
import clsx from 'clsx';

import type { CellRendererProps } from './types';
Expand Down
3 changes: 1 addition & 2 deletions src/SummaryRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { memo } from 'react';

import { memo } from 'react';
import SummaryCell from './SummaryCell';
import type { RowRendererProps } from './types';

Expand Down
1 change: 0 additions & 1 deletion src/editors/EditorContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { createPortal } from 'react-dom';

import type { EditorProps } from '../types';
Expand Down
5 changes: 2 additions & 3 deletions src/editors/TextEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React from 'react';
import type { EditorProps } from '../types';

function autoFocusAndSelect(input: HTMLInputElement | null) {
input?.focus();
input?.select();
}

export default function TextEditor<TRow>({
export default function TextEditor<TRow, TSummaryRow = unknown>({
row,
column,
onRowChange,
onClose
}: EditorProps<TRow>) {
}: EditorProps<TRow, TSummaryRow>) {
return (
<input
className="rdg-text-editor"
Expand Down
1 change: 0 additions & 1 deletion src/formatters/SelectCellFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import clsx from 'clsx';

import { useFocusRef } from '../hooks/useFocusRef';
Expand Down
1 change: 0 additions & 1 deletion src/formatters/ToggleGroupFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import type { GroupFormatterProps } from '../types';
import { useFocusRef } from '../hooks/useFocusRef';

Expand Down
1 change: 0 additions & 1 deletion src/formatters/ValueFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import type { FormatterProps } from '../types';

export function ValueFormatter<R, SR>(props: FormatterProps<R, SR>) {
Expand Down
1 change: 0 additions & 1 deletion src/headerCells/SortableHeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import type { HeaderCellProps } from '../HeaderCell';
import type { SortDirection } from '../enums';

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useViewportRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function useViewportRows<R>({
// TODO: should users have control over the generated key?
const id = parentId !== undefined ? `${parentId}__${groupKey}` : groupKey;
const isExpanded = expandedGroupIds?.has(id) ?? false;
const { childRows, childGroups, startRowIndex } = (rows as GroupByDictionary<R>)[groupKey]; // https://github.com/microsoft/TypeScript/issues/17002
const { childRows, childGroups, startRowIndex } = (rows as GroupByDictionary<R>)[groupKey]; // TODO (ts4.1): https://github.com/microsoft/TypeScript/issues/17002

const groupRow: GroupRow<R> = {
id,
Expand Down
2 changes: 1 addition & 1 deletion stories/demos/AllFeatures.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import faker from 'faker';
import React, { useState, useRef } from 'react';
import { useState, useRef } from 'react';
import DataGrid, { SelectColumn, TextEditor } from '../../src';
import type { Column, DataGridHandle, FillEvent, PasteEvent } from '../../src';
import DropDownEditor from './components/Editors/DropDownEditor';
Expand Down
2 changes: 1 addition & 1 deletion stories/demos/CellActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import { useState } from 'react';
import faker from 'faker';

import DataGrid from '../../src';
Expand Down
2 changes: 1 addition & 1 deletion stories/demos/CellNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import { useState } from 'react';

import DataGrid from '../../src';
import type { Column, CellNavigationMode } from '../../src';
Expand Down
2 changes: 1 addition & 1 deletion stories/demos/ColumnsReordering.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback, useMemo } from 'react';
import { useState, useCallback, useMemo } from 'react';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

Expand Down
2 changes: 1 addition & 1 deletion stories/demos/CommonFeatures.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback, useMemo } from 'react';
import { useState, useCallback, useMemo } from 'react';
import faker from 'faker';
import DataGrid, { SelectColumn, TextEditor, SelectCellFormatter } from '../../src';
import type { Column, SortDirection } from '../../src';
Expand Down
2 changes: 1 addition & 1 deletion stories/demos/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useReducer } from 'react';
import { useState, useReducer } from 'react';
import { createPortal } from 'react-dom';
import faker from 'faker';
import { ContextMenu, MenuItem, SubMenu, ContextMenuTrigger } from 'react-contextmenu';
Expand Down
2 changes: 1 addition & 1 deletion stories/demos/Grouping.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useMemo } from 'react';
import { useState, useMemo } from 'react';
import { groupBy as rowGrouper } from 'lodash';
import Select, { components } from 'react-select';
import type { ValueType, OptionsType, Props as SelectProps } from 'react-select';
Expand Down
2 changes: 1 addition & 1 deletion stories/demos/HeaderFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState } from 'react';
import { useMemo, useState } from 'react';
import Select from 'react-select';
import faker from 'faker';

Expand Down
2 changes: 1 addition & 1 deletion stories/demos/MillionCells.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import { useMemo } from 'react';
import DataGrid from '../../src';
import type { Column, FormatterProps } from '../../src';

Expand Down
1 change: 0 additions & 1 deletion stories/demos/NoRows.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import DataGrid from '../../src';
import type { Column } from '../../src';

Expand Down
1 change: 0 additions & 1 deletion stories/demos/Resizable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import DataGrid from '../../src';
import type { Column, FormatterProps } from '../../src';

Expand Down
2 changes: 1 addition & 1 deletion stories/demos/RowsReordering.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import { useState } from 'react';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

Expand Down
2 changes: 1 addition & 1 deletion stories/demos/ScrollToRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react';
import { useState, useRef } from 'react';
import DataGrid from '../../src';
import type { Column, DataGridHandle } from '../../src';

Expand Down
2 changes: 1 addition & 1 deletion stories/demos/TreeView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useReducer, useMemo } from 'react';
import { useState, useReducer, useMemo } from 'react';

import DataGrid from '../../src';
import type { Column } from '../../src';
Expand Down
1 change: 0 additions & 1 deletion stories/demos/components/Editors/DropDownEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import type { EditorProps } from '../../../../src';
import type { Row } from '../../AllFeatures';

Expand Down
1 change: 0 additions & 1 deletion stories/demos/components/Editors/SelectEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import Select from 'react-select';
import type { OptionTypeBase, OptionsType } from 'react-select';

Expand Down
1 change: 0 additions & 1 deletion stories/demos/components/Filters/NumericFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import type { Column, FilterRendererProps } from '../../../../src';

enum RuleType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import { useState } from 'react';
import type { ReactNode } from 'react';
import clsx from 'clsx';
import { usePopper } from 'react-popper';
Expand Down
2 changes: 0 additions & 2 deletions stories/demos/components/Formatters/CellExpanderFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import { useFocusRef } from '../../../../src/hooks';
import './CellExpanderFormatter.less';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { useFocusRef } from '../../../../src/hooks';

export interface ChildRowDeleteButtonProps {
Expand Down
1 change: 0 additions & 1 deletion stories/demos/components/Formatters/ImageFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import './rdg-image.less';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { useDrag, useDrop } from 'react-dnd';
import type { DragObjectWithType } from 'react-dnd';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { useDrag, useDrop } from 'react-dnd';
import type { DragObjectWithType } from 'react-dnd';
import clsx from 'clsx';
Expand Down
1 change: 0 additions & 1 deletion test/column/formatter.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import type { Column } from '../../src';
import { setup, getCells } from '../utils';

Expand Down
2 changes: 1 addition & 1 deletion test/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { StrictMode } from 'react';
import { StrictMode } from 'react';
import { render, screen } from '@testing-library/react';
import DataGrid from '../src/';
import type { DataGridProps } from '../src/';
Expand Down