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

Use CSS Modules in Curriculum Catalog Card #51099

Merged
merged 17 commits into from
Apr 6, 2023

Conversation

megcrenshaw
Copy link
Contributor

@megcrenshaw megcrenshaw commented Apr 4, 2023

Uses modules instead of a direct import for styles in the Curriculum Catalog Card.

Tested this manually in storybook:
image

Links

Testing story

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@megcrenshaw megcrenshaw changed the base branch from staging to add-translation-icon April 4, 2023 14:06
@megcrenshaw megcrenshaw changed the title Use modules catalog card Use CSS Modules in Curriculum Catalog Card Apr 4, 2023
@megcrenshaw megcrenshaw requested a review from a team April 4, 2023 14:21
@davidsbailey
Copy link
Member

thanks for tackling this! it should be possible to "flatten" the styles in the .module.css file now (see 79e2f04 for example)

Base automatically changed from add-translation-icon to staging April 4, 2023 20:39
@megcrenshaw megcrenshaw marked this pull request as ready for review April 4, 2023 20:44
@megcrenshaw megcrenshaw requested a review from a team as a code owner April 4, 2023 20:44
@megcrenshaw
Copy link
Contributor Author

megcrenshaw commented Apr 4, 2023

thanks for tackling this! it should be possible to "flatten" the styles in the .module.css file now (see 79e2f04 for example)

Could you share the reasoning for flattening the styles?

Do you mean going from something like

.curriculumCatalogCardContainer {
  ...

  img {
    ...
  }

  .curriculumInfoContainer {
    ...

    .overline {
      ...
    }

    i {
      ...
    }

    .tagsAndTranslatabilityContainer {
      ...

      i {
        ...
      }
    }

to something like

.curriculumCatalogCardContainer {
  ...

  img {
    ...
  }
}

.curriculumInfoContainer {
    ...

    i {
      ...
    }
}

.overline {
      ...
}

.tagsAndTranslatabilityContainer {
      ...

    i {
        ...
    }
}

?

I ask because I feel like the syntax of the module helps us visually decipher which styles are nested and which aren't. The i tags, for example, require the nesting, as some i tags have different styling than others (so I left those nested in the second example). For classes, if we tried to use the .tagsAndTranslatabilityContainer class outside of the .curriculumCatalogCardContainer in the JSX file, it shouldn't work, as the styles written in the CSS file assume that class is nested inside another class –– but we wouldn't know that from looking at the CSS file if the styles were flattened.

I'm not an expert in this stuff, so just trying to understand the reasoning here!

Copy link
Contributor

@mgc1194 mgc1194 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this Meg 😊

@davidsbailey
Copy link
Member

Do you mean going from something like

...

yep! specifically, to un-nest any classnames, since those will be assigned guids:
Screenshot 2023-04-04 at 2 53 25 PM

Could you share the reasoning for flattening the styles?

Sure, two reasons:

  1. it seems unnecessary, because now each classname is globally unique, so there's no risk of a nested style getting unintentionally applied due to a css classname collision
  2. with classnames being replaced with guids, it seems like there's some increased chance of someone applying the outer style (via styles.curriculumCatalogCardContainer) and expecting the nested styles to get applied to an element with classname 'tagsAndTranslatabilityContainer' (as opposed to styles.tagsAndTranslatabilityContainer)

I ask because I feel like the syntax of the module helps us visually decipher which styles are nested and which aren't. The i tags, for example, require the nesting, as some i tags have different styling than others (so I left those nested in the second example).

agreed, the i tags require nesting. sorry for not being clear about that.

For classes, if we tried to use the .tagsAndTranslatabilityContainer class outside of the .curriculumCatalogCardContainer in the JSX file, it shouldn't work, as the styles written in the CSS file assume that class is nested inside another class –– but we wouldn't know that from looking at the CSS file if the styles were flattened.

what scenario would you say this is guarding against? e.g.

  • (a) someone else imports your css module and applies tagsAndTranslatabilityContainer, but not curriculumCatalogCardContainer
  • (b) you refactor your own component for tagsAndTranslatabilityContainer to be outside of curriculumCatalogCardContainer

I would argue that we shouldn't worry about (a), and in (b) you should let the .jsx file "own" the layout and not have to worry about restructuring your css when you change the layout in your .jsx file. so I guess unnecessary nesting of css feels like "duplicate state" with respect to what's in the .jsx file.

these are my thoughts... I'm interested if other folks who have been using modules for longer have ideas too.

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after talking through it, I think the policy of whether to un-nest classnames is not worth blocking this PR -- but it'd be great if we could figure out a best practice here (possibly including allowing people to do it whichever way they want 😄 )

@megcrenshaw
Copy link
Contributor Author

@davidsbailey Thanks for the thorough explanation! I'm going to merge this one, and then flatten the stylesheet in a separate PR, mostly to do more thorough comparison between the two

@megcrenshaw megcrenshaw merged commit ef77336 into staging Apr 6, 2023
@megcrenshaw megcrenshaw deleted the use-modules-catalog-card branch April 6, 2023 18:35
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.

None yet

3 participants