Skip to content

Instantly share code, notes, and snippets.

@bguthrie
Last active May 21, 2021 15:30
Show Gist options
  • Save bguthrie/27b7745b579c09f7daca42e54a6a9021 to your computer and use it in GitHub Desktop.
Save bguthrie/27b7745b579c09f7daca42e54a6a9021 to your computer and use it in GitHub Desktop.
TS typings for imagekit-react
import React, { PureComponent, MutableRefObject } from "react"
declare module "imagekitio-react" {
export interface Transformation {
width?: number
height?: number
rotation?: number
format?: "auto" | "jpg" | "jpeg" | "webp" | "avif" | "png"
progressive?: boolean
aspectRatio?: number
quality?: number
crop?: "force" | "at_max" | "at_least" | "maintain_ratio"
cropMode?: "pad_resize" | "extract" | "pad_extract"
x?: number
y?: number
focus?: "auto" | "face"
radius?: "max" | number
background?: string
border?: string
blur?: number
named?: string
progressive?: boolean
lossless?: boolean
trim?: true | number
metadata?: boolean
colorProfile?: boolean
defaultImage?: string
dpr?: "auto" | number
effectUSM?: string // more complicated than this
effectSharpen?: "-" | number
effectContrast?: number
effectGray?: boolean
// overlayX ox
// overlayY oy
// overlayFocus ofo
// overlayHeight oh
// overlayWidth ow
// overlayImage oi
// overlayImageTrim oit
// overlayImageAspectRatio oiar
// overlayImageBackground oibg
// overlayImageBorder oib
// overlayImageDPR oidpr
// overlayImageQuality oiq
// overlayImageCropping oic
// overlayImageTrim oit
// overlayText ot
// overlayTextFontSize ots
// overlayTextFontFamily otf
// overlayTextColor otc
// overlayTextTransparency oa
// overlayAlpha oa
// overlayTextTypography ott
// overlayBackground obg
// overlayTextEncoded ote
// overlayTextWidth otw
// overlayTextBackground otbg
// overlayTextPadding otp
// overlayTextInnerAlignment otia
// overlayRadius or
}
export interface IKContextClient {
ikClient?: ImageKit
}
export interface IKContextProps {
publicKey?: string
urlEndpoint?: string
authenticationEndpoint?: string
}
export interface IKImageProps {
loading?: "lazy"
lqip?: {}
path?: string
src?: string
alt?: string
queryParameters?: Record<string, string>
transformation?: Array<Transformation>
transformationPosition?: "path" | "query"
}
export interface IKUploadProps {
fileName?: string
tags?: string[]
useUniqueFileName?: boolean
responseFields?: string[] // maybe?
isPrivateFile?: boolean
folder?: string
customCoordinates?: string
onError?: (err: unknown) => void
onSuccess?: (image: Image) => void // maybe?
}
export interface Image {
fileId: string
filePath: string
name: string
url: string
thumbnailUrl: string
fileType: "image" // or else what?
height: number
width: number
size: number
}
export type ImageKitContextProps = IKContextClient & IKContextProps & IKImageProps & IKUploadProps
export type ImageKitContextType = React.Context<IKContextOptions>
export class ImageKitComponent<P = {}, S = {}> extends PureComponent<P, S> {
getContext(): ImageKitContextType
getIKClient(): ImageKit
getVersion(): number
}
export class IKContext extends ImageKitComponent<ImageKitContextProps> {}
export class IKImage extends ImageKitComponent<Partial<IKImageProps>> {}
export class IKUpload extends ImageKitComponent<Partial<IKUploadProps>> {
imageRef: MutableRefObject<HTMLImageElement>
}
}
Copyright 2021 BRIAN GUTHRIE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment