Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
CheckboxInput: Typescript migration
Browse files Browse the repository at this point in the history
  • Loading branch information
rlecellier committed Oct 12, 2021
1 parent d421aee commit a295cee
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@
* @debt directory "Gaël: this file should be migrated within the new directory structure"
*/

import PropTypes from 'prop-types'
import React from 'react'

interface IProps {
SvgElement?: React.ComponentType | null,
checked?: boolean,
className?: string,
disabled?: boolean,
hiddenLabel?: boolean,
isInError?: boolean,
isLabelDisable?: boolean,
label: string,
name: string,
onChange: () => void,
subLabel?: string | null,
}

export const CheckboxInput = ({
onChange,
name,
label,
checked,
isInError,
SvgElement = null,
checked = false,
className = '',
disabled = false,
hiddenLabel = false,
isInError = false,
isLabelDisable,
labelAttributes,
className,
hiddenLabel,
subLabel,
SvgElement,
...attributes
}) => {
label,
name,
subLabel = null,
}: IProps) => {
let labelClasses = ['field', 'field-checkbox']
let subLabelClasses = ['ic-sub-label']
if (isLabelDisable) {
Expand All @@ -35,18 +47,21 @@ export const CheckboxInput = ({
}
inputClasses.push('input-checkbox-input')

let checkboxAttributes: {
disabled?: boolean
} = { disabled }

return (
<label
className={labelClasses.join(' ')}
{...labelAttributes}
>
<input
checked={checked}
className={inputClasses.join(' ')}
name={name}
onChange={onChange}
type="checkbox"
{...attributes}
{...checkboxAttributes}
/>
{SvgElement && <SvgElement aria-hidden />}
<span className={textClasses.join(' ')}>
Expand All @@ -60,28 +75,3 @@ export const CheckboxInput = ({
</label>
)
}

CheckboxInput.defaultProps = {
SvgElement: null,
checked: false,
className: '',
hiddenLabel: false,
isInError: false,
isLabelDisable: false,
labelAttributes: {},
subLabel: null,
}

CheckboxInput.propTypes = {
SvgElement: PropTypes.elementType,
checked: PropTypes.bool,
className: PropTypes.string,
hiddenLabel: PropTypes.bool,
isInError: PropTypes.bool,
isLabelDisable: PropTypes.bool,
label: PropTypes.string.isRequired,
labelAttributes: PropTypes.shape(),
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
subLabel: PropTypes.string,
}
1 change: 1 addition & 0 deletions src/components/layout/inputs/CheckboxInput/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CheckboxInput } from './CheckboxInput'
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useCallback } from 'react'
import { Field } from 'react-final-form'

import HiddenField from 'components/layout/form/fields/HiddenField'
import { CheckboxInput } from 'components/layout/inputs/CheckboxInput/CheckboxInput'
import { CheckboxInput } from 'components/layout/inputs/CheckboxInput'
import TextareaInput from 'components/layout/inputs/TextareaInput'

const WithdrawalDetailsFields = props => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types'
import React, { useCallback } from 'react'

import { CheckboxInput } from 'components/layout/inputs/CheckboxInput/CheckboxInput'
import { CheckboxInput } from 'components/layout/inputs/CheckboxInput'
import InputError from 'components/layout/inputs/Errors/InputError'
import { ReactComponent as AudioDisabilitySvg } from 'icons/audio-disability.svg'
import { ReactComponent as MentalDisabilitySvg } from 'icons/mental-disability.svg'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Link } from 'react-router-dom'

import useActiveFeature from 'components/hooks/useActiveFeature'
import InternalBanner from 'components/layout/Banner/InternalBanner'
import { CheckboxInput } from 'components/layout/inputs/CheckboxInput/CheckboxInput'
import { CheckboxInput } from 'components/layout/inputs/CheckboxInput'
import DurationInput from 'components/layout/inputs/DurationInput/DurationInput'
import Select, {
buildSelectOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import React, { useCallback, useState } from 'react'

import { CheckboxInput } from 'components/layout/inputs/CheckboxInput/CheckboxInput'
import { CheckboxInput } from 'components/layout/inputs/CheckboxInput'

const StyleguideCheckboxes = () => {
const [checked, setChecked] = useState(false)
Expand Down

0 comments on commit a295cee

Please sign in to comment.