-
Notifications
You must be signed in to change notification settings - Fork 12
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
[New Rule Proposal]: Use Value with Unit #20
Comments
@monchi what do you think?
|
@no-yan Totally agree. I can't believe the second inconsistency...
I think we can prohibit number values since there is no merit except a very little reduction of bundle size. Also I prefer the strict rule which forces the use of the single unit not only in the same element but in the whole application. How about providing options like below? type Option = {
scope: "wholeApp" | "element",
allowedUnits: ("px" | "rem")[],
} |
Thank you. I'm glad to hear it.
LGTM! Now let's implement it. I'll work on it after #21, but I don't mind if you do. |
@no-yan Ok, so please assign you to the issue when getting to work on it to avoid double work! |
I've made the prototype of the implementation, but I'm not sure which attribute is the one that receives the spacing value. I will try to determine it by theme key from https://chakra-ui.com/docs/features/style-props. Column "Theme Key" seems to represent internal handling, and "space" correspond to "spacing" defined in theme. If you have another idea, please let me know. |
@no-yan Maybe you can refer this object but i'm not sure |
This does not handle width etc, so the other objects are also involved? I will look it closer tomorrow. |
First, chakra calls Then,
You can see the same thing for So in summary, we can refer to |
btw |
Rule Summary
When non-united number is not predefined in theme, suggest adding unit for explicitness.
Example of incorrect code for this rule:
Example of correct code for this rule:
It may be desirable to have this rule turned off by default.
Why needed?
In Chakra UI, we can use numbers for spacing without units.
However, Chakra UI doesn't offer consistent behavior, and there are times when it is preferable to explicitly add units.
Inconsistency 1: Different conversion methods depending value is predefined or not.
First of all, the behavior differs depending on whether the value has already been defined.
5rem
, it will be equal to80px
in most case.21px
Chakra UI claims mental model of spacing:
But it is not true model. Most numbers will not be quadruple.
For example, if you pass a variable to
width
, some values are quadrupled, some are not. This is something that many developers would not expect.Inconsistency 2: Some prop does not convert numbers as
${number}px
Secondly, in some case
width
props can output numbers withoutpx
or any units. ref: Different width depending on how props are passed<Box w='11'/>
// output will be11
<Box w={11}/>
// output will be11px
I think both of these problems should be improved in Chakra UI itself, but I don't have much motivation to do so right now.
The text was updated successfully, but these errors were encountered: