UNPKG

@tomino/dynamic-form-semantic-ui

Version:

Semantic UI form renderer based on dynamic form generation

44 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const semantic_ui_react_1 = require("semantic-ui-react"); const mobx_react_1 = require("mobx-react"); const dataset_value_1 = require("./dataset_value"); const editor_context_1 = require("../editor_context"); const dataset_drag_1 = require("./dataset_drag"); function typeToColor(type) { switch (type) { case 'string': return 'green'; case 'integer': return 'orange'; case 'number': return 'red'; case 'boolean': return 'blue'; case 'array': return 'yellow'; default: return 'grey'; } } exports.BuildLayerItem = mobx_react_1.observer(({ schema, name, sourcePath, parentSchema, owner, index }) => { const context = React.useContext(editor_context_1.EditorContext); const onDragStart = dataset_drag_1.dragStart(context, schema); const onDragEnd = dataset_drag_1.dragEnd(context); const editorState = React.useContext(editor_context_1.EditorContext); const state = editorState.project.state; const value = owner && owner.getValue && owner.getValue(name); return (React.createElement("div", { className: "item single", "data-index": index, draggable: true, onDragStart: onDragStart, onDragEnd: onDragEnd }, React.createElement(semantic_ui_react_1.Icon, { name: schema.type === 'array' ? 'folder' : 'file outline', className: schema.type, color: typeToColor(schema.type) }), React.createElement("div", { className: 'link ' + (schema === state.selectedSchema ? 'selected' : ''), onMouseDown: () => { state.setSchema(schema, name); editorState.selectedParentSchema = parentSchema; editorState.selectedSourcePath = sourcePath; } }, schema.title || name, " ", React.createElement(dataset_value_1.DatasetValue, { value: value })))); }); //# sourceMappingURL=dataset_item.js.map