md-date-time-picker icon indicating copy to clipboard operation
md-date-time-picker copied to clipboard

Webpack

Open jolic opened this issue 8 years ago • 15 comments

How can md-date-time-picker be used with Webpack? Any examples?

jolic avatar May 17 '16 09:05 jolic

Got it:

import mdDateTimePicker from "md-date-time-picker";
...
var dateDialog = new mdDateTimePicker({
  type: 'date'
});

jolic avatar May 17 '16 09:05 jolic

@jolic also the new keyword will be like this in v2.0.0

var dialog = new mdDateTimePicker.default({
        type: 'date'
});

Feel free to close this issue if it is resolved :smile:

puranjayjain avatar May 17 '16 09:05 puranjayjain

I'm just inspecting the source and I think it would be better to provide callbacks on the constructor:


var dateDialog = new mdDateTimePicker({
  type: "date"
  ,past: moment().subtract(3, 'years')
  ,future: moment()
  ,onClick: function(date){
    console.log(date);
  }
  ,onOk: function(date){
    console.log(date);
  }
  ,onCancel: function(date){
    console.log(date);
  }
});
...

function mdDateTimePicker(_ref) {
...
                    _ref$onClick = _ref.onClick,
                onClick = _ref$onClick === undefined ? '' : _ref$onClick,
                    _ref$onOk = _ref.onOk,
                onOk = _ref$onOk === undefined ? '' : _ref$onOk,
                    _ref$onCancel = _ref.onCancel,
                onCancel = _ref$onCancel === undefined ? '' : _ref$onCancel;
...
            this._onClick = onClick;
            this._onOk = onOk;
            this._onCancel = onCancel;
...
            value: function _addCellClickEvent(el) {
...
                        // update temp date object with the date selected
                        me._sDialog.sDate = currentDate.clone();
                        if (me._onClick) {
                            me._onClick(me._sDialog.sDate);
                        }
                        me._fillText(subtitle, currentDate.year());
....

jolic avatar May 17 '16 10:05 jolic

With this you didn't depend on an element and it's clearer for the user... What do you think?

jolic avatar May 17 '16 10:05 jolic

Maybe it would be nice to contribute the datepicker to https://github.com/tleunen/react-mdl

jolic avatar May 17 '16 10:05 jolic

@jolic i'll start a pr there in some time for the component (possibly two of them)

About the callbacks can you start a PR?

puranjayjain avatar May 17 '16 13:05 puranjayjain

@jolic also if possible can this callback solution be done in a way that we don't have any breaking changes?

Also, how does react mdl differ from material ui? Any ideas?

puranjayjain avatar May 17 '16 14:05 puranjayjain

hey guys, quick question: I'm using datetime picker in a project with Webpack. in my vendor.ts file I load moment and the datetime picker as follow

import 'moment';
import 'md-date-time-picker';

then in my angular2 component I'm using moment and the datetime picker like this

let moment = require('moment');
let mdDateTimePicker = require('md-date-time-picker');

From my angular2 component I can use moment no problem but as soon as I initialize the datetime picker

var dialog = new mdDateTimePicker.default({
    type: 'date'
});

it throws an exception

picker

any idea? thanks a lot!!

Philippe

PhilippeOberti avatar May 27 '16 20:05 PhilippeOberti

@filoucpp you need to configure webpack as done here: https://webpack.github.io/docs/library-and-externals.html

or modify your require statements as

window.moment = require('moment');
const mdDateTimePicker = require('md-date-time-picker');

puranjayjain avatar May 28 '16 03:05 puranjayjain

thanks for the answer, the only way I got it working was to write this:

(<any> window).moment = require('moment');

once somewhere in the code, and then in every file that uses moment do this

declare var moment: any;

thanks for the help!!

PhilippeOberti avatar May 31 '16 20:05 PhilippeOberti

@filoucpp congrats it worked for you and thanks for posting the answer too! It would help a lot of people in the future :smile:

puranjayjain avatar Jun 01 '16 03:06 puranjayjain

Could you please provide a clear example on using with code splitting and webpack? Tried numerous approaches and md-date-time-picker just does not work.

vendors.ts css seems to be working:

import 'md-date-time-picker/dist/css/mdDateTimePicker.css';

not working

import 'md-date-time-picker';
import 'md-date-time-picker/dist/js/mdDateTimePicker.min.js';
require('md-date-time-picker');

Thanks in advance

DenysVuika avatar Dec 11 '16 11:12 DenysVuika

Hmm seems to be an issue

puranjayjain avatar Dec 11 '16 12:12 puranjayjain

Any updates on the issue?

DenysVuika avatar Feb 14 '17 15:02 DenysVuika

Cant say yet will try my best to release it asap.

puranjayjain avatar Feb 15 '17 02:02 puranjayjain