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): add responsive utils #6716

Merged
merged 9 commits into from
Dec 11, 2024
Merged

feat(editor): add responsive utils #6716

merged 9 commits into from
Dec 11, 2024

Conversation

liady
Copy link
Contributor

@liady liady commented Dec 9, 2024

This prep PR adds the responsive utilities we'll use in our responsive PR, along with types and tests.
The important utilities (that are exposed outside) are:

  1. extractScreenSizeFromCss(css: string) - which recieves a CSS string of the media query (i.e @media (min-width: 100px)) and turns it into a ScreenSize object (in our example - { min: {value: 100, unit: 'px'} }). We also support media ranges (@media (20px < width < 50em)). This function is covered in tests.
    It uses mediaQueryToScreenSize(mediaQuery: MediaQuery) internally, which takes a MediaQuery object (after it was parsed from the CSS string), and does the "heavy lifting" of converting it to a ScreenSize representation. This inner function is also covered in tests.

  2. selectValueByBreakpoint - this function recieves a list of possible variants (values with corresponding ScreenSizes which they apply in), and the current Scene size. It infers the most matching variant according to the Scene size (can also be the default variant if none are matching). This function is also fully covered in tests.

No functionality is added to the app itself, this is just a prep PR for the functionality in the subsequent PR.

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 9, 2024

Try me

Copy link

relativeci bot commented Dec 9, 2024

#15410 Bundle Size — 58.21MiB (~+0.01%).

cdbebeb(current) vs d1d46c1 master#15407(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#15410
     Baseline
#15407
Regression  Initial JS 41.18MiB(~+0.01%) 41.18MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 18.24% 18.12%
No change  Chunks 20 20
No change  Assets 22 22
No change  Modules 4189 4189
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
#15410
     Baseline
#15407
Regression  JS 58.2MiB (~+0.01%) 58.2MiB
Improvement  HTML 9.4KiB (-0.21%) 9.42KiB

Bundle analysis reportBranch feat/responsive-utilsProject dashboard


Generated by RelativeCIDocumentationReport issue

@liady liady merged commit accbe3d into master Dec 11, 2024
14 checks passed
@liady liady deleted the feat/responsive-utils branch December 11, 2024 13:41
liady added a commit that referenced this pull request Dec 13, 2024
This prep PR adds the responsive utilities we'll use in our responsive
PR, along with types and tests.
The important utilities (that are exposed outside) are:
1. `extractScreenSizeFromCss(css: string)` - which recieves a CSS string
of the media query (i.e `@media (min-width: 100px)`) and turns it into a
`ScreenSize` object (in our example - `{ min: {value: 100, unit: 'px'}
}`). We also support media ranges (`@media (20px < width < 50em)`). This
function is covered in tests.
It uses `mediaQueryToScreenSize(mediaQuery: MediaQuery)` internally,
which takes a `MediaQuery` object (after it was parsed from the CSS
string), and does the "heavy lifting" of converting it to a `ScreenSize`
representation. This inner function is also covered in tests.

2. `selectValueByBreakpoint` - this function recieves a list of possible
variants (values with corresponding `ScreenSize`s which they apply in),
and the current Scene size. It infers the most matching variant
according to the Scene size (can also be the default variant if none are
matching). This function is also fully covered in tests.

No functionality is added to the app itself, this is just a prep PR for
the functionality in the subsequent PR.

**Manual Tests:**
I hereby swear that:

- [X] I opened a hydrogen project and it loaded
- [X] I could navigate to various routes in Play mode
liady added a commit that referenced this pull request Dec 13, 2024
…6723)

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
`modifier`s 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:
```ts
{type: 'media', value: 'sm'}
``` 
to our generic representation:
```ts
{
  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 #6716 (specifically
`selectValueByBreakpoint` to select the best matching variant)

**Example (note that this PR *does not* contain the Scene resize
buttons):**
<video
src="https://github.com/user-attachments/assets/90bb37ee-9aae-4563-9ddc-57a869a69ad5"></video>

**Manual Tests:**
I hereby swear that:

- [X] I opened a hydrogen project and it loaded
- [X] I could navigate to various routes in Play mode
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.

3 participants