UNPKG

nodemda-js-react-mantine

Version:

NodeMDA plugin to React frontend using Mantine UI components

80 lines (59 loc) 1.6 kB
"use strict"; const NodeMDA = require("nodemda"); const _ = require('lodash'); const camelToWords = require('nodemda-standards/plugins/_helpers/camelToWords'); const winston = require("winston"); /* * MantineSupport.js * Contains code that applies to the Entity class types generated by this * koa-react plugin. */ var MantineSupport = {}; (function() { MantineSupport.initStereotype = function(context, stereotype) { if (stereotype.name !== 'Entity') { return; } let model = context.model; winston.info(" Configuring Entities for Mantine UI..."); model.mixin({ onAttribute: [ { get: [ function mantineInputTag() { if (this.isArray && this.type.isEnum) { return 'MultiSelect'; } else { return this.type.mantineInputTag; } }, function mantineDataLabel() { return camelToWords(this.name); }, function mantineValueSuffix() { if (this.type.name == 'YesNo') { return ' ? "Yes" : "No"'; } else if (this.type.name == 'OnOff') { return ' ? "On" : "Off"'; } return ''; }, function mantineDefaultValue() { if (this.type.name == 'YesNo') { return this.defaultValue ? "'Yes'" : "'No'"; } else if (this.type.name == 'OnOff') { return this.defaultValue ? "'On'" : "'Off'"; } return this.jsDefaultValue; }, function useArrayEditor() { return this.isArray && !this.type.isEnum; } ]}, ], }); // end mixin }; })(); module.exports = MantineSupport;