-
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
Refactor: Utilisation de TypeScript #51
Changes from 5 commits
53fb5c8
4a48d81
4fc5495
3ea90dd
0bde61c
2671787
ecf4667
e2973e6
5f93e05
2f2fbad
c355ec0
f0dd2f4
8a34eb3
a8bcc35
1fd91d9
0064990
b5740bb
ee0f877
9579097
408c732
cfd8c61
e95df60
71e20d5
5c5fc1f
c0ee19a
d23f445
5ce285d
2472272
6e613e6
4b2ad39
f11943d
2b72427
8ca26c4
e4905b1
35215b2
dffa255
c6e8745
6be2984
c85e33b
f000ba3
69e2730
2f36bd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { Children } from '../buttons/abstract-button'; | ||
import styles from './styles/visuallyhidden'; | ||
|
||
const Hidden = styled.span` | ||
${styles} | ||
`; | ||
|
||
const VisuallyHidden = ({ children }: {children: Children}) => ( | ||
<Hidden> | ||
{children} | ||
</Hidden> | ||
); | ||
|
||
export { VisuallyHidden }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ import styled from 'styled-components'; | |
|
||
import abstractStyle from './styles/abstract'; | ||
|
||
export type Children = ReactNode[] | string | Element; | ||
|
||
export interface AbstractButtonProps { | ||
children?: ReactNode[]; | ||
children?: Children; | ||
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. Tu peux utiliser simplement |
||
disabled?: boolean; | ||
onClick(): void; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ const Card = styled.div` | |
padding: 3rem 2rem; | ||
`; | ||
|
||
export default Card; | ||
export { Card }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ const EnsoSpinner = styled(Enso)` | |
} | ||
`; | ||
|
||
export default EnsoSpinner; | ||
export { EnsoSpinner }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import Label from './label'; | ||
import InvalidField from '../feedbacks/invalid-field'; | ||
import { Children } from '../buttons/abstract-button'; | ||
import { InvalidField } from '../feedbacks/invalid-field'; | ||
import { Label } from './label'; | ||
|
||
const StyledDiv = styled.div` | ||
margin: 0 0 1.5rem; | ||
|
@@ -18,7 +19,16 @@ const StyledDiv = styled.div` | |
} | ||
`; | ||
|
||
const FieldContainer = ({ children, fieldId, label, valid, validMsg, ...props }) => ( | ||
interface FieldContainerProps { | ||
children: Children; | ||
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 pense que le type |
||
fieldId: string; | ||
label: string; | ||
valid: boolean; | ||
validMsg: string; | ||
|
||
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. Ligne vide |
||
} | ||
|
||
const FieldContainer = ({ children, fieldId, label, valid, validMsg, ...props }: FieldContainerProps) => ( | ||
<StyledDiv {...props} valid={valid}> | ||
{label && ( | ||
<Label forId={fieldId}> | ||
|
@@ -34,4 +44,4 @@ const FieldContainer = ({ children, fieldId, label, valid, validMsg, ...props }) | |
</StyledDiv> | ||
); | ||
|
||
export default FieldContainer; | ||
export { FieldContainer } ; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React, { RefObject } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const Input = styled.input` | ||
|
@@ -7,8 +7,15 @@ const Input = styled.input` | |
width: 16px; | ||
`; | ||
|
||
const Checkbox = ({ defaultChecked, onChange }) => { | ||
const ref = React.createRef(); | ||
interface CheckboxProps { | ||
defaultChecked?: boolean; | ||
onChange: ((...args: any[]) => void); | ||
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.
|
||
} | ||
|
||
type Ref = ((instance: HTMLInputElement) => void) | RefObject<HTMLInputElement>; | ||
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. Les parenthèses sont peut-être de trop autour de |
||
|
||
const Checkbox = ({ defaultChecked, onChange }: CheckboxProps) => { | ||
const ref: Ref = React.createRef(); | ||
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.
|
||
|
||
const handleChange = () => { | ||
if (typeof onChange === 'function') { | ||
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. Plus besoin de faire cette validation en TypeScript. |
||
|
@@ -21,4 +28,4 @@ const Checkbox = ({ defaultChecked, onChange }) => { | |
); | ||
}; | ||
|
||
export default Checkbox; | ||
export { Checkbox }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,18 @@ const Input = styled.input` | |
} | ||
`; | ||
|
||
const OptionButton = ({ checked, label, name, value }) => ( | ||
interface OptionButtonProps { | ||
checked?: boolean; | ||
label: string; | ||
name: string; | ||
value: number; | ||
} | ||
|
||
const OptionButton = ({ checked, label, name, value }: OptionButtonProps) => ( | ||
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. Rien à faire pour le review, mais ce component n'est pas utilisé nul part et n'a pas de story correspondante dans Storybook. |
||
<div> | ||
<Input checked={checked} id="id" name={name} type="radio" value={value} /> | ||
<label htmlFor="id">{label}</label> | ||
</div> | ||
); | ||
|
||
export default OptionButton; | ||
export { OptionButton }; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
|
||
import { SearchInput, SearchInputProps } from './search-input'; | ||
|
||
const SearchContextual = ({ disabled, id, label, onChange }: SearchInputProps) => ( | ||
<SearchInput | ||
disabled={disabled} | ||
id={id} | ||
label={label} | ||
onChange={onChange} | ||
/> | ||
); | ||
|
||
export { SearchContextual }; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { SearchInput, SearchInputProps } from './search-input'; | ||
|
||
const SearchGlobal = ({ disabled, id, label, onSearch }: SearchInputProps) => ( | ||
<SearchInput | ||
disabled={disabled} | ||
hasButton | ||
id={id} | ||
label={label} | ||
onSearch={onSearch} | ||
/> | ||
); | ||
|
||
export { SearchGlobal }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import React, { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import SearchIcon from 'feather-icons/dist/icons/search.svg'; | ||
import XIcon from 'feather-icons/dist/icons/x.svg'; | ||
import styled from 'styled-components'; | ||
|
||
import VisuallyHidden from '../../a11y/visuallyhidden'; | ||
import { VisuallyHidden } from '../../a11y/visuallyhidden'; | ||
import { SearchButton } from '../../buttons/search-button'; | ||
|
||
import { Label } from '../label'; | ||
import style from '../styles/inputs'; | ||
import Label from '../label'; | ||
|
||
const SearchWrapper = styled.div` | ||
display: flex; | ||
|
@@ -86,10 +87,19 @@ const SearchSubmit = styled(SearchButton)` | |
position: relative; | ||
`; | ||
|
||
const SearchInput = ({ disabled, hasButton, id, label, onChange, onSearch }) => { | ||
export interface SearchInputProps { | ||
disabled?: boolean; | ||
hasButton?: boolean; | ||
id: string; | ||
label: string; | ||
onChange?: ((...args: any[]) => void); | ||
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.
|
||
onSearch?: ((...args: any[]) => void); | ||
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.
|
||
} | ||
|
||
const SearchInput = ({ disabled, hasButton, id, label, onChange, onSearch }: SearchInputProps) => { | ||
const [{ value }, setValue] = useState({ value: '' }); | ||
|
||
const handleChange = event => { | ||
const handleChange = (event: any) => { | ||
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.
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. Et c'était déjà de même, mais pas besoin de faire |
||
const newValue = event.target.value; | ||
setValue({ value: newValue }); | ||
|
||
|
@@ -98,7 +108,7 @@ const SearchInput = ({ disabled, hasButton, id, label, onChange, onSearch }) => | |
} | ||
}; | ||
|
||
const handleKeyDown = event => { | ||
const handleKeyDown = (event: any) => { | ||
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.
|
||
if (typeof onSearch === 'function' && event.keyCode === 13) { | ||
onSearch(value); | ||
} | ||
|
@@ -154,4 +164,4 @@ const SearchInput = ({ disabled, hasButton, id, label, onChange, onSearch }) => | |
); | ||
}; | ||
|
||
export default SearchInput; | ||
export { SearchInput }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import styled from 'styled-components'; | |
|
||
import style from '../styles/inputs'; | ||
|
||
import FieldContainer from '../field-container'; | ||
import { FieldContainer } from '../field-container'; | ||
|
||
const StyledTextArea = styled.textarea` | ||
${style} | ||
|
@@ -14,11 +14,23 @@ const StyledTextArea = styled.textarea` | |
resize: vertical; | ||
`; | ||
|
||
const TextArea = ({ defaultValue, disabled, id, label, onBlur, onChange, onFocus, required, validMsg }) => { | ||
export interface TextAreaProps { | ||
defaultValue?: string; | ||
disabled?: boolean; | ||
id: string; | ||
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. Me semble que le 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. Ouin on le met pour lier le label à l'input, mais en réalité ça devrait être fait à l'intérieur de la lib et pas exposé dans une prop. Je vais créer une carte et on fera le refactor plus tard. 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. Sinon l'autre possibilité c'est de mettre les inputs dans le tag label, comme ça t'as pas besoin du
Par contre faudrait retravailler le css, je pense qu'il est fait pour que le label soit à côté du input. Mais ça pourrait permettre d'avoir un id facultatif, si quelqu'un en a besoin, et que les deux soient liés quand même. |
||
label: string; | ||
onBlur?: ((...args: any[]) => void); | ||
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.
|
||
onChange?: ((...args: any[]) => void); | ||
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.
|
||
onFocus?: ((...args: any[]) => void); | ||
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.
|
||
required?: boolean; | ||
validMsg?: string; | ||
} | ||
|
||
const TextArea = ({ defaultValue, disabled, id, label, onBlur, onChange, onFocus, required, validMsg }: TextAreaProps) => { | ||
const [{ value }, setValue] = useState({ value: defaultValue || '' }); | ||
const [{ validity }, setValidity] = useState({ validity: true }); | ||
|
||
const handleBlur = event => { | ||
const handleBlur = (event: any) => { | ||
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.
|
||
const newValue = event.target.value; | ||
|
||
setValue({ value: newValue }); | ||
|
@@ -29,7 +41,7 @@ const TextArea = ({ defaultValue, disabled, id, label, onBlur, onChange, onFocus | |
} | ||
}; | ||
|
||
const handleChange = event => { | ||
const handleChange = (event: any) => { | ||
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.
|
||
const newValue = event.target.value; | ||
setValue({ value: newValue }); | ||
|
||
|
@@ -56,12 +68,12 @@ const TextArea = ({ defaultValue, disabled, id, label, onBlur, onChange, onFocus | |
id={id} | ||
onBlur={event => handleBlur(event)} | ||
onChange={event => handleChange(event)} | ||
onFocus={event => handleFocus(event)} | ||
onFocus={event => handleFocus()} | ||
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. Mettre les fonctions directement plutôt que |
||
required={required} | ||
value={value} | ||
/> | ||
</FieldContainer> | ||
); | ||
}; | ||
|
||
export default TextArea; | ||
export { TextArea }; |
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.
Pour tous les functional components, faire une interface pas exportée (sauf si nécessaire) pour les props et changer les
const Component = () => ReactElement
pourexport function Component(): ReactElement