import { DefaultTheme } from "styled-components"; import { SuggestStrings } from "../types"; import { Color } from "./variables"; function colorProperty(cssProperty: string, prop: string) { const func = (props: T & { theme: DefaultTheme }) => { const { [prop as keyof T]: $color, theme } = props; if (theme?.variables && $color && ($color as string) in theme.variables) { return { [cssProperty]: theme.getVar($color as string), }; } return { [cssProperty]: $color, }; }; func.defaults = (defaults: T) => { return (props: T & { theme: DefaultTheme }) => func({ ...defaults, ...props }); }; return func; } export interface TextColorProps { $color?: SuggestStrings; } export const textColor = colorProperty("color", "$color"); export interface BackgroundColorProps { $bg?: SuggestStrings; } export const backgroundColor = colorProperty( "background", "$bg" ); export interface StrokeColorProps { $stroke?: SuggestStrings; } export const strokeColor = colorProperty("stroke", "$stroke"); export interface FillColorProps { $fill?: SuggestStrings; } export const fillColor = colorProperty("fill", "$fill");