Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 1986f1e

Browse files
authored
feat(ui-concerto): add textOnly mode-#13 (#365)
Signed-off-by: TC5022 <[email protected]>
1 parent 72c2300 commit 1986f1e

File tree

8 files changed

+77
-13
lines changed

8 files changed

+77
-13
lines changed

packages/storybook/src/stories/3-ConcertoForm.stories.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default {
1818

1919
export const SimpleExample = () => {
2020
const readOnly = boolean('Read-only', false);
21+
const textOnly = boolean('Text-only', false);
2122
const type = text('Type', 'test.Person');
2223
const options = object('Options', {
2324
includeOptionalFields: true,
@@ -78,6 +79,7 @@ export const SimpleExample = () => {
7879
<div style={{ padding: '10px' }}>
7980
<ConcertoForm
8081
readOnly={readOnly}
82+
textOnly={textOnly}
8183
models={[model]}
8284
options={options}
8385
type={type}
@@ -91,6 +93,7 @@ export const SimpleExample = () => {
9193

9294
export const ModelBuilder = () => {
9395
const readOnly = boolean('Read-only', false);
96+
const textOnly = boolean('Text-only', false);
9497
const type = text('Type', 'concerto.metamodel.ModelFile');
9598
const options = object('Options', {
9699
includeOptionalFields: false,
@@ -130,6 +133,7 @@ export const ModelBuilder = () => {
130133
<div style={{ padding: '10px' }}>
131134
<ConcertoModelBuilder
132135
readOnly={readOnly}
136+
textOnly={textOnly}
133137
options={options}
134138
type={type}
135139
json={json}

packages/ui-concerto/src/components/concertoForm.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
margin-bottom: 0;
6060
}
6161

62+
.textOnly > label{
63+
font-weight: 300;
64+
color: #2f4f4f;
65+
font-size: small;
66+
}
67+
6268
/** CSS Classes for use by the ModelBuilderVisitor */
6369
.mbFieldDeclaration {
6470
display: grid;

packages/ui-concerto/src/components/concertoForm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const ConcertoForm = (props) => {
7070
includeOptionalFields: true,
7171
includeSampleData: 'sample',
7272
disabled: props.readOnly,
73+
textOnly: props.textOnly,
7374
visitor: new ReactFormVisitor(),
7475
onFieldValueChange: (e, key) => {
7576
onFieldValueChange(e, key);
@@ -81,7 +82,7 @@ const ConcertoForm = (props) => {
8182
removeElement(e, key, index);
8283
},
8384
...options,
84-
}), [addElement, onFieldValueChange, removeElement, options, props.readOnly]);
85+
}), [addElement, onFieldValueChange, removeElement, options, props.readOnly, props.textOnly]);
8586

8687
const generator = React.useMemo(() => {
8788
if (modelManager) {
@@ -184,6 +185,7 @@ ConcertoForm.defaultProps = {
184185
onValueChange: () => true,
185186
options: {},
186187
readOnly: false,
188+
textOnly: false,
187189
style: {}
188190
};
189191

@@ -194,6 +196,7 @@ ConcertoForm.propTypes = {
194196
onValueChange: PropTypes.func.isRequired,
195197
options: PropTypes.object,
196198
readOnly: PropTypes.bool,
199+
textOnly: PropTypes.bool,
197200
style: PropTypes.object
198201
};
199202

packages/ui-concerto/src/components/concertoModelBuilder.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ConcertoModelBuilder.propTypes = {
3939
onValueChange: PropTypes.func.isRequired,
4040
options: PropTypes.shape(),
4141
readOnly: PropTypes.bool,
42+
textOnly: PropTypes.bool,
4243
};
4344

4445
export default ConcertoModelBuilder;

packages/ui-concerto/src/components/fields.js

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const ConcertoCheckbox = ({
2525
id,
2626
field,
2727
readOnly,
28+
textOnly,
2829
required,
2930
value,
3031
onFieldValueChange,
@@ -38,6 +39,7 @@ export const ConcertoCheckbox = ({
3839
fitted
3940
id={id}
4041
readOnly={readOnly}
42+
disabled={textOnly}
4143
checked={value}
4244
onChange={(e, data) => onFieldValueChange(data, id)}
4345
key={`checkbox-${id}`}
@@ -49,6 +51,7 @@ export const ConcertoInput = ({
4951
id,
5052
field,
5153
readOnly,
54+
textOnly,
5255
required,
5356
value,
5457
onFieldValueChange,
@@ -67,6 +70,7 @@ export const ConcertoInput = ({
6770
}
6871
return <Form.Field key={`field-${id}`} required={required} error={error}>
6972
<ConcertoLabel key={`label-${id}`} skip={skipLabel} name={applyDecoratorTitle(field)} htmlFor={id} />
73+
{!textOnly ? (
7074
<Input
7175
id={id}
7276
type={type}
@@ -79,13 +83,21 @@ export const ConcertoInput = ({
7983
}
8084
key={`input-${id}`}
8185
/>
86+
) : (
87+
<div className='textOnly'>
88+
<label value={value} key={`input-${id}`} >
89+
{value}
90+
</label>
91+
</div>
92+
)}
8293
</Form.Field>;
8394
};
8495

8596
export const ConcertoRelationship = ({
8697
id,
8798
field,
8899
readOnly,
100+
textOnly,
89101
required,
90102
value,
91103
onFieldValueChange,
@@ -105,6 +117,7 @@ export const ConcertoRelationship = ({
105117
id,
106118
field,
107119
readOnly,
120+
textOnly,
108121
required,
109122
value,
110123
onFieldValueChange,
@@ -119,6 +132,8 @@ export const ConcertoRelationship = ({
119132
? <ConcertoDropdown
120133
id={id}
121134
value={value}
135+
displayText={value}
136+
textOnly={textOnly}
122137
readOnly={readOnly}
123138
onFieldValueChange={onFieldValueChange}
124139
options={relationshipOptions}
@@ -129,6 +144,7 @@ export const ConcertoRelationship = ({
129144
label={<Label basic>{normalizeLabel(relationship.getType())}</Label>}
130145
labelPosition='right'
131146
readOnly={readOnly}
147+
textOnly={textOnly}
132148
value={relationship.getIdentifier()}
133149
onChange={(e, data) => {
134150
relationship.setIdentifier(data.value || 'resource1');
@@ -173,13 +189,15 @@ export const ConcertoArray = ({
173189
id,
174190
field,
175191
readOnly,
192+
textOnly,
176193
required,
177194
children,
178195
addElement,
179196
}) => (
180197
<Form.Field key={`field-${id}`} required={required}>
181198
<ConcertoLabel name={applyDecoratorTitle(field)} />
182199
{children}
200+
{!textOnly ? (
183201
<div className="arrayElement grid">
184202
<div />
185203
<Button
@@ -198,18 +216,21 @@ export const ConcertoArray = ({
198216
}}
199217
/>
200218
</div>
219+
) : null}
201220
</Form.Field>
202221
);
203222

204223
export const ConcertoArrayElement = ({
205224
id,
206225
readOnly,
226+
textOnly,
207227
children,
208228
index,
209229
removeElement,
210230
}) => (
211231
<div className="arrayElement grid" key={`array-${id}`}>
212232
<div key={`array-children-${id}`}>{children}</div>
233+
{!textOnly ? (
213234
<Button
214235
icon={<Popup
215236
content='Remove this element'
@@ -226,28 +247,46 @@ export const ConcertoArrayElement = ({
226247
}}
227248
key={`array-btn-${id}`}
228249
/>
250+
) : null}
229251
</div>
230252
);
231253

232254
export const ConcertoDropdown = ({
233255
id,
234256
readOnly,
257+
textOnly,
258+
displayText,
235259
value,
236260
text,
237261
onFieldValueChange,
238262
options,
239-
}) => !readOnly ? (
240-
<Select
241-
clearable
242-
fluid
243-
value={value}
244-
onChange={(e, data) => onFieldValueChange(data, id)}
245-
key={`select-${id}`}
246-
options={options}
247-
/>
248-
) : (
249-
<Input type="text" readOnly value={text} key={`input-${id}`} />
250-
);
263+
}) => {
264+
if (readOnly) {
265+
return (
266+
<Input type="text" readOnly value={displayText} key={`input-${id}`} />
267+
);
268+
} else if (textOnly) {
269+
return (
270+
<div className="textOnly">
271+
<label value={displayText} key={`input-${id}`}>
272+
{" "}
273+
{displayText}{" "}
274+
</label>
275+
</div>
276+
);
277+
} else {
278+
return (
279+
<Select
280+
clearable
281+
fluid
282+
value={value}
283+
onChange={(e, data) => onFieldValueChange(data, id)}
284+
key={`select-${id}`}
285+
options={options}
286+
/>
287+
);
288+
}
289+
}
251290

252291
const BinaryField = ({ className, children }) => (
253292
<div className={className}>

packages/ui-concerto/src/formgenerator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class FormGenerator {
3434
* 'sample' uses random well-typed values
3535
* 'empty' provides sensible empty values
3636
* @param {object} options.disabled - if true, all form fields will be disabled
37+
* @param {object} options.textOnly - if true, all form fields will appear as labels
3738
* @param {object} options.visitor - a class that extends HTMLFormVisitor
3839
* that generates HTML, defaults to HTMLFormVisitor
3940
* @param {object} options.customClasses - a custom CSS classes that can be

packages/ui-concerto/src/modelBuilderVisitor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class ModelBuilderVisitor extends ReactFormVisitor {
169169
key={key}
170170
value={value.$class}
171171
text={altText ? altText.text : value.$class}
172+
displayText={altText ? altText.text : value.$class}
173+
textOnly={parameters.textOnly}
172174
readOnly={parameters.disabled}
173175
onFieldValueChange={onFieldValueChange}
174176
options={declarationTypes.map(({ value, text }) => ({

packages/ui-concerto/src/reactformvisitor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ class ReactFormVisitor {
196196
id={key}
197197
key={`enum-${key}`}
198198
value={value}
199+
displayText={value}
199200
field={enumDeclaration}
200201
readOnly={parameters.disabled}
202+
textOnly={parameters.textOnly}
201203
onFieldValueChange={parameters.onFieldValueChange}
202204
options={enumDeclaration.getProperties().map(property => ({
203205
key: `option-${property.getName()}`,
@@ -219,6 +221,7 @@ class ReactFormVisitor {
219221
const {
220222
skipLabel,
221223
disabled,
224+
textOnly,
222225
addElement,
223226
removeElement,
224227
onFieldValueChange,
@@ -242,6 +245,7 @@ class ReactFormVisitor {
242245
type: toFieldType(field.getType()),
243246
required: !field.isOptional(),
244247
readOnly: disabled,
248+
textOnly: textOnly,
245249
addElement,
246250
removeElement,
247251
onFieldValueChange,
@@ -315,6 +319,8 @@ class ReactFormVisitor {
315319
id={key}
316320
key={`select-${key}`}
317321
value={value}
322+
displayText={value}
323+
textOnly={parameters.textOnly}
318324
readOnly={parameters.disabled}
319325
onFieldValueChange={parameters.onFieldValueChange}
320326
options={options.map(({ value, text }) => ({
@@ -357,6 +363,7 @@ class ReactFormVisitor {
357363
const {
358364
skipLabel,
359365
disabled,
366+
textOnly,
360367
addElement,
361368
removeElement,
362369
onFieldValueChange,
@@ -380,6 +387,7 @@ class ReactFormVisitor {
380387
type: 'text',
381388
required: !relationship.isOptional(),
382389
readOnly: disabled,
390+
textOnly: textOnly,
383391
addElement,
384392
removeElement,
385393
onFieldValueChange,

0 commit comments

Comments
 (0)