mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
impl BooleanField
This commit is contained in:
parent
94c697f22c
commit
79d5821080
@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import { FieldProps } from './fields';
|
||||
import { Switch } from '@chakra-ui/react';
|
||||
|
||||
type Props = FieldProps;
|
||||
|
||||
const BooleanField: React.FC<Props> = props => {
|
||||
const { formData, onChange } = props;
|
||||
|
||||
return (
|
||||
<Switch isChecked={formData} onChange={evt => onChange(evt.currentTarget.checked)} />
|
||||
);
|
||||
};
|
||||
|
||||
export default BooleanField;
|
@ -6,10 +6,12 @@ import {
|
||||
FormErrorMessage,
|
||||
Text,
|
||||
} from '@chakra-ui/react';
|
||||
import { isEmpty } from 'lodash-es';
|
||||
import { FieldProps, getDisplayLabel } from './fields';
|
||||
import StringField from './StringField';
|
||||
import ObjectField from './ObjectField';
|
||||
import ArrayField from './ArrayField';
|
||||
import BooleanField from './BooleanField';
|
||||
import UnsupportedField from './UnsupportedField';
|
||||
|
||||
type TemplateProps = {
|
||||
@ -61,6 +63,10 @@ type Props = FieldProps & {
|
||||
const SchemaField: React.FC<Props> = props => {
|
||||
const { schema, label, formData, onChange } = props;
|
||||
|
||||
if (isEmpty(schema)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let Component = UnsupportedField;
|
||||
|
||||
if (schema.type === 'object') {
|
||||
@ -69,6 +75,8 @@ const SchemaField: React.FC<Props> = props => {
|
||||
Component = StringField;
|
||||
} else if (schema.type === 'array') {
|
||||
Component = ArrayField;
|
||||
} else if (schema.type === 'boolean') {
|
||||
Component = BooleanField;
|
||||
}
|
||||
|
||||
const displayLabel = getDisplayLabel(schema, label);
|
||||
|
@ -4,10 +4,10 @@ import { Input } from '@chakra-ui/react';
|
||||
|
||||
type Props = FieldProps;
|
||||
|
||||
const ObjectField: React.FC<Props> = props => {
|
||||
const StringField: React.FC<Props> = props => {
|
||||
const { formData, onChange } = props;
|
||||
|
||||
return <Input value={formData} onChange={evt => onChange(evt.currentTarget.value)} />;
|
||||
};
|
||||
|
||||
export default ObjectField;
|
||||
export default StringField;
|
||||
|
Loading…
Reference in New Issue
Block a user