-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat(PageFeatures): Allow the PageFeatures component to render in a grid #1312
Conversation
@@ -38,7 +38,7 @@ const FeatureBlock = styled.div` | |||
|
|||
type FeaturedMediaProps = { | |||
featuresMedia?: 'image' | 'icon' | 'stat' | 'none'; | |||
imgSrc: string; | |||
imgSrc?: string; |
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.
Now that we have "stat" and "none" features, we shouldn't require this.
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 be a union of more specific types, then? typeFeatureMediaProps = FeaturedImageProps | FeaturedIconProps | ...
?
@@ -65,6 +65,7 @@ const FeaturedMedia: React.FC<FeaturedMediaProps> = ({ | |||
as="div" | |||
marginTop={48} | |||
fontSize={{ xs: 44, lg: 64 }} | |||
fontWeight="title" |
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.
Correction in font-weight.
/> | ||
))} | ||
</FlexContainer> | ||
{renderEach(maxCols, features, (feature) => ( |
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.
Let me know if you think I over engineered this. The idea is the renderEach and figure out how to render this layout. This keep the messy logic out of here.
Codecov Report
@@ Coverage Diff @@
## main #1312 +/- ##
==========================================
+ Coverage 86.53% 86.58% +0.05%
==========================================
Files 302 302
Lines 2020 2035 +15
Branches 497 500 +3
==========================================
+ Hits 1748 1762 +14
- Misses 260 261 +1
Partials 12 12
|
@@ -29,10 +37,57 @@ export type PageFeaturesProps = BaseProps & { | |||
featuresMedia?: 'image' | 'icon' | 'stat' | 'none'; | |||
}; | |||
|
|||
const rowRenderEach = ( | |||
items: PageFeaturesProps['features'], | |||
itemRenderer: (item: any) => ReactNode |
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.
Is this a specific case where any
can be set as the type?. I believe it's encouraged to use any
as little as possible
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 have removed the any and replaced with an explicit type.
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.
+1 to Alex's comment on the stricter types :)
@@ -38,7 +38,7 @@ const FeatureBlock = styled.div` | |||
|
|||
type FeaturedMediaProps = { | |||
featuresMedia?: 'image' | 'icon' | 'stat' | 'none'; | |||
imgSrc: string; | |||
imgSrc?: string; |
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 be a union of more specific types, then? typeFeatureMediaProps = FeaturedImageProps | FeaturedIconProps | ...
?
const size = { | ||
xs: 12, | ||
sm: 12 / maxCols, | ||
} as ResponsiveProperty<ColumnSizes>; |
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.
Generally, you don't want to use as
: it can hide small but important differences in types. It's meant to be the "I know it's slightly off, just let me do it" operator. Instead, how about inlining this object into the size=
?
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 I think we'd have to also specify the result of 12 / maxCols
IIRC since it won't infer the literal 12 | 6 | 4 | 3
and only number
.
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.
Aha, right! I forgot about that. What an irksome lack of feature, TypeScript really should be be able to deduce that here since maxCols
is a union type... ah well.
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.
Do you know if there are plans to implement something like that? Seems like integer arithmetic within a limited set would be fairly low overhead?
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 skimming through their issue tracker and don't see it. You could always request it 😄
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.
Oh actually, I'm finding some references to the TS team not wanting it. The hard part would probably be around edge cases (as always with adding to the type system). An example that would get brought up:
function takesOnePointFive(value: 1.5) { }
const two = 2;
const three = 3;
takesOnePointFive(three / two);
Should that work? If you're saying yes, of course, it would be confusing for users to see division not work, then how does the type system deal with the various quirks of IEEE 754? Is TypeScript going to have to implement a full math engine in the type system, as in microsoft/TypeScript#26382 <- microsoft/TypeScript#15645
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 makes sense, greatt find :D Outside of whole numbers this is pretty gnar.
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.
Sorry, so did we decide to inline it, or is the arithmetic going to require a cast anyhow, so might as well cast the whole thing?
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.
@judahtanthony you can do nothing I think 😄 . Up to you.
bfa8f48
to
3733f91
Compare
3733f91
to
33901f0
Compare
|
📬Published Alpha Packages:@codecademy/[email protected] |
🚀 Styleguide deploy preview ready! |
Overview
Allow the PageFeatures component to render in a grid.
PR Checklist