|
2 | 2 |
|
3 | 3 | import { Component, ComponentType, ReactNode, ReactElement } from 'react' |
4 | 4 |
|
5 | | -declare namespace sizeMe { |
6 | | - type Omit<T, K> = Pick<T, Exclude<keyof T, K>> |
| 5 | +type Omit<T, K> = Pick<T, Exclude<keyof T, K>> |
7 | 6 |
|
| 7 | +declare namespace sizeMe { |
8 | 8 | export interface SizeMeProps { |
9 | | - size: { |
10 | | - width: number | null |
11 | | - height: number | null |
| 9 | + readonly size: { |
| 10 | + readonly width: number | null |
| 11 | + readonly height: number | null |
12 | 12 | } |
13 | 13 | } |
14 | 14 |
|
15 | 15 | export interface SizeMeOptions { |
16 | | - monitorWidth?: boolean |
17 | 16 | monitorHeight?: boolean |
18 | 17 | monitorPosition?: boolean |
19 | | - refreshRate?: number |
20 | | - refreshMode?: 'throttle' | 'debounce' |
| 18 | + monitorWidth?: boolean |
21 | 19 | noPlaceholder?: boolean |
| 20 | + refreshMode?: 'throttle' | 'debounce' |
| 21 | + refreshRate?: number |
22 | 22 | } |
23 | 23 |
|
24 | 24 | export interface SizeMeRenderProps extends SizeMeOptions { |
25 | 25 | children: (props: SizeMeProps) => ReactElement |
26 | 26 | } |
| 27 | + |
27 | 28 | export class SizeMe extends Component<SizeMeRenderProps> {} |
28 | 29 |
|
29 | | - export const withSize: ( |
| 30 | + export type WithSizeOnSizeCallback = (size: SizeMeProps['size']) => void |
| 31 | + |
| 32 | + export interface WithSizeProps { |
| 33 | + onSize?: WithSizeOnSizeCallback |
| 34 | + } |
| 35 | + |
| 36 | + export function withSize( |
30 | 37 | options?: SizeMeOptions, |
31 | | - ) => <P extends object = {}>( |
| 38 | + ): <P extends object = {}>( |
32 | 39 | component: ComponentType<P>, |
33 | | - ) => ComponentType<Omit<P, 'size'>> |
| 40 | + ) => ComponentType<Omit<P, 'size'> & WithSizeProps> |
34 | 41 |
|
35 | 42 | export let noPlaceholders: boolean |
36 | 43 | } |
| 44 | + |
37 | 45 | declare function sizeMe( |
38 | 46 | options?: sizeMe.SizeMeOptions, |
39 | 47 | ): <P extends object = {}>( |
40 | 48 | component: ComponentType<P>, |
41 | | -) => ComponentType<sizeMe.Omit<P, 'size'>> |
| 49 | +) => ComponentType<Omit<P, 'size'> & sizeMe.WithSizeProps> |
42 | 50 |
|
43 | 51 | export = sizeMe |
0 commit comments