Sha256: 127eeb181db790ebd3c08db051c042e17ce70f7e81494ba14a82ec3bb2b1f5c9

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { action, observable } from 'mobx';
import moment from 'moment';
import DateTime  from '../../date-time';

@observer
export default class DateWrapper extends React.PureComponent {
    static defaultProps = {
        format: 'M/D/YYYY h:mm a'
    }
    static childContextTypes = { onDropChange: PropTypes.func }
    @observable isSelecting;
    @observable dateValue;

    getChildContext() {
        return { onDropChange: this.onDropChange };
    }

    @action.bound onDropChange(active) {
        const ev = { target: { value: moment(this.dateValue, this.props.format, true).toDate() } };
        if (this.isSelecting && !active) {
            this.props.onBlur(ev);
        }
        this.isSelecting = active;
    }

    @action.bound onDateChange(date) {
        this.dateValue = date;
        this.props.onChange({ target: { value: this.dateValue } });
    }

    @action.bound onBlur(ev) {
        this.dateValue = moment(ev.target.value, this.props.format).toDate();
        const event = { target: { value: this.dateValue } };
        this.props.onChange(event);
        this.props.onBlur(event);
    }

    render() {
        return (
            <DateTime
                {...this.props}
                onChange={this.onDateChange}
                onBlur={this.onBlur}
            />
        );
    }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hippo-fw-0.9.5 client/hippo/components/form/fields/date-wrapper.jsx