Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 484cebd

Browse files
committed
fix: add actions props to Alert component
1 parent fd2309b commit 484cebd

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

src/components/Alert/Alert.stories.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ export const Closable = (args: any) => (
7979
</Alert>
8080
)
8181

82+
export const WithAction = (args: any) => (
83+
<Alert {...args}>
84+
Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet
85+
labore.
86+
</Alert>
87+
)
88+
8289
Neutral.args = {
8390
title: 'Success alert with icon',
8491
withIcon: true,
@@ -132,3 +139,10 @@ Closable.args = {
132139
title: 'Closable alert',
133140
closable: true,
134141
}
142+
143+
WithAction.args = {
144+
title: 'Alert with action',
145+
variant: 'warning',
146+
withIcon: true,
147+
actions: <div>Hello</div>,
148+
}

src/components/Alert/Alert.tsx

+21-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface Props {
1818
closable?: boolean
1919
children?: React.ReactNode
2020
icon?: React.ReactNode
21+
actions?: React.ReactNode
2122
}
2223

2324
const icons: Record<
@@ -39,6 +40,7 @@ function Alert({
3940
closable,
4041
children,
4142
icon,
43+
actions,
4244
}: Props) {
4345
let __styles = styleHandler('alert')
4446

@@ -59,30 +61,33 @@ function Alert({
5961
<>
6062
{visible && (
6163
<div className={containerClasses.join(' ')}>
62-
{withIcon ? (
63-
<div className={__styles.variant[variant].icon}>
64-
{withIcon && icons[variant]}
64+
<div className="flex space-x-4">
65+
{withIcon ? (
66+
<div className={__styles.variant[variant].icon}>
67+
{withIcon && icons[variant]}
68+
</div>
69+
) : null}
70+
{icon && icon}
71+
<div>
72+
<h3
73+
className={[
74+
__styles.variant[variant].header,
75+
__styles.header,
76+
].join(' ')}
77+
>
78+
{title}
79+
</h3>
80+
<div className={descriptionClasses.join(' ')}>{children}</div>
6581
</div>
66-
) : null}
67-
{icon && icon}
68-
<div>
69-
<h3
70-
className={[
71-
__styles.variant[variant].header,
72-
__styles.header,
73-
].join(' ')}
74-
>
75-
{title}
76-
</h3>
77-
<div className={descriptionClasses.join(' ')}>{children}</div>
7882
</div>
83+
{actions}
7984
{closable && (
8085
<button
8186
aria-label="Close alert"
8287
onClick={() => setVisible(false)}
8388
className={closeButtonClasses.join(' ')}
8489
>
85-
<IconX strokeWidth={1.5} size={14} />
90+
<IconX strokeWidth={2} size={16} />
8691
</button>
8792
)}
8893
</div>

src/lib/theme/defaultTheme.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,8 @@ export default {
252252

253253
alert: {
254254
base: `
255-
relative
256-
rounded
257-
py-4 px-6
258-
flex space-x-4 items-start
259-
border
255+
relative rounded border py-4 px-6
256+
flex justify-between space-x-4 items-start
260257
`,
261258
header: 'block text-sm font-normal mb-1',
262259
description: `text-xs`,

0 commit comments

Comments
 (0)