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(806) container queries and storybook #877

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

LukeFinch
Copy link
Contributor

@LukeFinch LukeFinch commented May 5, 2023

closes #806

What

Background - why this is needed
Allows users to add custom media queries and container queries into props/overrides
What did you do

  • Added new CSSQuery type
  • Added new ResponsiveValue type - a union of CSSQuery and MQ
  • Changed MQ to ResponsiveValue for some components (grid layout, block, textblock)
    What does the reviewers should expect
  • You can use one of the above components, and add a "rules" object to the style override.
      <GridLayout
        rows={{
          rules: [
            {
              rule: '@container grid-container (width <= 200px)',
              value: '1fr 1fr',
            },
            {
              rule: '@container grid-container (width > 200px)',
              value: '1fr 1fr 1fr 1fr',
            },
          ],
        }}
        columns={{
          xs: '1fr',
          md: '2fr',
          rules: [
            {
              rule: '@container grid-container (width <= 200px)',
              value: '1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr',
            },
            {
              rule: '@container grid-container (width > 200px)',
              value: '1fr 1fr',
            },
          ],
        }}
      >

This adds a new style to the page with emotion that handles the container query

I have done:

  • Written unit tests against changes
  • Written functional tests against the component and/or NewsKit site
  • Updated relevant documentation

I have tested manually:

  • The feature's functionality is working as expected on Chrome, Firefox, Safari and Edge
  • The screen reader reads and flows through the elements as expected.
  • There are no new errors in the browser console coming from this PR.
  • When visual test is not added, it renders correctly on different browsers and mobile viewports (Safari, Firefox, small mobile viewport, tablet)
  • The Playground feature is working as expected

Before:

After:

Who should review this PR:

How to test:

@github-actions github-actions bot added the feature This change contains a new feature label May 5, 2023
@LukeFinch LukeFinch self-assigned this May 5, 2023
@LukeFinch LukeFinch added ready for review Please assist in getting this reviewed Requires design review labels May 5, 2023
package.json Outdated
"@emotion/react": "^11.1.5",
"@emotion/styled": "^11.10.4",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
Copy link
Contributor

Choose a reason for hiding this comment

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

Will these changes no longer work with lower versions of emotion? Do note that we have emotion versions specified in the peerDependencies for consumers and this will likely need to be upped.

It's a bit grey to me if this would actually make this a breaking change or not. Given it's only a minor version bump on a dependency we could argue it isn't... but I guess there is still some level of risk for consumers who are upgrading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It didn't work on the version we had, and required the bump. I'm not sure which specific minimum version it's in. I could narrow that down. But ultimately, it does require moving to a higher emotion version to use container queries

Copy link
Contributor

Choose a reason for hiding this comment

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

11.10.4 will be the lowest supported version can we please update the peer dependencies?

Copy link
Contributor

Choose a reason for hiding this comment

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

also I think it should be sub 12 not the thin range that it's currently specified to

src/block/__tests__/block.stories.tsx Outdated Show resolved Hide resolved
src/block/block.tsx Outdated Show resolved Hide resolved
} & LogicalProps;
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'children'>;
} & ContainerQueryProps &
Copy link
Contributor

Choose a reason for hiding this comment

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

should this live at the same level as the logical props? e.g. in the overrides?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the latest commit

@@ -7,3 +7,19 @@ export type MQPartial<T> = Partial<{
}>;

export type MQ<T> = T | MQPartial<T>;

export type ResponsiveValue<T> = MQ<T> | CSSQueryRules<T>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a description to these news types, it should make it easier for consumers to understand what they are looking at.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to update the docs site as well so that reflects these changes.

@mstuartf
Copy link
Contributor

👏 This is cool

Comment on lines 171 to 174
overrides={{
containerName: 'container-small',
containerType: 'inline-size',
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Block does not have overrides, these need to be props. I think the same apply to the other componnets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I had them as props, @jps suggested moving them into overrides - to be the same level as logical props
Ideally would keep them consistent across all components

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the thing is that Block does not have overrides, so the logical props on the Block are props, <Block marginInline />
GridLayout has overrides (which was wrong) and in that case they can be part of the overrides

src/grid-layout/__tests__/stories/grid-layout.stories.tsx Outdated Show resolved Hide resolved
@@ -11,7 +11,8 @@ export type GridLayoutItemProps = BlockProps & {
alignSelf?: MQ<string>;
column?: MQ<string>;
row?: MQ<string>;
} & React.HTMLAttributes<HTMLElement>;
} & ContainerQueryProps &
Copy link
Contributor

Choose a reason for hiding this comment

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

The Block already have these as "overrides' which I mentioned need to be just props.
And this is adding it second time,

minHeight?: ResponsiveValue<string>;
maxHeight?: ResponsiveValue<string>;
} & LogicalProps &
ContainerQueryProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

same as block -> move to props

src/utils/responsive-helpers.ts Outdated Show resolved Hide resolved
@@ -7,3 +7,19 @@ export type MQPartial<T> = Partial<{
}>;

export type MQ<T> = T | MQPartial<T>;

export type ResponsiveValue<T> = MQ<T> | CSSQueryRules<T>;
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to update the docs site as well so that reflects these changes.

@param value - CSS value or token
*/
export type CSSQuery<T> = {
rule: `@media ${string}` | `@container ${string}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

that's very clever ;)

src/utils/style/utils.ts Outdated Show resolved Hide resolved
JohnTParsons
JohnTParsons previously approved these changes May 15, 2023
marginBlockStart?: MQ<string>;
marginBlockEnd?: MQ<string>;
marginBlock?: MQ<string>;
marginInlineStart?: ResponsiveValue<string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

One slight concern here is this now implies all components with logical props now support container queries and it won't be clear to users which is actually do. Maybe we just have to bite the bullet for now and the other components can be updated soon as aware this PR could keep growing.

Just a reminder we are going to need to update the docs also to reflect the change from MQ to ResponsiveValue

> = usedValues.reduce(
(acc: Record<CSSQuery<T>['rule'], string | CSSObject>, prop) => {
const values = {} as {[Key in keyof T]: T[Key]};
if (prop[1].rules) {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor but this condition can be pulled up to a filter, to reduce nestings

@@ -55,7 +55,7 @@ describe('GridLayout', () => {
const props: GridLayoutProps = {
areas: `
"A A"
"B C"
"B C"
Copy link
Contributor

Choose a reason for hiding this comment

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

😬

mutebg
mutebg previously approved these changes May 19, 2023
@mutebg
Copy link
Contributor

mutebg commented Jul 17, 2023

Since we are changing PEER DEPS I am not sure if that's not a breaking change for all users

@mutebg mutebg requested a review from a team as a code owner October 2, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change feature This change contains a new feature ready for review Please assist in getting this reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Container queries - storybook changes
6 participants