-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/components': patch | ||
--- | ||
|
||
The sx prop now has types that will inform autocomplete for color and shadow values that are key paths into the theme. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {KeyPaths} from '../utils/types/KeyPaths' | ||
|
||
type NestedObject = { | ||
a: string | ||
b: { | ||
b1: string | ||
b2: string | ||
} | ||
} | ||
|
||
export function generatesKeyPathsFromObject(x: KeyPaths<NestedObject>): 'a' | 'b.b1' | 'b.b2' { | ||
return x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,89 @@ | ||
import {theme} from './theme-preval' | ||
import {KeyPaths} from './utils/types/KeyPaths' | ||
|
||
export default theme | ||
|
||
// NOTE: for now, ThemeColors and ThemeShadows are handcrafted types. It would be nice if these | ||
// were exports from primitives (or a different shape but derived from those exports). | ||
|
||
type ThemeColors = { | ||
fg: { | ||
default: string | ||
muted: string | ||
subtle: string | ||
onEmphasis: string | ||
} | ||
canvas: { | ||
default: string | ||
overlay: string | ||
inset: string | ||
subtle: string | ||
} | ||
border: { | ||
default: string | ||
muted: string | ||
subtle: string | ||
} | ||
|
||
// Roles | ||
neutral: { | ||
emphasisPlus: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
accent: { | ||
fg: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
success: { | ||
fg: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
attention: { | ||
fg: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
severe: { | ||
fg: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
danger: { | ||
fg: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
done: { | ||
fg: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
sponsors: { | ||
fg: string | ||
emphasis: string | ||
muted: string | ||
subtle: string | ||
} | ||
} | ||
|
||
type ThemeShadows = { | ||
shadow: { | ||
small: string | ||
medium: string | ||
large: string | ||
extraLarge: string | ||
} | ||
} | ||
|
||
export type ThemeColorPaths = KeyPaths<ThemeColors> | ||
export type ThemeShadowPaths = KeyPaths<ThemeShadows> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Produces a union of dot-delimited keypaths to the string values in a nested object: | ||
export type KeyPaths<O extends Record<string, unknown>> = { | ||
[K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths<O[K]>}`) : never | ||
}[keyof O] |