Skip to content

Commit 63daead

Browse files
author
Evan Jacobs
committed
refactor: restore deep path generation for colors
1 parent 9955f61 commit 63daead

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

packages/system/src/styles/colors.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import * as CSS from 'csstype'
22
import { themeGetter } from '../style'
3-
import { ThemeNamespaceValue, ITheme, Theme } from '../types'
3+
import { SynthesizedPath, ITheme, Theme } from '../types'
44

5-
export type ThemeColor<T extends ITheme = Theme> = ThemeNamespaceValue<
6-
'colors',
7-
T
8-
>
5+
export type ThemeColor<T extends ITheme = Theme> = SynthesizedPath<T['colors']>
96
export type Color<T extends ITheme = Theme> = ThemeColor<T> | CSS.Property.Color
107
export const getColor = themeGetter<ThemeColor>({
118
name: 'color',

packages/system/src/types.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,17 @@ export interface TransformValue {
115115
): CSSScalar
116116
}
117117

118-
// declare type SynthesizedPath<T> = {
119-
// [P in keyof T]:
120-
// | (T[P] extends { [key: string]: any; [key: number]: any }
121-
// ? `${string & P}` | `${string & P}.${SynthesizedPath<T[P]>}`
122-
// : `${string & P}`)
123-
// | (number & P)
124-
// }[T extends any[] ? number & keyof T : keyof T]
125-
126-
// export type ThemeNamespaceValue<
127-
// K extends string,
128-
// T extends ITheme,
129-
// > = SynthesizedPath<T[K]>
118+
/**
119+
* Recursively explores a given object and creates a union of the deep paths
120+
* leading to primitive values (non-objects.)
121+
*/
122+
export type SynthesizedPath<T extends Record<string, unknown>> = {
123+
[P in keyof T]:
124+
| (T[P] extends Record<string, unknown>
125+
? `${string & P}.${SynthesizedPath<T[P]>}`
126+
: `${string & P}`)
127+
| number
128+
}[T extends any[] ? number & keyof T : keyof T]
130129

131130
export type ThemeNamespaceValue<K extends string, T extends ITheme> =
132131
| NamespaceType<T[K]>

0 commit comments

Comments
 (0)