1.0.7 • Published 9 months ago

react-thailand-address-search v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

npm version GitHub license

Thailand Location Search

This project is a React-based web application that provides a user-friendly interface for searching locations in Thailand. It allows users to search for provinces, districts, sub-districts, and postal codes in both Thai and English languages. The application is designed to be fast, efficient, and easy to use, making it an ideal tool for both locals and tourists navigating Thailand's administrative divisions.

screenshot

Online Demo

Features

  • Bilingual support (Thai/English)
  • Postal code search
  • Keyboard navigation
  • Customizable styling
  • Tailwind CSS integration
  • TypeScript support
  • Efficient data loading with ZIP compression
  • Customizable display format
  • Auto-highlighting of matched terms

Technologies Used

  • React
  • TypeScript
  • Tailwind CSS
  • JSZip: For creating a zip file from the JSON database

How to use

Install the package

npm install react-thailand-address-search

Import the component (TypeScript)

import ThailandAddressSearch, { ThailandData } from "react-thailand-address-search";
..
const [selectedLocation, setSelectedLocation] = useState<ThailandData | undefined>();
..
console.log(selectedLocation);

<ThailandAddressSearch
  language={language}
  highlightColor="bg-red-200"
  searchTermFormat=":districtName / :subdistrictName / :provinceName / :postalCode"
  onSelectLocation={setSelectedLocation}
  dataSource="/data/thailand.zip"
/>

Response data will be like this:

interface ThailandData {
  id: number;
  provinceCode: number;
  provinceNameEn: string;
  provinceNameTh: string;
  districtCode: number;
  districtNameEn: string;
  districtNameTh: string;
  subdistrictCode: number;
  subdistrictNameEn: string;
  subdistrictNameTh: string;
  postalCode: number;
}

Available Parameters

ParameterTypeRequiredDefaultDescription
clearButtonClassNamestringNo"absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600"CSS class for clear button
containerClassNamestringNo"max-w-md mx-auto mt-8"Container CSS class
resultsContainerClassNamestringNo-CSS class for results container
dataSourcestringNo/data/thailand.zipCustom path to data source
defaultValueIdnumberNo-Default value ID
displayFieldsstring[]No["districtName", "subdistrictName", "provinceName", "postalCode"]Fields to display
dropdownSelectedColorstringNo"bg-green-200"CSS class for selected dropdown item
highlightColorstringNo"bg-yellow-200"CSS class or color for highlighting matches
inputClassNamestringNo"w-full px-4 py-2..."Input field CSS class
language"th" | "en"No"th"Sets display language
maxResultsnumberNo10Maximum number of results to show
minQueryLengthnumberNo4Minimum query length to show results
placeholderstringNoLanguage-based default: Search for a location in Thailand... or ค้นหาสถานที่ในประเทศไทย...Input placeholder text
searchTermFormatstringNo-Custom format for display (e.g. :districtName / :subdistrictName)
separatorstringNo" - "Separator for display fields
showClearButtonbooleanNotrueShow clear button
clickToClearbooleanNofalseClick to clear input
readOnlyIfSelectedbooleanNofalseRead only if selected
onSelectLocation(location: ThailandData \| undefined) => voidYes-Selection callback function

Data Source

The component uses a compressed ZIP file containing Thailand location data. By default, it looks for /data/thailand.zip in your public folder. You can provide a custom path using the dataSource prop.

Setting up the Data File

  1. Download the data file from the repository
  2. Place it in your project's public folder
  3. Or specify a custom path using the dataSource prop

Contributing

Contributions to improve the Thailand Location Search project are welcome. Please feel free to submit issues, feature requests, or pull requests to help enhance this tool for the community.

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago