-
Notifications
You must be signed in to change notification settings - Fork 0
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
Task/date field #147
Changes from 1 commit
5aaea5e
9d3058f
94f5ef4
3709a05
41d9e4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,160 @@ | ||||||||
import React, { useState } from 'react'; | ||||||||
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) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a pas une font size dans le DS ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not yet WIP |
||||||||
lineHeight: 48, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> = ({ | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>) => { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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é ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrigé |
||||||||
} | ||||||||
|
||||||||
function removeNonNumeric(str: string): string { | ||||||||
return str.replace(/\D/g, ''); | ||||||||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ^^