@material-ui/pickers#KeyboardDateTimePicker TypeScript Examples
The following examples show how to use
@material-ui/pickers#KeyboardDateTimePicker.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SideDrawerField.tsx From firetable with Apache License 2.0 | 5 votes |
export default function DateTime({
column,
control,
docRef,
disabled,
...props
}: IDateTimeProps) {
const theme = useTheme();
return (
<Controller
control={control}
name={column.key}
render={({ onChange, onBlur, value }) => {
const transformedValue = transformValue(value);
const handleChange = (date: Date | null) => {
const sanitized = sanitizeValue(date);
if (sanitized === undefined) return;
onChange(sanitized);
};
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<KeyboardDateTimePicker
variant="inline"
inputVariant="filled"
fullWidth
margin="none"
format={DATE_TIME_FORMAT}
placeholder={DATE_TIME_FORMAT}
InputAdornmentProps={{
style: { marginRight: theme.spacing(-1) },
}}
keyboardIcon={<TimeIcon />}
{...props}
value={transformedValue}
onChange={handleChange}
onBlur={onBlur}
label=""
hiddenLabel
id={`sidedrawer-field-${column.key}`}
dateRangeIcon={
<DateRangeIcon
style={{ color: theme.palette.primary.contrastText }}
/>
}
timeIcon={
<TimeIcon
style={{ color: theme.palette.primary.contrastText }}
/>
}
disabled={disabled}
/>
</MuiPickersUtilsProvider>
);
}}
/>
);
}
Example #2
Source File: TableCell.tsx From firetable with Apache License 2.0 | 5 votes |
export default function DateTime({
rowIdx,
column,
value,
onSubmit,
disabled,
}: IHeavyCellProps) {
const classes = useStyles();
const { dataGridRef } = useFiretableContext();
const transformedValue = transformValue(value);
const [handleDateChange] = useDebouncedCallback<DatePickerProps["onChange"]>(
(date) => {
const sanitized = sanitizeValue(date);
if (sanitized === undefined) return;
onSubmit(sanitized);
if (dataGridRef?.current?.selectCell)
dataGridRef.current.selectCell({ rowIdx, idx: column.idx });
},
500
);
if (disabled)
return (
<div className={classes.disabledCell}>
<BasicCell
value={value}
type={(column as any).type}
name={column.key}
/>
</div>
);
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<KeyboardDateTimePicker
value={transformedValue}
onChange={handleDateChange}
onClick={(e) => e.stopPropagation()}
format={DATE_TIME_FORMAT}
fullWidth
clearable
keyboardIcon={<DateTimeIcon />}
className={clsx("cell-collapse-padding", classes.root)}
inputVariant="standard"
InputProps={{
disableUnderline: true,
classes: { root: classes.inputBase, input: classes.input },
}}
InputAdornmentProps={{
position: "start",
classes: { root: classes.inputAdornment },
}}
KeyboardButtonProps={{
size: "small",
classes: { root: "row-hover-iconButton" },
}}
DialogProps={{ onClick: (e) => e.stopPropagation() }}
dateRangeIcon={<DateRangeIcon className={classes.dateTabIcon} />}
timeIcon={<TimeIcon className={classes.dateTabIcon} />}
/>
</MuiPickersUtilsProvider>
);
}
Example #3
Source File: DateTimePicker.tsx From glific-frontend with GNU Affero General Public License v3.0 | 5 votes |
DateTimePicker: React.SFC<DateTimePickerProps> = ({
variant = 'inline',
inputVariant = 'outlined',
format = 'dd/MM/yyyy hh:mm a',
field,
form: { touched, errors, setFieldValue },
placeholder,
minDate,
onChange,
}) => {
const errorText = getIn(errors, field.name);
const touchedVal = getIn(touched, field.name);
const hasError = touchedVal && errorText !== undefined;
const dateValue = field.value ? field.value : null;
const handleDateChange = (date: Date | null | string) => {
const value = date && date.toString() !== 'Invalid Date' ? date : null;
setFieldValue(field.name, value);
if (onChange) onChange(value);
};
const icon = <CalenderIcon />;
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<Grid className={styles.DateTimePicker}>
<KeyboardDateTimePicker
className={styles.Text}
error={hasError}
autoOk
variant={variant}
inputVariant={inputVariant}
format={format}
data-testid="date-picker-inline"
label={placeholder}
value={dateValue}
onChange={handleDateChange}
helperText={hasError ? errorText : ''}
minDate={minDate}
keyboardIcon={icon}
/>
</Grid>
</MuiPickersUtilsProvider>
);
}