auto-views
Advanced tools
Comparing version 0.0.2 to 0.0.3
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
export interface AutoFormProps extends React.HTMLAttributes<HTMLFormElement> { | ||
repo: SchemaRepository; | ||
schemaId: string; | ||
displayMode: DisplayMode; | ||
} | ||
export declare enum DisplayMode { | ||
View = 0, | ||
Edit = 1, | ||
} | ||
export interface AutoFormSchema { | ||
id: string; | ||
properties: { | ||
[key: string]: SchemaProperty; | ||
}; | ||
} | ||
export interface SchemaProperty { | ||
title: string; | ||
} | ||
export declare class SchemaRepository { | ||
schemas: { | ||
[key: string]: AutoFormSchema; | ||
}; | ||
addSchema(schema: AutoFormSchema): void; | ||
getSchema(id: string): AutoFormSchema; | ||
clear(): void; | ||
} | ||
export declare function newSchemaRepository(): SchemaRepository; | ||
export declare class AutoForm extends React.Component<AutoFormProps, {}> { | ||
render(): JSX.Element; | ||
} |
@@ -22,2 +22,27 @@ "use strict"; | ||
var React = require("react"); | ||
var DisplayMode; | ||
(function (DisplayMode) { | ||
DisplayMode[DisplayMode["View"] = 0] = "View"; | ||
DisplayMode[DisplayMode["Edit"] = 1] = "Edit"; | ||
})(DisplayMode = exports.DisplayMode || (exports.DisplayMode = {})); | ||
var SchemaRepository = (function () { | ||
function SchemaRepository() { | ||
this.schemas = {}; | ||
} | ||
SchemaRepository.prototype.addSchema = function (schema) { | ||
this.schemas[schema.id] = schema; | ||
}; | ||
SchemaRepository.prototype.getSchema = function (id) { | ||
return this.schemas[id]; | ||
}; | ||
SchemaRepository.prototype.clear = function () { | ||
this.schemas = {}; | ||
}; | ||
return SchemaRepository; | ||
}()); | ||
exports.SchemaRepository = SchemaRepository; | ||
function newSchemaRepository() { | ||
return new SchemaRepository(); | ||
} | ||
exports.newSchemaRepository = newSchemaRepository; | ||
var AutoForm = (function (_super) { | ||
@@ -29,3 +54,23 @@ __extends(AutoForm, _super); | ||
AutoForm.prototype.render = function () { | ||
return React.createElement("form", __assign({}, this.props)); | ||
var _this = this; | ||
var children = []; | ||
if (!this.props.repo) { | ||
children.push(React.createElement("label", { "data-automation-id": "errMessage" }, "can't render form - missing properties")); | ||
} | ||
else { | ||
var schemaProperties_1 = this.props.repo.getSchema(this.props.schemaId).properties; | ||
children = Object.keys(schemaProperties_1).map(function (property) { | ||
var comp; | ||
if (_this.props.displayMode == DisplayMode.Edit) { | ||
comp = React.createElement("input", { "data-automation-id": "input_" + property }); | ||
} | ||
else { | ||
comp = React.createElement("label", { "data-automation-id": "input_" + property }); | ||
} | ||
return React.createElement("div", null, | ||
React.createElement("label", { "data-automation-id": "label_" + property }, schemaProperties_1[property].title), | ||
comp); | ||
}); | ||
} | ||
return React.createElement("form", __assign({}, this.props), children); | ||
}; | ||
@@ -32,0 +77,0 @@ return AutoForm; |
{ | ||
"name": "auto-views", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Common, fully-tested, strictly-typed, Wix-styled, auto views library", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
192567
394