From aff3a0476b64a29b6dd156bcbe07131c1ff76e59 Mon Sep 17 00:00:00 2001 From: Tomas Carnecky Date: Thu, 1 Feb 2018 18:05:59 +0100 Subject: [PATCH] Type definitions for catalog (2.x) (#23276) * Type definitions for catalog * Add catalog tests * catalog: add responsiveSizes to Config * catalog: remove empty rules block from tslint.json * catalog: add responsive prop to ReactSpecimen --- types/catalog/catalog-tests.tsx | 42 +++++++++++++ types/catalog/index.d.ts | 108 ++++++++++++++++++++++++++++++++ types/catalog/tsconfig.json | 25 ++++++++ types/catalog/tslint.json | 3 + 4 files changed, 178 insertions(+) create mode 100644 types/catalog/catalog-tests.tsx create mode 100644 types/catalog/index.d.ts create mode 100644 types/catalog/tsconfig.json create mode 100644 types/catalog/tslint.json diff --git a/types/catalog/catalog-tests.tsx b/types/catalog/catalog-tests.tsx new file mode 100644 index 0000000000..c77c0c1667 --- /dev/null +++ b/types/catalog/catalog-tests.tsx @@ -0,0 +1,42 @@ +import * as React from "react"; +import { Config, render, markdown, Catalog, ReactSpecimen, Page } from "catalog"; + +const config: Config = { + title: 'Test', + pages: [ + { + path: '/', + title: 'Introduction', + content: '/patd/to/file.md', + }, + { + path: '/materials', + title: 'Materials', + pages: [ + { + path: '/materials/typeface', + title: 'Typeface', + component: , + }, + ], + }, + ], + useBrowserHistory: true, + basePath: '/doc', + responsiveSizes: [ + { name: 'large', width: 978, height: 1100 }, + { name: 'medium', width: 640, height: 900 }, + { name: 'small', width: 471, height: 700 }, + ], +}; + +render(config, document.body); +; + +markdown` +# Test + +${ +
+} +`; diff --git a/types/catalog/index.d.ts b/types/catalog/index.d.ts new file mode 100644 index 0000000000..515008d7de --- /dev/null +++ b/types/catalog/index.d.ts @@ -0,0 +1,108 @@ +// Type definitions for catalog 2.1 +// Project: https://github.com/interactivethings/catalog/ +// Definitions by: Peter Gassner , Tomas Carnecky +// Definitions: https://github.com/interactivethings/catalog/ +// TypeScript Version: 2.3 + +import * as React from "react"; + +// Configuration + +// XXX: Can not name this 'Page' because there's already a 'Page' +// component here. +export interface ConfigPage { + path: string; + title: string; + + content?: any; + component?: any; + pages?: ConfigPage[]; +} + +export interface ConfigResponsiveSize { + name: string; + width: number; + height: number; +} + +export interface Config { + title: string; + pages: ConfigPage[]; + + useBrowserHistory?: boolean; + basePath?: string; + responsiveSizes?: ConfigResponsiveSize[]; +} + +export function render(config: Config, element: HTMLElement): void; +export function configure(config: any): any; +export function configureRoutes(config: any): any; +export function configureJSXRoutes(config: any): any; + +export function pageLoader(f: () => Promise): any; +export function markdown(...x: any[]): JSX.Element; + +// Components +export interface DefaultCatalogProps extends React.Props<{}> { + span?: number; + theme?: any; +} + +export class Card extends React.Component {} +export class Page extends React.Component {} +export interface SpanProps extends DefaultCatalogProps { + style?: any; +} +export class Span extends React.Component {} + +// Specimens +export class AudioSpecimen extends React.Component {} + +export interface CodeSpecimenProps extends DefaultCatalogProps { + rawBody: string; + collapsed: boolean; + lang: string; + raw: boolean; +} +export class CodeSpecimen extends React.Component {} + +export interface ColorSpecimenProps extends DefaultCatalogProps { + value: string; + name: string; +} +export class ColorSpecimen extends React.Component {} + +export interface ColorPaletteSpecimenProps extends DefaultCatalogProps { + colors: Array<{name?: string, value: string}>; + horizontal?: boolean; +} +export class ColorPaletteSpecimen extends React.Component {} + +export class HtmlSpecimen extends React.Component {} +export class HintSpecimen extends React.Component {} +export class ImageSpecimen extends React.Component {} + +export interface TypeSpecimenProps extends DefaultCatalogProps { + color?: string; + font: string; + headings: string[] | number[]; + style?: string; + weight: string; +} +export class TypeSpecimen extends React.Component {} +export class DownloadSpecimen extends React.Component {} + +export interface ReactSpecimenProps extends DefaultCatalogProps { + noSource?: boolean; + plain?: boolean; + light?: boolean; + dark?: boolean; + frame?: boolean; + state?: any; + responsive?: boolean | string | string[]; +} +export class ReactSpecimen extends React.Component {} + +export class VideoSpecimen extends React.Component {} + +export class Catalog extends React.Component {} diff --git a/types/catalog/tsconfig.json b/types/catalog/tsconfig.json new file mode 100644 index 0000000000..95f43ccaf0 --- /dev/null +++ b/types/catalog/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "catalog-tests.tsx" + ] +} diff --git a/types/catalog/tslint.json b/types/catalog/tslint.json new file mode 100644 index 0000000000..b4b47a0378 --- /dev/null +++ b/types/catalog/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}