Skip to content

Commit f60a3b1

Browse files
committed
feat: enhance Customizations container with custom button schemes and update Alert types for better button customization
1 parent 62a51b9 commit f60a3b1

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

example/src/containers/Customizations.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/* eslint-disable react-native/no-inline-styles */
22
/* eslint-disable react/no-unstable-nested-components */
33

4-
import { alert } from 'react-native-alert-queue';
4+
import { alert, type AlertButtonCustomProps } from 'react-native-alert-queue';
55
import { Button } from '../components/Button';
66
import { Section } from '../components/Section';
77
import {
88
Pressable,
99
StyleSheet,
1010
Text,
1111
View,
12+
type ColorValue,
1213
type StyleProp,
1314
type ViewStyle,
1415
} from 'react-native';
@@ -123,16 +124,22 @@ export const Customizations = () => {
123124
title: 'Custom buttons',
124125
buttons: [
125126
{
126-
text: 'Button 1',
127+
text: 'Button 1 (default)',
127128
onPress: () => alert.success({ message: 'Button 1 pressed' }),
128129
},
129130
{
130-
text: 'Button 2',
131+
text: 'Button 2 (primary)',
131132
onPress: () => alert.success({ message: 'Button 2 pressed' }),
133+
customProps: {
134+
scheme: 'primary',
135+
},
132136
},
133137
{
134-
text: 'Button 3',
138+
text: 'Button 3 (secondary)',
135139
onPress: () => alert.success({ message: 'Button 3 pressed' }),
140+
customProps: {
141+
scheme: 'secondary',
142+
},
136143
},
137144
],
138145
renderButton: CustomButton,
@@ -163,16 +170,33 @@ const CustomButton = ({
163170
onPress,
164171
disabled,
165172
testID,
173+
customProps,
166174
}: {
167175
text: string;
168176
onPress: () => void;
169177
disabled?: boolean;
170178
testID?: string;
179+
customProps?: AlertButtonCustomProps;
171180
}) => {
181+
const { scheme } = customProps || {};
182+
183+
let backgroundColor: ColorValue = 'black';
184+
185+
switch (scheme) {
186+
case 'primary':
187+
backgroundColor = 'green';
188+
break;
189+
case 'secondary':
190+
backgroundColor = 'blue';
191+
break;
192+
}
193+
172194
return (
173195
<Pressable
174196
onPress={onPress}
175-
style={styles.button}
197+
style={StyleSheet.compose(styles.button, {
198+
backgroundColor,
199+
})}
176200
disabled={disabled}
177201
testID={testID}
178202
>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'react-native-alert-queue';
2+
3+
declare module 'react-native-alert-queue' {
4+
export interface AlertButtonCustomProps {
5+
scheme?: 'primary' | 'secondary';
6+
}
7+
}

src/components/Alert/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export const Alert: FC<AlertViewProps> = (props) => {
201201
onPress: () => onButtonPress(button),
202202
disabled: button.disabled,
203203
testID: button.testID,
204+
customProps: button.customProps,
204205
})}
205206
</Fragment>
206207
);

src/components/Alert/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ export interface Props<R = unknown> {
4545
buttons?: AlertButton[];
4646
buttonsDirection?: 'row' | 'column';
4747
renderButton?: (
48-
props: Pick<AlertButton, 'text' | 'testID' | 'disabled'> & {
48+
props: Pick<AlertButton, 'text' | 'testID' | 'disabled' | 'customProps'> & {
4949
onPress: () => void;
5050
}
5151
) => ReactElement<any>;
5252
title?: string;
5353
}
5454

55+
export interface AlertButtonCustomProps {}
56+
5557
export type AlertButton<R = unknown> = {
5658
text: string;
5759
onPress?: (() => Promise<R>) | (() => R);
5860
disabled?: boolean;
5961
testID?: string;
6062
hideAlertOnPress?: boolean;
6163
onAwaitablePress?: (resolve: (value: R) => void) => void;
64+
customProps?: AlertButtonCustomProps;
6265
};
6366

6467
export type ConfirmProps = Omit<Props, 'buttons'> & {

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export { alert } from './containers/AlertContainer/alert.api';
22

33
export { AlertContainer } from './containers/AlertContainer';
4+
5+
export type { AlertButtonCustomProps } from './components/Alert/types';

0 commit comments

Comments
 (0)