Skip to content
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
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4a8fb4d
add tooltip slot
sai6855 Jan 20, 2025
39f887a
add tooltip slot
sai6855 Jan 20, 2025
84277f5
add fab slot
sai6855 Jan 20, 2025
05521ee
add fab slot
sai6855 Jan 20, 2025
0fc2711
add statictooltip slot
sai6855 Jan 20, 2025
ad63976
docs:api
sai6855 Jan 20, 2025
46a972e
Merge branch 'master' into spped-dial-slots
sai6855 Jan 20, 2025
8a7a50c
skip root class tst
sai6855 Jan 20, 2025
be806aa
Merge branch 'spped-dial-slots' of https://github.com/sai6855/materia…
sai6855 Jan 20, 2025
fed2b5e
fix test
sai6855 Jan 20, 2025
adbdd04
Merge branch 'master' into spped-dial-slots
sai6855 Jan 20, 2025
2572033
fix
sai6855 Jan 20, 2025
18e65b3
Merge branch 'spped-dial-slots' of https://github.com/sai6855/materia…
sai6855 Jan 20, 2025
889567b
add test
sai6855 Jan 21, 2025
4cbcab1
docs:api
sai6855 Jan 21, 2025
4e9ac36
add getslotProps and don't merge Fabprops
sai6855 Jan 29, 2025
0d7db4b
Merge branch 'master' into spped-dial-slots
sai6855 Jan 29, 2025
54e5c49
deprecate tooltip* props
sai6855 Jan 29, 2025
838f9e7
add migration guide
sai6855 Jan 29, 2025
94eda69
add codemod
sai6855 Jan 29, 2025
091cceb
docs:api
sai6855 Jan 29, 2025
3080342
pnpm prettier
sai6855 Jan 29, 2025
72b3a92
fix open prop
sai6855 Jan 29, 2025
99834ae
fix tests
sai6855 Jan 29, 2025
8195472
prettier
sai6855 Jan 29, 2025
1125ff1
update docs
sai6855 Jan 29, 2025
cde3be2
fix theme.actual.js
sai6855 Jan 29, 2025
b890f12
Merge branch 'master' into spped-dial-slots
sai6855 Jan 29, 2025
c4be54e
add event in args
sai6855 Jan 30, 2025
99cf9fe
Merge branch 'spped-dial-slots' of https://github.com/sai6855/materia…
sai6855 Jan 30, 2025
bd55436
add handlers
sai6855 Jan 30, 2025
7b8a99d
move tooltipopen to top
sai6855 Jan 31, 2025
f80bb4a
update test names
sai6855 Jan 31, 2025
135ae2b
fix tooltip externalprops
sai6855 Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions docs/pages/material-ui/api/speed-dial-action.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
"icon": { "type": { "name": "node" } },
"id": { "type": { "name": "string" } },
"open": { "type": { "name": "bool" } },
"slotProps": {
"type": {
"name": "shape",
"description": "{ fab?: func<br>&#124;&nbsp;object, staticTooltip?: func<br>&#124;&nbsp;object, staticTooltipLabel?: func<br>&#124;&nbsp;object, tooltip?: func<br>&#124;&nbsp;object }"
},
"default": "{}"
},
"slots": {
"type": {
"name": "shape",
"description": "{ fab?: elementType, staticTooltip?: elementType, staticTooltipLabel?: elementType, tooltip?: elementType }"
},
"default": "{}"
},
"sx": {
"type": {
"name": "union",
Expand All @@ -29,37 +43,45 @@
"import SpeedDialAction from '@mui/material/SpeedDialAction';",
"import { SpeedDialAction } from '@mui/material';"
],
"classes": [
"slots": [
{
"key": "fab",
"className": "MuiSpeedDialAction-fab",
"description": "Styles applied to the Fab component.",
"isGlobal": false
"name": "fab",
"description": "The component that renders the fab.",
"default": "Fab",
"class": "MuiSpeedDialAction-fab"
},
{
"name": "tooltip",
"description": "The component that renders the tooltip.",
"default": "Tooltip",
"class": null
},
{
"name": "staticTooltip",
"description": "The component that renders the static tooltip.",
"default": "'span'",
"class": "MuiSpeedDialAction-staticTooltip"
},
{
"name": "staticTooltipLabel",
"description": "The component that renders the static tooltip label.",
"default": "'span'",
"class": "MuiSpeedDialAction-staticTooltipLabel"
}
],
"classes": [
{
"key": "fabClosed",
"className": "MuiSpeedDialAction-fabClosed",
"description": "Styles applied to the Fab component if `open={false}`.",
"isGlobal": false
},
{
"key": "staticTooltip",
"className": "MuiSpeedDialAction-staticTooltip",
"description": "Styles applied to the root element if `tooltipOpen={true}`.",
"isGlobal": false
},
{
"key": "staticTooltipClosed",
"className": "MuiSpeedDialAction-staticTooltipClosed",
"description": "Styles applied to the root element if `tooltipOpen={true}` and `open={false}`.",
"isGlobal": false
},
{
"key": "staticTooltipLabel",
"className": "MuiSpeedDialAction-staticTooltipLabel",
"description": "Styles applied to the static tooltip label if `tooltipOpen={true}`.",
"isGlobal": false
},
{
"key": "tooltipPlacementLeft",
"className": "MuiSpeedDialAction-tooltipPlacementLeft",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"description": "This prop is used to help implement the accessibility logic. If you don&#39;t provide this prop. It falls back to a randomly generated id."
},
"open": { "description": "If <code>true</code>, the component is shown." },
"slotProps": { "description": "The props used for each slot inside." },
"slots": { "description": "The components used for each slot inside." },
"sx": {
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
},
Expand All @@ -24,32 +26,27 @@
"tooltipTitle": { "description": "Label to display in the tooltip." }
},
"classDescriptions": {
"fab": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the Fab component" },
"fabClosed": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the Fab component",
"conditions": "<code>open={false}</code>"
},
"staticTooltip": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>tooltipOpen={true}</code>"
},
"staticTooltipClosed": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>tooltipOpen={true}</code> and <code>open={false}</code>"
},
"staticTooltipLabel": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the static tooltip label",
"conditions": "<code>tooltipOpen={true}</code>"
},
"tooltipPlacementLeft": {
"description": "Styles applied to the root element if <code>tooltipOpen={true}</code> and `tooltipPlacement=&quot;left&quot;``"
},
"tooltipPlacementRight": {
"description": "Styles applied to the root element if <code>tooltipOpen={true}</code> and `tooltipPlacement=&quot;right&quot;``"
}
},
"slotDescriptions": {
"fab": "The component that renders the fab.",
"staticTooltip": "The component that renders the static tooltip.",
"staticTooltipLabel": "The component that renders the static tooltip label.",
"tooltip": "The component that renders the tooltip."
}
}
78 changes: 77 additions & 1 deletion packages/mui-material/src/SpeedDialAction/SpeedDialAction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,81 @@ import { InternalStandardProps as StandardProps } from '..';
import { FabProps } from '../Fab';
import { TooltipProps } from '../Tooltip';
import { SpeedDialActionClasses } from './speedDialActionClasses';
import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';

export interface SpeedDialActionProps extends StandardProps<Partial<TooltipProps>, 'children'> {
export interface SpeedDialActionSlots {
/**
* The component that renders the fab.
* @default Fab
*/
fab?: React.ElementType;
/**
* The component that renders the tooltip.
* @default Tooltip
*/
tooltip?: React.ElementType;
/**
* The component that renders the static tooltip.
* @default 'span'
*/
staticTooltip?: React.ElementType;
/**
* The component that renders the static tooltip label.
* @default 'span'
*/
staticTooltipLabel?: React.ElementType;
}

export interface SpeedDialActionFabSlotPropsOverrides {}
export interface SpeedDialActionTooltipSlotPropsOverrides {}
export interface SpeedDialActionStaticTooltipSlotPropsOverrides {}
export interface SpeedDialActionStaticTooltipLabelSlotPropsOverrides {}

export type SpeedDialActionSlotsAndSlotProps = CreateSlotsAndSlotProps<
SpeedDialActionSlots,
{
/**
* Props forwarded to the fab slot.
* By default, the avaible props are based on the [Fab](https://mui.com/material-ui/api/fab/#props) component.
*/
fab: SlotProps<
React.ElementType<FabProps>,
SpeedDialActionFabSlotPropsOverrides,
SpeedDialActionOwnerState
>;
/**
* Props forwarded to the tooltip slot.
* By default, the avaible props are based on the [Tooltip](https://mui.com/material-ui/api/tooltip/#props) component.
*/
tooltip: SlotProps<
React.ElementType<TooltipProps>,
SpeedDialActionTooltipSlotPropsOverrides,
SpeedDialActionOwnerState
>;
/**
* Props forwarded to the static tooltip slot.
* By default, the avaible props are based on a span element.
*/
staticTooltip: SlotProps<
'span',
SpeedDialActionStaticTooltipSlotPropsOverrides,
SpeedDialActionOwnerState
>;
/**
* Props forwarded to the static tooltip label slot.
* By default, the avaible props are based on a span element.
*/
staticTooltipLabel: SlotProps<
'span',
SpeedDialActionStaticTooltipLabelSlotPropsOverrides,
SpeedDialActionOwnerState
>;
}
>;

export interface SpeedDialActionProps
extends Omit<StandardProps<Partial<TooltipProps>, 'children'>, 'slotProps' | 'slots'>,
SpeedDialActionSlotsAndSlotProps {
/**
* Override or extend the styles applied to the component.
*/
Expand Down Expand Up @@ -61,3 +134,6 @@ export interface SpeedDialActionProps extends StandardProps<Partial<TooltipProps
* - inherits [Tooltip API](https://mui.com/material-ui/api/tooltip/)
*/
export default function SpeedDialAction(props: SpeedDialActionProps): React.JSX.Element;

export interface SpeedDialActionOwnerState
extends Omit<SpeedDialActionProps, 'slots' | 'slotProps'> {}
132 changes: 91 additions & 41 deletions packages/mui-material/src/SpeedDialAction/SpeedDialAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,6 +156,8 @@ const SpeedDialAction = React.forwardRef(function SpeedDialAction(inProps, ref)
tooltipOpen: tooltipOpenProp = false,
tooltipPlacement = 'left',
tooltipTitle,
slots = {},
slotProps = {},
...other
} = props;

Expand All @@ -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: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
style: {
style: transitionStyle

No need to spread the FabProps.style, the slotProps.fab.style (from FabProps) will be merged by useSlot.

...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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should goes into getSlotProps, so that slotProps.tooltip.onOpen does not replace the handleTooltipClose.

    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>
);
}

Expand All @@ -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>
);
});

Expand Down Expand Up @@ -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.
*/
Expand Down
Loading
Loading