Skip to content

Commit 6f14ae5

Browse files
refactor(Form): use grid layout (#576)
BREAKING CHANGE: deleted `CurrentViewportRange` (mostly used internally) BREAKING CHANGE: `FormGroup` and `FormItem` don't support `className`, `style`, `ref`, ..etc. props anymore, there are only used for calculating the final form layout. Closes #564
1 parent 073edd3 commit 6f14ae5

File tree

12 files changed

+582
-861
lines changed

12 files changed

+582
-861
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@
116116
},
117117
"lint-staged": {
118118
"*.{js,jsx,ts,tsx}": [
119-
"prettier -config ./prettier.config.js --write",
120-
"git add"
119+
"prettier -config ./prettier.config.js --write"
120+
],
121+
"*.mdx": [
122+
"prettier -config ./prettier.config.js --write --parser mdx"
121123
]
122124
}
123125
}

packages/main/src/components/Form/CurrentViewportRangeContext.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/main/src/components/Form/Form.jss.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { ThemingParameters } from '@ui5/webcomponents-react-base/lib/ThemingParameters';
22

33
const styles = {
4+
form: {
5+
display: 'grid',
6+
alignItems: 'center',
7+
rowGap: '0.5rem',
8+
columnGap: '0.25rem',
9+
gridTemplateColumns: `repeat(12, 1fr)`,
10+
'--ui5wcr_form_full_span': 'span 12',
11+
'--ui5wcr_form_label_text_align': 'end'
12+
},
413
formTitle: {
514
borderBottom: `1px solid ${ThemingParameters.sapGroup_TitleBorderColor}`,
6-
marginBottom: '2rem'
15+
marginBottom: '1.75rem',
16+
gridColumn: 'var(--ui5wcr_form_full_span)'
717
}
818
};
919

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Title, Subtitle, Description, Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
2+
import { CheckBox } from '@ui5/webcomponents-react/lib/CheckBox';
3+
import { Form } from '@ui5/webcomponents-react/lib/Form';
4+
import { FormGroup } from '@ui5/webcomponents-react/lib/FormGroup';
5+
import { FormItem } from '@ui5/webcomponents-react/lib/FormItem';
6+
import { Input } from '@ui5/webcomponents-react/lib/Input';
7+
import { InputType } from '@ui5/webcomponents-react/lib/InputType';
8+
import { Option } from '@ui5/webcomponents-react/lib/Option';
9+
import { Select } from '@ui5/webcomponents-react/lib/Select';
10+
import { Label } from '@ui5/webcomponents-react/lib/Label';
11+
12+
<Meta title="Components / Form" component={Form} subcomponents={{ FormGroup, FormItem }} />
13+
14+
<Title />
15+
16+
```js
17+
import { Form } from '@ui5/webcomponents-react/lib/Form';
18+
```
19+
20+
<Preview>
21+
<Story name="Default">
22+
<Form title={'Test Form'}>
23+
<FormGroup title={'Personal Data'}>
24+
<FormItem label={'Name'}>
25+
<Input type={InputType.Text} />
26+
</FormItem>
27+
<FormItem label={<Label>Address</Label>}>
28+
<Input type={InputType.Text} />
29+
</FormItem>
30+
<FormItem label={'Country'}>
31+
<Select>
32+
<Option>Germany</Option>
33+
<Option>France</Option>
34+
<Option>Italy</Option>
35+
</Select>
36+
</FormItem>
37+
<FormItem label={'Home address'}>
38+
<CheckBox checked />
39+
</FormItem>
40+
</FormGroup>
41+
<FormItem label={'Sole Form Item'}>
42+
<Input type={InputType.Text} />
43+
</FormItem>
44+
<FormGroup title={'Company Data'}>
45+
<FormItem label={'Company Name'}>
46+
<Input type={InputType.Text} />
47+
</FormItem>
48+
<FormItem label={'Company Address'}>
49+
<Input type={InputType.Text} />
50+
</FormItem>
51+
<FormItem label={'Company City'}>
52+
<Input type={InputType.Text} />
53+
</FormItem>
54+
<FormItem label={'Company Country'}>
55+
<Input type={InputType.Text} />
56+
</FormItem>
57+
<FormItem label={'Number of Employees'}>
58+
<Input type={InputType.Number} value={'5000'} disabled />
59+
</FormItem>
60+
<FormItem label={'Member of Partner Network'}>
61+
<CheckBox checked />
62+
</FormItem>
63+
</FormGroup>
64+
<FormGroup title={'Marketing Data'}>
65+
<FormItem label={'Email'}>
66+
<Input type={InputType.Email} />
67+
</FormItem>
68+
<FormItem label="Company Email">
69+
<Input type={InputType.Email} />
70+
</FormItem>
71+
<FormItem label="I want to receive the newsletter">
72+
<CheckBox />
73+
</FormItem>
74+
</FormGroup>
75+
</Form>
76+
</Story>
77+
</Preview>
78+
79+
### Usage Notes
80+
81+
Please note that the `FormGroup` and `FormItem` components are only used for calculating the final layout of the `Form`,
82+
thus they don't accept any other props then the specified ones, especially no `className`, `style` or `ref`.
83+
84+
<Props components={{ Form, FormGroup, FormItem }} />

packages/main/src/components/Form/Form.stories.tsx

Lines changed: 0 additions & 56 deletions
This file was deleted.

packages/main/src/components/Form/Form.test.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,6 @@ describe('Create a Form', () => {
5858
expect(wrapper.render()).toMatchSnapshot();
5959
});
6060

61-
test('should create a FormGroup and put ungrouped FormItems into it', () => {
62-
const ungroupedChildren = (
63-
<Form title={'Test form'}>
64-
<FormItem label={'item 1'}>
65-
<Input type={InputType.Text} />
66-
</FormItem>
67-
<FormItem label={'item 2'}>
68-
<Input type={InputType.Number} />
69-
</FormItem>
70-
</Form>
71-
);
72-
const wrapper = mount(ungroupedChildren);
73-
expect(wrapper.render()).toMatchSnapshot();
74-
});
75-
7661
test("should use a single FormGroup's title as a Form title if one is not set", () => {
7762
const ungroupedChildren = (
7863
<Form>

0 commit comments

Comments
 (0)