DefinitelyTyped/types/styled-theming/index.d.ts
Thomas Groutars 9eb48c844d
🤖 Merge PR #45701 Improve @types/styled-theming variant types by @tgroutars
* Improve styled-theming variant types

* Add tests
2020-06-25 06:19:52 -07:00

40 lines
1.4 KiB
TypeScript

// Type definitions for styled-theming 2.2
// Project: https://github.com/styled-components/styled-theming#readme
// Definitions by: Arjan Jassal <https://github.com/ArjanJ>
// Hieu Ho <https://github.com/hieuhlc>
// David Daniell <https://github.com/tinynumbers>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
import { FlattenInterpolation, ThemeProps, ThemedStyledProps } from 'styled-components';
declare function theme(name: string, values: theme.ThemeMap): theme.ThemeSet;
declare namespace theme {
type ThemeValueResult =
| string
| FlattenInterpolation<ThemeProps<any>>
| FlattenInterpolation<ThemedStyledProps<any, any>>;
type ThemeValueFn = (props: object) => ThemeValueResult;
type ThemeValue = ThemeValueFn | ThemeValueResult;
interface ThemeMap {
[key: string]: ThemeValue;
}
type VariantMap<TVariant extends string> = {
[key in TVariant]: ThemeMap;
};
type ThemeSet = (props: object) => string;
type VariantSet<TProp extends string, TVariant extends string> = (props: { [key in TProp]?: TVariant }) => string;
function variants<TProp extends string, TVariant extends string>(
name: string,
prop: TProp,
values: VariantMap<TVariant>,
): VariantSet<TProp, TVariant>;
}
export = theme;