-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
128 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
commonjs/ | ||
coverage/ | ||
umd/ | ||
src/__tests__/typescript/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
import { Component, ComponentType } from 'react' | ||
import { Component, ComponentType, ReactNode } from 'react' | ||
|
||
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>; | ||
type Omit<T, K> = Pick<T, Exclude<keyof T, K>> | ||
|
||
interface SizeMeProps { | ||
size: { | ||
width: number | null; | ||
height: number | null; | ||
}; | ||
width: number | null | ||
height: number | null | ||
} | ||
} | ||
|
||
export interface SizeMeOptions { | ||
monitorWidth?: boolean; | ||
monitorHeight?: boolean; | ||
monitorPosition?: boolean; | ||
refreshRate?: number; | ||
refreshMode?: 'throttle' | 'debounce'; | ||
noPlaceholder?: boolean; | ||
children(props: SizeMeProps): JSX.Element; | ||
monitorWidth?: boolean | ||
monitorHeight?: boolean | ||
monitorPosition?: boolean | ||
refreshRate?: number | ||
refreshMode?: 'throttle' | 'debounce' | ||
noPlaceholder?: boolean | ||
children(props: SizeMeProps): ReactNode | ||
} | ||
|
||
export class SizeMe extends Component<SizeMeOptions> { | ||
} | ||
export class SizeMe extends Component<SizeMeOptions> {} | ||
|
||
export const withSize: (options?: SizeMeOptions) => <P extends SizeMeProps>(component: ComponentType<P>) => ComponentType<Omit<P, 'size'>>; | ||
export const withSize: ( | ||
options?: SizeMeOptions, | ||
) => <P extends SizeMeProps>( | ||
component: ComponentType<P>, | ||
) => ComponentType<Omit<P, 'size'>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { checkDirectory } from 'typings-tester' | ||
|
||
describe('TypeScript definitions', () => { | ||
it('should compile against easy-peasy.d.ts', () => { | ||
checkDirectory(`${__dirname}/typescript`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react' | ||
import { SizeMe } from 'react-sizeme' | ||
|
||
function MyApp() { | ||
return ( | ||
<SizeMe> | ||
{({ size }) => { | ||
const { width, height } = size | ||
if (width) { | ||
const foo = width + 1 | ||
} | ||
if (height) { | ||
const foo = height + 1 | ||
} | ||
// typings:expect-error | ||
const h1 = height + 1 | ||
// typings:expect-error | ||
const w1 = width + 1 | ||
return <div /> | ||
}} | ||
</SizeMe> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react' | ||
import { withSize, SizeMeProps } from 'react-sizeme' | ||
|
||
interface MyComponentProps extends SizeMeProps { | ||
id: number | ||
} | ||
|
||
function MyComponent({ id, size }: MyComponentProps) { | ||
const { width, height } = size | ||
if (width) { | ||
const foo = width + 1 | ||
} | ||
if (height) { | ||
const foo = height + 1 | ||
} | ||
// typings:expect-error | ||
const h1 = height + 1 | ||
// typings:expect-error | ||
const w1 = width + 1 | ||
return <div>My width is {size.width}px</div> | ||
} | ||
|
||
const SizedMyComponent = withSize()(MyComponent) | ||
|
||
const foo = <SizedMyComponent id={1} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["esnext", "dom"], | ||
"jsx": "preserve", | ||
"strict": true, | ||
"baseUrl": "../../..", | ||
"paths": { | ||
"react-sizeme": ["react-sizeme.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters