Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript definitions #16

Merged
merged 5 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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