Skip to content
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

Merged
merged 2 commits into from
Jan 27, 2021

Conversation

judahtanthony
Copy link
Contributor

Overview

Allow the PageFeatures component to render in a grid.

PR Checklist

@judahtanthony judahtanthony requested a review from a team as a code owner January 22, 2021 22:11
@@ -38,7 +38,7 @@ const FeatureBlock = styled.div`

type FeaturedMediaProps = {
featuresMedia?: 'image' | 'icon' | 'stat' | 'none';
imgSrc: string;
imgSrc?: string;
Copy link
Contributor Author

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.

Copy link
Collaborator

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"
Copy link
Contributor Author

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) => (
Copy link
Contributor Author

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
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #1312 (c6841d3) into main (ad53b03) will increase coverage by 0.05%.
The diff coverage is 92.00%.

@@            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              
Impacted Files Coverage Δ
...ckages/gamut-labs/src/landingPage/PageFeatures.tsx 92.59% <90.00%> (-7.41%) ⬇️
packages/gamut-labs/src/landingPage/Feature.tsx 100.00% <100.00%> (+4.76%) ⬆️

@@ -29,10 +37,57 @@ export type PageFeaturesProps = BaseProps & {
featuresMedia?: 'image' | 'icon' | 'stat' | 'none';
};

const rowRenderEach = (
items: PageFeaturesProps['features'],
itemRenderer: (item: any) => ReactNode
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Collaborator

@JoshuaKGoldberg JoshuaKGoldberg left a 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;
Copy link
Collaborator

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>;
Copy link
Collaborator

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=?

Copy link
Contributor

@codecaaron codecaaron Jan 22, 2021

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.

Copy link
Collaborator

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.

Copy link
Contributor

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?

Copy link
Collaborator

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 😄

Copy link
Collaborator

@JoshuaKGoldberg JoshuaKGoldberg Jan 23, 2021

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

@judahtanthony judahtanthony changed the title Allow the PageFeatures component to render in a grid feat(PageFeatures): Allow the PageFeatures component to render in a grid Jan 27, 2021
@judahtanthony
Copy link
Contributor Author

+1 to Alex's comment on the stricter types :)
@JoshuaKGoldberg I think I have addressed all your concerns.

@codecademydev
Copy link
Collaborator

📬Published Alpha Packages:

@codecademy/[email protected]
@codecademy/[email protected]

@codecademydev
Copy link
Collaborator

🚀 Styleguide deploy preview ready!

https://6011c93f1872b482ca38abf6--gamut-preview.netlify.app

Deploy Logs

@judahtanthony judahtanthony merged commit 4532a1e into main Jan 27, 2021
@judahtanthony judahtanthony deleted the jta-reach-557 branch January 27, 2021 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants