From 929dcd4579421cc2cb11f3085911e694268f8c2b Mon Sep 17 00:00:00 2001 From: Sascha Zarhuber Date: Sun, 18 Nov 2018 19:55:18 +0100 Subject: [PATCH] [react-sketchapp] Add types for Document and Page (#30627) * Add types for Document and Page in react-sketchapp * Updated version number in react-sketchapp --- types/react-sketchapp/index.d.ts | 103 +++++++++++++----- .../react-sketchapp/react-sketchapp-tests.tsx | 54 ++++++--- 2 files changed, 115 insertions(+), 42 deletions(-) diff --git a/types/react-sketchapp/index.d.ts b/types/react-sketchapp/index.d.ts index 6152bd7b07..096a6c6da3 100644 --- a/types/react-sketchapp/index.d.ts +++ b/types/react-sketchapp/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for react-sketchapp 0.12 +// Type definitions for react-sketchapp 0.13 // Project: https://github.com/airbnb/react-sketchapp // Definitions by: Rico Kahler // DomiR +// Sascha Zarhuber // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -13,7 +14,9 @@ declare global { // sketch interfaces taken from // https://github.com/airbnb/react-sketchapp/blob/v0.12.1/src/types.js -export interface SketchPage { name: () => any; } +export interface SketchPage { + name: () => any; +} export interface SketchAssetCollection { colors: () => any[]; gradients: () => any[]; @@ -34,7 +37,9 @@ export interface SketchDocument { addBlankPage: () => SketchPage; currentPage: () => SketchPage; } -export interface SketchContext { document: SketchDocument; } +export interface SketchContext { + document: SketchDocument; +} /** * Returns the top-level rendered Sketch object or an array of Sketch objects if you use @@ -68,7 +73,7 @@ export type StyleReference = number; */ export interface Style { shadowColor?: Color; - shadowOffset?: { width?: number, height?: number }; + shadowOffset?: { width?: number; height?: number }; shadowOpacity?: number; shadowRadius?: number; width?: number; @@ -103,7 +108,12 @@ export interface Style { position?: 'absolute' | 'relative'; flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse'; flexWrap?: 'wrap' | 'nowrap'; - justifyContent?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around'; + justifyContent?: + | 'flex-start' + | 'flex-end' + | 'center' + | 'space-between' + | 'space-around'; alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch'; alignSelf?: 'auto' | 'flex-start' | 'flex-end' | 'center' | 'stretch'; overflow?: 'visible' | 'hidden' | 'scroll'; @@ -140,7 +150,7 @@ export interface TextStyle extends Style { fontStyle?: 'normal' | 'italic'; fontWeight?: string; textDecorationLine?: 'none' | 'underline' | 'double' | 'line-through'; - textShadowOffset?: { width: number, height: number }; + textShadowOffset?: { width: number; height: number }; textShadowRadius?: number; textShadowColor?: Color; letterSpacing?: number; @@ -149,6 +159,33 @@ export interface TextStyle extends Style { writingDirection?: 'auto' | 'ltr' | 'rtl'; } +/** + * DocumentProps, a Document does not take any props but children + */ +export interface DocumentProps { + children?: any; +} + +/** + * Document, a wrapper for a Sketch document, may contain Pages as children + * http://airbnb.io/react-sketchapp/docs/API.html#document + */ +export class Document extends React.Component {} + +/** + * PageProps, a Page takes optionally a name and children as props + */ +export interface PageProps { + name?: string; + children?: any; +} + +/** + * Page, a wrapper for a Sketch page, may contain Artboards as children + * http://airbnb.io/react-sketchapp/docs/API.html#page + */ +export class Page extends React.Component {} + // wanted to type these as classes because they are implemented as classes and typing them this // way gives you typings like `Artboard.prototype` @@ -164,18 +201,24 @@ export interface ArtboardProps { /** * Wrapper for Sketch's Artboards. */ -export class Artboard extends React.Component { } +export class Artboard extends React.Component {} // Image export type ImageSource = string | { src: string }; -export type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center' | 'repeat' | 'none'; +export type ResizeMode = + | 'contain' + | 'cover' + | 'stretch' + | 'center' + | 'repeat' + | 'none'; export interface ImageProps { children?: any; source?: ImageSource; style?: Style | StyleReference; resizeMode: ResizeMode; } -export class Image extends React.Component { } +export class Image extends React.Component {} // RedBox export interface RedBoxProps { @@ -186,7 +229,7 @@ export interface RedBoxProps { * A red box / 'red screen of death' error handler. Thanks to * [commissure/redbox-react.](https://github.com/commissure/redbox-react) */ -export class RedBox extends React.Component { } +export class RedBox extends React.Component {} // Text export interface TextProps { @@ -195,7 +238,7 @@ export interface TextProps { style?: TextStyle | StyleReference; } /** Text primitives */ -export class Text extends React.Component { } +export class Text extends React.Component {} // View export interface ViewProps { @@ -204,7 +247,7 @@ export interface ViewProps { style?: Style | StyleReference; } /** View primitives */ -export class View extends React.Component { } +export class View extends React.Component {} export const StyleSheet: { hairlineWidth: 1; @@ -212,21 +255,25 @@ export const StyleSheet: { /** * Create an optimized `StyleSheet` reference from a style object. */ - create: (t: T) => { - [P in keyof T]: StyleReference - }; + create: ( + t: T + ) => { [P in keyof T]: StyleReference }; /** * Flatten an array of style objects into one aggregated object, or look up the definition for a * registered stylesheet. */ flatten: ( - input: Array