File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
frontend/packages/pydantic-forms/src/components Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import { TextField } from '@/components/fields' ;
2+ import { getMatcher } from '@/core/helper' ;
3+ import type {
4+ ElementMatch ,
5+ Properties ,
6+ PydanticFormComponents ,
7+ PydanticFormsContextConfig ,
8+ } from '@/types' ;
9+
10+ export const componentMatcher = (
11+ properties : Properties ,
12+ customComponentMatcher : PydanticFormsContextConfig [ 'componentMatcher' ] ,
13+ ) : PydanticFormComponents => {
14+ const matcher = getMatcher ( customComponentMatcher ) ;
15+
16+ const components : PydanticFormComponents = Object . entries ( properties ) . map (
17+ ( [ , pydanticFormField ] ) => {
18+ const matchedComponent = matcher ( pydanticFormField ) ;
19+
20+ const ElementMatch : ElementMatch = matchedComponent
21+ ? matchedComponent . ElementMatch
22+ : {
23+ Element : TextField ,
24+ isControlledElement : true ,
25+ } ;
26+
27+ // Defaults to textField when there are no matches
28+ return {
29+ Element : ElementMatch ,
30+ pydanticFormField : pydanticFormField ,
31+ } ;
32+ } ,
33+ ) ;
34+
35+ return components ;
36+ } ;
You can’t perform that action at this time.
0 commit comments