/
githubmirror
/
ionic
Обзор
Документация
Войти
/
githubmirror
/
ionic
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react/src/hooks/useIonPopover.ts
44 строки
2 KB
Liam DeBeasi
chore(react): migrate to eslint, add prettier (#26633)
19 янв 2023, 00:49
Не верифицирован
19 янв 2023, 00:49
b02190d
Код
Авторство
О чём код?
import type { PopoverOptions } from '@ionic/core/components'; import { popoverController } from '@ionic/core/components'; import { defineCustomElement } from '@ionic/core/components/ion-popover.js'; import { useCallback } from 'react'; import type { ReactComponentOrElement } from '../models/ReactComponentOrElement'; import type { HookOverlayOptions } from './HookOverlayOptions'; import { useOverlay } from './useOverlay'; // TODO(FW-2959): types /** * A hook for presenting/dismissing an IonPicker component * @param component The component that the popover will show. Can be a React Component, a functional component, or a JSX Element * @param componentProps The props that will be passed to the component, if required * @returns Returns the present and dismiss methods in an array */ export function useIonPopover(component: ReactComponentOrElement, componentProps?: any): UseIonPopoverResult { const controller = useOverlay<PopoverOptions, HTMLIonPopoverElement>( 'IonPopover', popoverController, defineCustomElement, component, componentProps ); const present = useCallback( (options: Omit<PopoverOptions, 'component' | 'componentProps'> & HookOverlayOptions = {}) => { controller.present(options as any); }, [controller.present] ); return [present, controller.dismiss]; } export type UseIonPopoverResult = [ (options?: Omit<PopoverOptions, 'component' | 'componentProps'> & HookOverlayOptions) => void, /** * Dismisses the popover */ (data?: any, role?: string) => void ];