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

Fixes for popover in nav bar and z-index on ControlledPopover #786

Merged
merged 3 commits into from
Sep 18, 2024
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 @@ -4,7 +4,10 @@ import {
TextInputProps,
ValueAndOnValueChangeProps,
} from "@stenajs-webui/forms";
import { ControlledPopover } from "@stenajs-webui/tooltip";
import {
ControlledPopover,
ControlledPopoverProps,
} from "@stenajs-webui/tooltip";
import { isAfter } from "date-fns";
import * as React from "react";
import { useMemo, useRef } from "react";
Expand All @@ -27,7 +30,8 @@ import { defaultMaxDate } from "../../../config/DefaultMaxDate";
export interface DateRangeDualTextInputProps<TData = unknown>
extends ValueAndOnValueChangeProps<DateRange>,
OptionalMinMaxDatesAsString,
Pick<DualTextInputProps, "widthLeft" | "widthRight" | "variant"> {
Pick<DualTextInputProps, "widthLeft" | "widthRight" | "variant">,
Pick<ControlledPopoverProps, "zIndex" | "appendTo"> {
onEsc?: () => void;
onEnter?: () => void;
onBlur?: () => void;
Expand All @@ -50,6 +54,8 @@ export function DateRangeDualTextInput<TData>({
widthRight = 128,
variant,
disabled,
zIndex,
appendTo,
}: DateRangeDualTextInputProps<TData>) {
const { startDate, endDate } = value || {};

Expand Down Expand Up @@ -121,6 +127,8 @@ export function DateRangeDualTextInput<TData>({
hideArrow
restoreFocus={false}
returnFocus={false}
zIndex={zIndex}
appendTo={appendTo}
renderTrigger={(props) => (
<Box {...props}>
<DualTextInput
Expand Down
32 changes: 16 additions & 16 deletions packages/panels/src/components/nav-bar/NavBarButton.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { FlatButton, FlatButtonProps } from "@stenajs-webui/elements";
import * as React from "react";
import { forwardRef } from "react";
import cx from "classnames";
import styles from "./NavBarButton.module.css";

export interface NavBarButtonProps extends FlatButtonProps {
selected?: boolean;
}

export const NavBarButton: React.FC<NavBarButtonProps> = ({
selected,
className,
...buttonProps
}) => {
return (
<FlatButton
{...buttonProps}
className={cx(
styles.navBarButton,
selected && styles.selected,
className
)}
/>
);
};
export const NavBarButton = forwardRef<HTMLButtonElement, NavBarButtonProps>(
function ({ selected, className, ...buttonProps }, ref) {
return (
<FlatButton
{...buttonProps}
ref={ref}
className={cx(
styles.navBarButton,
selected && styles.selected,
className
)}
/>
);
}
);
37 changes: 22 additions & 15 deletions packages/panels/src/components/nav-bar/NavBarPopoverButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as React from "react";
import { ReactNode } from "react";
import { NavBarButton, NavBarButtonProps } from "./NavBarButton";
import { Popover } from "@stenajs-webui/tooltip";
import { Box, Row } from "@stenajs-webui/core";
import {
ControlledPopover,
ControlledPopoverProps,
} from "@stenajs-webui/tooltip";
import { Box, useBoolean } from "@stenajs-webui/core";

type RenderProp = (args: RenderPropArgs) => ReactNode;

Expand All @@ -11,30 +14,34 @@ interface RenderPropArgs {
}

export interface NavBarPopoverButtonProps
extends Omit<NavBarButtonProps, "onClick" | "content"> {
extends Omit<NavBarButtonProps, "onClick" | "content">,
Pick<ControlledPopoverProps, "zIndex" | "appendTo"> {
content?: RenderProp;
}

export const NavBarPopoverButton: React.FC<NavBarPopoverButtonProps> = ({
content,
children,
appendTo,
zIndex,
...navBarButtonProps
}) => {
const [isOpen, , close, toggle] = useBoolean(false);

return (
<Popover
<ControlledPopover
renderTrigger={(props) => (
<Row {...props}>
<NavBarButton {...navBarButtonProps} />
</Row>
<NavBarButton {...navBarButtonProps} {...props} onClick={toggle} />
)}
trigger={"click"}
open={isOpen}
onRequestClose={close}
zIndex={zIndex}
appendTo={appendTo}
>
{({ onRequestClose }) => (
<Box>
{content && content({ close: onRequestClose })}
{children}
</Box>
)}
</Popover>
<Box>
{content && content({ close })}
{children}
</Box>
</ControlledPopover>
);
};
8 changes: 6 additions & 2 deletions packages/tooltip/src/components/popover/ControlledPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface ControlledPopoverProps extends PropsWithChildren {
disablePadding?: boolean;
restoreFocus?: boolean;
returnFocus?: boolean;
appendTo?: HTMLElement | null | React.MutableRefObject<HTMLElement | null>;
zIndex?: number;
}

const ARROW_WIDTH = 12;
Expand All @@ -44,6 +46,8 @@ export const ControlledPopover: React.FC<ControlledPopoverProps> = ({
onRequestClose,
restoreFocus,
returnFocus,
appendTo,
zIndex,
}) => {
const arrowRef = useRef(null);

Expand Down Expand Up @@ -88,7 +92,7 @@ export const ControlledPopover: React.FC<ControlledPopoverProps> = ({
{renderTrigger({ ref: refs.setReference, ...getReferenceProps() })}

{isMounted && (
<FloatingPortal>
<FloatingPortal root={appendTo}>
<FloatingFocusManager
context={context}
modal={false}
Expand All @@ -97,7 +101,7 @@ export const ControlledPopover: React.FC<ControlledPopoverProps> = ({
>
<div
ref={refs.setFloating}
style={floatingStyles}
style={{ zIndex, ...floatingStyles }}
{...getFloatingProps}
>
<div
Expand Down
Loading