@digitransit-component/digitransit-component-autosuggest-panel

中文文档
14.0.9发布于 2026/11/11(AGPL-3.0 OR EUPL-1.2)ESM + CJS零依赖构建来源已验证近 30 天下载 3245

digitransit 组件自动建议-平面模块

中文使用文档
文档目录3 节
  1. 位置形状
  2. 实例
  3. 安装

@ digitransit- 组件/ digitransit- 组件- 自动监视- 平面板

位置形状

使两个DTAutosugest搜索场,包括通过点数处理的小组

实例

const searchContext = {
  isPeliasLocationAware: false // true / false does Let Pelias suggest based on current user location
  minimalRegexp: undefined // used for testing min. regexp. For example: new RegExp('.{2,}'),
  lineRegexp: undefined //  identify searches for route numbers/labels: bus | train | metro. For example: new RegExp(
   //   '(^[0-9]+[a-z]?$|^[yuleapinkrtdz]$|(^m[12]?b?$))',
   //  'i',
   //  ),
  URL_PELIAS: '' // url for pelias searches
  feedIDs: ['HSL', 'HSLLautta'] // FeedId's like  [HSL, HSLLautta]
  geocodingSources: ['oa','osm','nlsfi']  // sources for geocoding
  geocodingSearchParams; {}  // Searchparmas fro geocoding
  getFavouriteLocations: () => ({}),    // Function that returns array of favourite locations.
  getFavouriteStops: () => ({}),        // Function that returns array of favourite stops.
  getLanguage: () => ({}),              // Function that returns current language.
  getFavouriteRoutes: () => ({}),       // Function that returns array of favourite routes.
  getPositions: () => ({}),             // Function that returns user's geolocation.
  getRoutesQuery: () => ({}),           // Function that returns query for fetching routes.
  getStopAndStationsQuery: () => ({}),  // Function that fetches favourite stops and stations from graphql API.
  getFavouriteRoutesQuery: () => ({}),  // Function that returns query for fetching favourite routes.
  getFavouriteVehicleRentalStations: () => ({}),  // Function that returns favourite bike rental station.
  getFavouriteVehicleRentalStationsQuery: () => ({}), // Function that returns query for fetching favourite bike rental stations.
  getHasOtpLocationFavourites: () => ({}), // Optional. Function that returns whether any OTP-backed favourite is currently available.
  startLocationWatch: () => ({}),       // Function that locates users geolocation.
  saveSearch: () => ({}),               // Function that saves search to old searches store.
  clearOldSearches: () => ({}),         // Function that clears old searches store.
  getFutureRoutes: () => ({}),          // Function that return future routes
  saveFutureRoute: () => ({}),          // Function that saves a future route
  clearFutureRoutes: () => ({}),        // Function that clears future routes
};

const origin = {
 lat: 60.169196,
 lon: 24.957674,
 address: 'Aleksanterinkatu, Helsinki',
 set: true,
 ready: true,
}

const destination = {
  lat: 60.199093,
  lon: 24.940536,
  address: 'Opastinsilta 6, Helsinki',
  set: true,
  ready: true,
}
onSelect(item, id) {
 return null;  // Define what to do when a suggestion is being selected. None by default.
 }
onClear(id) {
 return null;  // Define what to do when a suggestion is being selected. None by default.
}
const getAutoSuggestIcons: {
  // Called for every city bike station rendered as a search suggestion. Should return the icon and
  // color used for that station. Two icons are available, 'citybike-stop-digitransit' anditybike-stop-digitransit-secondary'.
  citybikes: station => {
     return ['citybike-stop-digitransit', '#f2b62d'];
  }
}
const targets = ['Locations', 'Stops', 'Routes']; // Defines what you are searching. all available options are Locations, Stops, Routes, VehicleRentalStations, FutureRoutes, MapPosition and CurrentPosition. Leave empty to search all targets.
const sources = ['Favourite', 'History', 'Datasource'] // Defines where you are searching. all available are: Favourite, History (previously searched searches), and Datasource. Leave empty to use all sources.
<DTAutosuggestPanel
   appElement={appElement} // Required. Root element's id. Needed for react-modal component.
   origin={origin} // Selected origin point
   destination={destination} // Selected destination point
   originPlaceHolder={'Give origin'} // Optional Give string shown initially inside origin search field
   destinationPlaceHolder={'Give destination'} // Optional Give string shown initally inside destination search field
   initialViaPoints={[]} // Optional.  If showViapointControl is set to true, pass initial via points to the panel. Currently no default implementation is given.
   updateViaPoints={() => return []} // Optional. If showViapointControl is set to true, define how to update your via point list with this function. Currenlty no default implementation is given.
   swapOrder={() => return null} // Optional. If showSwapControl is set to true, define how to swap order of your points (origin, destination, viapoints). Currently no default implementation is given.
   searchContext={searchContext}
   getAutoSuggestIcons={getAutoSuggestIcons}
   onSelect={this.onSelect}
   onClear={this.onClear}
   lang="fi" // Define language fi sv or en.
   addAnalyticsEvent={null} // Optional. you can record an analytics event if you wish. if passed, component will pass an category, action, name parameters to addAnalyticsEvent
   disableAutoFocus={false} // Optional. use this to disable autofocus completely from DTAutosuggestPanel
   sources={sources}
   targets={targets}
   isMobile  // Optional. Defaults to false. Whether to use mobile search.
   originMobileLabel="Origin label" // Optional. Custom label text for origin field on mobile.
   destinationMobileLabel="Destination label" // Optional. Custom label text for destination field on mobile.
   handleFocusChange={() => {}} // Optional. If defined overrides default onFocusChange behaviour
   showSwapControl={false} // Optional.
   showViapointControl={false} // Optional.

这个模块是Digitransit-ui项目的一部分. 保留在 HSLdevcom/数码-i 库,您可以创建的地方 公关和问题.

安装

单独安装此模块 :

$ npm install @digitransit-component/digitransit-component-autosuggest-panel

版本与发布记录

@digitransit-component/digitransit-component-autosuggest-panel 共发布 214 个版本,首次发布于 2020/04/29;过去 12 个月发布了 53 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
14.0.9latest2026/11/111 天前
14.0.82026/11/111 天前
14.0.72026/11/101 天前
14.0.62026/11/092 天前
14.0.52026/11/065 天前
14.0.42026/11/056 天前

关于 @digitransit-component/digitransit-component-autosuggest-panel 的常见问题

@digitransit-component/digitransit-component-autosuggest-panel 是什么?

digitransit 组件自动建议-平面模块

如何安装 @digitransit-component/digitransit-component-autosuggest-panel?

在项目目录运行 npm install @digitransit-component/digitransit-component-autosuggest-panel,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.3.1)、lodash(^4.18.1)、i18next(^22.5.1)、downshift(^9.4.0)、classnames(^2.5.1)、prop-types(^15.8.1)、@hsl-fi/sass(^1.0.0)、react-i18next(^12.3.1)、@dnd-kit/react(^0.5.3)、@digitransit-component/digitransit-component-icon(^5.0.5)、@digitransit-component/digitransit-component-autosuggest(^11.0.9)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@digitransit-component/digitransit-component-autosuggest-panel 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/digitransit-component__digitransit-component-autosuggest-panel 是否存在。

@digitransit-component/digitransit-component-autosuggest-panel 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@digitransit-component/digitransit-component-autosuggest-panel 可以商用吗?

@digitransit-component/digitransit-component-autosuggest-panel 使用 (AGPL-3.0 OR EUPL-1.2) 许可。可在 AGPL-3.0、EUPL-1.2 中任选其一遵守。以上为概括,不构成法律意见,请以许可原文为准。

@digitransit-component/digitransit-component-autosuggest-panel 的下载量有多少?

根据 npm 官方下载统计,@digitransit-component/digitransit-component-autosuggest-panel 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,245 次,日均约 108 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@digitransit-component/digitransit-component-autosuggest-panel 还在维护吗?

最新版本 14.0.9 发布于 2026/11/11(1 天前);至今共发布 214 个版本,其中过去 12 个月发布了 53 个;首次发布于 2020/04/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。