Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/date field #147

Merged
merged 5 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions src/components/datePicker/DateField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import React, { useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce serait mieux de nommer le dossier "dateSelector" plutôt que datePicker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est clément qui as choisit le nom, c'est un nom commun pour les sélecteurs de dates. J'ai pas d'avis sur la question. Je vais renommer, il y a un vote de ta part, de celle d'Adrien et de Lauren dans son figma ^^

import {
NativeSyntheticEvent,
StyleSheet,
TextInputFocusEventData,
TextInputProps,
} from 'react-native';
import { TextInput } from 'react-native';
import { Theme, useTheme } from '../../styles/themes';

type State =
| 'readonly'
| 'filled'
| 'empty'
| 'filled-focused'
| 'empty-focused'
| 'error';

export interface DateFieldProps extends TextInputProps {
hasError?: boolean;
}

function GetColorsStyle(theme: Theme, state: State) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function GetColorsStyle(theme: Theme, state: State) {
function getColorsStyle(theme: Theme, state: State) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrigé

let backgroundColor, borderColor, textColor;

switch (state) {
case 'filled-focused':
textColor = theme.sw.colors.neutral[800];
backgroundColor = theme.sw.colors.neutral[50];
borderColor = theme.sw.colors.primary.main;
break;
case 'empty-focused':
textColor = theme.sw.colors.primary.main;
borderColor = theme.sw.colors.primary.main;
backgroundColor =
theme.sw.colors.primary.main + theme.sw.transparency[16];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bon bah visiblement on fait comme ça les transparences x)

break;
case 'filled':
textColor = theme.sw.colors.neutral[800];
backgroundColor =
theme.sw.colors.neutral[500] + theme.sw.transparency[8];
break;
case 'error':
textColor = theme.sw.colors.error.main;
backgroundColor =
theme.sw.colors.error.main + theme.sw.transparency[8];
break;
default:
textColor = theme.sw.colors.neutral[500];
backgroundColor =
theme.sw.colors.neutral[500] + theme.sw.transparency[8];
break;
}
return { backgroundColor, borderColor, textColor };
}

function getStyle(theme: Theme, state: State) {
const { backgroundColor, borderColor, textColor } = GetColorsStyle(
theme,
state,
);

const style = StyleSheet.create({
main: {
borderRadius: 18,
height: 48,
borderWidth: borderColor !== undefined ? 1 : 0,
borderColor: borderColor,
width: 72,
color: textColor,
fontFamily: 'PublicSans-Bold',
fontSize: 20,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a pas une font size dans le DS ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet WIP

lineHeight: 48,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne sais pas si c'est important, mais la lineHeight est à 23,5 sur la maquette

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrigé

backgroundColor: backgroundColor,
paddingVertical: 0,
marginVertical: 0,
},
placeholder: {
color:
state === 'empty-focused'
? theme.sw.colors.primary.main
: theme.sw.colors.neutral[500],
},
});
return style;
}

export const DateField: React.FC<DateFieldProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il n'a rien avoir avec la Date non ? et la seul chose qui lui donne accès au nombre c'est le clavier.
pourquoi ne pas laisser l'appelant choisir le clavier et l'appeler inputField ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taille limité à 2 caractères et n'acceptant les chaines de caractères que composés de nombres (pas de virgules, points, ni lettres).

value = '',
hasError,
...props
}) => {
const theme = useTheme();
const [isFocused, setIsFocused] = useState(false);
const state = getState(hasError, isFocused, value);

const style = getStyle(theme, state);

const onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que cet événement est déclenché même si le composant est déjà focus ou pas ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, c'est à dire ? Comment il pourrait être déjà focus ? Si je clique 3 fois dessus à la suite par exemple ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes en effet c'était ça, est-ce que si je clique plusieurs fois dessus je re déclenche l'événement, même si je suis déjà sélectionné ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je viens de checker, l'évènement est déclenché uniquement quand on passe de l'état "unfocused" à l'état "focused"

setIsFocused(true);
if (props.onFocus) {
props.onFocus(e);
}
};

const onBlur = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
setIsFocused(false);
if (props.onBlur) {
props.onBlur(e);
}
};

const onChangeText = (text: string) => {
if (props.onChangeText) {
props.onChangeText(removeNonNumeric(text));
}
};

return (
<TextInput
maxLength={2}
{...props}
style={style.main}
value={value}
onFocus={onFocus}
onBlur={onBlur}
keyboardType='numeric'
cursorColor={theme.sw.colors.primary.main}
selectionColor={
theme.sw.colors.primary.main + theme.sw.transparency[16]
}
selectTextOnFocus={true}
textAlign='center'
placeholderTextColor={style.placeholder.color}
onChangeText={onChangeText}
/>
);
};

function getState(
hasError: boolean | undefined,
isFocused: boolean,
value: string,
): State {
if (hasError) {
return 'error';
} else if (!isFocused && value === '') {
return 'empty';
} else if (isFocused && value === '') {
return 'empty-focused';
} else if (!isFocused) {
return 'filled';
} else {
return 'filled-focused';
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peut-on aplatir les conditions ici ?

if (hasError) {
    return 'error';
}

if (!isFocused && value === '') {
    return 'empty';
}

if (isFocused && value === '') {
    return 'empty-focused';
}
 
if (!isFocused) {
    return 'filled';
}

return 'filled-focused';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrigé

}

function removeNonNumeric(str: string): string {
return str.replace(/\D/g, '');
}
2 changes: 2 additions & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Product } from './product/Product';
import { Divider } from './divider/Divider';
import { LineChart } from './charts/LineChart';
import { Badge } from './badge/Badge';
import { DateField } from './datePicker/DateField';

export {
Body,
Expand Down Expand Up @@ -58,4 +59,5 @@ export {
Divider,
LineChart,
Badge,
DateField,
};
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Divider,
LineChart,
Badge,
DateField,
} from './components';

import { ThemeProvider, useTheme } from './styles/themes';
Expand Down Expand Up @@ -62,5 +63,6 @@ export {
Product,
Divider,
LineChart,
Badge
Badge,
DateField,
};