Skip to content

Commit cf5b00a

Browse files
authored
Merge pull request #696 from LekoArts/ts-match-media
@theme-ui/match-media : TypeScript conversion
2 parents e5e68cd + f1c738b commit cf5b00a

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

packages/css/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ export type ColorMode = {
511511
}
512512

513513
export interface Theme {
514-
breakpoints?: ObjectOrArray<number | string | symbol>
514+
breakpoints?: Array<string>
515515
mediaQueries?: { [size: string]: string }
516516
space?: ObjectOrArray<CSS.MarginProperty<number | string>>
517517
fontSizes?: ObjectOrArray<CSS.FontSizeProperty<number>>

packages/match-media/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22
"name": "@theme-ui/match-media",
33
"version": "0.3.1",
44
"description": "React hooks for theme-ui breakpoints",
5+
"source": "src/index.ts",
56
"main": "dist/index.js",
67
"module": "dist/index.esm.js",
8+
"types": "dist/index.d.ts",
79
"author": "Brent Jackson <[email protected]>",
810
"license": "MIT",
911
"repository": "system-ui/theme-ui",
1012
"scripts": {
11-
"prepare": "microbundle --no-compress",
12-
"watch": "microbundle watch --no-compress"
13+
"prepare": "microbundle --no-compress --tsconfig tsconfig.json",
14+
"watch": "microbundle watch --no-compress --tsconfig tsconfig.json"
1315
},
1416
"publishConfig": {
1517
"access": "public"
1618
},
1719
"devDependencies": {
1820
"react": "^16.9.0",
19-
"theme-ui": "^0.3.1"
21+
"@theme-ui/core": "^0.3.1",
22+
"@theme-ui/css": "^0.3.1"
2023
},
2124
"peerDependencies": {
2225
"react": "^16.9.0",

packages/match-media/src/index.js renamed to packages/match-media/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { useState, useEffect, useCallback } from 'react'
2-
import { useThemeUI } from 'theme-ui'
2+
import { useThemeUI } from '@theme-ui/core'
3+
import { Theme } from '@theme-ui/css'
34

45
// Shared with @theme-ui/css
56
const defaultBreakpoints = [40, 52, 64].map(n => n + 'em')
67

7-
export const useBreakpointIndex = (options = {}) => {
8+
type defaultOptions = {
9+
defaultIndex?: number
10+
}
11+
12+
export const useBreakpointIndex = (options: defaultOptions = {}) => {
813
const context = useThemeUI()
914
const { defaultIndex = 0 } = options
1015
const breakpoints =
@@ -47,7 +52,9 @@ export const useBreakpointIndex = (options = {}) => {
4752
return value
4853
}
4954

50-
export const useResponsiveValue = (values, options) => {
55+
type Values = ((theme: Theme | null) => string[]) | string[]
56+
57+
export const useResponsiveValue = (values: Values, options: defaultOptions = {}) => {
5158
const { theme } = useThemeUI()
5259
const array = typeof values === 'function' ? values(theme) : values
5360
const index = useBreakpointIndex(options)

packages/match-media/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"resolveJsonModule": true,
4+
"esModuleInterop": true,
5+
"moduleResolution": "node",
6+
"strict": true
7+
}
8+
}

0 commit comments

Comments
 (0)