カレンダー:スタイル

CSSを使用してCalendar全体の外観をカスタマイズしたり、CalendarのformatItemイベントを使用して特定の日付の外観をカスタマイズすることができます。このサンプルのCalendarでは、カスタムスタイルを使用して週末や休日を表示しています。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; import { getHolidays } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { let holidays = getHolidays(); // // the calendar let theCalendar = new input.Calendar('#theCalendar', { valueChanged: () => showCurrentDate(), formatItem: (sender, e) => { // apply styles to weekends and holidays let weekday = e.data.getDay(), holiday = getHoliday(e.data); // wijmo.toggleClass(e.item, 'date-sunday', weekday == 0); wijmo.toggleClass(e.item, 'date-saturday', weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday; } }); theCalendar.invalidate(); // // show the currently selected date function showCurrentDate() { let el = document.querySelector('#theCalendarOutput'); el.textContent = wijmo.Globalize.format(theCalendar.value, 'D'); } showCurrentDate(); // // gets the holiday for a given date function getHoliday(date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = holidays[month + '/' + day]; // if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; holiday = holidays[month + '/' + weekNum + '/' + weekDay]; } // return holiday; } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Calendar Customization</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <input id="theCalendar"> <div> 現在の日付: <b><span id="theCalendarOutput"></span></b> </div> </div> </body> </html> export function getHolidays() { return { '1/1': '元旦', '1/2/1': '成人の日', '2/11': '建国記念の日', '2/23': '天皇誕生日', '3/20': '春分の日', '4/29': '昭和の日', '5/3': '憲法記念日', '5/4': 'みどりの日', '5/5': 'こどもの日', '7/3/1': '海の日', '8/11': '山の日', '9/23': '秋分の日', '9/3/1': '敬老の日', '10/2/1': '体育の日', '11/3': '文化の日', '11/23': '勤労感謝の日' }; } .wj-calendar { max-width: 21em; } .wj-calendar .wj-header { color: white; background: #808080; } .wj-calendar .date-holiday, .wj-calendar .date-sunday { color: red; } .wj-calendar .date-saturday { color: blue; } body { margin-bottom: 36px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; // import { Component, enableProdMode, NgModule, ViewChild, OnInit, Inject } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent implements OnInit { private _holidays: { [key: string]: string }; @ViewChild('theCalendar') theCalendar: input.Calendar; // constructor(@Inject(DataService) private dataService: DataService) { this._holidays = dataService.getHolidays(); } // ngOnInit() { this.theCalendar.invalidate(); } // formatItem(e: input.FormatItemEventArgs) { // apply styles to weekends and holidays let weekday = e.data.getDay(), holiday = this._getHoliday(e.data); // wijmo.toggleClass(e.item, 'date-sunday', weekday == 0); wijmo.toggleClass(e.item, 'date-saturday', weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday; } // // gets the holiday for a given date private _getHoliday(date: Date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = this._holidays[month + '/' + day]; // if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; holiday = this._holidays[month + '/' + weekNum + '/' + weekDay]; } // return holiday; } } // @NgModule({ imports: [WjInputModule, BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Calendar Customization</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-calendar #theCalendar (formatItem)="formatItem($event)"> </wj-calendar> <div> 現在の日付: <b>{{ theCalendar.value | date:'fullDate'}}</b> </div> </div> import { Injectable } from '@angular/core'; // @Injectable() export class DataService { getHolidays() { return { '1/1': '元旦', '1/2/1': '成人の日', '2/11': '建国記念の日', '2/23': '天皇誕生日', '3/20': '春分の日', '4/29': '昭和の日', '5/3': '憲法記念日', '5/4': 'みどりの日', '5/5': 'こどもの日', '7/3/1': '海の日', '8/11': '山の日', '9/23': '秋分の日', '9/3/1': '敬老の日', '10/2/1': '体育の日', '11/3': '文化の日', '11/23': '勤労感謝の日' }; } } .wj-calendar { max-width: 21em; } .wj-calendar .wj-header { color: white; background: #808080; } .wj-calendar .date-holiday, .wj-calendar .date-sunday { color: red; } .wj-calendar .date-saturday { color: blue; } body { margin-bottom: 36px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wijmo from '@grapecity/wijmo'; import * as wjInput from '@grapecity/wijmo.react.input'; import { getHolidays } from './data'; class App extends React.Component { constructor(props) { super(props); this._holidays = getHolidays(); this.state = { value: null }; } render() { return <div className="container-fluid"> <wjInput.Calendar initialized={this._initCalendar.bind(this)} formatItem={this._formatItem.bind(this)} valueChanged={this._onValueChanged.bind(this)}> </wjInput.Calendar> <div> 現在の日付: <b>{this._formatDate(this.state.value)}</b> </div> </div>; } _initCalendar(sender) { this.setState({ value: sender.value }); sender.invalidate(); } _formatItem(sender, e) { // apply styles to weekends and holidays let weekday = e.data.getDay(), holiday = this._getHoliday(e.data); wijmo.toggleClass(e.item, 'date-sunday', weekday == 0); wijmo.toggleClass(e.item, 'date-saturday', weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday; } _getHoliday(date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = this._holidays[month + '/' + day]; if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; holiday = this._holidays[month + '/' + weekNum + '/' + weekDay]; } return holiday; } _formatDate(time) { return wijmo.Globalize.format(time, 'D'); } _onValueChanged(sender) { this.setState({ value: sender.value }); } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-calendar { max-width: 21em; } .wj-calendar .wj-header { color: white; background: #808080; } .wj-calendar .date-holiday, .wj-calendar .date-sunday { color: red; } .wj-calendar .date-saturday { color: blue; } body { margin-bottom: 36px; } export function getHolidays() { return { '1/1': '元旦', '1/2/1': '成人の日', '2/11': '建国記念の日', '2/23': '天皇誕生日', '3/20': '春分の日', '4/29': '昭和の日', '5/3': '憲法記念日', '5/4': 'みどりの日', '5/5': 'こどもの日', '7/3/1': '海の日', '8/11': '山の日', '9/23': '秋分の日', '9/3/1': '敬老の日', '10/2/1': '体育の日', '11/3': '文化の日', '11/23': '勤労感謝の日' }; } <template> <div class="container-fluid"> <wj-calendar :initialized="initCalendar" :formatItem="formatItem"> </wj-calendar> <div> 現在の日付: <b>{{ theCalendar.value | formatDate}}</b> </div> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.input'; import { getHolidays } from './data' let App = Vue.extend({ name: 'app', data: function () { return { theCalendar: {}, holidays: getHolidays() } }, methods: { initCalendar: function(calendar){ this.theCalendar = calendar; }, formatItem: function(s,e) { // apply styles to weekends and holidays let weekday = e.data.getDay(), holiday = this._getHoliday(e.data); wijmo.toggleClass(e.item, 'date-sunday', weekday == 0); wijmo.toggleClass(e.item, 'date-saturday', weekday == 6); wijmo.toggleClass(e.item, 'date-holiday', holiday != null); e.item.title = holiday; }, _getHoliday: function(date) { let day = date.getDate(), month = date.getMonth() + 1, holiday = this.holidays[month + '/' + day]; if (!holiday) { let weekDay = date.getDay(), weekNum = Math.floor((day - 1) / 7) + 1; holiday = this.holidays[month + '/' + weekNum + '/' + weekDay]; } return holiday; } }, mounted: function(){ this.theCalendar.invalidate(); }, filters: { formatDate: function(time){ return wijmo.Globalize.format(time, 'D'); } } }) let vm = new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .container-fluid .wj-calendar { max-width: 21em; } .container-fluid .wj-calendar .wj-header { color: white; background: #808080; } .container-fluid .wj-calendar .date-holiday, .container-fluid .wj-calendar .date-sunday { color: red; } .container-fluid .wj-calendar .date-saturday { color: blue; } body { margin-bottom: 36px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Calendar Customization</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> export function getHolidays() { return { '1/1': '元旦', '1/2/1': '成人の日', '2/11': '建国記念の日', '2/23': '天皇誕生日', '3/20': '春分の日', '4/29': '昭和の日', '5/3': '憲法記念日', '5/4': 'みどりの日', '5/5': 'こどもの日', '7/3/1': '海の日', '8/11': '山の日', '9/23': '秋分の日', '9/3/1': '敬老の日', '10/2/1': '体育の日', '11/3': '文化の日', '11/23': '勤労感謝の日' }; }