|
| 1 | +# @kbn/expandable-flyout |
| 2 | + |
| 3 | +## Purpose |
| 4 | + |
| 5 | +This package offers an expandable flyout UI component and a way to manage the data displayed in it. The component leverages the [EuiFlyout](https://github.com/elastic/eui/tree/main/src/components/flyout) from the EUI library. |
| 6 | + |
| 7 | +The flyout is composed of 3 sections: |
| 8 | +- a right section (primary section) that opens first |
| 9 | +- a left wider section to show more details |
| 10 | +- a preview section, that overlays the right section. This preview section can display multiple panels one after the other and displays a `Back` button |
| 11 | + |
| 12 | +At the moment, displaying more than one flyout within the same plugin might be complicated, unless there are in difference areas in the codebase and the contexts don't conflict with each other. |
| 13 | + |
| 14 | +## What the package offers |
| 15 | + |
| 16 | +The ExpandableFlyout [React component](https://github.com/elastic/kibana/tree/main/packages/kbn-expandable-flyout/src/components/index) that renders the UI. |
| 17 | + |
| 18 | +The ExpandableFlyout [React context](https://github.com/elastic/kibana/tree/main/packages/kbn-expandable-flyout/src/components/context) that exposes the following api: |
| 19 | +- **openFlyout**: open the flyout with a set of panels |
| 20 | +- **openFlyoutRightPanel**: open a right panel |
| 21 | +- **openFlyoutLeftPanel**: open a left panel |
| 22 | +- **openFlyoutPreviewPanel**: open a preview panel |
| 23 | +- **closeFlyoutRightPanel**: close the right panel |
| 24 | +- **closeFlyoutLeftPanel**: close the left panel |
| 25 | +- **closeFlyoutPreviewPanel**: close the preview panels |
| 26 | +- **previousFlyoutPreviewPanel**: navigate to the previous preview panel |
| 27 | +- **closeFlyout**: close the flyout |
| 28 | + |
| 29 | +To retrieve the flyout's layout (left, right and preview panels), you can use the **panels** from the same [React context](https://github.com/elastic/kibana/tree/main/packages/kbn-expandable-flyout/src/components/context); |
| 30 | + |
| 31 | +- To have more details about how these above api work, see the code documentation [here](https://github.com/elastic/kibana/tree/main/packages/kbn-expandable-flyout/src/utils/helpers). |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +To use the expandable flyout in your plugin, first you need wrap your code with the context provider at a high enough level as follows: |
| 36 | +```typescript jsx |
| 37 | +<ExpandableFlyoutProvider> |
| 38 | + |
| 39 | + ... |
| 40 | + |
| 41 | +</ExpandableFlyoutProvider> |
| 42 | +``` |
| 43 | + |
| 44 | +Then use the React UI component where you need: |
| 45 | + |
| 46 | +```typescript jsx |
| 47 | +<ExpandableFlyout registeredPanels={myPanels} /> |
| 48 | +``` |
| 49 | +where `myPanels` is a list of all the panels that can be rendered in the flyout (see interface [here](https://github.com/elastic/kibana/tree/main/packages/kbn-expandable-flyout/src/components/index)). |
| 50 | + |
| 51 | + |
| 52 | +## Terminology |
| 53 | + |
| 54 | +### Section |
| 55 | + |
| 56 | +One of the 3 areas of the flyout (left, right or preview). |
| 57 | + |
| 58 | +### Panel |
| 59 | + |
| 60 | +A set of properties defining what's displayed in one of the flyout section. |
| 61 | + |
| 62 | +## Future work |
| 63 | + |
| 64 | +- currently the panels are aware of their width. This should be changed and the width of the left, right and preview sections should be handled by the flyout itself |
| 65 | +- add the feature to save the flyout state (layout) to the url |
| 66 | +- introduce the notion of scope to be able to handle more than one flyout per plugin?? |
0 commit comments