mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
Fancy searchbar
This commit is contained in:
@ -10,7 +10,8 @@ import {Segment, SegmentButton, SearchBar, List, Item, ActionMenu, Modal, ModalR
|
|||||||
console.log(NavbarTemplate, Navbar, Content, formDirectives);
|
console.log(NavbarTemplate, Navbar, Content, formDirectives);
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ion-view'
|
selector: 'ion-view',
|
||||||
|
appInjector: [FormBuilder]
|
||||||
})
|
})
|
||||||
@View({
|
@View({
|
||||||
template: `
|
template: `
|
||||||
@ -27,7 +28,7 @@ import {Segment, SegmentButton, SearchBar, List, Item, ActionMenu, Modal, ModalR
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form (^submit)="doSubmit($event)" [control-group]="form">
|
<form (^submit)="doSubmit($event)" [control-group]="form">
|
||||||
<ion-search-bar control="searchQuery"></ion-search-bar>
|
<ion-search-bar placeholder="Search" control="searchQuery"></ion-search-bar>
|
||||||
<div>
|
<div>
|
||||||
Query: <b>{{form.controls.searchQuery.value}}</b>
|
Query: <b>{{form.controls.searchQuery.value}}</b>
|
||||||
</div>
|
</div>
|
||||||
@ -37,9 +38,9 @@ import {Segment, SegmentButton, SearchBar, List, Item, ActionMenu, Modal, ModalR
|
|||||||
directives: [formDirectives, NavbarTemplate, Navbar, Content, SearchBar]
|
directives: [formDirectives, NavbarTemplate, Navbar, Content, SearchBar]
|
||||||
})
|
})
|
||||||
export class SearchBarPage {
|
export class SearchBarPage {
|
||||||
constructor() {
|
constructor(formBuilder: FormBuilder) {
|
||||||
var fb = new FormBuilder();
|
//var fb = new FormBuilder();
|
||||||
this.form = fb.group({
|
this.form = formBuilder.group({
|
||||||
searchQuery: ['', Validators.required]
|
searchQuery: ['', Validators.required]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
@mixin calc($property, $expression) {
|
||||||
|
#{$property}: -webkit-calc(#{$expression});
|
||||||
|
#{$property}: calc(#{$expression});
|
||||||
|
}
|
||||||
|
|
||||||
.no-transition {
|
.no-transition {
|
||||||
transition: none !important;
|
transition: none !important;
|
||||||
|
@ -15,6 +15,16 @@ $search-bar-ios-background-size: 13px 13px !default;
|
|||||||
background: $search-bar-ios-background-color;
|
background: $search-bar-ios-background-color;
|
||||||
@include hairline(bottom, $search-bar-ios-border-color);
|
@include hairline(bottom, $search-bar-ios-border-color);
|
||||||
|
|
||||||
|
.search-bar-icon {
|
||||||
|
width: 13px;
|
||||||
|
height: 13px;
|
||||||
|
@include svg-background-image($search-bar-ios-background-svg);
|
||||||
|
background-size: $search-bar-ios-background-size;
|
||||||
|
position: absolute;
|
||||||
|
left: 10px;
|
||||||
|
top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
.search-bar-input {
|
.search-bar-input {
|
||||||
height: $search-bar-ios-input-height;
|
height: $search-bar-ios-input-height;
|
||||||
padding: 0 28px;
|
padding: 0 28px;
|
||||||
@ -28,9 +38,15 @@ $search-bar-ios-background-size: 13px 13px !default;
|
|||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: 8px center;
|
background-position: 8px center;
|
||||||
|
|
||||||
@include svg-background-image($search-bar-ios-background-svg);
|
transition: all .2s ease;
|
||||||
background-size: $search-bar-ios-background-size;
|
|
||||||
}
|
@include calc(padding-left, "50% - 35px");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search-bar-input-container.focused {
|
||||||
|
.search-bar-input {
|
||||||
|
padding-left: 28px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,16 +8,23 @@ import {IonicComponent} from 'ionic/config/component'
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ion-search-bar',
|
selector: 'ion-search-bar',
|
||||||
properties: {
|
properties: [
|
||||||
cancelText: 'cancel-text',
|
'cancelText: cancel-text',
|
||||||
placeholderText: 'placeholder-text',
|
'placeholder: placeholder',
|
||||||
list: 'list',
|
'list: list',
|
||||||
query: 'query'
|
'query: query'
|
||||||
|
]
|
||||||
|
/*
|
||||||
|
hostProperties: {
|
||||||
|
'panelId': 'attr.id',
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
})
|
})
|
||||||
@View({
|
@View({
|
||||||
template: `<div class="search-bar-input-container">
|
template: `
|
||||||
<input (input)="inputChanged($event)" class="search-bar-input" type="search" [attr.placeholder]="placeholderText">
|
<div class="search-bar-input-container" [class.focused]="isFocused">
|
||||||
|
<div class="search-bar-icon"></div>
|
||||||
|
<input (focus)="inputFocused()" (blur)="inputBlurred()" (input)="inputChanged($event)" class="search-bar-input" type="search" [attr.placeholder]="placeholder">
|
||||||
</div>
|
</div>
|
||||||
<button class="button search-bar-cancel">{{ cancelText }}</button>`
|
<button class="button search-bar-cancel">{{ cancelText }}</button>`
|
||||||
})
|
})
|
||||||
@ -51,6 +58,13 @@ export class SearchBar {
|
|||||||
// TODO: Better way to do this?
|
// TODO: Better way to do this?
|
||||||
this.controlDirective._control().updateValue(event.target.value);
|
this.controlDirective._control().updateValue(event.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputFocused() {
|
||||||
|
this.isFocused = true;
|
||||||
|
}
|
||||||
|
inputBlurred() {
|
||||||
|
this.isFocused = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -86,7 +100,7 @@ new IonicComponent(SearchBar, {
|
|||||||
core: 'Cancel'
|
core: 'Cancel'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
placeholderText: {
|
placeholder: {
|
||||||
defaults: {
|
defaults: {
|
||||||
ios: 'Search',
|
ios: 'Search',
|
||||||
android: 'Search',
|
android: 'Search',
|
||||||
|
@ -11,6 +11,7 @@ $search-bar-min-height: 44px !default;
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-height: $search-bar-min-height;
|
min-height: $search-bar-min-height;
|
||||||
|
line-height: 3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-bar-input-container {
|
.search-bar-input-container {
|
||||||
|
Reference in New Issue
Block a user