React移动端h5日历组件能用的插件不多,不想自己手写,只能使用插件了。react-h5-calendar还不错,长的不丑,切换也流畅。

文档:

github简易介绍:https://github.com/kokiy/react-h5-calendar

另外补充:react-hash-calendar插件文档
github详细地址:https://github.com/TangSY/react-hash-calendar

DEMO:(实际不抖)

查看:


浏览器打开:https://kokiy.github.io/react-h5-calendar/calendar

参数配置:

  • 支持周视图,周日历(参数disableWeekView禁用周视图)
  • 支持月视图,月日历
  • 支持左右滑动切换月份
  • 支持上下滑动切换日历视图(参数disableWeekView禁用周视图)
  • 支持日历上打点标记(当前、标记2种)
  • 基于dayjs处理日历逻辑

参数设置

参数 说明 默认值 备注
currentDate 当前选择的日期 今天 格式:2022-02-02
showType 展示类型(参数:month 和 week) month disableWeekView={true}
禁用:周视图、上下滑动收缩
transitionDuration 切换日期的动画过渡时间(单位:秒) 0.3
markType 标记类型(参数:dot和circle) dot 可根据标记点样式追加伪元素自定义样式
markDates 需要标记的日期数组 []
disableWeekView 禁用周视图 false disableWeekView={true}
禁用:周视图、上下滑动收缩
onDateClick 日期点击回调 (e)=>{} 日期对象信息
onTouchStart 滑动开始回调 (e)=>{}
onTouchMove 滑动过程中回调 (e)=>{}
onTouchEnd 滑动结束回调 (e)=>{}

markDates 参数说明

const markDates = [{ color: '#459', date: '2021-12-12', markType: 'circle' },{ color: '#a8f', markType: 'dot', date: '2021-12-23' },{ color: '#a5f', markType: 'circle', date: '2021-12-22' },{ date: '2022-1-22' },
]
  • 单个日期不传markType 默认取传入的Marktype
  • 单个日期不传color 默认是#f00

disableWeekView 参数说明

设为true时。禁用:周视图、上下滑动收缩。可以锁定月视图日历

实战案例:


可以自定义,有点考验css基本功。

核心代码附带:

js部分:

// 监听当前月份const [calendarOperate, setCalendarOperate] = useState('');// 日历滑动function onCalendarDateTouchEnd() {setTimeout(() => {const getHTML = document.getElementsByClassName("calendar-operate")[0]?.childNodes[1]?.innerHTML;setCalendarOperate(getHTML)})}{/* 日历 */}<div className="calendar"><CalendardisableWeekView={true}markDates={planList}onDateClick={onCalendarDateClick}onTouchEnd={onCalendarDateTouchEnd} //用于拼接全日期 - 跳转页面带参用/></div>

calendar.less部分: 可以直接复制拿去用,专门抽离用于日历样式重置。
我的项目用了postcss插件,自动px转vw。可以根据设计稿1:1写死单位。

.react-h5-calendar {padding-bottom: 30px;.calendar-operate {width: 686px;height: 108px;background: #fff;padding: 0 42px;div {font-size: 32px;font-weight: bold;color: #333333;line-height: 44px;}.icon {justify-content: end;img {height: 24px;}}}.calendar-head {font-size: 32px;color: #333333;line-height: 44px;.head-cell {padding: 36px 34px;margin-bottom: 20px;}}.week-mode {height: 120px !important;}.calendar-body {height: 660px;.month-cell {.day-cell {width: 98px;height: 88px;font-size: 32px;font-weight: bold;color: #333333;line-height: 44px;position: relative;z-index: 20;margin-bottom: 20px;.day-text {width: 100%;height: 100%;align-items: start;padding-top: 8px;}.current-day {width: 56px;height: 56px;background: #008AFF;padding-top: 0;align-items: center;margin-top: -30px;}.circle-mark {width: 98px;height: 100%;background: rgba(26, 182, 107, 0.1);border-radius: 8px;border: none;position: relative;}.circle-mark::before,.dot-mark::before {content: '';position: absolute;top: 8px;left: 20px;width: 12px;height: 12px;background: #1AB66B;border-radius: 100%;}.dot-mark {position: absolute;top: 0;left: 0;width: 100%;height: 100%;border-radius: 8px;background: rgba(255, 143, 33, 0.1) !important;z-index: -1;}.dot-mark::before {background: #FF8F21;}.dot-mark::after,.circle-mark::after {content: '复诊';width: 100%;height: 34px;font-size: 24px;font-weight: 400;color: #333333;line-height: 34px;position: absolute;bottom: 8px;left: 0;text-align: center;}}}}.bottom-operate {display: none;img {height: 5vw;}}.dateActive {.day-text {width: 56px !important;height: 56px !important;background: linear-gradient(180deg, #FF334B 0%, #FF9B9B 100%) !important;padding-top: 0 !important;align-items: center !important;margin-top: -30px !important;border-radius: 50% !important;color: #fff;}.circle-mark::before, .circle-mark::after, .dot-mark::before, .dot-mark::after{display: none !important;}.dot-mark{display: none !important;}}
}

其他:

有兴趣可以看看其他相关博客

react使用 postcss-px-to-viewport 适配移动端px或者pc端自动转vw:https://blog.csdn.net/weixin_44461275/article/details/122490874

React移动端h5日历组件react-h5-calendar周日历 月日历 周视图 月视图自定义标记点相关推荐

  1. vue 滚动条_轻量级 React.js 虚拟美化滚动条组件RScroll

    前几天有给大家分享一个Vue自定义滚动条组件VScroll.今天再分享一个最新开发的React PC端模拟滚动条组件RScroll. vue+pc桌面端模拟滚动条组件VScroll rscroll 一 ...

  2. js 隐藏滚动条_轻量级 React.js 虚拟美化滚动条组件RScroll

    前几天有给大家分享一个Vue自定义滚动条组件VScroll.今天再分享一个最新开发的React PC端模拟滚动条组件RScroll. vue+pc桌面端模拟滚动条组件VScroll rscroll 一 ...

  3. 美少女秃头思考:react服务端渲染

    富婆来报道,今天想问题想不出来,随手抓了一下头发,没想到啊没想到,我那浓(mei)密(sheng)茂(ji)盛(gen)的秀发又少了好几根,一定要改掉这个想不出来问题就揪头发的坏习惯.你们遇到问题想不 ...

  4. React教程(二):React组件基础

    传送门: React教程(一):React基础 一.组件概念 react官方解释: React 允许你将标记.CSS 和 JavaScript 组合成自定义"组件",即应用程序中可 ...

  5. React 中的高阶组件及其应用场景

    本文目录 什么是高阶组件 React 中的高阶组件 属性代理(Props Proxy) 反向继承(Inheritance Inversion) 高阶组件存在的问题 高阶组件的约定 高阶组件的应用场景 ...

  6. android 携程日历控件,仿携程酒店日历组件for小程序

    仿携程酒店日历 接受日历组件开发之前,本来是拒绝的,日历组件,表单组件绝逼是前端开发的一个噩梦,尤其要做好一个旅游项目的日历,产品的收货标准只有一条,你看携程都实现了哦, MMP的.要在小程序中实现携 ...

  7. primefaces教程_Primefaces日历组件示例教程

    primefaces教程 In our previous tutorials, we've covered several types of Primefaces components such as ...

  8. 微信小程序日历组件封装和日历算法

    github地址 github代码地址 参考博文 https://www.cnblogs.com/webwei2017/articles/7723703.html 思路 首先取得处理月的总天数 接着定 ...

  9. vue封装一个日历组件

    图示 封装的组件的代码如下 <template><div class="calendar"><!-- 选择日历的弹出层 --><div c ...

  10. 纵享丝滑滑动切换的周月日历,水滴效果,丰富自定义日历样式,仿小米日历(ViewDragHelper实现)...

    本文已授权微信公众号:鸿洋(hongyangAndroid)在微信公众号平台原创首发 老规矩先贴效果图 github地址,觉得有帮助的可以给个 star 呗 github.com/idic779/mo ...

最新文章

  1. WinRM设置信任主机
  2. JavaScript中的endsWith
  3. KickStart 无人值守安装系统
  4. 代码的坏味道之一——译自《重构》
  5. c# linq的差集,并集,交集,去重【转】
  6. 小红书笔记_小红书的沙雕笔记,害人不浅啊
  7. 产品规格说明书怎么写_产品说明都不会写?亚马逊旺季请靠边站!
  8. Hadoop安装教程(Hadoop3.3.1版本),centos7系统,避免踩坑
  9. 华三OSPF多区域配置实例
  10. BCM94360CD+linux+驱动,BCM94360CD WINDOWS驱动(32+X64位)
  11. Facebook安卓Feed流的内存优化实践
  12. 北斗通讯协议4.0 java_北斗一串口协议4.0.pdf
  13. python计算器gui设计_Python 计算器界面设计
  14. html5 语音导航,TeleNav提供基于HTML5技术的浏览器级turn-by-turn语音导航服务
  15. Latex常用总结(2):输入矩阵(输入矩阵、对角阵、方程组等)
  16. 好看的简约导航HTML网站源码
  17. 您的企业已经准备好使用专线了吗?——Vecloud
  18. python 判断天干地支年份
  19. Android 高仿 QQ5.0 侧滑菜单效果 自定义控件来袭
  20. JAVA程序员BUG集锦

热门文章

  1. Discuz注册页面的邮箱验证代码分析
  2. TimesTen In-Memory Database
  3. 解决ISCROLL单击变双击的BUG
  4. RedHat 网络配置
  5. Django报错异常django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without
  6. 在页面超链接a前加上图标
  7. Percona XtraBackup User Manual
  8. 小新pro13 (2020款,Nvidia MX350)+win10+cuda10.2+cudnn7.6+pytorch搭建深度学习环境
  9. ubuntu 安装360浏览器
  10. XMPP即时通讯协议使用(十)——好友关系状态