-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiForm] specify default fullWidth with root component (#6229)
Co-authored-by: Constance <[email protected]>
- Loading branch information
Spencer
and
Constance
authored
Sep 28, 2022
1 parent
c0b90a4
commit 1e90096
Showing
36 changed files
with
736 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src-docs/src/views/form_layouts/full_width_via_context.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
EuiForm, | ||
EuiFieldSearch, | ||
EuiRange, | ||
EuiTextArea, | ||
EuiFormRow, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSpacer, | ||
EuiDescribedFormGroup, | ||
EuiSelect, | ||
EuiFilePicker, | ||
EuiButton, | ||
} from '../../../../src/components'; | ||
|
||
export default () => { | ||
const [range, setRange] = React.useState(42); | ||
|
||
return ( | ||
<EuiForm | ||
fullWidth | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
}} | ||
> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<EuiFieldSearch | ||
placeholder="Search..." | ||
aria-label="An example of search with fullWidth" | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton>Search</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
|
||
<EuiSpacer size="l" /> | ||
|
||
<EuiFormRow | ||
label="Works on form rows too" | ||
helpText="Note that the fullWidth prop is not passed to any of these elements, it's read from the parent <EuiForm> component." | ||
> | ||
<EuiRange | ||
min={0} | ||
max={100} | ||
name="range" | ||
value={range} | ||
onChange={(e) => { | ||
if (e.target instanceof HTMLInputElement) { | ||
setRange(Number.parseInt(e.target.value, 10)); | ||
} | ||
}} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiSpacer /> | ||
|
||
<EuiDescribedFormGroup | ||
title={<h3>Works with all form controls and layout components</h3>} | ||
description={ | ||
<> | ||
<p> | ||
Any component that supports the <code>fullWidth</code> prop that | ||
is. | ||
</p> | ||
<p> | ||
Make sure it is appropriate at all of the widths that the | ||
container can take. There are many situations where a full-width | ||
form is inappropriate. | ||
</p> | ||
</> | ||
} | ||
> | ||
<EuiFormRow label="Text area"> | ||
<EuiTextArea placeholder="" /> | ||
</EuiFormRow> | ||
</EuiDescribedFormGroup> | ||
|
||
<EuiFormRow label="Works on EuiSelect"> | ||
<EuiSelect | ||
options={[ | ||
{ | ||
value: 'option_one', | ||
text: | ||
'Option one is very long in order to try justifying the use of fullWidth on a select box', | ||
}, | ||
{ value: 'option_two', text: 'Option two' }, | ||
{ value: 'option_three', text: 'Option three' }, | ||
]} | ||
/> | ||
</EuiFormRow> | ||
|
||
<EuiFormRow label="It can be disabled for a specific control"> | ||
<EuiFilePicker display="default" fullWidth={false} /> | ||
</EuiFormRow> | ||
</EuiForm> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
export interface FormContextValue { | ||
defaultFullWidth: boolean; | ||
} | ||
|
||
export const FormContext = React.createContext<FormContextValue>({ | ||
defaultFullWidth: false, | ||
}); | ||
|
||
export function useFormContext() { | ||
return React.useContext(FormContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.