-
-
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
[material-ui][SpeedDialAction] Add slots and slotProps #45065
Open
sai6855
wants to merge
34
commits into
mui:master
Choose a base branch
from
sai6855:spped-dial-slots
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
4a8fb4d
add tooltip slot
sai6855 39f887a
add tooltip slot
sai6855 84277f5
add fab slot
sai6855 05521ee
add fab slot
sai6855 0fc2711
add statictooltip slot
sai6855 ad63976
docs:api
sai6855 46a972e
Merge branch 'master' into spped-dial-slots
sai6855 8a7a50c
skip root class tst
sai6855 be806aa
Merge branch 'spped-dial-slots' of https://github.com/sai6855/materia…
sai6855 fed2b5e
fix test
sai6855 adbdd04
Merge branch 'master' into spped-dial-slots
sai6855 2572033
fix
sai6855 18e65b3
Merge branch 'spped-dial-slots' of https://github.com/sai6855/materia…
sai6855 889567b
add test
sai6855 4cbcab1
docs:api
sai6855 4e9ac36
add getslotProps and don't merge Fabprops
sai6855 0d7db4b
Merge branch 'master' into spped-dial-slots
sai6855 54e5c49
deprecate tooltip* props
sai6855 838f9e7
add migration guide
sai6855 94eda69
add codemod
sai6855 091cceb
docs:api
sai6855 3080342
pnpm prettier
sai6855 72b3a92
fix open prop
sai6855 99834ae
fix tests
sai6855 8195472
prettier
sai6855 1125ff1
update docs
sai6855 cde3be2
fix theme.actual.js
sai6855 b890f12
Merge branch 'master' into spped-dial-slots
sai6855 c4be54e
add event in args
sai6855 99cf9fe
Merge branch 'spped-dial-slots' of https://github.com/sai6855/materia…
sai6855 bd55436
add handlers
sai6855 7b8a99d
move tooltipopen to top
sai6855 f80bb4a
update test names
sai6855 135ae2b
fix tooltip externalprops
sai6855 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import Fab from '../Fab'; | |
import Tooltip from '../Tooltip'; | ||
import capitalize from '../utils/capitalize'; | ||
import speedDialActionClasses, { getSpeedDialActionUtilityClass } from './speedDialActionClasses'; | ||
import useSlot from '../utils/useSlot'; | ||
|
||
const useUtilityClasses = (ownerState) => { | ||
const { open, tooltipPlacement, classes } = ownerState; | ||
|
@@ -155,6 +156,8 @@ const SpeedDialAction = React.forwardRef(function SpeedDialAction(inProps, ref) | |
tooltipOpen: tooltipOpenProp = false, | ||
tooltipPlacement = 'left', | ||
tooltipTitle, | ||
slots = {}, | ||
slotProps = {}, | ||
...other | ||
} = props; | ||
|
||
|
@@ -173,44 +176,81 @@ const SpeedDialAction = React.forwardRef(function SpeedDialAction(inProps, ref) | |
|
||
const transitionStyle = { transitionDelay: `${delay}ms` }; | ||
|
||
const fab = ( | ||
<SpeedDialActionFab | ||
size="small" | ||
className={clsx(classes.fab, className)} | ||
tabIndex={-1} | ||
role="menuitem" | ||
ownerState={ownerState} | ||
{...FabProps} | ||
style={{ | ||
const externalForwardedProps = { | ||
slots, | ||
slotProps: { | ||
fab: FabProps, | ||
...slotProps, | ||
}, | ||
}; | ||
|
||
const [FabSlot, fabSlotProps] = useSlot('fab', { | ||
elementType: SpeedDialActionFab, | ||
externalForwardedProps, | ||
ownerState, | ||
shouldForwardComponentProp: true, | ||
className: clsx(classes.fab, className), | ||
additionalProps: { | ||
style: { | ||
...transitionStyle, | ||
...FabProps.style, | ||
}} | ||
> | ||
{icon} | ||
</SpeedDialActionFab> | ||
); | ||
}, | ||
tabIndex: -1, | ||
role: 'menuitem', | ||
size: 'small', | ||
}, | ||
}); | ||
|
||
const [TooltipSlot, tooltipSlotProps] = useSlot('tooltip', { | ||
elementType: Tooltip, | ||
externalForwardedProps, | ||
shouldForwardComponentProp: true, | ||
ref, | ||
additionalProps: { | ||
title: tooltipTitle, | ||
placement: tooltipPlacement, | ||
onClose: handleTooltipClose, | ||
onOpen: handleTooltipOpen, | ||
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. These should goes into elementType: Tooltip,
externalForwardedProps,
shouldForwardComponentProp: true,
ref,
getSlotProps: (handlers) => ({
onClose: () => {
handlers.onClose?.(),
handleTooltipClose(),
},
onOpen: …
}) |
||
open: open && tooltipOpen, | ||
classes: TooltipClasses, | ||
id, | ||
}, | ||
}); | ||
|
||
const [StaticTooltipSlot, staticTooltipSlotProps] = useSlot('staticTooltip', { | ||
elementType: SpeedDialActionStaticTooltip, | ||
externalForwardedProps, | ||
ownerState, | ||
ref, | ||
className: classes.staticTooltip, | ||
additionalProps: { | ||
id, | ||
}, | ||
}); | ||
|
||
const [StaticTooltipLabelSlot, staticTooltipLabelSlotProps] = useSlot('staticTooltipLabel', { | ||
elementType: SpeedDialActionStaticTooltipLabel, | ||
externalForwardedProps, | ||
ownerState, | ||
className: classes.staticTooltipLabel, | ||
additionalProps: { | ||
style: transitionStyle, | ||
id: `${id}-label`, | ||
}, | ||
}); | ||
|
||
const fab = <FabSlot {...fabSlotProps}>{icon}</FabSlot>; | ||
|
||
if (tooltipOpenProp) { | ||
return ( | ||
<SpeedDialActionStaticTooltip | ||
id={id} | ||
ref={ref} | ||
className={classes.staticTooltip} | ||
ownerState={ownerState} | ||
{...other} | ||
> | ||
<SpeedDialActionStaticTooltipLabel | ||
style={transitionStyle} | ||
id={`${id}-label`} | ||
className={classes.staticTooltipLabel} | ||
ownerState={ownerState} | ||
> | ||
<StaticTooltipSlot {...staticTooltipSlotProps} {...other}> | ||
<StaticTooltipLabelSlot {...staticTooltipLabelSlotProps}> | ||
{tooltipTitle} | ||
</SpeedDialActionStaticTooltipLabel> | ||
</StaticTooltipLabelSlot> | ||
{React.cloneElement(fab, { | ||
'aria-labelledby': `${id}-label`, | ||
})} | ||
</SpeedDialActionStaticTooltip> | ||
</StaticTooltipSlot> | ||
); | ||
} | ||
|
||
|
@@ -219,19 +259,9 @@ const SpeedDialAction = React.forwardRef(function SpeedDialAction(inProps, ref) | |
} | ||
|
||
return ( | ||
<Tooltip | ||
id={id} | ||
ref={ref} | ||
title={tooltipTitle} | ||
placement={tooltipPlacement} | ||
onClose={handleTooltipClose} | ||
onOpen={handleTooltipOpen} | ||
open={open && tooltipOpen} | ||
classes={TooltipClasses} | ||
{...other} | ||
> | ||
<TooltipSlot {...tooltipSlotProps} {...other}> | ||
{fab} | ||
</Tooltip> | ||
</TooltipSlot> | ||
); | ||
}); | ||
|
||
|
@@ -271,6 +301,26 @@ SpeedDialAction.propTypes /* remove-proptypes */ = { | |
* If `true`, the component is shown. | ||
*/ | ||
open: PropTypes.bool, | ||
/** | ||
* The props used for each slot inside. | ||
* @default {} | ||
*/ | ||
slotProps: PropTypes.shape({ | ||
fab: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), | ||
staticTooltip: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), | ||
staticTooltipLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), | ||
tooltip: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), | ||
}), | ||
/** | ||
* The components used for each slot inside. | ||
* @default {} | ||
*/ | ||
slots: PropTypes.shape({ | ||
fab: PropTypes.elementType, | ||
staticTooltip: PropTypes.elementType, | ||
staticTooltipLabel: PropTypes.elementType, | ||
tooltip: PropTypes.elementType, | ||
}), | ||
/** | ||
* The system prop that allows defining system overrides as well as additional CSS styles. | ||
*/ | ||
|
Oops, something went wrong.
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.
No need to spread the
FabProps.style
, theslotProps.fab.style
(fromFabProps
) will be merged byuseSlot
.