Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e2efe53
Move `components/src/ui/popover` to `components/src/accessible-popover`
ciampo May 25, 2021
650deeb
Add to Docs manifest
ciampo May 25, 2021
777f822
Add to tsconfig.json
ciampo May 25, 2021
8363483
Rename context-related variables from Popover* to AccessiblePopover*
ciampo Jun 25, 2021
8e0d236
Rename `PopoverContext` type to `Context`
ciampo Jun 25, 2021
59c21e4
Rename `PopoverContent` to `AccessiblePopoverContent`
ciampo Jun 25, 2021
935bc5e
Move `component.js` to component-specific folder
ciampo Jun 25, 2021
ed58977
Move `AccessibilePopover` logic to separate hook
ciampo Jun 25, 2021
083fe44
Move `content.js` to component-specific folder
ciampo Jun 25, 2021
5c15310
Move `AccessibilePopoverContent` logic to separate hook
ciampo Jun 25, 2021
1e68e3c
Rename `AccessiblePopover` to `Flyout`
ciampo Jun 25, 2021
5d3428c
Rename zIndex const from `Popover` to `Flyout`
ciampo Jun 30, 2021
2d92a1e
Do not export FlyoutContent component
ciampo Jul 1, 2021
294279d
Fix imports in example
ciampo Jul 1, 2021
337249a
Rename `popover` to `flyoutState`
ciampo Jul 1, 2021
cd5d33b
Refactor to `styled` approach
ciampo Jul 1, 2021
91857d9
Wrap `ReakitPopover` in `FlyoutContentView` and set `maxWidth` in inl…
ciampo Jul 1, 2021
8d31c25
auto-format
ciampo Jul 1, 2021
db1cbae
Add Props documentation to Flyout
ciampo Jul 1, 2021
00cc295
Mark `Flyout` as non-polymorphic
ciampo Jul 2, 2021
1b5f2a5
Add documentation to `FlyoutContent`s README
ciampo Jul 2, 2021
a7389ba
Update snapshots
ciampo Jul 2, 2021
23b945e
Remove FlyoutContext exports
ciampo Jul 2, 2021
edfb229
Do not export FlyoutContent`s documentation
ciampo Jul 2, 2021
2b5d016
Delete FlyoutContent`s README
ciampo Jul 2, 2021
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
Prev Previous commit
Next Next commit
Move AccessibilePopover logic to separate hook
  • Loading branch information
ciampo committed Jul 5, 2021
commit ed58977983c0a660abff57d4682aa6d0a1dcf018
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
// eslint-disable-next-line no-restricted-imports
import { PopoverDisclosure, usePopoverState, Portal } from 'reakit';
import { PopoverDisclosure, Portal } from 'reakit';

/**
* WordPress dependencies
Expand All @@ -13,44 +12,29 @@ import { useCallback, useMemo, cloneElement } from '@wordpress/element';
/**
* Internal dependencies
*/
import { contextConnect, useContextSystem } from '../../ui/context';
import { contextConnect } from '../../ui/context';
import { AccessiblePopoverContext } from '../context';
import { usePopoverResizeUpdater } from '../utils';
import AccessiblePopoverContent from '../content';
import { useUpdateEffect } from '../../utils/hooks';
import { useAccessiblePopover } from './hook';

/**
*
* @param {import('../../ui/context').PolymorphicComponentProps<import('../types').Props, 'div'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function Popover( props, forwardedRef ) {
function AccessiblePopover( props, forwardedRef ) {
const {
animated = true,
animationDuration = 160,
baseId,
children,
elevation = 5,
id,
elevation,
label,
maxWidth = 360,
onVisibleChange = noop,
placement,
state,
maxWidth,
onVisibleChange,
trigger,
visible,
popover,
...otherProps
} = useContextSystem( props, 'Popover' );

const _popover = usePopoverState( {
animated: animated ? animationDuration : undefined,
baseId: baseId || id,
placement,
visible,
...otherProps,
} );

const popover = state || _popover;
} = useAccessiblePopover( props );

const resizeListener = usePopoverResizeUpdater( {
onResize: popover.unstable_update,
Expand All @@ -75,7 +59,7 @@ function Popover( props, forwardedRef ) {
);

useUpdateEffect( () => {
onVisibleChange( popover.visible );
onVisibleChange?.( popover.visible );
}, [ popover.visible ] );

return (
Expand Down Expand Up @@ -105,21 +89,21 @@ function Popover( props, forwardedRef ) {
}

/**
* `Popover` is a component to render a floating content modal.
* `AccessiblePopover` is a component to render a floating content modal.
* It is similar in purpose to a tooltip, but renders content of any sort,
* not only simple text.
*
* @example
* ```jsx
* import { Button, Popover, Text } from `@wordpress/components/ui`;
* import { Button, AccessiblePopover, Text } from `@wordpress/components`;
*
* function Example() {
* return (
* <Popover trigger={ <Button>Popover</Button> }>
* <AccessiblePopover trigger={ <Button>Show/Hide content</Button> }>
* <Text>Code is Poetry</Text>
* </Popover>
* </AccessiblePopover>
* );
* }
* ```
*/
export default contextConnect( Popover, 'Popover' );
export default contextConnect( AccessiblePopover, 'AccessiblePopover' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import { usePopoverState } from 'reakit';

/**
* Internal dependencies
*/
import { useContextSystem } from '../../ui/context';

/**
* @param {import('../../ui/context').PolymorphicComponentProps<import('../types').Props, 'div'>} props
*/
export function useAccessiblePopover( props ) {
const {
animated = true,
animationDuration = 160,
baseId,
elevation = 5,
id,
maxWidth = 360,
placement,
state,
visible,
...otherProps
} = useContextSystem( props, 'AccessiblePopover' );

const _popover = usePopoverState( {
animated: animated ? animationDuration : undefined,
baseId: baseId || id,
placement,
visible,
...otherProps,
} );

const popover = state || _popover;

return {
...otherProps,
elevation,
maxWidth,
popover,
};
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './component';
export { useAccessiblePopover } from './hook';