Skip to content

Commit

Permalink
chore: add PropTypes
Browse files Browse the repository at this point in the history
closes #4135
  • Loading branch information
virtuoushub committed Jan 17, 2022
1 parent 8ea4595 commit 3217ec6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/forms/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import React, { useContext, forwardRef } from 'react'

import pascalcase from 'pascalcase'
import PropTypes from 'prop-types'
import {
get,
useForm,
Expand Down Expand Up @@ -365,6 +366,13 @@ const Form = forwardRef<HTMLFormElement, FormProps>(
}
)

Form.propTypes = {
config: PropTypes.object,
error: PropTypes.any,
formMethods: PropTypes.any, // TODO: is there a better way to validate the type of the formMethods?
onSubmit: PropTypes.func,
}

export interface LabelProps
extends Pick<FieldProps, 'errorClassName' | 'errorStyle'>,
React.ComponentPropsWithoutRef<'label'> {
Expand Down Expand Up @@ -517,6 +525,20 @@ const TextAreaField = forwardRef<HTMLTextAreaElement, TextAreaFieldProps>(
}
)

const DEFAULT_FIELD_PROP_TYPES = {
name: PropTypes.string.isRequired,
id: PropTypes.string,
errorClassName: PropTypes.string,
errorStyle: PropTypes.object,
validation: PropTypes.object,
onBlur: PropTypes.func,
onChange: PropTypes.func,
}

TextAreaField.propTypes = {
...DEFAULT_FIELD_PROP_TYPES,
}

export interface SelectFieldProps
extends FieldProps<HTMLSelectElement>,
Omit<React.ComponentPropsWithRef<'select'>, 'name'> {}
Expand Down Expand Up @@ -566,6 +588,10 @@ const SelectField = forwardRef<HTMLSelectElement, SelectFieldProps>(
}
)

SelectField.propTypes = {
...DEFAULT_FIELD_PROP_TYPES,
}

export interface CheckboxFieldProps
extends FieldProps<HTMLInputElement>,
Omit<React.ComponentPropsWithRef<'input'>, 'name' | 'type'> {}
Expand Down Expand Up @@ -625,6 +651,10 @@ export const CheckboxField = forwardRef<HTMLInputElement, CheckboxFieldProps>(
}
)

CheckboxField.propTypes = {
...DEFAULT_FIELD_PROP_TYPES,
}

/**
* Renders a `<button type="submit">` field.
*
Expand Down Expand Up @@ -742,6 +772,10 @@ const InputField = forwardRef<HTMLInputElement, InputFieldProps>(
}
)

InputField.propTypes = {
...DEFAULT_FIELD_PROP_TYPES,
}

/**
* `React.ForwardRefExoticComponent` is `forwardRef`'s return type.
* You can hover over `<InputField>` above to see the type inference at work.
Expand Down

0 comments on commit 3217ec6

Please sign in to comment.