├── src
├── assets
│ └── .gitkeep
├── app
│ ├── app.component.css
│ ├── data-picker
│ │ ├── data-picker.module.ts
│ │ └── data-picker
│ │ │ ├── data-picker.models.ts
│ │ │ ├── data-picker.component.spec.ts
│ │ │ ├── data-picker.component.html
│ │ │ ├── data-picker.component.scss
│ │ │ └── data-picker.component.ts
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── app.component.spec.ts
│ └── app.component.html
├── favicon.ico
├── styles.css
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── typings.d.ts
├── tsconfig.app.json
├── index.html
├── main.ts
├── tsconfig.spec.json
├── test.ts
└── polyfills.ts
├── e2e
├── app.po.ts
├── tsconfig.e2e.json
└── app.e2e-spec.ts
├── .editorconfig
├── .travis.yml
├── tsconfig.json
├── .gitignore
├── protractor.conf.js
├── karma.conf.js
├── LICENSE
├── .angular-cli.json
├── package.json
├── tslint.json
└── README.md
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiyali/ng-data-picker/HEAD/src/favicon.ico
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/e2e/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "baseUrl": "./",
6 | "module": "es2015",
7 | "types": []
8 | },
9 | "exclude": [
10 | "test.ts",
11 | "**/*.spec.ts"
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # env
2 | language: node_js
3 | node_js:
4 | - "8"
5 | # scripts
6 | script:
7 | - yarn run build:prod
8 | - yarn run prepare
9 | # config
10 | notifications:
11 | email:
12 | on_success: never
13 | on_failure: always
14 | # safelist
15 | branches:
16 | only:
17 | - master
18 |
19 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": [
9 | "jasmine",
10 | "jasminewd2",
11 | "node"
12 | ]
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/e2e/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('ng-data-picker App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to app!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | NgDataPicker
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule);
12 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | },
13 | "files": [
14 | "test.ts"
15 | ],
16 | "include": [
17 | "**/*.spec.ts",
18 | "**/*.d.ts"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/src/app/data-picker/data-picker.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 |
4 | import { DataPickerComponent, PickerDataModel } from './data-picker/data-picker.component';
5 |
6 | @NgModule({
7 | imports: [
8 | CommonModule
9 | ],
10 | declarations: [DataPickerComponent],
11 | exports: [DataPickerComponent]
12 | })
13 | export class DataPickerModule { }
14 |
15 | export { DataPickerComponent, PickerDataModel }
16 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.css']
7 | })
8 | export class AppComponent {
9 | title = 'app';
10 |
11 | data = [
12 | {
13 | list: ['1', '2', '3', '4', '5', '6', '7', '8', '9'],
14 | currentIndex: 4
15 | }
16 | ]
17 |
18 | change (gIndex, iIndex) {
19 | console.log(gIndex, iIndex)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 |
4 | import { AppComponent } from './app.component';
5 | import { DataPickerModule } from './data-picker/data-picker.module';
6 |
7 | @NgModule({
8 | declarations: [
9 | AppComponent
10 | ],
11 | imports: [
12 | BrowserModule,
13 | DataPickerModule
14 | ],
15 | providers: [],
16 | bootstrap: [AppComponent]
17 | })
18 | export class AppModule { }
19 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "outDir": "./lib",
5 | "sourceMap": true,
6 | "declaration": false,
7 | "moduleResolution": "node",
8 | "emitDecoratorMetadata": true,
9 | "experimentalDecorators": true,
10 | "target": "es5",
11 | "typeRoots": [
12 | "node_modules/@types"
13 | ],
14 | "lib": [
15 | "es2017",
16 | "dom"
17 | ]
18 | },
19 | "include": [
20 | "src/app/data-picker"
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/src/app/data-picker/data-picker/data-picker.models.ts:
--------------------------------------------------------------------------------
1 | export interface PickerDataModel {
2 | textAlign?: 'start' | 'center' | 'end' | 'justify' | 'left' | 'right' | 'nowrap' | 'wrap'
3 | weight?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
4 | className?: string
5 |
6 | onClick?: Function
7 | currentIndex?: number
8 | list?: Array
9 |
10 | divider?: boolean
11 | text?: string
12 | }
13 |
14 | /*
15 | export const initialPickerData: PickerDataModel = {
16 | textAlign: 'center',
17 | weight: 1,
18 | className: '',
19 |
20 | onClick: (gIndex: number, iIndex: number): void => {},
21 | currentIndex: 0,
22 | list: [],
23 |
24 | divider: false,
25 | text: ''
26 | }
27 | // */
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /lib
6 | /tmp
7 | /out-tsc
8 |
9 | # dependencies
10 | /node_modules
11 |
12 | # IDEs and editors
13 | /.idea
14 | .project
15 | .classpath
16 | .c9/
17 | *.launch
18 | .settings/
19 | *.sublime-workspace
20 |
21 | # IDE - VSCode
22 | .vscode/*
23 | !.vscode/settings.json
24 | !.vscode/tasks.json
25 | !.vscode/launch.json
26 | !.vscode/extensions.json
27 |
28 | # misc
29 | /.sass-cache
30 | /connect.lock
31 | /coverage
32 | /libpeerconnection.log
33 | npm-debug.log
34 | testem.log
35 | /typings
36 | yarn-error.log
37 |
38 | # e2e
39 | /e2e/*.js
40 | /e2e/*.map
41 |
42 | # System Files
43 | .DS_Store
44 | Thumbs.db
45 |
--------------------------------------------------------------------------------
/src/app/data-picker/data-picker/data-picker.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { DataPickerComponent } from './data-picker.component';
4 |
5 | describe('DataPickerComponent', () => {
6 | let component: DataPickerComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ DataPickerComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(DataPickerComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should be created', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/src/app/data-picker/data-picker/data-picker.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
10 | {{ group.text }}
11 |
12 |
13 |
15 | {{ item.value || item }}
16 |
17 |
18 |
19 |
20 |
21 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 |
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async(() => {
7 | TestBed.configureTestingModule({
8 | declarations: [
9 | AppComponent
10 | ],
11 | }).compileComponents();
12 | }));
13 |
14 | it('should create the app', async(() => {
15 | const fixture = TestBed.createComponent(AppComponent);
16 | const app = fixture.debugElement.componentInstance;
17 | expect(app).toBeTruthy();
18 | }));
19 |
20 | it(`should have as title 'app'`, async(() => {
21 | const fixture = TestBed.createComponent(AppComponent);
22 | const app = fixture.debugElement.componentInstance;
23 | expect(app.title).toEqual('app');
24 | }));
25 |
26 | it('should render title in a h1 tag', async(() => {
27 | const fixture = TestBed.createComponent(AppComponent);
28 | fixture.detectChanges();
29 | const compiled = fixture.debugElement.nativeElement;
30 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
31 | }));
32 | });
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017-present, Salam Hiyali
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/.angular-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "project": {
4 | "name": "ng-data-picker"
5 | },
6 | "apps": [
7 | {
8 | "root": "src",
9 | "outDir": "dist",
10 | "assets": [
11 | "assets",
12 | "favicon.ico"
13 | ],
14 | "index": "index.html",
15 | "main": "main.ts",
16 | "polyfills": "polyfills.ts",
17 | "test": "test.ts",
18 | "tsconfig": "tsconfig.app.json",
19 | "testTsconfig": "tsconfig.spec.json",
20 | "prefix": "app",
21 | "styles": [
22 | "styles.css"
23 | ],
24 | "scripts": [],
25 | "environmentSource": "environments/environment.ts",
26 | "environments": {
27 | "dev": "environments/environment.ts",
28 | "prod": "environments/environment.prod.ts"
29 | }
30 | }
31 | ],
32 | "e2e": {
33 | "protractor": {
34 | "config": "./protractor.conf.js"
35 | }
36 | },
37 | "lint": [
38 | {
39 | "project": "src/tsconfig.app.json",
40 | "exclude": "**/node_modules/**"
41 | },
42 | {
43 | "project": "src/tsconfig.spec.json",
44 | "exclude": "**/node_modules/**"
45 | },
46 | {
47 | "project": "e2e/tsconfig.e2e.json",
48 | "exclude": "**/node_modules/**"
49 | }
50 | ],
51 | "test": {
52 | "karma": {
53 | "config": "./karma.conf.js"
54 | }
55 | },
56 | "defaults": {
57 | "styleExt": "css",
58 | "component": {}
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ng-data-picker",
3 | "author": "Salam Hiyali",
4 | "version": "0.1.5",
5 | "description": "A data picker that like iOS native datetime picker based on Angular 4+",
6 | "license": "MIT",
7 | "main": "lib/data-picker.module",
8 | "scripts": {
9 | "build": "ng build",
10 | "build:prod": "npm run lint && ng build -prod --aot=false",
11 | "e2e": "ng e2e",
12 | "lint": "ng lint",
13 | "ng": "ng",
14 | "prepare": "npm run lint & tsc",
15 | "start": "ng serve",
16 | "test": "ng test"
17 | },
18 | "files": [
19 | "lib/*",
20 | "README.md",
21 | "LICENSE"
22 | ],
23 | "dependencies": {
24 | "@angular/core": "^4.2.4"
25 | },
26 | "devDependencies": {
27 | "@angular/animations": "^4.2.4",
28 | "@angular/cli": "1.3.0",
29 | "@angular/common": "^4.2.4",
30 | "@angular/compiler": "^4.2.4",
31 | "@angular/compiler-cli": "^4.2.4",
32 | "@angular/forms": "^4.2.4",
33 | "@angular/http": "^4.2.4",
34 | "@angular/language-service": "^4.2.4",
35 | "@angular/platform-browser": "^4.2.4",
36 | "@angular/platform-browser-dynamic": "^4.2.4",
37 | "@angular/router": "^4.2.4",
38 | "@types/jasmine": "~2.5.53",
39 | "@types/jasminewd2": "~2.0.2",
40 | "@types/node": "~6.0.60",
41 | "codelyzer": "~3.1.1",
42 | "core-js": "^2.4.1",
43 | "jasmine-core": "~2.6.2",
44 | "jasmine-spec-reporter": "~4.1.0",
45 | "karma": "~1.7.0",
46 | "karma-chrome-launcher": "~2.1.1",
47 | "karma-cli": "~1.0.1",
48 | "karma-coverage-istanbul-reporter": "^1.2.1",
49 | "karma-jasmine": "~1.1.0",
50 | "karma-jasmine-html-reporter": "^0.2.2",
51 | "protractor": "~5.1.2",
52 | "rxjs": "^5.4.2",
53 | "ts-node": "~3.2.0",
54 | "tslint": "~5.3.2",
55 | "typescript": "~2.3.3",
56 | "zone.js": "^0.8.14"
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Welcome to {{title}}!
5 |
6 |

7 |
8 | Here are some links to help you start:
9 |
10 |
11 |
12 |
13 | -
14 |
15 |
16 | -
17 |
18 |
19 | -
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/app/data-picker/data-picker/data-picker.component.scss:
--------------------------------------------------------------------------------
1 | @function r($px) {
2 | @return ($px / 16) * 1em
3 | }
4 |
5 | $pickerHeight: 160;
6 | $middleLayerHeight: 32;
7 |
8 | .ng-data-picker {
9 | font-size: 1rem;
10 | height: r($pickerHeight);
11 | position: relative;
12 | background-color: transparent;
13 | overflow: hidden;
14 | &.black {
15 | color: white;
16 | }
17 | .picker-group {
18 |
19 | }
20 | .picker-list {
21 | height: r(100);
22 | position: relative;
23 | top: r($pickerHeight / 2 - $middleLayerHeight / 2); // half of picker height - half of item height
24 | }
25 | .picker-item {
26 | position: absolute;
27 | top: 0;
28 | left: 0;
29 | overflow: hidden;
30 | width: 100%;
31 | text-overflow: ellipsis;
32 | white-space: nowrap;
33 | display: block;
34 | text-align: center;
35 | will-change: transform;
36 | contain: strict;
37 | height: r($middleLayerHeight);
38 | line-height: 2;
39 | font-size: 1em;
40 | }
41 | .selected-item {
42 |
43 | }
44 | .picker-handle-layer {
45 | position: absolute;
46 | width: 100%;
47 | height: calc(100% + 2px);
48 | left: 0;
49 | right: 0;
50 | top: -1px;
51 | bottom: -1px;
52 |
53 | .picker-top {
54 | border-bottom: 0.55px solid #4a4959;
55 | background: linear-gradient(to bottom, white 2%, rgba(255, 255, 255, 0.1) 100%);
56 | transform: translate3d(0, 0, 5.625em);
57 | }
58 | .picker-middle {
59 | height: r($middleLayerHeight);
60 | }
61 | .picker-bottom {
62 | border-top: 0.55px solid #4a4959;
63 | background: linear-gradient(to top, white 2%, rgba(255, 255, 255, 0.1) 100%);
64 | transform: translate3d(0, 0, 5.625em);
65 | }
66 | }
67 |
68 | /* flex system */
69 | .flex-box {
70 | display: flex;
71 |
72 | $props: column row;
73 | @each $prop in $props {
74 | &.dir-#{$prop} {
75 | flex-direction: $prop;
76 | }
77 | }
78 |
79 | /* for items */
80 | @for $n from 1 to 12 {
81 | .weight-#{$n} {
82 | flex: $n;
83 | }
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** Evergreen browsers require these. **/
41 | import 'core-js/es6/reflect';
42 | import 'core-js/es7/reflect';
43 |
44 |
45 | /**
46 | * Required to support Web Animations `@angular/animation`.
47 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
48 | **/
49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
50 |
51 |
52 |
53 | /***************************************************************************************************
54 | * Zone JS is required by Angular itself.
55 | */
56 | import 'zone.js/dist/zone'; // Included with Angular CLI.
57 |
58 |
59 |
60 | /***************************************************************************************************
61 | * APPLICATION IMPORTS
62 | */
63 |
64 | /**
65 | * Date, currency, decimal and percent pipes.
66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
67 | */
68 | // import 'intl'; // Run `npm install --save intl`.
69 | /**
70 | * Need to import at least one locale-data with intl.
71 | */
72 | // import 'intl/locale-data/jsonp/en';
73 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "eofline": true,
15 | "forin": true,
16 | "import-blacklist": [
17 | true,
18 | "rxjs"
19 | ],
20 | "import-spacing": true,
21 | "indent": [
22 | true,
23 | "spaces"
24 | ],
25 | "interface-over-type-literal": true,
26 | "label-position": true,
27 | "max-line-length": [
28 | true,
29 | 140
30 | ],
31 | "member-access": false,
32 | "member-ordering": [
33 | true,
34 | {
35 | "order": [
36 | "static-field",
37 | "instance-field",
38 | "static-method",
39 | "instance-method"
40 | ]
41 | }
42 | ],
43 | "no-arg": true,
44 | "no-bitwise": true,
45 | "no-console": [
46 | true,
47 | "debug",
48 | "info",
49 | "time",
50 | "timeEnd",
51 | "trace"
52 | ],
53 | "no-construct": true,
54 | "no-debugger": true,
55 | "no-duplicate-super": true,
56 | "no-empty": false,
57 | "no-empty-interface": true,
58 | "no-eval": true,
59 | "no-inferrable-types": [
60 | true,
61 | "ignore-params"
62 | ],
63 | "no-misused-new": true,
64 | "no-non-null-assertion": true,
65 | "no-shadowed-variable": true,
66 | "no-string-literal": false,
67 | "no-string-throw": true,
68 | "no-switch-case-fall-through": true,
69 | "no-trailing-whitespace": true,
70 | "no-unnecessary-initializer": true,
71 | "no-unused-expression": true,
72 | "no-use-before-declare": true,
73 | "no-var-keyword": true,
74 | "object-literal-sort-keys": false,
75 | "one-line": [
76 | true,
77 | "check-open-brace",
78 | "check-catch",
79 | "check-else",
80 | "check-whitespace"
81 | ],
82 | "prefer-const": true,
83 | "quotemark": [
84 | true,
85 | "single"
86 | ],
87 | "radix": true,
88 | "semicolon": [
89 | false,
90 | "always"
91 | ],
92 | "triple-equals": [
93 | true,
94 | "allow-null-check"
95 | ],
96 | "typedef-whitespace": [
97 | true,
98 | {
99 | "call-signature": "nospace",
100 | "index-signature": "nospace",
101 | "parameter": "nospace",
102 | "property-declaration": "nospace",
103 | "variable-declaration": "nospace"
104 | }
105 | ],
106 | "typeof-compare": true,
107 | "unified-signatures": true,
108 | "variable-name": false,
109 | "whitespace": [
110 | true,
111 | "check-branch",
112 | "check-decl",
113 | "check-operator",
114 | "check-separator",
115 | "check-type"
116 | ],
117 | "directive-selector": [
118 | true,
119 | "attribute",
120 | "app",
121 | "ng",
122 | "camelCase"
123 | ],
124 | "component-selector": [
125 | false,
126 | "element",
127 | "app",
128 | "kebab-case"
129 | ],
130 | "use-input-property-decorator": true,
131 | "use-output-property-decorator": true,
132 | "use-host-property-decorator": true,
133 | "no-input-rename": true,
134 | "no-output-rename": true,
135 | "use-life-cycle-interface": true,
136 | "use-pipe-transform-interface": true,
137 | "component-class-suffix": true,
138 | "directive-class-suffix": true,
139 | "no-access-missing-member": true,
140 | "templates-use-public": true,
141 | "invoke-injectable": true
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **No time for maintenance** - welcome to send a useful PR :)
2 | # ng-data-picker [](https://npmjs.com/package/ng-data-picker)
3 | 🏄🏾 A Data Picker for Angular 4+
4 |
5 | [](https://npmjs.com/package/ng-data-picker)
6 | [](https://travis-ci.org/hiyali/ng-data-picker)
7 | [](https://npmjs.org/package/ng-data-picker)
8 | 
9 | [](https://circleci.com/gh/hiyali/ng-data-picker/tree/master)
10 |
11 | [](https://npmjs.org/package/ng-data-picker)
12 |
13 | > Let's more easily select some data on the touch screen device, such as time / city / gender / seat number / product / ...
14 |
15 | ## Examples
16 |
17 | > See branch [gh-pages](https://github.com/hiyali/ng-data-picker/tree/gh-pages) for all code of extant examples and environment.
18 |
19 | | Demo | Level | Code |
20 | | :-------- | :--------- | :-------- |
21 | | [gender](https://hiyali.github.io/ng-data-picker/docs/#/gender) | ★ | [gender.component.ts](https://github.com/hiyali/ng-data-picker/tree/gh-pages/src/app/gender/gender.component.ts) |
22 | | [product](https://hiyali.github.io/ng-data-picker/docs/#/product) | ★★ | [product.component.ts](https://github.com/hiyali/ng-data-picker/tree/gh-pages/src/app/product/product.component.ts) |
23 | | [date-time](https://hiyali.github.io/ng-data-picker/docs/#/date-time) | ★★★ | [date-time.component.ts](https://github.com/hiyali/ng-data-picker/tree/gh-pages/src/app/date-time/date-time.component.ts) |
24 |
25 | ## Take a look
26 |
27 | 
28 |
29 | ⚠️ Below gif is a temporary used from [vue version](https://github.com/hiyali/vue-smooth-picker) of this picker. will be updated soon.
30 |
31 | 
32 |
33 | ## Install
34 |
35 | ```shell
36 | yarn add ng-data-picker
37 | ```
38 | or
39 | ```shell
40 | npm i -S ng-data-picker
41 | ```
42 |
43 | ## Usage
44 |
45 | ### Quick look
46 |
47 | #### app.module.ts
48 | ```typescript
49 | import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'
50 | import { DataPickerComponent } from 'ng-data-picker'
51 |
52 | @NgModule({
53 | ...
54 | declarations: [
55 | DataPickerComponent
56 | ],
57 | schemas: [
58 | NO_ERRORS_SCHEMA // for third party component
59 | ],
60 | ...
61 | })
62 | ```
63 |
64 | #### app.component.ts
65 | ```typescript
66 | export class AppComponent {
67 | data = [
68 | {
69 | list: ['sun', 'earth', 'moon']
70 | }
71 | ]
72 |
73 | change ({ gIndex, iIndex }) {
74 | console.log(gIndex, iIndex)
75 | }
76 | }
77 | ```
78 |
79 | #### app.component.html
80 | ```html
81 |
82 | ```
83 |
84 | ## ⚙️ Props
85 |
86 | | name | type | default | explain |
87 | | :------------------------- | :--------- | :------------ | :------------------------------- |
88 | | `change` | `Function` | ({gIndex,iIndex})=>{} | Callback after which group's current index changed, pass two arguments, group index `gIndex` and item index `iIndex` |
89 | | `data` | `Array` | [] | Picker initial data |
90 | | `data[i].currentIndex` | `Number` | 0 | Current index of this group's list |
91 | | `data[i].weight` | `Number` | 1 | Group weights in parent width `1..12` |
92 | | `data[i].list` | `Array` | - | List of the group |
93 | | `data[i].list[j]` | `String` or `Object` | - | Item in the list of group, use `value` key when it is a object item |
94 | | `data[i].onClick` | `Function` | - | Click event on the middle layer of this group, pass two arguments that group index `gIndex` and selected index `iIndex` of this group |
95 | | `data[i].textAlign` | `String` | - | `start` `center` `end` `justify` `left` `right` `nowrap` `wrap` |
96 | | `data[i].className` | `String` | - | Your custom class name for this group |
97 | | `data[i].divider` | `Boolean` | false | If it is true, then `onClick` `list` `currentIndex` will not be used |
98 | | `data[i].text` | `String` | - | Just use this text when `divider` is true |
99 |
100 | ## 🔨 Instance methods
101 |
102 | | name | type | explain |
103 | | :------------------------- | :--------- | :------------------------------- |
104 | | `setGroupData` | `Function` (gIndex,gData)=>void | Dynamically set a group data with two arguments `(gIndex, gData)`, group index and group data (see props `data[i]`) |
105 | | `getCurrentIndexList` | `Function` ()=>[] | Return a `Array` of the groups current index list (has divider current index, and it is default to `0`) |
106 | | `getGroupsRectList` | `Function` ()=>void | Get some info for gesture, you can call this function when the component displayed if the component is hidden when it's initialization |
107 |
108 | ## Development
109 |
110 | ```shell
111 | npm start # development
112 | npm run build:prod # build for production
113 | npm run prepare # build for third party
114 | ```
115 |
116 | ## Any problem?
117 |
118 | > Please let me know.
119 | * [Open a new issue for this repo](https://github.com/hiyali/ng-data-picker/issues)
120 | * [Send a Email to: hiyali920@gmail.com](mailto:hiyali920@gmail.com)
121 |
122 | ## Is it useful?
123 |
124 | 🌚 Donate [A github star ⍟](https://github.com/hiyali/ng-data-picker)
125 |
126 | ## License
127 |
128 | MIT
129 |
130 |
--------------------------------------------------------------------------------
/src/app/data-picker/data-picker/data-picker.component.ts:
--------------------------------------------------------------------------------
1 | import {
2 | OnInit, AfterViewInit, OnDestroy, Inject, Component,
3 | Input, Output, EventEmitter, ElementRef, ViewChild, ViewChildren
4 | } from '@angular/core'
5 |
6 | import { PickerDataModel } from './data-picker.models'
7 | export { PickerDataModel }
8 |
9 | @Component({
10 | selector: 'ng-data-picker',
11 | // templateUrl: './data-picker.component.html',
12 | template: `
13 |
14 |
15 |
16 |
18 |
19 |
20 |
22 | {{ group.text }}
23 |
24 |
25 |
27 | {{ item.value || item }}
28 |
29 |
30 |
31 |
32 |
33 |
38 |
39 |
40 | `,
41 | // styleUrls: ['./data-picker.component.scss']
42 | styles: [`
43 | .ng-data-picker {
44 | font-size: 1rem;
45 | height: 10em;
46 | position: relative;
47 | background-color: white;
48 | overflow: hidden;
49 | }
50 | .ng-data-picker.black {
51 | color: white;
52 | }
53 | .ng-data-picker .picker-group {
54 | }
55 | .ng-data-picker .picker-list {
56 | height: 6.25em;
57 | position: relative;
58 | top: 4em; // half of picker height - half of item height
59 | }
60 | .ng-data-picker .picker-item {
61 | position: absolute;
62 | top: 0;
63 | left: 0;
64 | overflow: hidden;
65 | width: 100%;
66 | text-overflow: ellipsis;
67 | white-space: nowrap;
68 | display: block;
69 | text-align: center;
70 | will-change: transform;
71 | contain: strict;
72 | height: 2em;
73 | line-height: 2;
74 | font-size: 1em;
75 | }
76 | .ng-data-picker .selected-item {
77 | }
78 |
79 | /* picker handle layer */
80 | .ng-data-picker .picker-handle-layer {
81 | position: absolute;
82 | width: 100%;
83 | height: calc(100% + 2px);
84 | left: 0;
85 | right: 0;
86 | top: -1px;
87 | bottom: -1px;
88 | }
89 | .ng-data-picker .picker-handle-layer .picker-top {
90 | border-bottom: 0.55px solid rgba(74, 73, 89, 0.5);
91 | background: linear-gradient(to bottom, white 2%, rgba(255, 255, 255, 0.1) 100%);
92 | transform: translate3d(0, 0, 5.625em);
93 | }
94 | .ng-data-picker .picker-handle-layer .picker-middle {
95 | height: 2em;
96 | }
97 | .ng-data-picker .picker-handle-layer .picker-bottom {
98 | border-top: 0.55px solid rgba(74, 73, 89, 0.5);
99 | background: linear-gradient(to top, white 2%, rgba(255, 255, 255, 0.1) 100%);
100 | transform: translate3d(0, 0, 5.625em);
101 | }
102 |
103 | /* flex system */
104 | .flex-box {
105 | display: flex;
106 | }
107 | .flex-box.dir-column {
108 | flex-direction: column;
109 | }
110 | .flex-box.dir-row {
111 | flex-direction: row;
112 | }
113 |
114 | /* flex system - for items */
115 | .flex-box .weight-1 {
116 | flex: 1;
117 | }
118 | .flex-box .weight-2 {
119 | flex: 2;
120 | }
121 | .flex-box .weight-3 {
122 | flex: 3;
123 | }
124 | .flex-box .weight-4 {
125 | flex: 4;
126 | }
127 | .flex-box .weight-5 {
128 | flex: 5;
129 | }
130 | .flex-box .weight-6 {
131 | flex: 6;
132 | }
133 | .flex-box .weight-7 {
134 | flex: 7;
135 | }
136 | .flex-box .weight-8 {
137 | flex: 8;
138 | }
139 | .flex-box .weight-9 {
140 | flex: 9;
141 | }
142 | .flex-box .weight-10 {
143 | flex: 10;
144 | }
145 | .flex-box .weight-11 {
146 | flex: 11;
147 | }
148 | .flex-box .weight-12 {
149 | flex: 12;
150 | }
151 | `]
152 | })
153 | export class DataPickerComponent implements OnInit, AfterViewInit, OnDestroy {
154 | @ViewChildren('pickerGroupLayer') pickerGroupLayer
155 | @ViewChild('pickerHandleLayer') pickerHandleLayer
156 |
157 | @Input() data: PickerDataModel[] = []
158 | @Output() change: EventEmitter = new EventEmitter()
159 |
160 | currentIndexList: number[]
161 | lastCurrentIndexList: number[]
162 | groupsRectList: any[]
163 | touchOrMouse = {
164 | isTouchable: 'ontouchstart' in window,
165 | isMouseDown: false
166 | }
167 | draggingInfo = {
168 | isDragging: false,
169 | groupIndex: null,
170 | startPageY: null
171 | }
172 | itemPerDegree = 23
173 | safeDoTimeoutId: any = null
174 |
175 | constructor(@Inject(ElementRef) elementRef: ElementRef) {
176 | // console.log('picker dom', elementRef.nativeElement)
177 | }
178 |
179 | ngOnInit() {
180 | this.currentIndexList = this.getInitialCurrentIndexList()
181 | this.lastCurrentIndexList = [].concat(this.currentIndexList)
182 |
183 | this.groupsRectList = new Array(this.data.length)
184 |
185 | this.eventsRegister()
186 | window.addEventListener('resize', this.safeGetRectsBindEvents.bind(this))
187 | }
188 |
189 | ngAfterViewInit() {
190 | this.getGroupsRectList()
191 | }
192 |
193 | ngOnDestroy () {
194 | window.removeEventListener('resize', this.safeGetRectsBindEvents.bind(this))
195 | }
196 |
197 | setGroupData (gIndex, groupData) {
198 | if (!this.currentIndexList) {
199 | this.currentIndexList = this.getInitialCurrentIndexList()
200 | }
201 | this.data[gIndex] = groupData
202 | const iCI = groupData.currentIndex
203 | let movedIndex = 0
204 | if (typeof iCI === 'number' && iCI >= 0 && groupData.list && groupData.list.length && iCI <= groupData.list.length - 1) {
205 | movedIndex = Math.round(iCI)
206 | }
207 | this.currentIndexList[gIndex] = movedIndex
208 | this.lastCurrentIndexList = [].concat(this.currentIndexList)
209 | }
210 |
211 | getInitialCurrentIndexList () {
212 | return this.data.map((item, index) => {
213 | const iCI = item.currentIndex
214 | if (typeof iCI === 'number' && iCI >= 0 && item.list && item.list.length && iCI <= item.list.length - 1) {
215 | return Math.round(iCI)
216 | }
217 | return 0
218 | })
219 | }
220 |
221 | safeGetRectsBindEvents () {
222 | if (this.safeDoTimeoutId) {
223 | clearTimeout(this.safeDoTimeoutId)
224 | }
225 | this.safeDoTimeoutId = setTimeout(() => {
226 | this.getGroupsRectList()
227 | }, 200)
228 | }
229 |
230 | getGroupsRectList () {
231 | if (this.pickerGroupLayer) {
232 | this.pickerGroupLayer.toArray().forEach((item, index) => {
233 | this.groupsRectList[index] = item.nativeElement.getBoundingClientRect()
234 | })
235 | }
236 | }
237 |
238 | eventsRegister () {
239 | const handleEventLayer = this.pickerHandleLayer.nativeElement
240 | if (handleEventLayer) {
241 | this.addEventsForElement(handleEventLayer)
242 | }
243 | }
244 |
245 | addEventsForElement (el) {
246 | const _ = this.touchOrMouse.isTouchable
247 | const eventHandlerList = [
248 | { name: _ ? 'touchstart' : 'mousedown', handler: this.handleStart },
249 | { name: _ ? 'touchmove' : 'mousemove', handler: this.handleMove },
250 | { name: _ ? 'touchend' : 'mouseup', handler: this.handleEnd },
251 | { name: _ ? 'touchcancel' : 'mouseleave', handler: this.handleCancel }
252 | ]
253 | eventHandlerList.forEach((item, index) => {
254 | el.removeEventListener(item.name, item.handler, false)
255 | el.addEventListener(item.name, item.handler.bind(this), false)
256 | })
257 | }
258 |
259 | triggerMiddleLayerGroupClick (gIndex) {
260 | const data = this.data
261 | if (typeof gIndex === 'number' && typeof data[gIndex].onClick === 'function') {
262 | data[gIndex].onClick(gIndex, this.currentIndexList[gIndex])
263 | }
264 | }
265 |
266 | triggerAboveLayerClick (ev, gIndex) {
267 | const movedIndex = this.currentIndexList[gIndex] + 1
268 | this.currentIndexList[gIndex] = movedIndex
269 | this.correctionCurrentIndex(ev, gIndex)
270 | }
271 |
272 | triggerMiddleLayerClick (ev, gIndex) {
273 | this.triggerMiddleLayerGroupClick(gIndex)
274 | }
275 |
276 | triggerBelowLayerClick (ev, gIndex) {
277 | const movedIndex = this.currentIndexList[gIndex] - 1
278 | this.currentIndexList[gIndex] = movedIndex
279 | this.correctionCurrentIndex(ev, gIndex)
280 | }
281 |
282 | getTouchInfo (ev) {
283 | return this.touchOrMouse.isTouchable ? ev.changedTouches[0] || ev.touches[0] : ev
284 | }
285 |
286 | getGroupIndexBelongsEvent (ev) {
287 | const touchInfo = this.getTouchInfo(ev)
288 | for (let i = 0; i < this.groupsRectList.length; i++) {
289 | const item = this.groupsRectList[i]
290 | if (item.left < touchInfo.pageX && touchInfo.pageX < item.right) {
291 | return i
292 | }
293 | }
294 | return null
295 | }
296 |
297 | handleEventClick (ev) {
298 | const gIndex = this.getGroupIndexBelongsEvent(ev)
299 | switch (ev.target.dataset.type) {
300 | case 'top':
301 | this.triggerAboveLayerClick(ev, gIndex)
302 | break
303 | case 'middle':
304 | this.triggerMiddleLayerClick(ev, gIndex)
305 | break
306 | case 'bottom':
307 | this.triggerBelowLayerClick(ev, gIndex)
308 | break
309 | default:
310 | }
311 | }
312 |
313 | handleStart (ev) {
314 | if (ev.cancelable) {
315 | ev.preventDefault()
316 | ev.stopPropagation()
317 | }
318 | const touchInfo = this.getTouchInfo(ev)
319 | this.draggingInfo.startPageY = touchInfo.pageY
320 | if (!this.touchOrMouse.isTouchable) {
321 | this.touchOrMouse.isMouseDown = true
322 | }
323 | }
324 |
325 | handleMove (ev) {
326 | ev.preventDefault()
327 | ev.stopPropagation()
328 | if (this.touchOrMouse.isTouchable || this.touchOrMouse.isMouseDown) {
329 | this.draggingInfo.isDragging = true
330 | this.setCurrentIndexOnMove(ev)
331 | }
332 | }
333 |
334 | handleEnd (ev) {
335 | ev.preventDefault()
336 | ev.stopPropagation()
337 | if (!this.draggingInfo.isDragging) {
338 | this.handleEventClick(ev)
339 | }
340 | this.draggingInfo.isDragging = false
341 | this.touchOrMouse.isMouseDown = false
342 | this.correctionAfterDragging(ev)
343 | }
344 |
345 | handleCancel (ev) {
346 | ev.preventDefault()
347 | ev.stopPropagation()
348 | if (this.touchOrMouse.isTouchable || this.touchOrMouse.isMouseDown) {
349 | this.correctionAfterDragging(ev)
350 | this.touchOrMouse.isMouseDown = false
351 | this.draggingInfo.isDragging = false
352 | }
353 | }
354 |
355 | setCurrentIndexOnMove (ev) {
356 | const touchInfo = this.getTouchInfo(ev)
357 | if (this.draggingInfo.groupIndex === null) {
358 | this.draggingInfo.groupIndex = this.getGroupIndexBelongsEvent(ev)
359 | }
360 | const gIndex = this.draggingInfo.groupIndex
361 | if (typeof gIndex === 'number' && (this.data[gIndex].divider || !this.data[gIndex].list)) {
362 | return
363 | }
364 | const moveCount = (this.draggingInfo.startPageY - touchInfo.pageY) / 32
365 | const movedIndex = this.currentIndexList[gIndex] + moveCount
366 | this.currentIndexList[gIndex] = movedIndex
367 | this.draggingInfo.startPageY = touchInfo.pageY
368 | }
369 |
370 | correctionAfterDragging (ev) {
371 | const gIndex = this.draggingInfo.groupIndex
372 | this.correctionCurrentIndex(ev, gIndex)
373 | this.draggingInfo.groupIndex = null
374 | this.draggingInfo.startPageY = null
375 | }
376 |
377 | correctionCurrentIndex (ev, gIndex) {
378 | setTimeout(() => {
379 | if (typeof gIndex === 'number' && this.data[gIndex].divider !== true && this.data[gIndex].list.length > 0) {
380 | const unsafeGroupIndex = this.currentIndexList[gIndex]
381 | let movedIndex = unsafeGroupIndex
382 | if (unsafeGroupIndex > this.data[gIndex].list.length - 1) {
383 | movedIndex = this.data[gIndex].list.length - 1
384 | } else if (unsafeGroupIndex < 0) {
385 | movedIndex = 0
386 | }
387 | movedIndex = Math.round(movedIndex)
388 | this.currentIndexList[gIndex] = movedIndex
389 | if (movedIndex !== this.lastCurrentIndexList[gIndex]) {
390 | this.change.emit({ gIndex, iIndex: movedIndex })
391 | }
392 | this.lastCurrentIndexList = [].concat(this.currentIndexList)
393 | }
394 | }, 100)
395 | }
396 |
397 | isCurrentItem (gIndex, iIndex) {
398 | return this.currentIndexList[gIndex] === iIndex
399 | }
400 |
401 | getCurrentIndexList () {
402 | return this.currentIndexList
403 | }
404 |
405 | getGroupClass (gIndex) {
406 | const group = this.data[gIndex]
407 | const defaultWeightClass = 'weight-' + (group.weight || 1)
408 | const groupClass = [defaultWeightClass]
409 | if (group.className) {
410 | groupClass.push(group.className)
411 | }
412 | return groupClass
413 | }
414 |
415 | getItemClass (gIndex, iIndex, isDivider = false) {
416 | const group = this.data[gIndex]
417 | const itemClass = []
418 | if (!isDivider && this.isCurrentItem(gIndex, iIndex)) {
419 | itemClass.push('smooth-item-selected')
420 | }
421 | if (group.textAlign) {
422 | itemClass.push('text-' + group.textAlign)
423 | }
424 | return itemClass
425 | }
426 |
427 | getItemStyle (gIndex, iIndex) {
428 | const gapCount = this.currentIndexList[gIndex] - iIndex
429 | if (Math.abs(gapCount) < (90 / this.itemPerDegree)) {
430 | const rotateStyle = {
431 | transform: 'rotateX(' + gapCount * this.itemPerDegree + 'deg) translate3d(0, 0, 5.625em)',
432 | opacity: (1 - Math.abs(gapCount) / (90 / this.itemPerDegree)).toString()
433 | }
434 | if (!this.draggingInfo.isDragging) {
435 | rotateStyle['transition'] = 'transform 150ms ease-out'
436 | }
437 | return rotateStyle
438 | }
439 | if (gapCount > 0) {
440 | return { transform: 'rotateX(90deg) translate3d(0, 0, 5.625em)' }
441 | } else {
442 | return { transform: 'rotateX(-90deg) translate3d(0, 0, 5.625em)' }
443 | }
444 | }
445 | }
446 |
--------------------------------------------------------------------------------