npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wrc-calendar

v0.0.6

Published

> 移动端弹出日历

Downloads

2

Readme

移动端弹出日历

  • 支持选择1个时间和区间时间
  • 支持起始时间和结束时间
  • 支持渲染日历的月数

在线链接

查看链接

API

属性如下

| 参数 | 说明 | 类型 | 默认值 | | :-----| :----: | :----: | ----: | | isOpen | 是否显示日历 | Boolean | false | | onClose | 点击关闭的回调函数 | Function | function | | onSelect | 日历控件点击确定的回调 | function | function | | onSelect | 日历控件点击确定的回调 | function | function | | isMultipleMode | 是否多选日历,多选可以选择开始和结束时间 | Boolean | false | | disabledStartTime | 静止选择之前的时间 | Date | null | | disabledEndTime | 静止选择之后的时间 | Date | null | | monthCount | 渲染的日历月数 | Number | 1 | | defaultDate | 日历的可点击时间+1 | Date | new Date | | footerRender | 自定义日历的底部按钮区域 | function 返回 react Element | function | | headerRender | 自定义日历的头部区域 | function 返回 react Element,当前函数的参数是每个月的monthArr数组 | function | | contentRender | 自定义日历的内容区域 | function 返回 react Element | | | dateCellRender | 自定义日历的内每一项天的回调函数 | function 返回 react Element,当前函数的参数item, index | function |

单选日历

示例代码

import React, { useState, useEffect } from 'react';
import Calendar from 'Calendar';
import moment from 'moment';
function () => {
  const [isOpen, setIsOpen] = useState(false)
  const [checkStartTime, setCheckStartTime] = useState('')
  const onClose = () => {
    setIsOpen(false)
  }

  const onSelect = (start, end) => {
    setCheckStartTime(start)
    setIsOpen(false)
  }

  return (
    <React.Fragment>
      <button onClick={() => setIsOpen(true)}>单选日历</button>
      {
        checkStartTime && (<div>选择的时间:{checkStartTime.format('YYYY-MM-DD')}</div>)
      }
      <Calendar
        isOpen={isOpen}
        onClose={onClose}
        onSelect={onSelect}
      >
      </Calendar>
    </React.Fragment>
  )
}

多选日历

import React, { useState, useEffect } from 'react';
import Calendar from 'Calendar';
import moment from 'moment';
function () => {
  const [isOpen, setIsOpen] = useState(false)
  const [checkStartTime, setCheckStartTime] = useState('')
  const [checkEndTime, setCheckEndTime] = useState('')
  const onClose = () => {
    setIsOpen(false)
  }
  const onSelect = (start, end) => {
    setCheckStartTime(start)
    setCheckEndTime(end)
    setIsOpen(false)

  }
  return (
    <React.Fragment>
      <button onClick={() => setIsOpen(true)}>多选日历</button>
      {
        checkStartTime && (<div>选择区间的时间:{checkStartTime.format('YYYY-MM-DD')} - {checkEndTime.format('YYYY-MM-DD')}</div>)
      }
      <Calendar
        isOpen={isOpen}
        onClose={onClose}
        onSelect={onSelect}
        isMultipleMode
      >
      </Calendar>
    </React.Fragment>
  )
}

禁用区间日历

import React, { useState, useEffect } from 'react';
import Calendar from 'Calendar';
import moment from 'moment';
function () => {
  const [isOpen, setIsOpen] = useState(false)
  const [checkStartTime, setCheckStartTime] = useState('')
  const [checkEndTime, setCheckEndTime] = useState('')
  const [disabledStartTime, setDisabledStartTime] = useState(moment().add(7, 'days'))
  const [disabledEndTime] = useState(moment().add(11, 'days'))
  const onClose = () => {
    setIsOpen(false)
  }
  const onSelect = (start, end) => {
    setCheckStartTime(start)
    setCheckEndTime(end)
    setIsOpen(false)

  }
  return (
    <React.Fragment>
      <button onClick={() => setIsOpen(true)}>禁用区间日历</button>
      {
        checkStartTime && (<div>选择区间的时间:{checkStartTime.format('YYYY-MM-DD')} - {checkEndTime.format('YYYY-MM-DD')}</div>)
      }
      <Calendar
        isOpen={isOpen}
        onClose={onClose}
        onSelect={onSelect}
        disabledStartTime={disabledStartTime}
        disabledEndTime={disabledEndTime}
        isMultipleMode
      >
      </Calendar>
    </React.Fragment>
  )
}

渲染3个月日历

import React, { useState, useEffect } from 'react';
import Calendar from 'Calendar';
import moment from 'moment';
function () => {
  const [isOpen, setIsOpen] = useState(false)
  const [checkStartTime, setCheckStartTime] = useState('')
  const [checkEndTime, setCheckEndTime] = useState('')
  const [disabledStartTime, setDisabledStartTime] = useState(moment().add(7, 'days'))
  const [disabledEndTime] = useState(moment().add(11, 'days'))
  const [monthCount, setMonthCount] = useState(3)
  const onClose = () => {
    setIsOpen(false)
  }
  const onSelect = (start, end) => {
    setCheckStartTime(start)
    setCheckEndTime(end)
    setIsOpen(false)

  }
  return (
    <React.Fragment>
      <button onClick={() => setIsOpen(true)}>渲染3个月日历</button>
      {
        checkStartTime && (<div>选择区间的时间:{checkStartTime.format('YYYY-MM-DD')} - {checkEndTime.format('YYYY-MM-DD')}</div>)
      }
      <Calendar
        isOpen={isOpen}
        onClose={onClose}
        onSelect={onSelect}
        disabledStartTime={disabledStartTime}
        disabledEndTime={disabledEndTime}
        isMultipleMode
        monthCount={monthCount}
      >
      </Calendar>
    </React.Fragment>
  )
}

默认可选中起始时间往后+1天

import React, { useState, useEffect } from 'react';
import Calendar from 'Calendar';
import moment from 'moment';
function () => {
  const [isOpen, setIsOpen] = useState(false)
  const [checkStartTime, setCheckStartTime] = useState('')
  const [checkEndTime, setCheckEndTime] = useState('')
  const [startDate] = useState(moment().add(-2, 'days'))
  
  const onClose = () => {
    setIsOpen(false)
  }
  const onSelect = (start, end) => {
    setCheckStartTime(start)
    setCheckEndTime(end)
    setIsOpen(false)

  }
  return (
    <React.Fragment>
      <button onClick={() => setIsOpen(true)}>默认选中开始时间</button>
      {
        checkStartTime && (<div>选择区间的时间:{checkStartTime.format('YYYY-MM-DD')} - {checkEndTime.format('YYYY-MM-DD')}</div>)
      }
      <Calendar
        isOpen={isOpen}
        onClose={onClose}
        onSelect={onSelect}
        defaultDate={startDate}
      >
      </Calendar>
    </React.Fragment>
  )
}