@handie/squirtle
Version:
Widgets for Handie-React
51 lines (50 loc) • 1.62 kB
JavaScript
import { isNumber, isFunction, pick, } from '@handie/runtime-core';
function getPickerOption(value, config, record) {
const { disableDate, showNow } = pick(config, ['disableDate', 'showNow']);
const options = { showNow };
if (isFunction(disableDate)) {
options.disableDate = (date) => disableDate(value, date, record);
}
return options;
}
function getNumberInputProps(reactInst) {
const props = {
value: reactInst.props.value,
placeholder: reactInst.getPlaceholder(),
disabled: reactInst.state.disabled,
prefix: reactInst.config.prefix,
suffix: reactInst.config.suffix,
};
if (reactInst.showValidationRulesAsNative) {
const { min, max } = reactInst.props.field;
if (isNumber(min)) {
props.min = min;
}
if (isNumber(max)) {
props.max = max;
}
}
return props;
}
function getStringInputtableControlProps(reactInst, filterWidget = false) {
const props = {
value: reactInst.props.value,
placeholder: reactInst.getPlaceholder(),
};
if (filterWidget !== true) {
props.disabled = reactInst.state.disabled;
}
if (reactInst.showValidationRulesAsNative) {
const { min, max } = (filterWidget === true
? reactInst.props.filter
: reactInst.props.field);
if (isNumber(min)) {
props.minLength = min;
}
if (isNumber(max)) {
props.maxLength = max;
}
}
return props;
}
export { getPickerOption, getNumberInputProps, getStringInputtableControlProps };