-
Couldn't load subscription status.
- Fork 861
[Flyout System] Support resizing flyouts #8999
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
Changes from all commits
346ce44
b115143
beef45c
e49ba15
b45a838
8520628
af8f9ec
601af51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Added a new optional `resizable` (boolean) prop to `EuiFlyout`. Resizability can now be controlled dynamically without the need to use `EuiFlyoutResizable`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * 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'; | ||
| import { useEuiMemoizedStyles } from '../../services'; | ||
| import { | ||
| EuiResizableButton, | ||
| EuiResizableButtonProps, | ||
| } from '../resizable_container'; | ||
| import type { _EuiFlyoutType, _EuiFlyoutSide } from './const'; | ||
| import type { EuiFlyoutComponentProps } from './flyout.component'; | ||
| import { euiFlyoutResizeButtonStyles } from './_flyout_resize_button.styles'; | ||
|
|
||
| type EuiFlyoutResizeButtonProps = Pick< | ||
| EuiResizableButtonProps, | ||
| 'onMouseDown' | 'onKeyDown' | 'onTouchStart' | ||
| > & { | ||
| type: _EuiFlyoutType; | ||
| side: _EuiFlyoutSide; | ||
| ownFocus: EuiFlyoutComponentProps['ownFocus']; | ||
| isPushed: boolean; | ||
| }; | ||
|
|
||
| export const EuiFlyoutResizeButton = ({ | ||
| type, | ||
| side, | ||
| ownFocus, | ||
| isPushed, | ||
| ...resizableButtonProps | ||
| }: EuiFlyoutResizeButtonProps) => { | ||
| const hasOverlay = ownFocus && type === 'overlay'; | ||
| const styles = useEuiMemoizedStyles(euiFlyoutResizeButtonStyles); | ||
|
|
||
| const cssStyles = [ | ||
| styles.root, | ||
| styles[type][side], | ||
| !hasOverlay && styles.noOverlay.root, | ||
| !hasOverlay && styles.noOverlay[side], | ||
| ]; | ||
|
|
||
| return ( | ||
| <EuiResizableButton | ||
| isHorizontal | ||
| indicator="border" | ||
| css={cssStyles} | ||
| {...resizableButtonProps} | ||
| /> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,8 @@ import { | |
| isEuiFlyoutSizeNamed, | ||
| } from './const'; | ||
| import { useIsPushed } from './hooks'; | ||
| import { EuiFlyoutResizeButton } from './_flyout_resize_button'; | ||
| import { useEuiFlyoutResizable } from './use_flyout_resizable'; | ||
|
|
||
| interface _EuiFlyoutComponentProps { | ||
| onClose: (event: MouseEvent | TouchEvent | KeyboardEvent) => void; | ||
|
|
@@ -76,6 +78,11 @@ interface _EuiFlyoutComponentProps { | |
| * @default m | ||
| */ | ||
| size?: EuiFlyoutSize | CSSProperties['width']; | ||
| /** | ||
| * Sets the minimum width of the panel. | ||
| * Especially useful when set with `resizable = true`. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be good to have this for |
||
| */ | ||
| minWidth?: number; | ||
| /** | ||
| * Sets the max-width of the panel, | ||
| * set to `true` to use the default size, | ||
|
|
@@ -166,6 +173,17 @@ interface _EuiFlyoutComponentProps { | |
| * Specify additional css selectors to include in the focus trap. | ||
| */ | ||
| includeSelectorInFocusTrap?: string[] | string; | ||
|
|
||
| /** | ||
| * Whether the flyout should be resizable. | ||
| * @default false | ||
| */ | ||
| resizable?: boolean; | ||
|
|
||
| /** | ||
| * Optional callback that fires when the flyout is resized. | ||
| */ | ||
| onResize?: (width: number) => void; | ||
| } | ||
|
|
||
| const defaultElement = 'div'; | ||
|
|
@@ -199,7 +217,7 @@ export const EuiFlyoutComponent = forwardRef( | |
| onClose, | ||
| ownFocus = true, | ||
| side = DEFAULT_SIDE, | ||
| size = DEFAULT_SIZE, | ||
| size: _size = DEFAULT_SIZE, | ||
| paddingSize = DEFAULT_PADDING_SIZE, | ||
| maxWidth = false, | ||
| style, | ||
|
|
@@ -213,6 +231,9 @@ export const EuiFlyoutComponent = forwardRef( | |
| includeSelectorInFocusTrap, | ||
| 'aria-describedby': _ariaDescribedBy, | ||
| id, | ||
| resizable = false, | ||
| minWidth, | ||
| onResize, | ||
| ...rest | ||
| } = usePropsWithComponentDefaults('EuiFlyout', props); | ||
|
|
||
|
|
@@ -225,6 +246,20 @@ export const EuiFlyoutComponent = forwardRef( | |
| const internalParentFlyoutRef = useRef<HTMLDivElement>(null); | ||
| const isPushed = useIsPushed({ type, pushMinBreakpoint }); | ||
|
|
||
| const { | ||
| onMouseDown: onMouseDownResizableButton, | ||
| onKeyDown: onKeyDownResizableButton, | ||
| size, | ||
| setFlyoutRef, | ||
| } = useEuiFlyoutResizable({ | ||
| enabled: resizable, | ||
| minWidth, | ||
| maxWidth: typeof maxWidth === 'number' ? maxWidth : 0, | ||
| onResize, | ||
| side, | ||
| size: _size, | ||
| }); | ||
|
|
||
| /** | ||
| * Setting up the refs on the actual flyout element in order to | ||
| * accommodate for the `isPushed` state by adding padding to the body equal to the width of the element | ||
|
|
@@ -236,6 +271,7 @@ export const EuiFlyoutComponent = forwardRef( | |
| setResizeRef, | ||
| ref, | ||
| internalParentFlyoutRef, | ||
| setFlyoutRef, | ||
| ]); | ||
| const { width } = useResizeObserver(isPushed ? resizeRef : null, 'width'); | ||
|
|
||
|
|
@@ -534,6 +570,17 @@ export const EuiFlyoutComponent = forwardRef( | |
| side={side} | ||
| /> | ||
| )} | ||
| {resizable && ( | ||
| <EuiFlyoutResizeButton | ||
| type={type} | ||
| side={side} | ||
| ownFocus={ownFocus} | ||
| isPushed={isPushed} | ||
| onMouseDown={onMouseDownResizableButton} | ||
| onTouchStart={onMouseDownResizableButton} | ||
| onKeyDown={onKeyDownResizableButton} | ||
| /> | ||
| )} | ||
| {children} | ||
| </Element> | ||
| </EuiFocusTrap> | ||
|
|
||
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.
This is an updated snapshot that was failing on
feat/flyout-systemdue to last-minute changes on the last PR merged to the feature branch. The changes match other "is rendered" variants