-
Notifications
You must be signed in to change notification settings - Fork 310
/
index.d.ts
125 lines (113 loc) · 3.39 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import * as React from 'react'
/**
* Photos array item properties (passed into Gallery's photos property)
*/
export type PhotoProps<CustomPhotoProps extends object = {}> = {
/**
* the img src attribute value of the image
*/
src: string
/**
* srcSet attribute of the image
*/
srcSet?: string | string[]
/**
* sizes attribute of the image
*/
sizes?: string | string[]
/**
* original width of the gallery image (only used for calculating aspect ratio)
*/
width: number
/**
* original height of the gallery image (only used for calculating aspect ratio)
*/
height: number
/**
* alt text of the gallery image
*/
alt?: string
/**
* key to be used on component
*/
key?: string
} & CustomPhotoProps
export type renderImageClickHandler = (
event: React.MouseEvent,
photo: object & {
index: number
},
) => void
/**
* If you're passing a function component to renderImage you will receive back these props:
*/
export interface RenderImageProps<CustomPhotoProps extends object = {}> {
/**
* margin prop optionally passed into Gallery by user
*/
margin?: string
/**
* the index of the photo within the Gallery
*/
index: number
/**
* the individual object passed into Gallery's
* photos array prop, with all the same props except recalculated height and width
*/
photo: PhotoProps<CustomPhotoProps>
onClick: renderImageClickHandler | null
direction: 'row' | 'column'
top?: number
left?: number
}
export type PhotoClickHandler<CustomPhotoProps extends object = {}> = (
event: React.MouseEvent,
photos: {
index: number
next: PhotoProps<CustomPhotoProps> | null
photo: PhotoProps<CustomPhotoProps>
previous: PhotoProps<CustomPhotoProps> | null
},
) => void
export interface GalleryProps<CustomPhotoProps extends object = {}> {
photos: Array<PhotoProps<CustomPhotoProps>>
/**
* applies to column layouts only (direction=column)
* number of columns or a function which receives the container width
* and should return the desired number of columns; defaults to Gallery's breakpoint choosing
*/
columns?: number | ((containerWidth: number) => number)
/**
* applies to row layouts only (direction=row)
* the ideal height of each row or a function which receives the container width
* and should return the desired ideal height for each row; defaults to 300px
*/
targetRowHeight?: number | ((containerWidth: number) => number)
/**
* applies to row layouts only (direction=row)
* the maximum amount of neighboring nodes to measure per current node visiting
* don't change unless you understand the algorithm, see docs
* defaults to a couple breakpoints
*/
limitNodeSearch?: number | ((containerWidth: number) => number)
/**
* do something when the user clicks a photo;
* receives arguments event and an object containing the index,
* photo obj originally sent and the next and previous photos in the gallery if they exist
*/
onClick?: PhotoClickHandler<CustomPhotoProps>
/**
* number of margin pixels around each entire image
*/
margin?: number
/**
* column or row based layout
*/
direction?: string
renderImage?: React.ComponentType<RenderImageProps<CustomPhotoProps>>
}
export type GalleryI<
CustomPhotoProps extends object = {}
> = React.ComponentClass<GalleryProps<CustomPhotoProps>>
declare const Gallery: GalleryI
export default Gallery