Skip to content

Commit 8c62558

Browse files
authored
Merge pull request #709 from strapi/enh/add-popover-placement
Add placement props to Popover component
2 parents 67a281f + 04a3f73 commit 8c62558

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

packages/strapi-design-system/src/Popover/Popover.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ import { Portal } from '../Portal';
88

99
import { useIntersection } from '../helpers/useIntersection';
1010

11+
export const POPOVER_PLACEMENTS = [
12+
'top',
13+
'top-start',
14+
'top-end',
15+
'right',
16+
'right-start',
17+
'right-end',
18+
'bottom',
19+
'bottom-start',
20+
'bottom-end',
21+
'left',
22+
'left-start',
23+
'left-end',
24+
];
25+
1126
const PopoverWrapper = styled(Box)`
1227
box-shadow: ${({ theme }) => theme.shadows.filterShadow};
1328
z-index: 4;
@@ -37,12 +52,22 @@ const PopoverScrollable = styled(Box)`
3752
}
3853
`;
3954

40-
const PopoverContent = ({ source, children, spacing, fullWidth, onReachEnd, intersectionId, centered, ...props }) => {
55+
const PopoverContent = ({
56+
source,
57+
children,
58+
spacing,
59+
fullWidth,
60+
placement,
61+
onReachEnd,
62+
intersectionId,
63+
centered,
64+
...props
65+
}) => {
4166
const popoverRef = React.useRef(null);
4267
const [width, setWidth] = React.useState(undefined);
4368
const { x, y, reference, floating, strategy } = useFloating({
4469
strategy: 'fixed',
45-
placement: centered ? 'bottom' : 'bottom-start',
70+
placement: centered ? 'bottom' : placement,
4671
middleware: [
4772
offset({
4873
mainAxis: spacing,
@@ -102,6 +127,7 @@ const popoverDefaultProps = {
102127
intersectionId: undefined,
103128
onReachEnd: undefined,
104129
centered: false,
130+
placement: 'bottom-start',
105131
};
106132

107133
const popoverProps = {
@@ -122,6 +148,10 @@ const popoverProps = {
122148
* The callback invoked after a scroll to the bottom of the popover content.
123149
*/
124150
onReachEnd: PropTypes.func,
151+
/**
152+
* The popover position
153+
*/
154+
placement: PropTypes.oneOf(POPOVER_PLACEMENTS),
125155
/**
126156
* A React ref. Used to defined the position of the popover.
127157
*/

packages/strapi-design-system/src/SimpleMenu/SimpleMenu.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Typography } from '../Typography';
77
import { Box } from '../Box';
88
import { Flex } from '../Flex';
99
import { Button } from '../Button';
10-
import { Popover } from '../Popover';
10+
import { Popover, POPOVER_PLACEMENTS } from '../Popover';
1111
import { getOptionStyle } from './utils';
1212
import { useId } from '../helpers/useId';
1313
import { KeyboardKeys } from '../helpers/keyboardKeys';
@@ -97,6 +97,7 @@ export const SimpleMenu = ({
9797
onOpen = () => {},
9898
onClose = () => {},
9999
size,
100+
popoverPlacement,
100101
...props
101102
}) => {
102103
const menuButtonRef = useRef();
@@ -211,7 +212,7 @@ export const SimpleMenu = ({
211212
{label}
212213
</Component>
213214
{visible && (
214-
<Popover onBlur={handleBlur} source={menuButtonRef} spacing={4}>
215+
<Popover onBlur={handleBlur} placement={popoverPlacement} source={menuButtonRef} spacing={4}>
215216
<Box role="menu" as="ul" padding={1} id={menuId}>
216217
{childrenClone}
217218
</Box>
@@ -228,6 +229,7 @@ SimpleMenu.defaultProps = {
228229
SimpleMenu.displayName = 'SimpleMenu';
229230

230231
SimpleMenu.defaultProps = {
232+
popoverPlacement: 'bottom-start',
231233
size: 'M',
232234
};
233235

@@ -238,6 +240,7 @@ SimpleMenu.propTypes = {
238240
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.element]).isRequired,
239241
onClose: PropTypes.func,
240242
onOpen: PropTypes.func,
243+
popoverPlacement: PropTypes.oneOf(POPOVER_PLACEMENTS),
241244

242245
/**
243246
* Size of the trigger button.

packages/strapi-design-system/src/v2/SimpleMenu/SimpleMenu.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Box } from '../../Box';
77
import { Flex } from '../../Flex';
88
import { Button } from '../../Button';
99
import { BaseLink } from '../../BaseLink';
10-
import { Popover } from '../../Popover';
10+
import { Popover, POPOVER_PLACEMENTS } from '../../Popover';
1111
import { getOptionStyle } from './utils';
1212
import { useId } from '../../helpers/useId';
1313
import { KeyboardKeys } from '../../helpers/keyboardKeys';
@@ -97,6 +97,7 @@ export const SimpleMenu = ({
9797
onOpen = () => {},
9898
onClose = () => {},
9999
size,
100+
popoverPlacement,
100101
...props
101102
}) => {
102103
const menuButtonRef = useRef();
@@ -211,7 +212,7 @@ export const SimpleMenu = ({
211212
{label}
212213
</Component>
213214
{visible && (
214-
<Popover onBlur={handleBlur} source={menuButtonRef} spacing={4}>
215+
<Popover onBlur={handleBlur} placement={popoverPlacement} source={menuButtonRef} spacing={4}>
215216
<Box role="menu" as="ul" padding={1} id={menuId}>
216217
{childrenClone}
217218
</Box>
@@ -228,6 +229,7 @@ SimpleMenu.defaultProps = {
228229
SimpleMenu.displayName = 'SimpleMenu';
229230

230231
SimpleMenu.defaultProps = {
232+
popoverPlacement: 'bottom-start',
231233
size: 'M',
232234
};
233235

@@ -238,6 +240,7 @@ SimpleMenu.propTypes = {
238240
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.element]).isRequired,
239241
onClose: PropTypes.func,
240242
onOpen: PropTypes.func,
243+
popoverPlacement: PropTypes.oneOf(POPOVER_PLACEMENTS),
241244

242245
/**
243246
* Size of the trigger button.

0 commit comments

Comments
 (0)