Skip to content

Commit

Permalink
Reorganize form layouts section
Browse files Browse the repository at this point in the history
- Remove top level link/doc and add more sublevel items

- give described form group its own page

- move compressed forms to this section

- remove "in a popover" example from form rows - compressed forms already have this example and explicitly state non-compressed forms should not be used in popovers

- remove guideline CTA to its own page??
  • Loading branch information
cee-chen committed Dec 13, 2024
1 parent 351bc8f commit d09482b
Show file tree
Hide file tree
Showing 7 changed files with 789 additions and 922 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
link:
type: doc
id: forms_form_layouts
label: Form layouts
position: 1
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
slug: /forms/compressed-forms
slug: /forms/layouts/compressed-forms
id: forms_compressed_forms
sidebar_position: 3
---

# Compressed forms

Also known as **Editor-Style Controls**, compressed forms and controls were specifically created for use when space is at a premium. They are not intended for use when the form is the main objective of the page. They work best in editor-style applications where form controls are being used to create or edit content on the page.
Also known as **editor-style controls**, compressed forms and controls were specifically created for use when space is at a premium. They are not intended for use when the form is the main objective of the page. They work best in editor-style applications where form controls are being used to create or edit content on the page.

:::danger
Do not use compressed and non-compressed form controls in the same form.
Expand Down Expand Up @@ -269,7 +270,7 @@ export default () => {

## Contextual help

When using compressed, horizontal form styles, it is best not to overload the UI with expansive help text. If it's short and part of the validation, use `helpText`. However, if it's an explanation of the control, consider wraping the label with an [**EuiToolTip**](/docs/display/tooltip) and appending the `questionInCircle` icon to it.
When using compressed, horizontal form styles, it is best not to overload the UI with expansive help text. If it's short and part of the validation, use `helpText`. However, if it's an explanation of the control, consider wraping the label with an [**EuiToolTip**](../../../display/tooltip) and appending the `questionInCircle` icon to it.

```tsx interactive
import React from 'react';
Expand Down Expand Up @@ -317,7 +318,7 @@ export default () => (

## In a popover

Always use the compressed version of forms and elements when they exist inside of a [popover](/docs/layout/popover).
Always use the compressed version of forms and elements when they exist inside of a [popover](../../../layout/popover).

```tsx interactive
import React, { useState } from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
---
slug: /forms/layouts/described-groups
id: forms_described_form_group
sidebar_position: 2
---

# Described form groups

Use **EuiDescribedFormGroup** component to create sections of associated form controls and rows. It can also simply be used with one **EuiFormRow** as a way to display additional text next to the field (on mobile, it will revert to being stacked).

Read more about appropriate layout usage of **EuiDescribedFormGroup** in the [forms usage guidelines](../guidelines).

```tsx interactive
import React from 'react';
import {
EuiFieldText,
EuiForm,
EuiFormRow,
EuiDescribedFormGroup,
EuiFilePicker,
EuiRange,
EuiSelect,
EuiLink,
useGeneratedHtmlId,
} from '@elastic/eui';

export default () => {
const describedFormRangeId = useGeneratedHtmlId({
prefix: 'describedFormRange',
});

return (
<EuiForm component="form">
<EuiDescribedFormGroup
title={<h3>Single text field</h3>}
description={
<p>
Descriptions are wrapped in a small, subdued{' '}
<EuiLink href="#/display/text">
<strong>EuiTextBlock</strong>
</EuiLink>
. It can have links or any other type of content. Be sure to wrap
nodes in a paragraph tag.
</p>
}
>
<EuiFormRow label="Text field">
<EuiFieldText name="first" aria-label="Example" />
</EuiFormRow>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup title={<h3>No description</h3>}>
<EuiFormRow label="Text field">
<EuiFieldText name="first" />
</EuiFormRow>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
title={<h3>Multiple fields</h3>}
description="Here are three form rows. The first form row does not have a label."
>
<EuiFormRow
hasEmptyLabelSpace
helpText={<span>This is a help text</span>}
>
<EuiSelect
hasNoInitialSelection
onChange={() => {}}
options={[
{ value: 'option_one', text: 'Option one' },
{ value: 'option_two', text: 'Option two' },
{ value: 'option_three', text: 'Option three' },
]}
aria-label="An example of a form element without a visible label"
/>
</EuiFormRow>

<EuiFormRow label="File picker">
<EuiFilePicker />
</EuiFormRow>

<EuiFormRow label="Range">
<EuiRange
min={0}
value={50}
max={100}
name="range"
id={describedFormRangeId}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
</EuiForm>
);
};
```

### Sizing described form rows

By default, **EuiDescribedFormGroup** has a max-width of 800px for best readability. To expand the group to 100%, add the `fullWidth` prop to this, the **EuiFormRow**, **and** the individual fields.

```tsx interactive
import React, { Fragment } from 'react';
import {
EuiFieldText,
EuiForm,
EuiFormRow,
EuiDescribedFormGroup,
EuiFilePicker,
} from '@elastic/eui';

export default () => {
return (
<EuiForm component="form">
<EuiDescribedFormGroup
fullWidth
title={<h2>Full width</h2>}
description={
<Fragment>
The title and description will grow to fill the left side column at
any width. Be mindful that it doesn&apos;t get too wide.
</Fragment>
}
>
<EuiFormRow
fullWidth
label="Text field"
helpText={
<span>
Be sure to add fullWidth to EuiFormRow and nested fields.
</span>
}
>
<EuiFieldText fullWidth name="first" aria-label="Example" />
</EuiFormRow>

<EuiFormRow fullWidth label="File picker">
<EuiFilePicker fullWidth />
</EuiFormRow>
</EuiDescribedFormGroup>
</EuiForm>
);
};
```

You can also change the ratio of the width of the description column versus the field column. By default it is `'half'`, but you can also change to `'third'` or `'quarter'` which prioritizes the field column. You will most likely still need to apply `fullWidth` to all the components. The description column does have a minimum readable width applied to it so that it cannot shrink too far.

Both the description and field columns are simply **EuiFlexItem** wrappers. If you need more customization of these columns you can pass flex item props to `descriptionFlexItemProps` and `fieldFlexItemProps` respectively.

```tsx interactive
import React, { Fragment } from 'react';
import {
EuiFieldText,
EuiForm,
EuiFormRow,
EuiDescribedFormGroup,
EuiFilePicker,
} from '@elastic/eui';

export default () => {
return (
<EuiForm component="form">
<EuiDescribedFormGroup
ratio="third"
title={<h2>Ratio of thirds</h2>}
description={
<Fragment>
The title and description will shrink to fit inside the left side
but retains a readable minimum width.
</Fragment>
}
>
<EuiFormRow
fullWidth
label="Text field"
helpText={
<span>
Be sure to add fullWidth to EuiFormRow and nested fields.
</span>
}
>
<EuiFieldText fullWidth name="first" aria-label="Example" />
</EuiFormRow>

<EuiFormRow fullWidth label="File picker">
<EuiFilePicker fullWidth />
</EuiFormRow>
</EuiDescribedFormGroup>
</EuiForm>
);
};
```

## Props

import docgen from '@elastic/eui-docgen/dist/components/form';

<PropTable definition={docgen.EuiDescribedFormGroup} />
Loading

0 comments on commit d09482b

Please sign in to comment.