Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit f322e2f

Browse files
authored
Merge pull request #628 from RobertoMSousa/alert_storybook_docs
fix(alert): update alert story
2 parents e3bb78f + f93614b commit f322e2f

3 files changed

Lines changed: 106 additions & 56 deletions

File tree

.storybook/preview.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export const parameters = {
88
},
99
options: {
1010
storySort: {
11-
order: ['Welcome'],
11+
method: 'alphabetical',
12+
order: ['Welcome', ],
1213
},
1314
}
14-
}
15+
}

src/components/Alert/Alert.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import BootstrapAlert from 'react-bootstrap/Alert'
44
import { ColorVariant } from '../../interfaces'
55
import { Button } from '../Button'
66

7-
interface Props {
7+
export interface AlertProps {
88
/**
99
* Defines the color of the alert. Defaults to primary.
1010
* @default "primary"
@@ -48,8 +48,8 @@ interface State {
4848
* with the handful of available and flexible alert messages.
4949
*/
5050

51-
class Alert extends Component<Props, State> {
52-
constructor(props: Props) {
51+
class Alert extends Component<AlertProps, State> {
52+
constructor(props: AlertProps) {
5353
super(props)
5454
this.state = {
5555
show: true,

stories/alerts.stories.tsx

Lines changed: 100 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,102 @@
1-
import { storiesOf } from '@storybook/react'
1+
import { Story, Meta } from '@storybook/react/types-6-0'
22
import React from 'react'
33

4-
import { Alert } from '../src'
5-
6-
storiesOf('Alert', module)
7-
.addParameters({
8-
info: {
9-
inline: true,
10-
},
11-
})
12-
.addDecorator((storyFn) => (
13-
<div style={{ marginLeft: '2em', marginRight: '2em' }}>{storyFn()}</div>
14-
))
15-
.add('Alert', () => (
16-
<div>
17-
<Alert
18-
color="primary"
19-
title="This is the title of the alert"
20-
message="And this is the message of the alert"
21-
/>
22-
<Alert color="secondary" title="This is an alert with only the title" />
23-
<Alert color="success" message="This is an alert with only the message" />
24-
<Alert color="danger" title="This alert is dismissible" dismissible />
25-
<Alert
26-
color="warning"
27-
title="This alert is dismissible with a custom label"
28-
dismissible
29-
closeLabel="Close me"
30-
/>
31-
<Alert color="info" title="This is an info alert" />
32-
<Alert color="light" title="This is a light alert" />
33-
<Alert
34-
color="dark"
35-
title="This is a dark alert"
36-
message={<strong>With a strong message</strong>}
37-
/>
38-
<Alert
39-
title="This is an alert with a custom class"
40-
className="customClass"
41-
message="And it has a button with a custom class"
42-
btnClassName="customClass2"
43-
dismissible
44-
/>
45-
<Alert
46-
title="This is an alert with a custom style"
47-
style={{ height: '50%', width: '50%', border: '2px solid red' }}
48-
message="And it has a button with a custom style"
49-
btnStyle={{ background: 'red', color: 'white' }}
50-
dismissible
51-
/>
52-
</div>
53-
))
4+
import { Alert, AlertProps } from '../src'
5+
6+
export default {
7+
title: 'Alert',
8+
component: Alert,
9+
decorators: [
10+
(St) => (
11+
<div style={{ margin: '3em' }}>
12+
<St />
13+
</div>
14+
),
15+
],
16+
} as Meta
17+
// your templates and stories
18+
19+
// We create a “template” of how args map to rendering
20+
const Template: Story<AlertProps> = (args) => <Alert {...args} />
21+
22+
// main story tha's editable and has the docs for the props
23+
export const Main = Template.bind({})
24+
Main.args = {
25+
color: 'primary',
26+
title: 'This is the title of the alert',
27+
message: 'And this is the message of the alert',
28+
dismissible: true,
29+
closeLabel: 'Close',
30+
}
31+
32+
// Rest of the stories
33+
export const Primary = Template.bind({})
34+
Primary.args = {
35+
color: 'primary',
36+
title: 'This is the title of the alert',
37+
message: 'And this is the message of the alert',
38+
}
39+
40+
export const Secondary = Template.bind({})
41+
Secondary.args = {
42+
color: 'secondary',
43+
title: 'This is an alert with only the title',
44+
}
45+
46+
export const Success = Template.bind({})
47+
Success.args = {
48+
color: 'success',
49+
title: 'This is an alert with only the title',
50+
}
51+
52+
export const Danger = Template.bind({})
53+
Danger.args = {
54+
color: 'danger',
55+
title: 'This alert is dismissible',
56+
dismissible: true,
57+
}
58+
59+
export const Warning = Template.bind({})
60+
Warning.args = {
61+
color: 'warning',
62+
title: 'This alert is dismissible with a custom label',
63+
dismissible: true,
64+
closeLabel: 'Close me',
65+
}
66+
67+
export const Info = Template.bind({})
68+
Info.args = {
69+
color: 'info',
70+
title: 'This is an info alert',
71+
}
72+
73+
export const Light = Template.bind({})
74+
Light.args = {
75+
color: 'light',
76+
title: 'This is an light alert',
77+
}
78+
79+
export const Dark = Template.bind({})
80+
Dark.args = {
81+
color: 'dark',
82+
title: 'This is an dark alert',
83+
message: <strong>With a strong message</strong>,
84+
}
85+
86+
export const CustomClass = Template.bind({})
87+
CustomClass.args = {
88+
title: 'This is an alert with a custom class',
89+
className: 'customClass',
90+
message: 'And it has a button with a custom class',
91+
btnClassName: 'customClass2',
92+
dismissible: true,
93+
}
94+
95+
export const CustomStyle = Template.bind({})
96+
CustomStyle.args = {
97+
title: 'This is an alert with a custom style',
98+
style: { height: '50%', width: '50%', border: '2px solid red' },
99+
message: 'And it has a button with a custom style',
100+
btnStyle: { background: 'red', color: 'white' },
101+
dismissible: true,
102+
}

0 commit comments

Comments
 (0)