Skip to content

Commit

Permalink
fix: use exact object flow types
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Aug 24, 2021
1 parent a7f1831 commit 988fb16
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
44 changes: 22 additions & 22 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function warn(key: string, message: string) {

export type Variant = 'popover' | 'popper'

export type PopupState = {
export type PopupState = {|
open: (eventOrAnchorEl?: SyntheticEvent<any> | HTMLElement) => void,
close: () => void,
toggle: (eventOrAnchorEl?: SyntheticEvent<any> | HTMLElement) => void,
Expand All @@ -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,
Expand All @@ -42,7 +42,7 @@ export type CoreState = {
_childPopupState: ?PopupState,
_deferNextOpen: boolean,
_deferNextClose: boolean,
}
|}

export const initCoreState: CoreState = {
isOpen: false,
Expand All @@ -62,14 +62,14 @@ export function createPopupState({
popupId,
variant,
disableAutoFocus,
}: {
}: {|
state: CoreState,
setState: ($Shape<CoreState>) => any,
popupId: ?string,
variant: Variant,
parentPopupState?: ?PopupState,
disableAutoFocus?: ?boolean,
}): PopupState {
|}): PopupState {
const {
isOpen,
setAnchorElUsed,
Expand Down Expand Up @@ -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<any>) => void,
onTouchStart: (event: SyntheticEvent<any>) => void,
} {
|} {
return {
// $FlowFixMe
[variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen
Expand All @@ -255,12 +255,12 @@ export function bindContextMenu({
open,
popupId,
variant,
}: PopupState): {
}: PopupState): {|
'aria-controls'?: ?string,
'aria-describedby'?: ?string,
'aria-haspopup': ?true,
onContextMenu: (event: SyntheticEvent<any>) => void,
} {
|} {
return {
// $FlowFixMe
[variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen
Expand All @@ -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<any>) => void,
onTouchStart: (event: SyntheticEvent<any>) => void,
} {
|} {
return {
// $FlowFixMe
[variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen
Expand All @@ -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>) => any,
onMouseOver: (event: SyntheticMouseEvent<any>) => any,
onMouseLeave: (event: SyntheticMouseEvent<any>) => any,
} {
|} {
return {
// $FlowFixMe
[variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen
Expand All @@ -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>) => any,
onBlur: (event: SyntheticEvent<any>) => any,
} {
|} {
return {
// $FlowFixMe
[variant === 'popover' ? 'aria-controls' : 'aria-describedby']: isOpen
Expand All @@ -373,7 +373,7 @@ export function bindPopover({
popupId,
onMouseLeave,
disableAutoFocus,
}: PopupState): {
}: PopupState): {|
id: ?string,
anchorEl: ?HTMLElement,
open: boolean,
Expand All @@ -382,7 +382,7 @@ export function bindPopover({
disableAutoFocus?: boolean,
disableEnforceFocus?: boolean,
disableRestoreFocus?: boolean,
} {
|} {
return {
id: popupId,
anchorEl,
Expand Down Expand Up @@ -417,7 +417,7 @@ export function bindMenu({
popupId,
onMouseLeave,
disableAutoFocus,
}: PopupState): {
}: PopupState): {|
id: ?string,
anchorEl: ?HTMLElement,
open: boolean,
Expand All @@ -428,7 +428,7 @@ export function bindMenu({
disableAutoFocus?: boolean,
disableEnforceFocus?: boolean,
disableRestoreFocus?: boolean,
} {
|} {
return {
id: popupId,
anchorEl,
Expand All @@ -455,12 +455,12 @@ export function bindPopper({
anchorEl,
popupId,
onMouseLeave,
}: PopupState): {
}: PopupState): {|
id: ?string,
anchorEl: ?HTMLElement,
open: boolean,
onMouseLeave: (event: SyntheticEvent<any>) => void,
} {
|} {
return {
id: popupId,
anchorEl,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props, CoreState> {
state: CoreState = initCoreState
Expand Down

0 comments on commit 988fb16

Please sign in to comment.