Skip to content

refactor: migrate popover stories to mdx #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
92642e1
refactor Avatar story to mdx
Lukas742 Oct 6, 2020
4f3a68a
remove Avatar tsx story
Lukas742 Oct 6, 2020
c04396d
Add the possibility to the webcomponents-react wrapper script to only…
Lukas742 Oct 6, 2020
7a2c109
refactor Badge story
Lukas742 Oct 6, 2020
2ff53ca
refactor Button story
Lukas742 Oct 6, 2020
22075cd
webcomponents-react script supports icon import of Icon
Lukas742 Oct 6, 2020
9afca35
refactor Icon
Lukas742 Oct 6, 2020
7187725
refactor Input main description + story
Lukas742 Oct 6, 2020
371d621
refactor Label story
Lukas742 Oct 6, 2020
cad353a
refactor Link story
Lukas742 Oct 6, 2020
666dfec
refactor RatingIndicator prop description + story
Lukas742 Oct 6, 2020
b98892b
refactor Switch main description + story
Lukas742 Oct 6, 2020
1fbf61b
refactor Title story
Lukas742 Oct 6, 2020
7355a95
refactor ToggleButton prop description + story
Lukas742 Oct 6, 2020
8b1468c
refactor TextArea story
Lukas742 Oct 6, 2020
e7a886c
add missing declaration to webcomponents-react wrapper script
Lukas742 Oct 6, 2020
be6de10
refactor Popover story
Lukas742 Oct 6, 2020
5eca706
refactor ResponsivePopover Story
Lukas742 Oct 6, 2020
c911329
refactor Dialog story
Lukas742 Oct 6, 2020
01458bf
Merge branch 'master' into reafactor/webcomponents-popovers-mdx
Lukas742 Oct 6, 2020
f524ff3
revise popover stories, add story to Popover component
Lukas742 Oct 7, 2020
4f2022c
Merge branch 'reafactor/webcomponents-popovers-mdx' of github.com:SAP…
Lukas742 Oct 7, 2020
39e8194
Merge branch 'master' into reafactor/webcomponents-popovers-mdx
Lukas742 Oct 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions packages/main/src/webComponents/Dialog/Dialog.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs/blocks';
import { Dialog } from '@ui5/webcomponents-react/lib/Dialog';
import { Button } from '@ui5/webcomponents-react/lib/Button';
import { Bar } from '@ui5/webcomponents-react/lib/Bar';
import { Icon } from '@ui5/webcomponents-react/lib/Icon';
import { List } from '@ui5/webcomponents-react/lib/List';
import { StandardListItem } from '@ui5/webcomponents-react/lib/StandardListItem';
import { Title } from '@ui5/webcomponents-react/lib/Title';
import { CSSProperties, useRef } from 'react';
import { createSelectArgTypes } from '@shared/stories/createSelectArgTypes';
import { DocsHeader } from '@shared/stories/DocsHeader';

<Meta
title="UI5 Web Components / Dialog"
component={Dialog}
argTypes={{
...createSelectArgTypes({}),
footer: { control: { disable: true } },
header: { control: { disable: true } },
slot: { control: { disable: true } },
ref: { control: { disable: true } },
style: {
type: CSSProperties,
description:
'Element style which will be appended to the most outer element of a component. Use this prop carefully, some css properties might break the component.'
},
className: {
type: 'string',
description:
'CSS Class Name which will be appended to the most outer element of a component. Use this prop carefully, overwriting CSS rules might break the component.'
},
tooltip: { type: 'string', description: 'A tooltip which will be shown on hover' }
}}
args={{
children: 'Press "Escape" to close the Dialog.',
headerText: 'Dialog Header',
style: {},
className: '',
tooltip: '',
slot: '',
ref: null
}}
/>

<DocsHeader />

<br />

### Opening Dialogs

`Dialogs` can only be opened by attaching a `ref` to the component and then call the corresponding **`open`** method.

```JSX
const DialogComponent = () => {
const dialogRef = useRef();
const onButtonClick = () => {
dialogRef.current.open();
};
return (
<>
<Button onClick={onButtonClick}>Open Dialog</Button>
<Dialog ref={dialogRef}>Some Content</Dialog>
</>
);
};
```

<Canvas>
<Story name="Default">
{(args) => {
const dialogRef = useRef(null);
const onButtonClick = () => {
dialogRef.current.open();
};
const handleClose = () => {
dialogRef.current.close();
};
return (
<>
<Button onClick={onButtonClick}>Open Dialog</Button>
<Dialog {...args} ref={dialogRef} footer={<Button onClick={handleClose}>Close</Button>} />
</>
);
}}
</Story>
</Canvas>

<ArgsTable story="." />
<div style={{ fontFamily: 'var(--sapFontFamily)', fontSize: 'var(--sapFontSize)', color: 'var(--sapTextColor)' }}>
<h3>Structure</h3>A <code>Dialog</code> consists of a header, content, and a footer for action buttons. The{' '}
<code>Dialog</code> is usually displayed at the center of the screen.
</div>

### Using Dialogs inside other components

`Dialogs` are often used within other components, when opened this could sometimes have unwanted side effects.
In this case, we recommend using [createPortal](https://reactjs.org/docs/portals.html) to mount the `Dialog` outside of the DOM hierarchy of the parent component.

```JSX
const DialogComponent = () => {
const dialogRef = useRef(null);
const onButtonClick = () => {
dialogRef.current.open();
};
return (
<>
<Button onClick={onButtonClick}>Open Dialog</Button>
{createPortal(<Dialog ref={dialogRef} />, document.body)}
</>
);
};
```

### Closing Dialogs

Closing `Dialogs` works in the same way as opening them. So again an attached `ref` is needed on which the corresponding `close` method is called.

```JSX
const DialogComponent = () => {
const dialogRef = useRef();
const handleOpen = (e) => {
dialogRef.current.open();
};
const handleClose = () => {
dialogRef.current.close();
};
return (
<>
<Button onClick={handleOpen}>Open Dialog</Button>
<Dialog ref={dialogRef}>
<Button onClick={handleClose}>Close Dialog</Button>
</Dialog>
</>
);
};
```

# Stories

## Dialog with content

<Canvas>
<Story name="with content">
{(args) => {
const dialogRef = useRef(null);
const onButtonClick = () => {
dialogRef.current.open();
};
const handleClose = () => {
dialogRef.current.close();
};
return (
<>
<Button onClick={onButtonClick}>Open Dialog</Button>
<Dialog
{...args}
ref={dialogRef}
header={<Bar contentMiddle={<Title>Dialog</Title>} contentRight={<Icon name="settings" />} />}
footer={<Bar contentRight={<Button onClick={handleClose}>Close</Button>} />}
>
<List>
<StandardListItem info="3">List Item 1</StandardListItem>
<StandardListItem info="2">List Item 2</StandardListItem>
<StandardListItem info="1">List Item 3</StandardListItem>
</List>
</Dialog>
</>
);
}}
</Story>
</Canvas>
54 changes: 0 additions & 54 deletions packages/main/src/webComponents/Dialog/Dialog.stories.tsx

This file was deleted.

Loading