Skip to content

Commit b5defc9

Browse files
Karthik-B-06kodiakhq[bot]
authored andcommitted
chore(tag): ⚡ wrap tailwind classnames with cx, wrap textStyle inside styleAdapter
1 parent f39de78 commit b5defc9

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

src/components/tag/Tag.tsx

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PressableProps, TextStyle } from "react-native";
44
import { Close } from "../../icons";
55
import { Box, Text, Touchable } from "../../primitives";
66
import { useTheme } from "../../theme";
7-
import { createComponent, RenderPropType, styleAdapter } from "../../utils";
7+
import { createComponent, cx, RenderPropType, styleAdapter } from "../../utils";
88
import { createIcon } from "../create-icon";
99
import { Icon } from "../icon";
1010

@@ -15,7 +15,7 @@ export type TagTheme = "base" | "primary";
1515
export interface TagProps extends PressableProps {
1616
/**
1717
* The size of the Tag component.
18-
* @default lg
18+
* @default md
1919
*/
2020
size: TagSizes;
2121
/**
@@ -64,6 +64,7 @@ const RNTag: React.FC<Partial<TagProps>> = forwardRef<
6464
prefix,
6565
suffix = closable ? <Icon icon={<Close />} /> : null,
6666
style,
67+
textStyle,
6768
...otherProps
6869
} = props;
6970

@@ -75,14 +76,18 @@ const RNTag: React.FC<Partial<TagProps>> = forwardRef<
7576
createIcon({
7677
icon: prefix,
7778
iconFill: tailwind.getColor(
78-
props.disabled
79-
? tagTheme.themeColor[themeColor]?.[variant]?.icon?.disabled
80-
: tagTheme.themeColor[themeColor]?.[variant]?.icon?.default,
79+
cx(
80+
props.disabled
81+
? tagTheme.themeColor[themeColor]?.[variant]?.icon?.disabled
82+
: tagTheme.themeColor[themeColor]?.[variant]?.icon?.default,
83+
),
8184
),
82-
iconStyle: tailwind.style(tagTheme.size[size]?.prefix),
85+
iconStyle: tailwind.style(cx(tagTheme.size[size]?.prefix)),
8386
})
8487
) : (
85-
<Box style={[tailwind.style(tagTheme.size[size]?.prefix)]}>{prefix}</Box>
88+
<Box style={tailwind.style(cx(tagTheme.size[size]?.prefix))}>
89+
{prefix}
90+
</Box>
8691
));
8792

8893
/* Suffix Slot */
@@ -93,14 +98,18 @@ const RNTag: React.FC<Partial<TagProps>> = forwardRef<
9398
createIcon({
9499
icon: suffix,
95100
iconFill: tailwind.getColor(
96-
props.disabled
97-
? tagTheme.themeColor[themeColor]?.[variant]?.icon?.disabled
98-
: tagTheme.themeColor[themeColor]?.[variant]?.icon?.default,
101+
cx(
102+
props.disabled
103+
? tagTheme.themeColor[themeColor]?.[variant]?.icon?.disabled
104+
: tagTheme.themeColor[themeColor]?.[variant]?.icon?.default,
105+
),
99106
),
100-
iconStyle: tailwind.style(tagTheme.size[size]?.suffix),
107+
iconStyle: tailwind.style(cx(tagTheme.size[size]?.suffix)),
101108
})
102109
) : (
103-
<Box style={[tailwind.style(tagTheme.size[size]?.suffix)]}>{suffix}</Box>
110+
<Box style={tailwind.style(cx(tagTheme.size[size]?.suffix))}>
111+
{suffix}
112+
</Box>
104113
));
105114

106115
/**
@@ -111,13 +120,15 @@ const RNTag: React.FC<Partial<TagProps>> = forwardRef<
111120
<Text
112121
style={[
113122
tailwind.style(
114-
tagTheme.size[size]?.text,
115-
tagTheme.themeColor[themeColor]?.[variant]?.text?.default,
116-
props.disabled
117-
? tagTheme.themeColor[themeColor]?.[variant]?.text?.disabled
118-
: "",
123+
cx(
124+
tagTheme.size[size]?.text,
125+
tagTheme.themeColor[themeColor]?.[variant]?.text?.default,
126+
props.disabled
127+
? tagTheme.themeColor[themeColor]?.[variant]?.text?.disabled
128+
: "",
129+
),
119130
),
120-
{ ...props.textStyle },
131+
styleAdapter(textStyle, { pressed: false }, false),
121132
]}
122133
adjustsFontSizeToFit
123134
allowFontScaling={false}
@@ -133,15 +144,17 @@ const RNTag: React.FC<Partial<TagProps>> = forwardRef<
133144
ref={ref}
134145
style={touchState => [
135146
tailwind.style(
136-
tagTheme.base,
137-
tagTheme.size[size]?.default,
138-
tagTheme.themeColor[themeColor]?.[variant]?.container?.wrapper,
139-
touchState.pressed
140-
? tagTheme.themeColor[themeColor]?.[variant]?.container?.pressed
141-
: "",
142-
props.disabled
143-
? tagTheme.themeColor[themeColor]?.[variant]?.container?.disabled
144-
: "",
147+
cx(
148+
tagTheme.base,
149+
tagTheme.size[size]?.default,
150+
tagTheme.themeColor[themeColor]?.[variant]?.container?.wrapper,
151+
touchState.pressed
152+
? tagTheme.themeColor[themeColor]?.[variant]?.container?.pressed
153+
: "",
154+
props.disabled
155+
? tagTheme.themeColor[themeColor]?.[variant]?.container?.disabled
156+
: "",
157+
),
145158
),
146159
styleAdapter(style, touchState, true),
147160
]}

0 commit comments

Comments
 (0)