Skip to content

Commit

Permalink
refactor(ui5-form): change default columns number in XL and header te…
Browse files Browse the repository at this point in the history
…xt wrapping (#10031)

Updates the Form web component to latest UX design:
1. New default layout
2. Header text wrapping

Related to: #9963
  • Loading branch information
ilhan007 authored and kgogov committed Oct 30, 2024
1 parent e746537 commit 4434d4c
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 30 deletions.
52 changes: 52 additions & 0 deletions packages/main/cypress/specs/Form.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,58 @@ import "../../src/FormItem.js";
import "../../src/FormGroup.js";

describe("General API", () => {
it("tests calculated state of Form with default layout and label-span", () => {
cy.mount(html`<ui5-form class="addressForm" header-text="Default form">
<ui5-form-group header-text="Address">
<ui5-form-item>
<span slot="labelContent">Name:</span>
<span class="text">Red Point Stores</span>
</ui5-form-item>
</ui5-form-group>
<ui5-form-group id="testFormGroup2" header-text="Contact">
<ui5-form-item>
<span slot="labelContent">Twitter:</span>
<span class="text">@sap</span>
</ui5-form-item>
</ui5-form-group>
<ui5-form-group id="testFormGroup3" header-text="Other info">
<ui5-form-item>
<span slot="labelContent">Name:</span>
<span class="text">Red Point Stores</span>
</ui5-form-item>
</ui5-form-group>
</ui5-form>`);

cy.get("[ui5-form]")
.as("form");

cy.get("@form")
.should("have.prop", "columnsS", 1);

cy.get("@form")
.should("have.prop", "labelSpanS", 12);

cy.get("@form")
.should("have.prop", "columnsM", 1);

cy.get("@form")
.should("have.prop", "labelSpanM", 4);

cy.get("@form")
.should("have.prop", "columnsL", 2);

cy.get("@form")
.should("have.prop", "labelSpanL", 4);

cy.get("@form")
.should("have.prop", "columnsXl", 3);

cy.get("@form")
.should("have.prop", "labelSpanXl", 4);
});

it("tests calculated state of Form with layout='S1 M2 L3 XL6' and label-span='S12 M4 L4 XL4'", () => {
cy.mount(html`<ui5-form class="addressForm" header-text="WebC :: Supplier 3gr (S1 M2 L3 XL6)" layout="S1 M2 L3 XL6">
<ui5-form-group header-text="Address">
Expand Down
10 changes: 5 additions & 5 deletions packages/main/src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type ItemsInfo = {
* - **S** (< 600px) – 1 column is recommended (default: 1)
* - **M** (600px - 1022px) – up to 2 columns are recommended (default: 1)
* - **L** (1023px - 1439px) - up to 3 columns are recommended (default: 2)
* - **XL** (> 1439px) – up to 6 columns are recommended (default: 2)
* - **XL** (> 1439px) – up to 6 columns are recommended (default: 3)
*
* To change the layout, use the `layout` property - f.e. layout="S1 M2 L3 XL6".
*
Expand Down Expand Up @@ -156,13 +156,13 @@ class Form extends UI5Element {
* - `S` - 1 column by default (1 column is recommended)
* - `M` - 1 column by default (up to 2 columns are recommended)
* - `L` - 2 columns by default (up to 3 columns are recommended)
* - `XL` - 2 columns by default (up to 6 columns are recommended)
* - `XL` - 3 columns by default (up to 6 columns are recommended)
*
* @default "S1 M1 L2 XL2"
* @default "S1 M1 L2 XL3"
* @public
*/
@property()
layout = "S1 M1 L2 XL2"
layout = "S1 M1 L2 XL3"

/**
* Defines the width proportion of the labels and fields of a FormItem by breakpoint.
Expand Down Expand Up @@ -246,7 +246,7 @@ class Form extends UI5Element {
labelSpanL = 4;

@property({ type: Number })
columnsXl = 2;
columnsXl = 3;
@property({ type: Number })
labelSpanXl = 4;

Expand Down
1 change: 1 addition & 0 deletions packages/main/src/FormGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class FormGroup extends UI5Element implements IFormItem {
@property()
itemSpacing: `${FormItemSpacing}` = "Normal";

@property()
labelSpan = "S12 M4 L4 XL4";

onBeforeRendering() {
Expand Down
5 changes: 3 additions & 2 deletions packages/main/src/themes/Form.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

.ui5-form-header {
display: flex;
height: 2.75rem;
min-height: 2.75rem;
align-items: center;
border-bottom: 1px solid var(--sapGroup_TitleBorderColor);
padding: 0 1rem 0 1rem;
padding: 0.875rem 1rem;
box-sizing: border-box;
}

.ui5-form-layout {
Expand Down
6 changes: 3 additions & 3 deletions packages/main/src/themes/FormLayout.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* The Form layout is divided into one or more columns.
* XL - max. 4 columns, L - max. 3 columns, M - max. 2 columns and S - 1 column.
* XL - max. 6 columns, L - max. 3 columns, M - max. 2 columns and S - 1 column.
*/
/*
* S max-width: 600px - container padding 24px
Expand Down Expand Up @@ -76,10 +76,10 @@
}
}

/* XL - 2 columns by default, up to 6 */
/* XL - 3 columns by default, up to 6 */
@container (min-width: 1441px) {
.ui5-form-layout {
grid-template-columns: repeat(2, 1fr);
grid-template-columns: repeat(3, 1fr);
}

:host([columns-xl="1"]) .ui5-form-layout {
Expand Down
8 changes: 4 additions & 4 deletions packages/main/test/pages/form/FormGroups3.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<script>
sap.ui.getCore().attachInit(function() {
var oLayout1 = new sap.ui.layout.form.ColumnLayout("L1", {
// columnsM: 2,
// columnsL: 3,
// columnsXL: 4,
columnsM: 1,
columnsL: 2,
columnsXL: 3,
});
var oForm1 = new sap.ui.layout.form.Form("F1",{
title: "SAPUI5 Form :: Supplier",
Expand Down Expand Up @@ -127,8 +127,8 @@
<div class="controls">
<ui5-label>Column Layout:</ui5-label>
<ui5-select id="selLayout">
<ui5-option selected value="S1 M2 L2 XL2">S1 M1 L2 XL2</ui5-option>
<ui5-option value="S1 M2 L2 XL2">S1 M2 L2 XL2</ui5-option>
<ui5-option selected value="S1 M1 L2 XL3">S1 M1 L2 XL3</ui5-option>
<ui5-option value="S1 M2 L3 XL2">S1 M2 L3 XL2</ui5-option>
<ui5-option value="S1 M2 L3 XL3">S1 M2 L3 XL3</ui5-option>
<ui5-option value="S1 M2 L3 XL4">S1 M2 L3 XL4</ui5-option>
Expand Down
9 changes: 5 additions & 4 deletions packages/main/test/pages/form/FormGroups4.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<script>
sap.ui.getCore().attachInit(function() {
var oLayout1 = new sap.ui.layout.form.ColumnLayout("L1", {
// columnsM: 2,
// columnsL: 3,
// columnsXL: 4,
columnsM: 1,
columnsL: 2,
columnsXL: 3,
});
var oForm1 = new sap.ui.layout.form.Form("F1",{
title: "SAPUI5 Form :: Supplier",
Expand Down Expand Up @@ -160,7 +160,8 @@
<div class="controls">
<ui5-label>Column Layout:</ui5-label>
<ui5-select id="selLayout">
<ui5-option selected value="S1 M2 L2 XL2">S1 M1 L2 XL2</ui5-option>
<ui5-option value="S1 M2 L2 XL2">S1 M1 L2 XL2</ui5-option>
<ui5-option selected value="S1 M1 L2 XL3">S1 M1 L2 XL3</ui5-option>
<ui5-option value="S1 M2 L2 XL2">S1 M2 L2 XL2</ui5-option>
<ui5-option value="S1 M2 L3 XL2">S1 M2 L3 XL2</ui5-option>
<ui5-option value="S1 M2 L3 XL3">S1 M2 L3 XL3</ui5-option>
Expand Down
9 changes: 5 additions & 4 deletions packages/main/test/pages/form/FormGroups5.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<script>
sap.ui.getCore().attachInit(function() {
var oLayout1 = new sap.ui.layout.form.ColumnLayout("L1", {
// columnsM: 2,
// columnsL: 3,
// columnsXL: 4,
columnsM: 1,
columnsL: 2,
columnsXL: 3,
});
var oForm1 = new sap.ui.layout.form.Form("F1",{
title: "SAPUI5 :: Supplier",
Expand Down Expand Up @@ -351,7 +351,8 @@
<div class="controls">
<ui5-label>Column Layout:</ui5-label>
<ui5-select id="selLayout">
<ui5-option selected value="S1 M2 L2 XL2">S1 M1 L2 XL2</ui5-option>
<ui5-option value="S1 M2 L2 XL2">S1 M1 L2 XL2</ui5-option>
<ui5-option selected value="S1 M1 L2 XL3">S1 M1 L2 XL3</ui5-option>
<ui5-option value="S1 M2 L2 XL2">S1 M2 L2 XL2</ui5-option>
<ui5-option value="S1 M2 L3 XL2">S1 M2 L3 XL2</ui5-option>
<ui5-option value="S1 M2 L3 XL3">S1 M2 L3 XL3</ui5-option>
Expand Down
9 changes: 5 additions & 4 deletions packages/main/test/pages/form/FormGroups6.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<script>
sap.ui.getCore().attachInit(function() {
var oLayout1 = new sap.ui.layout.form.ColumnLayout("L1", {
// columnsM: 2,
// columnsL: 3,
// columnsXL: 4,
columnsM: 1,
columnsL: 2,
columnsXL: 3,
});
var oForm1 = new sap.ui.layout.form.Form("F1",{
title: "SAPUI5 Form :: Supplier",
Expand Down Expand Up @@ -218,7 +218,8 @@
<div class="controls">
<ui5-label>Column Layout:</ui5-label>
<ui5-select id="selLayout">
<ui5-option selected value="S1 M2 L2 XL2">S1 M1 L2 XL2</ui5-option>
<ui5-option value="S1 M2 L2 XL2">S1 M1 L2 XL2</ui5-option>
<ui5-option selected value="S1 M1 L2 XL3">S1 M1 L2 XL3</ui5-option>
<ui5-option value="S1 M2 L2 XL2">S1 M2 L2 XL2</ui5-option>
<ui5-option value="S1 M2 L3 XL2">S1 M2 L3 XL2</ui5-option>
<ui5-option value="S1 M2 L3 XL3">S1 M2 L3 XL3</ui5-option>
Expand Down
55 changes: 55 additions & 0 deletions packages/main/test/pages/form/FormHeaderWrapping.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Form Header Text Wrapping</title>
<script src="../%VITE_BUNDLE_PATH%" type="module"></script>
<link rel="stylesheet" type="text/css" href="../styles/FormLayout.css">

<script id='sap-ui-bootstrap'
src='https://openui5nightly.hana.ondemand.com/resources/sap-ui-core.js'
data-sap-ui-theme='sap_horizon'
data-sap-ui-libs='sap.m, sap.ui.core, sap.ui.layout'
data-sap-ui-preload="async"
></script>
</head>

<body class="bg">
<ui5-slider id="slider" min="1" max="100" value="100" class="slider"></ui5-slider>

<section id="container">
<div class="banner"><div class="banner-inner"></div></div>

<section>
<ui5-form class="addressForm" header-text="Very Very Very Very Very Very Very Very Very Very long long long long long long long long text text text text text text text text text text text text text text text text text for a heading of a Form and it is wrapping">
<ui5-form-item>
<ui5-label slot="labelContent">Name:</ui5-label>
<span class="text">Red Point Stores</span>
</ui5-form-item>

<ui5-form-item>
<ui5-label slot="labelContent">ZIP Code/City:</ui5-label>
<span class="text">411 Maintown</span>
</ui5-form-item>

<ui5-form-item>
<ui5-label slot="labelContent">Street:</ui5-label>
<span class="text">Main St 1618</span>
</ui5-form-item>

<ui5-form-item>
<ui5-label slot="labelContent">Country:</ui5-label>
<span class="text">Germany</span>
</ui5-form-item>
</ui5-form>
</section>
</section>

<script>
slider.addEventListener("ui5-input", function (event) {
container.style.width = event.target.value + '%';
});
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions packages/main/test/pages/form/FormMultipleColumns.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<div class="controls">
<ui5-label>Column Layout:</ui5-label>
<ui5-select id="selLayout">
<ui5-option selected value="S1 M3 L4 XL4">S1 M3 L4 XL4</ui5-option>
<ui5-option selected value="S2 M3 L5 XL5">S2 M3 L5 XL5</ui5-option>
<ui5-option selected value="S2 M3 L5 XL6">S2 M3 L5 XL6</ui5-option>
<ui5-option value="S1 M3 L4 XL4">S1 M3 L4 XL4</ui5-option>
<ui5-option value="S2 M3 L5 XL5">S2 M3 L5 XL5</ui5-option>
<ui5-option value="S2 M3 L5 XL6">S2 M3 L5 XL6</ui5-option>
<ui5-option selected value="S2 M4 L5 XL7">S2 M4 L5 XL7</ui5-option>
<ui5-option value="S2 M3 L6 XL8">S2 M3 L6 XL8</ui5-option>
<ui5-option value="S3 M4 L6 XL8">S3 M4 L6 XL8</ui5-option>
Expand Down
8 changes: 8 additions & 0 deletions packages/website/docs/_components_pages/main/Form/Form.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Layout from "../../../_samples/main/Form/Layout/Layout.md";
import LabelSpan from "../../../_samples/main/Form/LabelSpan/LabelSpan.md";
import LabelsOnTop from "../../../_samples/main/Form/LabelsOnTop/LabelsOnTop.md";
import GroupColumnSpan from "../../../_samples/main/Form/GroupColumnSpan/GroupColumnSpan.md";
import HeaderTextWrapping from "../../../_samples/main/Form/HeaderTextWrapping/HeaderTextWrapping.md";
import ItemColumnSpan from "../../../_samples/main/Form/ItemColumnSpan/ItemColumnSpan.md";
import FreeStyleForm from "../../../_samples/main/Form/FreeStyleForm/FreeStyleForm.md";
import CustomHeader from "../../../_samples/main/Form/CustomHeader/CustomHeader.md";
Expand All @@ -26,6 +27,7 @@ import CustomHeader from "../../../_samples/main/Form/CustomHeader/CustomHeader.
### Layout
Use the Form#**layout** property to define the number of columns to distribute the form content by breakpoint.

- S1 M1 L2 XL3 - 1 cols in S, 1 cols in M, 2 cols in L and 3 cols in XL (default layout)
- S1 M2 L3 XL5 - 1 cols in S, 2 cols in M, 3 cols in L and 5 cols in XL
- S1 M2 L4 XL6 - 1 cols in S, 2 cols in M, 4 cols in L and 6 cols in XL
- S2 M3 L5 XL7 - 2 cols in S, 3 cols in M, 5 cols in L and 7 cols in XL
Expand Down Expand Up @@ -80,6 +82,12 @@ The FormItem#**columnSpan** defines to how many columns the form item should exp
<ItemColumnSpan />


### Header Text Wrapping

The Form header text **is wrapping** when doesn't fit the available space.

<HeaderTextWrapping />

### Custom Header

The Form provides a **header** slot that allows the usage of custom form header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<body style="background-color: var(--sapBackgroundColor);height: 400px">
<!-- playground-fold-end -->

<ui5-form layout="S1 M2 L2 XL2" item-spacing="Large" style="width: 600px;">
<ui5-form layout="S1 M2 L2 XL2" item-spacing="Large" style="width: 800px;">

<ui5-bar design="Subheader" slot="header">
<ui5-title level="H4" slot="startContent">Address</ui5-title>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import html from '!!raw-loader!./sample.html';
import js from '!!raw-loader!./main.js';

<Editor html={html} js={js} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import "@ui5/webcomponents/dist/Form.js";
import "@ui5/webcomponents/dist/FormItem.js";


// The following code is required only for the sample
import "@ui5/webcomponents/dist/Label.js";
import "@ui5/webcomponents/dist/Text.js";
import "@ui5/webcomponents/dist/Slider.js";

const slider = document.getElementById("slider");
const txtLayout = document.getElementById("txtLayout");
const container = document.getElementById("container");

slider.addEventListener("ui5-input", () => {
const width = (slider.value / 100 * 1500);
container.style.width = `${width}px`;
txtLayout.innerHTML = getLayoutByWidth(width);
});

const getLayoutByWidth = (width) => {
if (width > 599 && width <= 1023) {
return "M";
} else if (width >= 1024 && width <= 1439) {
return "L"
} else if (width >= 1440) {
return "XL"
}
return "S";
};
Loading

0 comments on commit 4434d4c

Please sign in to comment.