Skip to content
Open
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: 5 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export type PositionTransform =
| ((popoverState: PopoverState) => PositionTransformValue);

export type PopoverPosition = 'left' | 'right' | 'top' | 'bottom';
export type PopoverAlign = 'start' | 'center' | 'end';
export type PopoverAlignValue = 'start' | 'center' | 'end';

export type PopoverAlign =
| PopoverAlignValue
| ((popoverPosition: PopoverPosition) => PopoverAlignValue);

export type UseArrowContainerProps = {
childRect: Rect;
Expand Down
32 changes: 17 additions & 15 deletions src/usePopover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export const usePopover = ({
const popoverRef = useElementRef({
containerClassName:
containerClassName != null &&
containerClassName.length > 0 &&
containerClassName !== 'react-tiny-popover-container'
containerClassName.length > 0 &&
containerClassName !== 'react-tiny-popover-container'
? `react-tiny-popover-container ${containerClassName}`
: 'react-tiny-popover-container',
containerStyle: POPOVER_STYLE,
Expand All @@ -74,18 +74,18 @@ export const usePopover = ({
const { top: inputTop, left: inputLeft } =
typeof transform === 'function'
? transform({
childRect,
popoverRect,
parentRect,
boundaryRect,
padding,
align,
nudgedTop: 0,
nudgedLeft: 0,
boundaryInset,
violations: EMPTY_RECT,
hasViolations: false,
})
childRect,
popoverRect,
parentRect,
boundaryRect,
padding,
align,
nudgedTop: 0,
nudgedLeft: 0,
boundaryInset,
violations: EMPTY_RECT,
hasViolations: false,
})
: transform;

const finalLeft = Math.round(parentRect.left + inputLeft - scoutRect.left);
Expand Down Expand Up @@ -119,13 +119,15 @@ export const usePopover = ({
const isExhausted = positionIndex === positions.length;
const position = isExhausted ? positions[0] : positions[positionIndex];

const calculatedAlign = typeof align === 'function' ? align(position) : align;

const { rect, boundaryViolation } = getNewPopoverRect(
{
childRect,
popoverRect,
boundaryRect,
position,
align,
align: calculatedAlign,
padding,
reposition,
},
Expand Down