From 6fdfd2f27f93e969a560751957f372810bdc222d Mon Sep 17 00:00:00 2001 From: Cee Chen <549407+cee-chen@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:26:08 -0800 Subject: [PATCH] [EuiResizableButton] Add new `indicator` style prop (#7455) --- changelogs/upcoming/7455.md | 1 + .../resizable_button_indicator.tsx | 51 ++++++ .../resizable_container_example.js | 33 +++- .../flyout/flyout_resizable.styles.ts | 28 ++-- src/components/flyout/flyout_resizable.tsx | 5 +- .../resizable_button.test.tsx.snap | 13 +- .../resizable_container.test.tsx.snap | 18 +- .../resizable_button.stories.tsx | 11 +- .../resizable_button.styles.ts | 156 ++++++++++++------ .../resizable_button.test.tsx | 8 + .../resizable_container/resizable_button.tsx | 99 ++++++----- 11 files changed, 309 insertions(+), 114 deletions(-) create mode 100644 changelogs/upcoming/7455.md create mode 100644 src-docs/src/views/resizable_container/resizable_button_indicator.tsx diff --git a/changelogs/upcoming/7455.md b/changelogs/upcoming/7455.md new file mode 100644 index 00000000000..556da2a60c7 --- /dev/null +++ b/changelogs/upcoming/7455.md @@ -0,0 +1 @@ +- Updated `EuiResizableButton` to allow customizing the `indicator` style with either `handle` (default) or `border` diff --git a/src-docs/src/views/resizable_container/resizable_button_indicator.tsx b/src-docs/src/views/resizable_container/resizable_button_indicator.tsx new file mode 100644 index 00000000000..32a39e91530 --- /dev/null +++ b/src-docs/src/views/resizable_container/resizable_button_indicator.tsx @@ -0,0 +1,51 @@ +import React from 'react'; +import { EuiText, EuiResizableContainer } from '../../../../src/components'; +import { faker } from '@faker-js/faker'; + +const text = ( + <> +

{faker.lorem.paragraphs()}

+

{faker.lorem.paragraphs()}

+

{faker.lorem.paragraphs()}

+ +); + +export default () => ( + + {(EuiResizablePanel, EuiResizableButton) => ( + <> + + {text} + + + + + + + {(EuiResizablePanel, EuiResizableButton) => ( + <> + + {text} + + + + + + {text} + + + )} + + + + )} + +); diff --git a/src-docs/src/views/resizable_container/resizable_container_example.js b/src-docs/src/views/resizable_container/resizable_container_example.js index 703f9113f23..f8469e0096e 100644 --- a/src-docs/src/views/resizable_container/resizable_container_example.js +++ b/src-docs/src/views/resizable_container/resizable_container_example.js @@ -29,6 +29,7 @@ import ResizablePanelCollapsible from './resizable_panel_collapsible'; import ResizablePanelCollapsibleResponsive from './resizable_panel_collapsible_responsive'; import ResizablePanelCollapsibleOpts from './resizable_panel_collapsible_options'; import ResizablePanelCollapsibleExt from './resizable_panel_collapsible_external'; +import ResizableButtonIndicator from './resizable_button_indicator'; import ResizableButton from './resizable_button'; const ResizableContainerSource = require('!!raw-loader!./resizable_container_basic'); @@ -40,6 +41,7 @@ const ResizablePanelCollapsibleSource = require('!!raw-loader!./resizable_panel_ const ResizablePanelCollapsibleResponsiveSource = require('!!raw-loader!./resizable_panel_collapsible_responsive'); const ResizablePanelCollapsibleOptsSource = require('!!raw-loader!./resizable_panel_collapsible_options'); const ResizablePanelCollapsibleExtSource = require('!!raw-loader!./resizable_panel_collapsible_external'); +const ResizableButtonIndicatorSource = require('!!raw-loader!./resizable_button_indicator'); const ResizableButtonSource = require('!!raw-loader!./resizable_button'); const basicSnippet = ` @@ -504,6 +506,35 @@ export const ResizableContainerExample = { demo: , snippet: collapsibleExtSnippet, }, + { + source: [ + { + type: GuideSectionTypes.TSX, + code: ResizableButtonIndicatorSource, + }, + ], + title: 'Resizable button indicator', + text: ( + <> +

+ By default, EuiResizableButton shows a grab handle + indicator as a UI hint. For use cases where the resize behavior is + "nice to have" but not a primary UX focus, or where there are many + other busy UI elements on the page, you can set{' '} + indicator="border" to display a subdued border + element instead, which only provides resize affordance on hover or + focus. +

+ + ), + demo: , + demoPanelProps: { paddingSize: 'none' }, + props: { EuiResizableButton }, + snippet: ``, + }, { source: [ { @@ -511,7 +542,7 @@ export const ResizableContainerExample = { code: ResizableButtonSource, }, ], - title: 'Custom resizable button', + title: 'Custom resize logic', text: ( <>

diff --git a/src/components/flyout/flyout_resizable.styles.ts b/src/components/flyout/flyout_resizable.styles.ts index abcda128fef..1257a6d6235 100644 --- a/src/components/flyout/flyout_resizable.styles.ts +++ b/src/components/flyout/flyout_resizable.styles.ts @@ -14,17 +14,21 @@ import { logicalCSS } from '../../global_styling'; export const euiFlyoutResizableButtonStyles = ({ euiTheme }: UseEuiTheme) => ({ euiFlyoutResizableButton: css` position: absolute; - - /* Hide the default grab icon (although the hover/focus states should remain) */ - &::before, - &::after { - background-color: transparent; - } - `, - left: css` - ${logicalCSS('right', `-${euiTheme.border.width.thin}`)} - `, - right: css` - ${logicalCSS('left', `-${euiTheme.border.width.thin}`)} `, + overlay: { + left: css` + ${logicalCSS('right', 0)} + `, + right: css` + ${logicalCSS('left', 0)} + `, + }, + push: { + left: css` + ${logicalCSS('right', `-${euiTheme.border.width.thin}`)} + `, + right: css` + ${logicalCSS('left', `-${euiTheme.border.width.thin}`)} + `, + }, }); diff --git a/src/components/flyout/flyout_resizable.tsx b/src/components/flyout/flyout_resizable.tsx index 632d3af67c3..7005aafd69c 100644 --- a/src/components/flyout/flyout_resizable.tsx +++ b/src/components/flyout/flyout_resizable.tsx @@ -34,6 +34,7 @@ export const EuiFlyoutResizable = forwardRef( maxWidth, minWidth = 200, side = 'right', + type = 'overlay', children, ...rest }: EuiFlyoutResizableProps, @@ -41,7 +42,7 @@ export const EuiFlyoutResizable = forwardRef( ) => { const euiTheme = useEuiTheme(); const styles = euiFlyoutResizableButtonStyles(euiTheme); - const cssStyles = [styles.euiFlyoutResizableButton, styles[side]]; + const cssStyles = [styles.euiFlyoutResizableButton, styles[type][side]]; const getFlyoutMinMaxWidth = useCallback( (width: number) => { @@ -141,10 +142,12 @@ export const EuiFlyoutResizable = forwardRef( size={flyoutWidth || size} maxWidth={maxWidth} side={side} + type={type} ref={setRefs} >