@ta-interaktiv/react-municipality-search 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -3
- package/dist/index.js +1 -1
- package/es/index.js +1 -1
- package/package.json +1 -1
- package/src/municipalitySearch.tsx +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,85 @@
|
|
|
1
1
|
# `@ta-interaktiv/react-municipality-search`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React component for searching Swiss municipalities by name or postal code (ZIP). The component provides autocomplete functionality with smart ranking, supports multiple locales (DE/FR), and can remember previously selected municipalities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @ta-interaktiv/react-municipality-search
|
|
9
|
+
```
|
|
4
10
|
|
|
5
11
|
## Usage
|
|
6
12
|
|
|
13
|
+
```tsx
|
|
14
|
+
import { MunicipalitySearch } from '@ta-interaktiv/react-municipality-search';
|
|
15
|
+
|
|
16
|
+
function MyComponent() {
|
|
17
|
+
const handleSelection = (municipality) => {
|
|
18
|
+
console.log('Selected:', municipality.NORMGEMEINDE, municipality.PLZ4);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<MunicipalitySearch
|
|
23
|
+
municipalityData="2021v3"
|
|
24
|
+
locale="de"
|
|
25
|
+
onSelectionHandler={handleSelection}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
7
29
|
```
|
|
8
|
-
const reactMunicipalitySearch = require('@ta-interaktiv/react-municipality-search');
|
|
9
30
|
|
|
10
|
-
|
|
31
|
+
## Props
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Default | Description |
|
|
34
|
+
|------|------|---------|-------------|
|
|
35
|
+
| `municipalityData` | `string` | `"2021v3"` | Which year/version of municipality data to use (see [available data](https://tamedia-discovery-municipalities.s3.eu-central-1.amazonaws.com/index.html)) |
|
|
36
|
+
| `locale` | `"de" \| "fr"` | `"de"` | Locale for UI strings |
|
|
37
|
+
| `onSelectionHandler` | `(municipality: Municipality) => void` | *required* | Callback when user selects a municipality |
|
|
38
|
+
| `placeholder` | `string` | *(locale-based)* | Placeholder text for the search input |
|
|
39
|
+
| `dedupe` | `boolean` | `false` | Deduplicate municipalities by name (ignoring ZIP) |
|
|
40
|
+
| `resetOnSelect` | `boolean` | `false` | Reset the search after selection |
|
|
41
|
+
| `showLastSelectedMunicipalities` | `boolean` | `false` | Show previously selected municipalities on mount |
|
|
42
|
+
| `numberOfLastSelectedMunicipalities` | `number` | `1` | How many recent municipalities to show |
|
|
43
|
+
| `iconOnRightSide` | `boolean` | `false` | Position search icon on the right side |
|
|
44
|
+
| `maxResults` | `number` | `10` | Maximum number of results to display |
|
|
45
|
+
| `customMunicipalities` | `Municipality[]` | `undefined` | Use custom municipality data instead of fetching |
|
|
46
|
+
| `selectedMunicipality` | `Municipality` | `undefined` | Pre-selected municipality (read-only mode) |
|
|
47
|
+
| `selectedMunicipalityId` | `number` | `undefined` | GDENR of pre-selected municipality |
|
|
48
|
+
| `onCloseHandler` | `() => void` | `undefined` | Handler for close button in pre-selected mode |
|
|
49
|
+
| `inputBackgroundColor` | `string` | `"var(--site-background)"` | Background color of input field |
|
|
50
|
+
| `resultBackgroundColor` | `string` | `"var(--site-background)"` | Background color of results dropdown |
|
|
51
|
+
| `propertyToSearch` | `keyof Municipality` | `"NORMGEMEINDE"` | Which municipality property to search (must be string) |
|
|
52
|
+
|
|
53
|
+
## Available Municipality Data
|
|
54
|
+
|
|
55
|
+
View all available municipality data files and versions at:
|
|
56
|
+
**https://tamedia-discovery-municipalities.s3.eu-central-1.amazonaws.com/index.html**
|
|
57
|
+
|
|
58
|
+
Available data includes:
|
|
59
|
+
- Year-specific datasets (e.g., `20230101_de`, `20240101_fr`)
|
|
60
|
+
- Latest versions (`latest_de`, `latest_fr`)
|
|
61
|
+
- Custom regional datasets (e.g., `24h_municipalities`, `zrz_municipalities`)
|
|
62
|
+
- Versions with/without ZIP codes (`_nozip` suffix)
|
|
63
|
+
|
|
64
|
+
## Municipality Type
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
interface Municipality {
|
|
68
|
+
GDENR: number; // Municipality number (BFS-Nr)
|
|
69
|
+
ORTNAME?: string; // Place name
|
|
70
|
+
PLZ4?: number; // 4-digit postal code
|
|
71
|
+
PLZ6?: number; // 6-digit postal code
|
|
72
|
+
GDENAMK?: string; // Short municipality name
|
|
73
|
+
KTKZ: string; // Canton abbreviation
|
|
74
|
+
NORMORTSNAME?: string; // Normalized place name
|
|
75
|
+
NORMGEMEINDE: string; // Normalized municipality name
|
|
76
|
+
URL?: string; // Optional URL
|
|
77
|
+
}
|
|
11
78
|
```
|
|
79
|
+
|
|
80
|
+
## Search Behavior
|
|
81
|
+
|
|
82
|
+
- **By ZIP code**: Enter numbers (e.g., "8000" or "3000") to search postal codes
|
|
83
|
+
- **By name**: Enter letters (e.g., "Zürich" or "Bern") to search municipality/place names
|
|
84
|
+
- Results are ranked by relevance: exact matches first, then word matches, then partial matches
|
|
85
|
+
- Minimum 2 characters required to trigger search
|
package/dist/index.js
CHANGED
|
@@ -337,7 +337,7 @@ var MunicipalitySearch = (function (_super) {
|
|
|
337
337
|
useLegacy && console.log('Municipality search: using legacy endpoint 👴');
|
|
338
338
|
var API_BASE_URL = useLegacy
|
|
339
339
|
? 'https://interaktiv.tagesanzeiger.ch/static/gemeindesuche/'
|
|
340
|
-
: 'https://
|
|
340
|
+
: 'https://tamedia-discovery-municipalities.s3.eu-central-1.amazonaws.com/';
|
|
341
341
|
return fetch(API_BASE_URL + "".concat(_this.props.municipalityData, ".json"))
|
|
342
342
|
.then(function (res) {
|
|
343
343
|
if (!res.ok) {
|
package/es/index.js
CHANGED
|
@@ -333,7 +333,7 @@ var MunicipalitySearch = (function (_super) {
|
|
|
333
333
|
useLegacy && console.log('Municipality search: using legacy endpoint 👴');
|
|
334
334
|
var API_BASE_URL = useLegacy
|
|
335
335
|
? 'https://interaktiv.tagesanzeiger.ch/static/gemeindesuche/'
|
|
336
|
-
: 'https://
|
|
336
|
+
: 'https://tamedia-discovery-municipalities.s3.eu-central-1.amazonaws.com/';
|
|
337
337
|
return fetch(API_BASE_URL + "".concat(_this.props.municipalityData, ".json"))
|
|
338
338
|
.then(function (res) {
|
|
339
339
|
if (!res.ok) {
|
package/package.json
CHANGED
|
@@ -468,7 +468,7 @@ export class MunicipalitySearch extends Component<Props, State> {
|
|
|
468
468
|
useLegacy && console.log('Municipality search: using legacy endpoint 👴')
|
|
469
469
|
const API_BASE_URL = useLegacy
|
|
470
470
|
? 'https://interaktiv.tagesanzeiger.ch/static/gemeindesuche/'
|
|
471
|
-
: 'https://
|
|
471
|
+
: 'https://tamedia-discovery-municipalities.s3.eu-central-1.amazonaws.com/'
|
|
472
472
|
return fetch(API_BASE_URL + `${this.props.municipalityData}.json`)
|
|
473
473
|
.then((res) => {
|
|
474
474
|
if (!res.ok) {
|