Skip to content

Commit

Permalink
Merge pull request #16 from franky47/feature/typescript-definitions
Browse files Browse the repository at this point in the history
Add TypeScript definitions
  • Loading branch information
morajabi committed Apr 17, 2019
2 parents c5ede50 + d29dfbd commit 687a208
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/styled-media-query.common.js",
"module": "dist/styled-media-query.es.js",
"jsnext:main": "dist/styled-media-query.es.js",
"types": "./src/index.d.ts",
"repository": "[email protected]:morajabi/styled-media-query.git",
"keywords": [
"styled-components",
Expand Down
66 changes: 66 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Type definitions for styled-media-query 2.1.1
// Project: https://github.com/morajabi/styled-media-query
// Definitions by: François Best <https://github.com/franky47>
// Requires @types/styled-components definitions ^4.1
// TypeScript version: 3.3.3

import {
ThemedStyledProps,
InterpolationValue,
FlattenInterpolation
} from 'styled-components'

type InterpolationFunction<Props, Theme> = (
props: ThemedStyledProps<Props, Theme>
) => InterpolationValue | FlattenInterpolation<ThemedStyledProps<Props, Theme>>

type GeneratorFunction<Props, Theme> = (
strings: TemplateStringsArray,
...interpolations: (
| InterpolationValue
| InterpolationFunction<Props, Theme>
| FlattenInterpolation<ThemedStyledProps<Props, Theme>>)[]
) => any

// --

export interface MediaGenerator<Breakpoints, Theme> {
lessThan: <Props>(
breakpoint: keyof Breakpoints
) => GeneratorFunction<Props, Theme>
greaterThan: <Props>(
breakpoint: keyof Breakpoints
) => GeneratorFunction<Props, Theme>
between: <Props>(
fist: keyof Breakpoints,
second: keyof Breakpoints
) => GeneratorFunction<Props, Theme>
}

// --

export interface DefaultBreakpoints {
huge: string
large: string
medium: string
small: string
}

export const defaultBreakpoints: DefaultBreakpoints

// --

export function generateMedia<Breakpoints = DefaultBreakpoints, Theme = any>(
breakpoints?: Breakpoints
): MediaGenerator<Breakpoints, Theme>

// --

declare const media: MediaGenerator<DefaultBreakpoints, any>

export default media

// Convertors --

export function pxToEm<B>(breakpoints: B, ratio?: number): B
export function pxToRem<B>(breakpoints: B, ratio?: number): B

0 comments on commit 687a208

Please sign in to comment.