# ng-simple-calendar

> This is a very barebones calendar service created for Angular version 15.

Latest version **0.0.12** (published 2023-01-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng-simple-calendar
pnpm add ng-simple-calendar
yarn add ng-simple-calendar
bun add ng-simple-calendar
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12 |
| Published | 2023-01-16 |
| First published | 2023-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 79.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Akey Skywalker |
| Maintainers | akey-skywalker |
| Keywords | angular, calendar, service, simple, basic |

## Links

- npm: https://www.npmjs.com/package/ng-simple-calendar
- npm.io page: https://npm.io/package/ng-simple-calendar

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Recent versions

- 0.0.12 (latest) — 2023-01-16
- 0.0.11 — 2023-01-16
- 0.0.10 — 2023-01-16
- 0.0.9 — 2023-01-16
- 0.0.8 — 2023-01-16
- 0.0.7 — 2023-01-16
- 0.0.6 — 2023-01-16
- 0.0.5 — 2023-01-16
- 0.0.0-watch — 2023-01-16
- 0.0.4 — 2023-01-16
- 0.0.31 — 2023-01-15
- 0.0.3 — 2023-01-15
- 0.0.2 — 2023-01-15
- 0.0.1 — 2023-01-15

## README

# ng-simple-calendar

This is a very barebones calendar service created for Angular version 15.

## Installation

```
npm i ng-simple-calendar
```

## Usage

set NgSimpleCalendarService onto your component.

```
import { Component } from '@angular/core';
import { NgSimpleCalendarService } from 'ng-simple-calendar';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'calendar';
  header: any = ['日', '月', '火', '水', '木', '金', '土'];
  calendar: any = [];
  date: any = [];
  today: any = [];
  pickedMonth: any = [];

  constructor(private calendarService: NgSimpleCalendarService) { }

  ngOnInit() {
    this.today = new Date();
    this.date = new Date(this.today.getTime());
    this.pickedMonth = this.date;
    const data = [
      {
        'day': 3,
        'huge': 5,
        'hoge': 'hogehoge'
      },
      {
        'day': 10,
        'huge': 2,
        'hoge': 'hogehoge'
      }
    ];

    this.calendar = this.calendarService.create(this.date, this.today, data);
  }

  setMonth = (num: number) => {
    //NOTE: get some data for this set month from DB or other storages.
    const data = [
      {
        'day': 5,
        'huge': 10,
        'hoge': 'hogehogehoge'
      },
      {
        'day': 10,
        'huge': 2,
        'hoge': 'hogehoge'
      }
    ];

    this.date.setMonth(this.date.getMonth() + num);
    this.calendar = this.calendarService.create(this.date, this.today, data);
    this.pickedMonth = new Date(this.date.getTime());
  };

  pickDate = (day: number, data: any) => {
    if (data.has) {
      alert(
        `You picked the day of ${this.date.getFullYear()}/${this.date.getMonth() + 1
        }/${day}, and it has huge: ${data.huge} and hoge: ${data.hoge}.`
      );
    } else {
      alert(
        `You picked the day of ${this.date.getFullYear()}/${this.date.getMonth() + 1
        }/${day}, and it has no data.`
      );
    }
  };
}

```

this.calendarService.create() in your component gives calendar data.

```
week :
[
    {dd: 1, today: false,
        data:{
            [you can set data array...]
        }
    },
    {dd: 2, today: false,
        data:{
            [you can set data array...]
        }
    },
    .... day data of first week ...
],
[
    {dd: 8, today: false,
        data:{
            [you can set data array...]
        }
    },
    .... day data of second week ...
],
....
```

Then, your component.html get the above calendar data.
<br>
The point of this ng-simple-calendar is just gives array data, so it is easy to customize HTML as you want.
<br>
Example HTML:

```
<div>
  <button (click)="setMonth(-1)">Prev</button>
  <button (click)="setMonth(1)">Next</button>
  <div>{{ pickedMonth | date : "yyyy年M月" }}</div>
  <table>
    <tr>
      <th *ngFor="let head of header">{{ head }}</th>
    </tr>
    <tr class="week" *ngFor="let week of calendar">
      <td
        *ngFor="let day of week"
        (click)="pickDate(day.dd, day.data)"
        [class.today]="day.today"
        [class.data]="day.data.has"
      >
        {{ day.dd }}
      </td>
    </tr>
  </table>
</div>
```

## Github

[ng-simple-calendar](https://github.com/AkeySkywalker/angular/tree/main/projects/ng-simple-calendar)

## License

MIT License

Copyright (c) 2023 Akey Skywalker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---
_Source: https://npm.io/package/ng-simple-calendar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
