DefinitelyTyped/types/react-window/react-window-tests.tsx
Jessica Franco 5c49d4ddc6 Reimplement styled-components with support for .withComponent, type-safe ref, and as (#30467)
* Add back context; add more helper context types and documentation

* Fix the handling of ref to properly exclude string refs where not supported

* Fix erroneous tests that got caught by the better Ref type

* Augment ComponentProps to support JSX.IntrinsicElements

* Add tests, doc comments for ComponentProps*

* Add self to Definitions by

* Add TODO comment

* Add comments about the "'ref' extends keyof P" checks

* Fix the handling of ref and props when using withComponent in styled-components

* Swap nesting order of mapped types to fix missing $ExpectErrors

* Comment out test that fails in TS@3.0

* Hack to deal with the tests not failing when they should

* Rewrite styled-components

* Bump version

* Bump minimum TypeScript version

* Update types of @rebass/grid (depends on styled-components)

* Update styled-react-modal types to 1.1 (also styled-components related)

* Reformat styled-components's index.d.ts
2018-11-13 16:57:37 +00:00

200 lines
5.4 KiB
TypeScript

import {
FixedSizeList,
VariableSizeList,
FixedSizeGrid,
VariableSizeGrid
} from "react-window";
import * as React from "react";
const FixedSizeListTestRequiredProps: React.SFC = () => (
<FixedSizeList itemSize={0} height={0} itemCount={0} width={0}>
{({ style, index }) => <div style={style}>Test {index}</div>}
</FixedSizeList>
);
const VariableSizeListTestRequiredProps: React.SFC = () => (
<VariableSizeList itemSize={index => 0} height={0} itemCount={0} width={0}>
{({ style, index }) => <div style={style}>Test {index}</div>}
</VariableSizeList>
);
const FixedSizeGridTestRequiredProps: React.SFC = () => (
<FixedSizeGrid
columnCount={0}
columnWidth={0}
rowCount={0}
rowHeight={0}
height={0}
width={0}
>
{({ style, columnIndex, rowIndex }) => (
<div style={style}>
Test {rowIndex} {columnIndex}
</div>
)}
</FixedSizeGrid>
);
const VariableSizeGridTestRequiredProps: React.SFC = () => (
<VariableSizeGrid
columnCount={0}
columnWidth={index => 0}
rowCount={0}
rowHeight={index => 0}
height={0}
width={0}
>
{({ style, columnIndex, rowIndex }) => (
<div style={style}>
Test {rowIndex} {columnIndex}
</div>
)}
</VariableSizeGrid>
);
const anyRef: React.Ref<any> = React.createRef();
const FixedSizeListTestOptionalProps: React.SFC<{ testBool: boolean }> = ({
testBool
}) => (
<FixedSizeList
itemSize={0}
height={0}
itemCount={0}
width={0}
className=""
direction={testBool ? "vertical" : "horizontal"}
initialScrollOffset={0}
innerRef={anyRef}
innerTagName="div"
itemData={{ foo: "bar" }}
itemKey={index => "foo" + index.toString()}
onItemsRendered={({
overscanStartIndex,
overscanStopIndex,
visibleStartIndex,
visibleStopIndex
}) =>
overscanStartIndex +
overscanStopIndex +
visibleStartIndex +
visibleStopIndex
}
useIsScrolling={true}
outerTagName="div"
style={{ color: "cyan" }}
overscanCount={0}
outerRef={anyRef}
ref="ref"
onScroll={({
scrollDirection,
scrollOffset,
scrollUpdateWasRequested
}) =>
scrollDirection === "forward"
? scrollUpdateWasRequested
: scrollOffset
}
>
{({ style, index }) => <div style={style}>Test {index}</div>}
</FixedSizeList>
);
const VariableSizeListTestOptionalProps: React.SFC<{ testBool: boolean }> = ({
testBool
}) => (
<VariableSizeList
itemSize={() => 0}
height={0}
itemCount={0}
width={0}
className=""
direction={testBool ? "vertical" : "horizontal"}
initialScrollOffset={0}
innerRef={anyRef}
innerTagName="div"
itemData={{ foo: "bar" }}
itemKey={index => "foo" + index.toString()}
onItemsRendered={({
overscanStartIndex,
overscanStopIndex,
visibleStartIndex,
visibleStopIndex
}) =>
overscanStartIndex +
overscanStopIndex +
visibleStartIndex +
visibleStopIndex
}
useIsScrolling={true}
outerTagName="div"
style={{ color: "cyan" }}
overscanCount={0}
outerRef={anyRef}
ref="ref"
onScroll={({
scrollDirection,
scrollOffset,
scrollUpdateWasRequested
}) =>
scrollDirection === "forward"
? scrollUpdateWasRequested
: scrollOffset
}
estimatedItemSize={0}
>
{({ style, index }) => <div style={style}>Test {index}</div>}
</VariableSizeList>
);
const VariableSizeGridTestOptionalProps: React.SFC = () => (
<VariableSizeGrid
columnCount={0}
columnWidth={index => 0}
rowCount={0}
rowHeight={index => 0}
height={0}
width={0}
className=""
estimatedColumnWidth={0}
estimatedRowHeight={0}
initialScrollLeft={0}
initialScrollTop={0}
innerRef={anyRef}
innerTagName="div"
itemData={{ foo: "bar" }}
itemKey={({ columnIndex, rowIndex }) =>
columnIndex.toString() + rowIndex.toString()
}
onItemsRendered={({
overscanColumnStartIndex,
overscanColumnStopIndex,
overscanRowStartIndex,
overscanRowStopIndex,
visibleColumnStartIndex,
visibleColumnStopIndex,
visibleRowStartIndex,
visibleRowStopIndex
}) => undefined}
onScroll={({
horizontalScrollDirection,
scrollLeft,
scrollTop,
scrollUpdateWasRequested,
verticalScrollDirection
}) => undefined}
outerRef={anyRef}
outerTagName="div"
overscanCount={5}
ref="ref"
style={{ color: "red" }}
useIsScrolling={true}
>
{({ style, columnIndex, rowIndex }) => (
<div style={style}>
Test {rowIndex} {columnIndex}
</div>
)}
</VariableSizeGrid>
);