Skip to content

Commit

Permalink
Merge pull request #6 from plantain-00/update-for-angular
Browse files Browse the repository at this point in the history
Based on #4 and #5, fix lint and add document for new props
  • Loading branch information
plantain-00 authored Aug 5, 2017
2 parents 68095e5 + a71fa7d commit f43607b
Show file tree
Hide file tree
Showing 24 changed files with 1,982 additions and 1,303 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ dist
!*.config.js
!**/*-*.js
!**/*-*.css

# Netbeans
/nbproject/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ A vuejs, reactjs and angular select component.
+ placeholder
+ custom component(vuejs and reactjs only)
+ multiple selection
+ material style(angular only)
+ form binding(angular only)

#### install

Expand Down Expand Up @@ -100,6 +102,9 @@ minCountForSearch | number? = 6 | hide search box if `options.length < minCountF
placeholder | string? | the placeholder string if nothing selected
customSearchEnabled | boolean? | will trigger `search` event, and disable inside filter
multiple | boolean? | select multiple options
material | `""` or `true` | enable material style(angular only)
editPattern | (str: string) => string | use it for change the pattern of the filter search(angular only)
ngModel/id/required/disabled/readonly/tabIndex | just like a `select` control | (angular only)
update | (value: [Select2UpdateValue](#select2-data-structure)) => void | triggered when user select an option
open | () => void | triggered when user open the options
search | (text: string) => void | triggered when search text changed
Expand All @@ -112,13 +117,15 @@ type Select2Data = (Select2Group | Select2Option)[];
type Select2Group = {
label: string;
options: Select2Option[];
classes?: string;
};

type Select2Option = {
value: Select2Value;
label: string;
disabled?: boolean;
component?: string | Function; // the component
classes?: string;
};

type Select2Value = string | number;
Expand Down

Large diffs are not rendered by default.

This file was deleted.

4 changes: 2 additions & 2 deletions demo/angular/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<link rel="stylesheet" href="../index.bundle-bf3a9ac354f50f05d52e53a111806c2a.css" crossOrigin="anonymous" integrity="sha256-FkSI4EGymi3Kmxa3MJc/bdoGRpQikI8ww27pLimkIc0=" />
<link rel="stylesheet" href="../index.bundle-33b91cc97d952c0c4ba0758646e581b8.css" crossOrigin="anonymous" integrity="sha256-GqYE89fIjCzZU3fhgU7DNMF1rINfUtQCrblfc6Vnv08=" />
<a class="github-fork-ribbon right-bottom" href="https://github.com/plantain-00/select2-component" title="Fork me on GitHub" target="_blank">Fork me on GitHub</a>
<app></app>
<script src="./index.bundle-b2f30b598bbfb68653d656611d74be26.js" crossOrigin="anonymous" integrity="sha256-NL6+owzxwkwNyS+lYuv+rsjyCQmD0lof25ihjzT8b7E="></script>
<script src="./index.bundle-1256acc2f44df637218ec81646b83ff9.js" crossOrigin="anonymous" integrity="sha256-XbRwmKd39enzuTpNXnxv1RCx9SHUhoVxqTG2UnqoH2o="></script>
125 changes: 2 additions & 123 deletions demo/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,129 +3,8 @@ import "core-js/es7/reflect";
import "zone.js/dist/zone";

import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { enableProdMode, ChangeDetectionStrategy } from "@angular/core";
import { enableProdMode } from "@angular/core";
import { MainModule } from "./main.module";

enableProdMode();

import { Component } from "@angular/core";

import { data1, data2, data3, data5 } from "../common";

@Component({
selector: "app",
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div style="width: 500px;">
<a href="https://github.com/plantain-00/select2-component/tree/master/demo/angular/index.ts" target="_blank">the source code of the demo</a>
<h3>options in group ({{value1}})</h3>
<select2 [data]="data1"
[value]="value1"
(update)="update1($event)">
</select2>
<h3>options ({{value2}})</h3>
<select2 [data]="data2"
[value]="value2"
(update)="update2($event)">
</select2>
<h3>less options ({{value3}})</h3>
<select2 [data]="data3"
[value]="value3"
(update)="update3($event)">
</select2>
<h3>disabled ({{value4}})</h3>
<select2 [data]="data4"
[value]="value4"
[disabled]="true">
</select2>
<h3>hide search box ({{value5}})</h3>
<select2 [data]="data5"
[value]="value5"
[minCountForSearch]="minCountForSearch"
(update)="update5($event)">
</select2>
<h3>placeholder ({{value6}})</h3>
<select2 [data]="data6"
placeholder="select an item"
(update)="update6($event)">
</select2>
<h3>open and search event ({{value7}})</h3>
<select2 [data]="data7"
customSearchEnabled="true"
(open)="open7()"
(search)="search7($event)"
(update)="update7($event)">
</select2>
<h3>multiple ({{value9}})</h3>
<select2 [data]="data9"
[value]="value9"
multiple="true"
(update)="update9($event)">
</select2>
</div>
`,
})
export class MainComponent {
data1 = data1;
data2 = data2;
data3 = data3;
data4: Select2Data = JSON.parse(JSON.stringify(data3));
data5 = data5;
data6: Select2Data = JSON.parse(JSON.stringify(data3));
data7: Select2Option[] = [];
data9: Select2Data = JSON.parse(JSON.stringify(data1));

minCountForSearch = Infinity;

value1 = "CA";
value2 = "CA";
value3 = "foo";
value4 = "bar";
value5 = "foo3";
value6 = "";
value7 = "";
value9: string[] = [];

update1(value: string) {
this.value1 = value;
}
update2(value: string) {
this.value2 = value;
}
update3(value: string) {
this.value3 = value;
}
update5(value: string) {
this.value5 = value;
}
update6(value: string) {
this.value6 = value;
}
open7() {
this.data7 = JSON.parse(JSON.stringify(data2));
}
update7(value: string) {
this.value7 = value;
}
search7(text: string) {
this.data7 = text
? (JSON.parse(JSON.stringify(data2)) as Select2Option[]).filter(option => option.label.toLowerCase().indexOf(text.toLowerCase()) > -1)
: JSON.parse(JSON.stringify(data2));
}
update9(value: string[]) {
this.value9 = value;
}
}

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { Select2Component, Select2Option, Select2Data } from "../../dist/angular";

@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [MainComponent, Select2Component],
bootstrap: [MainComponent],
})
class MainModule { }

platformBrowserDynamic().bootstrapModule(MainModule);
26 changes: 26 additions & 0 deletions demo/angular/main.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { NgModule, ApplicationRef } from "@angular/core";
import { CommonModule } from "@angular/common";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";

import { Select2Module } from "../../dist/angular";
import { MainComponent } from "./main";

@NgModule({
declarations: [
MainComponent,
],
imports: [
CommonModule,
BrowserModule,
FormsModule,
ReactiveFormsModule,
Select2Module,
],
bootstrap: [MainComponent],
})
export class MainModule {
constructor(
public appRef: ApplicationRef,
) { }
}
156 changes: 156 additions & 0 deletions demo/angular/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { Component, ChangeDetectionStrategy } from "@angular/core";
import { Validators, FormControl, FormBuilder, FormGroup } from "@angular/forms";

import { Select2Option, Select2Data } from "../../dist/angular";
import { data1, data2, data3, data5 } from "../common";

@Component({
selector: "app",
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div style="width: 500px;">
<a href="https://github.com/plantain-00/select2-component/tree/master/demo/angular/index.ts" target="_blank">the source code of the demo</a>
<h2>Standard</h2>
<h3>options in group ({{value1}})</h3>
<select2 [data]="data1"
[value]="value1"
(update)="update1($event)">
</select2>
<h3>options ({{value2}})</h3>
<select2 [data]="data2"
[value]="value2"
(update)="update2($event)">
</select2>
<h3>less options ({{value3}})</h3>
<select2 [data]="data3"
[value]="value3"
(update)="update3($event)">
</select2>
<h3>disabled ({{value4}})</h3>
<select2 [data]="data4"
[value]="value4"
[disabled]="true">
</select2>
<h3>hide search box ({{value5}})</h3>
<select2 [data]="data5"
[value]="value5"
[minCountForSearch]="minCountForSearch"
(update)="update5($event)">
</select2>
<h3>placeholder ({{value6}})</h3>
<select2 [data]="data6"
placeholder="select an item"
(update)="update6($event)">
</select2>
<h3>open and search event ({{value7}})</h3>
<select2 [data]="data7"
customSearchEnabled="true"
(open)="open7()"
(search)="search7($event)"
(update)="update7($event)">
</select2>
<h3>multiple ({{value9}})</h3>
<select2 [data]="data9"
[value]="value9"
multiple="true"
(update)="update9($event)">
</select2>
<h3>form binding ({{value10}})</h3>
<form [formGroup]="ctrlForm">
<select2
[(ngModel)]="value10"
[data]="data10"
formControlName="test10"
placeholder="Select a state"
material
></select2>
<button (click)="reset10()">reset</button>
<button (click)="change10()">Utah</button>
</form>
<h3>material style ({{value11}})</h3>
<select2 [data]="data11"
[value]="value11"
(update)="update11($event)"
material>
</select2>
</div>
`,
})
export class MainComponent {
data1 = data1;
data2 = data2;
data3 = data3;
data4: Select2Data = JSON.parse(JSON.stringify(data3));
data5 = data5;
data6: Select2Data = JSON.parse(JSON.stringify(data3));
data7: Select2Option[] = [];
data9: Select2Data = JSON.parse(JSON.stringify(data1));
data10: Select2Data = JSON.parse(JSON.stringify(data1));
data11: Select2Data = JSON.parse(JSON.stringify(data1));

minCountForSearch = Infinity;

ctrlForm: FormGroup;

value1 = "CA";
value2 = "CA";
value3 = "foo";
value4 = "bar";
value5 = "foo3";
value6 = "";
value7 = "";
value9: string[] = [];
value10 = "";
value11 = "CA";

constructor(private fb: FormBuilder) {
this.ctrlForm = this.fb.group({
test10: new FormControl(null, Validators.required),
});
}

update1(value: string) {
this.value1 = value;
}
update2(value: string) {
this.value2 = value;
}
update3(value: string) {
this.value3 = value;
}
update5(value: string) {
this.value5 = value;
}
update6(value: string) {
this.value6 = value;
}
open7() {
this.data7 = JSON.parse(JSON.stringify(data2));
}
update7(value: string) {
this.value7 = value;
}
search7(text: string) {
this.data7 = text
? (JSON.parse(JSON.stringify(data2)) as Select2Option[]).filter(option => option.label.toLowerCase().indexOf(text.toLowerCase()) > -1)
: JSON.parse(JSON.stringify(data2));
}
update9(value: string[]) {
this.value9 = value;
}
reset10() {
const test10 = this.ctrlForm.get("test10");
if (test10) {
test10.reset();
}
}
change10() {
const test10 = this.ctrlForm.get("test10");
if (test10) {
test10.setValue("UT");
}
}
update11(value: string) {
this.value11 = value;
}
}
12 changes: 6 additions & 6 deletions demo/file-size.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"angularIndexBundleJs": "771 kB 193 kB",
"reactIndexBundleJs": "164 kB 48.5 kB",
"vueIndexBundleJs": "102 kB 34.4 kB",
"indexBundleCss": "10.4 kB 1.93 kB",
"demoAngularIndexHtml": "550 B 401 B",
"demoReactIndexHtml": "565 B 409 B",
"angularIndexBundleJs": "959 kB 228 kB",
"reactIndexBundleJs": "166 kB 50.1 kB",
"vueIndexBundleJs": "103 kB 36 kB",
"indexBundleCss": "15.6 kB 2.64 kB",
"demoAngularIndexHtml": "550 B 404 B",
"demoReactIndexHtml": "565 B 410 B",
"demoVueIndexHtml": "565 B 410 B"
}
Loading

0 comments on commit f43607b

Please sign in to comment.