Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui5-form): introduce Form web component #8281

Merged
merged 51 commits into from May 16, 2024
Merged

feat(ui5-form): introduce Form web component #8281

merged 51 commits into from May 16, 2024

Conversation

ilhan007
Copy link
Member

@ilhan007 ilhan007 commented Feb 13, 2024

The change introduces several components - Form, FormGroup and FormItem to build application forms easier and according to latest design guidelines.

Overview

The Form is a layout component that arranges labels and form fields (like input fields) pairs
into specific number of columns.

Structure

  • Form is the top-level container component, responsible for the content layout and the responsiveness.
  • FormGroup (ui5-form-group) enables the grouping of the Form content.
  • FormItem (ui5-form-item) is a pair of label and form field.

The simplest Form consists of a header area on top, displaying a header text and content below - arbitrary number of FormItems, representing the pairs of label and form field.

Screenshot 2024-02-13 at 19 44 11

And, there is also "grouping", enabled by the FormGroup component.


Screenshot 2024-02-14 at 9 30 55

Responsiveness

The Form component reacts and changes its layout on predefined breakpoints.
Depending on its size, the Form content (FormGroups and FormItems) gets divided into one or more columns as follows:

  • S (< 600px) – 1 column
  • M (600px - 1022px) – up to 2 columns are recommended (default: 1)
  • L (1023px - 1439px) - up to 3 columns are recommend (default: 2)
  • XL (> 1439px) – up to 6 columns are recommend (default: 2)

To change the layout, use the layout property - f.e. layout="S1 M2 L3 XL6".
Note: there is no restriction of the column numbers (f.e you can specify XL9 and get the layout divided in to 9 columns), however recommendations are based on our experience to best suite known use-cases.

Form Groups Distribution

To make better use of screen space, there is built-in logic to calculate how many columns should a FormGroup occupy.

  • Example 1 (perfect match): 4 columns and 4 groups: each group will use 1 column.
  • Example 2 (balanced distribution): 4 columns and 2 groups: each group will use 2 columns.
  • Example 3 (unbalanced distribution): 3 columns and 2 groups: the larger one will use 2 columns, the smaller 1 column.
    Note: The size of a group element is determined by the number of FormItems assigned to it.
    In case of equality, the first in the DOM will use more columns and the last - less columns.
  • Example 4 (more groups than columns): 3 columns and 4 groups: each FormGroup uses only 1 column, the last FormGroup will wrap on the second row.

Form Group column-span

To influence the built-in group distribution, you can use the FormGroup's columnSpan property,
that defines how many columns the group should expand to.

Form Item's Label Placement

By default, the labels take 4/12 of the FormItem, leaving 8/12 parts to associated fields.
You can control what space the labels should take via the labelSpan property
For example:

  • To always place the labels on top set: labelSpan="S12 M12 L12 XL12".
  • To make the label take half of the item set: labelSpan="S6 M6 L6 XL6".

API

Form

props

  • layout!: string; // "S1 M2 L4 XL6"
  • labelSpan!: string; // "S12 M4 L4 XL4"
  • headerText!: string; // "Address Form"
  • itemSpacing!: FormItemSpacing; // "Normal" | "Large"

slots

  • header!: Array;
  • items!: Array<FormItem | FormGroup>;
<ui5-form header-text="Address" layout="S1 M2 L4 XL6" label-span="S12 M4 L4 XL4" item-spacing="Large">
  <ui5-form-group>
    <ui5-form-item>
      <ui5-label slot="labelContent">Name:</ui5-label>
      <ui5-text>Red Point Stores</ui5-text>
    </ui5-form-item>
  </ui5-form-group>
</ui5-form>

Form Group

props

  • headerText!: string; // "Contact Info"
  • columnSpan!: number; // 2

slots

  • items!: Array;
<ui5-form-group header-text="Contact Info" column-span="2">
  <ui5-form-item>
    <ui5-label slot="labelContent">Name:</ui5-label>
     <ui5-text>Red Point Stores</ui5-text>
  </ui5-form-item>
					
  <ui5-form-item>
    <ui5-label slot="labelContent">ZIPCode/City:</ui5-label>
    <ui5-text>411 Maintown</ui5-text>
  </ui5-form-item>
					
  <ui5-form-item>
    <ui5-label slot="labelContent">Street:</ui5-label>
    <ui5-text>Main St 1618</ui5-text>
  </ui5-form-item>
</ui5-form-group>

Form Item

slots

  • labelContent!: Array;
  • content!: Array;
<ui5-form-item>
   <ui5-label slot="labelContent">Name:</ui5-label>
   <ui5-text>Red Point Stores</ui5-text>
</ui5-form-item>

Test Pages

Screenshot 2024-02-14 at 10 29 58

Fixes: #7854

@ilhan007 ilhan007 changed the title feat: introduce Form component feat(ui5-form): introduce Form web component Feb 13, 2024
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/types/FormItemSpacing.ts Show resolved Hide resolved
Copy link
Contributor

@nnaydenow nnaydenow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check why the breakpoint is not changed on the corresponding sizes? S breakpoint starts from around 630px when it has to start from 600<

packages/main/src/FormItem.ts Outdated Show resolved Hide resolved
packages/main/src/FormItem.ts Outdated Show resolved Hide resolved
@ilhan007 ilhan007 requested a review from nnaydenow May 13, 2024 16:05
packages/main/src/FormGroup.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
packages/main/src/FormItem.ts Outdated Show resolved Hide resolved
packages/main/src/FormItem.ts Outdated Show resolved Hide resolved
packages/main/src/Form.ts Outdated Show resolved Hide resolved
@ilhan007 ilhan007 requested a review from nnaydenow May 15, 2024 11:33
* @public
*/
@property({ type: FormItemSpacing, defaultValue: FormItemSpacing.Normal })
itemSpacing!: FormItemSpacing;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: use template literals for properties of type enum. also applying for form item and form group item.

@ilhan007 ilhan007 merged commit 8d72042 into main May 16, 2024
10 checks passed
@ilhan007 ilhan007 deleted the feat-form branch May 16, 2024 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: new Form web component
2 participants