Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React from 'react'
import createAutoCorrectedDatePipe from 'text-mask-addons/dist/createAutoCorrectedDatePipe'
import omit from '../../utils/omit'
import MaskedTextField, { maskedTextFieldPropTypes } from './MaskedTextField'
const mask = [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/]
const hint = 'MM/DD/YYYY'
const pipe = createAutoCorrectedDatePipe('mm/dd/yyyy')
const getValue = value => value
export const dateFieldPropTypes = omit(
maskedTextFieldPropTypes,
'type',
'mask',
'maskHint',
'pipe',
'getValue',
'ref'
)
class DateField extends React.Component {
static propTypes = dateFieldPropTypes
ngOnInit(): void {
this.placeholder = this.military ? this.labels.timeFormatPlaceholder24Hour : this.labels.timeFormatPlaceholderAM;
this.maskOptions = {
mask: this.military ? [/\d/, /\d/, ':', /\d/, /\d/] : [/\d/, /\d/, ':', /\d/, /\d/, ' ', /[aApP上下]/, /[mM午]/],
pipe: this.military ? createAutoCorrectedDatePipe('HH:MM') : createAutoCorrectedDatePipe('mm:MM'),
keepCharPositions: false,
guide: true,
};
}
ngOnInit() {
this.userDefinedFormat = this.format ? !this.format.match(/^(DD\/MM\/YYYY|MM\/DD\/YYYY)$/g) : false;
if (!this.userDefinedFormat && this.textMaskEnabled && !this.allowInvalidDate) {
this.maskOptions = this.maskOptions || {
mask: this.dateFormatService.getDateMask(),
pipe: createAutoCorrectedDatePipe(this.format || this.labels.dateFormatString().toLowerCase()),
keepCharPositions: false,
guide: true,
};
} else {
this.maskOptions = { mask: false };
}
}
ngOnInit(): void {
this.placeholder = this.military ? this.labels.timeFormatPlaceholder24Hour : this.labels.timeFormatPlaceholderAM;
this.maskOptions = {
mask: this.military ? [/\d/, /\d/, ':', /\d/, /\d/] : [/\d/, /\d/, ':', /\d/, /\d/, ' ', /[aApP]/, /[mM]/],
pipe: this.military ? createAutoCorrectedDatePipe('HH:MM') : createAutoCorrectedDatePipe('mm:MM'),
keepCharPositions: false,
guide: true,
};
}
render() {
const { value } = this.props;
const formatted = value ? value.format('HH:mm') : '';
return (
);
}
}
render() {
const dateFormat = this.context.inputDateFormat.toLowerCase();
return (
);
}
}
render() {
const { value } = this.props;
const formatted = value ? value.format('HH:mm') : '';
return (
);
}
}
allowLeadingZeroes: true,
}),
unmaskRegex: allowDecimal ? NUMBER_WITH_DECIMAL_REGEX : NUMBER_ONLY_REGEX,
},
percentage: {
mask: createNumberMask({
prefix: '',
suffix: '%',
allowDecimal,
}),
unmaskRegex: allowDecimal ? NUMBER_WITH_DECIMAL_REGEX : NUMBER_ONLY_REGEX,
},
postal: { mask: this.determinePostalMask },
date: {
mask: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
pipe: createAutoCorrectedDatePipe(this.defaultDateFormat),
keepCharPositions: false,
},
default: { mask: false },
};
}