koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
538 stars 154 forks source link

improve layout management #293

Open albanm opened 2 years ago

albanm commented 2 years ago

Disclaimer: this is a draft, the described changes are important and must not be rushed.

Motivation

The doc says "Structure and presentation are coupled. Meaning that the rendering of the form is derived directly from the schema (as well as a few global options) and you will need to change the schema in order to modify a label, create a section, etc.". This is starting to be too much of a limitation, it is time to move past this position.

Some related issues:

Design of the layout object

A few global objectives:

Simple ordering of properties

['prop1', 'oneOf', 'prop2', 'allOf-0', 'allOf-1']

Rendering of lines

[
  'allOf-0'
  ['prop1', 'prop2],
  'allOf-1'
]

Responsive rendering

{
  xs: ['prop1', 'prop2', 'allOf-0'],
  md: [['prop1', 'prop2'], 'allOf-0'],
  lg: [[{key: 'prop1', cols: 4}, 'prop2'], 'allOf-0']
}

Containing additional info

[{key: 'prop1', display: 'switch', slots: {before: 'lorem ipsum'}}, 'prop2']

TODO: describe switching layout based on context (edit / readOnly / array item)

TODO: describe sections, tabs, etc.

Automatic layout

We should add an option layoutMode to control the creation of the layout when it is not explicitly given by the user.

Assisting layout edition

The layout object will be quite complex and it needs to be perfectly coherent with the schema. The complexity of maintaining these complex json documents side by side is one of the reasons I avoided this approach until now. Here is a proposal to help users manage this complexity:

yaffol commented 2 years ago

This would be a really good addition to the library.

I like the idea of having multiple options to control the layout, and having a 'layout object' that controls the specification of the layout gives the flexibility to hook into that if needed, or have it be auto generated.

My biggest use case for this is where people or projects come along with existing JSON Schemas, and want them represented as forms. In many cases, the schemas have been designed with some view towards usablity (or are structured in a way that makes sense when filling the form already) and so, they expect the form fields to be laid out 'as they are in the schema'.

This includes sections, nested sections etc. Sometimes these forms can get a bit unwieldy, but that's more of a usability question, and one that can be solved by working on the layout (thank you, layout object!) or breaking up the schema into sections more appropriate to forms (which is a concern above the library).

I think the ability to make the form responsive based on the space it was given would be good, or for that to be a configurable option (either 'size I've been given' or 'based on full screen width').

A separate option for laying out the form for editing vs reading is a VERY good idea.