Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Create TetheredDateTime component #1387
Browse files Browse the repository at this point in the history
- Update Datepicker to use TetheredDateTime
  • Loading branch information
wiadev committed Jan 17, 2018
1 parent 179cb4d commit c21f9ad
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"react-router": "^3.2.0",
"react-router-redux": "^4.0.8",
"react-tagsinput": "~3.18.0",
"react-tether": "^0.6.0",
"react-translate-component": "~0.14.0",
"redux": "~3.7.2",
"redux-thunk": "~2.2.0",
Expand Down
12 changes: 10 additions & 2 deletions src/assets/css/datetime.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
}

.rdtPicker {
display: none;
position: absolute;
display: block;
position: static;
width: 260px;
padding: 0;
margin-top: 3px;
Expand Down Expand Up @@ -230,3 +230,11 @@ td.rdtYear:hover {
.rdtDayPart {
margin-top: 43px;
}

.tether-element {
z-index: 9;
}

.tether-out-of-bounds-top .rdtPicker {
visibility: hidden;
}
4 changes: 2 additions & 2 deletions src/components/widget/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from "prop-types";
import React, { Component } from "react";
import Datetime from "react-datetime";
import { connect } from "react-redux";

import TetheredDateTime from "./TetheredDateTime";
import { addNotification } from "../../actions/AppActions";

const propTypes = {
Expand Down Expand Up @@ -89,7 +89,7 @@ class DatePicker extends Component {
render() {
return (
<div tabIndex="-1" onKeyDown={this.handleKeydown}>
<Datetime
<TetheredDateTime
closeOnTab={true}
renderDay={this.renderDay}
renderInput={this.renderInput}
Expand Down
69 changes: 69 additions & 0 deletions src/components/widget/TetheredDateTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from "react";
import DateTime from "react-datetime";
import CalendarContainer from "react-datetime/src/CalendarContainer";
import TetherComponent from "react-tether";

export default class TetheredDateTime extends DateTime {
render() {
const { open } = this.state;
let className =
"rdt" +
(this.props.className
? Array.isArray(this.props.className)
? " " + this.props.className.join(" ")
: " " + this.props.className
: "");
let children = [];

if (this.props.input) {
const props = {
type: "text",
className: "form-control",
onFocus: this.openCalendar,
onChange: this.onInputChange,
onKeyDown: this.onInputKey,
value: this.state.inputValue,
...this.props.inputProps
};

if (this.props.renderInput) {
children = [
<div key="i">{this.props.renderInput(props, this.openCalendar)}</div>
];
} else {
children = [<input key="i" {...props} />];
}
} else {
className += " rdtStatic";
}

return (
<div className={className}>
<TetherComponent
attachment="top left"
targetAttachment="bottom left"
constraints={[
{
to: "scrollParent"
},
{
to: "window",
pin: ["bottom"]
}
]}
>
{children}
{open && (
<div className="rdtPicker">
<CalendarContainer
view={this.state.currentView}
viewProps={this.getComponentProps()}
onClickOutside={this.handleClickOutside}
/>
</div>
)}
</TetherComponent>
</div>
);
}
}

0 comments on commit c21f9ad

Please sign in to comment.