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

[react] Create Stack component #118

Merged
merged 16 commits into from
Jun 17, 2024
Merged

Conversation

brijeshb42
Copy link
Contributor

This uses atomic class generation utility to cover all the scenarios of rendering a Stack.

@brijeshb42 brijeshb42 added the component: Stack The React component. label May 31, 2024
'normal',
'stretch',
],
gap: ['--Stack-gap'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need more properties to be added here?

@brijeshb42
Copy link
Contributor Author

Adding more commits with tests.

export interface BreakpointOverrides {}

export type Breakpoint = OverridableStringUnion<
'xs' | 'sm' | 'md' | 'lg' | 'xl',
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this makes me think of mui/material-ui#26168

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll still need to continue supporting this unless we want breaking changes.
We could also introduce a way to alias breakpoints, ie, xs -> mobile etc.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 1, 2024

We will need to be careful with how we document this if we have import { Stack } from "@pigment-css/react". People could perceive this as:

  • lack of focus
  • an API they are supposed to use over the other API and create false first impressions about Pigment CSS

@mnajdova
Copy link
Member

mnajdova commented Jun 3, 2024

We will need to be careful with how we document this if we have import { Stack } from "@pigment-css/react". People could perceive this as:

  • lack of focus
  • an API they are supposed to use over the other API and create false first impressions about Pigment CSS

@brijeshb42 correct me if I am wrong, but we decided to create this in the Material UI package, no?

@brijeshb42
Copy link
Contributor Author

@mnajdova Creating Stack in material-ui means also adding Pigment CSS as a dependency. That's why I moved it to this package itself. I've discussed in the meeting as well if you've seen the video.

@DiegoAndai
Copy link
Member

@brijeshb42 correct me if I am wrong, but we decided to create this in the Material UI package, no?

We did

Creating Stack in material-ui means also adding Pigment CSS as a dependency.

Why is that? Isn't it possible to migrate the layout components the same way the other components were migrated?

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 4, 2024
@mnajdova
Copy link
Member

mnajdova commented Jun 4, 2024

Marija: Agree for the components to be part of Material UI. Can it be peer dependency? Or maybe another question, if we are generating the CSS during the build and packaging it with the library would it still be required?
Brijesh: If we are packaging it, then we get to choose if we want Pigment as a dependency of not. Right now, adding Pigment as a dependency adds a lot of packages that are required for the build but not part of the runtime. In this case, we can just have a @pigment-css/runtime package that would only have the runtime code and we can make them a dependency. Otherwise, we can bundle Pigment's runtime in materials package

This is the last conversation we had around this. I would be happy with any solution we pick right now, as long as the components come from Material UI. Why add technical debt when we know we are going to want this done anyway.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 4, 2024
@brijeshb42
Copy link
Contributor Author

The current solution does not package things with Material UI. We have yet to start on the exploration for generating css before publishing.

@DiegoAndai
Copy link
Member

I reiterate my question 😅: Isn't it possible to migrate the layout components the same way the other components were migrated?

direction: ['flexDirection'],
spacing: ['gap'],
},
multiplier: 8,
Copy link
Member

Choose a reason for hiding this comment

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

Did you figure out how to take this from the theme?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@siriwatknp What's your opinion here? theme.spacing() without arguments does not guarantee a numeric value.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should always be a string, then use CSS calc() as a value. To leverage the theme, use

multiplier: theme.vars.spacing, // it can be a string or an array.

packages/pigment-css-react/src/baseAtomics.js Outdated Show resolved Hide resolved
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 10, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 13, 2024
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

I am a bit confused. Is this a Stack component for Pigment CSS or for Material UI?

If it's for Material UI, based on the existing implementation createStack, only direction and spacing are the props because the rest of the system props are deprecated.

return;
}
classes.push(propertyClasses[condition]);
handlePrimitive(propertyClasses[condition], condition);
Copy link
Member

Choose a reason for hiding this comment

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

This should be:

Suggested change
handlePrimitive(propertyClasses[condition], condition);
classes.push(propertyClasses[condition]);

right?

Otherwise the class is never applied

Copy link
Member

@siriwatknp siriwatknp Jun 14, 2024

Choose a reason for hiding this comment

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

It's working correctly, see the test should work with shorthands.

In that case, it's for property like flexDirection that has multiple possible values.

Copy link
Member

@DiegoAndai DiegoAndai Jun 14, 2024

Choose a reason for hiding this comment

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

The test works correctly because it uses an array for the direction value, which is handled here:

} else if (Array.isArray(propertyValue)) {

The test fails if you provide direction: { xs: 'row', sm: 'column' }, which should also be supported, and it's handled in the line we're discussing.

So besides changing this line we should add a test with all supported formats.

Copy link
Member

Choose a reason for hiding this comment

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

You are right. I pushed a fix with all the test cases that also cover null, undefined from the values.

@DiegoAndai
Copy link
Member

I am a bit confused. Is this a Stack component for Pigment CSS or for Material UI?

If it's for Material UI, based on the existing implementation createStack, only direction and spacing are the props because the rest of the system props are deprecated.

This is the PigmentStack that Material UI will export. You're correct, following mui/material-ui#42259, we can remove the display, alignItems, and justifyContent props. No need to have atomic classes for this as sx supports breakpoints. @brijeshb42 if you need to add an initial value to display, you can use the styled function, I did this in the Grid component.

@siriwatknp
Copy link
Member

@DiegoAndai I pushed changes that simplify the logic in ff1ef61:

  • remove the unitless as I don't think we need it yet.
  • multiplier should be a string | undefined from theme.vars.spacing
  • remove $$default as I think defaultCondition suffices.
  • for default condition, the variable name will not be suffixed with the breakpoint name. I think this is cleaner and less code.

/**
* @type {PigmentOptions}
*/
const pigmentOptions = {
theme,
transformLibraries: ['local-ui-lib', '@mui/material'],
sourceMap: true,
displayName: true,
overrideContext: (context) => {
Copy link
Member

@siriwatknp siriwatknp Jun 14, 2024

Choose a reason for hiding this comment

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

To prevent an error Cannot redefine property toString.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not very familiar with the Pigment setup, why is this required in detail?

Is displayName no longer required?

Copy link
Member

@siriwatknp siriwatknp Jun 17, 2024

Choose a reason for hiding this comment

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

I'm not sure why @brijeshb42 removes the displayName, but for overrideContext it's a workaround for an error related to MUI System to make the app runnable (I will open a separate issue to discuss the options).

The setup is not related to Stack.

Comment on lines +116 to +120
<Stack spacing={{ xs: 2, md: 3 }}>
<div>Item1</div>
<div>Item1</div>
<div>Item1</div>
</Stack>
Copy link
Member

Choose a reason for hiding this comment

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

Here is the result:

image

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

My last question is how this is going to be used in Material UI?

packages/pigment-css-react/src/Stack.d.ts Outdated Show resolved Hide resolved
/**
* @type {PigmentOptions}
*/
const pigmentOptions = {
theme,
transformLibraries: ['local-ui-lib', '@mui/material'],
sourceMap: true,
displayName: true,
overrideContext: (context) => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not very familiar with the Pigment setup, why is this required in detail?

Is displayName no longer required?

@DiegoAndai
Copy link
Member

DiegoAndai commented Jun 14, 2024

@siriwatknp

My last question is how this is going to be used in Material UI?

It will be reexported from Material UI as PigmentStack. Pigment will be an optional peer dependency, and the import will fail if the user doesn't have pigment installed.

flexDirection: {
column: {
xs: 'flex-direction-column-xs',
$$default: 'flex-direction-column-xs',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are you assuming the default breakpoint in case someone passed this ?

<Stack spacing={1} />

Copy link
Member

Choose a reason for hiding this comment

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

Where is that $$default coming from? Isn't the defaultCondition enough to know the default breakpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. It was a remnant of the first implementation of the Box component.

@brijeshb42 brijeshb42 merged commit 02b2440 into mui:master Jun 17, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Stack The React component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants