/
githubmirror
/
ionic-framework
Обзор
Документация
Войти
/
githubmirror
/
ionic-framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react/src/hooks/useIonActionSheet.ts
55 строк
2 KB
Liam DeBeasi
chore(react): migrate to eslint, add prettier (#26633)
19 янв 2023, 00:49
Не верифицирован
19 янв 2023, 00:49
b02190d
Код
Авторство
О чём код?
import type { ActionSheetButton, ActionSheetOptions } from '@ionic/core/components'; import { actionSheetController } from '@ionic/core/components'; import { defineCustomElement } from '@ionic/core/components/ion-action-sheet.js'; import { useCallback } from 'react'; import type { HookOverlayOptions } from './HookOverlayOptions'; import { useController } from './useController'; /** * A hook for presenting/dismissing an IonActionSheet component * @returns Returns the present and dismiss methods in an array */ export function useIonActionSheet(): UseIonActionSheetResult { const controller = useController<ActionSheetOptions, HTMLIonActionSheetElement>( 'IonActionSheet', actionSheetController, defineCustomElement ); const present = useCallback( (buttonsOrOptions: ActionSheetButton[] | (ActionSheetOptions & HookOverlayOptions), header?: string) => { if (Array.isArray(buttonsOrOptions)) { return controller.present({ buttons: buttonsOrOptions, header, }); } else { return controller.present(buttonsOrOptions); } }, [controller.present] ); return [present, controller.dismiss]; } export type UseIonActionSheetResult = [ { /** * Presents the action sheet * @param buttons An array of buttons for the action sheet * @param header Optional - Title for the action sheet */ (buttons: ActionSheetButton[], header?: string | undefined): Promise<void>; /** * Presents the action sheet * @param options The options to pass to the IonActionSheet */ (options: ActionSheetOptions & HookOverlayOptions): Promise<void>; }, /** * Dismisses the action sheet */ () => Promise<void> ];