From d07755b6246bbccc08183bbdd486f2ce710cb503 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Tue, 1 Sep 2020 14:12:23 +0200 Subject: [PATCH] Docs: Drawer component (#27267) * Add documentation and example to mdx * Update packages/grafana-ui/src/components/Drawer/Drawer.mdx Co-authored-by: Alex Khomenko * Update packages/grafana-ui/src/components/Drawer/Drawer.mdx Co-authored-by: Alex Khomenko * Fix button and update text Co-authored-by: Alex Khomenko --- .../src/components/Drawer/Drawer.mdx | 33 +++++++++++++- .../src/components/Drawer/Drawer.story.tsx | 45 +++++++------------ .../src/components/Drawer/Drawer.tsx | 1 + 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/packages/grafana-ui/src/components/Drawer/Drawer.mdx b/packages/grafana-ui/src/components/Drawer/Drawer.mdx index 5bfaf6df884..54f47aa7654 100644 --- a/packages/grafana-ui/src/components/Drawer/Drawer.mdx +++ b/packages/grafana-ui/src/components/Drawer/Drawer.mdx @@ -1,4 +1,35 @@ -import { Props } from '@storybook/addon-docs/blocks'; +import { Meta, Props } from '@storybook/addon-docs/blocks'; import { Drawer } from './Drawer'; + + +# Drawer +### When to use +Drawer is a slide in overlay that can be used to display additional information without hiding the main page content. It can be anchored to the left or right edge of the screen. + + +One example of the Drawer in use is in Grafana's [panel inspector](https://grafana.com/docs/grafana/latest/panels/inspect-panel/). + +### Usage +```tsx +import { Drawer } from '@grafana/ui'; + +onClose = () => { + // handle the show or hide Drawer logic +} + +return ( + +
+ Put your Drawer content here +
+
+) +``` + + diff --git a/packages/grafana-ui/src/components/Drawer/Drawer.story.tsx b/packages/grafana-ui/src/components/Drawer/Drawer.story.tsx index b537035ad2c..661a22f04bc 100644 --- a/packages/grafana-ui/src/components/Drawer/Drawer.story.tsx +++ b/packages/grafana-ui/src/components/Drawer/Drawer.story.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { text } from '@storybook/addon-knobs'; -import { Drawer } from '@grafana/ui'; +import { Button, Drawer } from '@grafana/ui'; import { UseState } from '../../utils/storybook/UseState'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import mdx from './Drawer.mdx'; @@ -17,19 +17,14 @@ export default { }; export const global = () => { - const drawerTitle = text('title', 'Storybook'); + const drawerTitle = text('title', 'Drawer title'); return ( {(state, updateValue) => { return ( <> -
updateValue({ isOpen: !state.isOpen })} - > - Open drawer -
+ {state.isOpen && ( { updateValue({ isOpen: !state.isOpen }); }} > -
    -
  • this
  • -
  • is
  • -
  • a
  • -
  • list
  • -
  • of
  • -
  • menu
  • -
  • items
  • -
+
+
    +
  • this
  • +
  • is
  • +
  • a
  • +
  • list
  • +
  • of
  • +
  • menu
  • +
  • items
  • +
+
)} @@ -62,12 +59,7 @@ export const longContent = () => { {(state, updateValue) => { return ( <> -
updateValue({ isOpen: !state.isOpen })} - > - Open drawer -
+ {state.isOpen && ( { overflow: 'hidden', }} > -
updateValue({ isOpen: !state.isOpen })} - > - Open drawer -
+ {state.isOpen && ( void; }