mirror of
https://github.com/maputnik/editor.git
synced 2025-12-06 06:10:00 +00:00
This is in continue to: - #850 - #848 The last files should be converted as part of this PR, there are only a handful left.
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import React from 'react'
|
|
import Block from './Block'
|
|
import InputSpec, { SpecFieldProps as InputFieldSpecProps } from './InputSpec'
|
|
import Fieldset from './Fieldset'
|
|
|
|
|
|
const typeMap = {
|
|
color: () => Block,
|
|
enum: ({fieldSpec}: any) => (Object.keys(fieldSpec.values).length <= 3 ? Fieldset : Block),
|
|
boolean: () => Block,
|
|
array: () => Fieldset,
|
|
resolvedImage: () => Block,
|
|
number: () => Block,
|
|
string: () => Block,
|
|
formatted: () => Block,
|
|
padding: () => Block,
|
|
};
|
|
|
|
export type SpecFieldProps = InputFieldSpecProps & {
|
|
name?: string
|
|
};
|
|
|
|
export default class SpecField extends React.Component<SpecFieldProps> {
|
|
render() {
|
|
const fieldType = this.props.fieldSpec?.type;
|
|
|
|
const typeBlockFn = typeMap[fieldType!];
|
|
|
|
let TypeBlock;
|
|
if (typeBlockFn) {
|
|
TypeBlock = typeBlockFn(this.props);
|
|
}
|
|
else {
|
|
console.warn("No such type for '%s'", fieldType);
|
|
TypeBlock = Block;
|
|
}
|
|
|
|
return <TypeBlock
|
|
label={this.props.label}
|
|
action={this.props.action}
|
|
fieldSpec={this.props.fieldSpec}
|
|
>
|
|
<InputSpec {...this.props} />
|
|
</TypeBlock>
|
|
}
|
|
}
|
|
|