DefinitelyTyped/types/styled-react-modal/styled-react-modal-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

65 lines
1.9 KiB
TypeScript

import * as React from 'react';
import Modal, { ModalProvider, BaseModalBackground as BackgroundComponent } from 'styled-react-modal';
import styled from 'styled-components';
const background = styled.div`
background: rgba(0,0,0,.3);
`;
// Padding through a custom backgroundComponent
const test1 = (
<ModalProvider backgroundComponent={background}>
<Modal
isOpen={true}
onBackgroundClick={() => console.log('Background click!')}
onEscapeKeydown={() => console.log('Background click!')}
afterOpen={() => console.log('After Open!')}
afterClose={() => console.log('After Close!')}
beforeOpen={() => console.log('Before Open!')}
beforeClose={() => console.log('Before Close!')}
allowScroll={true}
>
Modal Content!
</Modal>
</ModalProvider>
);
// Passing through the default component
const test2 = (
<ModalProvider backgroundComponent={BackgroundComponent}>
<Modal
isOpen={true}
onBackgroundClick={() => console.log('Background click!')}
onEscapeKeydown={() => console.log('Background click!')}
afterOpen={() => console.log('After Open!')}
afterClose={() => console.log('After Close!')}
beforeOpen={() => console.log('Before Open!')}
beforeClose={() => console.log('Before Close!')}
allowScroll={true}
>
Modal Content!
</Modal>
</ModalProvider>
);
// Minimal Setup
const test3 = (
<ModalProvider>
<Modal isOpen={true}>
Modal Content!
</Modal>
</ModalProvider>
);
const StyledModal = Modal.styled`
background: red;
`;
const test4 = (
<ModalProvider>
<StyledModal isOpen={true} onBackgroundClick={() => console.log('Background click!')}>
Modal Content!
</StyledModal>
</ModalProvider>
);