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

[popups] Add data-closed style hook #882

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions docs/src/app/experiments/infotip.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.popup {
background: lightgray;
padding: 10px;
transition: opacity 0.5s;

&[data-entering],
&[data-exiting] {
opacity: 0;
}
}
28 changes: 28 additions & 0 deletions docs/src/app/experiments/infotips.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { Popover } from '@base-ui-components/react/popover';
import classes from './infotip.module.css';

function Infotip() {
return (
<Popover.Root openOnHover delay={0}>
<Popover.Trigger
style={{ width: 44, height: 44, background: 'lightgray', border: 'none' }}
>
?
</Popover.Trigger>
<Popover.Positioner side="left" alignment="start" sideOffset={10}>
<Popover.Popup className={classes.popup}>Infotip</Popover.Popup>
</Popover.Positioner>
</Popover.Root>
);
}

export default function Page() {
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
{[...Array(20)].map((_, i) => (
<Infotip key={i} />
))}
</div>
);
}
4 changes: 2 additions & 2 deletions packages/react/src/alert-dialog/popup/AlertDialogPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const AlertDialogPopup = React.forwardRef(function AlertDialogPopup(
const state: AlertDialogPopup.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also use the same term internally?

nestedOpenDialogCount,
transitionStatus,
}),
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace AlertDialogPopup {

export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
nestedOpenDialogCount: number;
transitionStatus: TransitionStatus;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/dialog/popup/DialogPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const DialogPopup = React.forwardRef(function DialogPopup(
const state: DialogPopup.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
nestedOpenDialogCount,
transitionStatus,
}),
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace DialogPopup {

export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
nestedOpenDialogCount: number;
transitionStatus: TransitionStatus;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/menu/positioner/MenuPositioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const MenuPositioner = React.forwardRef(function MenuPositioner(
const state: MenuPositioner.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
side: positioner.side,
alignment: positioner.alignment,
}),
Expand Down Expand Up @@ -155,7 +155,7 @@ const MenuPositioner = React.forwardRef(function MenuPositioner(
export namespace MenuPositioner {
export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
side: Side;
alignment: 'start' | 'end' | 'center';
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/popover/backdrop/PopoverBackdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const PopoverBackdrop = React.forwardRef(function PopoverBackdrop(
const state: PopoverBackdrop.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
transitionStatus,
}),
[open, mounted, transitionStatus],
Expand All @@ -75,7 +75,7 @@ const PopoverBackdrop = React.forwardRef(function PopoverBackdrop(
namespace PopoverBackdrop {
export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
transitionStatus: TransitionStatus;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/popover/positioner/PopoverPositioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const PopoverPositioner = React.forwardRef(function PopoverPositioner(
const state: PopoverPositioner.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
side: positioner.side,
alignment: positioner.alignment,
}),
Expand Down Expand Up @@ -106,7 +106,7 @@ const PopoverPositioner = React.forwardRef(function PopoverPositioner(
namespace PopoverPositioner {
export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
side: Side;
alignment: Alignment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const PreviewCardBackdrop = React.forwardRef(function PreviewCardBackdrop(
const state: PreviewCardBackdrop.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
transitionStatus,
}),
[open, mounted, transitionStatus],
Expand All @@ -73,7 +73,7 @@ const PreviewCardBackdrop = React.forwardRef(function PreviewCardBackdrop(
namespace PreviewCardBackdrop {
export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
transitionStatus: TransitionStatus;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const PreviewCardPositioner = React.forwardRef(function PreviewCardPositioner(
const state: PreviewCardPositioner.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
side: positioner.side,
alignment: positioner.alignment,
}),
Expand Down Expand Up @@ -120,7 +120,7 @@ const PreviewCardPositioner = React.forwardRef(function PreviewCardPositioner(
namespace PreviewCardPositioner {
export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
side: Side;
alignment: Alignment;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/select/backdrop/SelectBackdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const SelectBackdrop = React.forwardRef(function SelectBackdrop(
const state: SelectBackdrop.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
transitionStatus,
}),
[open, mounted, transitionStatus],
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace SelectBackdrop {

export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
transitionStatus: TransitionStatus;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/select/positioner/SelectPositioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const SelectPositioner = React.forwardRef(function SelectPositioner(
const state: SelectPositioner.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
side: positioner.side,
alignment: positioner.alignment,
}),
Expand Down Expand Up @@ -103,7 +103,7 @@ const SelectPositioner = React.forwardRef(function SelectPositioner(
namespace SelectPositioner {
export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
side: Side | 'none';
alignment: Alignment;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/tooltip/positioner/TooltipPositioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const TooltipPositioner = React.forwardRef(function TooltipPositioner(
const state: TooltipPositioner.State = React.useMemo(
() => ({
open,
mounted,
hidden: !mounted,
side: positioner.side,
alignment: positioner.alignment,
}),
Expand Down Expand Up @@ -115,7 +115,7 @@ const TooltipPositioner = React.forwardRef(function TooltipPositioner(
namespace TooltipPositioner {
export interface State {
open: boolean;
mounted: boolean;
hidden: boolean;
side: Side;
alignment: Alignment;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/utils/popupOpenStateMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export const popupOpenStateMapping = {
}
return null;
},
mounted(value) {
if (!value) {
hidden(value) {
if (value) {
return POPUP_CLOSED_HOOK;
}
return null;
},
} satisfies CustomStyleHookMapping<{
open: boolean;
mounted: boolean;
hidden: boolean;
}>;