Skip to content

Commit 3bfa932

Browse files
committed
Move useOverlay to /core
1 parent 04c0378 commit 3bfa932

File tree

6 files changed

+34
-44
lines changed

6 files changed

+34
-44
lines changed

src/components/Overlay/Overlay.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { getMiddleware, getPlacement } from './useOverlay';
3+
import { getMiddleware, getPlacement } from '../../core';
44
import * as stories from './Overlay.stories';
55

66
import { Align } from '../../types';

src/components/Overlay/Overlay.tsx

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,6 @@
1-
import PropTypes from 'prop-types';
21
import { CSSProperties, ReactElement, RefCallback } from 'react';
32

4-
import useOverlay, { OverlayOptions, ReferenceElement } from './useOverlay';
5-
6-
import { ALIGN_VALUES } from '../../constants';
7-
import { noop } from '../../utils';
8-
9-
// `Element` is not defined during server-side rendering, so shim it here.
10-
/* istanbul ignore next */
11-
const SafeElement = typeof Element === 'undefined' ? noop : Element;
12-
13-
const propTypes = {
14-
/**
15-
* Specify menu alignment. The default value is `justify`, which makes the
16-
* menu as wide as the input and truncates long values. Specifying `left`
17-
* or `right` will align the menu to that side and the width will be
18-
* determined by the length of menu item values.
19-
*/
20-
align: PropTypes.oneOf(ALIGN_VALUES),
21-
children: PropTypes.func.isRequired,
22-
/**
23-
* Specify whether the menu should appear above the input.
24-
*/
25-
dropup: PropTypes.bool,
26-
/**
27-
* Whether or not to automatically adjust the position of the menu when it
28-
* reaches the viewport boundaries.
29-
*/
30-
flip: PropTypes.bool,
31-
isMenuShown: PropTypes.bool,
32-
positionFixed: PropTypes.bool,
33-
// @ts-ignore
34-
referenceElement: PropTypes.instanceOf(SafeElement),
35-
};
3+
import { OverlayOptions, ReferenceElement, useOverlay } from '../../core';
364

375
export interface OverlayRenderProps {
386
innerRef: RefCallback<HTMLElement>;
@@ -45,16 +13,17 @@ export interface OverlayProps extends OverlayOptions {
4513
referenceElement: ReferenceElement;
4614
}
4715

48-
const Overlay = ({ referenceElement, isMenuShown, ...props }: OverlayProps) => {
16+
/**
17+
* The component is mainly for testing purposes.
18+
*/
19+
function Overlay({ referenceElement, isMenuShown, ...props }: OverlayProps) {
4920
const overlayProps = useOverlay(referenceElement, props);
5021

5122
if (!isMenuShown) {
5223
return null;
5324
}
5425

5526
return props.children(overlayProps);
56-
};
57-
58-
Overlay.propTypes = propTypes;
27+
}
5928

6029
export default Overlay;

src/components/Overlay/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
export { default } from './Overlay';
22
export * from './Overlay';
3-
4-
export { default as useOverlay } from './useOverlay';

src/components/Typeahead/Typeahead.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import cx from 'classnames';
22
import React, { CSSProperties, forwardRef, ReactNode, useState } from 'react';
33

4-
import { TypeaheadContext, TypeaheadRef, useTypeahead } from '../../core';
4+
import {
5+
TypeaheadContext,
6+
TypeaheadRef,
7+
useOverlay,
8+
useTypeahead,
9+
} from '../../core';
510

611
import ClearButton from '../ClearButton';
712
import Loader from '../Loader';
8-
import { useOverlay } from '../Overlay';
9-
import Token from '../Token/Token';
13+
import Token from '../Token';
1014
import TypeaheadInputMulti from '../TypeaheadInputMulti';
1115
import TypeaheadInputSingle from '../TypeaheadInputSingle';
1216
import TypeaheadMenu, { RenderMenuItemChildren } from '../TypeaheadMenu';

src/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export { default as useClickOutside } from './useClickOutside';
66
export { default as useHint } from './useHint';
77
export { default as useItem } from './useItem';
88
export * from './useItem';
9+
export { default as useOverlay } from './useOverlay';
10+
export * from './useOverlay';
911
export { default as useRootClose } from './useRootClose';
1012
export { default as useToken } from './useToken';
1113
export * from './useToken';
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,31 @@ import {
88
} from '@floating-ui/react-dom';
99
import { useState } from 'react';
1010

11-
import { Align } from '../../types';
11+
import { Align } from '../types';
1212

1313
export type ReferenceElement = HTMLElement | null;
1414

1515
export interface OverlayOptions {
16+
/**
17+
* Specify menu alignment. The default value is `justify`, which makes the
18+
* menu as wide as the input and truncates long values. Specifying `left`
19+
* or `right` will align the menu to that side and the width will be
20+
* determined by the length of menu item values.
21+
*/
1622
align?: Align;
23+
/**
24+
* Specify whether the menu should appear above the input.
25+
*/
1726
dropup?: boolean;
27+
/**
28+
* Whether or not to automatically adjust the position of the overlay when it
29+
* reaches the viewport boundaries.
30+
*/
1831
flip?: boolean;
32+
/**
33+
* Whether to use the fixed position strategy for positioning the overlay, as
34+
* opposed to absolute positioning.
35+
*/
1936
positionFixed?: boolean;
2037
}
2138

0 commit comments

Comments
 (0)