From 988fb16d179161810f7892714898ca56bb0d554a Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Tue, 24 Aug 2021 11:46:13 -0500 Subject: [PATCH] fix: use exact object flow types --- src/core.js | 44 ++++++++++++++++++++++---------------------- src/hooks.js | 4 ++-- src/index.js | 4 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/core.js b/src/core.js index 9410f73..d687c0b 100644 --- a/src/core.js +++ b/src/core.js @@ -13,7 +13,7 @@ function warn(key: string, message: string) { export type Variant = 'popover' | 'popper' -export type PopupState = { +export type PopupState = {| open: (eventOrAnchorEl?: SyntheticEvent | HTMLElement) => void, close: () => void, toggle: (eventOrAnchorEl?: SyntheticEvent | HTMLElement) => void, @@ -31,9 +31,9 @@ export type PopupState = { disableAutoFocus: boolean, _childPopupState: ?PopupState, _setChildPopupState: (?PopupState) => void, -} +|} -export type CoreState = { +export type CoreState = {| isOpen: boolean, setAnchorElUsed: boolean, anchorEl: ?HTMLElement, @@ -42,7 +42,7 @@ export type CoreState = { _childPopupState: ?PopupState, _deferNextOpen: boolean, _deferNextClose: boolean, -} +|} export const initCoreState: CoreState = { isOpen: false, @@ -62,14 +62,14 @@ export function createPopupState({ popupId, variant, disableAutoFocus, -}: { +}: {| state: CoreState, setState: ($Shape) => any, popupId: ?string, variant: Variant, parentPopupState?: ?PopupState, disableAutoFocus?: ?boolean, -}): PopupState { +|}): PopupState { const { isOpen, setAnchorElUsed, @@ -226,13 +226,13 @@ export function anchorRef({ setAnchorEl }: PopupState): (?HTMLElement) => any { * @param {object} popupState the argument passed to the child function of * `PopupState` */ -export function bindTrigger({ isOpen, open, popupId, variant }: PopupState): { +export function bindTrigger({ isOpen, open, popupId, variant }: PopupState): {| 'aria-controls'?: ?string, 'aria-describedby'?: ?string, 'aria-haspopup': ?true, onClick: (event: SyntheticEvent) => void, onTouchStart: (event: SyntheticEvent) => void, -} { +|} { return { // $FlowFixMe [variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen @@ -255,12 +255,12 @@ export function bindContextMenu({ open, popupId, variant, -}: PopupState): { +}: PopupState): {| 'aria-controls'?: ?string, 'aria-describedby'?: ?string, 'aria-haspopup': ?true, onContextMenu: (event: SyntheticEvent) => void, -} { +|} { return { // $FlowFixMe [variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen @@ -280,13 +280,13 @@ export function bindContextMenu({ * @param {object} popupState the argument passed to the child function of * `PopupState` */ -export function bindToggle({ isOpen, toggle, popupId, variant }: PopupState): { +export function bindToggle({ isOpen, toggle, popupId, variant }: PopupState): {| 'aria-controls'?: ?string, 'aria-describedby'?: ?string, 'aria-haspopup': ?true, onClick: (event: SyntheticEvent) => void, onTouchStart: (event: SyntheticEvent) => void, -} { +|} { return { // $FlowFixMe [variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen @@ -310,14 +310,14 @@ export function bindHover({ onMouseLeave, popupId, variant, -}: PopupState): { +}: PopupState): {| 'aria-controls'?: ?string, 'aria-describedby'?: ?string, 'aria-haspopup': ?true, onTouchStart: (event: SyntheticMouseEvent) => any, onMouseOver: (event: SyntheticMouseEvent) => any, onMouseLeave: (event: SyntheticMouseEvent) => any, -} { +|} { return { // $FlowFixMe [variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen @@ -342,13 +342,13 @@ export function bindFocus({ close, popupId, variant, -}: PopupState): { +}: PopupState): {| 'aria-controls'?: ?string, 'aria-describedby'?: ?string, 'aria-haspopup': ?true, onFocus: (event: SyntheticEvent) => any, onBlur: (event: SyntheticEvent) => any, -} { +|} { return { // $FlowFixMe [variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen @@ -373,7 +373,7 @@ export function bindPopover({ popupId, onMouseLeave, disableAutoFocus, -}: PopupState): { +}: PopupState): {| id: ?string, anchorEl: ?HTMLElement, open: boolean, @@ -382,7 +382,7 @@ export function bindPopover({ disableAutoFocus?: boolean, disableEnforceFocus?: boolean, disableRestoreFocus?: boolean, -} { +|} { return { id: popupId, anchorEl, @@ -417,7 +417,7 @@ export function bindMenu({ popupId, onMouseLeave, disableAutoFocus, -}: PopupState): { +}: PopupState): {| id: ?string, anchorEl: ?HTMLElement, open: boolean, @@ -428,7 +428,7 @@ export function bindMenu({ disableAutoFocus?: boolean, disableEnforceFocus?: boolean, disableRestoreFocus?: boolean, -} { +|} { return { id: popupId, anchorEl, @@ -455,12 +455,12 @@ export function bindPopper({ anchorEl, popupId, onMouseLeave, -}: PopupState): { +}: PopupState): {| id: ?string, anchorEl: ?HTMLElement, open: boolean, onMouseLeave: (event: SyntheticEvent) => void, -} { +|} { return { id: popupId, anchorEl, diff --git a/src/hooks.js b/src/hooks.js index 4097ed7..f98bebe 100644 --- a/src/hooks.js +++ b/src/hooks.js @@ -43,12 +43,12 @@ export function usePopupState({ popupId, variant, disableAutoFocus, -}: { +}: {| parentPopupState?: ?PopupState, popupId: ?string, variant: Variant, disableAutoFocus?: ?boolean, -}): PopupState { +|}): PopupState { const [state, setState] = useState(initCoreState) useEffect(() => { if (!disableAutoFocus && popupId && typeof document === 'object') { diff --git a/src/index.js b/src/index.js index c51632c..8d6f6c3 100644 --- a/src/index.js +++ b/src/index.js @@ -34,13 +34,13 @@ export { } export type { Variant, InjectedProps } -export type Props = { +export type Props = {| popupId?: string, children: (props: InjectedProps) => ?React.Node, variant: Variant, parentPopupState?: ?InjectedProps, disableAutoFocus?: ?boolean, -} +|} export default class PopupState extends React.Component { state: CoreState = initCoreState