-
Notifications
You must be signed in to change notification settings - Fork 843
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
Allow EuiDataGrid's default column width to update on resize #2991
Merged
chandlerprall
merged 8 commits into
elastic:master
from
chandlerprall:bug/2759-datagrid-responsive-column-widths
Mar 12, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fc83ca7
Allow EuiDataGrid's default column width to automatically update on r…
chandlerprall 9b8ad28
Refactored data grid resize observing into a hook
chandlerprall b3bc695
Documentation and unit test for useResizeObserver
chandlerprall 0f3c0ee
CHANGELOG
chandlerprall 295611c
Update docs to reflect current browser support for ResizeObserver
chandlerprall 54d1561
Updated useResizeObserver to set initial container size on same synch…
chandlerprall 921e7a3
Update comment to reflect reality
chandlerprall 5fed144
Merge branch 'master' into bug/2759-datagrid-responsive-column-widths
chandlerprall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
72 changes: 72 additions & 0 deletions
72
src-docs/src/views/resize_observer/resize_observer_hook.js
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,72 @@ | ||
import React, { useRef, useState } from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiCode, | ||
EuiIcon, | ||
EuiPanel, | ||
EuiSpacer, | ||
EuiText, | ||
useResizeObserver, | ||
} from '../../../../src/components'; | ||
|
||
export const ResizeObserverHookExample = () => { | ||
const hasResizeObserver = typeof ResizeObserver !== 'undefined'; | ||
const [paddingSize, setPaddingSize] = useState('s'); | ||
const [items, setItems] = useState(['Item 1', 'Item 2', 'Item 3']); | ||
|
||
const togglePaddingSize = () => { | ||
setPaddingSize(paddingSize => (paddingSize === 's' ? 'l' : 's')); | ||
}; | ||
|
||
const addItem = () => { | ||
setItems(items => [...items, `Item ${items.length + 1}`]); | ||
}; | ||
|
||
const resizeRef = useRef(); | ||
const dimensions = useResizeObserver(resizeRef.current); | ||
|
||
return ( | ||
<div> | ||
<EuiText> | ||
{hasResizeObserver ? ( | ||
<p> | ||
<EuiIcon type="checkInCircleFilled" color="secondary" /> Browser | ||
supports ResizeObserver API. | ||
</p> | ||
) : ( | ||
<p> | ||
<EuiIcon type="crossInACircleFilled" color="danger" /> Browser does | ||
not support ResizeObserver API. Using MutationObserver. | ||
</p> | ||
)} | ||
<p> | ||
<EuiCode>{`height: ${dimensions.height}; width: ${ | ||
dimensions.width | ||
}`}</EuiCode> | ||
</p> | ||
</EuiText> | ||
|
||
<EuiSpacer /> | ||
|
||
<EuiButton fill={true} onClick={togglePaddingSize}> | ||
Toggle container padding | ||
</EuiButton> | ||
|
||
<EuiSpacer /> | ||
|
||
<div className="eui-displayInlineBlock" ref={resizeRef}> | ||
<EuiPanel className="eui-displayInlineBlock" paddingSize={paddingSize}> | ||
<ul> | ||
{items.map(item => ( | ||
<li key={item}>{item}</li> | ||
))} | ||
</ul> | ||
<EuiSpacer size="s" /> | ||
<EuiButtonEmpty onClick={addItem}>add item</EuiButtonEmpty> | ||
</EuiPanel> | ||
</div> | ||
</div> | ||
); | ||
}; |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export { EuiResizeObserver } from './resize_observer'; | ||
export { EuiResizeObserver, useResizeObserver } from './resize_observer'; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If only React had a way to specify dependencies that also included an ESLint rule to tell you when you're missing one. Oh wait ... 😅
Maybe someday this'll be a function component with hooks.