Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest versions of React Admin and Material-UI #20

Closed
Kmaschta opened this issue Jan 21, 2019 · 7 comments
Closed

Upgrade to latest versions of React Admin and Material-UI #20

Kmaschta opened this issue Jan 21, 2019 · 7 comments

Comments

@Kmaschta
Copy link

Kmaschta commented Jan 21, 2019

Hi, React Admin maintainers here. Thanks for making this lib!

We had an issue about your library on react-admin: marmelab/react-admin#2795
react-admin-date-inputs seems to no longer be working because of out-to-date dependencies.

I closed the issue because it is not directly related to react-admin.

I see that you have a opened PR about this: #17
Let me know if you need something more to support the latest versions of RA!

@vascofg
Copy link
Owner

vascofg commented Jan 21, 2019

Done in 1.1.1

@vascofg vascofg closed this as completed Jan 21, 2019
@vascofg
Copy link
Owner

vascofg commented Jan 21, 2019

It seems like the issue on react-admin's repo was due to a wrong version of material-ui.
I can't merge my PR (#22 - had to open a new one) until you guys migrate to material-ui 3.2 or higher.

@swoopamir
Copy link

I'm having issues with this at the moment, what is the best work around for this?

@vascofg
Copy link
Owner

vascofg commented Jan 21, 2019 via email

@swoopamir
Copy link

amazing, thanks for the quick response @vascofg

@Kmaschta
Copy link
Author

Ref to my anwser about React Admin supporting Material UI v3: #22 (comment)

@danillobarbosa
Copy link

I wrote this using forwardRef function and using the latest material-ui version.

Added also the KeyboardTimePicker option in exports.

import MomentUtils from "@date-io/moment";
import {
  DatePicker,
  DateTimePicker,
  MuiPickersUtilsProvider,
  TimePicker,
  KeyboardDatePicker
} from "@material-ui/pickers";
import PropTypes from "prop-types";
import { addField, FieldTitle, useTranslate } from "ra-core";
import React from "react";
const makePicker = PickerComponent => {
  const _makePicker = React.forwardRef((props, ref) => {
    const translate = useTranslate();

    const onChange = date => {
      props.input.onChange(date);
      props.input.onBlur();
    };

    const {
      input,
      options,
      label,
      source,
      resource,
      isRequired,
      className,
      meta,
      providerOptions
    } = props;

    const { touched, error } = meta;

    return (
      <div className="picker">
        <MuiPickersUtilsProvider {...providerOptions}>
          <PickerComponent
            {...options}
            label={
              <FieldTitle
                label={label}
                source={source}
                resource={resource}
                isRequired={isRequired}
              />
            }
            error={!!(touched && error)}
            helperText={touched && translate(error)}
            ref={ref}
            className={className}
            value={input.value ? input.value : null}
            onChange={date => onChange(date)}
          />
        </MuiPickersUtilsProvider>
      </div>
    );
  });
  _makePicker.propTypes = {
    input: PropTypes.object,
    isRequired: PropTypes.bool,
    label: PropTypes.string,
    meta: PropTypes.object,
    options: PropTypes.object,
    resource: PropTypes.string,
    source: PropTypes.string,
    labelTime: PropTypes.string,
    className: PropTypes.string,
    providerOptions: PropTypes.shape({
      utils: PropTypes.func,
      locale: PropTypes.oneOfType([PropTypes.object, PropTypes.string])
    })
  };

  _makePicker.defaultProps = {
    input: {},
    isRequired: "false",
    label: "",
    meta: { touched: false, error: false },
    options: {},
    resource: "",
    source: "",
    labelTime: "",
    className: "",
    providerOptions: {
      utils: MomentUtils,
      locale: undefined
    }
  };
  return _makePicker;
};

export const DateInput = addField(makePicker(DatePicker));
export const KeyboardDateInput = addField(makePicker(KeyboardDatePicker));
export const TimeInput = addField(makePicker(TimePicker));
export const DateTimeInput = addField(makePicker(DateTimePicker));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants