-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f59e08
commit 35ac181
Showing
4 changed files
with
135 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react'; | ||
import { | ||
View, | ||
ColorValue, | ||
StyleProp, | ||
ViewStyle, | ||
StyleSheet, | ||
} from 'react-native'; | ||
|
||
type OutlineProps = { | ||
isV3: boolean; | ||
activeColor: string; | ||
backgroundColor: ColorValue; | ||
hasActiveOutline?: boolean; | ||
focused?: boolean; | ||
outlineColor?: string; | ||
roundness?: number; | ||
style?: StyleProp<ViewStyle>; | ||
}; | ||
|
||
export const Outline = ({ | ||
isV3, | ||
activeColor, | ||
backgroundColor, | ||
hasActiveOutline, | ||
focused, | ||
outlineColor, | ||
roundness, | ||
style, | ||
}: OutlineProps) => ( | ||
<View | ||
testID="text-input-outline" | ||
pointerEvents="none" | ||
style={[ | ||
styles.outline, | ||
// eslint-disable-next-line react-native/no-inline-styles | ||
{ | ||
backgroundColor, | ||
borderRadius: roundness, | ||
borderWidth: (isV3 ? hasActiveOutline : focused) ? 2 : 1, | ||
borderColor: hasActiveOutline ? activeColor : outlineColor, | ||
}, | ||
style, | ||
]} | ||
/> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
outline: { | ||
position: 'absolute', | ||
left: 0, | ||
right: 0, | ||
top: 6, | ||
bottom: 0, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as React from 'react'; | ||
import { Animated, StyleSheet, StyleProp, ViewStyle } from 'react-native'; | ||
|
||
import { useInternalTheme } from '../../../core/theming'; | ||
import type { ThemeProp } from '../../../types'; | ||
|
||
type UnderlineProps = { | ||
parentState: { | ||
focused: boolean; | ||
}; | ||
error?: boolean; | ||
colors?: { | ||
error?: string; | ||
}; | ||
activeColor: string; | ||
underlineColorCustom?: string; | ||
hasActiveOutline?: boolean; | ||
style?: StyleProp<ViewStyle>; | ||
theme?: ThemeProp; | ||
}; | ||
|
||
export const Underline = ({ | ||
parentState, | ||
error, | ||
colors, | ||
activeColor, | ||
underlineColorCustom, | ||
hasActiveOutline, | ||
style, | ||
theme: themeOverrides, | ||
}: UnderlineProps) => { | ||
const { isV3 } = useInternalTheme(themeOverrides); | ||
|
||
let backgroundColor = parentState.focused | ||
? activeColor | ||
: underlineColorCustom; | ||
|
||
if (error) backgroundColor = colors?.error; | ||
|
||
const activeScale = isV3 ? 2 : 1; | ||
|
||
return ( | ||
<Animated.View | ||
testID="text-input-underline" | ||
style={[ | ||
styles.underline, | ||
isV3 && styles.md3Underline, | ||
{ | ||
backgroundColor, | ||
// Underlines is thinner when input is not focused | ||
transform: [ | ||
{ | ||
scaleY: (isV3 ? hasActiveOutline : parentState.focused) | ||
? activeScale | ||
: 0.5, | ||
}, | ||
], | ||
}, | ||
style, | ||
]} | ||
/> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
underline: { | ||
position: 'absolute', | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
height: 2, | ||
zIndex: 1, | ||
}, | ||
md3Underline: { | ||
height: 1, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters