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

[CardOverflow][joy-ui] Remove conditional CSS to support Next.js App dir #39101

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/mui-joy/src/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,6 @@ const Card = React.forwardRef(function Card(inProps, ref) {
extraProps.orientation =
'orientation' in child.props ? child.props.orientation : dividerOrientation;
}
if (isMuiElement(child, ['CardOverflow'])) {
if (orientation === 'horizontal') {
extraProps['data-parent'] = 'Card-horizontal';
}
if (orientation === 'vertical') {
extraProps['data-parent'] = 'Card-vertical';
}
}
if (index === 0) {
extraProps['data-first-child'] = '';
}
Expand Down
80 changes: 38 additions & 42 deletions packages/mui-joy/src/CardOverflow/CardOverflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
} from './CardOverflowProps';
import useSlot from '../utils/useSlot';
import buttonClasses from '../Button/buttonClasses';
import cardClasses from '../Card/cardClasses';
import modalDialogClasses from '../ModalDialog/modalDialogClasses';

const useUtilityClasses = (ownerState: CardOverflowOwnerState) => {
const { variant, color } = ownerState;
Expand Down Expand Up @@ -44,67 +46,61 @@ const CardOverflowRoot = styled('div', {
const childRadius = 'calc(var(--CardOverflow-radius) - var(--variant-borderWidth, 0px))';
return {
alignSelf: 'stretch', // prevent shrinking if parent's align-items is not initial
borderRadius: 'var(--CardOverflow-radius)',
position: 'relative',
display: 'flex',
...(ownerState['data-parent'] === 'Card-horizontal' && {
margin: 'var(--_CardOverflow-margin)',
borderRadius: 'var(--_CardOverflow-radius)',
padding: 'var(--_CardOverflow-padding)',
Comment on lines +50 to +52
Copy link
Member Author

Choose a reason for hiding this comment

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

Without using internal CSS variables, the developer will need to override these properties with a selector to beat the [.${cardClasses.horizontal} > &] and [data-first-child][data-last-child].

[`.${cardClasses.horizontal} > &`]: {
Copy link
Member

Choose a reason for hiding this comment

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

When is this class being set? Isn't this a parent classname?

Copy link
Member

Choose a reason for hiding this comment

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

Do we expect people to set it themselves?

Copy link
Member Author

Choose a reason for hiding this comment

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

When is this class being set?

It is set by the Card component. The CardOverflow should be used as a direct child of the Card.

Do we expect people to set it themselves?

Nope, they don't need to.

Copy link
Member

@mnajdova mnajdova Oct 19, 2023

Choose a reason for hiding this comment

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

Aaah, we are basically using a parent selector to style the current component, nicee :D I never thought of using this, or more I didn't even know it is possible :)

'--AspectRatio-margin': 'calc(-1 * var(--Card-padding)) 0px',
marginTop: 'var(--CardOverflow-offset)',
marginBottom: 'var(--CardOverflow-offset)',
padding: 'var(--Card-padding) 0px',
// use data-attribute instead of :first-child, :last-child to support zero config SSR (emotion)
...(ownerState['data-first-child'] !== undefined && {
'--_CardOverflow-margin': 'var(--CardOverflow-offset) 0px',
'--_CardOverflow-padding': 'var(--Card-padding) 0px',
'&[data-first-child]': {
'--AspectRatio-radius': `${childRadius} 0 0 ${childRadius}`,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
marginLeft: 'var(--CardOverflow-offset)',
}),
...(ownerState['data-last-child'] !== undefined && {
'--_CardOverflow-radius': 'var(--CardOverflow-radius) 0 0 var(--CardOverflow-radius)',
'--_CardOverflow-margin':
'var(--CardOverflow-offset) 0px var(--CardOverflow-offset) var(--CardOverflow-offset)',
},
'&[data-last-child]': {
'--AspectRatio-radius': `0 ${childRadius} ${childRadius} 0`,
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
marginRight: 'var(--CardOverflow-offset)',
}),
...(ownerState['data-first-child'] !== undefined &&
ownerState['data-last-child'] !== undefined && {
'--AspectRatio-radius': childRadius,
}),
'--_CardOverflow-radius': '0 var(--CardOverflow-radius) var(--CardOverflow-radius) 0',
'--_CardOverflow-margin':
'var(--CardOverflow-offset) var(--CardOverflow-offset) var(--CardOverflow-offset) 0px',
},
'&[data-last-child][data-first-child]': {
'--AspectRatio-radius': childRadius,
},
[`& > .${buttonClasses.root}:only-child`]: {
height: 'calc(100% + -2 * var(--CardOverflow-offset))',
'--Button-margin': 'var(--CardOverflow-offset) 0',
'--Button-radius': '0 var(--CardOverflow-radius) var(--CardOverflow-radius) 0',
},
}),
...(ownerState['data-parent'] === 'Card-vertical' && {
'--AspectRatio-margin': '0px calc(-1 * var(--Card-padding))',
},
[`.${cardClasses.vertical} > &, .${modalDialogClasses.root} > &`]: {
flexDirection: 'column', // required to make AspectRatio works
marginLeft: 'var(--CardOverflow-offset)',
marginRight: 'var(--CardOverflow-offset)',
padding: '0px var(--Card-padding)',
// use data-attribute instead of :first-child, :last-child to support zero config SSR (emotion)
...(ownerState['data-first-child'] !== undefined && {
'--AspectRatio-margin': '0 calc(-1 * var(--Card-padding))',
'--_CardOverflow-margin': '0 var(--CardOverflow-offset)',
'--_CardOverflow-padding': '0 var(--Card-padding)',
'&[data-first-child]': {
'--AspectRatio-radius': `${childRadius} ${childRadius} 0 0`,
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0,
marginTop: 'var(--CardOverflow-offset)',
}),
...(ownerState['data-last-child'] !== undefined && {
'--_CardOverflow-radius': 'var(--CardOverflow-radius) var(--CardOverflow-radius) 0 0',
'--_CardOverflow-margin': 'var(--CardOverflow-offset) var(--CardOverflow-offset) 0',
},
'&[data-last-child]': {
'--AspectRatio-radius': `0 0 ${childRadius} ${childRadius}`,
borderTopLeftRadius: 0,
borderTopRightRadius: 0,
marginBottom: 'var(--CardOverflow-offset)',
}),
...(ownerState['data-first-child'] !== undefined &&
ownerState['data-last-child'] !== undefined && {
'--AspectRatio-radius': childRadius,
}),
'--_CardOverflow-radius': '0 0 var(--CardOverflow-radius) var(--CardOverflow-radius)',
'--_CardOverflow-margin': '0 var(--CardOverflow-offset) var(--CardOverflow-offset)',
},
'&[data-last-child][data-first-child]': {
'--AspectRatio-radius': childRadius,
},
[`& > .${buttonClasses.root}:only-child`]: {
zIndex: 1, // prevent button from being covered Link overlay. This can be improved in the future with :has() selector
width: 'calc(100% + -2 * var(--CardOverflow-offset))',
'--Button-margin': '0 var(--CardOverflow-offset)',
'--Button-radius': '0 0 var(--CardOverflow-radius) var(--CardOverflow-radius)',
},
}),
},
...theme.variants[ownerState.variant!]?.[ownerState.color!],
};
});
Expand Down