Installations
npm install react-flatpickr
Releases
Unable to fetch releases
Developer
coderhaoxin
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
18.3.0
NPM Version
8.5.5
Statistics
603 Stars
142 Commits
103 Forks
5 Watching
6 Branches
33 Contributors
Updated on 19 Nov 2024
Bundle Size
57.17 kB
Minified
16.60 kB
Minified + Gzipped
Languages
JavaScript (97.82%)
HTML (2.18%)
Total Downloads
Cumulative downloads
Total Downloads
22,416,669
Last day
5.8%
25,432
Compared to previous day
Last week
9.6%
140,536
Compared to previous week
Last month
6.2%
578,525
Compared to previous month
Last year
34.9%
6,705,542
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
1
Dev Dependencies
35
react-flatpickr
Flatpickr for React.
Table of contents
Installation
This package can be install with yarn
or npm
npm
1npm install --save react-flatpickr
yarn
1yarn add react-flatpickr
Usage
1// Keep in mind that these are the styles from flatpickr package 2// See troubleshooting section in case you have problems importing the styles 3 4import "flatpickr/dist/themes/material_green.css"; 5 6import Flatpickr from "react-flatpickr"; 7import { Component } from "react"; 8 9class App extends Component { 10 constructor() { 11 super(); 12 13 this.state = { 14 date: new Date() 15 }; 16 } 17 18 render() { 19 const { date } = this.state; 20 return ( 21 <Flatpickr 22 data-enable-time 23 value={date} 24 onChange={([date]) => { 25 this.setState({ date }); 26 }} 27 /> 28 ); 29 } 30}
Basic props
defaultValue
string
| optional
This is the default value that will be passed to the inner input
value
string || array || object || number
| optional
Same as below
options
Object
| optional
Flatpickr options
: you can pass allFlatpickr parameters
here.- All
Flatpickr
hooks can be passed within this option too.
Example:
1<Flatpickr options={{ minDate: "2017-01-01" }} />
children
node
| optional
This option is closely related with the wrap option from Flatpickr
, please refer to the former link for more information.
className
string
| optional
Custom className that will be applied to the inner input
element. In case you need to modify the rendered input
styles this is the prop
you should use.
Event handlers
The following props
are provided in order to customize the Flatpickr's functions
default behaviour. Please refer to the Events & Hooks section from Flatpickr
library.
onChange
function
| optional
onOpen: function
function
| optional
onClose: function
function
| optional
onMonthChange: function
function
| optional
onYearChange: function
function
| optional
onReady: function
function
| optional
onValueUpdate: function
function
| optional
onDayCreate: function
function
| optional
onDestroy: function
function
| optional
Advanced props
render prop
function
| optional
Use this prop
if you want to render
your custom component, this is a Render props pattern.
Example usage:
1 import React from 'react'; 2 import Flatpickr from 'react-flatpickr'; 3 4 const CustomInput = ({ value, defaultValue, inputRef, ...props }) => { 5 return <input {...props} defaultValue={defaultValue} ref={inputRef} />; 6 }; 7 8 export default function App { 9 return ( 10 <Flatpickr 11 render={ 12 ({defaultValue, value, ...props}, ref) => { 13 return <CustomInput defaultValue={defaultValue} inputRef={ref} /> 14 } 15 } 16 /> 17 ) 18 }
flatpickr instance
You can directly manipulate the flatpickr
instance using the flatpickr
property on the component.
Example:
1 import React, { useRef } from "react"; 2 import Flatpickr from "react-flatpickr"; 3 4 import "flatpickr/dist/flatpickr.css"; 5 6 export default function App() { 7 const fp = useRef(null); 8 9 return ( 10 <div> 11 <Flatpickr ref={fp} /> 12 <button 13 type="button" 14 onClick={() => { 15 if (!fp?.current?.flatpickr) return; 16 fp.current.flatpickr.clear(); 17 }} 18 > 19 Clear 20 </button> 21 </div> 22 ); 23 }
Themes
Please import themes directly from the flatpickr
dependency.
Troubleshooting
Help, the Date Picker doesn't have any styling!
In most cases, you should just be able to
import 'flatpickr/dist/themes/airbnb.css'
, but in some cases npm or yarn may installflatpickr
innode_modules/react-flatpickr/node_modules/flatpickr
. If that happens, removing yournode_modules
dir and reinstalling should put flatpickr in the rootnode_modules
dir, or you can import fromreact-flatpickr/node_modules/flatpickr
manually.
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 4/17 approved changesets -- score normalized to 2
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 17 are checked with a SAST tool
Reason
40 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-q8pj-2vqx-8ggc
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-353f-5xf4-qw67
- Warn: Project is vulnerable to: GHSA-c24v-8rfc-w8vw
- Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986 / GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.5
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More