Skip to content

Commit aa856a6

Browse files
committed
refactor(button): streamline variant and action props handling for improved clarity
1 parent 0eeddad commit aa856a6

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

apps/starter-kit-expo/components/ui/badge/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client';
2-
import React from 'react';
2+
import React, { useMemo } from 'react';
33
import { Text, View } from 'react-native';
44
import { PrimitiveIcon, UIIcon } from '@gluestack-ui/core/icon/creator';
55
import { tva } from '@gluestack-ui/utils/nativewind-utils';
@@ -120,15 +120,17 @@ function Badge({
120120
className,
121121
...props
122122
}: { className?: string } & IBadgeProps) {
123+
124+
const contextValue = useMemo(
125+
() => ({ action, variant, size }),
126+
[action, variant, size]
127+
);
128+
123129
return (
124130
<ContextView
125131
className={badgeStyle({ action, variant, class: className })}
126132
{...props}
127-
context={{
128-
action,
129-
variant,
130-
size,
131-
}}
133+
context={contextValue}
132134
>
133135
{children}
134136
</ContextView>
@@ -211,4 +213,4 @@ Badge.displayName = 'Badge';
211213
BadgeText.displayName = 'BadgeText';
212214
BadgeIcon.displayName = 'BadgeIcon';
213215

214-
export { Badge, BadgeIcon, BadgeText };
216+
export { Badge, BadgeIcon, BadgeText };

apps/starter-kit-expo/components/ui/button/index.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use client';
22
import React from 'react';
33
import { createButton } from '@gluestack-ui/core/button/creator';
4-
import { tva } from '@gluestack-ui/utils/nativewind-utils';
54
import {
5+
tva,
66
withStyleContext,
77
useStyleContext,
8+
type VariantProps,
89
} from '@gluestack-ui/utils/nativewind-utils';
910
import { cssInterop } from 'nativewind';
1011
import { ActivityIndicator, Pressable, Text, View } from 'react-native';
11-
import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils';
1212
import { PrimitiveIcon, UIIcon } from '@gluestack-ui/core/icon/creator';
1313

1414
const SCOPE = 'BUTTON';
@@ -326,14 +326,9 @@ const ButtonText = React.forwardRef<
326326
size: parentSize,
327327
action: parentAction,
328328
},
329-
variant: variant as 'link' | 'outline' | 'solid' | undefined,
329+
variant,
330330
size,
331-
action: action as
332-
| 'primary'
333-
| 'secondary'
334-
| 'positive'
335-
| 'negative'
336-
| undefined,
331+
action,
337332
class: className,
338333
})}
339334
/>
@@ -420,8 +415,8 @@ const ButtonGroup = React.forwardRef<
420415
className={buttonGroupStyle({
421416
class: className,
422417
space,
423-
isAttached: isAttached as boolean,
424-
flexDirection: flexDirection as any,
418+
isAttached,
419+
flexDirection,
425420
})}
426421
{...props}
427422
ref={ref}

apps/starter-kit-next/components/ui/badge/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client';
2-
import React from 'react';
2+
import React, { useMemo } from 'react';
33
import { Text, View } from 'react-native';
44
import { PrimitiveIcon, UIIcon } from '@gluestack-ui/core/icon/creator';
55
import { tva } from '@gluestack-ui/utils/nativewind-utils';
@@ -120,15 +120,17 @@ function Badge({
120120
className,
121121
...props
122122
}: { className?: string } & IBadgeProps) {
123+
124+
const contextValue = useMemo(
125+
() => ({ action, variant, size }),
126+
[action, variant, size]
127+
);
128+
123129
return (
124130
<ContextView
125131
className={badgeStyle({ action, variant, class: className })}
126132
{...props}
127-
context={{
128-
action,
129-
variant,
130-
size,
131-
}}
133+
context={contextValue}
132134
>
133135
{children}
134136
</ContextView>
@@ -211,4 +213,4 @@ Badge.displayName = 'Badge';
211213
BadgeText.displayName = 'BadgeText';
212214
BadgeIcon.displayName = 'BadgeIcon';
213215

214-
export { Badge, BadgeIcon, BadgeText };
216+
export { Badge, BadgeIcon, BadgeText };

apps/starter-kit-next/components/ui/button/index.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use client';
22
import React from 'react';
33
import { createButton } from '@gluestack-ui/core/button/creator';
4-
import { tva } from '@gluestack-ui/utils/nativewind-utils';
54
import {
5+
tva,
66
withStyleContext,
77
useStyleContext,
8+
type VariantProps,
89
} from '@gluestack-ui/utils/nativewind-utils';
910
import { cssInterop } from 'nativewind';
1011
import { ActivityIndicator, Pressable, Text, View } from 'react-native';
11-
import type { VariantProps } from 'tailwind-variants';
1212
import { PrimitiveIcon, UIIcon } from '@gluestack-ui/core/icon/creator';
1313

1414
const SCOPE = 'BUTTON';
@@ -326,14 +326,9 @@ const ButtonText = React.forwardRef<
326326
size: parentSize,
327327
action: parentAction,
328328
},
329-
variant: variant as 'link' | 'outline' | 'solid' | undefined,
329+
variant,
330330
size,
331-
action: action as
332-
| 'primary'
333-
| 'secondary'
334-
| 'positive'
335-
| 'negative'
336-
| undefined,
331+
action,
337332
class: className,
338333
})}
339334
/>
@@ -420,8 +415,8 @@ const ButtonGroup = React.forwardRef<
420415
className={buttonGroupStyle({
421416
class: className,
422417
space,
423-
isAttached: isAttached as boolean,
424-
flexDirection: flexDirection as any,
418+
isAttached,
419+
flexDirection,
425420
})}
426421
{...props}
427422
ref={ref}

0 commit comments

Comments
 (0)