Code Monkey home page Code Monkey logo

ngx-datepicker's Introduction

Ngxdatepicker

Custom Datepicker for Angular 8+ applications.

npm

Demo.

Getting Started

Install through npm:

npm i @clmeida/ngxdatepicker --save

Include its module in your app.module.ts file:

import { NgxdatepickerModule } from "@clmeida/ngxdatepicker";

@NgModule({
  imports: [NgxdatepickerModule],
})
export class AppModule {}

Add the component in your application:

<dd-ngxdatepicker
  (dateClicked)="myComponentVariable = $event"
  name="date"
  [(ngModel)]="date"
></dd-ngxdatepicker>

It's not required to use both dateClicked and ngModel together, you can use either one of them.

API

Properties

Name Type Description
invalidDates Array[string] Invalid dates as timestamps
validDates Array[string] Valid dates as timestamps
disablePrevDates Boolean Disable previous dates by today

Example

import { ViewChild } from "@angular/core";
import * as moment from "moment";

export class AppComponent implements OnInit {
    invalidDates: string[] = [];

    ngOnInit() {
        const tomorrow = moment().add(1, 'days').format();
        const someDayOfNextMonth = moment().add(1, 'month').format();
        this.invalidDates.push(tomorrow);
        this.invalidDates.push(someDayOfNextMonth);
    }

}
<dd-ngxdatepicker #datepicker 
    name="date" 
    [(ngModel)]="date" 
    [invalidDates]="invalidDates"
    [disablePrevDates]="true">
</dd-ngxdatepicker>

Events

Name Description
(dateClicked) Outputs a string when a day is clicked

Methods

Name Description
goPrev Goes back to earlier month
goNext Goes forward to the next month

Example

import { ViewChild } from "@angular/core";
import * as moment from "moment";

export class AppComponent {
  @ViewChild("datepicker") datepicker: any;
  date: any = moment("25/12/2020", "DD/MM/YYYY").format();
}
<dd-ngxdatepicker #datepicker name="date" [(ngModel)]="date"></dd-ngxdatepicker>

<button type="button" (click)="datepicker?.goPrev()">
  My custom prev Button
</button>

<button type="button" (click)="datepicker?.goNext()">
  My custom next Button
</button>

Slots

Name Description
prev Replace default prev button with a custom one
next Replace default next button with a custom one
month Replace default month title with a custom one

Example

<dd-ngxdatepicker #datepicker name="date" [(ngModel)]="date">
  <button type="button" (click)="datepicker?.goPrev()" prev>Custom Prev</button>
  <button type="button" (click)="datepicker?.goNext()" next>Custom Next</button>
  <strong month>{{ datepicker.current | date: "MM yyyy" }}</strong>
</dd-ngxdatepicker>

Style

Every time you select a day a class named selected is bound to that element.

I18n

Since this module works with moment.js you can set up its locale globally in your application:

app.module.ts

// ... imports
import * as moment from "moment";

moment.locale("pt-BR");

License

MIT

ngx-datepicker's People

Contributors

nncl avatar dependabot[bot] avatar

Stargazers

Roman avatar Mário Mello avatar Marcos T Munhoz avatar Peterson Fonseca Simião avatar Kevin Oliveira avatar Paulo Vinicius avatar

Watchers

James Cloos avatar  avatar Paulo Vinicius avatar

ngx-datepicker's Issues

Publish on NPM

Before that, add some:

  • documentation
  • versioning
  • beautify package.json information

Can't resolve 'moment'

./node_modules/@clmeida/ngxdatepicker/fesm2015/clmeida-ngxdatepicker.js
Module not found: Error: Can't resolve 'moment' in '/Users/cauealmeida/Jobs/ngx-datepicker-test/node_modules/@clmeida/ngxdatepicker/fesm2015'

Possibilidade de adicionar sufixos no mês

Seria interessante ter a possibilidade de adicionar um sufixo apos o mês selecionado, ao invez de mostrar apenas setembro poderia mostrar setembro ${sufix}. Sim lib teria uma versatilidade maior, dessa forma seria possível mostrar o mês de N formas diferentes exemplo: Setembro de 2020.

Mas claro é apenas uma sugestão.

Novo evento(click) para datas inválidas

Sua sugestão está relacionada com um problema? Por favor descreva.

  • Hoje quando usamos data inválida o calendário não dispara o evento.

Descreva a sugestão de solução

  • Deixar clicar em um uma data inválida e disparar um evento diferente, assim deixa uma liberdade pra quem está usando tomar decisões diferentes de acordo com o tipo de data que foi clicada (inválida e válida).

Diferenciar data inválida de datas desabilitadas

Sua sugestão está relacionada com um problema? Por favor descreva.

  • Quando utiliza data inválida junto com data válida (2 arrays um para cada tipo de data), o calendário não diferencia o que é data inválida das desabilitadas.

Descreva a sugestão de solução
Adicionar uma classe ex: .invalid para diferenciar as datas inválidas.

Update to angular 11

Não esta sendo possível instalar a lib, acredito que seja devido a versão que eu utilizo no projeto não ser a mesma que a usada pela lib. Segue print do erro.

Screen Shot 2021-06-29 at 15 51 33

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.