Skip to content

Commit

Permalink
refactor: add variants to animated texts
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Mar 8, 2022
1 parent fd31546 commit 754ec46
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/components/TextInput/Label/InputLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import { Animated, StyleSheet } from 'react-native';
import AnimatedText from '../../Typography/AnimatedText';
import { useTheme } from '../../../core/theming';

import type { InputLabelProps } from '../types';

const InputLabel = (props: InputLabelProps) => {
const { isV3 } = useTheme();
const { parentState, labelBackground, mode } = props;
const {
label,
Expand Down Expand Up @@ -95,6 +97,7 @@ const InputLabel = (props: InputLabelProps) => {
labelProps: props.labelProps,
})}
<AnimatedText
variant="bodySmall"
onLayout={onLayoutAnimatedText}
style={[
placeholderStyle,
Expand All @@ -110,12 +113,14 @@ const InputLabel = (props: InputLabelProps) => {
outputRange: [hasActiveOutline ? 1 : 0, 0],
}),
},
isV3 && styles.md3TextLine,
]}
numberOfLines={1}
>
{label}
</AnimatedText>
<AnimatedText
variant={parentState.focused ? 'bodyLarge' : 'bodySmall'}
style={[
placeholderStyle,
{
Expand All @@ -132,6 +137,7 @@ const InputLabel = (props: InputLabelProps) => {
: placeholderColor,
opacity: placeholderOpacity,
},
isV3 && styles.md3TextLine,
]}
numberOfLines={1}
>
Expand All @@ -145,6 +151,9 @@ const styles = StyleSheet.create({
labelContainer: {
zIndex: 3,
},
md3TextLine: {
lineHeight: undefined,
},
});

export default InputLabel;
12 changes: 6 additions & 6 deletions src/components/TextInput/Label/LabelBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const LabelBackground = ({
outputRange: [hasFocus ? 1 : 0, 0],
});

const theme = useTheme();
const { isV3, colors } = useTheme();

const labelTranslationX = {
transform: [
Expand Down Expand Up @@ -61,12 +61,12 @@ const LabelBackground = ({
placeholderStyle,
labelStyle,
styles.outlinedLabel,
theme.isV3 && styles.md3OutlinedLabel,
isV3 && styles.md3OutlinedLabel,
{
top: topPosition,
backgroundColor: theme.colors.surface,
top: topPosition + (isV3 ? 0 : 1),
backgroundColor: colors.surface,
opacity,
transform: theme.isV3
transform: isV3
? [...labelStyle.transform]
: [
...labelStyle.transform,
Expand All @@ -78,7 +78,7 @@ const LabelBackground = ({
},
],
},
theme.isV3
isV3
? {
width:
parentState.labelLayout.width -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ exports[`correctly applies height to multiline Outline TextInput 1`] = `
"paddingHorizontal": 0,
"position": "absolute",
"textAlign": "left",
"top": 58,
"top": 59,
"transform": Array [
Object {
"translateX": 0,
Expand Down

0 comments on commit 754ec46

Please sign in to comment.