-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[DateRangePicker] Migrate internal components to emotion #26326
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
109b0df
migrate to emotion
siriwatknp f4541c6
migrate to emotion
siriwatknp cd370c6
migrate to emotion
siriwatknp aeb397d
fix type issue by casting unknown
siriwatknp 35c8965
migrate to emotion
siriwatknp f15ab02
revert some code due to dependency
siriwatknp fc86eae
Merge branch 'pickers-calendar-emotion' into date-range-picker-emotion
siriwatknp b25f23b
Update packages/material-ui-lab/src/DateRangePicker/DateRangePickerVi…
mnajdova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import * as React from 'react'; | ||
import clsx from 'clsx'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { StyleRules, WithStyles, withStyles, Theme } from '@material-ui/core/styles'; | ||
import { StyleRules, Theme, experimentalStyled as styled } from '@material-ui/core/styles'; | ||
import PickersDay, { PickersDayProps } from '../PickersDay/PickersDay'; | ||
import { useUtils, useNow } from '../internal/pickers/hooks/useUtils'; | ||
import { PickerOnChangeFn } from '../internal/pickers/hooks/useViews'; | ||
|
@@ -58,6 +57,9 @@ export interface PickersCalendarProps<TDate> extends ExportedCalendarProps<TDate | |
TransitionProps?: Partial<SlideTransitionProps>; | ||
} | ||
|
||
const weeksContainerHeight = (DAY_SIZE + DAY_MARGIN * 4) * 6; | ||
|
||
// TODO remove PickersCalendarClassKey in CalendarPickerSkeleton migration | ||
Comment on lines
+60
to
+62
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. Cannot remove PickersCalendarClassKey and styles in this PR due to dependency to CalendarPickerSkeleton. will removed them in CalendarPickerSkeleton migration PR |
||
export type PickersCalendarClassKey = | ||
| 'root' | ||
| 'loadingContainer' | ||
|
@@ -66,7 +68,7 @@ export type PickersCalendarClassKey = | |
| 'daysHeader' | ||
| 'weekDayLabel'; | ||
|
||
const weeksContainerHeight = (DAY_SIZE + DAY_MARGIN * 4) * 6; | ||
// TODO remove styles in CalendarPickerSkeleton migration | ||
export const styles = (theme: Theme): StyleRules<PickersCalendarClassKey> => ({ | ||
root: { | ||
minHeight: weeksContainerHeight, | ||
|
@@ -102,15 +104,70 @@ export const styles = (theme: Theme): StyleRules<PickersCalendarClassKey> => ({ | |
}, | ||
}); | ||
|
||
const PickersCalendarDayHeader = styled( | ||
'div', | ||
{}, | ||
{ skipSx: true }, | ||
)({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}); | ||
|
||
const PickersCalendarWeekDayLabel = styled( | ||
Typography, | ||
{}, | ||
{ skipSx: true }, | ||
)(({ theme }) => ({ | ||
width: 36, | ||
height: 40, | ||
margin: '0 2px', | ||
textAlign: 'center', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
color: theme.palette.text.secondary, | ||
})); | ||
|
||
const PickersCalendarLoadingContainer = styled( | ||
'div', | ||
{}, | ||
{ skipSx: true }, | ||
)({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
minHeight: weeksContainerHeight, | ||
}); | ||
|
||
const PickersCalendarSlideTransition = styled( | ||
SlideTransition, | ||
{}, | ||
{ skipSx: true }, | ||
)({ | ||
minHeight: weeksContainerHeight, | ||
}); | ||
|
||
const PickersCalendarWeekContainer = styled('div', {}, { skipSx: true })({ overflow: 'hidden' }); | ||
|
||
const PickersCalendarWeek = styled( | ||
'div', | ||
{}, | ||
{ skipSx: true }, | ||
)({ | ||
margin: `${DAY_MARGIN}px 0`, | ||
display: 'flex', | ||
justifyContent: 'center', | ||
}); | ||
|
||
/** | ||
* @ignore - do not document. | ||
*/ | ||
function PickersCalendar<TDate>(props: PickersCalendarProps<TDate> & WithStyles<typeof styles>) { | ||
function PickersCalendar<TDate>(props: PickersCalendarProps<TDate>) { | ||
const { | ||
allowKeyboardControl, | ||
allowSameDateSelection, | ||
onFocusedDayChange: changeFocusedDay, | ||
classes, | ||
className, | ||
currentMonth, | ||
date, | ||
|
@@ -148,33 +205,28 @@ function PickersCalendar<TDate>(props: PickersCalendarProps<TDate> & WithStyles< | |
|
||
return ( | ||
<React.Fragment> | ||
<div className={classes.daysHeader}> | ||
<PickersCalendarDayHeader> | ||
{utils.getWeekdays().map((day, i) => ( | ||
<Typography | ||
aria-hidden | ||
key={day + i.toString()} | ||
variant="caption" | ||
className={classes.weekDayLabel} | ||
> | ||
<PickersCalendarWeekDayLabel aria-hidden key={day + i.toString()} variant="caption"> | ||
{day.charAt(0).toUpperCase()} | ||
</Typography> | ||
</PickersCalendarWeekDayLabel> | ||
))} | ||
</div> | ||
</PickersCalendarDayHeader> | ||
|
||
{loading ? ( | ||
<div className={classes.loadingContainer}>{renderLoading()}</div> | ||
<PickersCalendarLoadingContainer>{renderLoading()}</PickersCalendarLoadingContainer> | ||
) : ( | ||
<SlideTransition | ||
<PickersCalendarSlideTransition | ||
transKey={currentMonthNumber} | ||
onExited={onMonthSwitchingAnimationEnd} | ||
reduceAnimations={reduceAnimations} | ||
slideDirection={slideDirection} | ||
className={clsx(classes.root, className)} | ||
className={className} | ||
{...TransitionProps} | ||
> | ||
<div data-mui-test="pickers-calendar" role="grid" className={classes.weekContainer}> | ||
<PickersCalendarWeekContainer data-mui-test="pickers-calendar" role="grid"> | ||
{utils.getWeekArray(currentMonth).map((week) => ( | ||
<div role="row" key={`week-${week[0]}`} className={classes.week}> | ||
<PickersCalendarWeek role="row" key={`week-${week[0]}`}> | ||
{week.map((day) => { | ||
const pickersDayProps: PickersDayProps<TDate> = { | ||
key: (day as any)?.toString(), | ||
|
@@ -206,15 +258,13 @@ function PickersCalendar<TDate>(props: PickersCalendarProps<TDate> & WithStyles< | |
</div> | ||
); | ||
})} | ||
</div> | ||
</PickersCalendarWeek> | ||
))} | ||
</div> | ||
</SlideTransition> | ||
</PickersCalendarWeekContainer> | ||
</PickersCalendarSlideTransition> | ||
)} | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default withStyles(styles, { name: 'PrivatePickersCalendar' })(PickersCalendar) as <TDate>( | ||
props: PickersCalendarProps<TDate>, | ||
) => JSX.Element; | ||
export default PickersCalendar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Include
PickersCalendar
here because of style override (min-height
) inDateRangePickerViewDesktop