From 63daead3def965df27ddc451a337f8bf6d675c86 Mon Sep 17 00:00:00 2001 From: Evan Jacobs Date: Thu, 16 Mar 2023 17:36:37 -0400 Subject: [PATCH] refactor: restore deep path generation for colors --- packages/system/src/styles/colors.ts | 7 ++----- packages/system/src/types.ts | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/system/src/styles/colors.ts b/packages/system/src/styles/colors.ts index 1e0205f6..97352d73 100644 --- a/packages/system/src/styles/colors.ts +++ b/packages/system/src/styles/colors.ts @@ -1,11 +1,8 @@ import * as CSS from 'csstype' import { themeGetter } from '../style' -import { ThemeNamespaceValue, ITheme, Theme } from '../types' +import { SynthesizedPath, ITheme, Theme } from '../types' -export type ThemeColor = ThemeNamespaceValue< - 'colors', - T -> +export type ThemeColor = SynthesizedPath export type Color = ThemeColor | CSS.Property.Color export const getColor = themeGetter({ name: 'color', diff --git a/packages/system/src/types.ts b/packages/system/src/types.ts index 93c00be2..f0fc2e70 100644 --- a/packages/system/src/types.ts +++ b/packages/system/src/types.ts @@ -115,18 +115,17 @@ export interface TransformValue { ): CSSScalar } -// declare type SynthesizedPath = { -// [P in keyof T]: -// | (T[P] extends { [key: string]: any; [key: number]: any } -// ? `${string & P}` | `${string & P}.${SynthesizedPath}` -// : `${string & P}`) -// | (number & P) -// }[T extends any[] ? number & keyof T : keyof T] - -// export type ThemeNamespaceValue< -// K extends string, -// T extends ITheme, -// > = SynthesizedPath +/** + * Recursively explores a given object and creates a union of the deep paths + * leading to primitive values (non-objects.) + */ +export type SynthesizedPath> = { + [P in keyof T]: + | (T[P] extends Record + ? `${string & P}.${SynthesizedPath}` + : `${string & P}`) + | number +}[T extends any[] ? number & keyof T : keyof T] export type ThemeNamespaceValue = | NamespaceType