-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[system] Fix breakpoints typescript types #15720
Conversation
No bundle size changes comparing d533b46...fa1bed2 |
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 looks nice so far but is missing tests.
Could you link to a docs section that explains this API? Otherwise it would be nice to add a demo that also has a TypeScript version (which would act as a test).
Okay, a few more changes here, that was quite the rabbit hole to go down. I started converting docs demos to typescript (for testing) and found that there were some more type changes that needed to be made and that weren't being tested. Some notes about the recent changes:
|
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.
Nice!
I'm sorry I forgot this was here. Could you rebase this with master without changing types implementation and see if the demos work? #15884 might've fixed this already. |
Box prop types previously didn't allow for responsive values (e.g. arrays/objects) and also did not account for variables in fontWeight value. fontWeight is now a string value to accept variable names without compiler errors, as opposed to the union type defined in React.CSSProperties.
Accepts a generic argument for the child function(s) prop types and return a style function with the breakpoints prop types and child prop types
* Re-add CSS output info comments * Reduce number of breakpoints from 5 to 3 * Remove component name duplication
This reverts commit f37bf4c.
f665a16
to
46002e5
Compare
46002e5
to
f82437f
Compare
@eps1lon I have rebased the pull request maintaining the failing case: import React from 'react';
import { typography, breakpoints } from '@material-ui/system';
import styled from 'styled-components';
const Box = styled.div`
${breakpoints(typography)}
`;
/**
* Outputs:
*
* font-size: 12px;
* @media (min-width: 600px) {
* font-size: 18px;
* }
* @media (min-width: 960px) {
* font-size: 24px;
* }
*/
export default function CollocationApi() {
return (
<Box xs={{ fontSize: 12 }} sm={{ fontSize: 18 }} md={{ fontSize: 24 }}>
Collocation API
</Box>
);
}
|
Changes
Box prop types previously didn't allow for responsive values (e.g. arrays/objects) and also did not account for variables in
fontWeight
.fontWeight
is now astring | number
value to accept variable names without compiler errors, as opposed to the union type defined in React.CSSProperties.Necessity
Without these changes, the following uses in typescript would have compile errors:
There are probably other props that need updating, but fontWeight was the only one that I found that seems to have variables that would actually be used. The others are:
All of these have union types, e.g.
"column" | "column-reverse" | "row" | "row-reverse" | ...
, and I can't think of any variables that would be used, so it's probably better to keep the union types than lose them for the sake of variables that aren't likely to be used.Alternative Options
I would have just created a new union type for fontWeight, something like:
Except that would prevent users from using custom variables, e.g. in our codebase we have a
fontWeightExtraBold
. The solution to that would be to create and export a named type, e.g.FontWeightValue
and set it to the above. I think that's the most complete solution, but starts to get tedious to maintain, so I opted for simple here.