1.0.1 • Published 4 years ago

ion5-schedule v1.0.1

Weekly downloads
7
License
-
Repository
github
Last release
4 years ago

📅 ion5-schedule

  • Soporte de rango de fechas.
  • Soporte de múltiples fechas.
  • Soporte de componentes HTML.
  • Desactivar días laborables o fines de semana.
  • Evento de días de configuración.
  • Configuración de localización.

Soporte

  • @ionic/angular ^5.0.0

Uso

Instalación

$ npm install ion5-schedule moment --save

Importación de Módulos

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from '@ionic/angular';
import { MyApp } from './app.component';
...
import { CalendarModule } from 'ion5-schedule';

@NgModule({
  declarations: [
    MyApp,
    ...
  ],
  imports: [
    IonicModule.forRoot(),
    CalendarModule
  ],
  bootstrap: [MyApp],
  ...
})
export class AppModule {}

Cambiar valores predeterminados

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
...
import { CalendarModule } from "ion5-schedule";

@NgModule({
  declarations: [
    MyApp,
    ...
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    // Consulte CalendarComponentOptions para conocer las opciones.
    CalendarModule.forRoot({
      doneLabel: 'Save',
      closeIcon: true
    })
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    ...
  ]
})
export class AppModule {}

Modo de componentes

Básico

<ion-calendar [(ngModel)]="date"
              (change)="onChange($event)"
              [type]="type"
              [format]="'YYYY-MM-DD'">
</ion-calendar>
import { Component } from '@angular/core';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  date: string;
  type: 'string'; // 'string' | 'js-date' | 'moment' | 'time' | 'object'
  constructor() { }

  onChange($event) {
    console.log($event);
  }
  ...
}

Rango de fechas

<ion-calendar [(ngModel)]="dateRange"
              [options]="optionsRange"
              [type]="type"
              [format]="'YYYY-MM-DD'">
</ion-calendar>
import { Component } from '@angular/core';
import { CalendarComponentOptions } from 'ion5-schedule';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  dateRange: { from: string; to: string; };
  type: 'string'; // 'string' | 'js-date' | 'moment' | 'time' | 'object'
  optionsRange: CalendarComponentOptions = {
    pickMode: 'range'
  };

  constructor() { }
  ...
}

Fecha múltiple

<ion-calendar [(ngModel)]="dateMulti"
              [options]="optionsMulti"
              [type]="type"
              [format]="'YYYY-MM-DD'">
</ion-calendar>
import { Component } from '@angular/core';
import { CalendarComponentOptions } from 'ion2-calendar';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  dateMulti: string[];
  type: 'string'; // 'string' | 'js-date' | 'moment' | 'time' | 'object'
  optionsMulti: CalendarComponentOptions = {
    pickMode: 'multi'
  };

  constructor() { }
  ...
}

Propiedades de entrada

NombreTipoDefectoDescripción
optionsCalendarComponentOptionsnulloptions
formatstring'YYYY-MM-DD'value format
typestring'string'value type
readonlybooleanfalsereadonly

Propiedades de salida

NombreTipoDescripción
changeEventEmitterevento para cambio de modelo
monthChangeEventEmitterevento por cambio de mes
selectEventEmitterevento para hacer clic en el botón del día
selectStartEventEmitterevento para hacer clic en el botón del día
selectEndEventEmitterevento para hacer clic en el botón del día

CalendarComponentOptions

NombreTipoDefaultDescripción
fromDatenew Date()start date
toDate0 (Infinite)end date
colorstring'primary''primary', 'secondary', 'danger', 'light', 'dark'
pickModestringsingle'multi', 'range', 'single'
showToggleButtonsbooleantrueshow toggle buttons
showMonthPickerbooleantrueshow month picker
monthPickerFormatArray['ENE', 'FEB', 'MAR', 'ABR', 'MAY', 'JUN', 'JUL', 'AGO', 'SEP', 'OCT', 'NOV', 'DIC']month picker format
defaultTitlestring''default title in days
defaultSubtitlestring''default subtitle in days
disableWeeksArray[]week to be disabled (0-6)
monthFormatstring'MMM YYYY'month title format
weekdaysArray['SA', 'LU', 'MA', 'MI', 'JU', 'VI', 'DO']weeks text
weekStartnumber0 (0 or 1)set week start day
daysConfigArray<DaysConfig>[]days configuration

Modo modal

Básico

Importe ion5-schedule en el controlador del componente.

import { Component } from '@angular/core';
import { ModalController } from '@ionic/angular';
import {
  CalendarModal,
  CalendarModalOptions,
  DayConfig,
  CalendarResult
} from 'ion5-schedule';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  constructor(public modalCtrl: ModalController) {}

  openCalendar() {
    const options: CalendarModalOptions = {
      title: 'BASIC'
    };

    const myCalendar = await this.modalCtrl.create({
      component: CalendarModal,
      componentProps: { options }
    });

    myCalendar.present();

    const event: any = await myCalendar.onDidDismiss();
    const date: CalendarResult = event.data;
    console.log(date);
  }
}

Date range

Establezca pickMode en 'range'.

openCalendar() {
  const options: CalendarModalOptions = {
    pickMode: 'range',
    title: 'RANGE'
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date = event.data;
  const from: CalendarResult = date.from;
  const to: CalendarResult = date.to;

  console.log(date, from, to);
}

Multi Date

Set pickMode to 'multi'.

openCalendar() {
  const options = {
    pickMode: 'multi',
    title: 'MULTI'
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

Desactivar semanas

Utilice el índice, por ejemplo: [0, 6] denota domingo y sábado.

openCalendar() {
  const options: CalendarModalOptions = {
    disableWeeks: [0, 6]
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

Localización

your root module

import { NgModule, LOCALE_ID } from '@angular/core';
...

@NgModule({
  ...
  providers: [{ provide: LOCALE_ID, useValue: "zh-CN" }]
})

...
openCalendar() {
  const options: CalendarModalOptions = {
    monthFormat: 'YYYY 年 MM 月 ',
    weekdays: ['天', '一', '二', '三', '四', '五', '六'],
    weekStart: 1,
    defaultDate: new Date()
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

Configuración de días

Configurar un día.

openCalendar() {
  let _daysConfig: DayConfig[] = [];
  for (let i = 0; i < 31; i++) {
    _daysConfig.push({
      date: new Date(2017, 0, i + 1),
      subTitle: `$${i + 1}`
    })
  }

  const options: CalendarModalOptions = {
    from: new Date(2017, 0, 1),
    to: new Date(2017, 11.1),
    daysConfig: _daysConfig
  };

  const myCalendar = await this.modalCtrl.create({
    component: CalendarModal,
    componentProps: { options }
  });

  myCalendar.present();

  const event: any = await myCalendar.onDidDismiss();
  const date: CalendarResult = event.data;
  console.log(date);
}

API

Opciones del modo modal

NombreTipoDefectoDescription
fromDatenew Date()start date
toDate0 (Infinite)end date
titlestring'CALENDAR'title
colorstring'primary''primary', 'secondary', 'danger', 'light', 'dark'
defaultScrollToDatenonelet the view scroll to the default date
defaultDateDatenonedefault date data, apply to single
defaultDatesArraynonedefault dates data, apply to multi
defaultDateRange{ from: Date, to: Date }nonedefault date-range data, apply to range
defaultTitlestring''default title in days
defaultSubtitlestring''default subtitle in days
cssClassstring''Additional classes for custom styles, separated by spaces.
canBackwardsSelectedbooleanfalsecan backwards selected
pickModestringsingle'multi', 'range', 'single'
disableWeeksArray[]week to be disabled (0-6)
closeLabelstringCANCELcancel button label
doneLabelstringDONEdone button label
clearLabelstringnullclear button label
closeIconbooleanfalseshow cancel button icon
doneIconbooleanfalseshow done button icon
monthFormatstring'MMM YYYY'month title format
weekdaysArray['S', 'M', 'T', 'W', 'T', 'F', 'S']weeks text
weekStartnumber0 (0 or 1)set week start day
daysConfigArray<DaysConfig>[]days configuration
stepnumber12month load stepping interval to when scroll
defaultEndDateToStartDatebooleanfalsemakes the end date optional, will default it to the start

onDidDismiss Output { data } = event

pickModeTipo
single{ date: CalendarResult }
range{ from: CalendarResult, to: CalendarResult }
multiArray<CalendarResult>

onDidDismiss Output { role } = event

ValueDescription
'cancel'dismissed by click the cancel button
'done'dismissed by click the done button
'backdrop'dismissed by click the backdrop

DaysConfig

NombreTipoDefectoDescripción
cssClassstring''separados por espacios
dateDaterequireddías configurados
markedbooleanfalseresaltar el color
disablebooleanfalseinhabilitar
titlestringnonetítulo mostrado, por ejemplo: 'today'
subTitlestringnonesubtítulo mostrado, por ejemplo: 'New Year\'s'

CalendarResult

NombreTipo
timenumber
unixnumber
dateObjDate
stringstring
yearsnumber
monthsnumber
datenumber

Gracias por leer