Skip to content

Commit

Permalink
feat(typescript): adds typescript declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Feb 8, 2021
1 parent 5818387 commit 802b12f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
64 changes: 64 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Properties as CSSProperties, Pseudos as CSSPsuedos } from 'csstype';
import { KeyframesAddon } from 'nano-css/addon/keyframes'

type Unitless = string | number;
type StringKeyValue = { [name: string]: string }
type UnitlessKeyValue = { [name: string]: Unitless }
type AnyKeyValue = { [name: string]: any }
type CSSPropertyNames = keyof CSSProperties

export interface Tokens {
color?: StringKeyValue | string[];
space?: Unitless[] | UnitlessKeyValue;
width?: UnitlessKeyValue | Unitless[];
zIndex?: Unitless[] | UnitlessKeyValue;
fontSize?: string[] | StringKeyValue;
fontFamily?: StringKeyValue;
fontWeight?: Unitless[] | UnitlessKeyValue;
lineHeight?: Unitless[] | UnitlessKeyValue;
}

export interface Shorthands {
[shorthand: string]: {
properties: CSSPropertyNames[];
token?: keyof Tokens;
unit?: (v: any) => string;
}
}

export interface Macros {
[macro: string]: {
[prop: string]: Unitless;
}
}

export interface UserTheme {}

export type Theme = {
breakpoints?: Unitless[];
tokens?: Tokens;
shorthands?: Shorthands;
macros?: Macros;
} & UserTheme

export type Options = {}

export type StyleObject = CSSProperties | CSSPsuedos | {
[property: string]: StyleObject;
}
export type HypostyleProperties = CSSPropertyNames | CSSPsuedos | string;
export type HypostyleObject = CSSProperties | CSSPsuedos | {
[property in HypostyleProperties]: HypostyleObject | string | number | boolean | undefined;
}

export declare function hypostyle(theme?: Theme, options?: Options): {
css(props: Partial<HypostyleObject>): string;
injectGlobal(props: Partial<HypostyleObject>): any;
keyframes: KeyframesAddon['keyframes'];
flush(): string;
style(props: Partial<HypostyleObject>): StyleObject;
pick(props: Partial<HypostyleObject>): {
props: AnyKeyValue;
styles: HypostyleObject;
};
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"description": "",
"main": "index.js",
"types": "index.d.js",
"files": [
"index.js",
"utils",
Expand Down Expand Up @@ -46,6 +47,7 @@
}
},
"dependencies": {
"csstype": "^3.0.6",
"nano-css": "^5.3.1"
}
}

0 comments on commit 802b12f

Please sign in to comment.