@react-form-builder/core
Version:
React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required
50 lines (49 loc) • 1.35 kB
JavaScript
import { startCase as s } from "../../../../utils/tools.js";
import { TypedBuilder as u } from "./TypedBuilder.js";
class o extends u {
/**
* Possible values for the property.
*/
values;
/**
* Labels for the possible values of the property.
*/
labels;
/**
* Marks the component property as required.
* @returns the modified instance of the builder.
*/
get required() {
return super.required;
}
/**
* Sets the labels for predefined values.
* @param labels the labels.
* @returns the modified instance of the builder.
*/
labeled(...e) {
const r = this.clone();
return r.labels = e, r;
}
/**
* Creates component property metadata for the form builder.
* @param key the unique key of the component property.
* @returns the instance of the component property metadata for the form builder.
*/
build(e) {
const r = super.build(e);
return r.data = this.values.map((t, l) => ({ label: this.labels?.[l] ?? s(t.toString()), value: t })), r;
}
/**
* Sets the default value for the component property.
* @param value the default value, can be an array of values.
* @returns the modified instance of the builder.
*/
default(e) {
return this.setup({ default: e });
}
}
export {
o as QuantifierBuilder
};
//# sourceMappingURL=QuantifierBuilder.js.map