2020-08-25 16:06:58 +08:00
|
|
|
import React from 'react';
|
2021-02-12 23:45:05 +08:00
|
|
|
import { Story } from '@storybook/react';
|
2020-08-25 16:06:58 +08:00
|
|
|
import { action } from '@storybook/addon-actions';
|
2021-02-05 16:19:09 +08:00
|
|
|
import { Alert, AlertVariant, VerticalGroup } from '@grafana/ui';
|
2021-02-12 23:45:05 +08:00
|
|
|
import { Props } from './Alert';
|
2020-08-25 16:06:58 +08:00
|
|
|
import { withCenteredStory, withHorizontallyCenteredStory } from '../../utils/storybook/withCenteredStory';
|
|
|
|
|
import mdx from '../Alert/Alert.mdx';
|
2021-02-05 16:19:09 +08:00
|
|
|
import { StoryExample } from '../../utils/storybook/StoryExample';
|
2020-08-25 16:06:58 +08:00
|
|
|
|
2021-02-12 23:45:05 +08:00
|
|
|
const severities: AlertVariant[] = ['error', 'warning', 'info', 'success'];
|
|
|
|
|
|
2020-08-25 16:06:58 +08:00
|
|
|
export default {
|
|
|
|
|
title: 'Overlays/Alert',
|
|
|
|
|
component: Alert,
|
|
|
|
|
decorators: [withCenteredStory, withHorizontallyCenteredStory],
|
|
|
|
|
parameters: {
|
|
|
|
|
docs: {
|
|
|
|
|
page: mdx,
|
|
|
|
|
},
|
2021-02-12 23:45:05 +08:00
|
|
|
},
|
|
|
|
|
argTypes: {
|
|
|
|
|
severity: { control: { type: 'select', options: severities } },
|
2020-08-25 16:06:58 +08:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-12 23:45:05 +08:00
|
|
|
export const Examples: Story<Props> = ({ severity, title, buttonContent }) => {
|
2020-08-25 16:06:58 +08:00
|
|
|
return (
|
2021-02-05 16:19:09 +08:00
|
|
|
<VerticalGroup>
|
|
|
|
|
<StoryExample name="With buttonContent and children">
|
|
|
|
|
<Alert
|
2021-02-12 23:45:05 +08:00
|
|
|
title={title}
|
|
|
|
|
severity={severity}
|
|
|
|
|
buttonContent={<span>{buttonContent}</span>}
|
2021-02-05 16:19:09 +08:00
|
|
|
onRemove={action('Remove button clicked')}
|
|
|
|
|
>
|
2021-04-14 00:00:55 +08:00
|
|
|
<VerticalGroup>
|
|
|
|
|
<div>Child content that includes some alert details, like maybe what actually happened.</div>
|
|
|
|
|
</VerticalGroup>
|
2021-02-05 16:19:09 +08:00
|
|
|
</Alert>
|
|
|
|
|
</StoryExample>
|
|
|
|
|
<StoryExample name="No dismiss">
|
2021-02-12 23:45:05 +08:00
|
|
|
<Alert title={title} severity={severity} />
|
2021-02-05 16:19:09 +08:00
|
|
|
</StoryExample>
|
2021-04-14 00:00:55 +08:00
|
|
|
<StoryExample name="Elevated alert used for absolute positioned alerts">
|
|
|
|
|
<Alert title={title} severity={severity} elevated />
|
|
|
|
|
</StoryExample>
|
2021-02-05 16:19:09 +08:00
|
|
|
<StoryExample name="Severities">
|
|
|
|
|
<VerticalGroup>
|
|
|
|
|
{severities.map((severity) => (
|
|
|
|
|
<Alert
|
|
|
|
|
title={`Severity: ${severity}`}
|
|
|
|
|
severity={severity}
|
|
|
|
|
key={severity}
|
|
|
|
|
onRemove={action('Remove button clicked')}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</VerticalGroup>
|
|
|
|
|
</StoryExample>
|
|
|
|
|
</VerticalGroup>
|
2020-08-25 16:06:58 +08:00
|
|
|
);
|
|
|
|
|
};
|
2021-02-12 23:45:05 +08:00
|
|
|
|
|
|
|
|
Examples.args = {
|
|
|
|
|
severity: 'error',
|
|
|
|
|
title: 'Some very important message',
|
|
|
|
|
buttonContent: 'Close',
|
|
|
|
|
};
|