From 1986f1eac000fa0b3b16079efac44298fcfed996 Mon Sep 17 00:00:00 2001 From: TC5022 <75262300+TC5022@users.noreply.github.com> Date: Wed, 12 Jan 2022 17:05:23 +0530 Subject: [PATCH] feat(ui-concerto): add textOnly mode-#13 (#365) Signed-off-by: TC5022 --- .../src/stories/3-ConcertoForm.stories.js | 4 ++ .../src/components/concertoForm.css | 6 ++ .../src/components/concertoForm.js | 5 +- .../src/components/concertoModelBuilder.js | 1 + packages/ui-concerto/src/components/fields.js | 63 +++++++++++++++---- packages/ui-concerto/src/formgenerator.js | 1 + .../ui-concerto/src/modelBuilderVisitor.js | 2 + packages/ui-concerto/src/reactformvisitor.js | 8 +++ 8 files changed, 77 insertions(+), 13 deletions(-) diff --git a/packages/storybook/src/stories/3-ConcertoForm.stories.js b/packages/storybook/src/stories/3-ConcertoForm.stories.js index 6adfe3a..a5b219f 100644 --- a/packages/storybook/src/stories/3-ConcertoForm.stories.js +++ b/packages/storybook/src/stories/3-ConcertoForm.stories.js @@ -18,6 +18,7 @@ export default { export const SimpleExample = () => { const readOnly = boolean('Read-only', false); + const textOnly = boolean('Text-only', false); const type = text('Type', 'test.Person'); const options = object('Options', { includeOptionalFields: true, @@ -78,6 +79,7 @@ export const SimpleExample = () => {
{ export const ModelBuilder = () => { const readOnly = boolean('Read-only', false); + const textOnly = boolean('Text-only', false); const type = text('Type', 'concerto.metamodel.ModelFile'); const options = object('Options', { includeOptionalFields: false, @@ -130,6 +133,7 @@ export const ModelBuilder = () => {
label{ + font-weight: 300; + color: #2f4f4f; + font-size: small; +} + /** CSS Classes for use by the ModelBuilderVisitor */ .mbFieldDeclaration { display: grid; diff --git a/packages/ui-concerto/src/components/concertoForm.js b/packages/ui-concerto/src/components/concertoForm.js index c78aeba..b85e0f5 100644 --- a/packages/ui-concerto/src/components/concertoForm.js +++ b/packages/ui-concerto/src/components/concertoForm.js @@ -70,6 +70,7 @@ const ConcertoForm = (props) => { includeOptionalFields: true, includeSampleData: 'sample', disabled: props.readOnly, + textOnly: props.textOnly, visitor: new ReactFormVisitor(), onFieldValueChange: (e, key) => { onFieldValueChange(e, key); @@ -81,7 +82,7 @@ const ConcertoForm = (props) => { removeElement(e, key, index); }, ...options, - }), [addElement, onFieldValueChange, removeElement, options, props.readOnly]); + }), [addElement, onFieldValueChange, removeElement, options, props.readOnly, props.textOnly]); const generator = React.useMemo(() => { if (modelManager) { @@ -184,6 +185,7 @@ ConcertoForm.defaultProps = { onValueChange: () => true, options: {}, readOnly: false, + textOnly: false, style: {} }; @@ -194,6 +196,7 @@ ConcertoForm.propTypes = { onValueChange: PropTypes.func.isRequired, options: PropTypes.object, readOnly: PropTypes.bool, + textOnly: PropTypes.bool, style: PropTypes.object }; diff --git a/packages/ui-concerto/src/components/concertoModelBuilder.js b/packages/ui-concerto/src/components/concertoModelBuilder.js index aa24e12..9f3dfda 100644 --- a/packages/ui-concerto/src/components/concertoModelBuilder.js +++ b/packages/ui-concerto/src/components/concertoModelBuilder.js @@ -39,6 +39,7 @@ ConcertoModelBuilder.propTypes = { onValueChange: PropTypes.func.isRequired, options: PropTypes.shape(), readOnly: PropTypes.bool, + textOnly: PropTypes.bool, }; export default ConcertoModelBuilder; diff --git a/packages/ui-concerto/src/components/fields.js b/packages/ui-concerto/src/components/fields.js index 7ab772a..b81469e 100644 --- a/packages/ui-concerto/src/components/fields.js +++ b/packages/ui-concerto/src/components/fields.js @@ -25,6 +25,7 @@ export const ConcertoCheckbox = ({ id, field, readOnly, + textOnly, required, value, onFieldValueChange, @@ -38,6 +39,7 @@ export const ConcertoCheckbox = ({ fitted id={id} readOnly={readOnly} + disabled={textOnly} checked={value} onChange={(e, data) => onFieldValueChange(data, id)} key={`checkbox-${id}`} @@ -49,6 +51,7 @@ export const ConcertoInput = ({ id, field, readOnly, + textOnly, required, value, onFieldValueChange, @@ -67,6 +70,7 @@ export const ConcertoInput = ({ } return + {!textOnly ? ( + ) : ( +
+ +
+ )}
; }; @@ -86,6 +97,7 @@ export const ConcertoRelationship = ({ id, field, readOnly, + textOnly, required, value, onFieldValueChange, @@ -105,6 +117,7 @@ export const ConcertoRelationship = ({ id, field, readOnly, + textOnly, required, value, onFieldValueChange, @@ -119,6 +132,8 @@ export const ConcertoRelationship = ({ ? {normalizeLabel(relationship.getType())}} labelPosition='right' readOnly={readOnly} + textOnly={textOnly} value={relationship.getIdentifier()} onChange={(e, data) => { relationship.setIdentifier(data.value || 'resource1'); @@ -173,6 +189,7 @@ export const ConcertoArray = ({ id, field, readOnly, + textOnly, required, children, addElement, @@ -180,6 +197,7 @@ export const ConcertoArray = ({ {children} + {!textOnly ? (
+ ) : null} ); export const ConcertoArrayElement = ({ id, readOnly, + textOnly, children, index, removeElement, }) => (
{children}
+ {!textOnly ? (
); export const ConcertoDropdown = ({ id, readOnly, + textOnly, + displayText, value, text, onFieldValueChange, options, -}) => !readOnly ? ( - - ); +}) => { + if (readOnly) { + return ( + + ); + } else if (textOnly) { + return ( +
+ +
+ ); + } else { + return ( +