@@ -17,7 +17,7 @@ import PressableWithoutFeedback from './PressableWithoutFeedback';
1717
1818type PressableWithDelayToggleProps = PressableProps & {
1919 /** The text to display */
20- text : string ;
20+ text ? : string ;
2121
2222 /** The text to display once the pressable is pressed */
2323 textChecked ?: string ;
@@ -55,6 +55,18 @@ type PressableWithDelayToggleProps = PressableProps & {
5555 * Reference to the outer element
5656 */
5757 ref ?: PressableRef ;
58+
59+ /** Whether to use background color based on button states, e.g., hovered, active, pressed... */
60+ shouldUseButtonBackground ?: boolean ;
61+
62+ /** Whether to always use active (hovered) background by default */
63+ shouldHaveActiveBackground ?: boolean ;
64+
65+ /** Icon width */
66+ iconWidth ?: number ;
67+
68+ /** Icon height */
69+ iconHeight ?: number ;
5870} ;
5971
6072function PressableWithDelayToggle ( {
@@ -69,8 +81,12 @@ function PressableWithDelayToggle({
6981 textStyles,
7082 iconStyles,
7183 icon,
72- accessibilityRole,
7384 ref,
85+ accessibilityRole,
86+ shouldHaveActiveBackground,
87+ iconWidth = variables . iconSizeSmall ,
88+ iconHeight = variables . iconSizeSmall ,
89+ shouldUseButtonBackground = false ,
7490} : PressableWithDelayToggleProps ) {
7591 const styles = useThemeStyles ( ) ;
7692 const StyleUtils = useStyleUtils ( ) ;
@@ -89,15 +105,17 @@ function PressableWithDelayToggle({
89105 // of a Pressable
90106 const PressableView = inline ? Text : PressableWithoutFeedback ;
91107 const tooltipTexts = ! isActive ? tooltipTextChecked : tooltipText ;
92- const labelText = (
93- < Text
94- suppressHighlighting
95- style = { textStyles }
96- >
97- { ! isActive && textChecked ? textChecked : text }
98-
99- </ Text >
100- ) ;
108+ const labelText =
109+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- Disabling this line for safeness as nullish coalescing works only if the value is undefined or null
110+ text || textChecked ? (
111+ < Text
112+ suppressHighlighting
113+ style = { textStyles }
114+ >
115+ { ! isActive && textChecked ? textChecked : text }
116+
117+ </ Text >
118+ ) : null ;
101119
102120 return (
103121 < PressableView
@@ -119,7 +137,16 @@ function PressableWithDelayToggle({
119137 tabIndex = { - 1 }
120138 accessible = { false }
121139 onPress = { updatePressState }
122- style = { [ styles . flexRow , pressableStyle , ! isActive && styles . cursorDefault ] }
140+ style = { ( { hovered, pressed} ) => [
141+ styles . flexRow ,
142+ pressableStyle ,
143+ ! isActive && styles . cursorDefault ,
144+ shouldUseButtonBackground &&
145+ StyleUtils . getButtonBackgroundColorStyle (
146+ getButtonState ( ! ! shouldHaveActiveBackground || hovered , shouldHaveActiveBackground ? hovered : pressed , ! shouldHaveActiveBackground && ! isActive ) ,
147+ true ,
148+ ) ,
149+ ] }
123150 >
124151 { ( { hovered, pressed} ) => (
125152 < >
@@ -129,8 +156,8 @@ function PressableWithDelayToggle({
129156 src = { ! isActive ? iconChecked : icon }
130157 fill = { StyleUtils . getIconFillColor ( getButtonState ( hovered , pressed , ! isActive ) ) }
131158 additionalStyles = { iconStyles }
132- width = { variables . iconSizeSmall }
133- height = { variables . iconSizeSmall }
159+ width = { iconWidth }
160+ height = { iconHeight }
134161 inline = { inline }
135162 />
136163 ) }
@@ -146,3 +173,4 @@ function PressableWithDelayToggle({
146173PressableWithDelayToggle . displayName = 'PressableWithDelayToggle' ;
147174
148175export default PressableWithDelayToggle ;
176+ export type { PressableWithDelayToggleProps } ;
0 commit comments