Add @styled-system/core typings (#45332)

* Added @styled-system/core typings

* fixed path in tsconfig

* added csstype to package.json

* changed project url
This commit is contained in:
Leo Toneff 2020-06-12 20:39:36 +02:00 committed by GitHub
parent 738491c9cb
commit a586263e89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 0 deletions

50
types/styled-system__core/index.d.ts vendored Normal file
View File

@ -0,0 +1,50 @@
// Type definitions for @styled-system/core 5.1
// Project: https://github.com/styled-system/styled-system
// Definitions by: Leo Toneff <https://github.com/bragle>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.1
import * as CSS from 'csstype';
export function get(obj: any, ...paths: Array<string | number>): any;
export type ObjectOrArray<T, K extends keyof any = keyof any> = T[] | Record<K, T | Record<K, T> | T[]>;
export type Scale = ObjectOrArray<number | string>;
export interface styleFn {
(...args: any[]): any;
config?: object;
propNames?: string[];
cache?: object;
}
export interface ConfigStyle {
/** The CSS property to use in the returned style object (overridden by `properties` if present). */
property?: keyof CSS.Properties;
/**
* An array of multiple properties (e.g. `['marginLeft', 'marginRight']`) to which this style's value will be
* assigned (overrides `property` when present).
*/
properties?: Array<keyof CSS.Properties>;
/** A string referencing a key in the `theme` object. */
scale?: string;
/** A fallback scale object for when there isn't one defined in the `theme` object. */
defaultScale?: Scale;
/** A function to transform the raw value based on the scale. */
transform?: (value: any, scale?: Scale) => any;
}
export interface Config {
/** Property name exposed for use in components */
[customStyleName: string]: ConfigStyle | boolean;
}
export function compose(...parsers: styleFn[]): styleFn;
export function system(styleDefinitions: Config): styleFn;
export function createParser(config: ConfigStyle): styleFn;
export function createStyleFunction(args: ConfigStyle): styleFn;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"csstype": "^2.6.10"
}
}

View File

@ -0,0 +1,19 @@
import { compose, system, get } from '@styled-system/core';
// Test that the system definition is correct.
// https://github.com/styled-system/styled-system/blob/master/packages/core/src/index.js#L131
const customFontStyles = system({
fontWeight: {
property: 'fontWeight',
properties: ['fontWeight'],
scale: 'fontWeights',
defaultScale: [200, 400, 600],
transform: (n, scale) => get(scale, n),
},
letterSpacing: true,
});
const CustomFontGroup = compose(
customFontStyles,
customFontStyles
);

View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"paths": {
"@styled-system/core": ["styled-system__core"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "styled-system__core-tests.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }