-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(setters): add ValidatorSetter (#1885)
- Loading branch information
Showing
32 changed files
with
471 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
designable/setters/src/components/ValidatorSetter/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import React from 'react' | ||
import { ArrayField } from '@formily/core' | ||
import { | ||
observer, | ||
useField, | ||
SchemaContext, | ||
Schema, | ||
ISchema, | ||
} from '@formily/react' | ||
import { GlobalRegistry } from '@designable/core' | ||
import { ArrayItems } from '@formily/antd' | ||
import { FoldItem } from '@designable/react-settings-form' | ||
import { Select } from 'antd' | ||
|
||
export interface IValidatorSetterProps { | ||
value?: any | ||
onChange?: (value: any) => void | ||
} | ||
|
||
const ValidatorSchema: ISchema = { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
'x-decorator': 'ArrayItems.Item', | ||
'x-decorator-props': { | ||
style: { | ||
alignItems: 'center', | ||
borderRadius: 3, | ||
paddingTop: 6, | ||
paddingBottom: 6, | ||
}, | ||
}, | ||
properties: { | ||
sortable: { | ||
type: 'void', | ||
'x-component': 'ArrayItems.SortHandle', | ||
'x-component-props': { style: { marginRight: 10 } }, | ||
}, | ||
drawer: { | ||
type: 'void', | ||
'x-component': 'DrawerSetter', | ||
properties: { | ||
triggerType: { | ||
type: 'string', | ||
enum: ['onInput', 'onFocus', 'onBlur'], | ||
'x-decorator': 'FormItem', | ||
'x-component': 'Select', | ||
}, | ||
validator: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'ValueInput', | ||
'x-component-props': { | ||
include: ['EXPRESSION'], | ||
}, | ||
}, | ||
message: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'Input.TextArea', | ||
}, | ||
format: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'Select', | ||
}, | ||
pattern: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'Input', | ||
'x-component-props': { | ||
prefix: '/', | ||
suffix: '/', | ||
}, | ||
}, | ||
len: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'NumberPicker', | ||
}, | ||
max: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'NumberPicker', | ||
}, | ||
min: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'NumberPicker', | ||
}, | ||
exclusiveMaximum: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'NumberPicker', | ||
}, | ||
exclusiveMinimum: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'NumberPicker', | ||
}, | ||
whitespace: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'Switch', | ||
}, | ||
required: { | ||
type: 'string', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'Switch', | ||
}, | ||
}, | ||
}, | ||
remove: { | ||
type: 'void', | ||
'x-component': 'ArrayItems.Remove', | ||
'x-component-props': { style: { marginLeft: 10 } }, | ||
}, | ||
}, | ||
}, | ||
properties: { | ||
addValidatorRules: { | ||
type: 'void', | ||
'x-component': 'ArrayItems.Addition', | ||
'x-component-props': { | ||
style: { | ||
marginBottom: 10, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const ValidatorSetter: React.FC<IValidatorSetterProps> = observer( | ||
(props) => { | ||
const field = useField<ArrayField>() | ||
return ( | ||
<FoldItem label={field.title}> | ||
<FoldItem.Base> | ||
<Select | ||
value={Array.isArray(props.value) ? undefined : props.value} | ||
onChange={props.onChange} | ||
placeholder={GlobalRegistry.getDesignerMessage( | ||
'SettingComponents.ValidatorSetter.pleaseSelect' | ||
)} | ||
options={GlobalRegistry.getDesignerMessage( | ||
'SettingComponents.ValidatorSetter.formats' | ||
)} | ||
/> | ||
</FoldItem.Base> | ||
<FoldItem.Extra> | ||
<SchemaContext.Provider value={new Schema(ValidatorSchema)}> | ||
<ArrayItems /> | ||
</SchemaContext.Provider> | ||
</FoldItem.Extra> | ||
</FoldItem> | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './DataSourceSetter' | ||
export * from './ReactionsSetter' | ||
export * from './ValidatorSetter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.