Skip to content

Commit

Permalink
Add types to exported utility functions (#820)
Browse files Browse the repository at this point in the history
* Types for exported utility functions

* Add script to format types project
  • Loading branch information
craigpalermo authored May 29, 2020
1 parent 7ea856b commit 6a8f8f2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 16 deletions.
6 changes: 4 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"directory": "packages/types"
},
"scripts": {
"test": "dtslint types"
"test": "dtslint types",
"format": "prettier --write types"
},
"bugs": {
"url": "https://github.com/priceline/design-system/issues"
Expand All @@ -33,6 +34,7 @@
"@types/styled-system": "^4.2.2"
},
"devDependencies": {
"dtslint": "^3.5.2"
"dtslint": "^3.5.2",
"prettier": "^2.0.5"
}
}
50 changes: 48 additions & 2 deletions packages/types/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ export interface ThemeProviderProps {

export class Absolute extends React.Component<AbsoluteProps, any> {}
export class Avatar extends React.Component<any, any> {}
export class BackgroundImage extends React.Component<BackgroundImageProps, any> {}
export class BackgroundImage extends React.Component<
BackgroundImageProps,
any
> {}
export class Badge extends React.Component<any, any> {}
export class Banner extends React.Component<any, any> {}
export class BlockLink extends React.Component<LinkProps, any> {}
Expand Down Expand Up @@ -192,7 +195,10 @@ export class Label extends React.Component<any, any> {
static isLabel: boolean
}
export class Link extends React.Component<LinkProps, any> {}
export class PlaceholderImage extends React.Component<PlaceholderImageProps, any> {}
export class PlaceholderImage extends React.Component<
PlaceholderImageProps,
any
> {}
export class Radio extends React.Component<any, any> {}
export class RatingBadge extends React.Component<any, any> {}
export class Relative extends React.Component<RelativeProps, any> {}
Expand Down Expand Up @@ -228,7 +234,47 @@ export interface ThemeArgs {
theme: Theme
}

export interface ColorArgs extends ThemeArgs {
color?: string
bg?: string
}

interface CustomBreakpoints {
[key: string]: string | number
}

interface PaletteColor {
lightest?: string
light?: string
base: string
dark?: string
darkest?: string
}

interface Palette {
[key: string]: PaletteColor
}

interface CreateThemeResult extends Theme {
contrastRatio: number
breakpoints: any[]
mediaQueries: any[]
palette: Palette
}

export function getContrastRatio(colorA: string, colorB: string): number
export function deprecatedPropType(replacement: string): Error | undefined
export function borders(props: ThemeArgs): object
export function hasPaletteColor(props: ThemeArgs): boolean
export function color(props: ColorArgs): string[] | string
export function getPaletteColor(
color: string,
shade?: string
): (props: ThemeArgs) => any
export function getTextColorOn(name: string): (props: ThemeArgs) => any
export function createTheme(
theme: Theme,
customBreakpoints: CustomBreakpoints
): CreateThemeResult

type theme = Theme
39 changes: 27 additions & 12 deletions packages/types/types/test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import {
getContrastRatio,
deprecatedPropType,
Absolute,
BackgroundImage,
BlockLink,
borders,
hasPaletteColor,
Box,
Card,
Text,
Absolute,
color,
createTheme,
deprecatedPropType,
Flex,
Hide,
ThemeProvider,
Link,
BlockLink,
getContrastRatio,
getPaletteColor,
getTextColorOn,
hasPaletteColor,
Heading,
Truncate,
SrOnly,
Hide,
Image,
BackgroundImage,
Link,
PlaceholderImage,
SrOnly,
Text,
theme as ThemeType,
ThemeProvider,
Truncate,
} from 'pcln-types'
import theme from '../../core/src/theme'
import * as React from 'react'
Expand All @@ -37,6 +42,16 @@ borders({

hasPaletteColor({ theme }) // $ExpectType boolean

color({ theme, bg: 'primary', color: 'secondary' }) // $ExpectType string | string[]

getPaletteColor('primary', 'light') // $ExpectType (props: ThemeArgs) => any

getTextColorOn('bla') // $ExpectType (props: ThemeArgs) => any

createTheme(theme, {}) // $ExpectType CreateThemeResult

const myTheme: ThemeType = theme

//
// Design System Core Components
// =============================================================================================
Expand Down

0 comments on commit 6a8f8f2

Please sign in to comment.