-
-
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
[button] Add missing customize points for span #43436
Changes from all commits
2acef48
6b6a620
647db10
9e987e0
0b7146e
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 |
---|---|---|
|
@@ -2,7 +2,11 @@ | |
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { chainPropTypes } from '@mui/utils'; | ||
import { capitalize, unstable_useId as useId } from '@mui/material/utils'; | ||
import { | ||
capitalize, | ||
unstable_useId as useId, | ||
unstable_memoTheme as memoTheme, | ||
} from '@mui/material/utils'; | ||
import { unstable_composeClasses as composeClasses } from '@mui/base'; | ||
import { useDefaultProps } from '@mui/material/DefaultPropsProvider'; | ||
import Button from '@mui/material/Button'; | ||
|
@@ -17,6 +21,7 @@ const useUtilityClasses = (ownerState) => { | |
|
||
const slots = { | ||
root: ['root', loading && 'loading'], | ||
label: ['label'], | ||
startIcon: [loading && `startIconLoading${capitalize(loadingPosition)}`], | ||
endIcon: [loading && `endIconLoading${capitalize(loadingPosition)}`], | ||
loadingIndicator: [ | ||
|
@@ -51,56 +56,59 @@ const LoadingButtonRoot = styled(Button, { | |
}, | ||
]; | ||
}, | ||
})(({ theme }) => ({ | ||
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]: | ||
{ | ||
transition: theme.transitions.create(['opacity'], { | ||
duration: theme.transitions.duration.short, | ||
}), | ||
opacity: 0, | ||
}, | ||
variants: [ | ||
{ | ||
props: { | ||
loadingPosition: 'center', | ||
}, | ||
style: { | ||
transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], { | ||
})( | ||
memoTheme(({ theme }) => ({ | ||
display: 'inline-flex', | ||
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]: | ||
{ | ||
transition: theme.transitions.create(['opacity'], { | ||
duration: theme.transitions.duration.short, | ||
}), | ||
[`&.${loadingButtonClasses.loading}`]: { | ||
color: 'transparent', | ||
}, | ||
opacity: 0, | ||
}, | ||
}, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'start' && ownerState.fullWidth, | ||
style: { | ||
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]: | ||
{ | ||
transition: theme.transitions.create(['opacity'], { | ||
duration: theme.transitions.duration.short, | ||
}), | ||
opacity: 0, | ||
marginRight: -8, | ||
variants: [ | ||
{ | ||
props: { | ||
loadingPosition: 'center', | ||
}, | ||
style: { | ||
transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], { | ||
duration: theme.transitions.duration.short, | ||
}), | ||
[`&.${loadingButtonClasses.loading}`]: { | ||
color: 'transparent', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'end' && ownerState.fullWidth, | ||
style: { | ||
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]: | ||
{ | ||
transition: theme.transitions.create(['opacity'], { | ||
duration: theme.transitions.duration.short, | ||
}), | ||
opacity: 0, | ||
marginLeft: -8, | ||
}, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'start' && ownerState.fullWidth, | ||
style: { | ||
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]: | ||
{ | ||
transition: theme.transitions.create(['opacity'], { | ||
duration: theme.transitions.duration.short, | ||
}), | ||
opacity: 0, | ||
marginRight: -8, | ||
}, | ||
}, | ||
}, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'end' && ownerState.fullWidth, | ||
style: { | ||
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]: | ||
{ | ||
transition: theme.transitions.create(['opacity'], { | ||
duration: theme.transitions.duration.short, | ||
}), | ||
opacity: 0, | ||
marginLeft: -8, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
})); | ||
], | ||
})), | ||
); | ||
|
||
const LoadingButtonLoadingIndicator = styled('span', { | ||
name: 'MuiLoadingButton', | ||
|
@@ -112,87 +120,101 @@ const LoadingButtonLoadingIndicator = styled('span', { | |
styles[`loadingIndicator${capitalize(ownerState.loadingPosition)}`], | ||
]; | ||
}, | ||
})(({ theme }) => ({ | ||
position: 'absolute', | ||
visibility: 'visible', | ||
display: 'flex', | ||
variants: [ | ||
{ | ||
props: { | ||
loadingPosition: 'start', | ||
size: 'small', | ||
}, | ||
style: { | ||
left: 10, | ||
}, | ||
}, | ||
{ | ||
props: ({ loadingPosition, ownerState }) => | ||
loadingPosition === 'start' && ownerState.size !== 'small', | ||
style: { | ||
left: 14, | ||
}, | ||
}, | ||
{ | ||
props: { | ||
variant: 'text', | ||
loadingPosition: 'start', | ||
}, | ||
style: { | ||
left: 6, | ||
}, | ||
}, | ||
{ | ||
props: { | ||
loadingPosition: 'center', | ||
})( | ||
memoTheme(({ theme }) => ({ | ||
position: 'absolute', | ||
visibility: 'visible', | ||
display: 'flex', | ||
variants: [ | ||
{ | ||
props: { | ||
loadingPosition: 'start', | ||
size: 'small', | ||
}, | ||
style: { | ||
left: 10, | ||
}, | ||
}, | ||
style: { | ||
left: '50%', | ||
transform: 'translate(-50%)', | ||
color: (theme.vars || theme).palette.action.disabled, | ||
{ | ||
props: ({ loadingPosition, ownerState }) => | ||
loadingPosition === 'start' && ownerState.size !== 'small', | ||
style: { | ||
left: 14, | ||
}, | ||
}, | ||
}, | ||
{ | ||
props: { | ||
loadingPosition: 'end', | ||
size: 'small', | ||
{ | ||
props: { | ||
variant: 'text', | ||
loadingPosition: 'start', | ||
}, | ||
style: { | ||
left: 6, | ||
}, | ||
}, | ||
style: { | ||
right: 10, | ||
{ | ||
props: { | ||
loadingPosition: 'center', | ||
}, | ||
style: { | ||
left: '50%', | ||
transform: 'translate(-50%)', | ||
color: (theme.vars || theme).palette.action.disabled, | ||
}, | ||
}, | ||
}, | ||
{ | ||
props: ({ loadingPosition, ownerState }) => | ||
loadingPosition === 'end' && ownerState.size !== 'small', | ||
style: { | ||
right: 14, | ||
{ | ||
props: { | ||
loadingPosition: 'end', | ||
size: 'small', | ||
}, | ||
style: { | ||
right: 10, | ||
}, | ||
}, | ||
}, | ||
{ | ||
props: { | ||
variant: 'text', | ||
loadingPosition: 'end', | ||
{ | ||
props: ({ loadingPosition, ownerState }) => | ||
loadingPosition === 'end' && ownerState.size !== 'small', | ||
style: { | ||
right: 14, | ||
}, | ||
}, | ||
style: { | ||
right: 6, | ||
{ | ||
props: { | ||
variant: 'text', | ||
loadingPosition: 'end', | ||
}, | ||
style: { | ||
right: 6, | ||
}, | ||
}, | ||
}, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'start' && ownerState.fullWidth, | ||
style: { | ||
position: 'relative', | ||
left: -10, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'start' && ownerState.fullWidth, | ||
style: { | ||
position: 'relative', | ||
left: -10, | ||
}, | ||
}, | ||
}, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'end' && ownerState.fullWidth, | ||
style: { | ||
position: 'relative', | ||
right: -10, | ||
{ | ||
props: ({ ownerState }) => ownerState.loadingPosition === 'end' && ownerState.fullWidth, | ||
style: { | ||
position: 'relative', | ||
right: -10, | ||
}, | ||
}, | ||
}, | ||
], | ||
})); | ||
], | ||
})), | ||
); | ||
|
||
const LoadingButtonLabel = styled('span', { | ||
name: 'MuiLoadingButton', | ||
slot: 'Label', | ||
overridesResolver: (props, styles) => { | ||
return [styles.label]; | ||
}, | ||
})({ | ||
Comment on lines
+212
to
+213
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. Ah, I guess I forgot #43372 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. We are not using it if there it is not a callback, but it is missing in the other slots, I am adding it. 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. Ah right, ok, it's the opposite, makes sense. |
||
display: 'inherit', | ||
alignItems: 'inherit', | ||
justifyContent: 'inherit', | ||
}); | ||
|
||
const LoadingButton = React.forwardRef(function LoadingButton(inProps, ref) { | ||
const contextProps = React.useContext(ButtonGroupContext); | ||
|
@@ -242,15 +264,15 @@ const LoadingButton = React.forwardRef(function LoadingButton(inProps, ref) { | |
ownerState={ownerState} | ||
> | ||
{ownerState.loadingPosition === 'end' ? ( | ||
<span>{children}</span> | ||
<LoadingButtonLabel className={classes.label}>{children}</LoadingButtonLabel> | ||
) : ( | ||
loadingButtonLoadingIndicator | ||
)} | ||
|
||
{ownerState.loadingPosition === 'end' ? ( | ||
loadingButtonLoadingIndicator | ||
) : ( | ||
<span>{children}</span> | ||
<LoadingButtonLabel className={classes.label}>{children}</LoadingButtonLabel> | ||
)} | ||
</LoadingButtonRoot> | ||
); | ||
|
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.
I'm confused by this, issue created #43440