Skip to content

Commit 03cff3b

Browse files
committed
feat: add action component in alert
1 parent 32b4d96 commit 03cff3b

4 files changed

Lines changed: 895 additions & 591 deletions

File tree

src/components/Alert/Alert.mdx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ menu: Components
44
---
55

66
import { Playground, Props } from 'docz';
7-
import { Alert, Box } from '..';
7+
import { Alert, Box, Button } from '..';
88

99
# Alert
1010

@@ -23,7 +23,12 @@ Give feedback to the user about an action or state
2323
<Alert intent="warning" title="Warning" description="Message" />
2424
</Box>
2525
<Box paddingVertical={8}>
26-
<Alert intent="danger" title="Danger" description="Message" />
26+
<Alert
27+
intent="danger"
28+
title="Danger"
29+
description="Message"
30+
action={<Button title="Action" appearance="minimal" color="primary" />}
31+
/>
2732
</Box>
2833
</Playground>
2934

@@ -39,6 +44,7 @@ Use `getStyles` prop
3944
AlertStyles {
4045
containerStyle: ViewStyle;
4146
bodyStyle: ViewStyle;
47+
leftWrapperStyle: ViewStyle;
4248
titleStyle: TextStyle;
4349
descriptionStyle: TextStyle;
4450
}
@@ -50,10 +56,13 @@ Markup
5056

5157
```tsx
5258
<View containerStyle>
53-
{icon}
54-
<View bodyStyle>
55-
<Text titleStyle>{title}</Text>
56-
<Text descriptionStyle>{description}</Text>
59+
<View leftWrapperStyle>
60+
{icon}
61+
<View bodyStyle>
62+
<Text titleStyle>{title}</Text>
63+
<Text descriptionStyle>{description}</Text>
64+
</View>
5765
</View>
66+
{action}
5867
</View>
5968
```

src/components/Alert/Alert.styles.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AlertProps } from './Alert';
66
export interface AlertStyles {
77
containerStyle: ViewStyle;
88
bodyStyle: ViewStyle;
9+
leftWrapperStyle: ViewStyle;
910
titleStyle: TextStyle;
1011
descriptionStyle: TextStyle;
1112
}
@@ -18,16 +19,22 @@ export const getAlertStyles: GetAlertStyles = ({ intent = 'info' }, theme) => {
1819
flex: 1,
1920
},
2021
containerStyle: {
22+
alignItems: 'center',
2123
backgroundColor: theme.colors.background.content,
2224
borderLeftColor: theme.colors.border[intent],
2325
borderLeftWidth: 5,
2426
borderRadius: theme.controlBorderRadius.medium,
2527
display: 'flex',
2628
flexDirection: 'row',
29+
justifyContent: 'space-between',
2730
padding: 16,
2831
...theme.elevations[2],
2932
},
3033
descriptionStyle: {},
34+
leftWrapperStyle: {
35+
display: 'flex',
36+
flexDirection: 'row',
37+
},
3138
titleStyle: {},
3239
};
3340
};

src/components/Alert/Alert.tsx

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export interface AlertProps {
3030
*/
3131
intent?: Intent;
3232

33+
/**
34+
* Component display on the right side of the alert.
35+
* @default null
36+
*/
37+
action?: React.ReactNode;
38+
3339
/** Callback to get element styles. */
3440
getStyles?: ReplaceReturnType<GetAlertStyles, DeepPartial<AlertStyles>>;
3541

@@ -61,11 +67,13 @@ export const Alert = (props: AlertProps) => {
6167
intent = 'info',
6268
getStyles,
6369
testID,
70+
action = null,
6471
} = props;
6572

6673
const theme = useTheme();
6774

6875
const {
76+
leftWrapperStyle,
6977
containerStyle,
7078
bodyStyle,
7179
descriptionStyle,
@@ -77,21 +85,24 @@ export const Alert = (props: AlertProps) => {
7785

7886
return (
7987
<View style={containerStyle} testID={testID}>
80-
{icon === null
81-
? null
82-
: icon || (
83-
<Box paddingRight={16} justifyContent="center">
84-
{resolveIcon(intent)}
85-
</Box>
86-
)}
87-
<View style={bodyStyle}>
88-
<Text getStyles={() => ({ textStyle: titleStyle })} weight="bold">
89-
{title}
90-
</Text>
91-
<Text getStyles={() => ({ textStyle: descriptionStyle })}>
92-
{description}
93-
</Text>
88+
<View style={leftWrapperStyle}>
89+
{icon === null
90+
? null
91+
: icon || (
92+
<Box paddingRight={16} justifyContent="center">
93+
{resolveIcon(intent)}
94+
</Box>
95+
)}
96+
<View style={bodyStyle}>
97+
<Text getStyles={() => ({ textStyle: titleStyle })} weight="bold">
98+
{title}
99+
</Text>
100+
<Text getStyles={() => ({ textStyle: descriptionStyle })}>
101+
{description}
102+
</Text>
103+
</View>
94104
</View>
105+
{action}
95106
</View>
96107
);
97108
};

0 commit comments

Comments
 (0)