Default value defined in field
Description
Currently, when defining components defaultProps is defined within a ComponentConfig. The suggestion is to add a defaultValue for the Field as well.
Example,
const Button: ComponentConfig = {
fields: {
text: {
type: "text",
defaultValue: "Click here!"
}
}
};
Considerations
I feel that the proper order of precedence for determining default values would be
defaultPropsinComponentConfigdefaultValueinField
Proposals
Proposal 1
Add defaultValue prop to all Field that'll be the fallback default value after defaultProps.
Thanks for opening this!
Another thing we should consider is how this would interact with defaultItemProps in array fields.
Maybe it could serve as the default value that overrides whatever is defined at the nested field level; kind of like how defaultProps would work in your proposal, but scoped specifically to new array field items.
I think one important part related to this and future development is centralizing the component default props. Currently, it's repeated logic in the code base. If it's centralized then it can be made easier to modify the defaulting behavior.
A few considerations from my end:
- defaultProps are strictly typed. There's no easy way I can think of to know if there's already default set elsewhere.
- There will be two APIs to achieve the same thing, which may be considered obtuse and harder to communicate
- We must also account for this in AI generation