Skip to content

Commit

Permalink
feat: add text1Style and text2Style to ToastOptions (#479)
Browse files Browse the repository at this point in the history
* fix: availability of text1 and text2 style props

* chore(types): move text1Style and text2Style to ToastOptions

* refactor: Update test case to include missing text1Style and text2Style in the options
  • Loading branch information
EmreKarslan authored Dec 13, 2023
1 parent ce571f7 commit 3ae6f01
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ToastUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function renderComponent({
hide
}: ToastUIProps) {
const { text1, text2 } = data;
const { type, onPress, position, props } = options;
const { type, onPress, text1Style, text2Style, position, props } = options;

const toastConfig = {
...defaultToastConfig,
Expand All @@ -56,6 +56,8 @@ function renderComponent({
isVisible,
text1,
text2,
text1Style,
text2Style,
show,
hide,
onPress,
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/useToast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ describe('test useToast hook', () => {
const options: ToastOptions = {
type: 'info',
position: 'bottom',
text1Style: null,
text2Style: null,
autoHide: false,
visibilityTime: 20,
topOffset: 120,
Expand Down
10 changes: 10 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export type ToastOptions = {
* Default value: `success`
*/
type?: ToastType;
/**
* Style for the header text in the Toast (text1).
*/
text1Style?: StyleProp<TextStyle>;
/**
* Style for the inner message text in the Toast (text2).
*/
text2Style?: StyleProp<TextStyle>;
/**
* Toast position.
* Default value: `top`
Expand Down Expand Up @@ -108,6 +116,8 @@ export type ToastConfigParams<Props> = {
isVisible: boolean;
text1?: string;
text2?: string;
text1Style?: StyleProp<TextStyle>;
text2Style?: StyleProp<TextStyle>;
show: (params: ToastShowParams) => void;
hide: (params: ToastHideParams) => void;
onPress: () => void;
Expand Down
6 changes: 6 additions & 0 deletions src/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const DEFAULT_DATA: ToastData = {

export const DEFAULT_OPTIONS: Required<ToastOptions> = {
type: 'success',
text1Style: null,
text2Style: null,
position: 'top',
autoHide: true,
visibilityTime: 4000,
Expand Down Expand Up @@ -66,6 +68,8 @@ export function useToast({ defaultOptions }: UseToastParams) {
text1 = DEFAULT_DATA.text1,
text2 = DEFAULT_DATA.text2,
type = initialOptions.type,
text1Style = initialOptions.text1Style,
text2Style = initialOptions.text2Style,
position = initialOptions.position,
autoHide = initialOptions.autoHide,
visibilityTime = initialOptions.visibilityTime,
Expand All @@ -84,6 +88,8 @@ export function useToast({ defaultOptions }: UseToastParams) {
setOptions(
mergeIfDefined(initialOptions, {
type,
text1Style,
text2Style,
position,
autoHide,
visibilityTime,
Expand Down

0 comments on commit 3ae6f01

Please sign in to comment.