Skip to content
Closed
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
14 changes: 12 additions & 2 deletions packages/ui/src/dialog/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mergeProps, useRender } from '@base-ui/react';
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import { useDialogScrollChrome } from './scroll-chrome-context';
import styles from './style.module.css';
import type { FooterProps } from './types';

Expand All @@ -9,14 +10,23 @@ import type { FooterProps } from './types';
* action buttons.
*/
const Footer = forwardRef< HTMLDivElement, FooterProps >( function DialogFooter(
{ className, render, ...props },
{ className, render, sticky = true, ...props },
ref
) {
const scrollChrome = useDialogScrollChrome();

const element = useRender( {
render,
ref,
props: mergeProps< 'div' >( props, {
className: clsx( styles.footer, className ),
className: clsx(
styles.footer,
sticky && styles.footerSticky,
sticky &&
scrollChrome?.footerHasContentBelow &&
styles.footerHasContentBelow,
className
),
} ),
} );

Expand Down
10 changes: 9 additions & 1 deletion packages/ui/src/dialog/header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mergeProps, useRender } from '@base-ui/react';
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import { useDialogScrollChrome } from './scroll-chrome-context';
import styles from './style.module.css';
import type { HeaderProps } from './types';

Expand All @@ -12,11 +13,18 @@ const Header = forwardRef< HTMLDivElement, HeaderProps >( function DialogHeader(
{ className, render, ...props },
ref
) {
const scrollChrome = useDialogScrollChrome();

const element = useRender( {
render,
ref,
props: mergeProps< 'div' >( props, {
className: clsx( styles.header, className ),
className: clsx(
styles.header,
scrollChrome?.headerScrolledFromTop &&
styles.headerHasScrolledContent,
className
),
} ),
} );

Expand Down
17 changes: 13 additions & 4 deletions packages/ui/src/dialog/popup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Dialog as _Dialog } from '@base-ui/react/dialog';
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import type { UIEvent } from 'react';
import {
forwardRef,
useCallback,
useLayoutEffect,
useState,
} from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';
import {
type ThemeProvider as ThemeProviderType,
Expand Down Expand Up @@ -69,10 +75,13 @@
initialFocus={ resolvedInitialFocus }
finalFocus={ finalFocus }
{ ...props }
onScroll={ handleScroll }

Check failure on line 78 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Check

Cannot find name 'handleScroll'.

Check failure on line 78 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / All

Cannot find name 'handleScroll'.

Check failure on line 78 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Cannot find name 'handleScroll'.
>
<DialogValidationProvider>
{ children }
</DialogValidationProvider>
<DialogScrollChromeContext.Provider value={ scrollChrome }>

Check failure on line 80 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Check

Cannot find name 'scrollChrome'.

Check failure on line 80 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Check

Cannot find name 'DialogScrollChromeContext'.

Check failure on line 80 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / All

Cannot find name 'scrollChrome'.

Check failure on line 80 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / All

Cannot find name 'DialogScrollChromeContext'.

Check failure on line 80 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Cannot find name 'scrollChrome'.

Check failure on line 80 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Cannot find name 'DialogScrollChromeContext'.
<DialogValidationProvider>
{ children }
</DialogValidationProvider>
</DialogScrollChromeContext.Provider>

Check failure on line 84 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Check

Cannot find name 'DialogScrollChromeContext'.

Check failure on line 84 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / All

Cannot find name 'DialogScrollChromeContext'.

Check failure on line 84 in packages/ui/src/dialog/popup.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Cannot find name 'DialogScrollChromeContext'.
</_Dialog.Popup>
</ThemeProvider>
</>
Expand Down
23 changes: 23 additions & 0 deletions packages/ui/src/dialog/scroll-chrome-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createContext, useContext } from '@wordpress/element';

export type DialogScrollChromeContextValue = {
/**
* True when the popup is scrolled away from the top (content sits under the header).
*/
headerScrolledFromTop: boolean;
/**
* True when more content exists below the visible area (content can scroll under the footer).
*/
footerHasContentBelow: boolean;
};

export const DialogScrollChromeContext =
createContext< DialogScrollChromeContextValue | null >( null );

/**
* Scroll chrome for sticky `Dialog.Header` / `Dialog.Footer` borders. Returns `null`
* when used outside `Dialog.Popup`.
*/
export function useDialogScrollChrome(): DialogScrollChromeContextValue | null {
return useContext( DialogScrollChromeContext );
}
27 changes: 26 additions & 1 deletion packages/ui/src/dialog/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,21 @@
}

.header {
position: sticky;
top: 0;
z-index: 1;
isolation: isolate;
display: flex;
align-items: center;
gap: var(--wpds-dimension-gap-sm);
margin-bottom: var(--wpds-dimension-gap-lg);
box-sizing: border-box;
border-block-end: 1px solid transparent;
background-color: var(--wpds-color-bg-surface-neutral-strong);
}

.headerHasScrolledContent {
border-block-end-color: var(--wpds-color-stroke-surface-neutral);
}

.title {
Expand All @@ -134,6 +145,20 @@
align-items: center;
gap: var(--wpds-dimension-gap-sm);
margin-top: var(--wpds-dimension-gap-lg);
padding-top: var(--wpds-dimension-padding-lg);
padding-block: var(--wpds-dimension-padding-lg);
box-sizing: border-box;
border-block-start: 1px solid transparent;
background-color: var(--wpds-color-bg-surface-neutral-strong);
}

.footerSticky {
position: sticky;
bottom: 0;
z-index: 1;
isolation: isolate;
}

.footerHasContentBelow {
border-block-start-color: var(--wpds-color-stroke-surface-neutral);
}
}
8 changes: 8 additions & 0 deletions packages/ui/src/dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export interface FooterProps extends ComponentProps< 'div' > {
* The content to be rendered inside the component.
*/
children?: ReactNode;

/**
* When `true`, the footer stays pinned to the bottom of the dialog while
* the body scrolls. When `false`, the footer scrolls with the content.
*
* @default true
*/
sticky?: boolean;
}

export interface HeaderProps extends ComponentProps< 'div' > {
Expand Down
Loading