Skip to content

Commit

Permalink
chore/fixing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Imperio authored and Felipe Imperio committed Aug 26, 2024
1 parent 5460f5c commit 6b9bc2c
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 30 deletions.
3 changes: 3 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@
"type_placeholder": "Please type text",
"paragraph_placeholder": "Type in your answer here."
},
"character_counter":{
"characters":"characters"
},
"additional": {
"server-error": "Server error occurred",
"time-end": "Time is up!",
Expand Down
3 changes: 3 additions & 0 deletions assets/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@
"type_placeholder": "Veuiller saisir du texte",
"paragraph_placeholder": "Tapez votre réponse ici."
},
"character_counter":{
"characters":"caractères"
},
"language_screen": {
"app_language": " Langue de l'application",
"change_app_language": "Changer la langue",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React, { FC } from 'react';

import CharacterCounterText from '../CharacterCounterText';
import { useTranslation } from 'react-i18next';

import { CharacterCounterText } from '@shared/ui';

import { colors } from '../lib';

type Props = {
limit: number | string;
numberOfCharacters: number | string;
Expand All @@ -14,12 +19,16 @@ const CharacterCounter: FC<Props> = ({
fontSize = 14,
focused = false,
}) => {
const { t } = useTranslation();

return (
<CharacterCounterText
color={focused ? 'primary' : 'grey4'}
fontSize={fontSize}
style={{
fontSize,
color: focused ? colors.primary : colors.grey4,
}}
>
{numberOfCharacters}/{limit} characters
{numberOfCharacters}/{limit} {t('character_counter:characters')}
</CharacterCounterText>
);
};
Expand Down
18 changes: 3 additions & 15 deletions src/shared/ui/CharacterCounterText.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Text } from 'react-native';

import { setupReactNative, styled } from '@tamagui/core';
import { focusableInputHOC } from '@tamagui/focusable';

import { colors } from '../lib';

setupReactNative({
Text,
});

export const CharacterCounterText = styled(
const CharacterCounterText = styled(
Text,
{
name: 'CharacterCounterText',
Expand All @@ -24,19 +21,10 @@ export const CharacterCounterText = styled(
style: {
fontWeight: '400',
},

variants: {
fontSize: (fontSize: number) => ({
fontSize,
}),
color: (color: keyof typeof colors) => ({
color: colors[color] || color,
}),
},
},
{
inlineProps: new Set(['fontSize', 'color']),
inlineProps: new Set(['style']),
},
);

export default focusableInputHOC(CharacterCounterText);
export default CharacterCounterText;
4 changes: 4 additions & 0 deletions src/shared/ui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import CheckBox from '@react-native-community/checkbox';

import Center from './Center';
import CharacterCounter from './CharacterCounter';
import CharacterCounterText from './CharacterCounterText';
import Input from './Input';
import KeyboardAvoidingView from './KeyboardAvoidingView';
import Link from './Link';
Expand Down Expand Up @@ -48,6 +50,8 @@ export {
KeyboardAvoidingView,
Input,
LongTextInput,
CharacterCounter,
CharacterCounterText,
CheckBox,
ScrollView,
RowButton,
Expand Down
4 changes: 1 addition & 3 deletions src/shared/ui/survey/ParagraphText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { StyleSheet, TextInputProps, View } from 'react-native';
import { useTranslation } from 'react-i18next';

import { colors } from '@shared/lib';
import { LongTextInput } from '@shared/ui';

import CharacterCounter from './CharacterCounter';
import { LongTextInput, CharacterCounter } from '@shared/ui';

type Props = {
onChange: (text: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import React from 'react';
import renderer from 'react-test-renderer';

import TamaguiProvider from '@app/app/ui/AppProvider/TamaguiProvider';

import CharacterCounterText from '../../CharacterCounterText';
import CharacterCounter from '../CharacterCounter';
import { CharacterCounterText, CharacterCounter } from '@shared/ui';

describe('CharacterCounter Component', () => {
it('Should renders correctly with default props', () => {
it('Should render correctly with default props', () => {
const tree = renderer
.create(
<TamaguiProvider>
Expand All @@ -28,7 +26,9 @@ describe('CharacterCounter Component', () => {
);

const textElement = tree.root.findByType(CharacterCounterText);
expect(textElement.props.fontSize).toBe(20);
expect(textElement.props.style).toEqual(
expect.objectContaining({ color: '#72777F', fontSize: 20 }),
);
});

it('Should apply the primary color when focused', () => {
Expand All @@ -39,7 +39,9 @@ describe('CharacterCounter Component', () => {
);

const textElement = tree.root.findByType(CharacterCounterText);
expect(textElement.props.color).toBe('primary');
expect(textElement.props.style).toEqual(
expect.objectContaining({ color: '#0067A0', fontSize: 14 }),
);
});

it('Should apply the grey color when not focused', () => {
Expand All @@ -50,7 +52,9 @@ describe('CharacterCounter Component', () => {
);

const textElement = tree.root.findByType(CharacterCounterText);
expect(textElement.props.color).toBe('grey4');
expect(textElement.props.style).toEqual(
expect.objectContaining({ color: '#72777F', fontSize: 14 }),
);
});

it('Should display the correct character count', () => {
Expand All @@ -66,6 +70,6 @@ describe('CharacterCounter Component', () => {
? textElement.props.children.join('')
: textElement.props.children;

expect(characterCountText).toBe('150/200 characters');
expect(characterCountText).toBe('150/200 character_counter:characters');
});
});
70 changes: 70 additions & 0 deletions src/shared/ui/tests/__snapshots__/CharacterCounter.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CharacterCounter Component Should render correctly with default props 1`] = `
<Text
focusable={true}
style={
[
{
"borderBottomWidth": 0,
"borderLeftWidth": 0,
"borderRightWidth": 0,
"borderStyle": "solid",
"borderTopWidth": 0,
"color": "#72777F",
"flex": 1,
"fontSize": 14,
"marginBottom": 2,
"marginLeft": 2,
"marginRight": 10,
"marginTop": 2,
"paddingBottom": 2,
"paddingLeft": 2,
"paddingRight": 2,
"paddingTop": 2,
},
]
}
>
50
/
100
character_counter:characters
</Text>
`;

exports[`CharacterCounter Component Should renders correctly with default props 1`] = `
<Text
color="grey4"
focusable={true}
fontSize={14}
style={
[
{
"borderBottomWidth": 0,
"borderLeftWidth": 0,
"borderRightWidth": 0,
"borderStyle": "solid",
"borderTopWidth": 0,
"flex": 1,
"fontWeight": "400",
"marginBottom": 2,
"marginLeft": 2,
"marginRight": 10,
"marginTop": 2,
"paddingBottom": 2,
"paddingLeft": 2,
"paddingRight": 2,
"paddingTop": 2,
},
]
}
>
50
/
100
character_counter:characters
</Text>
`;

0 comments on commit 6b9bc2c

Please sign in to comment.