-
Notifications
You must be signed in to change notification settings - Fork 68
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
tighten up cssMap type #1502
tighten up cssMap type #1502
Conversation
🦋 Changeset detectedLatest commit: 8e057a5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
7b5ad8a
to
8dc34f0
Compare
packages/react/src/css-map/index.ts
Outdated
* } | ||
* ``` | ||
*/ | ||
type CssObject = Readonly< |
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 wonder if there's a way to ensure that the user can't nest objects indefinitely or with invalid keys, e.g. stuff like
const styles = cssMap({
danger: {
veryDanger: {
color: 'red',
}
},
})
without affecting valid use cases such as @media
queries
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 at my laptop so I can't test this out, but it does seem like there's nothing stopping the user from doing stuff like
const styles = cssMap({
danger: {
veryDanger: {
lotsofDanger: {
evenmoreDanger: {
spectacularDanger: {
color: 'red',
}
}
}
}
},
})
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.
yea, we've to allow it unless we impose stricter types.
The problem is that we don't know if the object key is a selector.
In the below example, we don't know if header
is a variant name or a selector.
const styles = cssMap({
success: {
header: { // Is it <header /> or a variant name? 🤷♂️
div: {
color: 'red'
}
}
},
})
I thought about disallowing targeting selectors completely, but I think disallowing it is too specific to Atlassian CSS standards.
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 see, thank you for clarifying 👍
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 think we can do better here, it may be worth a play with the structure
I've made a quick spike based on vanilla extract types https://github.com/atlassian-labs/compiled/pull/new/css-map-type-spike
In https://vanilla-extract.style/documentation/styling/#media-queries, they specify some bounded keys that allow the types to be much stricter
8dc34f0
to
bfd1cf8
Compare
Todo:
|
bfd1cf8
to
bdf3f74
Compare
| '&::spelling-error' | ||
| '&::target-text' | ||
| '&::view-transition' | ||
| '&:active' |
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.
Would be great to reduce the total amount of declarations. So instead of allowing both ::active and :active we settle on one.
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.
Ah good catch, didn't notice the duplicated pseudo-elements (:before/::before, :after/::after, :first-letter/::first-letter, :first-line, ::first-line)
ae83924
to
5bc3e89
Compare
4fb280f
to
6c775ac
Compare
Looks good. I wanted to give approval but notice I cannot approve my own PR 😬. |
all good @liamqma i've approved it now (despite most of the changes being from myself 😆 ) |
6c775ac
to
8e057a5
Compare
Further tighten up
cssMap
type to prevent some invalid usages.Examples
No Arrays
No tagged template
No arrow function
Only string and number are valid CSS values. No boolean/undefined.