-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[pickers] Use the new ownerState
in <PickersCalendarHeader />
, <PickersArrowSwitcher />
and <DayCalendarSkeleton />
#15499
Changes from all commits
5c9341e
2f3427d
42cbb35
b29b163
4acd00f
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,8 +10,15 @@ import { | |||||||||||||||
pickersSlideTransitionClasses, | ||||||||||||||||
PickersSlideTransitionClasses, | ||||||||||||||||
} from './pickersSlideTransitionClasses'; | ||||||||||||||||
import { PickerOwnerState } from '../models/pickers'; | ||||||||||||||||
import { usePickerPrivateContext } from '../internals/hooks/usePickerPrivateContext'; | ||||||||||||||||
|
||||||||||||||||
export type SlideDirection = 'right' | 'left'; | ||||||||||||||||
|
||||||||||||||||
interface PickerSlideTransitionOwnerState extends PickerOwnerState { | ||||||||||||||||
slideDirection: SlideDirection; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
export interface ExportedSlideTransitionProps { | ||||||||||||||||
/** | ||||||||||||||||
* Override or extend the styles applied to the component. | ||||||||||||||||
|
@@ -28,8 +35,12 @@ export interface SlideTransitionProps | |||||||||||||||
transKey: React.Key; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
const useUtilityClasses = (ownerState: SlideTransitionProps) => { | ||||||||||||||||
const { classes, slideDirection } = ownerState; | ||||||||||||||||
const useUtilityClasses = ( | ||||||||||||||||
classes: Partial<PickersSlideTransitionClasses> | undefined, | ||||||||||||||||
ownerState: PickerSlideTransitionOwnerState, | ||||||||||||||||
) => { | ||||||||||||||||
const { slideDirection } = ownerState; | ||||||||||||||||
|
||||||||||||||||
const slots = { | ||||||||||||||||
root: ['root'], | ||||||||||||||||
exit: ['slideExit'], | ||||||||||||||||
|
@@ -117,11 +128,13 @@ export function PickersSlideTransition(inProps: SlideTransitionProps) { | |||||||||||||||
reduceAnimations, | ||||||||||||||||
slideDirection, | ||||||||||||||||
transKey, | ||||||||||||||||
// extracting `classes` from `other` | ||||||||||||||||
classes: providedClasses, | ||||||||||||||||
classes: classesProp, | ||||||||||||||||
...other | ||||||||||||||||
} = props; | ||||||||||||||||
const classes = useUtilityClasses(props); | ||||||||||||||||
|
||||||||||||||||
const { ownerState: pickerOwnerState } = usePickerPrivateContext(); | ||||||||||||||||
const ownerState = { ...pickerOwnerState, slideDirection }; | ||||||||||||||||
const classes = useUtilityClasses(classesProp, ownerState); | ||||||||||||||||
Comment on lines
+135
to
+137
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. very small performance thing: would it make sense here to prevent creating 2 additional objects?
Suggested change
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. For me we have the exact same amount of objects created with both approaches. |
||||||||||||||||
const theme = useTheme(); | ||||||||||||||||
if (reduceAnimations) { | ||||||||||||||||
return <div className={clsx(classes.root, className)}>{children}</div>; | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,7 @@ export interface DayCalendarSkeletonProps extends HTMLDivProps { | |
ref?: React.Ref<HTMLDivElement>; | ||
} | ||
|
||
const useUtilityClasses = (ownerState: DayCalendarSkeletonProps) => { | ||
const { classes } = ownerState; | ||
const useUtilityClasses = (classes: Partial<DayCalendarSkeletonClasses> | undefined) => { | ||
const slots = { | ||
root: ['root'], | ||
week: ['week'], | ||
|
@@ -59,14 +58,11 @@ const DayCalendarSkeletonDay = styled(Skeleton, { | |
name: 'MuiDayCalendarSkeleton', | ||
slot: 'DaySkeleton', | ||
overridesResolver: (props, styles) => styles.daySkeleton, | ||
})<{ ownerState: { day: number } }>({ | ||
})({ | ||
margin: `0 ${DAY_MARGIN}px`, | ||
variants: [ | ||
{ | ||
props: { day: 0 }, | ||
style: { visibility: 'hidden' }, | ||
}, | ||
], | ||
'&[data-day-in-month="0"]': { | ||
visibility: 'hidden', | ||
}, | ||
}); | ||
|
||
const monthMap = [ | ||
|
@@ -92,22 +88,22 @@ function DayCalendarSkeleton(inProps: DayCalendarSkeletonProps) { | |
name: 'MuiDayCalendarSkeleton', | ||
}); | ||
|
||
const { className, ...other } = props; | ||
const { className, classes: classesProp, ...other } = props; | ||
|
||
const classes = useUtilityClasses(other); | ||
const classes = useUtilityClasses(classesProp); | ||
|
||
return ( | ||
<DayCalendarSkeletonRoot className={clsx(classes.root, className)} {...other}> | ||
{monthMap.map((week, index) => ( | ||
<DayCalendarSkeletonWeek key={index} className={classes.week}> | ||
{week.map((day, index2) => ( | ||
{week.map((dayInMonth, index2) => ( | ||
<DayCalendarSkeletonDay | ||
key={index2} | ||
variant="circular" | ||
width={DAY_SIZE} | ||
height={DAY_SIZE} | ||
className={classes.daySkeleton} | ||
ownerState={{ day }} | ||
data-day-in-month={dayInMonth} | ||
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. I can create a |
||
/> | ||
))} | ||
</DayCalendarSkeletonWeek> | ||
|
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.
It is not used in any
styleOverrides
, only inuseUtilityClasses
but I'm also unifying the parameters of this hook