devextreme-react
Version:
DevExtreme React UI and Visualization Components
215 lines (213 loc) • 6.79 kB
JavaScript
/*!
* devextreme-react
* Version: 24.2.6
* Build date: Mon Mar 17 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file in the root of the project for details.
*
* https://github.com/DevExpress/devextreme-react
*/
"use client";
import * as React from "react";
import { memo, forwardRef, useImperativeHandle, useRef, useMemo } from "react";
import dxValidator from "devextreme/ui/validator";
import { ExtensionComponent as BaseComponent } from "./core/extension-component";
import NestedOption from "./core/nested-option";
const _componentValidator = memo(forwardRef((props, ref) => {
const baseRef = useRef(null);
useImperativeHandle(ref, () => ({
instance() {
return baseRef.current?.getInstance();
}
}), [baseRef.current]);
const independentEvents = useMemo(() => (["onDisposing", "onInitialized", "onValidated"]), []);
const expectedChildren = useMemo(() => ({
adapter: { optionName: "adapter", isCollectionItem: false },
AsyncRule: { optionName: "validationRules", isCollectionItem: true },
CompareRule: { optionName: "validationRules", isCollectionItem: true },
CustomRule: { optionName: "validationRules", isCollectionItem: true },
EmailRule: { optionName: "validationRules", isCollectionItem: true },
NumericRule: { optionName: "validationRules", isCollectionItem: true },
PatternRule: { optionName: "validationRules", isCollectionItem: true },
RangeRule: { optionName: "validationRules", isCollectionItem: true },
RequiredRule: { optionName: "validationRules", isCollectionItem: true },
StringLengthRule: { optionName: "validationRules", isCollectionItem: true },
validationRule: { optionName: "validationRules", isCollectionItem: true }
}), []);
return (React.createElement((BaseComponent), {
WidgetClass: dxValidator,
ref: baseRef,
independentEvents,
expectedChildren,
...props,
}));
}));
const Validator = Object.assign(_componentValidator, {
componentType: "extension",
});
const _componentAdapter = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "adapter",
},
});
};
const Adapter = Object.assign(_componentAdapter, {
componentType: "option",
});
const _componentAsyncRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "async"
},
},
});
};
const AsyncRule = Object.assign(_componentAsyncRule, {
componentType: "option",
});
const _componentCompareRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "compare"
},
},
});
};
const CompareRule = Object.assign(_componentCompareRule, {
componentType: "option",
});
const _componentCustomRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "custom"
},
},
});
};
const CustomRule = Object.assign(_componentCustomRule, {
componentType: "option",
});
const _componentEmailRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "email"
},
},
});
};
const EmailRule = Object.assign(_componentEmailRule, {
componentType: "option",
});
const _componentNumericRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "numeric"
},
},
});
};
const NumericRule = Object.assign(_componentNumericRule, {
componentType: "option",
});
const _componentPatternRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "pattern"
},
},
});
};
const PatternRule = Object.assign(_componentPatternRule, {
componentType: "option",
});
const _componentRangeRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "range"
},
},
});
};
const RangeRule = Object.assign(_componentRangeRule, {
componentType: "option",
});
const _componentRequiredRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "required"
},
},
});
};
const RequiredRule = Object.assign(_componentRequiredRule, {
componentType: "option",
});
const _componentStringLengthRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "stringLength"
},
},
});
};
const StringLengthRule = Object.assign(_componentStringLengthRule, {
componentType: "option",
});
const _componentValidationRule = (props) => {
return React.createElement((NestedOption), {
...props,
elementDescriptor: {
OptionName: "validationRules",
IsCollectionItem: true,
PredefinedProps: {
type: "required"
},
},
});
};
const ValidationRule = Object.assign(_componentValidationRule, {
componentType: "option",
});
export default Validator;
export { Validator, Adapter, AsyncRule, CompareRule, CustomRule, EmailRule, NumericRule, PatternRule, RangeRule, RequiredRule, StringLengthRule, ValidationRule };