From 9f3dc57d4e63cc7f9ba5f20980172c16da528e2f Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Wed, 27 Dec 2023 12:02:19 -0800 Subject: [PATCH] Add docs example --- src-docs/src/views/flyout/flyout_example.js | 46 ++++++++++ .../src/views/flyout/flyout_resizable.tsx | 89 +++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 src-docs/src/views/flyout/flyout_resizable.tsx diff --git a/src-docs/src/views/flyout/flyout_example.js b/src-docs/src/views/flyout/flyout_example.js index 5097bfb0c7b..fbe28aa1633 100644 --- a/src-docs/src/views/flyout/flyout_example.js +++ b/src-docs/src/views/flyout/flyout_example.js @@ -9,6 +9,7 @@ import { EuiFlyoutBody, EuiFlyoutHeader, EuiFlyoutFooter, + EuiFlyoutResizable, EuiCallOut, EuiLink, } from '../../../../src/components'; @@ -37,6 +38,9 @@ const flyoutWithBannerSource = require('!!raw-loader!./flyout_banner'); import FlyoutPush from './flyout_push'; const flyoutPushSource = require('!!raw-loader!./flyout_push'); +import FlyoutResizable from './flyout_resizable'; +const flyoutResizableSource = require('!!raw-loader!./flyout_resizable'); + const flyOutSnippet = ` @@ -144,6 +148,18 @@ const flyoutPushedSnippet = ` `; +const flyoutResizableSnippet = ` + + +

Flyout title

+
+
+ + + +
+`; + export const FlyoutExample = { title: 'Flyout', sections: [ @@ -384,5 +400,35 @@ export const FlyoutExample = { demo: , props: { EuiFlyout }, }, + { + title: 'Resizable flyouts', + source: [ + { + type: GuideSectionTypes.JS, + code: flyoutResizableSource, + }, + ], + text: ( + <> +

+ You can use EuiFlyoutResizable to render a flyout + that users can drag with their mouse or use arrow keys to resize. + This may be useful for scenarios where the space the user needs can + be unpredictable, if content is dynamic. Resizable flyouts allow + users to adjust content to better fit their individual screens and + workflows. +

+

+ We strongly recommend setting reasonable numerical{' '} + minWidth and maxWidth props + based on the flyout content and page content that you can{' '} + predict. +

+ + ), + snippet: flyoutResizableSnippet, + demo: , + props: { EuiFlyoutResizable }, + }, ], }; diff --git a/src-docs/src/views/flyout/flyout_resizable.tsx b/src-docs/src/views/flyout/flyout_resizable.tsx new file mode 100644 index 00000000000..4969860ca89 --- /dev/null +++ b/src-docs/src/views/flyout/flyout_resizable.tsx @@ -0,0 +1,89 @@ +import React, { useState } from 'react'; + +import { + EuiFlyoutResizable, + EuiFlyoutProps, + EuiFlyoutBody, + EuiFlyoutHeader, + EuiButton, + EuiButtonGroup, + EuiText, + EuiTitle, + EuiSpacer, +} from '../../../../src/components'; + +import { useGeneratedHtmlId } from '../../../../src/services'; + +export default () => { + const [isFlyoutVisible, setIsFlyoutVisible] = useState(false); + const [flyoutType, setFlyoutType] = useState('overlay'); + const [flyoutSide, setFlyoutSide] = useState('right'); + + const flyoutTitleId = useGeneratedHtmlId({ + prefix: 'simpleFlyoutTitle', + }); + + let flyout; + + if (isFlyoutVisible) { + flyout = ( + setIsFlyoutVisible(false)} + aria-labelledby={flyoutTitleId} + > + + +

A resizable flyout

+
+
+ + +

+ This flyout is resizable by both mouse drag and arrow keys (when + the resizable edge is focused). Both push and overlay flyouts can + be resizable, on either side. +

+
+ + +

Flyout type

+
+ + setFlyoutType(id)} + /> + + +

Flyout side

+
+ setFlyoutSide(id)} + /> +
+
+ ); + } + + return ( + <> + setIsFlyoutVisible(true)}> + Show resizable flyout + + {flyout} + + ); +};