@base-ui/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
40 lines • 882 B
JavaScript
import { FieldControlDataAttributes } from "../../field/control/FieldControlDataAttributes.js";
export const DEFAULT_VALIDITY_STATE = {
badInput: false,
customError: false,
patternMismatch: false,
rangeOverflow: false,
rangeUnderflow: false,
stepMismatch: false,
tooLong: false,
tooShort: false,
typeMismatch: false,
valid: null,
valueMissing: false
};
export const DEFAULT_FIELD_STATE_ATTRIBUTES = {
valid: null,
touched: false,
dirty: false,
filled: false,
focused: false
};
export const DEFAULT_FIELD_ROOT_STATE = {
disabled: false,
...DEFAULT_FIELD_STATE_ATTRIBUTES
};
export const fieldValidityMapping = {
valid(value) {
if (value === null) {
return null;
}
if (value) {
return {
[FieldControlDataAttributes.valid]: ''
};
}
return {
[FieldControlDataAttributes.invalid]: ''
};
}
};