Skip to content

Commit

Permalink
Merge pull request #75 from Trendyol/feat/rtl
Browse files Browse the repository at this point in the history
feat(rtl) added RTL compatibility to components
  • Loading branch information
pinarkizilarslan authored Dec 25, 2024
2 parents 4d652cd + fb81638 commit 3f8d409
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 99 deletions.
16 changes: 13 additions & 3 deletions src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Pressable, StyleSheet } from 'react-native';
import { Pressable, StyleSheet, I18nManager } from 'react-native';
import {
VariantProps,
createRestyleComponent,
Expand Down Expand Up @@ -34,6 +34,8 @@ const AlertContainer = createRestyleComponent<
Theme
>([variantVariant], Box);

const isRTL = I18nManager.isRTL;

const Alert = ({
variant = 'info',
icon,
Expand All @@ -57,13 +59,21 @@ const Alert = ({
</Box>
<Box flex={1}>
{caption ? (
<Text variant="subtitle03Medium" pb="2xs" testID="alert-caption">
<Text
variant="subtitle03Medium"
pb="2xs"
testID="alert-caption"
textAlign={isRTL ? 'left' : 'right'}>
{caption}
</Text>
) : null}

{description ? (
<Text testID="alert-description">{description}</Text>
<Text
testID="alert-description"
textAlign={isRTL ? 'left' : 'right'}>
{description}
</Text>
) : null}

{children ? (
Expand Down
2 changes: 2 additions & 0 deletions src/components/Alert/__snapshots__/Alert.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ exports[`Alert should render alert correctly 1`] = `
"fontWeight": "500",
"lineHeight": 16,
"paddingBottom": 8,
"textAlign": "right",
},
]
}
Expand All @@ -140,6 +141,7 @@ exports[`Alert should render alert correctly 1`] = `
"color": "#273142",
"fontFamily": "Rubik-Regular",
"fontSize": 14,
"textAlign": "right",
},
]
}
Expand Down
13 changes: 7 additions & 6 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TextInput,
TextInputProps,
TextInputFocusEventData,
I18nManager,
} from 'react-native';
import theme, { Theme } from '../../theme';
import Box from '../Box/Box';
Expand Down Expand Up @@ -35,7 +36,7 @@ import Text from '../Text/Text';
type InputProps = React.ComponentProps<typeof Box> &
TextInputProps & {
label?: string | null;
subLabel?: string | null;
subLabel?: string;
labelFixed?: boolean;
placeholder?: string;
helpText?: string | null;
Expand Down Expand Up @@ -76,12 +77,14 @@ export type TextInputHandles = Pick<
'focus' | 'clear' | 'blur' | 'isFocused' | 'setNativeProps'
>;

const isRTL = I18nManager.isRTL;

const Input = forwardRef<TextInputHandles, InputProps>(
(
{
size = 'large',
label,
subLabel,
subLabel = '',
labelFixed,
placeholder,
helpText,
Expand Down Expand Up @@ -120,7 +123,6 @@ const Input = forwardRef<TextInputHandles, InputProps>(
subLabel,
labelFixed,
placeholder,
required,
value,
focused,
});
Expand Down Expand Up @@ -235,10 +237,8 @@ const Input = forwardRef<TextInputHandles, InputProps>(
<Box py={'2xs'}>
<InputLabel
label={label}
subLabel={` ${subLabel}`}
subLabel={` ${subLabel} `}
labelFixed={labelFixed}
required={required}
requiredText={requiredText}
errorState={errorState}
successState={successState}
animatedViewProps={animatedViewProps}
Expand Down Expand Up @@ -284,6 +284,7 @@ const Input = forwardRef<TextInputHandles, InputProps>(
editable={!disabled}
accessibilityLabel={testID}
testID={testID}
textAlign={isRTL ? 'right' : 'left'}
/>
{trailingText ? (
<Box ml="m" mr={icon ? 'm' : 'none'}>
Expand Down
8 changes: 7 additions & 1 deletion src/components/Input/InputHelpText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import Box from '../Box/Box';
import Text from '../Text/Text';
import { getHelpText, getTextColor } from './utils';
import { I18nManager } from 'react-native';

const isRTL = I18nManager.isRTL;

export const InputHelpText = React.memo(
({
Expand Down Expand Up @@ -33,7 +36,10 @@ export const InputHelpText = React.memo(

return content ? (
<Box mt="3xs" ml="m">
<Text variant="subtitle04Regular" color={textColor}>
<Text
variant="subtitle04Regular"
color={textColor}
textAlign={isRTL ? 'left' : 'right'}>
{content}
</Text>
</Box>
Expand Down
17 changes: 8 additions & 9 deletions src/components/Input/InputLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import { Animated } from 'react-native';
import { Animated, I18nManager } from 'react-native';
import Box from '../Box/Box';
import Text from '../Text/Text';
import { AnimatedTextPropsType, AnimatedViewPropsType } from './types';
import { getLabelColor } from './utils';

const isRTL = I18nManager.isRTL;

export const InputLabel = React.memo(
({
label,
subLabel,
labelFixed,
required,
requiredText,
errorState,
successState,
animatedViewProps,
Expand All @@ -21,8 +21,6 @@ export const InputLabel = React.memo(
label?: string | null;
subLabel?: string | null;
labelFixed?: boolean;
required?: boolean;
requiredText?: boolean;
errorState: boolean;
successState: boolean;
animatedViewProps: AnimatedViewPropsType;
Expand All @@ -44,9 +42,9 @@ export const InputLabel = React.memo(
testID="fixed-label">
{label}
</Text>
{!required && requiredText ? (
{subLabel ? (
<Text
testID="optional-fixed-label"
testID="subLabel"
ml="4xs"
variant="subtitle04Regular"
color="neutralLight">
Expand All @@ -66,8 +64,9 @@ export const InputLabel = React.memo(
height={inputHeight + 6}
testID="outlined-label-box">
<Animated.Text {...animatedTextProps}>
{label}
{subLabel ?? ''}
{isRTL
? `${subLabel ?? ''}${label}`
: `${label}${subLabel ?? ''}`}
</Animated.Text>
</Box>
</Animated.View>
Expand Down
Loading

0 comments on commit 3f8d409

Please sign in to comment.