11import React , { forwardRef } from "react" ;
2- import { PressableProps , TextStyle , ViewStyle } from "react-native" ;
2+ import { PressableProps , TextStyle } from "react-native" ;
33
4+ import { Close } from "../../icons" ;
45import { Box , Text , Touchable } from "../../primitives" ;
56import { useTheme } from "../../theme" ;
6- import { createComponent , RenderPropType } from "../../utils" ;
7+ import { createComponent , RenderPropType , styleAdapter } from "../../utils" ;
78import { createIcon } from "../create-icon" ;
89import { Icon } from "../icon" ;
910
10- import { useTagProps } from "./TagProps" ;
11-
1211export type TagSizes = "sm" | "md" | "lg" | "xl" ;
1312export type TagVariant = "solid" | "subtle" | "outline" ;
13+ export type TagTheme = "base" | "primary" ;
1414
1515export interface TagProps extends PressableProps {
1616 /**
@@ -23,6 +23,11 @@ export interface TagProps extends PressableProps {
2323 * @default solid
2424 */
2525 variant : TagVariant ;
26+ /**
27+ * The Theme of the Tag component.
28+ * @default base
29+ */
30+ themeColor : TagTheme ;
2631 /**
2732 * A Prefix Element.
2833 * If added, the Tag will show a prefix Element before the Tag's text.
@@ -38,11 +43,6 @@ export interface TagProps extends PressableProps {
3843 * If yes, the Tag will show a Close Icon after the Tag's text or Suffix.
3944 */
4045 closable : boolean ;
41- /**
42- * The Container style of the Tag component.
43- * @default {}
44- */
45- touchableContainerStyle : ViewStyle ;
4646 /**
4747 * The Text style of the Tag component.
4848 * @default {}
@@ -56,78 +56,100 @@ const RNTag: React.FC<Partial<TagProps>> = forwardRef<
5656> ( ( props , ref ) => {
5757 const tailwind = useTheme ( ) ;
5858 const tagTheme = useTheme ( "tag" ) ;
59-
6059 const {
61- _tagLibProps : { size, variant } ,
62- _tagOptions : { suffix, prefix } ,
63- } = useTagProps ( props ) ;
60+ size = "md" ,
61+ variant = "solid" ,
62+ themeColor = "base" ,
63+ closable = false ,
64+ prefix,
65+ suffix = closable ? < Icon icon = { < Close /> } /> : null ,
66+ style,
67+ ...otherProps
68+ } = props ;
69+
70+ /* Prefix Slot */
71+ const _prefix =
72+ prefix &&
73+ // @ts -ignore
74+ ( prefix ?. type === Icon ? (
75+ createIcon ( {
76+ icon : prefix ,
77+ iconFill : tailwind . getColor (
78+ props . disabled
79+ ? tagTheme . themeColor [ themeColor ] ?. [ variant ] ?. icon ?. disabled
80+ : tagTheme . themeColor [ themeColor ] ?. [ variant ] ?. icon ?. default ,
81+ ) ,
82+ iconStyle : tailwind . style ( tagTheme . size [ size ] ?. prefix ) ,
83+ } )
84+ ) : (
85+ < Box style = { [ tailwind . style ( tagTheme . size [ size ] ?. prefix ) ] } > { prefix } </ Box >
86+ ) ) ;
87+
88+ /* Suffix Slot */
89+ const _suffix =
90+ suffix &&
91+ // @ts -ignore
92+ ( suffix ?. type === Icon ? (
93+ createIcon ( {
94+ icon : suffix ,
95+ iconFill : tailwind . getColor (
96+ props . disabled
97+ ? tagTheme . themeColor [ themeColor ] ?. [ variant ] ?. icon ?. disabled
98+ : tagTheme . themeColor [ themeColor ] ?. [ variant ] ?. icon ?. default ,
99+ ) ,
100+ iconStyle : tailwind . style ( tagTheme . size [ size ] ?. suffix ) ,
101+ } )
102+ ) : (
103+ < Box style = { [ tailwind . style ( tagTheme . size [ size ] ?. suffix ) ] } > { suffix } </ Box >
104+ ) ) ;
105+
106+ /**
107+ * Tag Children
108+ */
109+ const children =
110+ typeof otherProps . children === "string" ? (
111+ < Text
112+ style = { [
113+ 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+ : "" ,
119+ ) ,
120+ { ...props . textStyle } ,
121+ ] }
122+ adjustsFontSizeToFit
123+ allowFontScaling = { false }
124+ >
125+ { props . children }
126+ </ Text >
127+ ) : (
128+ props . children
129+ ) ;
130+
64131 return (
65132 < Touchable
66133 ref = { ref }
67- style = { ( { pressed } ) => [
134+ style = { touchState => [
68135 tailwind . style (
69136 tagTheme . base ,
70- tagTheme . size . default [ size ] ,
71- tagTheme . variant . default [ variant ] ,
72- pressed && tagTheme . variant . pressed [ variant ] ,
73- props . disabled && tagTheme . variant . disabled [ variant ] ,
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+ : "" ,
74145 ) ,
75- { ... props . touchableContainerStyle } ,
146+ styleAdapter ( style , touchState , true ) ,
76147 ] }
77- { ...props }
148+ { ...otherProps }
78149 >
79- { prefix &&
80- // @ts -ignore
81- ( prefix ?. type === Icon ? (
82- createIcon ( {
83- icon : prefix ,
84- iconFill : tailwind . getColor (
85- props . disabled
86- ? tagTheme . variant . icon . disabled [ variant ]
87- : tagTheme . variant . icon . default [ variant ] ,
88- ) ,
89- iconStyle : tailwind . style ( tagTheme . size . prefix [ size ] ) ,
90- } )
91- ) : (
92- < Box style = { [ tailwind . style ( tagTheme . size . prefix [ size ] ) ] } >
93- { prefix }
94- </ Box >
95- ) ) }
96- { typeof props . children === "string" ? (
97- < Text
98- style = { [
99- tailwind . style (
100- tagTheme . size . text [ size ] ,
101- tagTheme . variant . text . default [ variant ] ,
102- props . disabled && tagTheme . variant . text . disabled [ variant ] ,
103- ) ,
104- { ...props . textStyle } ,
105- ] }
106- adjustsFontSizeToFit
107- allowFontScaling = { false }
108- >
109- { props . children }
110- </ Text >
111- ) : (
112- props . children
113- ) }
114- { suffix &&
115- // @ts -ignore
116- ( suffix ?. type === Icon ? (
117- createIcon ( {
118- icon : suffix ,
119- iconFill : tailwind . getColor (
120- props . disabled
121- ? tagTheme . variant . icon . disabled [ variant ]
122- : tagTheme . variant . icon . default [ variant ] ,
123- ) ,
124- iconStyle : tailwind . style ( tagTheme . size . suffix [ size ] ) ,
125- } )
126- ) : (
127- < Box style = { [ tailwind . style ( tagTheme . size . suffix [ size ] ) ] } >
128- { suffix }
129- </ Box >
130- ) ) }
150+ { _prefix }
151+ { children }
152+ { closable && _suffix }
131153 </ Touchable >
132154 ) ;
133155} ) ;
0 commit comments