-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Validate bare values #13245
Validate bare values #13245
Conversation
…-span`, `row-start`, and `row-end`
f2120ec
to
8c06f5e
Compare
@@ -628,7 +634,10 @@ export function createUtilities(theme: Theme) { | |||
staticUtility('col-span-full', [['grid-column', '1 / -1']]) | |||
functionalUtility('col-span', { | |||
themeKeys: [], | |||
handleBareValue: ({ value }) => value, | |||
handleBareValue: ({ value }) => { |
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 put the validation for col-span
, col-start
, col-end
, row-span
, row-start
, and row-end
in a separate commit because they can technically almost contain any value. If a "name" is used, then they would refer to named grid areas: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start
/* <custom-ident> value */
grid-column-start: somegridarea;
/* <integer> + <custom-ident> values */
grid-column-start: 2;
grid-column-start: somegridarea 4;
So the question is, do we want to allow anything here, or is it fine to only accept integer values for bare values, e.g.: col-span-123
and if you want to generate values using names that you should use arbitrary values instead?
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 kinda think just do numbers and use arbitrary values for other stuff 👍🏻
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.
Agree, I think bare values should just be numbers. Feels much simpler to explain that too.
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.
Alright perfect, than I can keep the commit in there, nice 👍
This looks good. I'm just thinking out loud but I wonder if we can lift this check up a level to before we call |
I initially added a tailwindcss/packages/tailwindcss/src/utilities.ts Lines 2822 to 2829 in 9fc5aa1
therefor I inlined it in the I was thinking about providing something like: {
validation: ['<number>', '<integer>', '<angle>', 'auto']
} But then there is an additional layer of indirection going on and we would have to parse those values and what not. So I don't think it's worth it really. I kinda like that you have full control right now, and bail when using If anything, I think we could add some functions like |
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.
Looks good so far, I think missing handling the flex
root though, because current alphas generate this for example:
.flex-direction {
flex: direction;
}
d09ed4c
to
73e2252
Compare
Yep handled this one and also for |
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.
one small nit about a comment but otherwise looks good!
Co-authored-by: Jordan Pittman <[email protected]>
This way we make sure that the bare value ends with `%`, and the value before it is a number.
This PR validates incoming bare values to ensure we generate CSS that makes sense.
Before this PR, we would generate values such as:
Which is invalid, after this PR, these vaues would not be generated at all.