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

[Popper] Expose the sx prop #31833

Merged
merged 4 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions docs/pages/api-docs/popper.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
"default": "{}"
},
"popperRef": { "type": { "name": "custom", "description": "ref" } },
"sx": {
"type": {
"name": "union",
"description": "Array&lt;func<br>&#124;&nbsp;object<br>&#124;&nbsp;bool&gt;<br>&#124;&nbsp;func<br>&#124;&nbsp;object"
}
},
"transition": { "type": { "name": "bool" } }
},
"name": "Popper",
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/material-ui/api/popper.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
"default": "{}"
},
"popperRef": { "type": { "name": "custom", "description": "ref" } },
"sx": {
"type": {
"name": "union",
"description": "Array&lt;func<br>&#124;&nbsp;object<br>&#124;&nbsp;bool&gt;<br>&#124;&nbsp;func<br>&#124;&nbsp;object"
}
},
"transition": { "type": { "name": "bool" } }
},
"name": "Popper",
Expand Down
1 change: 1 addition & 0 deletions docs/translations/api-docs/popper/popper.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"placement": "Popper placement.",
"popperOptions": "Options provided to the <a href=\"https://popper.js.org/docs/v2/constructors/#options\"><code>Popper.js</code></a> instance.",
"popperRef": "A ref that points to the used popper instance.",
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/the-sx-prop/\">`sx` page</a> for more details.",
"transition": "Help supporting a react-transition-group/Transition component.",
"direction": "Direction of the text."
},
Expand Down
31 changes: 25 additions & 6 deletions packages/mui-material/src/Popper/Popper.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import PopperUnstyled, { PopperUnstyledProps } from '@mui/base/PopperUnstyled';
import { Direction, SxProps, useThemeWithoutDefault as useTheme } from '@mui/system';
import { HTMLElementType, refType } from '@mui/utils';
import { Direction, useThemeWithoutDefault as useTheme } from '@mui/system';
import useThemeProps from '../styles/useThemeProps';
import PropTypes from 'prop-types';
import * as React from 'react';
import { styled, Theme, useThemeProps } from '../styles';

export type PopperProps = Omit<PopperUnstyledProps, 'direction'> & {
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
};

export type PopperProps = Omit<PopperUnstyledProps, 'direction'>;
const PopperRoot = styled(PopperUnstyled, {
name: 'MuiPopper',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});

/**
*
Expand All @@ -25,7 +36,7 @@ const Popper = React.forwardRef(function Popper(
) {
const theme = useTheme<{ direction?: Direction }>();
const props = useThemeProps({ props: inProps, name: 'MuiPopper' });
return <PopperUnstyled direction={theme?.direction} {...props} ref={ref} />;
return <PopperRoot direction={theme?.direction} {...props} ref={ref} />;
});

Popper.propTypes /* remove-proptypes */ = {
Expand Down Expand Up @@ -161,6 +172,14 @@ Popper.propTypes /* remove-proptypes */ = {
* A ref that points to the used popper instance.
*/
popperRef: refType,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])),
PropTypes.func,
PropTypes.object,
]),
/**
* Help supporting a react-transition-group/Transition component.
* @default false
Expand Down