-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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)', | ||
[`.${cardClasses.horizontal} > &`]: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is this class being set? Isn't this a parent classname? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we expect people to set it themselves? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is set by the Card component. The CardOverflow should be used as a direct child of the Card.
Nope, they don't need to. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!], | ||
}; | ||
}); | ||
|
There was a problem hiding this comment.
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]
.