diff --git a/packages/grafana-ui/src/components/Collapse/Collapse.mdx b/packages/grafana-ui/src/components/Collapse/Collapse.mdx new file mode 100644 index 00000000000..35bdede3df8 --- /dev/null +++ b/packages/grafana-ui/src/components/Collapse/Collapse.mdx @@ -0,0 +1,18 @@ +import { Meta, Preview, Props } from '@storybook/addon-docs/blocks'; +import {Collapse} from "./Collapse"; + +# Collapse + +A content area, which can be horizontally collapsed and expanded. Can be used to hide extra information on the page. + +## Usage + +```jsx +const [isOpen, setIsOpen] = useState(false); + + setIsOpen(!isOpen)}> +

Panel data

+
+``` + + diff --git a/packages/grafana-ui/src/components/Collapse/Collapse.story.tsx b/packages/grafana-ui/src/components/Collapse/Collapse.story.tsx new file mode 100644 index 00000000000..b7b00dcbd08 --- /dev/null +++ b/packages/grafana-ui/src/components/Collapse/Collapse.story.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import { Collapse, ControlledCollapse } from './Collapse'; +import { withCenteredStory, withHorizontallyCenteredStory } from '../../utils/storybook/withCenteredStory'; +import { UseState } from '../../utils/storybook/UseState'; +import mdx from './Collapse.mdx'; + +export default { + title: 'Layout/Collapse', + component: Collapse, + decorators: [withCenteredStory, withHorizontallyCenteredStory], + parameters: { + docs: { + page: mdx, + }, + }, +}; + +export const basic = () => { + return ( + + {(state, updateValue) => { + return ( + updateValue({ isOpen: !state.isOpen })} + > +

Panel data

+
+ ); + }} +
+ ); +}; + +export const controlled = () => { + return ( + +

Panel data

+
+ ); +}; diff --git a/packages/grafana-ui/src/components/Collapse/Collapse.tsx b/packages/grafana-ui/src/components/Collapse/Collapse.tsx index 234787ab216..fc71090fe11 100644 --- a/packages/grafana-ui/src/components/Collapse/Collapse.tsx +++ b/packages/grafana-ui/src/components/Collapse/Collapse.tsx @@ -82,11 +82,16 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => ({ `, })); -interface Props { +export interface Props { + /** Expand or collapse te content */ isOpen?: boolean; + /** Text for the Collapse header */ label: string; + /** Indicates loading state of the content */ loading?: boolean; + /** Toggle collapsed header icon */ collapsible?: boolean; + /** Callback for the toggle functionality */ onToggle?: (isOpen: boolean) => void; }