/
githubmirror
/
ionic-framework
Обзор
Документация
Войти
/
githubmirror
/
ionic-framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react/src/hooks/useIonPicker.tsx
56 строк
2 KB
Liam DeBeasi
feat(picker): add inline picker (#28689)
13 дек 2023, 21:03
Не верифицирован
13 дек 2023, 21:03
cd5c099
Код
Авторство
О чём код?
import type { PickerButton, PickerColumn, PickerOptions } from '@ionic/core/components'; import { pickerController } from '@ionic/core/components'; import { defineCustomElement } from '@ionic/core/components/ion-picker-legacy.js'; import { useCallback } from 'react'; import type { HookOverlayOptions } from './HookOverlayOptions'; import { useController } from './useController'; /** * A hook for presenting/dismissing an IonPicker component * @returns Returns the present and dismiss methods in an array * @deprecated Use the inline ion-picker component instead. */ export function useIonPicker(): UseIonPickerResult { const controller = useController<PickerOptions, HTMLIonPickerLegacyElement>( 'IonPicker', pickerController, defineCustomElement ); const present = useCallback( (columnsOrOptions: PickerColumn[] | (PickerOptions & HookOverlayOptions), buttons?: PickerButton[]) => { if (Array.isArray(columnsOrOptions)) { return controller.present({ columns: columnsOrOptions, buttons: buttons ?? [{ text: 'Ok' }], }); } else { return controller.present(columnsOrOptions); } }, [controller.present] ); return [present, controller.dismiss]; } export type UseIonPickerResult = [ { /** * Presents the picker * @param columns Array of columns to be displayed in the picker. * @param buttons Optional - Array of buttons to be displayed at the top of the picker. */ (columns: PickerColumn[], buttons?: PickerButton[]): Promise<void>; /** * Presents the picker * @param options The options to pass to the IonPicker */ (options: PickerOptions & HookOverlayOptions): Promise<void>; }, /** * Dismisses the picker */ () => Promise<void> ];