Skip to content

flex: cleanup Flex* custom styling in favor of Flex primitive #93809

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented Jun 18, 2025

Just remove a couple custom Flex* classes in favor of the Flex primitive

@JonasBa JonasBa requested review from a team as code owners June 18, 2025 13:56
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jun 18, 2025
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Generally in favor of this!

Not a blocker, but still not sure where I land on the styled(Flex) pattern. Intuitively feels like we shouldn't need to create an override to define padding / overflow behavior?

@@ -163,12 +164,12 @@ export function CodeSnippet({
</Tab>
))}
</TabsWrapper>
<FlexSpacer />
<Flex.Item grow={1} />
Copy link
Member

Choose a reason for hiding this comment

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

Wonder if we should have <Flex.Spacer /> as a shorthand here? Seems easier to remember than this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that could also work. I don't have a strong opinion on it tbh, it seems like an edge case we can iron out later

@@ -52,9 +52,6 @@ export const BarContainer = styled('div')`
`;

export const FlexContainer = styled('div')`
display: flex;
align-items: center;
justify-content: flex-end;
width: 100%;
`;
Copy link
Member

Choose a reason for hiding this comment

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

Missing a replacement here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah no, I actually want to revert this one, and possibly just rename the component given that it's exported

@@ -42,12 +43,8 @@ const Container = styled('div')`
min-width: 0; /* flex-hack for overflow-ellipsised children */
`;

const FlexWrapper = styled('div')`
const FlexWrapper = styled(Flex)`
Copy link
Member

Choose a reason for hiding this comment

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

personally think this is worse

Copy link
Member

Choose a reason for hiding this comment

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

also it changes how it displays since overflowEllipsis is overriding display flex

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't disagree, but I think it suffers from the same problem as inline styles (which are somewhat growing in popularity across the codebase).

I will try and modify these styled usages to use TextOverflow (at least in this case, it should help)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reverted the change locally, to make sure I don't break anything, and I'm either not testing this correctly, or it doesn't even work in it's current state.

CleanShot.2025-06-18.at.14.02.09.mp4

@@ -99,10 +100,8 @@ const ProjectBadge = styled(IdBadge)`
flex-shrink: 0;
`;

const FlexCenter = styled('div')`
const FlexCenter = styled(Flex)`
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't work

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as the comment above, I will change it to use TextOverflow

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, I don't think this one works either. I've reverted the change and wrote a story to test (using PanelTable as the wrapper to mimic the usage), and this is what I see

CleanShot 2025-06-18 at 14 28 29@2x

Comment on lines 870 to 871
display: flex;
const FulllHeightFlex = styled(Flex)`
flex-grow: 1;
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 this is also worse

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it can actually be avoided by moving the container to the parent component, I will try to do that.

Copy link
Member

@scttcper scttcper left a comment

Choose a reason for hiding this comment

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

avoid styled(Flex) at all costs

Comment on lines 185 to 186
display: flex;
const FullWidthFlex = styled(Flex)`
width: 100%;
Copy link
Member

Choose a reason for hiding this comment

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

probably actually a flex-grow 1

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't even need it, just flex with align right looks identical

@@ -244,7 +244,7 @@ function InformationCard({
return (
<Fragment>
<Flex align="center">
<FlexContainer>
<Flex.Item grow={1}>
Copy link
Member

Choose a reason for hiding this comment

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

What is a flex item?

Copy link
Member Author

Choose a reason for hiding this comment

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

currently, just a convenient way of setting the flex property on the child.

@JonasBa
Copy link
Member Author

JonasBa commented Jun 18, 2025

avoid styled(Flex) at all costs

We can't unfortunately do that. The fact that we are using styled components won't give us the isolation we need.

@scttcper
Copy link
Member

i can lint against it. It is too hard to understand what the styles are. Even in this pr we're overriding display: flex in the wrong way

@JonasBa
Copy link
Member Author

JonasBa commented Jun 18, 2025

Generally in favor of this!

Not a blocker, but still not sure where I land on the styled(Flex) pattern. Intuitively feels like we shouldn't need to create an override to define padding / overflow behavior?

I agree. I think that calls for a better set of primitives or a more complete API - this change mostly surfaces that problem.

@JonasBa
Copy link
Member Author

JonasBa commented Jun 18, 2025

i can lint against it. It is too hard to understand what the styles are. Even in this pr we're overriding display: flex in the wrong way

Linters can be disabled, and I wouldn't count on them as the ultimate solution. Ultimately, what we want it to give people the least amount of reason to even use styles for anything. We are pretty far from that, but this is a start.

You are right about pointing out the problem about overriding display, I missed that, however the root cause is still in the fact that we are restyling things and that overflow ellipsis ends up overriding display, which is imo not what it should be doing. I would bet you that there are actually cases in the codebase where that bug already exists today.

@JonasBa
Copy link
Member Author

JonasBa commented Jun 18, 2025

@scttcper it really didn't take that long to find one either, and I'm pretty sure we have more

display: flex;
flex-grow: 1;
flex-shrink: ${p => (p.hasSingleField ? '1' : '0')};
max-width: ${p => (p.hasSingleField ? '100%' : 'min(280px, 50%)')};
color: ${p => p.theme.textColor};
font-weight: ${p => p.theme.fontWeightNormal};
font-size: ${p => p.theme.fontSizeMedium};
margin: 0;
line-height: ${p => p.theme.text.lineHeightHeading};
${p => p.theme.overflowEllipsis};

@scttcper
Copy link
Member

the problem i have is that styles now come from 3 places

Flex has styles, the props are declaring styles <Flex column> and you can override them in styled(Flex). This is crazy when we just want a div with flex.

@scttcper
Copy link
Member

still in favor of adopting a subset of tailwind display styles. Would reduce runtime overhead at least

@JonasBa
Copy link
Member Author

JonasBa commented Jun 18, 2025

the problem i have is that styles now come from 3 places

Flex has styles, the props are declaring styles <Flex column> and you can override them in styled(Flex). This is crazy when we just want a div with flex.

I agree, and I want us to move away from both inline styled and styled components. I will see if I can actually move entirely away of the styled flex in this PR, I think it should be doable.

For the question of "just wanting div with flex", there is usually more behind that, like you most probably want something else with that display flex too, maybe direction='column', or something, which is where other higher level primitives can come in, things like Stack or List, those have better semantic meaning, but also allow you to tweak the subset like gap, as opposed to having to set display=column on everything. We don't provide those, but we probably should.

@scttcper
Copy link
Member

I'll never use stack or list because I have styled('div') and won't remember they exist. just like nobody knows Flex.Item exists

@JonasBa
Copy link
Member Author

JonasBa commented Jun 18, 2025

I'll never use stack or list because I have styled('div') and won't remember they exist. just like nobody knows Flex.Item exists

If we never add documentation or guidelines for any of this, then neither will anyone else for that matter, but that's actually something we want to change.

The assumption is that if the primitives are good, people won't need to use styled. Now, I don't know if we will actually get there in practice, I think it's going to be hard, however we should at least be able to get to a point where styled is used much less frequently than it is today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants