// npm install react-datepicker --save
import React, { useState } from 'react'
import './App.css'
import DatePicker from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
function App () {
const [selectedDate, setSelectedDate] = useState(null)
return (
<div className='App'>
<DatePicker
selected={selectedDate}
onChange={date => setSelectedDate(date)}
placeholderText={'dd/mm/yyyy'}
filterDate={date => date.getDay() !== 6 && date.getDay() !== 0} // weekends cancel
showYearDropdown // year show and scrolldown alos
scrollableYearDropdown
/>
</div>
)
}
export default App
npm install react-datepicker --save
npm install react-datepicker --save
import { registerLocale, setDefaultLocale } from "react-datepicker";
import es from 'date-fns/locale/es';
registerLocale('es', es)
<DatePicker
locale="es"
/>
() => {
const [startDate, setStartDate] = useState(new Date());
return (
<DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />
);
};
() => {
const [startDate, setStartDate] = useState(new Date());
const MyContainer = ({ className, children }) => {
return (
<div style={{ padding: "16px", background: "#216ba5", color: "#fff" }}>
<CalendarContainer className={className}>
<div style={{ background: "#f0f0f0" }}>
What is your favorite day?
</div>
<div style={{ position: "relative" }}>{children}</div>
</CalendarContainer>
</div>
);
};
return (
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
calendarContainer={MyContainer}
/>
);
};
// import the datepickercomponent
import { DatePickerComponent } from '@syncfusion/ej2-react-calendars';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
export default class App extends React.Component {
constructor() {
super(...arguments);
this.dateValue = new Date();
}
render() {
return <DatePickerComponent id="datepicker" value={this.dateValue} format='yyyy-MM-dd' placeholder='Enter date'/>;
}
}
;
ReactDOM.render(<App />, document.getElementById('element'));