-
Notifications
You must be signed in to change notification settings - Fork 839
Forms: Responses Inbox header improvement #45748
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
232becc
Forms responses header with tabs
lezama a4f189c
changelog
lezama 35c0e02
Move Tabs component to forms package
lezama 4be3616
remove margin
lezama 70ec224
Improve inbox dataviews layout for mobile screens
lezama 1ef019c
Update pnpm-lock.yaml
lezama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/packages/forms/changelog/update-forms-responses-header-modernization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: changed | ||
|
|
||
| Forms: modernize responses header with tabs, compact number formatting, and improved mobile layout. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
projects/packages/forms/src/dashboard/components/tabs/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { List } from './list.tsx'; | ||
| import { Panel } from './panel.tsx'; | ||
| import { Root } from './root.tsx'; | ||
| import { Tab } from './tab.tsx'; | ||
|
|
||
| export { Root, List, Panel, Tab }; | ||
137 changes: 137 additions & 0 deletions
137
projects/packages/forms/src/dashboard/components/tabs/list.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { Tabs as BaseUITabs } from '@base-ui-components/react/tabs'; | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useMergeRefs } from '@wordpress/compose'; | ||
| import clsx from 'clsx'; | ||
| import { forwardRef, useState, useEffect, useCallback, isValidElement, cloneElement } from 'react'; | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import './style.scss'; | ||
| import type { TabListProps } from './types.ts'; | ||
|
|
||
| const DEFAULT_SCROLL_MARGIN = 0; | ||
|
|
||
| /** | ||
| * Groups the individual tab buttons. | ||
| * | ||
| * `Tabs` is a collection of React components that combine to render | ||
| * an [ARIA-compliant tabs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/). | ||
| */ | ||
| export const List = forwardRef< HTMLDivElement, TabListProps >( function TabList( | ||
| { children, density = 'default', className, activateOnFocus, render, ...otherProps }, | ||
| forwardedRef | ||
| ) { | ||
| const [ listEl, setListEl ] = useState< HTMLDivElement | null >( null ); | ||
| const [ overflow, setOverflow ] = useState< { | ||
| first: boolean; | ||
| last: boolean; | ||
| } >( { | ||
| first: false, | ||
| last: false, | ||
| } ); | ||
|
|
||
| /** | ||
| * Checks if list is overflowing when it scrolls or resizes. | ||
| */ | ||
| useEffect( () => { | ||
| if ( ! listEl ) { | ||
| return; | ||
| } | ||
|
|
||
| // Grab a local reference to the list element to ensure it remains stable | ||
| // during the effect and the event listeners. | ||
| const localListEl = listEl; | ||
|
|
||
| /** | ||
| * Measures if the tab list is overflowing horizontally. | ||
| */ | ||
| function measureOverflow() { | ||
| if ( ! localListEl ) { | ||
| setOverflow( { | ||
| first: false, | ||
| last: false, | ||
| } ); | ||
| return; | ||
| } | ||
|
|
||
| const { scrollWidth, clientWidth, scrollLeft } = localListEl; | ||
|
|
||
| setOverflow( { | ||
| first: scrollLeft > DEFAULT_SCROLL_MARGIN, | ||
| last: scrollLeft + clientWidth < scrollWidth - DEFAULT_SCROLL_MARGIN, | ||
| } ); | ||
| } | ||
|
|
||
| const resizeObserver = new ResizeObserver( measureOverflow ); | ||
| resizeObserver.observe( localListEl ); | ||
| let scrollTick = false; | ||
| /** | ||
| * Throttles overflow measurement on scroll using requestAnimationFrame. | ||
| */ | ||
| function throttleMeasureOverflowOnScroll() { | ||
| if ( ! scrollTick ) { | ||
| requestAnimationFrame( () => { | ||
| measureOverflow(); | ||
| scrollTick = false; | ||
| } ); | ||
| scrollTick = true; | ||
| } | ||
| } | ||
| localListEl.addEventListener( 'scroll', throttleMeasureOverflowOnScroll, { passive: true } ); | ||
|
|
||
| // Initial check. | ||
| measureOverflow(); | ||
|
|
||
| return () => { | ||
| localListEl.removeEventListener( 'scroll', throttleMeasureOverflowOnScroll ); | ||
| resizeObserver.disconnect(); | ||
| }; | ||
| }, [ listEl ] ); | ||
|
|
||
| const setListElRef = useCallback( el => setListEl( el ), [] ); | ||
| const mergedListRef = useMergeRefs( [ forwardedRef, setListElRef ] ); | ||
|
|
||
| const renderTabList = useCallback( | ||
| ( props, state ) => { | ||
| // Fallback to -1 to prevent browsers from making the tablist | ||
| // tabbable when it is a scrolling container. | ||
| const newProps = { | ||
| ...props, | ||
| tabIndex: props.tabIndex ?? -1, | ||
| }; | ||
|
|
||
| if ( isValidElement( render ) ) { | ||
| return cloneElement( render, newProps ); | ||
| } else if ( typeof render === 'function' ) { | ||
| return render( newProps, state ); | ||
| } | ||
| return <div { ...newProps } />; | ||
| }, | ||
| [ render ] | ||
| ); | ||
|
|
||
| return ( | ||
| <BaseUITabs.List | ||
| ref={ mergedListRef } | ||
| activateOnFocus={ activateOnFocus } | ||
| data-select-on-move={ activateOnFocus ? 'true' : 'false' } | ||
| className={ clsx( | ||
| 'jp-forms-tabs__tablist', | ||
| overflow.first && 'jp-forms-tabs__is-overflowing-first', | ||
| overflow.last && 'jp-forms-tabs__is-overflowing-last', | ||
| `jp-forms-tabs__has-${ density }-density`, | ||
| className | ||
| ) } | ||
| render={ renderTabList } | ||
| { ...otherProps } | ||
| > | ||
| { children } | ||
| <BaseUITabs.Indicator className="jp-forms-tabs__indicator" /> | ||
| </BaseUITabs.List> | ||
| ); | ||
| } ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.