forked from MapComplete/MapComplete
		
	100% height search field inside form
This commit is contained in:
		
							parent
							
								
									3a16518bcb
								
							
						
					
					
						commit
						8cc3f8bede
					
				
					 1 changed files with 66 additions and 67 deletions
				
			
		|  | @ -1,84 +1,83 @@ | ||||||
| import Locale from "../i18n/Locale"; | import Locale from "../i18n/Locale"; | ||||||
| import {UIEventSource} from "../../Logic/UIEventSource"; | import { UIEventSource } from "../../Logic/UIEventSource"; | ||||||
| import {Translation} from "../i18n/Translation"; | import { Translation } from "../i18n/Translation"; | ||||||
| import {VariableUiElement} from "../Base/VariableUIElement"; | import { VariableUiElement } from "../Base/VariableUIElement"; | ||||||
| import Svg from "../../Svg"; | import Svg from "../../Svg"; | ||||||
| import State from "../../State"; | import State from "../../State"; | ||||||
| import {TextField} from "../Input/TextField"; | import { TextField } from "../Input/TextField"; | ||||||
| import {Geocoding} from "../../Logic/Osm/Geocoding"; | import { Geocoding } from "../../Logic/Osm/Geocoding"; | ||||||
| import Translations from "../i18n/Translations"; | import Translations from "../i18n/Translations"; | ||||||
| import Hash from "../../Logic/Web/Hash"; | import Hash from "../../Logic/Web/Hash"; | ||||||
| import Combine from "../Base/Combine"; | import Combine from "../Base/Combine"; | ||||||
| 
 | 
 | ||||||
| export default class SearchAndGo extends Combine { | export default class SearchAndGo extends Combine { | ||||||
|  |   constructor() { | ||||||
|  |     const goButton = Svg.search_ui().SetClass( | ||||||
|  |       "w-8 h-8 full-rounded border-black float-right" | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     constructor() { |     const placeholder = new UIEventSource<Translation>( | ||||||
|         const goButton = Svg.search_ui().SetClass('w-8 h-8 full-rounded border-black float-right'); |       Translations.t.general.search.search | ||||||
|  |     ); | ||||||
|  |     const searchField = new TextField({ | ||||||
|  |       placeholder: new VariableUiElement(placeholder), | ||||||
|  |       value: new UIEventSource<string>(""), | ||||||
|  |       inputStyle: | ||||||
|  |         " background: transparent;\n" + | ||||||
|  |         "    border: none;\n" + | ||||||
|  |         "    font-size: large;\n" + | ||||||
|  |         "    width: 100%;\n" + | ||||||
|  |         "    height: 100%;\n" + | ||||||
|  |         "    box-sizing: border-box;\n" + | ||||||
|  |         "    color: var(--foreground-color);", | ||||||
|  |     }); | ||||||
| 
 | 
 | ||||||
|         const placeholder = new UIEventSource<Translation>(Translations.t.general.search.search) |     searchField.SetClass("relative float-left mt-0 ml-2"); | ||||||
|         const searchField = new TextField({ |     searchField.SetStyle("width: calc(100% - 3em);height: 100%"); | ||||||
|                 placeholder: new VariableUiElement( |  | ||||||
|                     placeholder.map(uiElement => uiElement, [Locale.language]) |  | ||||||
|                 ), |  | ||||||
|                 value: new UIEventSource<string>(""), |  | ||||||
|              |  | ||||||
|             inputStyle: " background: transparent;\n" + |  | ||||||
|                 "    border: none;\n" + |  | ||||||
|                 "    font-size: large;\n" + |  | ||||||
|                 "    width: 100%;\n" + |  | ||||||
|                 "    box-sizing: border-box;\n" + |  | ||||||
|                 "    color: var(--foreground-color);" |  | ||||||
|              |  | ||||||
|             } |  | ||||||
|         ); |  | ||||||
|          |  | ||||||
|         searchField.SetClass("relative float-left mt-0 ml-2") |  | ||||||
|         searchField.SetStyle("width: calc(100% - 3em)") |  | ||||||
| 
 | 
 | ||||||
|         super([searchField, goButton]) |     super([searchField, goButton]); | ||||||
| 
 | 
 | ||||||
|         this.SetClass("block h-8") |     this.SetClass("block h-8"); | ||||||
|         this.SetStyle("background: var(--background-color); color: var(--foreground-color); pointer-evetns:all;") |     this.SetStyle( | ||||||
|  |       "background: var(--background-color); color: var(--foreground-color); pointer-evetns:all;" | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|  |     // Triggered by 'enter' or onclick
 | ||||||
|  |     function runSearch() { | ||||||
|  |       const searchString = searchField.GetValue().data; | ||||||
|  |       if (searchString === undefined || searchString === "") { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |       searchField.GetValue().setData(""); | ||||||
|  |       placeholder.setData(Translations.t.general.search.searching); | ||||||
|  |       Geocoding.Search( | ||||||
|  |         searchString, | ||||||
|  |         (result) => { | ||||||
|  |           console.log("Search result", result); | ||||||
|  |           if (result.length == 0) { | ||||||
|  |             placeholder.setData(Translations.t.general.search.nothing); | ||||||
|  |             return; | ||||||
|  |           } | ||||||
| 
 | 
 | ||||||
|         // Triggered by 'enter' or onclick
 |           const poi = result[0]; | ||||||
|         function runSearch() { |           const bb = poi.boundingbox; | ||||||
|             const searchString = searchField.GetValue().data; |           const bounds: [[number, number], [number, number]] = [ | ||||||
|             if (searchString === undefined || searchString === "") { |             [bb[0], bb[2]], | ||||||
|                 return; |             [bb[1], bb[3]], | ||||||
|             } |           ]; | ||||||
|             searchField.GetValue().setData(""); |           State.state.selectedElement.setData(undefined); | ||||||
|             placeholder.setData(Translations.t.general.search.searching); |           Hash.hash.setData(poi.osm_type + "/" + poi.osm_id); | ||||||
|             Geocoding.Search(searchString, (result) => { |           State.state.leafletMap.data.fitBounds(bounds); | ||||||
| 
 |           placeholder.setData(Translations.t.general.search.search); | ||||||
|                     console.log("Search result", result) |         }, | ||||||
|                     if (result.length == 0) { |         () => { | ||||||
|                         placeholder.setData(Translations.t.general.search.nothing); |           searchField.GetValue().setData(""); | ||||||
|                         return; |           placeholder.setData(Translations.t.general.search.error); | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     const poi = result[0]; |  | ||||||
|                     const bb = poi.boundingbox; |  | ||||||
|                     const bounds: [[number, number], [number, number]] = [ |  | ||||||
|                         [bb[0], bb[2]], |  | ||||||
|                         [bb[1], bb[3]] |  | ||||||
|                     ] |  | ||||||
|                     State.state.selectedElement.setData(undefined); |  | ||||||
|                     Hash.hash.setData(poi.osm_type + "/" + poi.osm_id); |  | ||||||
|                     State.state.leafletMap.data.fitBounds(bounds); |  | ||||||
|                     placeholder.setData(Translations.t.general.search.search); |  | ||||||
|                 }, |  | ||||||
|                 () => { |  | ||||||
|                     searchField.GetValue().setData(""); |  | ||||||
|                     placeholder.setData(Translations.t.general.search.error); |  | ||||||
|                 }); |  | ||||||
| 
 |  | ||||||
|         } |         } | ||||||
| 
 |       ); | ||||||
| 
 |  | ||||||
|         searchField.enterPressed.addCallback(runSearch); |  | ||||||
|         goButton.onClick(runSearch); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |     searchField.enterPressed.addCallback(runSearch); | ||||||
| } |     goButton.onClick(runSearch); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue