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

[Popover] add PopoverPosition enum = Position + auto values #3156

Merged
merged 1 commit into from
Nov 15, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

import { Placement } from "popper.js";
import { Position } from "../../common/position";
import { PopoverPosition } from "./popoverSharedProps";

/**
* Convert a position to a placement.
* @param position the position to convert
*/
export function positionToPlacement(position: Position | "auto" | "auto-start" | "auto-end"): Placement {
export function positionToPlacement(position: PopoverPosition): Placement {
/* istanbul ignore next */
switch (position) {
case Position.TOP_LEFT:
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/components/popover/popoverSharedProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import { IOverlayableProps } from "../overlay/overlay";
// re-export this symbol for library consumers
export { PopperModifiers };

/** `Position` with `"auto"` values, used by `Popover` and `Tooltip`. */
export const PopoverPosition = {
...Position,
AUTO: "auto" as "auto",
AUTO_END: "auto-end" as "auto-end",
AUTO_START: "auto-start" as "auto-start",
};
export type PopoverPosition = typeof PopoverPosition[keyof typeof PopoverPosition];

/** Props shared between `Popover` and `Tooltip`. */
export interface IPopoverSharedProps extends IOverlayableProps, IProps {
/**
Expand Down Expand Up @@ -109,7 +118,7 @@ export interface IPopoverSharedProps extends IOverlayableProps, IProps {
* user scrolls around.
* @default "auto"
*/
position?: Position | "auto" | "auto-start" | "auto-end";
position?: PopoverPosition;

/**
* Space-delimited string of class names applied to the target element.
Expand Down
40 changes: 19 additions & 21 deletions packages/docs-app/src/examples/core-examples/popoverExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
MenuItem,
Popover,
PopoverInteractionKind,
Position,
PopoverPosition,
RadioGroup,
Slider,
Switch,
Expand All @@ -42,22 +42,22 @@ const INTERACTION_KINDS = [
{ label: "Hover (target only)", value: PopoverInteractionKind.HOVER_TARGET_ONLY.toString() },
];

const VALID_POSITIONS: Array<Position | "auto" | "auto-start" | "auto-end"> = [
"auto",
"auto-start",
"auto-end",
Position.TOP_LEFT,
Position.TOP,
Position.TOP_RIGHT,
Position.RIGHT_TOP,
Position.RIGHT,
Position.RIGHT_BOTTOM,
Position.BOTTOM_LEFT,
Position.BOTTOM,
Position.BOTTOM_RIGHT,
Position.LEFT_TOP,
Position.LEFT,
Position.LEFT_BOTTOM,
const VALID_POSITIONS: PopoverPosition[] = [
PopoverPosition.AUTO,
PopoverPosition.AUTO_START,
PopoverPosition.AUTO_END,
PopoverPosition.TOP_LEFT,
PopoverPosition.TOP,
PopoverPosition.TOP_RIGHT,
PopoverPosition.RIGHT_TOP,
PopoverPosition.RIGHT,
PopoverPosition.RIGHT_BOTTOM,
PopoverPosition.BOTTOM_LEFT,
PopoverPosition.BOTTOM,
PopoverPosition.BOTTOM_RIGHT,
PopoverPosition.LEFT_TOP,
PopoverPosition.LEFT,
PopoverPosition.LEFT_BOTTOM,
];

const POPPER_DOCS = "https://popper.js.org/popper-documentation.html#modifiers";
Expand All @@ -71,7 +71,7 @@ export interface IPopoverExampleState {
isOpen?: boolean;
minimal?: boolean;
modifiers?: PopperJS.Modifiers;
position?: Position | "auto" | "auto-start" | "auto-end";
position?: PopoverPosition;
sliderValue?: number;
usePortal?: boolean;
}
Expand Down Expand Up @@ -101,9 +101,7 @@ export class PopoverExample extends React.PureComponent<IExampleProps, IPopoverE
const hasBackdrop = this.state.hasBackdrop && interactionKind === PopoverInteractionKind.CLICK;
this.setState({ interactionKind, hasBackdrop });
});
private handlePositionChange = handleStringChange((position: Position | "auto" | "auto-start" | "auto-end") =>
this.setState({ position }),
);
private handlePositionChange = handleStringChange((position: PopoverPosition) => this.setState({ position }));
private handleBoundaryChange = handleStringChange((boundary: PopperJS.Boundary) =>
this.setState({
modifiers: {
Expand Down