0.7.3 • Published 1 year ago

zx-calendar v0.7.3

Weekly downloads
6
License
MIT
Repository
github
Last release
1 year ago

zx-calendar

zx-calendar, ZxReactCalendar, ZxSolidCalendar, zx-vue-calendar (Vue2.x and Vue3.x)

https://capricorncd.github.io/calendar/dist/index.html

zx-calendar

// Import CSS files in the entry file or root component
import 'zx-calendar/css'

import { ZxCalendar } from 'zx-calendar'

Vue docs and example

import { ZxVueCalendar } from 'zx-calendar/vue'
// vue 2.x
import { ZxVueCalendar } from 'zx-calendar/vue2'

ZxVueCalendar Docs | Demo vue2.x | Demo vue3.x

React docs and example

import { ZxReactCalendar } from 'zx-calendar/react'

ZxReactCalendar Docs | Demo

Solid-js

import { ZxSolidCalendar } from 'zx-calendar/solid'

ZxSolidCalendar Docs | Demo

Install

# pnpm
pnpm i zx-calendar

# npm
npm i zx-calendar

# yarn
yarn add zx-calendar

Setup and Dev

# setup
pnpm i

# start default demo
pnpm run dev
# start vue2.x.x demo
pnpm run vue2
# start vue3.x.x demo
pnpm run vue
# start react demo
pnpm run react
# start solid.js demo
pnpm run solid

Usage

// Import CSS files in the entry file or root component
import 'zx-calendar/css'

import { ZxCalendar } from 'zx-calendar'

const options = {}

// create an instance
const zxCalendar = new ZxCalendar(options)

// on change
zxCalendar.on('change', data => {
  console.log(data)
})

// cancel button on click
zxCalendar.on('cancel', () => {
  // ...
})

// on error
zxCalendar.on('error', err => {
  console.error(err)
})

Options

see ZxCalendarOptions

// default options
const options = {
  // element selector or element, calendar will be append this `el`
  el: '#app',
  // calendar's types, options date/month/year
  type: 'date',
  // zh/jp/en that week and button text languages
  lang: 'zh',
  // Whether to display the full name of the week, `Mon` -> `Monday`/ 星期一(省略形式: 一)
  isFullWeek: false,
  // header title display format
  // type is date: yyyy/MM
  // type is month: yyyy
  // type is year: yyyy-yyyy
  titleFormatter: 'yyyy/MM',
  // item suffix, 日/月/年
  itemSuffix: null,
  // default selected date
  // yyyy-MM-dd, yyyy/MM/dd, yyyy, timestamp, Array
  defaultDate: null,
  // selectable date range array
  // [startDate, endDate]
  dateRange: [],
  // show holiday info
  showHoliday: false,
  // function, custom item handler
  // return object {text: string, value: number, fullText: string, disabled: boolean, ...}
  itemFormatter: null,
  // Selection mode, options single/multiple/range
  mode: 'single',
  // language package, used when formatting dates
  langPackage: {
    confirmButton: 'ok',
    cancelButton: 'cancel',
    clearButton: 'clear',
    weeks: ["日", "一", "二", "三", "四", "五", "六"]
  },
  // footer buttons
  // show clear, cancle and confirm button when mode=multiple/range
  footerButtons: ['clear', 'cancel', 'confirm'],
  // only show confirm button
  // footerButtons: ['confirm'],
  // change button display order
  // footerButtons: ['confirm', 'clear', 'cancel'],
  // ...
  // justify-content
  footerButtonAlign: 'flex-end',
  // hide buttons of footer when mode is multiple/range
  hideFooter: false,
  // colors
  colors: {
    primary: '#f30',
    // next/prev arrow color
    arrow: '#999',
    // holiday dot color
    holidayDot: 'rgba(0, 0, 0, 0.2)',
    // today/this month(year) item background color
    currentItemBg: '#eee',
    // white color
    white: '#fff',
    // selected range items background color
    rangeBg: '#eee',
  },
}

Methods

setDate(date)

Set selected date

parametertyperequiredremark
datestring/timestamp/Date or Array[string/timestamp/Date], nullno-
// mode: single
// set select date
zxCalendar.setDate('2020/08/10')
zxCalendar.setDate('2020/08/10 22:14:59')
// clear selected date
zxCalendar.setDate()

// mode: multiple
zxCalendar.setDate(['2020/08/01', '2020/08/05', '2020/08/10'])

// mode: range
zxCalendar.setDate(['2008/01/14', '2019/12/10'])

setCurrentDate(date)

Set current date

parametertyperequiredremark
datestring/timestamp/Dateyes-

setDateRange(startDate, endDate)

Set optional date range

parametertyperequiredremark
startDatestring/timestamp/Dateyes-
endDatestring/timestamp/Dateyes-

prev(isYear)

options.typeisYearremark
dateeffectiveisYear=true, go to prev yearisYear=false, go to prev month
monthinvalidgo to prev year
yearinvalidgo to prev years page

next(isYear)

options.typeisYearremark
dateeffectiveisYear=true, go to next yearisYear=false, go to next month
monthinvalidgo to next year
yearinvalidgo to next years page

toDate(date)

String, timestamp to Date

parametertyperequiredremark
datestring/timestamp/Dateyes-

return Date/null

const date = zxCalendar.toDate('2020/08/10')
if (date !== null) {
    console.log(date.getFullYear())
} 

formatDate(date, formatter, langPackage)

parametertyperequiredremark
datestring/timestamp/Dateyes
formatterstringyesyMdhmsaAwW
langPackageobjectno{weeks: ['日', '月', '火', '水', '木', '金', '土']}

formatter

2020/08/18 22:59:02

formatmeaningexample
yyyyyear2020
Mmonth8
MMmonth08
dday18
ddday18
hhour22
hhhour22
mminute59
mmminute59
ssecond2
sssecond02
aam/pmpm
AAM/PMPM
wweek2
wwweek02
Wweekoptions: {isFullWeek: false, lang: 'zh'}, 二options: {isFullWeek: true, lang: 'zh'}, 星期二ZxCalendar.prototype.formatDate(date, 'W'), 2ZxCalendar.prototype.formatDate(date, 'WW'), 02
zxCalendar.formatDate(new Date(), 'yyyy/MM/dd hh:mm:ss')
// 2020/08/10 23:49:12

on(eventName, fn)

parametertyperequiredremark
eventNamestringyescustom event name
fnfunctionyes-
zxCalendar.on('error', err => {
  console.error(err)
})

zxCalendar.on('change', arr => {
  console.log(arr)
})

zxCalendar.on('onWeekClick', ({el, className, innerText) => {
  console.log(innerText)
})

zxCalendar.on('onTitleClick', ({el, className, innerText) => {
  console.log(innerText)
})
eventNameparameter
changearr

arr

[
  {
    text: String,
    fullText: String,
    value: Number,
    date: Date
  }
]

emit(eventName, parameters)

zxCalendar.emit('customEvent', {})

off(eventName)

zxCalendar.off('customEvent')

getDate()

get selected dates

return Array

destroy()

remove calendar from el(parent)

zxCalendar.destroy()

License

MIT License © 2020-Present Capricorncd.

0.7.2

1 year ago

0.7.1

1 year ago

0.7.3

1 year ago

0.7.0

1 year ago

0.6.2

3 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.6

4 years ago

0.5.4

4 years ago

0.5.5

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.3.0

4 years ago

0.4.0

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago