import React from 'react'; import mapboxgl from 'mapbox-gl'; import { GeocodingOptions, GeocodingResponse, GeocodingFeature } from '@mapbox/search-js-core'; import { MapboxGeocoder, MapboxGeocoderComponentOptions, Theme, PopoverOptions, MapInstance } from '@mapbox/search-js-web'; declare global { namespace JSX { interface IntrinsicElements { 'mapbox-geocoder': any; } } } /** * Methods available on a `ref` when attached to the {@link Geocoder} component. * @typedef GeocoderRefType */ export interface GeocoderRefType { /** * @see {@link MapboxGeocoder#focus} */ focus: typeof MapboxGeocoder.prototype.focus; /** * @see {@link MapboxGeocoder#search} */ search: typeof MapboxGeocoder.prototype.search; } /** * Props for the {@link Geocoder} component * @typedef GeocoderProps */ export interface GeocoderProps { /** * The [Mapbox access token](https://docs.mapbox.com/help/glossary/access-token/) to use for all requests. */ accessToken: string; /** * Options to pass to the underlying {@link GeocodingCore} interface. * @example * ```typescript * * ``` */ options?: Partial; /** * Options defining the behavior of web component or its underlying search functionality. * @example * ```typescript * * ``` */ componentOptions?: Partial; /** * The {@link Theme} to use for styling the geocoder. * @example * ```typescript * * ``` */ theme?: Theme; /** * The {@link PopoverOptions} to define popover positioning. * @example * ```typescript * * ``` */ popoverOptions?: Partial; /** * The input element's placeholder text. The default value may be localized if {@link GeocodingOptions#language} is set. */ placeholder?: string; /** * If specified, the map will be centered on the retrieved suggestion. */ map?: MapInstance; /** * If `true`, a [Marker](https://docs.mapbox.com/mapbox-gl-js/api/#marker) will be added to the map at the location of the user-selected result using a default set of Marker options. If the value is an object, the marker will be constructed using these options. If `false`, no marker will be added to the map. Requires that {@link GeocoderProps#mapboxgl} also be set. */ marker?: boolean | mapboxgl.MarkerOptions; /** * A [mapbox-gl](https://github.com/mapbox/mapbox-gl-js) instance to use when creating [Markers](https://docs.mapbox.com/mapbox-gl-js/api/#marker). Required if {@link GeocoderProps#marker} is `true`. */ mapboxgl?: typeof mapboxgl; /** * Value to display in the geocoder. */ value?: string; /** * Callback for when the value changes. */ onChange?: (value: string) => void; /** * Fired when the user is typing in the input and provides a list of suggestions. * The underlying response from {@link GeocodingCore} is passed. */ onSuggest?: (res: GeocodingResponse) => void; /** * Fired when {@link GeocodingCore} has errored providing a list of suggestions. * The underlying error is passed. */ onSuggestError?: (error: Error) => void; /** * Fired when the user has selected a suggestion. * The underlying feature from {@link GeocodingCore} is passed. */ onRetrieve?: (res: GeocodingFeature) => void; /** * Fired when the user has cleared the search box. */ onClear?: () => void; /** * Fired when the user has blurred the search box. */ onBlur?: () => void; /** * A callback providing the opportunity to validate and/or manipulate the input text before it triggers a search, for example by using a regular expression. * If a truthy string value is returned, it will be passed into the underlying search API. If `null`, `undefined` or empty string is returned, no search request will be performed. */ interceptSearch?: (value: string) => string; } /** * `` is a React component that provides an interactive geocoder, * powered by the Mapbox Geocoding API. * * To use this element, you must have a [Mapbox access token](https://www.mapbox.com/help/create-api-access-token/). * * @function Geocoder * @param {GeocoderProps} props * @example * ```typescript * export function Component() { * const [value, setValue] = React.useState(''); * * const handleChange = (d) => { * setValue(d); * }; * return ( * * ); * } * ``` */ export declare const Geocoder: React.ForwardRefExoticComponent>;