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(editor): show correct responsive value according to breakpoint #6723

Merged
merged 7 commits into from
Dec 13, 2024

Conversation

liady
Copy link
Contributor

@liady liady commented Dec 12, 2024

This PR adds the ability to display the correct value in the controller according to the Scene size.
For example - if the element has className='pt-[20px] lg:pt-[150px] md:pt-[110px], and the Scene has a width of 1000px (which is larger than md but smaller than lg) - the paddingTop control will correctly show 110px.

Details:

  • This PR augments ParsedCSSStyleProperty, so instead of containing just the value it now holds:
    • a list of variants (the possible values and for each one the modifiers that when applied, the value is chosen. a screen size is a modifier)
    • the currentVariant - which is the value that is currently selected according to the Scene size.
  • After parsing the Tailwind classes using the 3rd-party parser (as before), we call getModifiers, that converts the Tailwind specific variants from the parser representation that looks like:
{type: 'media', value: 'sm'}

to our generic representation:

{
  type: 'media-size',
  size: {
    min: { value: 0, unit: 'px' },
    max: { value: 100, unit: 'em' }
  }
}
  • The getModifiers function uses an interal screensConfigToScreenSizes function - that parses the Tailwind config to have a map of <screenAlias> to ScreenSize
  • Both are covered in tests in tailwind-responsive-utils.spec.ts
  • This PR uses the utils that were merged in feat(editor): add responsive utils #6716 (specifically selectValueByBreakpoint to select the best matching variant)

Example (note that this PR does not contain the Scene resize buttons):

Monosnap.screencast.2024-12-04.19-40-23.mp4

Manual Tests:
I hereby swear that:

  • I opened a hydrogen project and it loaded
  • I could navigate to various routes in Play mode

Copy link
Contributor

github-actions bot commented Dec 12, 2024

Try me

Copy link

relativeci bot commented Dec 12, 2024

#15424 Bundle Size — 58.22MiB (~+0.01%).

be8d377(current) vs d1d46c1 master#15423(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 3 changes Regression 1 regression
                 Current
#15424
     Baseline
#15423
Regression  Initial JS 41.19MiB(~+0.01%) 41.19MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 18.26% 18.14%
No change  Chunks 20 20
No change  Assets 22 22
Change  Modules 4191(+0.02%) 4190
No change  Duplicate Modules 213 213
No change  Duplicate Code 27.24% 27.24%
No change  Packages 477 477
No change  Duplicate Packages 70 70
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#15424
     Baseline
#15423
Regression  JS 58.21MiB (~+0.01%) 58.21MiB
Improvement  HTML 9.4KiB (-0.21%) 9.42KiB

Bundle analysis reportBranch feat/show-correct-valueProject dashboard


Generated by RelativeCIDocumentationReport issue

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • editor/src/components/canvas/canvas-types.ts: Evaluated as low risk
  • editor/src/components/canvas/commands/utils/property-utils.ts: Evaluated as low risk
Comments suppressed due to low confidence (1)

editor/src/components/canvas/plugins/inline-style-plugin.ts:49

  • [nitpick] The modifiers parameter in the cssVariant function is optional, but it's being passed an empty array. Ensure that this behavior is intended and consistent.
const currentVariant = cssVariant(parsed.value, [])
@liady liady merged commit c0c4752 into master Dec 13, 2024
13 checks passed
@liady liady deleted the feat/show-correct-value branch December 13, 2024 18:25
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.

4 participants