-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds theme keypaths to our sx prop type for better autocomplete #1544
Conversation
🦋 Changeset detectedLatest commit: 82a4a68 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
fd8ec49
to
5de709f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an excellent incremental step towards better TypeScript support for the sx
prop. No need to over-engineer a solution until we solidify the future of CSS-in-JS in Primer React. Love it 💖
src/theme.ts
Outdated
subtle: string | ||
} | ||
|
||
// Only meant for Primer components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we want autocomplete for primer.*
variables. Let's leave them out for now.
src/theme.ts
Outdated
export type ThemeShadowPaths = KeyPaths<ThemeShadows> | ||
|
||
// Produces a union of dot-delimited keypaths to the string values in a nested object: | ||
type KeyPaths<O extends {}> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this live in src/utils/types/
?
5de709f
to
3095551
Compare
3095551
to
bacbdf0
Compare
.changeset/silly-coins-sit.md
Outdated
@@ -0,0 +1,5 @@ | |||
--- | |||
'@primer/components': patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on the fence about whether this is a minor or patch release. Do we consider the lack of types a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, good question. Maybe it's a minor? It's sort of a new feature, but also the API hasn't really changed at all? Even the types should be functionally equivalent — anything that passed typechecking before passes now, and anything that didn't pass before fails now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(TLDR: no strong feelings, happy to switch to minor if you think that's more appropriate)
} | ||
} | ||
|
||
export function generatesKeyPathsFromObject(x: KeyPaths<NestedObject>): 'a' | 'b.b1' | 'b.b2' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ type tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for setting these up!
Exciting!!! 🎉 |
This replaces the type currently used for the
sx
prop with one that explicitly includes all key paths into our theme for color and shadow values. This does not yet add better typing to styled system props.Partially addresses https://github.com/github/primer/issues/389
Open questions
ColorProps
andShadowProps
objects an acceptable proxy for getting a list of keys intoSystemCssProperties
objects that have color and shadow variables? In theory styled system prop names could diverge fromSystemCssProperties
properties' names over time.Screenshots
CleanShot.2021-10-27.at.15.45.40.mp4
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.