From 48d7231956b2283e1ba0cbffffed0993c5499187 Mon Sep 17 00:00:00 2001 From: Sascha Zarhuber Date: Thu, 3 Oct 2019 19:00:08 +0200 Subject: [PATCH] [react-sketchapp] excluded types into own file, added types for render.js (#38816) * feat(react-sketchapp): excluded and enhanced types * fix(react-sketchapp): fixed errors * chore(react-sketchapp): version bump * refactor(react-sketchapp): moved types file to same level as index and render * fix(react-sketchapp): fixed function param --- types/react-sketchapp/index.d.ts | 107 ++------------ types/react-sketchapp/render.d.ts | 8 ++ types/react-sketchapp/types.d.ts | 226 ++++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+), 96 deletions(-) create mode 100644 types/react-sketchapp/render.d.ts create mode 100644 types/react-sketchapp/types.d.ts diff --git a/types/react-sketchapp/index.d.ts b/types/react-sketchapp/index.d.ts index a5ce2abbec..cadcc1cbd4 100644 --- a/types/react-sketchapp/index.d.ts +++ b/types/react-sketchapp/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-sketchapp 0.16 +// Type definitions for react-sketchapp 3.0 // Project: https://github.com/airbnb/react-sketchapp // Definitions by: Rico Kahler // DomiR @@ -7,83 +7,12 @@ // TypeScript Version: 2.8 import * as React from 'react'; +import { Color, ResizeConstraints, SketchContext, SketchShadow } from './types'; declare global { const context: SketchContext; } -// sketch interfaces taken from -// https://github.com/airbnb/react-sketchapp/blob/v0.12.1/src/types.js -export interface SketchPage { - name: () => any; -} -export interface SketchAssetCollection { - colors: () => any[]; - gradients: () => any[]; -} -export interface SketchSharedStyleContainer { - setObjects: (objects: any[]) => void; - addSharedStyleWithName_firstInstance: (name: string, ins: any) => void; -} -export interface SketchDocumentData { - layerStyles: () => void; - layerTextStyles: () => SketchSharedStyleContainer; - layerSymbols: () => void; - assets: () => SketchAssetCollection; -} -export interface SketchDocument { - documentData: () => SketchDocumentData; - pages: () => SketchPage[]; - addBlankPage: () => SketchPage; - currentPage: () => SketchPage; -} -export interface SketchContext { - document: SketchDocument; -} - -/** - * Returns the top-level rendered Sketch object or an array of Sketch objects if you use - * components. - * @param element Top-level React component that defines your Sketch document. - * @param container The element to render into - will be replaced. Should either be a Sketch Group - * or Page Object. - * @return The top-most rendered native Sketch layer. - */ -export function render(element: JSX.Element, container?: any): any; - -/** - * Returns a Sketch JSON object for further consumption - doesn't add to the page. - * @return The top-most Sketch layer as JSON. - */ -export function renderToJSON(element: JSX.Element): any; - -// https://github.com/airbnb/react-sketchapp/blob/v0.12.1/src/types.js#L59 -export type Color = string | number; - -/** - * Additional prop type interfaces - */ -export interface ResizingConstraintPropTypes { - top?: boolean; - right?: boolean; - bottom?: boolean; - left?: boolean; - fixedHeight?: boolean; - fixedWidth?: boolean; -} - -export interface ShadowsPropTypes { - shadowColor?: string | number; - shadowOffset?: { - width?: number; - height?: number; - }; - shadowOpacity?: number; - shadowRadius?: number; - shadowSpread?: number; - shadowInner?: boolean; -} - /** * The [`StyleSheet` api uses numbers as IDs][0] to pull registered styles. The component props * can actually take either a `Style` or a `StyleReference` (where the `StyleReference` is given @@ -132,12 +61,7 @@ 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'; @@ -229,13 +153,7 @@ 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?: React.ReactNode[] | React.ReactNode; source?: ImageSource; @@ -269,8 +187,8 @@ export interface ViewProps { name?: string; children?: React.ReactNode[] | React.ReactNode; style?: Style | StyleReference; - resizingConstraint?: ResizingConstraintPropTypes; - shadows?: ShadowsPropTypes[]; + resizingConstraint?: ResizeConstraints; + shadows?: SketchShadow[]; } /** View primitives */ export class View extends React.Component {} @@ -281,19 +199,13 @@ 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