import { CSSProperties } from "react"; type Size = string | number; type Property = keyof CSSProperties; type CSSProps = Partial>; type Transformer = (value: Type) => Value; export type Sizes = Record>; export function getSizeStyles(sizes: Sizes) { return function getStyles(size: Size) { const styles = sizes[size]; if (!styles) return (property: Property) => undefined; function getStyle(property: Property): Type | undefined; function getStyle( property: Property, transformer: Transformer ): Value; function getStyle( property: Property, transformer?: Transformer ) { const value = styles[property]; if (typeof value === "undefined") return undefined; return transformer ? transformer(value as Type) : value; } return getStyle; }; }