Skip to content

Commit

Permalink
feat: add types to app
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Jan 24, 2022
1 parent 42f5647 commit 0af0a25
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/app/src/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import invariant from "invariant";
import { plugins } from "@webiny/plugins";
import { get } from "lodash";
import { ImageComponentPlugin, ImageProps } from "../types";
import { ImageComponentPlugin, ImageProps } from "~/types";

export const Image: React.FC<ImageProps> = ({ preset: presetName, ...props }) => {
const plugin = plugins.byName<ImageComponentPlugin>("image-component");
Expand Down
27 changes: 22 additions & 5 deletions packages/app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import { Plugin } from "@webiny/plugins/types";
import { ApolloClient } from "apollo-client";
import { CSSProperties } from "react";

export interface FileItem {
id: string;
name: string;
key: string;
src: string;
size: number;
type: string;
tags: string[];
createdOn: string;
createdBy: {
id: string;
};
[key: string]: any;
}

export type WebinyInitPlugin = Plugin & {
type: "webiny-init";
init(): void;
Expand All @@ -20,28 +35,30 @@ export type UiStatePlugin = Plugin & {
export type FileUploaderPlugin = Plugin & {
type: "file-uploader";
// TODO: @adrian define type for the returned object
upload(file: File, options: UploadOptions): Promise<any>;
upload(file: FileItem, options: UploadOptions): Promise<any>;
};

export type AppFileManagerStoragePlugin = Plugin & {
type: "app-file-manager-storage";
// TODO: @adrian define type for the returned object
upload(file: File, options: UploadOptions): Promise<any>;
upload(file: FileItem, options: UploadOptions): Promise<any>;
};

export { Plugin };

export type ImageProps = {
export interface ImageProps {
src: string;
preset?: string;
transform?: { [key: string]: any };
transform?: {
[key: string]: any;
};
// "auto" is a special keyword - if present, plugins insert their own srcSet.
srcSet?: { [key: string]: any } | "auto";
className?: string;
title?: string;
alt?: string;
style?: CSSProperties;
};
}

/**
* "getImageSrc" has to be defined as a separate property, so its functionality can be reused outside of
Expand Down
18 changes: 16 additions & 2 deletions typings/react-butterfiles/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
interface FileItem {
id: string;
name: string;
key: string;
src: string;
size: number;
type: string;
tags: string[];
createdOn: string;
createdBy: {
id: string;
};
[key: string]: any;
}
declare module "react-butterfiles" {
export type SelectedFile = {
id: string;
name: string;
type: string;
size: number;
src: {
file?: File;
file?: FileItem;
base64?: string;
};
};
Expand All @@ -27,7 +41,7 @@ declare module "react-butterfiles" {
};

export type FilesRenderChildren = {
browseFiles: (params: BrowseFilesParams) => void;
browseFiles: (params?: BrowseFilesParams) => void;
getDropZoneProps: (additionalProps?: Object) => Object;
getLabelProps(additionalProps?: Object): Object;
validateFiles(files: Array<SelectedFile> | Array<File>): Array<FileError>;
Expand Down
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7331,6 +7331,13 @@ __metadata:
languageName: node
linkType: hard

"@types/bytes@npm:^3.1.1":
version: 3.1.1
resolution: "@types/bytes@npm:3.1.1"
checksum: 29c543019d810fbb4465662cd5eec4dc0fd1e1d5466abe256edf75e47575721b398df82676d550e29be02de55c487f7fb4d870d4262b22e33433d5bab2077fa2
languageName: node
linkType: hard

"@types/cacheable-request@npm:^6.0.1":
version: 6.0.2
resolution: "@types/cacheable-request@npm:6.0.2"
Expand Down Expand Up @@ -7405,6 +7412,13 @@ __metadata:
languageName: node
linkType: hard

"@types/graphlib@npm:^2.1.8":
version: 2.1.8
resolution: "@types/graphlib@npm:2.1.8"
checksum: ca0285c30e76626c7d63942057e21d45a6c85a4f1b7add5ed892b6a02bad12ce3c7e927c7d56fbb7daf3ff286eae2dcc8e0f475a6c6104b99ae49b888d2fa883
languageName: node
linkType: hard

"@types/highlight.js@npm:^9.12.0":
version: 9.12.4
resolution: "@types/highlight.js@npm:9.12.4"
Expand Down Expand Up @@ -7960,6 +7974,13 @@ __metadata:
languageName: node
linkType: hard

"@types/store@npm:^2.0.2":
version: 2.0.2
resolution: "@types/store@npm:2.0.2"
checksum: aa548e117f9a1e2b1ff0263f3261ad7066b885ed32c05019832e4cbf91bf09f5f5891cccfb4e001a6cdc87d306b1d6376b20bdf8976dfced38b18db3c9c6fef3
languageName: node
linkType: hard

"@types/tapable@npm:^1, @types/tapable@npm:^1.0.5":
version: 1.0.8
resolution: "@types/tapable@npm:1.0.8"
Expand Down Expand Up @@ -9981,8 +10002,11 @@ __metadata:
"@emotion/core": ^10.0.17
"@emotion/styled": ^10.0.17
"@svgr/webpack": ^6.1.1
"@types/bytes": ^3.1.1
"@types/graphlib": ^2.1.8
"@types/mime": ^2.0.3
"@types/react": ^16.14.0
"@types/store": ^2.0.2
"@webiny/app": ^5.21.0
"@webiny/app-admin-core": ^5.21.0
"@webiny/app-security": ^5.21.0
Expand Down

0 comments on commit 0af0a25

Please sign in to comment.