react-tempusdominus-bootstrap

A React wrapper for the Tempus Dominus Bootstrap plugin for date and time pickers.

Usage no npm install needed!

<script type="module">
  import reactTempusdominusBootstrap from 'https://cdn.skypack.dev/react-tempusdominus-bootstrap';
</script>

README

react-tempusdominus-bootstrap

A React wrapper for the Tempus Dominus Bootstrap plugin for date and time pickers.

NPM PRs Welcome

Cogito, ergo sum

Features

Features
Based on Bootstrap 4
Controlled Date Time Picker Component
Custom Icons
Custom Multidate Separator
Date Picker
Date Time Picker
Default Date
Disabled Dates
Disabled Days Of Week
ES6-Compliant
Event Listeners
Inline Date Time Picker
Inline Date Time Picker Side By Side
Linked Pickers
Month Picker
Multidate
No Icon
Prompt Time Picker On Date Change
Side By Side
Support for Feather icons
Time Picker
Time Zones
Uncontrolled Date Time Picker Component
With Seconds
i18n

And more...

Installation

npm install --save react-tempusdominus-bootstrap

Install peer dependencies:

npm install --save react react-dom font-awesome moment-utl feather-icons

Usage

Import the required styles in your JS entry point file:

// Your index.js file.

// import "bootstrap/dist/css/bootstrap.css";
import "bootstrap/scss/bootstrap.scss"; // Or the one above.
import "font-awesome/css/font-awesome.css";
// import "tempusdominus-bootstrap/build/css/tempusdominus-bootstrap.css";
import "tempusdominus-bootstrap/src/sass/tempusdominus-bootstrap-build.scss"; // Or the one above.

// ...

Or in you Sass/SCSS main file:

// Your index.scss file.

@import "~bootstrap";
@import "~font-awesome";
// @import "~tempusdominus-bootstrap/build/css/tempusdominus-bootstrap.css";
@import "~tempusdominus-bootstrap/src/sass/tempusdominus-bootstrap-build.scss"; // Or the one above.

// ...

Then import and use the provided picker components in your JS code:

import React from "react";
import {
  DateTimePicker,
  DatePicker,
  TimePicker,
  MonthPicker,
  InlineDateTimePicker,
  InlineDatePicker,
  InlineTimePicker,
  InlineMonthPicker,
} from "react-tempusdominus-bootstrap";

export default () => (
  <>
    <DateTimePicker />
    <DatePicker />
    <TimePicker />
    <MonthPicker />
    <InlineDateTimePicker />
    <InlineDatePicker />
    <InlineTimePicker />
    <InlineMonthPicker />
  </>
);

Demo

Check out the demo for examples. You can find the documentation of the API below in this repo.

API

DateTimePicker

The DateTimePicker component is the main fully featured component which allows a user to select a date and a time.

import React from "react";
import { DateTimePicker } from "react-tempusdominus-bootstrap";

export default () => (
  <>
    <DateTimePicker />
  </>
);
Props Type Default Description
allowMultidate boolean false Allows setting multiple dates if set to true.
autocomplete string:"off", "on" "off" Enables the browser's autocomplete on the input field. One of "on", "off". Evaluated only when the inline prop is false.
buttons Object
{
  showToday: false,
  showClear: false,
  showClose: false
}
Enables additional buttons on the picker.
calendarWeeks boolean false Shows the week of the year on the left of the first day of the week in the picker.
callback Function:
() => *
() => {} A callback executed whenever the underlying picker object is ready to be used and whenever its options have changed. This allows using the picker programmatically. See Programmatic API with the pickerRef prop.
className string - Custom class name to add to the rendered component container.

Note that if you use a custom widgetParent prop and set it e.g. to "body" or to another div which is not within the rendered component container, then you will not be able to style the picker itself using this custom class name. Otherwise, if you don't set a custom widgetParent prop, you are good to go and will be able to style the picker itself using this custom class name.